11 const uint16_t MAX_ISO_TP_MESSAGE_SIZE;
12 const uint16_t MAX_CAN_FRAME_SIZE;
13 const uint8_t ISO_TP_DEFAULT_RESPONSE_TIMEOUT;
14 const bool ISO_TP_DEFAULT_FRAME_PADDING_STATUS;
16 typedef void (*LogShim)(const char* message);
17 typedef bool (*SendCanMessageShim)(const uint16_t arbitration_id,
18 const uint8_t* data, const uint8_t size);
19 typedef bool (*SetTimerShim)(uint16_t time_ms, void (*callback));
21 typedef void (*IsoTpMessageReceivedHandler)(const uint16_t arbitration_id,
22 const uint8_t* payload, const uint16_t size);
23 typedef void (*IsoTpMessageSentHandler)(const uint16_t arbitration_id,
24 const uint8_t* payload, const uint16_t size, const bool success);
25 typedef void (*IsoTpCanFrameSentHandler)(const uint16_t arbitration_id,
26 const uint8_t* payload, const uint8_t size);
28 // TODO this is really necessary and it would leak this library into the user's
31 // const uint16_t arbitration_id;
32 // const uint8_t* payload;
33 // const uint16_t size;
38 SendCanMessageShim send_can_message;
39 SetTimerShim set_timer;
44 uint16_t arbitration_id;
45 IsoTpMessageReceivedHandler message_received_callback;
46 IsoTpMessageSentHandler message_sent_callback;
47 IsoTpCanFrameSentHandler can_frame_sent_callback;
52 uint8_t* receive_buffer;
53 uint16_t received_buffer_size;
54 uint16_t incoming_message_size;
56 // TODO timer callback
61 PCI_FIRST_FRAME = 0x1,
62 PCI_CONSECUTIVE_FRAME = 0x2,
63 PCI_FLOW_CONTROL_FRAME = 0x3
64 } IsoTpProtocolControlInformation;
67 PCI_FLOW_STATUS_CONTINUE = 0x0,
68 PCI_FLOW_STATUS_WAIT = 0x1,
69 PCI_FLOW_STATUS_OVERFLOW = 0x2
72 IsoTpShims isotp_init_shims(LogShim log,
73 SendCanMessageShim send_can_message,
74 SetTimerShim set_timer);
76 IsoTpHandler isotp_init(IsoTpShims* shims,
77 uint16_t arbitration_id,
78 IsoTpMessageReceivedHandler message_received_callback,
79 IsoTpMessageSentHandler message_sent_callback,
80 IsoTpCanFrameSentHandler can_frame_sent_callback);
82 /* Public: Change the timeout for waiting on an ISO-TP response frame.
84 * If this function is not used, the conventional 100ms is used by default.
86 * handler - the ISO-TP handler to modify.
87 * timeout - the new timeout in milliseconds.
89 void isotp_set_timeout(IsoTpHandler* handler, uint16_t timeout_ms);
91 // TODO we have to make sure to copy the payload internall if it's more than 1
92 // frame, the soure could go out of scope
93 bool isotp_send(IsoTpHandler* handler, const uint8_t* payload,
94 uint16_t payload_size);
96 void isotp_receive_can_frame(IsoTpHandler* handler,
97 const uint16_t arbitration_id, const uint64_t data,
98 const uint8_t length);
100 void isotp_destroy(IsoTpHandler* handler);
102 void log_isotp_message(const uint16_t arbitration_id, const uint8_t* payload,
103 const uint16_t size);
110 #endif // __ISOTP_H__