Skip to main content

CanHeader

Enum CanHeader 

Source
#[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 27Bits 26-24Bits 23-12Variant
07, 6, 5, 4Node ID chunkCid
000x700Rid
000x701Amd
000x702Ame
000x703Amr
0otherotherOtherControl (e.g. error information reports)
11CAN-MTIMessage
12-5dest aliasDatagram
17dest aliasStream
10, 6anyReserved
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
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

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

§seq: u8

Sequence number 7, 6, 5 or 4 (bits 26-24).

§node_id_bits: u16

The 12-bit slice of the Node ID this frame carries.

§alias: u16

The alias being requested.

§

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.

Fields

§alias: u16

The alias being reserved or defended.

§

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.

Fields

§alias: u16

The alias being mapped.

§

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.

Fields

§alias: u16

The alias of the node asking.

§

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.

Fields

§alias: u16

The alias being released.

§

OtherControl

Some other control frame (for example the error information report frames), passed through undecoded.

Fields

§seq: u8

Bits 26-24.

§var: u16

Bits 23-12.

§alias: u16

Source alias.

§

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.

Fields

§mti: Mti

The message type (only the low 12 bits travel on CAN).

§alias: u16

Source alias.

§

Datagram

Datagram frame addressed to dest.

Fields

§kind: MessageFrameType

Which part of the datagram this frame is (only the four datagram variants of MessageFrameType are produced by decode).

§dest: u16

Destination alias.

§alias: u16

Source alias.

§

Stream

Stream data frame addressed to dest.

Fields

§dest: u16

Destination alias.

§alias: u16

Source alias.

§

Reserved

Reserved frame type.

Fields

§kind: u8

The frame type, 0 or 6.

§var: u16

Bits 23-12.

§alias: u16

Source alias.

Implementations§

Source§

impl CanHeader

Source

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.

Source

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.

Source

pub fn src_alias(&self) -> u16

The source alias, whatever the frame type.

Trait Implementations§

Source§

impl Clone for CanHeader

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for CanHeader

Source§

impl Debug for CanHeader

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for CanHeader

Source§

impl Hash for CanHeader

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for CanHeader

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for CanHeader

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.