diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/isotp/isotp.c | 28 | ||||
-rw-r--r-- | src/isotp/isotp.h | 19 | ||||
-rw-r--r-- | src/isotp/receive.c | 7 | ||||
-rw-r--r-- | src/isotp/receive.h | 19 |
4 files changed, 59 insertions, 14 deletions
diff --git a/src/isotp/isotp.c b/src/isotp/isotp.c index da7fa29d..597ffe9d 100644 --- a/src/isotp/isotp.c +++ b/src/isotp/isotp.c @@ -1,15 +1,32 @@ #include <isotp/isotp.h> +#include <isotp/receive.h> +#include <bitfield/bitfield.h> const uint16_t MAX_ISO_TP_MESSAGE_SIZE = 4096; const uint16_t MAX_CAN_FRAME_SIZE = 8; const uint8_t ISO_TP_DEFAULT_RESPONSE_TIMEOUT = 100; const bool ISO_TP_DEFAULT_FRAME_PADDING_STATUS = true; -void isotp_receive_can_frame(const uint16_t arbitration_id, const uint8_t* data, - const uint8_t length) { - //match with any request we made - //handle flow control if necessary - //call callback if message completed +void isotp_receive_can_frame(IsoTpHandler* handler, + const uint16_t arbitration_id, const uint8_t* data, const uint8_t length) { + if(arbitration_id != handler->arbitration_id){ + return; + } + + // TODO use CanMessage struct from canutil library - allocate payload buffer + // on stack, 8 bytes + // TODO this function should receive uint64_t... + IsoTpProtocolControlInformation pci = (IsoTpProtocolControlInformation) + getBitField((uint64_t)data, 0, 2, false); + + switch(pci) { + case PCI_SINGLE: + isotp_handle_single_frame(handler, arbitration_id, data, length); + break; + default: + handler->shims->log("Only single frame messages are supported"); + break; + } } bool isotp_send(const uint8_t* payload, uint16_t payload_size) { @@ -36,6 +53,7 @@ IsoTpHandler isotp_init(IsoTpShims* shims, uint16_t arbitration_id, IsoTpCanFrameSentHandler can_frame_sent_callback) { IsoTpHandler handler = { shims: shims, + arbitration_id: arbitration_id, message_received_callback: message_received_callback, message_sent_callback: message_sent_callback, can_frame_sent_callback: can_frame_sent_callback, diff --git a/src/isotp/isotp.h b/src/isotp/isotp.h index c500f6e3..089ecbc0 100644 --- a/src/isotp/isotp.h +++ b/src/isotp/isotp.h @@ -42,7 +42,7 @@ typedef struct { typedef struct { IsoTpShims* shims; - uint16_t arb_id; + uint16_t arbitration_id; IsoTpMessageReceivedHandler message_received_callback; IsoTpMessageSentHandler message_sent_callback; IsoTpCanFrameSentHandler can_frame_sent_callback; @@ -58,16 +58,16 @@ typedef struct { } IsoTpHandler; typedef enum { - PCI_SINGLE, - PCI_FIRST_FRAME, - PCI_CONSECUTIVE_FRAME, - PCI_FLOW_CONTROL_FRAME + PCI_SINGLE = 0x0, + PCI_FIRST_FRAME = 0x1, + PCI_CONSECUTIVE_FRAME = 0x2, + PCI_FLOW_CONTROL_FRAME = 0x3 } IsoTpProtocolControlInformation; typedef enum { - PCI_FLOW_STATUS_CONTINUE, - PCI_FLOW_STATUS_WAIT, - PCI_FLOW_STATUS_OVERFLOW + PCI_FLOW_STATUS_CONTINUE = 0x0, + PCI_FLOW_STATUS_WAIT = 0x1, + PCI_FLOW_STATUS_OVERFLOW = 0x2 } IsoTpFlowStatus; IsoTpShims isotp_init_shims(LogShim log, @@ -93,7 +93,8 @@ void isotp_set_timeout(IsoTpHandler* handler, uint16_t timeout_ms); // frame, the soure could go out of scope bool isotp_send(const uint8_t* payload, uint16_t payload_size); -void isotp_receive_can_frame(const uint16_t arbitration_id, const uint8_t* data, +void isotp_receive_can_frame(IsoTpHandler* handler, + const uint16_t arbitration_id, const uint8_t* data, const uint8_t length); void isotp_destroy(IsoTpHandler* handler); diff --git a/src/isotp/receive.c b/src/isotp/receive.c new file mode 100644 index 00000000..9add9d5f --- /dev/null +++ b/src/isotp/receive.c @@ -0,0 +1,7 @@ +#include <isotp/receive.h> + +void isotp_handle_single_frame(IsoTpHandler* handler, + const uint16_t arbitration_id, const uint8_t* data, + const uint8_t length) { + handler->message_received_callback(arbitration_id, data, length); +} diff --git a/src/isotp/receive.h b/src/isotp/receive.h new file mode 100644 index 00000000..f7d6c61f --- /dev/null +++ b/src/isotp/receive.h @@ -0,0 +1,19 @@ +#ifndef __ISOTP_RECEIVE_H__ +#define __ISOTP_RECEIVE_H__ + +#include <isotp/isotp.h> +#include <stdint.h> +#include <stdbool.h> + +#ifdef __cplusplus +extern "C" { +#endif + +void isotp_handle_single_frame(IsoTpHandler* handler, const uint16_t arbitration_id, + const uint8_t* data, const uint8_t length); + +#ifdef __cplusplus +} +#endif + +#endif // __ISOTP_RECEIVE_H__ |