bf6c0ade48e231264cdde5c487f52bfa7e3e1e7b
[apps/agl-service-can-low-level.git] / src / canutil / read.h
1 #ifndef __READ_H__
2 #define __READ_H__
3
4 #include <stdint.h>
5 #include <stdbool.h>
6
7 #ifdef __cplusplus
8 extern "C" {
9 #endif
10
11 /* Public: Parse a CAN signal from a message and apply required transformation.
12  *
13  * data - the payload containing the signal.
14  * bit_offset - the starting bit for the signal.
15  * bit_size - the width of the signal.
16  * factor - the transformation factor for the signal value, applied after
17  *      pulling out the bit field. Use 1.0 for no factor.
18  * offset - the transformation offset for the signal value, applied after
19  *      pulling out the bit field. Use 0 for no offset.
20  *
21  * Returns the decoded and transformed value of the signal.
22  */
23 float eightbyte_parse_float(const uint64_t data, const uint8_t bit_offset,
24         const uint8_t bit_size, const float factor, const float offset);
25
26 float bitfield_parse_float(const uint8_t data[], const uint16_t size,
27         const uint8_t bit_offset, const uint8_t bit_size, const float factor,
28         const float offset);
29
30 /* Public: Parse a CAN signal from a message and interpret it as a boolean.
31  *
32  * data - the payload containing the signal.
33  * bit_offset - the starting bit for the signal.
34  * bit_size - the width of the signal.
35  * factor - the transformation factor for the signal value, applied after
36  *      pulling out the bit field. Use 1.0 for no factor.
37  * offset - the transformation offset for the signal value, applied after
38  *      pulling out the bit field. Use 0 for no offset.
39  *
40  * Returns false if the value was 0, otherwise true.
41  */
42 bool eightbyte_parse_bool(uint64_t data, uint8_t bit_offset, uint8_t bit_size,
43         float factor, float offset);
44
45 #ifdef __cplusplus
46 }
47 #endif
48
49 #endif // __READ_H__