Remove old hipchat token from Travis CI config.
[apps/agl-service-can-low-level.git] / src / canutil / read.c
1 #include <canutil/read.h>
2 #include <bitfield/bitfield.h>
3 #include <bitfield/8byte.h>
4
5 static float decode_float(uint64_t raw, float factor, float offset) {
6     return raw * factor + offset;
7 }
8
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);
13 }
14
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;
19 }
20
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,
23         const float offset) {
24     return decode_float(get_bitfield(source, source_length, bit_offset, bit_size),
25             factor, offset);
26 }
27
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,
30         const float offset) {
31     float value = bitfield_parse_float(source, source_length, bit_offset,
32             bit_size, factor, offset);
33     return value == 0.0 ? false : true;
34 }