Standardize names for functions.
authorChristopher Peplin <chris.peplin@rhubarbtech.com>
Sat, 4 Jan 2014 16:12:21 +0000 (11:12 -0500)
committerChristopher Peplin <chris.peplin@rhubarbtech.com>
Sat, 4 Jan 2014 16:12:21 +0000 (11:12 -0500)
README.mkd
src/bitfield/8byte.c
src/bitfield/8byte.h
src/bitfield/bitfield.h
src/canutil/write.c
tests/8byte_tests.c

index 0cad3d2..99ede1a 100644 (file)
@@ -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
index 3c555f0..5f31042 100644 (file)
@@ -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;
index ab775ca..2916c21 100644 (file)
@@ -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.
index 80f3124..a080c86 100644 (file)
@@ -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.
index 09e6caa..5b91aaf 100644 (file)
@@ -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;
index 12ff417..51e927e 100644 (file)
@@ -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,