Don't use debug function directly in library.
[apps/agl-service-can-low-level.git] / src / isotp / isotp.c
1 #include <isotp/isotp.h>
2 #include <isotp/receive.h>
3 #include <bitfield/bitfield.h>
4
5 const uint16_t MAX_ISO_TP_MESSAGE_SIZE = 4096;
6 const uint16_t MAX_CAN_FRAME_SIZE = 8;
7 const uint8_t ISO_TP_DEFAULT_RESPONSE_TIMEOUT = 100;
8 const bool ISO_TP_DEFAULT_FRAME_PADDING_STATUS = true;
9
10
11 void isotp_set_timeout(IsoTpHandler* handler, uint16_t timeout_ms) {
12     handler->timeout_ms = timeout_ms;
13 }
14
15 IsoTpShims isotp_init_shims(LogShim log, SendCanMessageShim send_can_message,
16         SetTimerShim set_timer) {
17     IsoTpShims shims = {
18         log: log,
19         send_can_message: send_can_message,
20         set_timer: set_timer
21     };
22     return shims;
23 }
24
25 IsoTpHandler isotp_init(IsoTpShims* shims, uint16_t arbitration_id,
26         IsoTpMessageReceivedHandler message_received_callback,
27         IsoTpMessageSentHandler message_sent_callback,
28         IsoTpCanFrameSentHandler can_frame_sent_callback) {
29     IsoTpHandler handler = {
30         shims: shims,
31         arbitration_id: arbitration_id,
32         message_received_callback: message_received_callback,
33         message_sent_callback: message_sent_callback,
34         can_frame_sent_callback: can_frame_sent_callback,
35         timeout_ms: ISO_TP_DEFAULT_RESPONSE_TIMEOUT,
36         frame_padding: ISO_TP_DEFAULT_FRAME_PADDING_STATUS,
37         sending: false
38     };
39     return handler;
40 }
41
42 void isotp_message_to_string(const IsoTpMessage* message, char* destination,
43         size_t destination_length) {
44     snprintf(destination, destination_length,"ID: 0x%02x, Payload: 0x%llx",
45             // TODO the payload may be backwards here
46             message->arbitration_id, message->payload);
47 }