diff options
-rw-r--r-- | src/isotp/isotp.c | 16 | ||||
-rw-r--r-- | src/isotp/isotp.h | 7 | ||||
-rw-r--r-- | tests/common.c | 8 |
3 files changed, 15 insertions, 16 deletions
diff --git a/src/isotp/isotp.c b/src/isotp/isotp.c index 7c12d430..f303e214 100644 --- a/src/isotp/isotp.c +++ b/src/isotp/isotp.c @@ -39,15 +39,9 @@ IsoTpHandler isotp_init(IsoTpShims* shims, uint16_t arbitration_id, return handler; } -// TODO this would be better as a "isotp_message_to_string" -void log_isotp_message(const IsoTpMessage* message) { - debug("ID: 0x%02x", message->arbitration_id); - if(message->size > 0) { - debug("Payload:"); - for(int i = 0; i < message->size; i++) { - debug("0x%x", message->payload[i]); - } - } else { - debug("(no payload)"); - } +void isotp_message_to_string(const IsoTpMessage* message, char* destination, + size_t destination_length) { + snprintf(destination, destination_length,"ID: 0x%02x, Payload: 0x%llx", + // TODO the payload may be backwards here + message->arbitration_id, message->payload); } diff --git a/src/isotp/isotp.h b/src/isotp/isotp.h index 619dcc69..74a4897a 100644 --- a/src/isotp/isotp.h +++ b/src/isotp/isotp.h @@ -3,6 +3,7 @@ #include <stdint.h> #include <stdbool.h> +#include <stdio.h> #define CAN_MESSAGE_BYTE_SIZE 8 @@ -21,7 +22,7 @@ typedef struct { const uint16_t size; } IsoTpMessage; -typedef void (*LogShim)(const char* message); +typedef void (*LogShim)(const char* message, ...); typedef bool (*SendCanMessageShim)(const uint16_t arbitration_id, const uint8_t* data, const uint8_t size); typedef bool (*SetTimerShim)(uint16_t time_ms, void (*callback)); @@ -88,8 +89,8 @@ void isotp_set_timeout(IsoTpHandler* handler, uint16_t timeout_ms); void isotp_destroy(IsoTpHandler* handler); -void log_isotp_message(const IsoTpMessage* message); - +void isotp_message_to_string(const IsoTpMessage* message, char* destination, + size_t destination_length); #ifdef __cplusplus } diff --git a/tests/common.c b/tests/common.c index 4c6a40ff..833a5ed4 100644 --- a/tests/common.c +++ b/tests/common.c @@ -46,7 +46,9 @@ void mock_set_timer(uint16_t time_ms, void (*callback)) { void message_received(const IsoTpMessage* message) { debug("Received ISO-TP message:"); message_was_received = true; - log_isotp_message(message); + char str_message[24]; + isotp_message_to_string(message, str_message, sizeof(str_message)); + debug("%s", str_message); last_message_received_arb_id = message->arbitration_id; last_message_received_payload_size = message->size; if(message->size > 0) { @@ -60,7 +62,9 @@ void message_sent(const IsoTpMessage* message, const bool success) { } else { debug("Unable to send ISO-TP message:"); } - log_isotp_message(message); + char str_message[24] = {0}; + isotp_message_to_string(message, str_message, sizeof(str_message)); + debug("%s", str_message); last_message_sent_arb_id = message->arbitration_id; last_message_sent_payload_size = message->size; |