#[repr(C)]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: u32
The 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: u32
The framework assigns a sequence number to messages that are sent. This can be used to track replies to previously sent messages.
reply: CecOpcode
This 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: RxStatus
The message receive status bits. Set by the driver.
tx_status: TxStatus
The 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?
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
fn main() -> std::io::Result<()> {
let cec = CecDevice::open("/dev/cec0")?;
let capas = cec.get_capas();
println!("capas {:?}", capas);
cec.set_mode(CecModeInitiator::None, CecModeFollower::Monitor)?;
loop {
let f = cec.poll(
PollFlags::POLLIN | PollFlags::POLLRDNORM | PollFlags::POLLPRI,
PollTimeout::NONE,
)?;
if f.intersects(PollFlags::POLLPRI) {
let evt = cec.get_event()?;
println!("evt {:x?}", evt);
}
if f.contains(PollFlags::POLLIN | PollFlags::POLLRDNORM) {
let msg = cec.rec()?;
if msg.is_ok() {
match (msg.initiator(), msg.destination(), msg.opcode()) {
(i, d, Some(Ok(o))) => {
println!("msg {:?}->{:?} {:?} {:x?}", i, d, o, msg.parameters());
}
_ => println!("msg {:x?}", msg),
}
} else {
println!("msg {:x?}", msg);
}
}
}
}
More examples
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
fn main() -> std::io::Result<()> {
let cec = CecDevice::open("/dev/cec0")?;
cec.set_mode(CecModeInitiator::Send, CecModeFollower::ExclusivePassthru)?;
let physical_addr = cec.get_phys()?;
loop {
let msg = cec.rec()?;
match msg.opcode() {
Some(Ok(CecOpcode::ActiveSource))
| Some(Ok(CecOpcode::RoutingInformation))
| Some(Ok(CecOpcode::SetStreamPath))
if physical_addr == msg.parameters() =>
{
// this is not done by the core
println!("THIS IS US {:?}", msg.opcode().unwrap().unwrap());
cec.transmit_data(
CecLogicalAddress::Playback2,
CecLogicalAddress::UnregisteredBroadcast,
CecOpcode::ActiveSource,
&physical_addr.to_bytes(),
)?;
}
Some(Ok(CecOpcode::ReportPhysicalAddr)) => {} //core is still taking care of that
Some(Ok(opcode)) if msg.destination() == CecLogicalAddress::UnregisteredBroadcast => {
//dont answer brodcasts
println!(
"{:?}: {:?} {:x?}",
msg.initiator(),
opcode,
msg.parameters()
);
}
Some(Ok(CecOpcode::GetCecVersion)) => {
cec.transmit_data(
msg.destination(),
msg.initiator(),
CecOpcode::CecVersion,
&[Version::V1_3A.into()],
)?;
}
Some(Ok(CecOpcode::GiveDeviceVendorId)) => {
cec.transmit_data(
msg.destination(),
msg.initiator(),
CecOpcode::FeatureAbort,
&[
CecOpcode::GiveDeviceVendorId.into(),
CecAbortReason::Unrecognized.into(),
],
)?; /*
cec.transmit_data(
msg.destination(),
msg.initiator(),
CecOpcode::DeviceVendorId,
&[0,0,0])?;*/
}
Some(Ok(CecOpcode::Abort)) => {
cec.transmit_data(
msg.destination(),
msg.initiator(),
CecOpcode::FeatureAbort,
&[CecOpcode::Abort.into(), CecAbortReason::Other.into()],
)?;
}
Some(Ok(CecOpcode::GivePhysicalAddr)) => {
let l = cec.get_log()?;
let mut addr = Vec::with_capacity(3);
if let Some(log) = l.addresses().first() {
addr.extend_from_slice(&physical_addr.to_bytes());
addr.push((*log).into());
cec.transmit_data(
msg.destination(),
msg.initiator(),
CecOpcode::ReportPhysicalAddr,
&addr,
)?;
} //else no address yet?!?!?
}
Some(Ok(CecOpcode::GiveOsdName)) => {
cec.transmit_data(
msg.destination(),
msg.initiator(),
CecOpcode::SetOsdName,
b"pi4",
)?;
}
Some(Ok(CecOpcode::GiveDevicePowerStatus)) => {
cec.transmit_data(
msg.destination(),
msg.initiator(),
CecOpcode::ReportPowerStatus,
&[CecPowerStatus::On.into()],
)?;
}
Some(Ok(CecOpcode::GiveFeatures)) => {}
Some(Ok(opcode)) => {
println!(
"{:?} -> {:?} : {:?} {:x?}",
msg.initiator(),
msg.destination(),
opcode,
msg.parameters()
);
}
_ => {
println!("{:?}", msg);
}
}
}
}
sourcepub fn destination(&self) -> CecLogicalAddress
pub fn destination(&self) -> CecLogicalAddress
return the destination’s logical address
Examples found in repository?
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
fn main() -> std::io::Result<()> {
let cec = CecDevice::open("/dev/cec0")?;
let capas = cec.get_capas();
println!("capas {:?}", capas);
cec.set_mode(CecModeInitiator::None, CecModeFollower::Monitor)?;
loop {
let f = cec.poll(
PollFlags::POLLIN | PollFlags::POLLRDNORM | PollFlags::POLLPRI,
PollTimeout::NONE,
)?;
if f.intersects(PollFlags::POLLPRI) {
let evt = cec.get_event()?;
println!("evt {:x?}", evt);
}
if f.contains(PollFlags::POLLIN | PollFlags::POLLRDNORM) {
let msg = cec.rec()?;
if msg.is_ok() {
match (msg.initiator(), msg.destination(), msg.opcode()) {
(i, d, Some(Ok(o))) => {
println!("msg {:?}->{:?} {:?} {:x?}", i, d, o, msg.parameters());
}
_ => println!("msg {:x?}", msg),
}
} else {
println!("msg {:x?}", msg);
}
}
}
}
More examples
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
fn main() -> std::io::Result<()> {
let cec = CecDevice::open("/dev/cec0")?;
cec.set_mode(CecModeInitiator::Send, CecModeFollower::ExclusivePassthru)?;
let physical_addr = cec.get_phys()?;
loop {
let msg = cec.rec()?;
match msg.opcode() {
Some(Ok(CecOpcode::ActiveSource))
| Some(Ok(CecOpcode::RoutingInformation))
| Some(Ok(CecOpcode::SetStreamPath))
if physical_addr == msg.parameters() =>
{
// this is not done by the core
println!("THIS IS US {:?}", msg.opcode().unwrap().unwrap());
cec.transmit_data(
CecLogicalAddress::Playback2,
CecLogicalAddress::UnregisteredBroadcast,
CecOpcode::ActiveSource,
&physical_addr.to_bytes(),
)?;
}
Some(Ok(CecOpcode::ReportPhysicalAddr)) => {} //core is still taking care of that
Some(Ok(opcode)) if msg.destination() == CecLogicalAddress::UnregisteredBroadcast => {
//dont answer brodcasts
println!(
"{:?}: {:?} {:x?}",
msg.initiator(),
opcode,
msg.parameters()
);
}
Some(Ok(CecOpcode::GetCecVersion)) => {
cec.transmit_data(
msg.destination(),
msg.initiator(),
CecOpcode::CecVersion,
&[Version::V1_3A.into()],
)?;
}
Some(Ok(CecOpcode::GiveDeviceVendorId)) => {
cec.transmit_data(
msg.destination(),
msg.initiator(),
CecOpcode::FeatureAbort,
&[
CecOpcode::GiveDeviceVendorId.into(),
CecAbortReason::Unrecognized.into(),
],
)?; /*
cec.transmit_data(
msg.destination(),
msg.initiator(),
CecOpcode::DeviceVendorId,
&[0,0,0])?;*/
}
Some(Ok(CecOpcode::Abort)) => {
cec.transmit_data(
msg.destination(),
msg.initiator(),
CecOpcode::FeatureAbort,
&[CecOpcode::Abort.into(), CecAbortReason::Other.into()],
)?;
}
Some(Ok(CecOpcode::GivePhysicalAddr)) => {
let l = cec.get_log()?;
let mut addr = Vec::with_capacity(3);
if let Some(log) = l.addresses().first() {
addr.extend_from_slice(&physical_addr.to_bytes());
addr.push((*log).into());
cec.transmit_data(
msg.destination(),
msg.initiator(),
CecOpcode::ReportPhysicalAddr,
&addr,
)?;
} //else no address yet?!?!?
}
Some(Ok(CecOpcode::GiveOsdName)) => {
cec.transmit_data(
msg.destination(),
msg.initiator(),
CecOpcode::SetOsdName,
b"pi4",
)?;
}
Some(Ok(CecOpcode::GiveDevicePowerStatus)) => {
cec.transmit_data(
msg.destination(),
msg.initiator(),
CecOpcode::ReportPowerStatus,
&[CecPowerStatus::On.into()],
)?;
}
Some(Ok(CecOpcode::GiveFeatures)) => {}
Some(Ok(opcode)) => {
println!(
"{:?} -> {:?} : {:?} {:x?}",
msg.initiator(),
msg.destination(),
opcode,
msg.parameters()
);
}
_ => {
println!("{:?}", msg);
}
}
}
}
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?
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
fn main() -> std::io::Result<()> {
let cec = CecDevice::open("/dev/cec0")?;
let capas = cec.get_capas();
println!("capas {:?}", capas);
cec.set_mode(CecModeInitiator::None, CecModeFollower::Monitor)?;
loop {
let f = cec.poll(
PollFlags::POLLIN | PollFlags::POLLRDNORM | PollFlags::POLLPRI,
PollTimeout::NONE,
)?;
if f.intersects(PollFlags::POLLPRI) {
let evt = cec.get_event()?;
println!("evt {:x?}", evt);
}
if f.contains(PollFlags::POLLIN | PollFlags::POLLRDNORM) {
let msg = cec.rec()?;
if msg.is_ok() {
match (msg.initiator(), msg.destination(), msg.opcode()) {
(i, d, Some(Ok(o))) => {
println!("msg {:?}->{:?} {:?} {:x?}", i, d, o, msg.parameters());
}
_ => println!("msg {:x?}", msg),
}
} else {
println!("msg {:x?}", msg);
}
}
}
}
More examples
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
fn main() -> std::io::Result<()> {
let cec = CecDevice::open("/dev/cec0")?;
cec.set_mode(CecModeInitiator::Send, CecModeFollower::ExclusivePassthru)?;
let physical_addr = cec.get_phys()?;
loop {
let msg = cec.rec()?;
match msg.opcode() {
Some(Ok(CecOpcode::ActiveSource))
| Some(Ok(CecOpcode::RoutingInformation))
| Some(Ok(CecOpcode::SetStreamPath))
if physical_addr == msg.parameters() =>
{
// this is not done by the core
println!("THIS IS US {:?}", msg.opcode().unwrap().unwrap());
cec.transmit_data(
CecLogicalAddress::Playback2,
CecLogicalAddress::UnregisteredBroadcast,
CecOpcode::ActiveSource,
&physical_addr.to_bytes(),
)?;
}
Some(Ok(CecOpcode::ReportPhysicalAddr)) => {} //core is still taking care of that
Some(Ok(opcode)) if msg.destination() == CecLogicalAddress::UnregisteredBroadcast => {
//dont answer brodcasts
println!(
"{:?}: {:?} {:x?}",
msg.initiator(),
opcode,
msg.parameters()
);
}
Some(Ok(CecOpcode::GetCecVersion)) => {
cec.transmit_data(
msg.destination(),
msg.initiator(),
CecOpcode::CecVersion,
&[Version::V1_3A.into()],
)?;
}
Some(Ok(CecOpcode::GiveDeviceVendorId)) => {
cec.transmit_data(
msg.destination(),
msg.initiator(),
CecOpcode::FeatureAbort,
&[
CecOpcode::GiveDeviceVendorId.into(),
CecAbortReason::Unrecognized.into(),
],
)?; /*
cec.transmit_data(
msg.destination(),
msg.initiator(),
CecOpcode::DeviceVendorId,
&[0,0,0])?;*/
}
Some(Ok(CecOpcode::Abort)) => {
cec.transmit_data(
msg.destination(),
msg.initiator(),
CecOpcode::FeatureAbort,
&[CecOpcode::Abort.into(), CecAbortReason::Other.into()],
)?;
}
Some(Ok(CecOpcode::GivePhysicalAddr)) => {
let l = cec.get_log()?;
let mut addr = Vec::with_capacity(3);
if let Some(log) = l.addresses().first() {
addr.extend_from_slice(&physical_addr.to_bytes());
addr.push((*log).into());
cec.transmit_data(
msg.destination(),
msg.initiator(),
CecOpcode::ReportPhysicalAddr,
&addr,
)?;
} //else no address yet?!?!?
}
Some(Ok(CecOpcode::GiveOsdName)) => {
cec.transmit_data(
msg.destination(),
msg.initiator(),
CecOpcode::SetOsdName,
b"pi4",
)?;
}
Some(Ok(CecOpcode::GiveDevicePowerStatus)) => {
cec.transmit_data(
msg.destination(),
msg.initiator(),
CecOpcode::ReportPowerStatus,
&[CecPowerStatus::On.into()],
)?;
}
Some(Ok(CecOpcode::GiveFeatures)) => {}
Some(Ok(opcode)) => {
println!(
"{:?} -> {:?} : {:?} {:x?}",
msg.initiator(),
msg.destination(),
opcode,
msg.parameters()
);
}
_ => {
println!("{:?}", msg);
}
}
}
}
sourcepub fn parameters(&self) -> &[u8] ⓘ
pub fn parameters(&self) -> &[u8] ⓘ
Examples found in repository?
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
fn main() -> std::io::Result<()> {
let cec = CecDevice::open("/dev/cec0")?;
let capas = cec.get_capas();
println!("capas {:?}", capas);
cec.set_mode(CecModeInitiator::None, CecModeFollower::Monitor)?;
loop {
let f = cec.poll(
PollFlags::POLLIN | PollFlags::POLLRDNORM | PollFlags::POLLPRI,
PollTimeout::NONE,
)?;
if f.intersects(PollFlags::POLLPRI) {
let evt = cec.get_event()?;
println!("evt {:x?}", evt);
}
if f.contains(PollFlags::POLLIN | PollFlags::POLLRDNORM) {
let msg = cec.rec()?;
if msg.is_ok() {
match (msg.initiator(), msg.destination(), msg.opcode()) {
(i, d, Some(Ok(o))) => {
println!("msg {:?}->{:?} {:?} {:x?}", i, d, o, msg.parameters());
}
_ => println!("msg {:x?}", msg),
}
} else {
println!("msg {:x?}", msg);
}
}
}
}
More examples
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
fn main() -> std::io::Result<()> {
let cec = CecDevice::open("/dev/cec0")?;
cec.set_mode(CecModeInitiator::Send, CecModeFollower::ExclusivePassthru)?;
let physical_addr = cec.get_phys()?;
loop {
let msg = cec.rec()?;
match msg.opcode() {
Some(Ok(CecOpcode::ActiveSource))
| Some(Ok(CecOpcode::RoutingInformation))
| Some(Ok(CecOpcode::SetStreamPath))
if physical_addr == msg.parameters() =>
{
// this is not done by the core
println!("THIS IS US {:?}", msg.opcode().unwrap().unwrap());
cec.transmit_data(
CecLogicalAddress::Playback2,
CecLogicalAddress::UnregisteredBroadcast,
CecOpcode::ActiveSource,
&physical_addr.to_bytes(),
)?;
}
Some(Ok(CecOpcode::ReportPhysicalAddr)) => {} //core is still taking care of that
Some(Ok(opcode)) if msg.destination() == CecLogicalAddress::UnregisteredBroadcast => {
//dont answer brodcasts
println!(
"{:?}: {:?} {:x?}",
msg.initiator(),
opcode,
msg.parameters()
);
}
Some(Ok(CecOpcode::GetCecVersion)) => {
cec.transmit_data(
msg.destination(),
msg.initiator(),
CecOpcode::CecVersion,
&[Version::V1_3A.into()],
)?;
}
Some(Ok(CecOpcode::GiveDeviceVendorId)) => {
cec.transmit_data(
msg.destination(),
msg.initiator(),
CecOpcode::FeatureAbort,
&[
CecOpcode::GiveDeviceVendorId.into(),
CecAbortReason::Unrecognized.into(),
],
)?; /*
cec.transmit_data(
msg.destination(),
msg.initiator(),
CecOpcode::DeviceVendorId,
&[0,0,0])?;*/
}
Some(Ok(CecOpcode::Abort)) => {
cec.transmit_data(
msg.destination(),
msg.initiator(),
CecOpcode::FeatureAbort,
&[CecOpcode::Abort.into(), CecAbortReason::Other.into()],
)?;
}
Some(Ok(CecOpcode::GivePhysicalAddr)) => {
let l = cec.get_log()?;
let mut addr = Vec::with_capacity(3);
if let Some(log) = l.addresses().first() {
addr.extend_from_slice(&physical_addr.to_bytes());
addr.push((*log).into());
cec.transmit_data(
msg.destination(),
msg.initiator(),
CecOpcode::ReportPhysicalAddr,
&addr,
)?;
} //else no address yet?!?!?
}
Some(Ok(CecOpcode::GiveOsdName)) => {
cec.transmit_data(
msg.destination(),
msg.initiator(),
CecOpcode::SetOsdName,
b"pi4",
)?;
}
Some(Ok(CecOpcode::GiveDevicePowerStatus)) => {
cec.transmit_data(
msg.destination(),
msg.initiator(),
CecOpcode::ReportPowerStatus,
&[CecPowerStatus::On.into()],
)?;
}
Some(Ok(CecOpcode::GiveFeatures)) => {}
Some(Ok(opcode)) => {
println!(
"{:?} -> {:?} : {:?} {:x?}",
msg.initiator(),
msg.destination(),
opcode,
msg.parameters()
);
}
_ => {
println!("{:?}", msg);
}
}
}
}
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?
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
fn main() -> std::io::Result<()> {
let cec = CecDevice::open("/dev/cec0")?;
let capas = cec.get_capas();
println!("capas {:?}", capas);
cec.set_mode(CecModeInitiator::None, CecModeFollower::Monitor)?;
loop {
let f = cec.poll(
PollFlags::POLLIN | PollFlags::POLLRDNORM | PollFlags::POLLPRI,
PollTimeout::NONE,
)?;
if f.intersects(PollFlags::POLLPRI) {
let evt = cec.get_event()?;
println!("evt {:x?}", evt);
}
if f.contains(PollFlags::POLLIN | PollFlags::POLLRDNORM) {
let msg = cec.rec()?;
if msg.is_ok() {
match (msg.initiator(), msg.destination(), msg.opcode()) {
(i, d, Some(Ok(o))) => {
println!("msg {:?}->{:?} {:?} {:x?}", i, d, o, msg.parameters());
}
_ => println!("msg {:x?}", msg),
}
} else {
println!("msg {:x?}", msg);
}
}
}
}