summaryrefslogtreecommitdiffstats
path: root/src/canutil/read.c
blob: 5e882c3d0679de71168cd95c8f522f1a04df2c1b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <bitfield/bitfield.h>

float bitfield_parse_float(uint64_t data, uint8_t bit_offset, uint8_t bit_size,
        float factor, float offset) {
    uint64_t raw = get_bit_field(data, bit_offset,
            bit_size, true);
    return raw * factor + offset;
}

bool bitfield_parse_bool(uint64_t data, uint8_t bit_offset, uint8_t bit_size,
        float factor, float offset) {
    float value = bitfield_parse_float(data, bit_offset, bit_size, factor, offset);
    return value == 0.0 ? false : true;
}