summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorChristopher Peplin <chris.peplin@rhubarbtech.com>2014-01-01 16:08:10 -0500
committerChristopher Peplin <chris.peplin@rhubarbtech.com>2014-01-01 16:10:57 -0500
commit482c7eafcb35a4031ab6f2241b14ac495735b7cd (patch)
tree8fdff5d9e5ae49df5ed0909dfdb8fc628674ed80 /src
parent8702b34a8ffdf220c9b054d8f1950a82c9387d6a (diff)
Return completed rx messages instead of relying on callbacks.
Diffstat (limited to 'src')
-rw-r--r--src/isotp/isotp.c28
-rw-r--r--src/isotp/isotp.h14
-rw-r--r--src/isotp/receive.c1
-rw-r--r--src/isotp/send.c2
-rw-r--r--src/isotp/send.h3
5 files changed, 22 insertions, 26 deletions
diff --git a/src/isotp/isotp.c b/src/isotp/isotp.c
index f7189d2b..9aa051bc 100644
--- a/src/isotp/isotp.c
+++ b/src/isotp/isotp.c
@@ -33,26 +33,29 @@ void isotp_message_to_string(const IsoTpMessage* message, char* destination,
message->arbitration_id, payload_string);
}
-bool isotp_receive_can_frame(IsoTpShims* shims, IsoTpHandle* handle,
+IsoTpMessage isotp_receive_can_frame(IsoTpShims* shims, IsoTpHandle* handle,
const uint16_t arbitration_id, const uint8_t data[],
const uint8_t data_length) {
- bool message_completed = false;
+ IsoTpMessage message = {
+ arbitration_id: arbitration_id,
+ completed: false
+ };
if(data_length < 1) {
- return message_completed;
+ return message;
}
if(handle->type == ISOTP_HANDLE_RECEIVING) {
if(handle->receive_handle.arbitration_id != arbitration_id) {
- return message_completed;
+ return message;
}
} else if(handle->type == ISOTP_HANDLE_SENDING) {
if(handle->send_handle.receiving_arbitration_id != arbitration_id) {
- return message_completed;
+ return message;
}
} else {
shims->log("The ISO-TP handle is corrupt");
- return message_completed;
+ return message;
}
IsoTpProtocolControlInformation pci = (IsoTpProtocolControlInformation)
@@ -70,18 +73,15 @@ bool isotp_receive_can_frame(IsoTpShims* shims, IsoTpHandle* handle,
switch(pci) {
case PCI_SINGLE: {
- IsoTpMessage message = {
- arbitration_id: arbitration_id,
- payload: payload,
- size: payload_length
- };
-
- message_completed = isotp_handle_single_frame(handle, &message);
+ message.payload = payload;
+ message.size = payload_length;
+ message.completed = true;
+ isotp_handle_single_frame(handle, &message);
break;
}
default:
shims->log("Only single frame messages are supported");
break;
}
- return message_completed;
+ return message;
}
diff --git a/src/isotp/isotp.h b/src/isotp/isotp.h
index 4f58dac4..103c402d 100644
--- a/src/isotp/isotp.h
+++ b/src/isotp/isotp.h
@@ -18,8 +18,9 @@ const bool ISO_TP_DEFAULT_FRAME_PADDING_STATUS;
typedef struct {
const uint16_t arbitration_id;
- const uint8_t* payload;
- const uint16_t size;
+ uint8_t* payload;
+ uint16_t size;
+ bool completed;
} IsoTpMessage;
typedef void (*LogShim)(const char* message, ...);
@@ -95,11 +96,8 @@ IsoTpShims isotp_init_shims(LogShim log,
/* Public:
*
- * Returns true if a complete ISO-TP message was sent or received as of
- * processing this CAN frame. Check the 'success' and 'completed' flag on the
- * handle to make sure.
*/
-bool isotp_receive_can_frame(IsoTpShims* shims, IsoTpHandle* handle,
+IsoTpMessage isotp_receive_can_frame(IsoTpShims* shims, IsoTpHandle* handle,
const uint16_t arbitration_id, const uint8_t data[],
const uint8_t size);
@@ -121,8 +119,8 @@ IsoTpHandle isotp_send(IsoTpShims* shims, const uint16_t arbitration_id,
const uint8_t* payload, uint16_t size,
IsoTpMessageSentHandler callback);
-IsoTpHandle isotp_receive(IsoTpShims* shims, const uint16_t arbitration_id,
- IsoTpMessageReceivedHandler callback);
+IsoTpHandle 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 e69c59b7..fa96156d 100644
--- a/src/isotp/receive.c
+++ b/src/isotp/receive.c
@@ -24,4 +24,3 @@ IsoTpHandle isotp_receive(IsoTpShims* shims,
};
return handle;
}
-
diff --git a/src/isotp/send.c b/src/isotp/send.c
index 67703cae..6cce5c92 100644
--- a/src/isotp/send.c
+++ b/src/isotp/send.c
@@ -49,6 +49,8 @@ IsoTpHandle isotp_send_multi_frame(IsoTpShims* shims, IsoTpMessage* message,
completed: true,
type: ISOTP_HANDLE_SENDING
};
+ // 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;
}
diff --git a/src/isotp/send.h b/src/isotp/send.h
index 937e5320..8f707b29 100644
--- a/src/isotp/send.h
+++ b/src/isotp/send.h
@@ -9,9 +9,6 @@
extern "C" {
#endif
-IsoTpHandle isotp_send(IsoTpShims* shims, const uint16_t arbitration_id,
- const uint8_t* payload, uint16_t size,
- IsoTpMessageSentHandler callback);
#ifdef __cplusplus
}