Add skeleton tests for receiving and sending ISO-TP messages.
[apps/agl-service-can-low-level.git] / src / isotp / isotp.c
1 #include <isotp/isotp.h>
2
3 const uint16_t MAX_ISO_TP_MESSAGE_SIZE = 4096;
4 const uint16_t MAX_CAN_FRAME_SIZE = 8;
5 const uint8_t ISO_TP_DEFAULT_RESPONSE_TIMEOUT = 100;
6 const bool ISO_TP_DEFAULT_FRAME_PADDING_STATUS = true;
7
8 void isotp_receive_can_frame(const uint16_t arbitration_id, const uint8_t* data,
9         const uint8_t length) {
10     //match with any request we made
11     //handle flow control if necessary
12     //call callback if message completed
13 }
14
15 bool isotp_send(const uint8_t* payload, uint16_t payload_size) {
16      // we determine if it's single/multi frame and start the send
17 }
18
19 void isotp_set_timeout(IsoTpHandler* handler, uint16_t timeout_ms) {
20     handler->timeout_ms = timeout_ms;
21 }
22
23 IsoTpShims isotp_init_shims(LogShim log, SendCanMessageShim send_can_message,
24         SetTimerShim set_timer) {
25     IsoTpShims shims = {
26         log: log,
27         send_can_message: send_can_message,
28         set_timer: set_timer
29     };
30     return shims;
31 }
32
33 IsoTpHandler isotp_init(IsoTpShims* shims, uint16_t arbitration_id,
34         IsoTpMessageReceivedHandler message_received_callback,
35         IsoTpMessageSentHandler message_sent_callback,
36         IsoTpCanFrameSentHandler can_frame_sent_callback) {
37     IsoTpHandler handler = {
38         shims: shims,
39         message_received_callback: message_received_callback,
40         message_sent_callback: message_sent_callback,
41         can_frame_sent_callback: can_frame_sent_callback,
42         timeout_ms: ISO_TP_DEFAULT_RESPONSE_TIMEOUT,
43         frame_padding: ISO_TP_DEFAULT_FRAME_PADDING_STATUS,
44         sending: false
45     };
46     return handler;
47 }
48
49 // TODO this would be better as a "isotp_message_to_string"
50 void log_isotp_message(const uint16_t arbitration_id,
51         const uint8_t* payload, const uint16_t size) {
52     debug("ID: 0x%02x, Payload:", arbitration_id);
53     for(int i = 0; i < size; i++) {
54         debug("0x%x", payload[i]);
55     }
56 }