summaryrefslogtreecommitdiffstats
path: root/libs/bitfield-c/src
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2019-11-23 13:39:52 +0100
committerRomain Forlot <romain.forlot@iot.bzh>2020-01-09 15:55:03 +0100
commit78e8a778786bf3f9050e55d99dd2b4338e8f4a8e (patch)
tree8dde7b0f50ea497f7a79ba60909570305328cb26 /libs/bitfield-c/src
parentd76433ade0b75c8cc2b45fdae52a21d7fb28f526 (diff)
bitfield-c: use unsigned int instead of uint8_t
Use unsigned int instead of uint8_t upon destination and source array length. This is needed to handle gathered multi-frames message data which could be greater than 1 simple messages. Bug-AGL: SPEC-2988 Change-Id: I107bff383c2d0771dbc2a30770ec5c195b1c22ac Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'libs/bitfield-c/src')
-rw-r--r--libs/bitfield-c/src/bitfield/8byte.c18
-rw-r--r--libs/bitfield-c/src/bitfield/8byte.h14
-rw-r--r--libs/bitfield-c/src/bitfield/bitarray.c30
-rw-r--r--libs/bitfield-c/src/bitfield/bitfield.c28
-rw-r--r--libs/bitfield-c/src/bitfield/bitfield.h58
-rw-r--r--libs/bitfield-c/src/canutil/read.c12
-rw-r--r--libs/bitfield-c/src/canutil/read.h14
-rw-r--r--libs/bitfield-c/src/canutil/write.c18
-rw-r--r--libs/bitfield-c/src/canutil/write.h20
9 files changed, 106 insertions, 106 deletions
diff --git a/libs/bitfield-c/src/bitfield/8byte.c b/libs/bitfield-c/src/bitfield/8byte.c
index 9325ed1b..be46e825 100644
--- a/libs/bitfield-c/src/bitfield/8byte.c
+++ b/libs/bitfield-c/src/bitfield/8byte.c
@@ -6,13 +6,13 @@
#define EIGHTBYTE_BIT (8 * sizeof(uint64_t))
-uint8_t eightbyte_get_nibble(const uint64_t source, const uint8_t nibble_index,
+unsigned int eightbyte_get_nibble(const uint64_t source, const unsigned int nibble_index,
const bool data_is_big_endian) {
- return (uint8_t) eightbyte_get_bitfield(source, NIBBLE_SIZE * nibble_index,
+ return (unsigned int) eightbyte_get_bitfield(source, NIBBLE_SIZE * nibble_index,
NIBBLE_SIZE, data_is_big_endian);
}
-uint8_t eightbyte_get_byte(uint64_t source, const uint8_t byte_index,
+unsigned int eightbyte_get_byte(uint64_t source, const unsigned int byte_index,
const bool data_is_big_endian) {
if(data_is_big_endian) {
source = __builtin_bswap64(source);
@@ -23,8 +23,8 @@ uint8_t eightbyte_get_byte(uint64_t source, const uint8_t byte_index,
// TODO is this funciton necessary anymore? is it any faster for uint64_t than
// get_bitfield(data[], ...)? is the performance better on a 32 bit platform
// like the PIC32?
-uint64_t eightbyte_get_bitfield(uint64_t source, const uint16_t offset,
- const uint16_t bit_count, const bool data_is_big_endian) {
+uint64_t eightbyte_get_bitfield(uint64_t source, const unsigned int offset,
+ const unsigned int bit_count, const bool data_is_big_endian) {
int startByte = offset / CHAR_BIT;
int endByte = (offset + bit_count - 1) / CHAR_BIT;
@@ -32,11 +32,11 @@ uint64_t eightbyte_get_bitfield(uint64_t source, const uint16_t offset,
source = __builtin_bswap64(source);
}
- uint8_t* bytes = (uint8_t*)&source;
+ unsigned int* bytes = (unsigned int*)&source;
uint64_t ret = bytes[startByte];
if(startByte != endByte) {
// The lowest byte address contains the most significant bit.
- uint8_t i;
+ unsigned int i;
for(i = startByte + 1; i <= endByte; i++) {
ret = ret << 8;
ret = ret | bytes[i];
@@ -47,8 +47,8 @@ uint64_t eightbyte_get_bitfield(uint64_t source, const uint16_t offset,
return ret & bitmask(bit_count);
}
-bool eightbyte_set_bitfield(uint64_t value, const uint16_t offset,
- const uint16_t bit_count, uint64_t* destination) {
+bool eightbyte_set_bitfield(uint64_t value, const unsigned int offset,
+ const unsigned int bit_count, uint64_t* destination) {
if(value > bitmask(bit_count)) {
return false;
}
diff --git a/libs/bitfield-c/src/bitfield/8byte.h b/libs/bitfield-c/src/bitfield/8byte.h
index 04512690..97c200bb 100644
--- a/libs/bitfield-c/src/bitfield/8byte.h
+++ b/libs/bitfield-c/src/bitfield/8byte.h
@@ -36,8 +36,8 @@ extern "C" {
*
* Returns the value of the requested bit field, right aligned in a uint64_t.
*/
-uint64_t eightbyte_get_bitfield(uint64_t source, const uint16_t offset,
- const uint16_t bit_count, const bool data_is_big_endian);
+uint64_t eightbyte_get_bitfield(uint64_t source, const unsigned int offset,
+ const unsigned int bit_count, const bool data_is_big_endian);
/* Public: Return a single nibble from the payload, with range checking.
*
@@ -47,9 +47,9 @@ uint64_t eightbyte_get_bitfield(uint64_t source, const uint16_t offset,
* data_is_big_endian - if the data passed in is little endian, set this to false and it
* will be flipped before grabbing the bit field.
*
- * Returns the retreived nibble, right aligned in a uint8_t.
+ * Returns the retreived nibble, right aligned in a unsigned int.
*/
-uint8_t eightbyte_get_nibble(const uint64_t source, const uint8_t nibble_index,
+unsigned int eightbyte_get_nibble(const uint64_t source, const unsigned int nibble_index,
const bool data_is_big_endian);
/* Public: Return a single byte from the payload, with range checking.
@@ -61,7 +61,7 @@ uint8_t eightbyte_get_nibble(const uint64_t source, const uint8_t nibble_index,
*
* Returns the retreived byte.
*/
-uint8_t eightbyte_get_byte(const uint64_t source, const uint8_t byte_index,
+unsigned int eightbyte_get_byte(const uint64_t source, const unsigned int byte_index,
const bool data_is_big_endian);
/* Public: Set the bit field in the given data array to the new value.
@@ -75,11 +75,11 @@ uint8_t eightbyte_get_byte(const uint64_t source, const uint8_t byte_index,
* false if it will not fit.
*/
bool eightbyte_set_bitfield(uint64_t value,
- const uint16_t offset, const uint16_t bit_count, uint64_t* destination);
+ const unsigned int offset, const unsigned int bit_count, uint64_t* destination);
/* Private: Determine the index of the last bit used.
*/
-uint8_t find_end_bit(const uint16_t num_bits);
+unsigned int find_end_bit(const unsigned int num_bits);
#ifdef __cplusplus
}
diff --git a/libs/bitfield-c/src/bitfield/bitarray.c b/libs/bitfield-c/src/bitfield/bitarray.c
index dcb9a08f..ec786a11 100644
--- a/libs/bitfield-c/src/bitfield/bitarray.c
+++ b/libs/bitfield-c/src/bitfield/bitarray.c
@@ -15,15 +15,15 @@
bit_count = 0; \
} } while (0)
-static const uint8_t reverse_mask[] =
+static const unsigned int reverse_mask[] =
{ 0x55, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, 0xff };
-static const uint8_t reverse_mask_xor[] =
+static const unsigned int reverse_mask_xor[] =
{ 0xff, 0x7f, 0x3f, 0x1f, 0x0f, 0x07, 0x03, 0x01, 0x00 };
-bool copy_bits(const uint8_t* source_origin, const uint16_t source_length,
- const uint16_t source_offset, uint16_t bit_count,
- uint8_t* destination_origin, const uint16_t destination_length,
- const uint16_t destination_offset) {
+bool copy_bits(const uint8_t* source_origin, const unsigned int source_length,
+ const unsigned int source_offset, unsigned int bit_count,
+ uint8_t* destination_origin, const unsigned int destination_length,
+ const unsigned int destination_offset) {
if(bit_count < 1) {
return false;
}
@@ -108,8 +108,8 @@ bool copy_bits(const uint8_t* source_origin, const uint16_t source_length,
return true;
}
-uint16_t bits_to_bytes(uint32_t bits) {
- uint8_t byte_count = bits / CHAR_BIT;
+unsigned int bits_to_bytes(uint32_t bits) {
+ unsigned int byte_count = bits / CHAR_BIT;
if(bits % CHAR_BIT != 0) {
++byte_count;
}
@@ -121,14 +121,14 @@ uint16_t bits_to_bytes(uint32_t bits) {
*
* Returns: a bit position from 0 to 7.
*/
-uint8_t find_end_bit(const uint16_t numBits) {
+unsigned int find_end_bit(const unsigned int numBits) {
int endBit = numBits % CHAR_BIT;
return endBit == 0 ? CHAR_BIT : endBit;
}
-bool copy_bits_right_aligned(const uint8_t source[], const uint16_t source_length,
- const uint16_t offset, const uint16_t bit_count,
- uint8_t* destination, const uint16_t destination_length) {
+bool copy_bits_right_aligned(const uint8_t source[], const unsigned int source_length,
+ const unsigned int offset, const unsigned int bit_count,
+ uint8_t* destination, const unsigned int destination_length) {
return copy_bits(source, source_length, offset, bit_count, destination,
destination_length,
// provide a proper destination offset so the result is right
@@ -137,9 +137,9 @@ bool copy_bits_right_aligned(const uint8_t source[], const uint16_t source_lengt
CHAR_BIT - find_end_bit(bit_count));
}
-bool copy_bytes_right_aligned(const uint8_t source[], const uint16_t source_length,
- const uint16_t offset, const uint16_t byte_count,
- uint8_t* destination, const uint16_t destination_length) {
+bool copy_bytes_right_aligned(const uint8_t source[], const unsigned int source_length,
+ const unsigned int offset, const unsigned int byte_count,
+ uint8_t* destination, const unsigned int destination_length) {
return copy_bits_right_aligned(source, source_length, offset * CHAR_BIT,
byte_count * CHAR_BIT, destination, destination_length);
}
diff --git a/libs/bitfield-c/src/bitfield/bitfield.c b/libs/bitfield-c/src/bitfield/bitfield.c
index 795f0208..e9077e1c 100644
--- a/libs/bitfield-c/src/bitfield/bitfield.c
+++ b/libs/bitfield-c/src/bitfield/bitfield.c
@@ -4,14 +4,14 @@
#include <stddef.h>
#include <sys/param.h>
-uint64_t bitmask(const uint8_t bit_count) {
+uint64_t bitmask(const unsigned int bit_count) {
return (((uint64_t)0x1) << bit_count) - 1;
}
-uint8_t get_nibble(const uint8_t source[], const uint8_t source_length,
- const uint8_t nibble_index) {
- uint8_t byte_index = nibble_index / 2;
- uint8_t result = get_byte(source, source_length, byte_index);
+unsigned int get_nibble(const uint8_t source[], const unsigned int source_length,
+ const unsigned int nibble_index) {
+ unsigned int byte_index = nibble_index / 2;
+ unsigned int result = get_byte(source, source_length, byte_index);
if(nibble_index % 2 == 0) {
result >>= NIBBLE_SIZE;
}
@@ -19,16 +19,16 @@ uint8_t get_nibble(const uint8_t source[], const uint8_t source_length,
return result;
}
-uint8_t get_byte(const uint8_t source[], const uint8_t source_length,
- const uint8_t byte_index) {
+unsigned int get_byte(const uint8_t source[], const unsigned int source_length,
+ const unsigned int byte_index) {
if(byte_index < source_length) {
return source[byte_index];
}
return 0;
}
-uint64_t get_bitfield(const uint8_t source[], const uint8_t source_length,
- const uint16_t offset, const uint16_t bit_count) {
+uint64_t get_bitfield(const uint8_t source[], const unsigned int source_length,
+ const unsigned int offset, const unsigned int bit_count) {
if(bit_count > 64 || bit_count < 1) {
// TODO error reporting?
return 0;
@@ -47,15 +47,15 @@ uint64_t get_bitfield(const uint8_t source[], const uint8_t source_length,
return combined.whole;
}
-bool set_nibble(const uint16_t nibble_index, const uint8_t value,
- uint8_t* destination, const uint16_t destination_length) {
+bool set_nibble(const unsigned int nibble_index, const unsigned int value,
+ uint8_t* destination, const unsigned int destination_length) {
return copy_bits(&value, CHAR_BIT, NIBBLE_SIZE, NIBBLE_SIZE, destination,
destination_length, nibble_index * NIBBLE_SIZE);
}
-bool set_bitfield(const uint64_t value, const uint16_t offset,
- const uint16_t bit_count, uint8_t destination[],
- uint16_t destination_length) {
+bool set_bitfield(const uint64_t value, const unsigned int offset,
+ const unsigned int bit_count, uint8_t destination[],
+ unsigned int destination_length) {
if(value > bitmask(bit_count)) {
return false;
}
diff --git a/libs/bitfield-c/src/bitfield/bitfield.h b/libs/bitfield-c/src/bitfield/bitfield.h
index df92639a..8dd7499f 100644
--- a/libs/bitfield-c/src/bitfield/bitfield.h
+++ b/libs/bitfield-c/src/bitfield/bitfield.h
@@ -37,8 +37,8 @@ extern "C" {
*
* Returns the value of the requested bit field, right aligned in a uint64_t.
*/
-uint64_t get_bitfield(const uint8_t source[], const uint8_t source_length,
- const uint16_t offset, const uint16_t bit_count);
+uint64_t get_bitfield(const uint8_t source[], const unsigned int source_length,
+ const unsigned int offset, const unsigned int bit_count);
/* Public: Return a single nibble from the byte array, with range checking.
*
@@ -47,10 +47,10 @@ uint64_t get_bitfield(const uint8_t source[], const uint8_t source_length,
* nibble_index - the index of the nibble to retreive. The leftmost nibble is
* index 0.
*
- * Returns the retreived nibble, right aligned in a uint8_t.
+ * Returns the retreived nibble, right aligned in a unsigned int.
*/
-uint8_t get_nibble(const uint8_t source[], const uint8_t source_length,
- const uint8_t nibble_index);
+unsigned int get_nibble(const uint8_t source[], const unsigned int source_length,
+ const unsigned int nibble_index);
/* Public: Return a single byte from the byte array, with range checking.
*
@@ -60,8 +60,8 @@ uint8_t get_nibble(const uint8_t source[], const uint8_t source_length,
*
* Returns the retreived byte.
*/
-uint8_t get_byte(const uint8_t source[], const uint8_t source_length,
- const uint8_t byte_index);
+unsigned int get_byte(const uint8_t source[], const unsigned int source_length,
+ const unsigned int byte_index);
/* Public: Copy a range of bits from one bit array to another.
*
@@ -74,8 +74,8 @@ uint8_t get_byte(const uint8_t source[], const uint8_t source_length,
*
* For example:
*
- * uint8_t source[4] = {0x11, 0x22, 0x33, 0x44};
- * uint8_t destination[4] = {0};
+ * unsigned int source[4] = {0x11, 0x22, 0x33, 0x44};
+ * unsigned int destination[4] = {0};
* copy_bits(source, sizeof(source), 8, 8, destination,
* sizeof(destination), 0);
* // destination[0] == 0x22
@@ -105,10 +105,10 @@ uint8_t get_byte(const uint8_t source[], const uint8_t source_length,
* Returns true if the copy was successful and false if the range exceeded the
* size of the source or destination, or if the range size negative or 0.
*/
-bool copy_bits(const uint8_t* source_origin, const uint16_t source_length,
- const uint16_t source_offset, uint16_t bit_count,
- uint8_t* destination_origin, const uint16_t destination_length,
- const uint16_t destination_offset);
+bool copy_bits(const uint8_t* source_origin, const unsigned int source_length,
+ const unsigned int source_offset, unsigned int bit_count,
+ uint8_t* destination_origin, const unsigned int destination_length,
+ const unsigned int destination_offset);
/* Public: Copy a range of bits from one array to another, right aligning the
* result.
@@ -118,8 +118,8 @@ bool copy_bits(const uint8_t* source_origin, const uint16_t source_length,
*
* For example:
*
- * uint8_t source[4] = {0x11, 0x22, 0x33, 0x44};
- * uint8_t destination[4] = {0};
+ * unsigned int source[4] = {0x11, 0x22, 0x33, 0x44};
+ * unsigned int destination[4] = {0};
* copy_bits_right_aligned(source, sizeof(source), 8, 8, destination,
* sizeof(destination));
* // destination[0] == 0x0
@@ -136,9 +136,9 @@ bool copy_bits(const uint8_t* source_origin, const uint16_t source_length,
* Returns true if the copy was successful and false if the range exceeded the
* size of the source or destination, or if the range size negative or 0.
*/
-bool copy_bits_right_aligned(const uint8_t source[], const uint16_t source_length,
- const uint16_t offset, const uint16_t bit_count,
- uint8_t* destination, const uint16_t destination_length);
+bool copy_bits_right_aligned(const uint8_t source[], const unsigned int source_length,
+ const unsigned int offset, const unsigned int bit_count,
+ uint8_t* destination, const unsigned int destination_length);
/* Public: Copy a range of bytes from one byte array to another.
*
@@ -161,9 +161,9 @@ bool copy_bits_right_aligned(const uint8_t source[], const uint16_t source_lengt
* Returns true if the copy was successful and false if the range exceeded the
* size of the source or destination, or if the range size negative or 0.
*/
-bool copy_bytes_right_aligned(const uint8_t source[], const uint16_t source_length,
- const uint16_t offset, const uint16_t byte_count,
- uint8_t* destination, const uint16_t destination_length);
+bool copy_bytes_right_aligned(const uint8_t source[], const unsigned int source_length,
+ const unsigned int offset, const unsigned int byte_count,
+ uint8_t* destination, const unsigned int destination_length);
/* Public: Set the a nibble in the given data array to the new value.
*
@@ -177,8 +177,8 @@ bool copy_bytes_right_aligned(const uint8_t source[], const uint16_t source_leng
* Returns true if the bit_count is enough to fully represent the value, and
* false if it will not fit.
*/
-bool set_nibble(const uint16_t nibble_index, const uint8_t value,
- uint8_t* destination, const uint16_t destination_length);
+bool set_nibble(const unsigned int nibble_index, const unsigned int value,
+ uint8_t* destination, const unsigned int destination_length);
/* Public: Set the bit field in the given data array to the new value.
*
@@ -192,21 +192,21 @@ bool set_nibble(const uint16_t nibble_index, const uint8_t value,
* Returns true if the bit_count is enough to fully represent the value, and
* false if it will not fit.
*/
-bool set_bitfield(const uint64_t value, const uint16_t offset,
- const uint16_t bit_count, uint8_t destination[],
- uint16_t destination_length);
+bool set_bitfield(const uint64_t value, const unsigned int offset,
+ const unsigned int bit_count, uint8_t destination[],
+ unsigned int destination_length);
/* Public: Return a right aligned bitmask for a uint64_t.
*
* bit_count - the number of bits to mask, right aligned.
*/
-uint64_t bitmask(const uint8_t bit_count);
+uint64_t bitmask(const unsigned int bit_count);
/* Private:
*/
-uint16_t bits_to_bytes(uint32_t bits);
+unsigned int bits_to_bytes(uint32_t bits);
-/* Private: A union to assist swapping between uint64_t and a uint8_t array.
+/* Private: A union to assist swapping between uint64_t and a unsigned int array.
*/
typedef union {
uint64_t whole;
diff --git a/libs/bitfield-c/src/canutil/read.c b/libs/bitfield-c/src/canutil/read.c
index d0cbb71a..5790a7a1 100644
--- a/libs/bitfield-c/src/canutil/read.c
+++ b/libs/bitfield-c/src/canutil/read.c
@@ -6,27 +6,27 @@ static float decode_float(uint64_t raw, float factor, float offset) {
return raw * factor + offset;
}
-float eightbyte_parse_float(uint64_t data, uint8_t bit_offset, uint8_t bit_size,
+float eightbyte_parse_float(uint64_t data, unsigned int bit_offset, unsigned int bit_size,
float factor, float offset) {
return decode_float(eightbyte_get_bitfield(data, bit_offset, bit_size,
true), factor, offset);
}
-bool eightbyte_parse_bool(uint64_t data, uint8_t bit_offset, uint8_t bit_size,
+bool eightbyte_parse_bool(uint64_t data, unsigned int bit_offset, unsigned int bit_size,
float factor, float offset) {
float value = eightbyte_parse_float(data, bit_offset, bit_size, factor, offset);
return value == 0.0 ? false : true;
}
-float bitfield_parse_float(const uint8_t source[], const uint16_t source_length,
- const uint8_t bit_offset, const uint8_t bit_size, const float factor,
+float bitfield_parse_float(const uint8_t source[], const unsigned int source_length,
+ const unsigned int bit_offset, const unsigned int bit_size, const float factor,
const float offset) {
return decode_float(get_bitfield(source, source_length, bit_offset, bit_size),
factor, offset);
}
-bool bitfield_parse_bool(const uint8_t source[], const uint16_t source_length,
- const uint8_t bit_offset, const uint8_t bit_size, const float factor,
+bool bitfield_parse_bool(const uint8_t source[], const unsigned int source_length,
+ const unsigned int bit_offset, const unsigned int bit_size, const float factor,
const float offset) {
float value = bitfield_parse_float(source, source_length, bit_offset,
bit_size, factor, offset);
diff --git a/libs/bitfield-c/src/canutil/read.h b/libs/bitfield-c/src/canutil/read.h
index 86fea785..8afe4f4a 100644
--- a/libs/bitfield-c/src/canutil/read.h
+++ b/libs/bitfield-c/src/canutil/read.h
@@ -20,8 +20,8 @@ extern "C" {
*
* Returns the decoded and transformed value of the signal.
*/
-float eightbyte_parse_float(const uint64_t source, const uint8_t bit_offset,
- const uint8_t bit_size, const float factor, const float offset);
+float eightbyte_parse_float(const uint64_t source, const unsigned int bit_offset,
+ const unsigned int bit_size, const float factor, const float offset);
/* Public: Parse a CAN signal from a message storage as a byte array and apply
* required transformation.
@@ -37,8 +37,8 @@ float eightbyte_parse_float(const uint64_t source, const uint8_t bit_offset,
*
* Returns the decoded and transformed value of the signal.
*/
-float bitfield_parse_float(const uint8_t source[], const uint16_t source_size,
- const uint8_t bit_offset, const uint8_t bit_size, const float factor,
+float bitfield_parse_float(const uint8_t source[], const unsigned int source_size,
+ const unsigned int bit_offset, const unsigned int bit_size, const float factor,
const float offset);
/* Public: Parse a CAN signal from a message and interpret it as a boolean.
@@ -53,7 +53,7 @@ float bitfield_parse_float(const uint8_t source[], const uint16_t source_size,
*
* Returns false if the value was 0, otherwise true.
*/
-bool eightbyte_parse_bool(uint64_t source, uint8_t bit_offset, uint8_t bit_size,
+bool eightbyte_parse_bool(uint64_t source, unsigned int bit_offset, unsigned int bit_size,
float factor, float offset);
/* Public: Parse a CAN signal from a message storage as a byte array and
@@ -70,8 +70,8 @@ bool eightbyte_parse_bool(uint64_t source, uint8_t bit_offset, uint8_t bit_size,
*
* Returns false if the value was 0, otherwise true.
*/
-bool bitfield_parse_bool(const uint8_t source[], const uint16_t source_size,
- const uint8_t bit_offset, const uint8_t bit_size, const float factor,
+bool bitfield_parse_bool(const uint8_t source[], const unsigned int source_size,
+ const unsigned int bit_offset, const unsigned int bit_size, const float factor,
const float offset);
#ifdef __cplusplus
diff --git a/libs/bitfield-c/src/canutil/write.c b/libs/bitfield-c/src/canutil/write.c
index 7f3a3e04..317ccf04 100644
--- a/libs/bitfield-c/src/canutil/write.c
+++ b/libs/bitfield-c/src/canutil/write.c
@@ -14,7 +14,7 @@ uint64_t float_to_fixed_point(const float value, const float factor,
return (uint64_t)raw;
}
-uint64_t eightbyte_encode_float(float value, uint8_t bit_offset, uint8_t bit_size,
+uint64_t eightbyte_encode_float(float value, unsigned int bit_offset, unsigned int bit_size,
float factor, float offset) {
uint64_t result = 0;
if(!eightbyte_set_bitfield(float_to_fixed_point(value, factor, offset),
@@ -24,14 +24,14 @@ uint64_t eightbyte_encode_float(float value, uint8_t bit_offset, uint8_t bit_siz
return result;
}
-uint64_t eightbyte_encode_bool(const bool value, const uint8_t bit_offset,
- const uint8_t bit_size) {
+uint64_t eightbyte_encode_bool(const bool value, const unsigned int bit_offset,
+ const unsigned int bit_size) {
return eightbyte_encode_float(value, bit_offset, bit_size, 1.0, 0);
}
-bool bitfield_encode_float(const float value, const uint8_t bit_offset,
- const uint8_t bit_size, const float factor, const float offset,
- uint8_t destination[], const uint8_t destination_length) {
+bool bitfield_encode_float(const float value, const unsigned int bit_offset,
+ const unsigned int bit_size, const float factor, const float offset,
+ uint8_t destination[], const unsigned int destination_length) {
if(!set_bitfield(float_to_fixed_point(value, factor, offset), bit_offset,
bit_size, destination, destination_length)) {
// debug("%f will not fit in a %d bit field", value, bit_size);
@@ -40,9 +40,9 @@ bool bitfield_encode_float(const float value, const uint8_t bit_offset,
return true;
}
-bool bitfield_encode_bool(const bool value, const uint8_t bit_offset,
- const uint8_t bit_size, uint8_t destination[],
- const uint16_t destination_length) {
+bool bitfield_encode_bool(const bool value, const unsigned int bit_offset,
+ const unsigned int bit_size, uint8_t destination[],
+ const unsigned int destination_length) {
return bitfield_encode_float(value, bit_offset, bit_size, 1.0, 0,
destination, destination_length);
}
diff --git a/libs/bitfield-c/src/canutil/write.h b/libs/bitfield-c/src/canutil/write.h
index c2bef20e..7f653b98 100644
--- a/libs/bitfield-c/src/canutil/write.h
+++ b/libs/bitfield-c/src/canutil/write.h
@@ -23,15 +23,15 @@ extern "C" {
*
* Returns a big-endian uint64_t with the value encoded as a bitfield.
*/
-uint64_t eightbyte_encode_float(float value, uint8_t bit_offset,
- uint8_t bit_size, float factor, float offset);
+uint64_t eightbyte_encode_float(float value, unsigned int bit_offset,
+ unsigned int bit_size, float factor, float offset);
uint64_t float_to_fixed_point(const float value, const float factor,
const float offset);
-bool bitfield_encode_float(const float value, const uint8_t bit_offset,
- const uint8_t bit_size, const float factor, const float offset,
- uint8_t destination[], const uint8_t destination_length);
+bool bitfield_encode_float(const float value, const unsigned int bit_offset,
+ const unsigned int bit_size, const float factor, const float offset,
+ uint8_t destination[], const unsigned int destination_length);
/* Public: Encode a boolean into fixed bit width field in a bit array.
*
@@ -43,12 +43,12 @@ bool bitfield_encode_float(const float value, const uint8_t bit_offset,
*
* Returns a big-endian uint64_t with the value encoded as a bitfield.
*/
-uint64_t eightbyte_encode_bool(const bool value, const uint8_t bit_offset,
- const uint8_t bit_size);
+uint64_t eightbyte_encode_bool(const bool value, const unsigned int bit_offset,
+ const unsigned int bit_size);
-bool bitfield_encode_bool(const bool value, const uint8_t bit_offset, const
- uint8_t bit_size, uint8_t destination[],
- const uint16_t destination_length);
+bool bitfield_encode_bool(const bool value, const unsigned int bit_offset, const
+ unsigned int bit_size, uint8_t destination[],
+ const unsigned int destination_length);
#ifdef __cplusplus
}