Skip to main content

Received

Struct Received 

Source
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: u16

The frame’s COB-ID (11-bit standard identifier).

Implementations§

Source§

impl Received

Source

pub fn data(&self) -> &[u8]

The received bytes, trimmed to the frame’s data length.

Source

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§

Source§

impl Clone for Received

Source§

fn clone(&self) -> Received

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Received

Source§

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

Formats the value using the given formatter. Read more

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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
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.