pub struct CecPhysicalAddress(/* private fields */);Expand description
CEC physical address
It is a 16-bit number where each group of 4 bits represent a digit of the physical address a.b.c.d where the most significant 4 bits represent ‘a’. The CEC root device (usually the TV) has address 0.0.0.0. Every device that is hooked up to an input of the TV has address a.0.0.0 (where ‘a’ is ≥ 1), devices hooked up to those in turn have addresses a.b.0.0, etc. So a topology of up to 5 devices deep is supported. The physical address a device shall use is stored in the EDID of the sink.
For example, the EDID for each HDMI input of the TV will have a different physical address of the form a.0.0.0 that the sources will read out and use as their physical address.
phys_addr is either 0 (if this is the CEC root device) or a valid physical address obtained from the sink’s EDID as read by this CEC device (if this is a source device) or a physical address obtained and modified from a sink EDID and used for a sink CEC device.
If nothing is connected, then phys_addr is CecPhysicalAddress::INVALID. See HDMI 1.4b, section 8.7 (Physical Address).
Implementations§
Source§impl CecPhysicalAddress
impl CecPhysicalAddress
pub const INVALID: CecPhysicalAddress
pub const fn from_bytes(bytes: [u8; 2]) -> CecPhysicalAddress
pub const fn from_num(num: u16) -> CecPhysicalAddress
Sourcepub const fn to_bytes(&self) -> [u8; 2]
pub const fn to_bytes(&self) -> [u8; 2]
Examples found in repository?
8fn main() -> std::io::Result<()> {
9 let cec = CecDevice::open("/dev/cec0")?;
10
11 cec.set_mode(CecModeInitiator::Send, CecModeFollower::ExclusivePassthru)?;
12
13 let physical_addr = cec.get_phys()?;
14
15 loop {
16 let msg = cec.rec()?;
17 match msg.opcode() {
18 Some(Ok(CecOpcode::ActiveSource))
19 | Some(Ok(CecOpcode::RoutingInformation))
20 | Some(Ok(CecOpcode::SetStreamPath))
21 if physical_addr == msg.parameters() =>
22 {
23 // this is not done by the core
24 println!("THIS IS US {:?}", msg.opcode().unwrap().unwrap());
25 cec.transmit_data(
26 CecLogicalAddress::Playback2,
27 CecLogicalAddress::UnregisteredBroadcast,
28 CecOpcode::ActiveSource,
29 &physical_addr.to_bytes(),
30 )?;
31 }
32 Some(Ok(CecOpcode::ReportPhysicalAddr)) => {} //core is still taking care of that
33 Some(Ok(opcode)) if msg.destination() == CecLogicalAddress::UnregisteredBroadcast => {
34 //dont answer brodcasts
35 println!(
36 "{:?}: {:?} {:x?}",
37 msg.initiator(),
38 opcode,
39 msg.parameters()
40 );
41 }
42 Some(Ok(CecOpcode::GetCecVersion)) => {
43 cec.transmit_data(
44 msg.destination(),
45 msg.initiator(),
46 CecOpcode::CecVersion,
47 &[Version::V1_3A.into()],
48 )?;
49 }
50 Some(Ok(CecOpcode::GiveDeviceVendorId)) => {
51 cec.transmit_data(
52 msg.destination(),
53 msg.initiator(),
54 CecOpcode::FeatureAbort,
55 &[
56 CecOpcode::GiveDeviceVendorId.into(),
57 CecAbortReason::Unrecognized.into(),
58 ],
59 )?; /*
60 cec.transmit_data(
61 msg.destination(),
62 msg.initiator(),
63 CecOpcode::DeviceVendorId,
64 &[0,0,0])?;*/
65 }
66 Some(Ok(CecOpcode::Abort)) => {
67 cec.transmit_data(
68 msg.destination(),
69 msg.initiator(),
70 CecOpcode::FeatureAbort,
71 &[CecOpcode::Abort.into(), CecAbortReason::Other.into()],
72 )?;
73 }
74 Some(Ok(CecOpcode::GivePhysicalAddr)) => {
75 let l = cec.get_log()?;
76 let mut addr = Vec::with_capacity(3);
77 if let Some(log) = l.addresses().first() {
78 addr.extend_from_slice(&physical_addr.to_bytes());
79 addr.push((*log).into());
80
81 cec.transmit_data(
82 msg.destination(),
83 msg.initiator(),
84 CecOpcode::ReportPhysicalAddr,
85 &addr,
86 )?;
87 } //else no address yet?!?!?
88 }
89 Some(Ok(CecOpcode::GiveOsdName)) => {
90 cec.transmit_data(
91 msg.destination(),
92 msg.initiator(),
93 CecOpcode::SetOsdName,
94 b"pi4",
95 )?;
96 }
97 Some(Ok(CecOpcode::GiveDevicePowerStatus)) => {
98 cec.transmit_data(
99 msg.destination(),
100 msg.initiator(),
101 CecOpcode::ReportPowerStatus,
102 &[CecPowerStatus::On.into()],
103 )?;
104 }
105 Some(Ok(CecOpcode::GiveFeatures)) => {}
106 Some(Ok(opcode)) => {
107 println!(
108 "{:?} -> {:?} : {:?} {:x?}",
109 msg.initiator(),
110 msg.destination(),
111 opcode,
112 msg.parameters()
113 );
114 }
115 _ => {
116 println!("{:?}", msg);
117 }
118 }
119 }
120}pub const fn to_num(&self) -> u16
Trait Implementations§
Source§impl Clone for CecPhysicalAddress
impl Clone for CecPhysicalAddress
Source§fn clone(&self) -> CecPhysicalAddress
fn clone(&self) -> CecPhysicalAddress
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more