Skip to content

Commit

Permalink
update isotp-c to latest, fix sa defect in isotp_mock.c
Browse files Browse the repository at this point in the history
  • Loading branch information
driftregion committed Feb 7, 2025
1 parent b04d1f9 commit 2052d4d
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 21 deletions.
17 changes: 11 additions & 6 deletions src/tp/isotp-c/isotp.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ static int isotp_send_flow_control(const IsoTpLink* link, uint8_t flow_status, u
return ret;
}

static int isotp_send_single_frame(const IsoTpLink* link, uint32_t id) {
static int isotp_send_single_frame(const IsoTpLink* link, uint32_t) {

IsoTpCanMessage message;
int ret;
Expand Down Expand Up @@ -186,7 +186,7 @@ static int isotp_receive_first_frame(IsoTpLink *link, IsoTpCanMessage *message,

/* check data length */
payload_length = message->as.first_frame.FF_DL_high;
payload_length = (payload_length << 8) + message->as.first_frame.FF_DL_low;
payload_length = (uint16_t)(payload_length << 8) + message->as.first_frame.FF_DL_low;

/* should not use multiple frame transmition */
if (payload_length <= 7) {
Expand Down Expand Up @@ -269,8 +269,13 @@ int isotp_send_with_id(IsoTpLink *link, uint32_t id, const uint8_t payload[], ui

if (size > link->send_buf_size) {
isotp_user_debug("Message size too large. Increase ISO_TP_MAX_MESSAGE_SIZE to set a larger buffer\n");
char message[128];
sprintf(&message[0], "Attempted to send %d bytes; max size is %d!\n", size, link->send_buf_size);
const int32_t messageSize = 128;
char message[messageSize];
int32_t writtenChars = sprintf(&message[0], "Attempted to send %d bytes; max size is %d!\n", size, link->send_buf_size);

assert(writtenChars <= messageSize);
(void) writtenChars;

isotp_user_debug(message);
return ISOTP_RET_OVERFLOW;
}
Expand All @@ -284,7 +289,7 @@ int isotp_send_with_id(IsoTpLink *link, uint32_t id, const uint8_t payload[], ui
link->send_size = size;
link->send_offset = 0;
(void) memcpy(link->send_buffer, payload, size);

if (link->send_size < 8) {
/* send single frame */
ret = isotp_send_single_frame(link, id);
Expand All @@ -307,7 +312,7 @@ int isotp_send_with_id(IsoTpLink *link, uint32_t id, const uint8_t payload[], ui
return ret;
}

void isotp_on_can_message(IsoTpLink *link, const uint8_t *data, uint8_t len) {
void isotp_on_can_message(IsoTpLink* link, const uint8_t* data, uint8_t len) {
IsoTpCanMessage message;
int ret;

Expand Down
6 changes: 3 additions & 3 deletions src/tp/isotp-c/isotp.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef __ISOTP_H__
#define __ISOTP_H__
#ifndef ISOTPC_H
#define ISOTPC_H

#include <stdio.h>
#include <string.h>
Expand Down Expand Up @@ -130,5 +130,5 @@ int isotp_receive(IsoTpLink *link, uint8_t *payload, const uint16_t payload_size
}
#endif

#endif // __ISOTP_H__
#endif // ISOTPC_H

7 changes: 3 additions & 4 deletions src/tp/isotp-c/isotp_config.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef __ISOTP_CONFIG__
#define __ISOTP_CONFIG__
#ifndef ISOTPC_CONFIG_H
#define ISOTPC_CONFIG_H

/* Max number of messages the receiver can receive at one time, this value
* is affected by can driver queue length
Expand Down Expand Up @@ -36,5 +36,4 @@
*/
//#define ISO_TP_USER_SEND_CAN_ARG

#endif

#endif // ISOTPC_CONFIG_H
7 changes: 3 additions & 4 deletions src/tp/isotp-c/isotp_defines.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef __ISOTP_DEFINES_H__
#define __ISOTP_DEFINES_H__
#ifndef ISOTPC_USER_DEFINITIONS_H
#define ISOTPC_USER_DEFINITIONS_H

#include <stdint.h>

Expand Down Expand Up @@ -225,5 +225,4 @@ typedef enum {
#define ISOTP_PROTOCOL_RESULT_BUFFER_OVFLW -8
#define ISOTP_PROTOCOL_RESULT_ERROR -9

#endif

#endif // ISOTPC_USER_DEFINITIONS_H
6 changes: 3 additions & 3 deletions src/tp/isotp-c/isotp_user.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef __ISOTP_USER_H__
#define __ISOTP_USER_H__
#ifndef ISOTPC_USER_H
#define ISOTPC_USER_H

#include <stdint.h>

Expand Down Expand Up @@ -32,5 +32,5 @@ uint32_t isotp_user_get_us(void);
}
#endif

#endif // __ISOTP_H__
#endif // ISOTPC_USER_H

2 changes: 1 addition & 1 deletion src/tp/isotp_mock.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ UDSTp_t *ISOTPMockNew(const char *name, ISOTPMockArgs_t *args) {
if (name) {
strncpy(tp->name, name, sizeof(tp->name));
} else {
snprintf(tp->name, sizeof(tp->name), "TPMock%d", TPCount);
snprintf(tp->name, sizeof(tp->name), "TPMock%u", TPCount);
}
ISOTPMockAttach(tp, args);
return &tp->hdl;
Expand Down

0 comments on commit 2052d4d

Please sign in to comment.