aboutsummaryrefslogtreecommitdiffstats
path: root/libs
diff options
context:
space:
mode:
Diffstat (limited to 'libs')
-rw-r--r--libs/bitfield-c/README.mkd6
-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
-rw-r--r--libs/bitfield-c/tests/8byte_tests.c8
-rw-r--r--libs/bitfield-c/tests/bitfield_tests.c30
-rw-r--r--libs/bitfield-c/tests/read_tests.c2
-rw-r--r--libs/bitfield-c/tests/write_tests.c4
14 files changed, 131 insertions, 131 deletions
diff --git a/libs/bitfield-c/README.mkd b/libs/bitfield-c/README.mkd
index 439b3dd0..8fa723f9 100644
--- a/libs/bitfield-c/README.mkd
+++ b/libs/bitfield-c/README.mkd
@@ -9,10 +9,10 @@ started, here are examples using the API:
## Bitfield Manipulation
-The bitfields are stored in `uint8_t[]`.
+The bitfields are stored in `unsigned int[]`.
- uint8_t data[4] = {0x12, 0x34, 0x56, 0x78};
- uint8_t result = get_byte(data, sizeof(data), 0);
+ unsigned int data[4] = {0x12, 0x34, 0x56, 0x78};
+ unsigned int result = get_byte(data, sizeof(data), 0);
// result = 0x12;
result = get_nibble(data, sizeof(data), 0);
// result = 0x1;
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
}
diff --git a/libs/bitfield-c/tests/8byte_tests.c b/libs/bitfield-c/tests/8byte_tests.c
index 64554acc..ccb49cd9 100644
--- a/libs/bitfield-c/tests/8byte_tests.c
+++ b/libs/bitfield-c/tests/8byte_tests.c
@@ -173,8 +173,8 @@ END_TEST
START_TEST(test_eightbyte_get_byte)
{
uint64_t data = 0x00000000F34DFCFF;
- uint8_t result = eightbyte_get_byte(data, 0, false);
- uint8_t expected = 0x0;
+ unsigned int result = eightbyte_get_byte(data, 0, false);
+ unsigned int expected = 0x0;
ck_assert_int_eq(result, expected);
result = eightbyte_get_byte(data, 4, false);
@@ -198,8 +198,8 @@ END_TEST
START_TEST(test_eightbyte_get_nibble)
{
uint64_t data = 0x00000000F34DFCFF;
- uint8_t result = eightbyte_get_nibble(data, 0, false);
- uint8_t expected = 0x0;
+ unsigned int result = eightbyte_get_nibble(data, 0, false);
+ unsigned int expected = 0x0;
ck_assert_int_eq(result, expected);
result = eightbyte_get_nibble(data, 2, false);
diff --git a/libs/bitfield-c/tests/bitfield_tests.c b/libs/bitfield-c/tests/bitfield_tests.c
index b8c83b59..1e61dae5 100644
--- a/libs/bitfield-c/tests/bitfield_tests.c
+++ b/libs/bitfield-c/tests/bitfield_tests.c
@@ -4,8 +4,8 @@
START_TEST (test_get_byte)
{
- uint8_t data[4] = {0x12, 0x34, 0x56, 0x78};
- uint8_t result = get_byte(data, sizeof(data), 0);
+ unsigned int data[4] = {0x12, 0x34, 0x56, 0x78};
+ unsigned int result = get_byte(data, sizeof(data), 0);
ck_assert_int_eq(result, 0x12);
result = get_byte(data, sizeof(data), 3);
ck_assert_int_eq(result, 0x78);
@@ -14,7 +14,7 @@ END_TEST
START_TEST (test_set_nibble)
{
- uint8_t data[4] = {0};
+ unsigned int data[4] = {0};
fail_unless(set_nibble(0, 0x1, data, sizeof(data)));
fail_unless(set_nibble(1, 0x2, data, sizeof(data)));
fail_unless(set_nibble(2, 0x3, data, sizeof(data)));
@@ -28,7 +28,7 @@ END_TEST
START_TEST (test_set_bitfield)
{
- uint8_t data[4] = {0};
+ unsigned int data[4] = {0};
fail_unless(set_bitfield(0x12, 0, 8, data, sizeof(data)));
fail_unless(set_bitfield(bitmask(3), 10, 3, data, sizeof(data)));
ck_assert_int_eq(data[0], 0x12);
@@ -38,7 +38,7 @@ END_TEST
START_TEST (test_set_bitfield_doesnt_fit)
{
- uint8_t data[4] = {0};
+ unsigned int data[4] = {0};
fail_if(set_bitfield(0xffff, 0, 8, data, sizeof(data)));
ck_assert_int_eq(data[0], 0);
ck_assert_int_eq(data[1], 0);
@@ -49,8 +49,8 @@ END_TEST
START_TEST (test_get_nibble)
{
- uint8_t data[4] = {0x12, 0x34, 0x56, 0x78};
- uint8_t result = get_nibble(data, sizeof(data), 0);
+ unsigned int data[4] = {0x12, 0x34, 0x56, 0x78};
+ unsigned int result = get_nibble(data, sizeof(data), 0);
ck_assert_int_eq(result, 0x1);
result = get_nibble(data, sizeof(data), 1);
ck_assert_int_eq(result, 0x2);
@@ -61,8 +61,8 @@ END_TEST
START_TEST (test_get_bits_out_of_range)
{
- uint8_t data[4] = {0x12, 0x34, 0x56, 0x78};
- uint8_t result[4];
+ unsigned int data[4] = {0x12, 0x34, 0x56, 0x78};
+ unsigned int result[4];
fail_if(copy_bits_right_aligned(data, sizeof(data), 25, 16, result,
sizeof(result)));
}
@@ -70,8 +70,8 @@ END_TEST
START_TEST (test_get_bits)
{
- uint8_t data[4] = {0x12, 0x34, 0x56, 0x78};
- uint8_t result[4] = {0};
+ unsigned int data[4] = {0x12, 0x34, 0x56, 0x78};
+ unsigned int result[4] = {0};
fail_unless(copy_bits_right_aligned(data, sizeof(data), 0, 16, result,
sizeof(result)));
ck_assert_int_eq(result[2], 0x12);
@@ -81,8 +81,8 @@ END_TEST
START_TEST (test_copy_bytes)
{
- uint8_t data[4] = {0x12, 0x34, 0x56, 0x78};
- uint8_t result[4] = {0};
+ unsigned int data[4] = {0x12, 0x34, 0x56, 0x78};
+ unsigned int result[4] = {0};
fail_unless(copy_bytes_right_aligned(data, sizeof(data), 1, 3, result,
sizeof(result)));
ck_assert_int_eq(result[1], 0x34);
@@ -93,8 +93,8 @@ END_TEST
START_TEST (test_get_uneven_bits)
{
- uint8_t data[4] = {0x12, 0x34, 0x56, 0x78};
- uint8_t result[4] = {0};
+ unsigned int data[4] = {0x12, 0x34, 0x56, 0x78};
+ unsigned int result[4] = {0};
fail_unless(copy_bits_right_aligned(data, sizeof(data), 4, 12, result,
sizeof(result)));
ck_assert_int_eq(result[2], 0x2);
diff --git a/libs/bitfield-c/tests/read_tests.c b/libs/bitfield-c/tests/read_tests.c
index 5008cc52..192a0fe0 100644
--- a/libs/bitfield-c/tests/read_tests.c
+++ b/libs/bitfield-c/tests/read_tests.c
@@ -3,7 +3,7 @@
#include <canutil/read.h>
const uint64_t BIG_ENDIAN_TEST_DATA = __builtin_bswap64(0xEB00000000000000);
-const uint8_t ARRAY_TEST_DATA[] = {0xEB, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0};
+const unsigned int ARRAY_TEST_DATA[] = {0xEB, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0};
START_TEST (test_eightbyte_parse_float)
{
diff --git a/libs/bitfield-c/tests/write_tests.c b/libs/bitfield-c/tests/write_tests.c
index 4d5d8fc3..9e65b9d0 100644
--- a/libs/bitfield-c/tests/write_tests.c
+++ b/libs/bitfield-c/tests/write_tests.c
@@ -30,7 +30,7 @@ END_TEST
START_TEST (test_bitfield_encode_float)
{
- uint8_t data[8] = {0};
+ unsigned int data[8] = {0};
bitfield_encode_float(0, 1, 3, 1, 0, data, sizeof(data));
ck_assert_int_eq(data[0], 0);
ck_assert_int_eq(data[1], 0);
@@ -55,7 +55,7 @@ END_TEST
START_TEST (test_bitfield_encode_bool)
{
- uint8_t data[8] = {0};
+ unsigned int data[8] = {0};
bitfield_encode_bool(true, 1, 3, data, sizeof(data));
ck_assert_int_eq(data[0], 0x10);
ck_assert_int_eq(data[1], 0);