# Pure Python 3 CAN decoder for a 8-byte payload.
FRAME_LEN = 8
def dbc_1_data_bytes_physical(data: bytes) -> float:
if len(data) < 8:
raise ValueError("Expected at least 8 payload bytes")
raw = (int.from_bytes(data[:8], "big") >> 56) & 0xFF
return raw * (1.0) + (0.0)
def dbc_2_engine_rpm_physical(data: bytes) -> float:
if len(data) < 8:
raise ValueError("Expected at least 8 payload bytes")
raw = (int.from_bytes(data[:8], "big") >> 24) & 0xFFFF
return raw * (0.25) + (0.0)
def dbc_3_coolant_temp_physical(data: bytes) -> float:
if len(data) < 8:
raise ValueError("Expected at least 8 payload bytes")
raw = (int.from_bytes(data[:8], "big") >> 16) & 0xFF
return raw * (1.0) + (-40.0)
def dbc_4_vehicle_speed_physical(data: bytes) -> float:
if len(data) < 8:
raise ValueError("Expected at least 8 payload bytes")
raw = (int.from_bytes(data[:8], "big") >> 8) & 0xFF
return raw * (1.0) + (0.0)
def decode_frame(data: bytes) -> dict[str, float]:
return {
"dbc_1_data_bytes": dbc_1_data_bytes_physical(data),
"dbc_2_engine_rpm": dbc_2_engine_rpm_physical(data),
"dbc_3_coolant_temp": dbc_3_coolant_temp_physical(data),
"dbc_4_vehicle_speed": dbc_4_vehicle_speed_physical(data),
}
Map OBD-II Mode 01 response bytes in standard Motorola big-endian order
ISO 15765-4 passenger vehicle diagnostics and EV drivetrain CAN gateways pack multi-byte values in big-endian (Motorola MSB-first) order. Using Motorola start bits (7 for byte 0, 31 for byte 3, 47 for byte 5) keeps firmware unpackers synchronized across bit-packed sensor fields.
Click any bit cell in the 64-bit interactive grid to trace how big-endian bit masks walk downward inside each byte before jumping upward across byte boundaries, then copy the self-contained C99 inline helpers.
Formulas
OBD-II RPM = ((256 × A) + B) ÷ 4 → 0x1F40 (8,000) × 0.25 = 2,000 rpm
Coolant temperature = byte − 40 → 0x82 (130) − 40 = 90 °C
Payload 04 41 0C 1F 40 82 50 32 extracts 4 PCI data bytes, 2,000 rpm engine speed (0x1F40 × 0.25), 90 °C coolant temperature (130 − 40) and 80 km/h vehicle speed.
Frequently asked questions
Why does a Motorola 16-bit signal at byte 3 use start bit 31 instead of 24?
Vector DBC Motorola convention indexes from the most significant bit of the starting byte (3 × 8 + 7 = 31) and walks downward to byte 4 bit 32.
Can I add EV battery state-of-health or UDS response bytes to the same grid?
Yes. Add rows in the DBC signals table or extend the hex payload to 16 bytes for CAN FD diagnostic responses.
Do the C99 extractors avoid unaligned pointer casts?
Yes. The generated DBC_BIT macro reads individual bytes from a uint8_t buffer so it stays portable and strict-aliasing safe on Cortex-M and RISC-V MCUs.