summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristopher Peplin <chris.peplin@rhubarbtech.com>2013-12-29 14:20:12 -0500
committerChristopher Peplin <chris.peplin@rhubarbtech.com>2013-12-29 14:21:27 -0500
commit3a6af99be9a10f795b84a5783939b86d7102fb63 (patch)
tree237302584675ab0d838f70e52a20f429c7074da7
parente5a2a6b9550319cf05c3a3ae93080b17d322078e (diff)
Standardize function names to snake_case.
-rw-r--r--README.mkd6
-rw-r--r--src/bitfield/bitarray.c6
-rw-r--r--src/bitfield/bitfield.c6
-rw-r--r--src/bitfield/bitfield.h14
-rw-r--r--tests/bitfield_tests.c16
-rw-r--r--tests/write_tests.c1
6 files changed, 24 insertions, 25 deletions
diff --git a/README.mkd b/README.mkd
index 76feddbe..836b151e 100644
--- a/README.mkd
+++ b/README.mkd
@@ -11,9 +11,9 @@ started, here are examples using the API:
## Bitfield Manipulation
uint8_t data[4] = {0x12, 0x34, 0x56, 0x78};
- uint8_t result = getByte(data, sizeof(data), 0);
- uint8_t result = getNibble(data, sizeof(data), 0);
- fail_unless(copyBitsRightAligned(data, 4, 4, 12, result, 4));
+ uint8_t result = get_byte(data, sizeof(data), 0);
+ uint8_t result = get_nibble(data, sizeof(data), 0);
+ fail_unless(copy_bits_right_aligned(data, 4, 4, 12, result, 4));
## 8 Byte Bitfield Decoding
diff --git a/src/bitfield/bitarray.c b/src/bitfield/bitarray.c
index f8c23527..35fc2d9e 100644
--- a/src/bitfield/bitarray.c
+++ b/src/bitfield/bitarray.c
@@ -20,7 +20,7 @@ static const uint8_t reverse_mask[] =
static const uint8_t reverse_mask_xor[] =
{ 0xff, 0x7f, 0x3f, 0x1f, 0x0f, 0x07, 0x03, 0x01, 0x00 };
-bool copyBits(const uint8_t* source_origin, const uint16_t source_length,
+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) {
@@ -118,10 +118,10 @@ uint8_t find_end_bit(const uint16_t numBits) {
return endBit == 0 ? CHAR_BIT : endBit;
}
-bool copyBitsRightAligned(const uint8_t source[], const uint16_t source_length,
+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) {
- return copyBits(source, source_length, offset, bit_count, destination,
+ return copy_bits(source, source_length, offset, bit_count, destination,
destination_length,
// provide a proper destination offset so the result is right
// aligned
diff --git a/src/bitfield/bitfield.c b/src/bitfield/bitfield.c
index 3bf00ac0..7dfa7cd4 100644
--- a/src/bitfield/bitfield.c
+++ b/src/bitfield/bitfield.c
@@ -5,10 +5,10 @@
#define NIBBLE_SIZE (CHAR_BIT / 2)
-uint8_t getNibble(const uint8_t source[], const uint8_t source_length,
+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 = getByte(source, source_length, byte_index);
+ uint8_t result = get_byte(source, source_length, byte_index);
if(nibble_index % 2 == 0) {
result >>= NIBBLE_SIZE;
}
@@ -16,7 +16,7 @@ uint8_t getNibble(const uint8_t source[], const uint8_t source_length,
return result;
}
-uint8_t getByte(const uint8_t source[], const uint8_t source_length,
+uint8_t get_byte(const uint8_t source[], const uint8_t source_length,
const uint8_t byte_index) {
if(byte_index < source_length) {
return source[byte_index];
diff --git a/src/bitfield/bitfield.h b/src/bitfield/bitfield.h
index 6f5f1c18..52ed143d 100644
--- a/src/bitfield/bitfield.h
+++ b/src/bitfield/bitfield.h
@@ -17,7 +17,7 @@ extern "C" {
*
* Returns the retreived nibble, right aligned in a uint8_t.
*/
-uint8_t getNibble(const uint8_t source[], const uint8_t source_length,
+uint8_t get_nibble(const uint8_t source[], const uint8_t source_length,
const uint8_t nibble_index);
/* Public: Return a single byte from the byte array, with range checking.
@@ -28,7 +28,7 @@ uint8_t getNibble(const uint8_t source[], const uint8_t source_length,
*
* Returns the retreived byte.
*/
-uint8_t getByte(const uint8_t source[], const uint8_t source_length,
+uint8_t get_byte(const uint8_t source[], const uint8_t source_length,
const uint8_t byte_index);
/* Public: Copy a range of bits from one bit array to another.
@@ -44,7 +44,7 @@ uint8_t getByte(const uint8_t source[], const uint8_t source_length,
*
* uint8_t source[4] = {0x11, 0x22, 0x33, 0x44};
* uint8_t destination[4] = {0};
- * copyBits(source, sizeof(source), 8, 8, destination,
+ * copy_bits(source, sizeof(source), 8, 8, destination,
* sizeof(destination), 0);
* // destination[0] == 0x22
* // destination[1] == 0x0
@@ -73,7 +73,7 @@ uint8_t getByte(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 copyBits(const uint8_t* source_origin, const uint16_t source_length,
+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);
@@ -88,7 +88,7 @@ bool copyBits(const uint8_t* source_origin, const uint16_t source_length,
*
* uint8_t source[4] = {0x11, 0x22, 0x33, 0x44};
* uint8_t destination[4] = {0};
- * copyBitsRightAligned(source, sizeof(source), 8, 8, destination,
+ * copy_bits_right_aligned(source, sizeof(source), 8, 8, destination,
* sizeof(destination));
* // destination[0] == 0x0
* // destination[1] == 0x0
@@ -98,13 +98,13 @@ bool copyBits(const uint8_t* source_origin, const uint16_t source_length,
* int value = (int)destination;
* // value == 0x22 == 32
*
- * The arguments are the same as copyBits, but without the destination_offset
+ * The arguments are the same as copy_bits, but without the destination_offset
* option - that's set automatically to right align the result.
*
* 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 copyBitsRightAligned(const uint8_t source[], const uint16_t source_length,
+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);
diff --git a/tests/bitfield_tests.c b/tests/bitfield_tests.c
index f6287c19..3f54eee1 100644
--- a/tests/bitfield_tests.c
+++ b/tests/bitfield_tests.c
@@ -5,9 +5,9 @@
START_TEST (test_get_byte)
{
uint8_t data[4] = {0x12, 0x34, 0x56, 0x78};
- uint8_t result = getByte(data, sizeof(data), 0);
+ uint8_t result = get_byte(data, sizeof(data), 0);
ck_assert_int_eq(result, 0x12);
- result = getByte(data, sizeof(data), 3);
+ result = get_byte(data, sizeof(data), 3);
ck_assert_int_eq(result, 0x78);
}
END_TEST
@@ -15,11 +15,11 @@ END_TEST
START_TEST (test_get_nibble)
{
uint8_t data[4] = {0x12, 0x34, 0x56, 0x78};
- uint8_t result = getNibble(data, sizeof(data), 0);
+ uint8_t result = get_nibble(data, sizeof(data), 0);
ck_assert_int_eq(result, 0x1);
- result = getNibble(data, sizeof(data), 1);
+ result = get_nibble(data, sizeof(data), 1);
ck_assert_int_eq(result, 0x2);
- result = getNibble(data, sizeof(data), 2);
+ result = get_nibble(data, sizeof(data), 2);
ck_assert_int_eq(result, 0x3);
}
END_TEST
@@ -28,7 +28,7 @@ START_TEST (test_get_bits_out_of_range)
{
uint8_t data[4] = {0x12, 0x34, 0x56, 0x78};
uint8_t result[4];
- fail_if(copyBitsRightAligned(data, 4, 25, 16, result, 4));
+ fail_if(copy_bits_right_aligned(data, 4, 25, 16, result, 4));
}
END_TEST
@@ -36,7 +36,7 @@ START_TEST (test_get_bits)
{
uint8_t data[4] = {0x12, 0x34, 0x56, 0x78};
uint8_t result[4] = {0};
- fail_unless(copyBitsRightAligned(data, 4, 0, 16, result, 4));
+ fail_unless(copy_bits_right_aligned(data, 4, 0, 16, result, 4));
ck_assert_int_eq(result[0], 0x12);
ck_assert_int_eq(result[1], 0x34);
}
@@ -46,7 +46,7 @@ START_TEST (test_get_uneven_bits)
{
uint8_t data[4] = {0x12, 0x34, 0x56, 0x78};
uint8_t result[4] = {0};
- fail_unless(copyBitsRightAligned(data, 4, 4, 12, result, 4));
+ fail_unless(copy_bits_right_aligned(data, 4, 4, 12, result, 4));
ck_assert_int_eq(result[0], 0x2);
ck_assert_int_eq(result[1], 0x34);
}
diff --git a/tests/write_tests.c b/tests/write_tests.c
index 8cc35e21..4091ac4f 100644
--- a/tests/write_tests.c
+++ b/tests/write_tests.c
@@ -27,7 +27,6 @@ START_TEST (test_encode_bool)
ck_assert_int_eq(value, 0x0000000000000000LLU);
}
END_TEST
-// TODO test encode bool
Suite* canwriteSuite(void) {
Suite* s = suite_create("write");