Add 'CAN-binder/libs/isotp-c/' from commit 'ee24440b7c123ab1b0317e57be33e837a1cb51f1'
[apps/agl-service-can-low-level.git] / CAN-binder / libs / isotp-c / src / isotp / receive.h
1 #ifndef __ISOTP_RECEIVE_H__
2 #define __ISOTP_RECEIVE_H__
3
4 #include <isotp/isotp.h>
5 #include <stdint.h>
6 #include <stdbool.h>
7
8 #ifdef __cplusplus
9 extern "C" {
10 #endif
11
12 /* Public: A handle for beginning and continuing receiving a single ISO-TP
13  * message - both single and multi-frame.
14  *
15  * Since an ISO-TP message may contain multiple frames, we need to keep a handle
16  * around while waiting for subsequent CAN messages to complete the message.
17  * This struct encapsulates the local state required.
18  *
19  * completed - True if the received message request is completely finished.
20  * success - True if the message request was successful. The value if this field
21  *      isn't valid if 'completed' isn't true.
22  */
23 typedef struct {
24     bool completed;
25     bool success;
26
27     // Private
28     uint32_t arbitration_id;
29     IsoTpMessageReceivedHandler message_received_callback;
30     uint16_t timeout_ms;
31     // timeout_ms: ISO_TP_DEFAULT_RESPONSE_TIMEOUT,
32     uint8_t* receive_buffer;
33     uint16_t received_buffer_size;
34     uint16_t incoming_message_size;
35     // TODO timer callback for multi frame
36 } IsoTpReceiveHandle;
37
38 /* Public: Initiate receiving a single ISO-TP message on a particular
39  * arbitration ID.
40  *
41  * Note that no actual CAN data has been received at this point - this just sets
42  * up a handle to be used when new CAN messages to arrive, so they can be parsed
43  * as potential single or multi-frame ISO-TP messages.
44  *
45  * shims -  Low-level shims required to send and receive CAN messages, etc.
46  * arbitration_id - The arbitration ID to receive the message on.
47  * callback - an optional function to be called when the message is completely
48  *      received (use NULL if no callback required).
49  *
50  * Returns a handle to be used with isotp_continue_receive when a new CAN frame
51  * arrives. The 'completed' field in the returned IsoTpReceiveHandle will be true
52  * when the message is completely sent.
53  */
54 IsoTpReceiveHandle isotp_receive(IsoTpShims* shims,
55         const uint32_t arbitration_id, IsoTpMessageReceivedHandler callback);
56
57 /* Public: Continue to receive a an ISO-TP message, based on a freshly
58  * received CAN message.
59  *
60  * For a multi-frame ISO-TP message, this function must be called
61  * repeatedly whenever a new CAN message is received in order to complete
62  * receipt.
63  *
64  * TODO does this API work for if we wanted to receive an ISO-TP message and
65  * send our own flow control messages back?
66  *
67  * shims -  Low-level shims required to send and receive CAN messages, etc.
68  * handle - An IsoTpReceiveHandle previously returned by isotp_receive(...).
69  * arbitration_id - The arbitration_id of the received CAN message.
70  * data - The data of the received CAN message.
71  * size - The size of the data in the received CAN message.
72  *
73  * Returns an IsoTpMessage with the 'completed' field set to true if a message
74  * was completely received. If 'completed' is false, more CAN frames are
75  * required to complete the messages, or the arbitration ID didn't match this
76  * handle. Keep passing the same handle to this function when CAN frames arrive.
77  */
78 IsoTpMessage isotp_continue_receive(IsoTpShims* shims,
79         IsoTpReceiveHandle* handle, const uint32_t arbitration_id,
80         const uint8_t data[], const uint8_t size);
81
82 #ifdef __cplusplus
83 }
84 #endif
85
86 #endif // __ISOTP_RECEIVE_H__