summaryrefslogtreecommitdiffstats
path: root/src/canutil/read.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/canutil/read.c')
-rw-r--r--src/canutil/read.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/canutil/read.c b/src/canutil/read.c
new file mode 100644
index 00000000..6b4e40aa
--- /dev/null
+++ b/src/canutil/read.c
@@ -0,0 +1,14 @@
+#include <bitfield/bitfield.h>
+
+float parseFloat(uint64_t data, uint8_t bitPosition, uint8_t bitSize,
+ float factor, float offset) {
+ uint64_t rawValue = getBitField(data, bitPosition,
+ bitSize, true);
+ return rawValue * factor + offset;
+}
+
+bool parseBoolean(uint64_t data, uint8_t bitPosition, uint8_t bitSize,
+ float factor, float offset) {
+ float value = parseFloat(data, bitPosition, bitSize, factor, offset);
+ return value == 0.0 ? false : true;
+}