summaryrefslogtreecommitdiffstats
path: root/CAN-binder/libs/bitfield-c/src/canutil/read.c
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2017-05-02 17:50:50 +0200
committerRomain Forlot <romain.forlot@iot.bzh>2017-05-02 17:50:50 +0200
commitd170c9faeae2cf29c19f3523714ecdf58be73bed (patch)
tree114b0f8bc52df642567a7450cfbee2dbfce117d8 /CAN-binder/libs/bitfield-c/src/canutil/read.c
parentb6c09cbda2b6b47981d65265184a21223e526d4a (diff)
parenta34745ec93ae0a1d4f1b640dba8fb6702331a8e9 (diff)
Add 'CAN-binder/libs/bitfield-c/' from commit 'a34745ec93ae0a1d4f1b640dba8fb6702331a8e9'
git-subtree-dir: CAN-binder/libs/bitfield-c git-subtree-mainline: b6c09cbda2b6b47981d65265184a21223e526d4a git-subtree-split: a34745ec93ae0a1d4f1b640dba8fb6702331a8e9
Diffstat (limited to 'CAN-binder/libs/bitfield-c/src/canutil/read.c')
-rw-r--r--CAN-binder/libs/bitfield-c/src/canutil/read.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/CAN-binder/libs/bitfield-c/src/canutil/read.c b/CAN-binder/libs/bitfield-c/src/canutil/read.c
new file mode 100644
index 00000000..d0cbb71a
--- /dev/null
+++ b/CAN-binder/libs/bitfield-c/src/canutil/read.c
@@ -0,0 +1,34 @@
+#include <canutil/read.h>
+#include <bitfield/bitfield.h>
+#include <bitfield/8byte.h>
+
+static float decode_float(uint64_t raw, float factor, float offset) {
+ return raw * factor + offset;
+}
+
+float eightbyte_parse_float(uint64_t data, uint8_t bit_offset, uint8_t bit_size,
+ float factor, float offset) {
+ return decode_float(eightbyte_get_bitfield(data, bit_offset, bit_size,
+ true), factor, offset);
+}
+
+bool eightbyte_parse_bool(uint64_t data, uint8_t bit_offset, uint8_t bit_size,
+ float factor, float offset) {
+ float value = eightbyte_parse_float(data, bit_offset, bit_size, factor, offset);
+ return value == 0.0 ? false : true;
+}
+
+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) {
+ return decode_float(get_bitfield(source, source_length, bit_offset, bit_size),
+ factor, offset);
+}
+
+bool 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;
+}