diff options
Diffstat (limited to 'src/canutil')
-rw-r--r-- | src/canutil/read.c | 12 | ||||
-rw-r--r-- | src/canutil/read.h | 4 | ||||
-rw-r--r-- | src/canutil/write.c | 14 | ||||
-rw-r--r-- | src/canutil/write.h | 4 |
4 files changed, 17 insertions, 17 deletions
diff --git a/src/canutil/read.c b/src/canutil/read.c index 6b4e40aa..5e882c3d 100644 --- a/src/canutil/read.c +++ b/src/canutil/read.c @@ -1,14 +1,14 @@ #include <bitfield/bitfield.h> -float parseFloat(uint64_t data, uint8_t bitPosition, uint8_t bitSize, +float bitfield_parse_float(uint64_t data, uint8_t bit_offset, uint8_t bit_size, float factor, float offset) { - uint64_t rawValue = getBitField(data, bitPosition, - bitSize, true); - return rawValue * factor + offset; + uint64_t raw = get_bit_field(data, bit_offset, + bit_size, true); + return raw * factor + offset; } -bool parseBoolean(uint64_t data, uint8_t bitPosition, uint8_t bitSize, +bool bitfield_parse_bool(uint64_t data, uint8_t bit_offset, uint8_t bit_size, float factor, float offset) { - float value = parseFloat(data, bitPosition, bitSize, factor, offset); + float value = bitfield_parse_float(data, bit_offset, bit_size, factor, offset); return value == 0.0 ? false : true; } diff --git a/src/canutil/read.h b/src/canutil/read.h index 6ac4eebe..3742d6d1 100644 --- a/src/canutil/read.h +++ b/src/canutil/read.h @@ -16,10 +16,10 @@ extern "C" { * * Returns the final, transformed value of the signal. */ -float parseFloat(uint64_t data, uint8_t bitPosition, uint8_t bitSize, +float bitfield_parse_float(uint64_t data, uint8_t bit_offset, uint8_t bit_size, float factor, float offset); -bool parseBoolean(uint64_t data, uint8_t bitPosition, uint8_t bitSize, +bool bitfield_parse_bool(uint64_t data, uint8_t bit_offset, uint8_t bit_size, float factor, float offset); #ifdef __cplusplus diff --git a/src/canutil/write.c b/src/canutil/write.c index 64b57297..14d2a449 100644 --- a/src/canutil/write.c +++ b/src/canutil/write.c @@ -1,19 +1,19 @@ #include "write.h" #include <bitfield/bitfield.h> -uint64_t encodeFloat(float value, uint8_t bitPosition, uint8_t bitSize, +uint64_t bitfield_encode_float(float value, uint8_t bit_offset, uint8_t bit_size, float factor, float offset) { - float rawValue = (value - offset) / factor; - if(rawValue > 0) { + float raw = (value - offset) / factor; + if(raw > 0) { // round up to avoid losing precision when we cast to an int - rawValue += 0.5; + raw += 0.5; } uint64_t result = 0; - setBitField(&result, (uint64_t)rawValue, bitPosition, bitSize); + set_bit_field(&result, (uint64_t)raw, bit_offset, bit_size); return result; } -uint64_t encodeBoolean(bool value, uint8_t bitPosition, uint8_t bitSize, +uint64_t bitfield_encode_bool(bool value, uint8_t bit_offset, uint8_t bit_size, float factor, float offset) { - return encodeFloat(value, offset, factor, bitPosition, bitSize); + return bitfield_encode_float(value, offset, factor, bit_offset, bit_size); } diff --git a/src/canutil/write.h b/src/canutil/write.h index 1b086dbe..3d13b1df 100644 --- a/src/canutil/write.h +++ b/src/canutil/write.h @@ -8,10 +8,10 @@ extern "C" { #endif -uint64_t encodeFloat(float value, uint8_t bitPosition, uint8_t bitSize, +uint64_t bitfield_encode_float(float value, uint8_t bit_offset, uint8_t bit_size, float factor, float offset); -uint64_t encodeBoolean(bool value, uint8_t bitPosition, uint8_t bitSize, +uint64_t bitfield_encode_bool(bool value, uint8_t bit_offset, uint8_t bit_size, float factor, float offset); #ifdef __cplusplus |