pub struct CecMsg {
pub timeout: u32,
pub sequence: u32,
pub reply: CecOpcode,
pub rx_status: RxStatus,
pub tx_status: TxStatus,
/* private fields */
}Expand description
CEC message returned from CecDevice::rec and CecDevice::rec_for
Fields§
§timeout: u32The timeout (in ms) that is used to timeout CEC_RECEIVE. Set to 0 if you want to wait forever. This timeout can also be used with CEC_TRANSMIT as the timeout for waiting for a reply. If 0, then it will use a 1 second timeout instead of waiting forever as is done with CEC_RECEIVE.
sequence: u32The framework assigns a sequence number to messages that are sent. This can be used to track replies to previously sent messages.
reply: CecOpcodeThis field is ignored with CEC_RECEIVE and is only used by CEC_TRANSMIT. If non-zero, then wait for a reply with this opcode. Set to CEC_MSG_FEATURE_ABORT if you want to wait for a possible ABORT reply.
If there was an error when sending the msg or FeatureAbort was returned, then reply is set to 0.
If reply is non-zero upon return, then len/msg are set to the received message. If reply is zero upon return and status has the CEC_TX_STATUS_FEATURE_ABORT bit set, then len/msg are set to the received feature abort message. If reply is zero upon return and status has the CEC_TX_STATUS_MAX_RETRIES bit set, then no reply was seen at all. If reply is non-zero for CEC_TRANSMIT and the message is a broadcast, then -EINVAL is returned. if reply is non-zero, then timeout is set to 1000 (the required maximum response time).
rx_status: RxStatusThe message receive status bits. Set by the driver.
tx_status: TxStatusThe message transmit status bits. Set by the driver.
Implementations§
Source§impl CecMsg
impl CecMsg
Sourcepub fn initiator(&self) -> CecLogicalAddress
pub fn initiator(&self) -> CecLogicalAddress
return the initiator’s logical address
Examples found in repository?
9fn main() -> std::io::Result<()> {
10 let cec = CecDevice::open("/dev/cec0")?;
11 let capas = cec.get_capas();
12 println!("capas {:?}", capas);
13 cec.set_mode(CecModeInitiator::None, CecModeFollower::Monitor)?;
14
15 loop {
16 let f = cec.poll(
17 PollFlags::POLLIN | PollFlags::POLLRDNORM | PollFlags::POLLPRI,
18 PollTimeout::NONE,
19 )?;
20
21 if f.intersects(PollFlags::POLLPRI) {
22 let evt = cec.get_event()?;
23 println!("evt {:x?}", evt);
24 }
25 if f.contains(PollFlags::POLLIN | PollFlags::POLLRDNORM) {
26 let msg = cec.rec()?;
27
28 if msg.is_ok() {
29 match (msg.initiator(), msg.destination(), msg.opcode()) {
30 (i, d, Some(Ok(o))) => {
31 println!("msg {:?}->{:?} {:?} {:x?}", i, d, o, msg.parameters());
32 }
33 _ => println!("msg {:x?}", msg),
34 }
35 } else {
36 println!("msg {:x?}", msg);
37 }
38 }
39 }
40}More examples
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}Sourcepub fn destination(&self) -> CecLogicalAddress
pub fn destination(&self) -> CecLogicalAddress
return the destination’s logical address
Examples found in repository?
9fn main() -> std::io::Result<()> {
10 let cec = CecDevice::open("/dev/cec0")?;
11 let capas = cec.get_capas();
12 println!("capas {:?}", capas);
13 cec.set_mode(CecModeInitiator::None, CecModeFollower::Monitor)?;
14
15 loop {
16 let f = cec.poll(
17 PollFlags::POLLIN | PollFlags::POLLRDNORM | PollFlags::POLLPRI,
18 PollTimeout::NONE,
19 )?;
20
21 if f.intersects(PollFlags::POLLPRI) {
22 let evt = cec.get_event()?;
23 println!("evt {:x?}", evt);
24 }
25 if f.contains(PollFlags::POLLIN | PollFlags::POLLRDNORM) {
26 let msg = cec.rec()?;
27
28 if msg.is_ok() {
29 match (msg.initiator(), msg.destination(), msg.opcode()) {
30 (i, d, Some(Ok(o))) => {
31 println!("msg {:?}->{:?} {:?} {:x?}", i, d, o, msg.parameters());
32 }
33 _ => println!("msg {:x?}", msg),
34 }
35 } else {
36 println!("msg {:x?}", msg);
37 }
38 }
39 }
40}More examples
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}Sourcepub fn opcode(
&self,
) -> Option<Result<CecOpcode, TryFromPrimitiveError<CecOpcode>>>
pub fn opcode( &self, ) -> Option<Result<CecOpcode, TryFromPrimitiveError<CecOpcode>>>
return the opcode of the message, None for poll
Examples found in repository?
9fn main() -> std::io::Result<()> {
10 let cec = CecDevice::open("/dev/cec0")?;
11 let capas = cec.get_capas();
12 println!("capas {:?}", capas);
13 cec.set_mode(CecModeInitiator::None, CecModeFollower::Monitor)?;
14
15 loop {
16 let f = cec.poll(
17 PollFlags::POLLIN | PollFlags::POLLRDNORM | PollFlags::POLLPRI,
18 PollTimeout::NONE,
19 )?;
20
21 if f.intersects(PollFlags::POLLPRI) {
22 let evt = cec.get_event()?;
23 println!("evt {:x?}", evt);
24 }
25 if f.contains(PollFlags::POLLIN | PollFlags::POLLRDNORM) {
26 let msg = cec.rec()?;
27
28 if msg.is_ok() {
29 match (msg.initiator(), msg.destination(), msg.opcode()) {
30 (i, d, Some(Ok(o))) => {
31 println!("msg {:?}->{:?} {:?} {:x?}", i, d, o, msg.parameters());
32 }
33 _ => println!("msg {:x?}", msg),
34 }
35 } else {
36 println!("msg {:x?}", msg);
37 }
38 }
39 }
40}More examples
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}Sourcepub fn parameters(&self) -> &[u8] ⓘ
pub fn parameters(&self) -> &[u8] ⓘ
Examples found in repository?
9fn main() -> std::io::Result<()> {
10 let cec = CecDevice::open("/dev/cec0")?;
11 let capas = cec.get_capas();
12 println!("capas {:?}", capas);
13 cec.set_mode(CecModeInitiator::None, CecModeFollower::Monitor)?;
14
15 loop {
16 let f = cec.poll(
17 PollFlags::POLLIN | PollFlags::POLLRDNORM | PollFlags::POLLPRI,
18 PollTimeout::NONE,
19 )?;
20
21 if f.intersects(PollFlags::POLLPRI) {
22 let evt = cec.get_event()?;
23 println!("evt {:x?}", evt);
24 }
25 if f.contains(PollFlags::POLLIN | PollFlags::POLLRDNORM) {
26 let msg = cec.rec()?;
27
28 if msg.is_ok() {
29 match (msg.initiator(), msg.destination(), msg.opcode()) {
30 (i, d, Some(Ok(o))) => {
31 println!("msg {:?}->{:?} {:?} {:x?}", i, d, o, msg.parameters());
32 }
33 _ => println!("msg {:x?}", msg),
34 }
35 } else {
36 println!("msg {:x?}", msg);
37 }
38 }
39 }
40}More examples
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}Sourcepub fn is_broadcast(&self) -> bool
pub fn is_broadcast(&self) -> bool
return true if this is a broadcast message
Sourcepub fn is_ok(&self) -> bool
pub fn is_ok(&self) -> bool
Examples found in repository?
9fn main() -> std::io::Result<()> {
10 let cec = CecDevice::open("/dev/cec0")?;
11 let capas = cec.get_capas();
12 println!("capas {:?}", capas);
13 cec.set_mode(CecModeInitiator::None, CecModeFollower::Monitor)?;
14
15 loop {
16 let f = cec.poll(
17 PollFlags::POLLIN | PollFlags::POLLRDNORM | PollFlags::POLLPRI,
18 PollTimeout::NONE,
19 )?;
20
21 if f.intersects(PollFlags::POLLPRI) {
22 let evt = cec.get_event()?;
23 println!("evt {:x?}", evt);
24 }
25 if f.contains(PollFlags::POLLIN | PollFlags::POLLRDNORM) {
26 let msg = cec.rec()?;
27
28 if msg.is_ok() {
29 match (msg.initiator(), msg.destination(), msg.opcode()) {
30 (i, d, Some(Ok(o))) => {
31 println!("msg {:?}->{:?} {:?} {:x?}", i, d, o, msg.parameters());
32 }
33 _ => println!("msg {:x?}", msg),
34 }
35 } else {
36 println!("msg {:x?}", msg);
37 }
38 }
39 }
40}