pub struct Received {
pub cob_id: u16,
/* private fields */
}Expand description
A CANopen frame received from the bus: its COB-ID and up to eight bytes.
Fields§
§cob_id: u16The frame’s COB-ID (11-bit standard identifier).
Implementations§
Source§impl Received
impl Received
Sourcepub fn payload(&self) -> &[u8; 8]
pub fn payload(&self) -> &[u8; 8]
The full eight-byte payload, zero-padded — convenient for the
fixed-size SDO codecs, which expect a &[u8; 8].
Examples found in repository?
examples/vcan_loopback.rs (line 103)
83 fn serve(node: NodeId, ready: mpsc::Sender<()>) -> Result<(), Box<dyn Error>> {
84 let bus = SocketCan::open(IFACE)?;
85 bus.set_read_timeout(Duration::from_secs(3))?;
86
87 let mut od = ObjectDictionary::<8>::new();
88 od.insert(
89 Address::new(0x1000, 0),
90 Entry::constant(Value::Unsigned32(0x0004_0192)),
91 )?;
92 od.insert(Address::new(0x1017, 0), Entry::rw(Value::Unsigned16(1000)))?;
93 od.insert(Address::new(0x2000, 0), Entry::rw(Value::Unsigned64(0)))?;
94
95 let mut server = SdoServer::new(node);
96 ready.send(()).map_err(|_| "client went away")?;
97
98 // Serve until a read times out (the client is done and the bus is idle).
99 while let Ok(frame) = bus.recv() {
100 if frame.cob_id != server.request_cob_id() {
101 continue;
102 }
103 if let Some(response) = server.handle(&mut od, frame.payload()) {
104 bus.send(server.response_cob_id(), &response)?;
105 }
106 }
107 Ok(())
108 }Trait Implementations§
Auto Trait Implementations§
impl Freeze for Received
impl RefUnwindSafe for Received
impl Send for Received
impl Sync for Received
impl Unpin for Received
impl UnsafeUnpin for Received
impl UnwindSafe for Received
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more