From 0dbbdd9b594269fdb66c834146011df48678a901 Mon Sep 17 00:00:00 2001 From: Sam Anthony Date: Sat, 1 Nov 2025 17:36:26 -0400 Subject: extract big-endian signals from frames --- fw/signal.h | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 fw/signal.h (limited to 'fw/signal.h') diff --git a/fw/signal.h b/fw/signal.h new file mode 100644 index 0000000..8bbc120 --- /dev/null +++ b/fw/signal.h @@ -0,0 +1,33 @@ +/** DBC Signals. + * See "DBC File Format Documentation" v.01/2007 + * + * Device PIC16F1459 + * Compiler: XC8 v3.00 + * + * Usage: + * + * #include + * #include + * #include "types.h" + * #include "can.h" + * #include "signal.h" + */ + +// Byte order +typedef enum { + LITTLE_ENDIAN = 0, + BIG_ENDIAN, +} ByteOrder; + +// A Signal Format defines how a DBC signal is encoded in a CAN frame. +typedef struct { + CanId id; // ID of message containing the signal + U8 start; // start bit -- position of signal within DATA FIELD + U8 size; // size of the signal in bits + ByteOrder order; // little-endian/big-endian + bool isSigned; +} SigFmt; + +// Extract the raw signal value out of a CAN frame's DATA FIELD. +// Assumes the frame's ID matches that of the signal. +Status sigPluck(const SigFmt *sig, const CanFrame *frame, Number *raw); -- cgit v1.2.3