summaryrefslogtreecommitdiffstats
path: root/src/canutil/read.c
diff options
context:
space:
mode:
authorChristopher Peplin <chris.peplin@rhubarbtech.com>2014-01-04 10:51:16 -0500
committerChristopher Peplin <chris.peplin@rhubarbtech.com>2014-01-04 10:52:42 -0500
commit08db5c9eb826f7aa0dba36cbef8011d7bc6b55a5 (patch)
treeb2875552387f00191c772bc6da08dcaa7e6d2e87 /src/canutil/read.c
parent6f3a81ed8287357b54aad16bff27495c6eaca6df (diff)
Add a get_bitfield function for byte arrays.
Diffstat (limited to 'src/canutil/read.c')
-rw-r--r--src/canutil/read.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/src/canutil/read.c b/src/canutil/read.c
index 4864a60f..3931721a 100644
--- a/src/canutil/read.c
+++ b/src/canutil/read.c
@@ -4,7 +4,7 @@
float eightbyte_parse_float(uint64_t data, uint8_t bit_offset, uint8_t bit_size,
float factor, float offset) {
- uint64_t raw = eightbyte_get_bit_field(data, bit_offset, bit_size, true);
+ uint64_t raw = eightbyte_get_bitfield(data, bit_offset, bit_size, true);
return raw * factor + offset;
}
@@ -14,9 +14,19 @@ bool eightbyte_parse_bool(uint64_t data, uint8_t bit_offset, uint8_t bit_size,
return value == 0.0 ? false : true;
}
-float bitfield_parse_float(const uint8_t data[], const uint16_t size,
+float bitfield_parse_float(const uint8_t source[], const uint16_t source_length,
const uint8_t bit_offset, const uint8_t bit_size, const float factor,
const float offset) {
- //TODO
- return 0;
+ uint64_t raw = get_bitfield(source, source_length, bit_offset, bit_size);
+ // TODO seems dumb that this is repeated from eightbyte_parse_float - is it
+ // really worth keeping around these two implementations?
+ return raw * factor + offset;
+}
+
+float bitfield_parse_bool(const uint8_t source[], const uint16_t source_length,
+ const uint8_t bit_offset, const uint8_t bit_size, const float factor,
+ const float offset) {
+ float value = bitfield_parse_float(source, source_length, bit_offset,
+ bit_size, factor, offset);
+ return value == 0.0 ? false : true;
}