Skip to main content

irbt_proto/
lib.rs

1//! Wire protocol between the ir-bt-bridge firmware and the `irbt` host tools.
2//!
3//! Every message is a [`Frame`], serialized with `postcard`, followed by a
4//! CRC-16, COBS-encoded and delimited by `0x00` bytes on both sides:
5//!
6//! ```text
7//! 0x00 | COBS( postcard(frame) ‖ crc16_le ) | 0x00
8//! ```
9//!
10//! COBS guarantees the encoded body never contains `0x00`, so the delimiter is
11//! unambiguous and a receiver can resynchronize at the next `0x00` after
12//! garbage. Bytes that don't form a valid frame (ROM bootloader text, panic
13//! dumps) are surfaced by [`Decoder`] as [`Decoded::Raw`] instead of being lost.
14//!
15//! **postcard is not self-describing: enum variant order is wire ABI.** Only
16//! ever append variants/fields at the end, and bump [`PROTOCOL_VERSION`] for
17//! anything that changes existing encodings. `tests::golden_*` pin the bytes.
18
19#![no_std]
20
21extern crate alloc;
22
23mod codec;
24mod messages;
25
26pub use codec::{encode, Decoded, Decoder, EncodeError, MAX_FRAME_LEN};
27pub use messages::*;
28
29/// Bumped on any change that alters the encoding of existing messages.
30///
31/// - 2: [`Status::battery`].
32pub const PROTOCOL_VERSION: u16 = 2;