Skip to content

SignalCodec

#include <mrx/can/SignalCodec.hpp>
class mrx::can::SignalCodec

Transport-independent DBC signal encoding and decoding.

Bit numbers use DBC’s least-significant-bit numbering within each byte. Motorola traversal decreases within a byte, then moves to the most significant bit of the next byte. Signals must fit in the payload and have lengths from 1 to 64 bits. Raw values are unsigned bit patterns, including for signed signals. Failed operations leave output arguments unchanged. Physical conversion uses double precision and may lose integer precision for wide signals; use the raw methods when exact 64-bit values are required.

ReturnNameDescription
boolreadRaw staticExtracts the raw bit pattern; returns false for an invalid layout.
boolwriteRaw staticInserts a raw bit pattern, preserving other bits; rejects values that do not fit.
booldecode staticDecodes a signed or unsigned raw value as raw * factor + offset.
boolencode staticEncodes a physical value using (physical - offset) / factor.

static
static bool readRaw(const QByteArray& payload, const SignalDescription& signal, quint64& raw)

Extracts the raw bit pattern; returns false for an invalid layout.


static
static bool writeRaw(QByteArray& payload, const SignalDescription& signal, quint64 raw)

Inserts a raw bit pattern, preserving other bits; rejects values that do not fit.


static
static bool decode(const QByteArray& payload, const SignalDescription& signal, double& physical)

Decodes a signed or unsigned raw value as raw * factor + offset.

False for an invalid layout, non-finite conversion, or non-finite factor or offset.


static
static bool encode(QByteArray& payload, const SignalDescription& signal, double physical)

Encodes a physical value using (physical - offset) / factor.

The result is rounded to nearest integer, with ties away from zero. Returns false for non-finite values, zero factor, invalid layouts, or results outside the signed or unsigned signal range. No bits change on failure.