1 #include <canutil/read.h>
2 #include <bitfield/bitfield.h>
3 #include <bitfield/8byte.h>
5 static float decode_float(uint64_t raw, float factor, float offset) {
6 return raw * factor + offset;
9 float eightbyte_parse_float(uint64_t data, uint8_t bit_offset, uint8_t bit_size,
10 float factor, float offset) {
11 return decode_float(eightbyte_get_bitfield(data, bit_offset, bit_size,
12 true), factor, offset);
15 bool eightbyte_parse_bool(uint64_t data, uint8_t bit_offset, uint8_t bit_size,
16 float factor, float offset) {
17 float value = eightbyte_parse_float(data, bit_offset, bit_size, factor, offset);
18 return value == 0.0 ? false : true;
21 float bitfield_parse_float(const uint8_t source[], const uint16_t source_length,
22 const uint8_t bit_offset, const uint8_t bit_size, const float factor,
24 return decode_float(get_bitfield(source, source_length, bit_offset, bit_size),
28 bool bitfield_parse_bool(const uint8_t source[], const uint16_t source_length,
29 const uint8_t bit_offset, const uint8_t bit_size, const float factor,
31 float value = bitfield_parse_float(source, source_length, bit_offset,
32 bit_size, factor, offset);
33 return value == 0.0 ? false : true;