Skip to main content

Module bits

Module bits 

Source
Expand description

Signal bit coding — the two bit-numbering systems of the DBC format.

DBC files number bits within the payload per byte, LSB-first: bit b lives in byte b / 8 at in-byte mask 1 << (b % 8). That numbering is the same for both byte orders; what differs is which bit start_bit names and the direction of travel:

§Intel (little-endian, @1)

start_bit names the least significant bit of the signal; the value is spread over the following bit_length bits, ascending, straight through byte boundaries — a plain LSB-first linear field.

§Motorola (big-endian, @0)

start_bit names the most significant bit of the signal, in the classic “sawtooth” numbering: extraction descends within each byte (MSB → LSB), then jumps from bit 0 of one byte to bit 7 of the next (+15 in DBC numbering — the sawtooth). This reproduces exactly what Vector CANdb++, cantools, and the socketcan-cib tools do for @0 signals, including the famous layouts that straddle three bytes.

Bits falling outside the buffer read as 0 on extraction (extract_raw is total); insertion reports the bytes it needs (max_bit_position → crate::DbcError::BufferTooShort).

Functions§

extract_raw
Extracts bit_length raw bits laid out per byte_order, MSB-aligned into the low bits of the result.
insert_raw
Inserts value’s low bit_length bits per byte_order, the exact inverse of extract_raw.
max_bit_position
The highest DBC bit number the signal layout touches.
sign_extend
Sign-extends raw (the low bit_length bits) to i64 two’s complement.