aboutsummaryrefslogtreecommitdiffstats
path: root/fw/signal.h
diff options
context:
space:
mode:
authorSam Anthony <sam@samanthony.xyz>2025-11-01 17:36:26 -0400
committerSam Anthony <sam@samanthony.xyz>2025-11-01 17:36:26 -0400
commit0dbbdd9b594269fdb66c834146011df48678a901 (patch)
tree91e3969691926868ad8a41d7d907720e4d4ab276 /fw/signal.h
parentd0ceeb4e2ad98c2f5698d78513143a39c6f36b95 (diff)
downloadcan-gauge-interface-0dbbdd9b594269fdb66c834146011df48678a901.zip
extract big-endian signals from frames
Diffstat (limited to 'fw/signal.h')
-rw-r--r--fw/signal.h33
1 files changed, 33 insertions, 0 deletions
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 <stdbool.h>
+ * #include <stdint.h>
+ * #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);