summaryrefslogtreecommitdiffstats
path: root/tests/common.c
diff options
context:
space:
mode:
authorChristopher Peplin <chris.peplin@rhubarbtech.com>2013-12-27 18:28:03 -0500
committerChristopher Peplin <chris.peplin@rhubarbtech.com>2013-12-27 18:28:53 -0500
commit34a7c0ca08683eb83d6b6b3d5a6a8fb2f7d5b918 (patch)
tree1efa4c1b7c206e06817ea3bd6e171647c67b3602 /tests/common.c
parent61344915dfdd01101d086b79b56109a9942cbf1a (diff)
Add skeleton tests for receiving and sending ISO-TP messages.
Diffstat (limited to 'tests/common.c')
-rw-r--r--tests/common.c86
1 files changed, 86 insertions, 0 deletions
diff --git a/tests/common.c b/tests/common.c
new file mode 100644
index 00000000..fb26c4af
--- /dev/null
+++ b/tests/common.c
@@ -0,0 +1,86 @@
+#include <isotp/isotp.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+
+IsoTpShims SHIMS;
+IsoTpHandler ISOTP_HANDLER;
+
+uint16_t last_can_frame_sent_arb_id;
+uint8_t last_can_payload_sent;
+uint8_t last_can_payload_size;
+bool can_frame_was_sent;
+
+bool message_was_received;
+uint16_t last_message_received_arb_id;
+uint8_t* last_message_received_payload;
+uint8_t last_message_received_payload_size;
+
+uint16_t last_message_sent_arb_id;
+bool last_message_sent_status;
+uint8_t* last_message_sent_payload;
+uint8_t last_message_sent_payload_size;
+
+void debug(const char* format, ...) {
+ va_list args;
+ va_start(args, format);
+ vprintf(format, args);
+ va_end(args);
+}
+
+void mock_send_can(const uint16_t arbitration_id, const uint8_t* data,
+ const uint8_t size) {
+}
+
+void mock_set_timer(uint16_t time_ms, void (*callback)) {
+}
+
+void message_received(const uint16_t arbitration_id, const uint8_t* payload,
+ const uint16_t size) {
+ debug("Received ISO-TP message:");
+ log_isotp_message(arbitration_id, payload, size);
+ last_message_received_arb_id = arbitration_id;
+ last_message_received_payload_size = size;
+ memcpy(last_message_received_payload, payload, size);
+}
+
+void message_sent(const bool success, const uint16_t arbitration_id,
+ const uint8_t* payload, const uint16_t size) {
+ if(success) {
+ debug("Sent ISO-TP message:");
+ } else {
+ debug("Unable to send ISO-TP message:");
+ }
+ log_isotp_message(arbitration_id, payload, size);
+
+ message_was_received = true;
+ last_message_sent_arb_id = arbitration_id;
+ last_message_sent_payload_size = size;
+ memcpy(last_message_sent_payload, payload, size);
+}
+
+void can_frame_sent(const uint16_t arbitration_id,
+ const uint8_t* payload, const uint8_t size) {
+ debug("Sent CAN Frame:");
+ log_isotp_message(arbitration_id, payload, size);
+ for(int i = 0; i < size; i++) {
+ debug("0x%x", payload[i]);
+ }
+
+ can_frame_was_sent = true;
+ last_can_frame_sent_arb_id = arbitration_id;
+ last_can_payload_sent = size;
+ memcpy(last_can_payload_sent, payload, size);
+}
+
+void setup() {
+ SHIMS = isotp_init_shims(debug, mock_send_can, mock_set_timer);
+ ISOTP_HANDLER = isotp_init(&SHIMS, 0x2a, message_received, message_sent,
+ can_frame_sent);
+ last_message_received_payload = malloc(MAX_ISO_TP_MESSAGE_SIZE);
+ last_message_sent_status = false;
+ message_was_received = false;
+ can_frame_was_sent = false;
+}
+