1af326688783a376538f2c7e7427d4743a6fc847
[apps/agl-service-can-low-level.git] / CAN-binder / libs / isotp-c / src / isotp / send.h
1 #ifndef __ISOTP_SEND_H__
2 #define __ISOTP_SEND_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 sending 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 flow control messages from the receiver.
17  * This struct encapsulates the local state required.
18  *
19  * completed - True if the message was completely sent, or the send was
20  *      otherwise cancelled.
21  * success - True if the message send request was successful. The value if this
22  *      field isn't valid if 'completed' isn't true.
23  */
24 typedef struct {
25     bool completed;
26     bool success;
27
28     // Private
29     uint16_t sending_arbitration_id;
30     uint16_t receiving_arbitration_id;
31     IsoTpMessageSentHandler message_sent_callback;
32     IsoTpCanFrameSentHandler can_frame_sent_callback;
33     // TODO going to need some state here for multi frame messages
34 } IsoTpSendHandle;
35
36 /* Public: Initiate sending a single ISO-TP message.
37  *
38  * If the message fits in a single ISO-TP frame (i.e. the payload isn't more
39  * than 7 bytes) it will be sent immediately and the returned IsoTpSendHandle's
40  * 'completed' flag will be true.
41  *
42  * For multi-frame messages, see isotp_continue_send(...).
43  *
44  * shims -  Low-level shims required to send CAN messages, etc.
45  * arbitration_id - The arbitration ID to send the message on.
46  * payload - The payload for the message. If no payload, NULL is valid is size
47  *      is also 0.
48  * size - The size of the payload, or 0 if no payload.
49  * callback - an optional function to be called when the message is completely
50  *      sent (use NULL if no callback required).
51  *
52  * Returns a handle to be used with isotp_continue_send to continue sending
53  * multi-frame messages. The 'completed' field in the returned IsoTpSendHandle
54  * will be true when the message is completely sent.
55  */
56 IsoTpSendHandle isotp_send(IsoTpShims* shims, const uint16_t arbitration_id,
57         const uint8_t payload[], uint16_t size,
58         IsoTpMessageSentHandler callback);
59
60 /* Public: Continue to send a multi-frame ISO-TP message, based on a freshly
61  * received CAN message (potentially from the receiver about flow control).
62  *
63  * For a multi-frame ISO-TP message, this function must be called
64  * repeatedly whenever a new CAN message is received in order to complete the
65  * send. The sender can't just blast everything onto the bus at once - it must
66  * wait for some response from the receiver to know how much to send at once.
67  *
68  * shims -  Low-level shims required to send CAN messages, etc.
69  * handle - An IsoTpSendHandle previously returned by isotp_send(...).
70  * arbitration_id - The arbitration_id of the received CAN message.
71  * data - The data of the received CAN message.
72  * size - The size of the data in the received CAN message.
73  *
74  * Returns true if the message was completely sent, or the send was
75  *      otherwise cancelled. Check the 'success' field of the handle to see if
76  *      it was successful.
77  */
78 bool isotp_continue_send(IsoTpShims* shims, IsoTpSendHandle* handle,
79         const uint16_t arbitration_id, const uint8_t data[],
80         const uint8_t size);
81
82 #ifdef __cplusplus
83 }
84 #endif
85
86 #endif // __ISOTP_SEND_H__