#include <isotp/send.h>
+#include <bitfield/bitfield.h>
+#include <string.h>
#define PCI_NIBBLE_INDEX 0
#define PAYLOAD_LENGTH_NIBBLE_INDEX 1
}
}
-IsoTpHandle isotp_send_single_frame(IsoTpShims* shims, IsoTpMessage* message,
+IsoTpSendHandle isotp_send_single_frame(IsoTpShims* shims, IsoTpMessage* message,
IsoTpMessageSentHandler callback) {
- IsoTpHandle handle = {
+ IsoTpSendHandle handle = {
success: false,
- completed: true,
- type: ISOTP_HANDLE_SENDING
+ completed: true
};
uint8_t can_data[CAN_MESSAGE_BYTE_SIZE] = {0};
}
shims->send_can_message(message->arbitration_id, can_data,
- 1 + message->size);
+ shims->frame_padding ? 8 : 1 + message->size);
handle.success = true;
isotp_complete_send(shims, message, true, callback);
return handle;
}
-IsoTpHandle isotp_send_multi_frame(IsoTpShims* shims, IsoTpMessage* message,
+IsoTpSendHandle isotp_send_multi_frame(IsoTpShims* shims, IsoTpMessage* message,
IsoTpMessageSentHandler callback) {
// TODO make sure to copy message into a local buffer
shims->log("Only single frame messages are supported");
- IsoTpHandle handle = {
+ IsoTpSendHandle handle = {
success: false,
- completed: true,
- type: ISOTP_HANDLE_SENDING
+ completed: true
};
// TODO need to set sending and receiving arbitration IDs separately if we
// can't always just add 0x8 (and I think we can't)
return handle;
}
-IsoTpHandle isotp_send(IsoTpShims* shims, const uint16_t arbitration_id,
+IsoTpSendHandle isotp_send(IsoTpShims* shims, const uint16_t arbitration_id,
const uint8_t payload[], uint16_t size,
IsoTpMessageSentHandler callback) {
IsoTpMessage message = {
return isotp_send_multi_frame(shims, &message, callback);
}
}
+
+bool isotp_continue_send(IsoTpShims* shims, IsoTpSendHandle* handle,
+ const uint16_t arbitration_id, const uint8_t data[],
+ const uint8_t size) {
+ // TODO this will need to be tested when we add multi-frame support,
+ // which is when it'll be necessary to pass in CAN messages to SENDING
+ // handles.
+ if(handle->receiving_arbitration_id != arbitration_id) {
+ if(shims->log != NULL) {
+ shims->log("The arb ID 0x%x doesn't match the expected tx continuation ID 0x%x",
+ arbitration_id, handle->receiving_arbitration_id);
+ }
+ return false;
+ }
+ return false;
+}