Expand description
can-iso-tp: a lightweight ISO-TP (ISO 15765-2) transport layer for CAN.
ISO-TP (“ISO Transport Protocol”) defines how to carry larger payloads over classic CAN by segmenting messages into:
- a Single Frame (small payloads),
- a First Frame + multiple Consecutive Frames (larger payloads), and
- Flow Control frames to regulate pacing and batching.
This crate provides:
- A blocking/polling node (
IsoTpNode) built on split CAN Tx/Rx halves fromembedded-can-interface. - An async node (
IsoTpAsyncNode) for async runtimes viaAsyncRuntime. - Small supporting building blocks (
rx,tx,pdu, config and addressing helpers).
The public API is designed to be usable in no_std environments. Allocation is optional (see
feature flags). Regardless of allocator availability, receive-side reassembly requires an
explicit caller-provided buffer (borrowed or owned).
§Feature flags
std(default): enables allocation support and exportsStdClock.alloc: enables allocation support without the Rust standard library (e.g. to useRxStorage::Owned).uds: enables 29-bit UDS “normal fixed” addressing helpers (can-uds) and multi-peer demultiplexers ([IsoTpDemux], [IsoTpAsyncDemux]) that providereply_tometadata.
§Concepts
- Addressing: ISO-TP supports “normal” addressing (just CAN IDs), and extended/mixed modes
where an additional addressing byte is inserted before the PCI. This crate models that via
IsoTpConfig::tx_addr/IsoTpConfig::rx_addrand helpers inaddress. - PCI offset: when an addressing byte is present, the Protocol Control Information starts at
byte 1 rather than byte 0. Helpers like
IsoTpConfig::tx_pci_offsetandpdu::decode_with_offsetkeep the encoding/decoding logic consistent. - Progress: the non-blocking API uses
Progressto indicate whether a step completed, needs more work, or would block.
§Quick start
The IsoTpNode API is structured as:
- polling: repeatedly call
IsoTpNode::poll_send/IsoTpNode::poll_recv, or - blocking: call
IsoTpNode::send/IsoTpNode::recv, which spin internally until done or timeout.
This crate does not ship a concrete CAN driver. For tests and examples, the workspace includes
embedded-can-mock which implements embedded-can-interface.
ⓘ
use core::time::Duration;
use can_iso_tp::{IsoTpConfig, IsoTpNode, Progress, StdClock};
use embedded_can_interface::SplitTxRx;
let (tx, rx) = driver.split();
let mut rx_buf = [0u8; 4095];
let mut node = IsoTpNode::with_clock(tx, rx, cfg, StdClock, &mut rx_buf).unwrap();
// Send (blocking)
node.send(b"hello", Duration::from_millis(100))?;
// Receive (polling)
let mut out = Vec::new();
loop {
// In a superloop, you typically pass your current time here.
let clock = StdClock;
let now = clock.now();
match node.poll_recv(now, &mut |data| out = data.to_vec())? {
Progress::Completed => break,
Progress::InFlight | Progress::WaitingForFlowControl | Progress::WouldBlock => continue,
}
}Re-exports§
pub use address::AsymmetricAddress;pub use address::IsoTpAddress;pub use address::RxAddress;pub use address::TargetAddressType;pub use address::TxAddress;pub use async_io::AsyncRuntime;pub use async_io::TimedOut;pub use async_node::IsoTpAsyncNode;pub use config::IsoTpConfig;pub use errors::IsoTpError;pub use errors::TimeoutKind;pub use rx::RxStorage;pub use timer::Clock;pub use timer::StdClock;pub use tx::Progress;
Modules§
- address
- Helpers for ISO-TP addressing modes.
- async_
io - Async helpers for integrating ISO-TP with runtimes (tokio, embassy, …).
- async_
node - Async ISO-TP node implementation.
- config
- ISO-TP configuration container.
- errors
- Transport-layer error types.
- pdu
- Encode and decode ISO-TP protocol control information.
- rx
- Receive-side reassembly and flow-control decisions.
- timer
- Clock abstraction to support
stdandno_stdenvironments. - tx
- Transmit-side progress tracking for ISO-TP.
Structs§
- IsoTp
Node - ISO-TP endpoint backed by split transmit/receive halves and a clock.
- IsoTp
Node Builder - Builder for
IsoTpNodethat enforces providing RX storage before construction. - IsoTp
Node Builder With Rx - Builder state after RX storage has been provided.
- RxFlow
Control - Receive-side ISO-TP flow-control parameters (BS/STmin).
Traits§
- CanFrame
- Re-export of the CAN frame trait. A CAN2.0 Frame
Type Aliases§
- CanId
- Alias for CAN identifier.