diff options
-rw-r--r-- | README.mkd | 16 | ||||
-rw-r--r-- | src/bitfield/8byte.c | 2 | ||||
-rw-r--r-- | src/bitfield/8byte.h | 2 | ||||
-rw-r--r-- | src/bitfield/bitfield.h | 2 | ||||
-rw-r--r-- | src/canutil/write.c | 2 | ||||
-rw-r--r-- | tests/8byte_tests.c | 18 |
6 files changed, 21 insertions, 21 deletions
@@ -30,11 +30,11 @@ useful. ### 8 Byte Decoding uint64_t data = 0x8000000000000000; - uint64_t result = get_bitfield(data, 0, 1, false); + uint64_t result = eightbyte_get_bitfield(data, 0, 1, false); // result == 0x1 data = 0x0402574d555a0401; - result = get_bitfield(data, 16, 32, false); + result = eightbyte_get_bitfield(data, 16, 32, false); // result = 0x574d555a; data = 0x00000000F34DFCFF; @@ -50,8 +50,8 @@ useful. ### 8 Byte Encoding uint64_t data = 0; - fail_unless(set_bit_field(&data, 1, 0, 1)); - uint64_t result = get_bitfield(data, 0, 1, false); + fail_unless(8byte_set_bitfield(&data, 1, 0, 1)); + uint64_t result = eightbyte_get_bitfield(data, 0, 1, false); ck_assert_int_eq(result, 0x1); ### CAN Signal Encoding @@ -59,10 +59,10 @@ useful. The library supports encoding floating point CAN signals as well as booleans into a uint64_t payload. - uint64_t payload = bitfield_encode_float(1, 1, 3, 1, 0) + uint64_t payload = eightbyte_encode_float(1, 1, 3, 1, 0) // payload == 0x1000000000000000 - payload = bitfield_encode_bool(true, 1, 3); + payload = eightbyte_encode_bool(true, 1, 3); // payload == 0x1000000000000000 ### CAN Signal Decoding @@ -70,14 +70,14 @@ into a uint64_t payload. The library supports parsing floating point CAN signals as well as booleans. uint64_t payload = 0xeb00000000000000; - float float_result = bitfield_parse_float(payload, + float float_result = eightbyte_parse_float(payload, 2, // starting bit 4, // width of the signal's field 1001.0, // transformation factor for the signal value -30000.0); // transformation offset for the signal value // float_result == -19990.0 - bool bool_result = bitfield_parse_bool(payload, + bool bool_result = eightbyte_parse_bool(payload, 0, // starting bit 1, // width of the signal's field 1.0, // transformation factor for the signal value diff --git a/src/bitfield/8byte.c b/src/bitfield/8byte.c index 3c555f08..5f310425 100644 --- a/src/bitfield/8byte.c +++ b/src/bitfield/8byte.c @@ -46,7 +46,7 @@ uint64_t eightbyte_get_bitfield(uint64_t source, const uint16_t offset, return ret & bitmask(bit_count); } -bool set_bit_field(uint64_t* destination, uint64_t value, const uint16_t offset, +bool eightbyte_set_bitfield(uint64_t* destination, uint64_t value, const uint16_t offset, const uint16_t bit_count) { if(value > bitmask(bit_count)) { return false; diff --git a/src/bitfield/8byte.h b/src/bitfield/8byte.h index ab775caa..2916c218 100644 --- a/src/bitfield/8byte.h +++ b/src/bitfield/8byte.h @@ -74,7 +74,7 @@ uint8_t eightbyte_get_byte(const uint64_t source, const uint8_t byte_index, * Returns true if the bit_count is enough to fully represent the value, and * false if it will not fit. */ -bool eightbyte_set_bit_field(uint64_t* destination, uint64_t value, +bool eightbyte_set_bitfield(uint64_t* destination, uint64_t value, const uint16_t offset, const uint16_t bit_count); /* Private: Determine the index of the last bit used. diff --git a/src/bitfield/bitfield.h b/src/bitfield/bitfield.h index 80f31243..a080c866 100644 --- a/src/bitfield/bitfield.h +++ b/src/bitfield/bitfield.h @@ -37,7 +37,7 @@ extern "C" { * * Returns the value of the requested bit field, right aligned in a uint64_t. */ -uint64_t get_bits(const uint8_t source[], const uint8_t source_length, +uint64_t get_bitfield(const uint8_t source[], const uint8_t source_length, const uint16_t offset, const uint16_t bit_count); /* Public: Return a single nibble from the byte array, with range checking. diff --git a/src/canutil/write.c b/src/canutil/write.c index 09e6caa3..5b91aaf9 100644 --- a/src/canutil/write.c +++ b/src/canutil/write.c @@ -12,7 +12,7 @@ uint64_t eightbyte_encode_float(float value, uint8_t bit_offset, uint8_t bit_siz raw += 0.5; } uint64_t result = 0; - if(!set_bit_field(&result, (uint64_t)raw, bit_offset, bit_size)) { + if(!eightbyte_set_bitfield(&result, (uint64_t)raw, bit_offset, bit_size)) { // debug("%f will not fit in a %d bit field", value, bit_size); } return result; diff --git a/tests/8byte_tests.c b/tests/8byte_tests.c index 12ff417d..51e927e4 100644 --- a/tests/8byte_tests.c +++ b/tests/8byte_tests.c @@ -103,23 +103,23 @@ START_TEST (test_get_off_byte_boundary) START_TEST (test_set_wont_fit) { uint64_t data = 0; - fail_if(set_bit_field(&data, 100, 0, 1)); + fail_if(eightbyte_set_bitfield(&data, 100, 0, 1)); } END_TEST START_TEST (test_set_field) { uint64_t data = 0; - fail_unless(set_bit_field(&data, 1, 0, 1)); + fail_unless(eightbyte_set_bitfield(&data, 1, 0, 1)); uint64_t result = eightbyte_get_bitfield(data, 0, 1, false); ck_assert_int_eq(result, 0x1); data = 0; - fail_unless(set_bit_field(&data, 1, 1, 1)); + fail_unless(eightbyte_set_bitfield(&data, 1, 1, 1)); result = eightbyte_get_bitfield(data, 1, 1, false); ck_assert_int_eq(result, 0x1); data = 0; - fail_unless(set_bit_field(&data, 0xf, 3, 4)); + fail_unless(eightbyte_set_bitfield(&data, 0xf, 3, 4)); result = eightbyte_get_bitfield(data, 3, 4, false); ck_assert_int_eq(result, 0xf); } @@ -128,14 +128,14 @@ END_TEST START_TEST (test_set_doesnt_clobber_existing_data) { uint64_t data = 0xFFFC4DF300000000; - fail_unless(set_bit_field(&data, 0x4fc8, 16, 16)); + fail_unless(eightbyte_set_bitfield(&data, 0x4fc8, 16, 16)); uint64_t result = eightbyte_get_bitfield(data, 16, 16, false); fail_unless(result == 0x4fc8, "Field retrieved in 0x%llx was 0x%llx instead of 0x%x", data, result, 0xc84f); data = 0x8000000000000000; - fail_unless(set_bit_field(&data, 1, 21, 1)); + fail_unless(eightbyte_set_bitfield(&data, 1, 21, 1)); fail_unless(data == 0x8000040000000000LLU, "Expected combined value 0x8000040000000000 but got 0x%llx%llx", data >> 32, data); @@ -145,7 +145,7 @@ END_TEST START_TEST (test_set_off_byte_boundary) { uint64_t data = 0xFFFC4DF300000000; - fail_unless(set_bit_field(&data, 0x12, 12, 8)); + fail_unless(eightbyte_set_bitfield(&data, 0x12, 12, 8)); uint64_t result = eightbyte_get_bitfield(data, 12, 12, false); ck_assert_int_eq(result,0x12d); } @@ -154,14 +154,14 @@ END_TEST START_TEST (test_set_odd_number_of_bits) { uint64_t data = 0xFFFC4DF300000000LLU; - fail_unless(set_bit_field(&data, 0x12, 11, 5)); + fail_unless(eightbyte_set_bitfield(&data, 0x12, 11, 5)); uint64_t result = eightbyte_get_bitfield(data, 11, 5, false); fail_unless(result == 0x12, "Field set in 0x%llx%llx%llx%llx was 0x%llx instead of 0x%llx", data, result, 0x12); data = 0xFFFC4DF300000000LLU; - fail_unless(set_bit_field(&data, 0x2, 11, 5)); + fail_unless(eightbyte_set_bitfield(&data, 0x2, 11, 5)); result = eightbyte_get_bitfield(data, 11, 5, false); fail_unless(result == 0x2, "Field set in 0x%llx%llx%llx%llx was 0x%llx instead of 0x%llx", data, result, |