1 #include <canutil/write.h>
2 #include <bitfield/bitfield.h>
3 #include <bitfield/8byte.h>
5 uint64_t eightbyte_encode_float(float value, uint8_t bit_offset, uint8_t bit_size,
6 float factor, float offset) {
7 float raw = (value - offset) / factor;
9 // round up to avoid losing precision when we cast to an int
10 // TODO do we need a way to encode an int back to a signal without any
15 if(!set_bit_field(&result, (uint64_t)raw, bit_offset, bit_size)) {
16 // debug("%f will not fit in a %d bit field", value, bit_size);
21 uint64_t eightbyte_encode_bool(const bool value, const uint8_t bit_offset,
22 const uint8_t bit_size) {
23 return eightbyte_encode_float(value, bit_offset, bit_size, 1.0, 0);
26 bool bitfield_encode_float(float value, uint8_t bit_offset,
27 uint8_t bit_size, float factor, float offset, uint8_t destination[]) {