Sketch out the API and add some notes.
[apps/agl-service-can-low-level.git] / src / isotp / isotp.h
1 #ifndef __ISOTP_H__
2 #define __ISOTP_H__
3
4 #ifdef __cplusplus
5 extern "C" {
6 #endif
7
8 struct {
9     uint16_t arb_id;
10     void* message_received_callback;
11     void* message_sent_callback;
12     void* can_frame_sent_callback;
13
14     // Private
15     uint16_t timeout_ms;
16     bool framePadding;
17     uint8_t* receive_buffer;
18     uint16_t received_buffer_size;
19     uint16_t incoming_message_size;
20     bool sending;
21     // TODO timer
22 } IsoTpHandler;
23
24 enum {
25     PCI_SINGLE,
26     PCI_FIRST_FRAME,
27     PCI_CONSECUTIVE_FRAME,
28     PCI_FLOW_CONTROL_FRAME
29 } IsoTpProtocolControlInformation;
30
31 enum {
32     PCI_FLOW_STATUS_CONTINUE,
33     PCI_FLOW_STATUS_WAIT,
34     PCI_FLOW_STATUS_OVERFLOW
35 } IsoTpFlowStatus;
36
37 const uint16_t MAX_ISO_TP_MESSAGE_SIZE = 4096;
38 const uint16_t MAX_CAN_FRAME_SIZE = 8;
39 const uint8_t ISO_TP_DEFAULT_RESPONSE_TIMEOUT = 100;
40 const bool ISO_TP_DEFAULT_FRAME_PADDING_STATUS = true;
41
42 IsoTpHandler isotp_init(uint16_t arbitration_id,
43         IsoTpMessageReceivedHandler* message_received_callback,
44         IsoTpMessageSentHandler* message_sent_callback,
45         IsoTpCanFrameSentHandler* can_frame_sent_callback);
46
47 void isotp_set_timeout(uint16_t timeout);
48
49 // TODO we have to make sure to copy the payload internall if it's more than 1
50 // frame, the soure could go out of scope
51 bool isotp_send(const uint8_t* payload, uint16_t payload_size);
52
53 void isotp_receive_can_frame(const uint16_t arbitration_id, const uint8_t* data,
54         const uint8_t length);
55
56 void isotp_destroy(IsoTpHandler* handler);
57
58 #ifdef __cplusplus
59 }
60 #endif
61
62 #endif // __ISOTP_H__