diff --git a/src/canmap.c b/src/canmap.c index fa46159..cb676b8 100644 --- a/src/canmap.c +++ b/src/canmap.c @@ -129,6 +129,7 @@ int canmap_compute_frame(int *socket, struct can_frame *frame) { } else { /* no free buffer */ + printf("fatal: no free buffer available"); return CANMAP_COMPRET_ERROR; } case CANMAP_STATUS_FF: @@ -147,12 +148,14 @@ int canmap_compute_frame(int *socket, struct can_frame *frame) { dst->data_iter = 5; dst->block_counter = 1; if(write(*socket, &flowcontrol, sizeof(struct can_frame)) < 1) { + printf("fatal: cannot send flowcontrol frame"); return CANMAP_COMPRET_ERROR; } return CANMAP_COMPRET_TRANS; } else { /* no free buffer */ + printf("fatal: no free buffer available"); return CANMAP_COMPRET_ERROR; } case CANMAP_STATUS_CF: @@ -179,6 +182,7 @@ int canmap_compute_frame(int *socket, struct can_frame *frame) { dst->block_counter = 0; /* send flowcontrol */ if(write(*socket, &flowcontrol, sizeof(struct can_frame)) < 1) { + printf("fatal: cannot send flowcontrol frame"); return CANMAP_COMPRET_ERROR; } } @@ -186,10 +190,12 @@ int canmap_compute_frame(int *socket, struct can_frame *frame) { } else { /* no buffer found */ + printf("fatal: no buffer found for consecutive frame"); return CANMAP_COMPRET_ERROR; } } /* if the code comes till here, something is very broken */ + printf("fatal: frame cannot be processed as canmap frame"); return CANMAP_COMPRET_ERROR; } diff --git a/src/canmap.h b/src/canmap.h index 3b6a91b..7354381 100644 --- a/src/canmap.h +++ b/src/canmap.h @@ -52,7 +52,7 @@ THE SOFTWARE. #define CANMAP_COMPRET_COMPLETE 1 /* Transmission Complete */ #define CANMAP_COMPRET_TRANS 0 /* Transmission pending... */ -#define CANMAP_COMPRET_ERROR -1 /* No ISO-TP Frame or no fre buffer */ +#define CANMAP_COMPRET_ERROR -1 /* No ISO-TP Frame or no free buffer */ #define CANMAP_FLOWSTAT_CLEAR 0 #define CANMAP_FLOWSTAT_WAIT 1 diff --git a/src/main.c b/src/main.c index 166fc18..e2d6f64 100644 --- a/src/main.c +++ b/src/main.c @@ -324,15 +324,23 @@ void *can2tcp(void *arg) { conn = (struct connection_data*)arg; while(1) { /* if websocket is free */ - nbytes = recv(cansocket, &frame, sizeof(struct can_frame), MSG_PEEK); - pthread_mutex_lock(&(conn->canlock)); nbytes = recv(cansocket, &frame, sizeof(struct can_frame), 0); - if (nbytes == sizeof(struct can_frame)) { + if (nbytes > 0) { + if (verbose > 0) { + printf("can in: 0x%02x (%d)", frame.can_id, frame.len); + } + pthread_mutex_lock(&(conn->canlock)); int status; status = canmap_compute_frame(&(cansocket), &frame); if(status == CANMAP_COMPRET_COMPLETE) { if(canmap_get_frame(&isoframe)) { + if (verbose > 0) { + printf("canmap complete: 0x%02x->0x%02x (%04d)", isoframe.sender, isoframe.rec, isoframe.dl); + } memset(sock_send, 0, sizeof(sock_send)); + if (verbose > 0) { + printf("tcp out: %s", sock_send); + } canmap_fr2str(sock_send, &isoframe); send(conn->websocket, sock_send, strlen(sock_send), 0); canmap_reset_frame(&isoframe); @@ -341,8 +349,8 @@ void *can2tcp(void *arg) { else if(status == CANMAP_COMPRET_ERROR) { /* msg still in transmission */ } + pthread_mutex_unlock(&(conn->canlock)); } - pthread_mutex_unlock(&(conn->canlock)); } }