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>
impl<const N: usize> Node<N>
Sourcepub fn new(node_id: NodeId, od: ObjectDictionary<N>) -> Self
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.
Sourcepub fn enable_lss(&mut self, address: LssAddress)
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.
Sourcepub fn set_node_id(&mut self, node_id: NodeId)
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.
Sourcepub fn apply_lss_node_id(&mut self) -> Option<NodeId>
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.
Sourcepub fn lss(&self) -> Option<&LssSlave>
pub fn lss(&self) -> Option<&LssSlave>
The LSS slave, if LSS is enabled (e.g. to read its pending node-id).
Sourcepub fn add_rpdo(
&mut self,
cob_id: u16,
mapping: PdoMapping<MAX_PDO_MAPPING>,
) -> Result<()>
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.
Sourcepub fn add_tpdo(
&mut self,
cob_id: u16,
mapping: PdoMapping<MAX_PDO_MAPPING>,
transmission: TransmissionType,
) -> Result<()>
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.
Sourcepub fn configure_pdos_from_od(&mut self)
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.
Sourcepub fn take_written_object(&mut self) -> Option<Address>
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
(0x1400–0x1BFF) 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();
}
}Sourcepub fn od(&self) -> &ObjectDictionary<N>
pub fn od(&self) -> &ObjectDictionary<N>
Borrow the object dictionary (e.g. to publish process data).
Sourcepub fn od_mut(&mut self) -> &mut ObjectDictionary<N>
pub fn od_mut(&mut self) -> &mut ObjectDictionary<N>
Mutably borrow the object dictionary.
Sourcepub fn boot(&mut self) -> TxFrame
pub fn boot(&mut self) -> TxFrame
Finish initialisation: enter pre-operational and return the boot-up
frame to transmit (0x700 + node, data 0x00).
Sourcepub fn node_guard_response(&mut self) -> TxFrame
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).
Sourcepub fn heartbeat(&self) -> TxFrame
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).
Sourcepub fn on_frame(&mut self, cob_id: u16, data: &[u8]) -> Option<TxFrame>
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.
Sourcepub fn sync_tpdos(&self) -> Vec<TxFrame, MAX_PDOS>
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).