#[non_exhaustive]pub enum CanHeader {
Cid {
seq: u8,
node_id_bits: u16,
alias: u16,
},
Rid {
alias: u16,
},
Amd {
alias: u16,
},
Ame {
alias: u16,
},
Amr {
alias: u16,
},
OtherControl {
seq: u8,
var: u16,
alias: u16,
},
Message {
mti: Mti,
alias: u16,
},
Datagram {
kind: MessageFrameType,
dest: u16,
alias: u16,
},
Stream {
dest: u16,
alias: u16,
},
Reserved {
kind: u8,
var: u16,
alias: u16,
},
}Expand description
A decoded CAN identifier.
CanHeader::decode interprets any 29-bit identifier and
CanHeader::encode builds one; encode(decode(id)) == id for every
identifier with bit 28 set. Every variant carries the source alias
(bits 11-0), available uniformly through CanHeader::src_alias.
| Bit 27 | Bits 26-24 | Bits 23-12 | Variant |
|---|---|---|---|
| 0 | 7, 6, 5, 4 | Node ID chunk | Cid |
| 0 | 0 | 0x700 | Rid |
| 0 | 0 | 0x701 | Amd |
| 0 | 0 | 0x702 | Ame |
| 0 | 0 | 0x703 | Amr |
| 0 | other | other | OtherControl (e.g. error information reports) |
| 1 | 1 | CAN-MTI | Message |
| 1 | 2-5 | dest alias | Datagram |
| 1 | 7 | dest alias | Stream |
| 1 | 0, 6 | any | Reserved |
use rolcb::can::CanHeader;
use rolcb::Mti;
let h = CanHeader::Message { mti: Mti::PCER, alias: 0x123 };
assert_eq!(h.encode(), 0x195B_4123);
assert_eq!(CanHeader::decode(0x195B_4123), h);
assert_eq!(CanHeader::Rid { alias: 0x285 }.encode(), 0x1070_0285);The enum is #[non_exhaustive]: match it with a _ arm.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Cid
Check ID frame. seq is 7..=4; node_id_bits is the 12-bit chunk of
the Node ID being reserved (7 = bits 47-36 … 4 = bits 11-0).
The first step of alias reservation. A node sends CID7, CID6, CID5,
CID4 with its candidate alias, then waits 200 ms for objections. A
node that already owns the alias answers with CanHeader::Rid.
Build the whole set with cid_frames.
Fields
Rid
Reserve ID. Sent after the 200 ms CID wait to claim the alias, and by an alias owner to object to someone else’s CID for its alias.
Amd
Alias Map Definition. Data is the 6-byte Node ID. Announces “this
alias now belongs to this Node ID”; the node becomes permitted to
send messages. Also the reply to CanHeader::Ame.
Ame
Alias Mapping Enquiry. With empty data, every permitted node replies with its AMD; with a 6-byte Node ID, only that node replies. Used by gateways and tools to rebuild their alias tables.
Amr
Alias Map Reset. Data is the 6-byte Node ID. The sender is giving up this alias (for example after a collision); others must forget the mapping and any partial multi-frame messages from it.
OtherControl
Some other control frame (for example the error information report frames), passed through undecoded.
Message
Global or addressed OpenLCB message.
For addressed MTIs the destination alias is not in the header but
in the first two data bytes; see
Message::to_frames.
Datagram
Datagram frame addressed to dest.
Fields
kind: MessageFrameTypeWhich part of the datagram this frame is (only the four datagram
variants of MessageFrameType are produced by decode).
Stream
Stream data frame addressed to dest.
Reserved
Reserved frame type.
Implementations§
Source§impl CanHeader
impl CanHeader
Sourcepub fn decode(id: u32) -> CanHeader
pub fn decode(id: u32) -> CanHeader
Interpret a 29-bit identifier. Never fails: unrecognised values map to
OtherControl or
Reserved. Bit 28 is not checked.
Sourcepub fn encode(&self) -> u32
pub fn encode(&self) -> u32
Build the 29-bit identifier (with the reserved bit 28 set).
A Datagram whose kind is not one of the
four datagram variants is encoded as DatagramOnly. Every field is
masked to its width (3 bits for seq/kind, 12 bits for aliases and
the variable field), so an out-of-range value can never spill into a
neighbouring field.