Skip to main content

Node

Struct Node 

Source
pub struct Node<const N: usize> { /* private fields */ }
Expand description

A CANopen device node: an object dictionary served over SDO, with NMT state, heartbeat/boot-up production, and PDO exchange.

Implementations§

Source§

impl<const N: usize> Node<N>

Source

pub fn new(node_id: NodeId, od: ObjectDictionary<N>) -> Self

Create a node with node_id serving od. It starts in NmtState::Initialising; call Node::boot to go operational-ready.

Source

pub fn enable_lss(&mut self, address: LssAddress)

Enable LSS with this node’s 128-bit identity (LssAddress, object 0x1018). The node then answers LSS master requests on 0x7E5, letting a master (re)assign its node-id over the bus.

A node awaiting an LSS-assigned id should be left in NmtState::Initialising (do not call Node::boot) so it serves only LSS; after the id is assigned, call Node::apply_lss_node_id then boot.

Source

pub fn set_node_id(&mut self, node_id: NodeId)

Change the node-id, rebuilding the SDO server for the new COB-IDs. Call on the reset that follows an LSS reconfiguration.

Source

pub fn apply_lss_node_id(&mut self) -> Option<NodeId>

Adopt a node-id assigned over LSS: if the LSS slave holds a valid pending id, apply it (rebuilding the SDO server) and return it. Call this on the node’s reset after an LSS configuration.

Source

pub fn lss(&self) -> Option<&LssSlave>

The LSS slave, if LSS is enabled (e.g. to read its pending node-id).

Source

pub fn add_rpdo( &mut self, cob_id: u16, mapping: PdoMapping<MAX_PDO_MAPPING>, ) -> Result<()>

Configure a receive PDO: when a frame arrives on cob_id (while operational), its bytes are unpacked into the mapped objects.

Returns Error::MappingFull once MAX_PDOS receive PDOs are set.

Source

pub fn add_tpdo( &mut self, cob_id: u16, mapping: PdoMapping<MAX_PDO_MAPPING>, transmission: TransmissionType, ) -> Result<()>

Configure a transmit PDO: Node::sync_tpdos packs and emits it on SYNC (for synchronous types) and Node::tpdo emits it on demand.

Returns Error::MappingFull once MAX_PDOS transmit PDOs are set.

Source

pub fn configure_pdos_from_od(&mut self)

(Re)build the PDO configuration from the PDO parameter objects in the object dictionary — communication parameters at 0x1400+ (RPDO) / 0x1800+ (TPDO) and mapping parameters at 0x1600+ / 0x1A00+ (CiA 301 §7.5.2). Call this after a master configures PDOs by writing those objects over SDO, so the node picks up the new layout.

Any programmatic PDO configuration is replaced. PDOs whose communication COB-ID has the “invalid” bit set are skipped, as are entries that are absent or malformed.

Source

pub fn take_written_object(&mut self) -> Option<Address>

Take the address of the object a master most recently wrote over SDO, clearing it. Poll after Node::on_frame to react to configuration writes — for example, re-read the PDO layout when a PDO parameter object (0x14000x1BFF) changes:

node.on_frame(cob_id, &data);
if let Some(addr) = node.take_written_object() {
    if (0x1400..=0x1BFF).contains(&addr.index) {
        node.configure_pdos_from_od();
    }
}
Source

pub fn node_id(&self) -> NodeId

This node’s id.

Source

pub fn state(&self) -> NmtState

The current NMT state.

Source

pub fn od(&self) -> &ObjectDictionary<N>

Borrow the object dictionary (e.g. to publish process data).

Source

pub fn od_mut(&mut self) -> &mut ObjectDictionary<N>

Mutably borrow the object dictionary.

Source

pub fn boot(&mut self) -> TxFrame

Finish initialisation: enter pre-operational and return the boot-up frame to transmit (0x700 + node, data 0x00).

Source

pub fn node_guard_response(&mut self) -> TxFrame

The node-guarding response frame (0x700 + node), reporting the current state with an alternating toggle bit. Call this when the master polls the node with an RTR frame on that COB-ID (the legacy error-control alternative to Node::heartbeat).

Source

pub fn heartbeat(&self) -> TxFrame

The heartbeat frame for the current state. Transmit it on your heartbeat timer (the producer heartbeat time lives in object 0x1017).

Source

pub fn on_frame(&mut self, cob_id: u16, data: &[u8]) -> Option<TxFrame>

Process an incoming CAN frame, returning a response to transmit, if any.

Handles NMT node-control (0x000), SDO requests (0x600 + node), LSS master requests (0x7E5, when enabled), and received PDOs. SDO is served only in pre-operational and operational states, and PDOs only in operational, per CiA 301; LSS is served regardless of NMT state. Frames for other COB-IDs are ignored.

Source

pub fn sync_tpdos(&self) -> Vec<TxFrame, MAX_PDOS>

The synchronous transmit PDOs to send in response to a SYNC.

Packs every configured TPDO with a synchronous transmission type from the current object dictionary. Empty unless the node is operational — PDOs are exchanged only in that state (CiA 301 §7.3.5).

Source

pub fn tpdo(&self, index: usize) -> Option<TxFrame>

Emit transmit PDO index on demand (an event-driven transmission), or None if there is no such PDO or the node is not operational.

Trait Implementations§

Source§

impl<const N: usize> Debug for Node<N>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<const N: usize> Freeze for Node<N>

§

impl<const N: usize> RefUnwindSafe for Node<N>

§

impl<const N: usize> Send for Node<N>

§

impl<const N: usize> Sync for Node<N>

§

impl<const N: usize> Unpin for Node<N>

§

impl<const N: usize> UnsafeUnpin for Node<N>

§

impl<const N: usize> UnwindSafe for Node<N>

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