1 CAN Message Utilities for C
4 ## Bitfield Manipulation
6 uint8_t data[4] = {0x12, 0x34, 0x56, 0x78};
7 uint8_t result = getByte(data, sizeof(data), 0);
8 uint8_t result = getNibble(data, sizeof(data), 0);
9 fail_unless(copyBitsRightAligned(data, 4, 4, 12, result, 4));
11 ## 8 Byte Bitfield Manipulation
13 TODO setting bit fields is just copying
14 TODO bring back old uint64_t implementation of getBitField if it's faster /
17 ## CAN Signal Encoding
19 The library supports encoding floating point CAN signals as well as booleans
20 into a uint64_t payload.
22 uint64_t payload = bitfield_encode_float(1, 1, 3, 1, 0)
23 // payload == 0x1000000000000000
25 payload = bitfield_encode_bool(true, 1, 3);
26 // payload == 0x1000000000000000
28 ## CAN Signal Decoding
30 The library supports parsing floating point CAN signals as well as booleans.
32 uint64_t payload = 0xeb00000000000000;
33 float float_result = bitfield_parse_float(payload,
35 4, // width of the signal's field
36 1001.0, // transformation factor for the signal value
37 -30000.0); // transformation offset for the signal value
38 // float_result == -19990.0
40 bool bool_result = bitfield_parse_bool(payload,
42 1, // width of the signal's field
43 1.0, // transformation factor for the signal value
44 0); // transformation offset for the signal value
45 // bool_result == true
49 The library includes a test suite that uses the `check` C unit test library.
55 Chris Peplin cpeplin@ford.com
59 Copyright (c) 2013 Ford Motor Company
61 Licensed under the BSD license.