Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix calls to printf #39

Merged
merged 1 commit into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ static const char *ClientStateName(enum UDSClientRequestState state) {
}

static void changeState(UDSClient_t *client, enum UDSClientRequestState state) {
printf("client state: %s (%d) -> %s (%d)\n", ClientStateName(client->state), client->state,
UDS_DBG_PRINT("client state: %s (%d) -> %s (%d)\n", ClientStateName(client->state), client->state,
ClientStateName(state), state);
client->state = state;
}
Expand Down Expand Up @@ -212,7 +212,7 @@ static void PollLowLevel(UDSClient_t *client) {
changeState(client, kRequestStateIdle);
}
} else {
printf("received %zd bytes\n", len);
UDS_DBG_PRINT("received %zd bytes\n", len);
client->recv_size = len;
changeState(client, kRequestStateProcessResponse);
}
Expand Down
4 changes: 2 additions & 2 deletions src/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,7 @@ void UDSServerPoll(UDSServer_t *srv) {
}

if (UDSTimeAfter(UDSMillis(), srv->p2_timer)) {
printf("len: %zu\n", r->send_len);
UDS_DBG_PRINT("len: %zu\n", r->send_len);
ssize_t ret = UDSTpSend(srv->tp, r->send_buf, r->send_len, NULL);
// TODO test injection of transport errors:
if (ret < 0) {
Expand Down Expand Up @@ -945,4 +945,4 @@ void UDSServerPoll(UDSServer_t *srv) {
}
}
}
}
}
2 changes: 2 additions & 0 deletions src/sys_arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
#include <Arduino.h>

#define UDS_TP UDS_TP_ISOTP_C
#ifndef UDS_ENABLE_DBG_PRINT
#define UDS_ENABLE_DBG_PRINT 1
#endif
#define UDS_ENABLE_ASSERT 1
int print_impl(const char *fmt, ...);
#define UDS_DBG_PRINT_IMPL print_impl
Expand Down
2 changes: 2 additions & 0 deletions src/sys_esp32.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
#include <esp_timer.h>

#define UDS_TP_ISOTP_C 1
#ifndef UDS_ENABLE_DBG_PRINT
#define UDS_ENABLE_DBG_PRINT 1
#endif
#define UDS_ENABLE_ASSERT 1

