Expand description
GridConnect ASCII framing: :X19490ABCN0102030405060708;
Used by most LCC USB adapters (RR-CirKits Buffer-USB, TCS, SPROG CANISB) and by GridConnect-over-TCP hubs such as JMRI (port 12021).
GridConnect is a simple ASCII encoding of one CAN frame per token:
:X19490ABCN0102030405060708;
│└──┬───┘│└──────┬───────┘└ terminator
│ │ │ └ 0-8 data bytes as hex pairs
│ │ └ 'N' = normal frame ('R' = remote request, accepted when parsing)
│ └ 29-bit identifier, 1-8 hex digits
└ 'X' = extended frame ('S' = standard 11-bit, not used by OpenLCB)Frames are usually separated by newlines, but any whitespace (or none)
is allowed. The same text is used over USB serial adapters and raw TCP (the
JMRI/OpenLCB “GridConnect over TCP” hub protocol, also spoken by this
crate’s hub module, feature hub).
format()turns aCanFrameinto text (uppercase hex, no newline);write()does the same into anycore::fmt::Writewithout allocating.CanFrame’sDisplayimpl uses it too.parse()reads one complete token, leniently (case-insensitive, surrounding whitespace ignored).CanFrame’sFromStrimpl calls it.Decodersplits an arbitrary byte stream into frames, handling tokens that are split across reads.
use rolcb::gridconnect;
let f = gridconnect::parse(":X19490ABCN0102;")?;
assert_eq!(f.id, 0x1949_0ABC);
assert_eq!(f.data(), &[1, 2]);
assert_eq!(gridconnect::format(&f), ":X19490ABCN0102;");Structs§
- Decoder
- Incremental decoder for a GridConnect byte stream (serial port, TCP socket,
or any other byte transport). Frames may be split arbitrarily across
pushcalls and may be separated by any whitespace (or nothing at all).
Functions§
- format
- Format a frame as a GridConnect string (without a trailing newline).
- parse
- Parse a single GridConnect frame. Leading/trailing whitespace is ignored.
Only extended (
X) frames are meaningful for OpenLCB; standard (S) frames are rejected. - write
- Write a frame as GridConnect text into
out, without allocating.