Skip to main content

CecPhysicalAddress

Struct CecPhysicalAddress 

Source
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

Source

pub const INVALID: CecPhysicalAddress

Source

pub const fn from_bytes(bytes: [u8; 2]) -> CecPhysicalAddress

Source

pub const fn from_num(num: u16) -> CecPhysicalAddress

Source

pub const fn to_bytes(&self) -> [u8; 2]

Examples found in repository?
examples/pass.rs (line 29)
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}
Source

pub const fn to_num(&self) -> u16

Trait Implementations§

Source§

impl Clone for CecPhysicalAddress

Source§

fn clone(&self) -> CecPhysicalAddress

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CecPhysicalAddress

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<[u8; 2]> for CecPhysicalAddress

Source§

fn from(value: [u8; 2]) -> Self

Converts to this type from the input type.
Source§

impl From<u16> for CecPhysicalAddress

Source§

fn from(value: u16) -> Self

Converts to this type from the input type.
Source§

impl PartialEq<&[u8]> for CecPhysicalAddress

Source§

fn eq(&self, other: &&[u8]) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<[u8; 2]> for CecPhysicalAddress

Source§

fn eq(&self, other: &[u8; 2]) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<u16> for CecPhysicalAddress

Source§

fn eq(&self, other: &u16) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq for CecPhysicalAddress

Source§

fn eq(&self, other: &CecPhysicalAddress) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for CecPhysicalAddress

Source§

impl Eq for CecPhysicalAddress

Source§

impl StructuralPartialEq for CecPhysicalAddress

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.