#endif
8 changes: 4 additions & 4 deletions src/tp/isotp_c.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ int peek_link(IsoTpLink *link, uint8_t *buf, size_t bufsize, bool functional) {
goto done;
case ISOTP_RECEIVE_STATUS_FULL:
ret = link->receive_size;
printf("The link is full. Copying %d bytes\n", ret);
UDS_DBG_PRINT("The link is full. Copying %d bytes\n", ret);
memmove(buf, link->receive_buffer, link->receive_size);
break;
default:
Expand All @@ -55,7 +55,7 @@ static ssize_t tp_peek(UDSTpHandle_t *hdl, uint8_t **p_buf, UDSSDU_t *info) {
uint32_t sa = tp->phys_sa;

if (ret > 0) {
printf("just got %d bytes\n", ret);
UDS_DBG_PRINT("just got %d bytes\n", ret);
ta = tp->phys_sa;
sa = tp->phys_ta;
ta_type = UDS_A_TA_TYPE_PHYSICAL;
Expand All @@ -66,7 +66,7 @@ static ssize_t tp_peek(UDSTpHandle_t *hdl, uint8_t **p_buf, UDSSDU_t *info) {
} else {
ret = peek_link(&tp->func_link, tp->recv_buf, sizeof(tp->recv_buf), true);
if (ret > 0) {
printf("just got %d bytes on func link \n", ret);
UDS_DBG_PRINT("just got %d bytes on func link \n", ret);
ta = tp->func_sa;
sa = tp->func_ta;
ta_type = UDS_A_TA_TYPE_FUNCTIONAL;
Expand Down Expand Up @@ -128,7 +128,7 @@ static ssize_t tp_send(UDSTpHandle_t *hdl, uint8_t *buf, size_t len, UDSSDU_t *i

static void tp_ack_recv(UDSTpHandle_t *hdl) {
assert(hdl);
printf("ack recv\n");
UDS_DBG_PRINT("ack recv\n");
UDSISOTpC_t *tp = (UDSISOTpC_t *)hdl;
uint16_t out_size = 0;
isotp_receive(&tp->phys_link, tp->recv_buf, sizeof(tp->recv_buf), &out_size);
Expand Down
10 changes: 5 additions & 5 deletions src/tp/isotp_c_socketcan.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ static int isotp_c_socketcan_tp_peek_link(IsoTpLink *link, uint8_t *buf, size_t
goto done;
case ISOTP_RECEIVE_STATUS_FULL:
ret = link->receive_size;
printf("The link is full. Copying %d bytes\n", ret);
UDS_DBG_PRINT("The link is full. Copying %d bytes\n", ret);
memmove(buf, link->receive_buffer, link->receive_size);
break;
default:
Expand All @@ -148,7 +148,7 @@ static ssize_t isotp_c_socketcan_tp_peek(UDSTpHandle_t *hdl, uint8_t **p_buf, UD
uint32_t sa = tp->phys_sa;

if (ret > 0) {
printf("just got %d bytes\n", ret);
UDS_DBG_PRINT("just got %d bytes\n", ret);
ta = tp->phys_sa;
sa = tp->phys_ta;
ta_type = UDS_A_TA_TYPE_PHYSICAL;
Expand All @@ -160,7 +160,7 @@ static ssize_t isotp_c_socketcan_tp_peek(UDSTpHandle_t *hdl, uint8_t **p_buf, UD
ret = isotp_c_socketcan_tp_peek_link(&tp->func_link, tp->recv_buf, sizeof(tp->recv_buf),
true);
if (ret > 0) {
printf("just got %d bytes on func link \n", ret);
UDS_DBG_PRINT("just got %d bytes on func link \n", ret);
ta = tp->func_sa;
sa = tp->func_ta;
ta_type = UDS_A_TA_TYPE_FUNCTIONAL;
Expand Down Expand Up @@ -238,7 +238,7 @@ static ssize_t isotp_c_socketcan_tp_send(UDSTpHandle_t *hdl, uint8_t *buf, size_

static void isotp_c_socketcan_tp_ack_recv(UDSTpHandle_t *hdl) {
assert(hdl);
printf("ack recv\n");
UDS_DBG_PRINT("ack recv\n");
UDSTpISOTpC_t *tp = (UDSTpISOTpC_t *)hdl;
uint16_t out_size = 0;
isotp_receive(&tp->phys_link, tp->recv_buf, sizeof(tp->recv_buf), &out_size);
Expand Down Expand Up @@ -282,4 +282,4 @@ void UDSTpISOTpCDeinit(UDSTpISOTpC_t *tp) {
tp->fd = -1;
}

#endif
#endif
14 changes: 7 additions & 7 deletions src/tp/isotp_sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,18 +147,18 @@ static int LinuxSockBind(const char *if_name, uint32_t rxid, uint32_t txid, bool
perror("setsockopt");
return -1;
}

struct can_isotp_options opts;
memset(&opts, 0, sizeof(opts));
// configure socket to wait for tx completion to catch FC frame timeouts
opts.flags |= CAN_ISOTP_WAIT_TX_DONE;

if (functional) {
printf("configuring fd: %d as functional\n", fd);
UDS_DBG_PRINT("configuring fd: %d as functional\n", fd);
// configure the socket as listen-only to avoid sending FC frames
opts.flags |= CAN_ISOTP_LISTEN_MODE;
}

if (setsockopt(fd, SOL_CAN_ISOTP, CAN_ISOTP_OPTS, &opts, sizeof(opts)) < 0) {
perror("setsockopt (isotp_options):");
return -1;
Expand All @@ -177,7 +177,7 @@ static int LinuxSockBind(const char *if_name, uint32_t rxid, uint32_t txid, bool
addr.can_ifindex = ifr.ifr_ifindex;

if (bind(fd, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
printf("Bind: %s %s\n", strerror(errno), if_name);
UDS_DBG_PRINT("Bind: %s %s\n", strerror(errno), if_name);
return -1;
}
return fd;
Expand All @@ -199,7 +199,7 @@ UDSErr_t UDSTpIsoTpSockInitServer(UDSTpIsoTpSock_t *tp, const char *ifname, uint
tp->phys_fd = LinuxSockBind(ifname, source_addr, target_addr, false);
tp->func_fd = LinuxSockBind(ifname, source_addr_func, 0, true);
if (tp->phys_fd < 0 || tp->func_fd < 0) {
printf("foo\n");
UDS_DBG_PRINT("foo\n");
fflush(stdout);
return UDS_ERR;
}
Expand Down Expand Up @@ -227,7 +227,7 @@ UDSErr_t UDSTpIsoTpSockInitClient(UDSTpIsoTpSock_t *tp, const char *ifname, uint
if (tp->phys_fd < 0 || tp->func_fd < 0) {
return UDS_ERR;
}
printf("%s initialized phys link (fd %d) rx 0x%03x tx 0x%03x func link (fd %d) rx 0x%03x tx "
UDS_DBG_PRINT("%s initialized phys link (fd %d) rx 0x%03x tx 0x%03x func link (fd %d) rx 0x%03x tx "
"0x%03x\n",
strlen(tp->tag) ? tp->tag : "client", tp->phys_fd, source_addr, target_addr, tp->func_fd,
source_addr, target_addr_func);
Expand Down
4 changes: 2 additions & 2 deletions src/tp/mock.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ static void TPMockDetach(TPMock_t *tp) {
TPs[j - 1] = TPs[j];
}
TPCount--;
printf("TPMock: detached %s. TPCount: %d\n", tp->name, TPCount);
UDS_DBG_PRINT("TPMock: detached %s. TPCount: %d\n", tp->name, TPCount);
return;
}
}
Expand All @@ -158,7 +158,7 @@ static void TPMockDetach(TPMock_t *tp) {

UDSTpHandle_t *TPMockNew(const char *name, TPMockArgs_t *args) {
if (TPCount >= MAX_NUM_TP) {
printf("TPCount: %d, too many TPs\n", TPCount);
UDS_DBG_PRINT("TPCount: %d, too many TPs\n", TPCount);
return NULL;
}
TPMock_t *tp = malloc(sizeof(TPMock_t));
Expand Down
Loading