Skip to main content

Crate can_iso_tp

Crate can_iso_tp 

Source
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 from embedded-can-interface.
  • An async node (IsoTpAsyncNode) for async runtimes via AsyncRuntime.
  • 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 exports StdClock.
  • alloc: enables allocation support without the Rust standard library (e.g. to use RxStorage::Owned).
  • uds: enables 29-bit UDS “normal fixed” addressing helpers (can-uds) and multi-peer demultiplexers ([IsoTpDemux], [IsoTpAsyncDemux]) that provide reply_to metadata.

§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_addr and helpers in address.
  • 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_offset and pdu::decode_with_offset keep the encoding/decoding logic consistent.
  • Progress: the non-blocking API uses Progress to indicate whether a step completed, needs more work, or would block.

§Quick start

The IsoTpNode API is structured as:

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 std and no_std environments.
tx
Transmit-side progress tracking for ISO-TP.

Structs§

IsoTpNode
ISO-TP endpoint backed by split transmit/receive halves and a clock.
IsoTpNodeBuilder
Builder for IsoTpNode that enforces providing RX storage before construction.
IsoTpNodeBuilderWithRx
Builder state after RX storage has been provided.
RxFlowControl
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.