X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=README.mkd;h=59d5ae5d7b5e5f35668eb46139f6ffa698c33e90;hb=31caa9c77dbfc438a104fbcab6db5165528c0f89;hp=76feddbe63689907d7d1a3a4fd9462ff6ec235de;hpb=e5a2a6b9550319cf05c3a3ae93080b17d322078e;p=apps%2Fagl-service-can-low-level.git diff --git a/README.mkd b/README.mkd index 76feddbe..59d5ae5d 100644 --- a/README.mkd +++ b/README.mkd @@ -1,21 +1,33 @@ -CAN Message Utilities for C +Bitfield Utilities in C =========================== This is a C library with functions to help encode and decode Controller Area -Network (CAN) message payloads. Some of the bitfield functions may be useful for -other areas, too. +Network (CAN) message payloads or other bitfields. The header files contain complete function documentation, but to get you started, here are examples using the API: ## Bitfield Manipulation +The bitfields are stored in `uint8_t[]`. + 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); + // result = 0x12; + result = get_nibble(data, sizeof(data), 0); + // result = 0x1; + bool success = copy_bits_right_aligned(data, 4, 4, 12, result, 4) + // success == true + // result[0] == 0x2 + // result[1] == 0x34 + +## 8 Byte Helpers + +If you are dealing with 8 byte CAN messages as `uint64_t`, there are some +additional functions prefixed with `eightbyte_` that may be faster or more +useful. -## 8 Byte Bitfield Decoding +### 8 Byte Decoding uint64_t data = 0x8000000000000000; uint64_t result = get_bit_field(data, 0, 1, false); @@ -26,22 +38,23 @@ started, here are examples using the API: // result = 0x574d555a; data = 0x00000000F34DFCFF; - result = nth_byte(data, 0); + result = eightbyte_get_byte(data, 0, false); //result = 0x0 - result = nth_byte(data, 4); + result = eightbyte_get_byte(data, 4, false); //result = 0xF3 -## 8 Byte Bitfield Encoding + result = eightbyte_get_nibble(data, 10, false); + //result = 0x4; + +### 8 Byte Encoding uint64_t data = 0; fail_unless(set_bit_field(&data, 1, 0, 1)); uint64_t result = get_bit_field(data, 0, 1, false); ck_assert_int_eq(result, 0x1); -TODO setting bit fields is just copying - -## CAN Signal Encoding +### CAN Signal Encoding The library supports encoding floating point CAN signals as well as booleans into a uint64_t payload. @@ -52,7 +65,7 @@ into a uint64_t payload. payload = bitfield_encode_bool(true, 1, 3); // payload == 0x1000000000000000 -## CAN Signal Decoding +### CAN Signal Decoding The library supports parsing floating point CAN signals as well as booleans. @@ -73,7 +86,8 @@ The library supports parsing floating point CAN signals as well as booleans. ## Testing -The library includes a test suite that uses the `check` C unit test library. +The library includes a test suite that uses the `check` C unit test library. It +requires the unit testing library `check`. $ make test