Skip to content
Open
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
6 changes: 6 additions & 0 deletions src/canmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -179,17 +182,20 @@ 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;
}
}
return CANMAP_COMPRET_TRANS;
}
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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/canmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 12 additions & 4 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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));
}
}

Expand Down