summaryrefslogtreecommitdiffstats
path: root/README.mkd
diff options
context:
space:
mode:
Diffstat (limited to 'README.mkd')
-rw-r--r--README.mkd28
1 files changed, 24 insertions, 4 deletions
diff --git a/README.mkd b/README.mkd
index 8f6ac5f1..b96d587b 100644
--- a/README.mkd
+++ b/README.mkd
@@ -3,26 +3,46 @@ CAN Message Utilities for C
## 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));
+
+## 8 Byte Bitfield Manipulation
+
+TODO setting bit fields is just copying
+TODO bring back old uint64_t implementation of getBitField if it's faster /
+ simpler
+
## CAN Signal Encoding
+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)
+ // payload == 0x1000000000000000
+
+ payload = bitfield_encode_bool(true, 1, 3);
+ // payload == 0x1000000000000000
+
## CAN Signal Decoding
The library supports parsing floating point CAN signals as well as booleans.
uint64_t payload = 0xeb00000000000000;
- float result = bitfield_parse_float(payload,
+ float float_result = bitfield_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
- // result == -19990.0
+ // float_result == -19990.0
- bool result = bitfield_parse_bool(payload,
+ bool bool_result = bitfield_parse_bool(payload,
0, // starting bit
1, // width of the signal's field
1.0, // transformation factor for the signal value
0); // transformation offset for the signal value
- // result == true
+ // bool_result == true
## Testing