Expand description
§canopen-rs
A no_std-first CANopen (CiA 301) protocol stack in Rust.
This core crate is transport-agnostic and allocation-free: it models the
object dictionary, encodes/decodes SDO and PDO messages, and drives the
NMT state machine. It is designed to run unchanged on a bare-metal MCU
node and on a host (Linux/SocketCAN) via the companion canopen-host
crate.
CAN frames are represented through the embedded_can traits, so any
controller or socket that implements them can carry CANopen traffic.
§Example: an SDO read, transport-free
A device exposes an ObjectDictionary; a client reads it
from a server one frame at a time — no bus required, so the
same logic runs on a host or an MCU.
use canopen_rs::sdo::{SdoClient, SdoEvent, SdoServer};
use canopen_rs::{Address, DataType, Entry, NodeId, ObjectDictionary, Value};
let node = NodeId::new(0x10).unwrap();
// The device's object dictionary, served by an SDO server.
let mut od = ObjectDictionary::<8>::new();
od.insert(Address::new(0x1000, 0), Entry::constant(Value::Unsigned32(0x1234))).unwrap();
let mut server = SdoServer::new(node);
// The client drives the transaction; expedited vs segmented is automatic.
let mut client = SdoClient::new(node);
let mut frame = client.read(Address::new(0x1000, 0), DataType::Unsigned32);
let value = loop {
let response = server.handle(&mut od, &frame).expect("server replies");
match client.on_response(&response) {
SdoEvent::Send(next) => frame = next,
SdoEvent::Complete(v) => break v.unwrap(),
SdoEvent::Aborted(code) => panic!("aborted {code:#010x}"),
}
};
assert_eq!(value, Value::Unsigned32(0x1234));§Status
Early development. The API will change. See the roadmap in the workspace
README.md.
Re-exports§
pub use datatypes::DataType;pub use datatypes::Value;pub use emcy::EmergencyMessage;pub use emcy::ErrorRegister;pub use lss::LssAddress;pub use lss::LssSlave;pub use lss::LssState;pub use nmt::NmtCommand;pub use nmt::NmtState;pub use nmt::NmtStateMachine;pub use node::Node;pub use node::TxFrame;pub use object_dictionary::AccessType;pub use object_dictionary::Address;pub use object_dictionary::Entry;pub use object_dictionary::ObjectDictionary;pub use pdo::MappingEntry;pub use pdo::PdoKind;pub use pdo::PdoMapping;pub use pdo::TransmissionType;pub use sdo::SdoClient;pub use sdo::SdoEvent;pub use sdo::SdoServer;pub use sdo::Segment;pub use sdo::SegmentReader;pub use sdo::SegmentWriter;pub use sync::SyncCounter;pub use time::TimeOfDay;pub use types::Error;pub use types::NodeId;pub use types::Result;
Modules§
- datatypes
- CANopen basic data types and their little-endian value encoding.
- emcy
- Emergency object (EMCY) — device error signalling (CiA 301 §7.2.7).
- lss
- Layer Setting Services (LSS, CiA 305) — configure a node’s node-id and bit timing over the bus.
- nmt
- Network Management (NMT) — the node state machine (CiA 301 §7.3).
- node
- A CANopen device node — object dictionary + SDO server + NMT state in one frame-driven type.
- object_
dictionary - The CANopen object dictionary (OD) model.
- pdo
- Process Data Object (PDO) — real-time process data (CiA 301 §7.2.2).
- sdo
- Service Data Object (SDO) protocol (CiA 301 §7.2.4).
- sync
- Synchronisation object (SYNC) — the network heartbeat for synchronous communication (CiA 301 §7.2.5).
- time
- Time stamp object (TIME) — the network time-of-day (CiA 301 §7.2.6).
- transport
- Bridging CANopen frames to the
embedded_cantraits. - types
- Foundational CANopen types shared across the stack.