diff options
author | Christopher Peplin <chris.peplin@rhubarbtech.com> | 2013-12-24 10:56:35 -0500 |
---|---|---|
committer | Christopher Peplin <chris.peplin@rhubarbtech.com> | 2013-12-24 10:56:35 -0500 |
commit | bc1baf25a0844861713829c0e9e69e4a2d447cc6 (patch) | |
tree | 37ad821656ffa979248f6154573f5cd9f30932a3 /src/canutil/read.c |
Initial commit, pulled from openxc/vi-firmware.
Diffstat (limited to 'src/canutil/read.c')
-rw-r--r-- | src/canutil/read.c | 14 |
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; +} |