1 #include <isotp/receive.h>
2 #include <bitfield/bitfield.h>
5 static void isotp_complete_receive(IsoTpReceiveHandle* handle, IsoTpMessage* message) {
6 if(handle->message_received_callback != NULL) {
7 handle->message_received_callback(message);
11 bool isotp_handle_single_frame(IsoTpReceiveHandle* handle, IsoTpMessage* message) {
12 isotp_complete_receive(handle, message);
16 IsoTpReceiveHandle isotp_receive(IsoTpShims* shims,
17 const uint16_t arbitration_id, IsoTpMessageReceivedHandler callback) {
18 IsoTpReceiveHandle handle = {
21 arbitration_id: arbitration_id,
22 message_received_callback: callback
28 IsoTpMessage isotp_continue_receive(IsoTpShims* shims,
29 IsoTpReceiveHandle* handle, const uint16_t arbitration_id,
30 const uint8_t data[], const uint8_t size) {
31 IsoTpMessage message = {
32 arbitration_id: arbitration_id,
42 if(handle->arbitration_id != arbitration_id) {
43 if(shims->log != NULL) {
44 shims->log("The arb ID 0x%x doesn't match the expected rx ID 0x%x",
45 arbitration_id, handle->arbitration_id);
50 IsoTpProtocolControlInformation pci = (IsoTpProtocolControlInformation)
51 get_nibble(data, size, 0);
53 uint8_t payload_length = get_nibble(data, size, 1);
54 uint8_t payload[payload_length];
55 if(payload_length > 0 && size > 0) {
56 memcpy(payload, &data[1], payload_length);
59 // TODO this is set up to handle rx a response with a payload, but not to
60 // handle flow control responses for multi frame messages that we're in the
65 if(payload_length > 0) {
66 memcpy(message.payload, payload, payload_length);
68 message.size = payload_length;
69 message.completed = true;
70 handle->success = true;
71 handle->completed = true;
72 isotp_handle_single_frame(handle, &message);
76 shims->log("Only single frame messages are supported");