summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorChristopher Peplin <chris.peplin@rhubarbtech.com>2014-01-03 13:40:02 -0500
committerChristopher Peplin <chris.peplin@rhubarbtech.com>2014-01-03 13:40:02 -0500
commit330358c978ea3d324740a8dba884c4493fa339b8 (patch)
tree405c6f572531e5624bb15da16bc73da99035503e /src
parent99dd20fc3d6c14d9e8af65264ad712ca6718dcdd (diff)
Split up functions to rx CAN messages for rx and tx of ISO-TP.
Diffstat (limited to 'src')
-rw-r--r--src/isotp/isotp.c55
-rw-r--r--src/isotp/isotp.h36
-rw-r--r--src/isotp/receive.c20
-rw-r--r--src/isotp/receive.h4
-rw-r--r--src/isotp/send.c16
5 files changed, 57 insertions, 74 deletions
diff --git a/src/isotp/isotp.c b/src/isotp/isotp.c
index e233d386..6de40c31 100644
--- a/src/isotp/isotp.c
+++ b/src/isotp/isotp.c
@@ -33,9 +33,9 @@ void isotp_message_to_string(const IsoTpMessage* message, char* destination,
message->payload[7]);
}
-IsoTpMessage isotp_receive_can_frame(IsoTpShims* shims, IsoTpHandle* handle,
- const uint16_t arbitration_id, const uint8_t data[],
- const uint8_t data_length) {
+IsoTpMessage isotp_continue_receive(IsoTpShims* shims,
+ IsoTpReceiveHandle* handle, const uint16_t arbitration_id,
+ const uint8_t data[], const uint8_t size) {
IsoTpMessage message = {
arbitration_id: arbitration_id,
completed: false,
@@ -43,40 +43,24 @@ IsoTpMessage isotp_receive_can_frame(IsoTpShims* shims, IsoTpHandle* handle,
size: 0
};
- if(data_length < 1) {
+ if(size < 1) {
return message;
}
- if(handle->type == ISOTP_HANDLE_RECEIVING) {
- if(handle->receive_handle.arbitration_id != arbitration_id) {
- if(shims->log != NULL) {
- shims->log("The arb ID 0x%x doesn't match the expected rx ID 0x%x",
- arbitration_id, handle->receive_handle.arbitration_id);
- }
- return message;
+ if(handle->arbitration_id != arbitration_id) {
+ if(shims->log != NULL) {
+ shims->log("The arb ID 0x%x doesn't match the expected rx ID 0x%x",
+ arbitration_id, handle->arbitration_id);
}
- } else if(handle->type == ISOTP_HANDLE_SENDING) {
- // 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->send_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->send_handle.receiving_arbitration_id);
- }
- return message;
- }
- } else {
- shims->log("The ISO-TP handle is corrupt");
return message;
}
IsoTpProtocolControlInformation pci = (IsoTpProtocolControlInformation)
- get_nibble(data, data_length, 0);
+ get_nibble(data, size, 0);
- uint8_t payload_length = get_nibble(data, data_length, 1);
+ uint8_t payload_length = get_nibble(data, size, 1);
uint8_t payload[payload_length];
- if(payload_length > 0 && data_length > 0) {
+ if(payload_length > 0 && size > 0) {
memcpy(payload, &data[1], payload_length);
}
@@ -102,3 +86,20 @@ IsoTpMessage isotp_receive_can_frame(IsoTpShims* shims, IsoTpHandle* handle,
}
return message;
}
+
+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;
+}
+
diff --git a/src/isotp/isotp.h b/src/isotp/isotp.h
index adf0f247..f4ffa371 100644
--- a/src/isotp/isotp.h
+++ b/src/isotp/isotp.h
@@ -43,6 +43,8 @@ typedef struct {
} IsoTpShims;
typedef struct {
+ bool success;
+ bool completed;
uint16_t arbitration_id;
IsoTpMessageReceivedHandler message_received_callback;
@@ -54,15 +56,16 @@ typedef struct {
uint8_t* receive_buffer;
uint16_t received_buffer_size;
uint16_t incoming_message_size;
- // TODO timer callback
+ // TODO timer callback for multi frame
} IsoTpReceiveHandle;
typedef struct {
+ bool success;
+ bool completed;
uint16_t sending_arbitration_id;
uint16_t receiving_arbitration_id;
IsoTpMessageSentHandler message_sent_callback;
IsoTpCanFrameSentHandler can_frame_sent_callback;
-
// TODO going to need some state here for multi frame messages
} IsoTpSendHandle;
@@ -71,15 +74,6 @@ typedef enum {
ISOTP_HANDLE_RECEIVING
} IsoTpHandleType;
-typedef struct {
- bool success;
- bool completed;
- IsoTpHandleType type;
- IsoTpReceiveHandle receive_handle;
- IsoTpSendHandle send_handle;
-} IsoTpHandle;
-
-
typedef enum {
PCI_SINGLE = 0x0,
PCI_FIRST_FRAME = 0x1,
@@ -97,18 +91,14 @@ IsoTpShims isotp_init_shims(LogShim log,
SendCanMessageShim send_can_message,
SetTimerShim set_timer);
-/* Public:
- *
- */
-IsoTpMessage isotp_receive_can_frame(IsoTpShims* shims, IsoTpHandle* handle,
+IsoTpMessage isotp_continue_receive(IsoTpShims* shims,
+ IsoTpReceiveHandle* handle, const uint16_t arbitration_id,
+ const uint8_t data[], const uint8_t size);
+
+bool isotp_continue_send(IsoTpShims* shims, IsoTpSendHandle* handle,
const uint16_t arbitration_id, const uint8_t data[],
const uint8_t size);
-// TODO perhaps this makes more sense as 2 functions:
-// bool isotp_continue_send()
-// IsoTpMessage isotp_continue_receive()
-// but both with the same args
-
/* Public: Change the timeout for waiting on an ISO-TP response frame.
*
* If this function is not used, the conventional 100ms is used by default.
@@ -118,16 +108,14 @@ IsoTpMessage isotp_receive_can_frame(IsoTpShims* shims, IsoTpHandle* handle,
*/
// void isotp_set_timeout(IsoTpHandler* handler, uint16_t timeout_ms);
-// void isotp_destroy(IsoTpHandler* handler);
-
void isotp_message_to_string(const IsoTpMessage* message, char* destination,
size_t destination_length);
-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);
-IsoTpHandle isotp_receive(IsoTpShims* shims,
+IsoTpReceiveHandle isotp_receive(IsoTpShims* shims,
const uint16_t arbitration_id, IsoTpMessageReceivedHandler callback);
#ifdef __cplusplus
diff --git a/src/isotp/receive.c b/src/isotp/receive.c
index b07950c5..3eba9b53 100644
--- a/src/isotp/receive.c
+++ b/src/isotp/receive.c
@@ -1,28 +1,24 @@
#include <isotp/receive.h>
-bool isotp_handle_single_frame(IsoTpHandle* handle, IsoTpMessage* message) {
+bool isotp_handle_single_frame(IsoTpReceiveHandle* handle, IsoTpMessage* message) {
isotp_complete_receive(handle, message);
return true;
}
-void isotp_complete_receive(IsoTpHandle* handle, IsoTpMessage* message) {
- if(handle->receive_handle.message_received_callback != NULL) {
- handle->receive_handle.message_received_callback(message);
+void isotp_complete_receive(IsoTpReceiveHandle* handle, IsoTpMessage* message) {
+ if(handle->message_received_callback != NULL) {
+ handle->message_received_callback(message);
}
}
-IsoTpHandle isotp_receive(IsoTpShims* shims,
+IsoTpReceiveHandle isotp_receive(IsoTpShims* shims,
const uint16_t arbitration_id, IsoTpMessageReceivedHandler callback) {
- IsoTpReceiveHandle receive_handle = {
+ IsoTpReceiveHandle handle = {
+ success: false,
+ completed: false,
arbitration_id: arbitration_id,
message_received_callback: callback
};
- IsoTpHandle handle = {
- success: false,
- completed: false,
- receive_handle: receive_handle,
- type: ISOTP_HANDLE_RECEIVING
- };
return handle;
}
diff --git a/src/isotp/receive.h b/src/isotp/receive.h
index b01e12de..f43d32e2 100644
--- a/src/isotp/receive.h
+++ b/src/isotp/receive.h
@@ -9,9 +9,9 @@
extern "C" {
#endif
-void isotp_complete_receive(IsoTpHandle* handle, IsoTpMessage* message);
+void isotp_complete_receive(IsoTpReceiveHandle* handle, IsoTpMessage* message);
-bool isotp_handle_single_frame(IsoTpHandle* handle, IsoTpMessage* message);
+bool isotp_handle_single_frame(IsoTpReceiveHandle* handle, IsoTpMessage* message);
#ifdef __cplusplus
}
diff --git a/src/isotp/send.c b/src/isotp/send.c
index b87c5602..dfba1df3 100644
--- a/src/isotp/send.c
+++ b/src/isotp/send.c
@@ -11,12 +11,11 @@ void isotp_complete_send(IsoTpShims* shims, IsoTpMessage* message,
}
}
-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};
@@ -42,21 +41,20 @@ IsoTpHandle isotp_send_single_frame(IsoTpShims* shims, IsoTpMessage* message,
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 = {