Draft implemenation of receiving and parsing single fram diag messages.
[apps/agl-service-can-low-level.git] / tests / common.c
1 #include <obd2/obd2.h>
2 #include <stdint.h>
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <stdarg.h>
6
7 DiagnosticShims SHIMS;
8
9 uint16_t last_can_frame_sent_arb_id;
10 uint8_t last_can_payload_sent[8];
11 uint8_t last_can_payload_size;
12 bool can_frame_was_sent;
13
14 DiagnosticResponse last_response_received;
15 bool last_response_was_received;
16
17 void debug(const char* format, ...) {
18     va_list args;
19     va_start(args, format);
20     vprintf(format, args);
21     printf("\r\n");
22     va_end(args);
23 }
24
25 void mock_send_can(const uint16_t arbitration_id, const uint8_t* data,
26         const uint8_t size) {
27     can_frame_was_sent = true;
28     last_can_frame_sent_arb_id = arbitration_id;
29     last_can_payload_size = size;
30     if(size > 0) {
31         memcpy(last_can_payload_sent, data, size);
32     }
33 }
34
35 void mock_set_timer(uint16_t time_ms, void (*callback)) {
36 }
37
38 void setup() {
39     SHIMS = diagnostic_init_shims(debug, mock_send_can, mock_set_timer);
40     memset(last_can_payload_sent, 0, sizeof(last_can_payload_sent));
41     can_frame_was_sent = false;
42     last_response_was_received = false;
43 }
44