From 32e25cbca210a359b09768537b6f443fe90a3070 Mon Sep 17 00:00:00 2001 From: Romain Forlot Date: Tue, 20 Jun 2017 10:24:05 +0000 Subject: Separation Generator to a dedicated repo Change-Id: Id94831651c3266861435272a6e36c7884bef2c45 Signed-off-by: Romain Forlot --- libs/bitfield-c/src/canutil/read.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 libs/bitfield-c/src/canutil/read.c (limited to 'libs/bitfield-c/src/canutil/read.c') diff --git a/libs/bitfield-c/src/canutil/read.c b/libs/bitfield-c/src/canutil/read.c new file mode 100644 index 00000000..d0cbb71a --- /dev/null +++ b/libs/bitfield-c/src/canutil/read.c @@ -0,0 +1,34 @@ +#include +#include +#include + +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; +} -- cgit 1.2.3-korg