Test all canutil functions and document in README.
[apps/agl-service-can-low-level.git] / README.mkd
1 CAN Message Utilities for C
2 ============
3
4 ## Bitfield Manipulation
5
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));
10
11 ## 8 Byte Bitfield Manipulation
12
13 TODO setting bit fields is just copying
14 TODO bring back old uint64_t implementation of getBitField if it's faster /
15     simpler
16
17 ## CAN Signal Encoding
18
19 The library supports encoding floating point CAN signals as well as booleans
20 into a uint64_t payload.
21
22     uint64_t payload = bitfield_encode_float(1, 1, 3, 1, 0)
23     // payload == 0x1000000000000000
24
25     payload = bitfield_encode_bool(true, 1, 3);
26     // payload == 0x1000000000000000
27
28 ## CAN Signal Decoding
29
30 The library supports parsing floating point CAN signals as well as booleans.
31
32     uint64_t payload = 0xeb00000000000000;
33     float float_result = bitfield_parse_float(payload,
34             2, // starting bit
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
39
40     bool bool_result = bitfield_parse_bool(payload,
41             0, // starting bit
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
46
47 ## Testing
48
49 The library includes a test suite that uses the `check` C unit test library.
50
51     $ make test
52
53 ## Authors
54
55 Chris Peplin cpeplin@ford.com
56
57 ## License
58
59 Copyright (c) 2013 Ford Motor Company
60
61 Licensed under the BSD license.