From 7f0692a1742522f44dfdb5ab5a528c422824e5c3 Mon Sep 17 00:00:00 2001 From: Gareth Potter Date: Tue, 23 Jul 2024 17:38:40 +0100 Subject: [PATCH 1/4] fix request response timer --- src/can.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/can.c b/src/can.c index 1a8b7c9..f50a81f 100644 --- a/src/can.c +++ b/src/can.c @@ -481,7 +481,7 @@ int thingset_can_send_inst(struct thingset_can *ts_can, uint8_t *tx_buf, size_t ts_can->request_response.callback = callback; ts_can->request_response.cb_arg = callback_arg; k_timer_init(&ts_can->request_response.timer, thingset_can_reqresp_timeout_handler, NULL); - k_timer_start(&ts_can->request_response.timer, timeout, timeout); + k_timer_start(&ts_can->request_response.timer, timeout, K_NO_WAIT); ts_can->request_response.can_id = thingset_can_get_tx_addr(&tx_addr).ext_id; } From 9a275432973102851a5ae34efeaea16a1aa1e31f Mon Sep 17 00:00:00 2001 From: Gareth Potter Date: Tue, 23 Jul 2024 23:51:31 +0100 Subject: [PATCH 2/4] CAN ID on callback --- src/can.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/can.c b/src/can.c index f50a81f..c075d62 100644 --- a/src/can.c +++ b/src/can.c @@ -449,7 +449,7 @@ static void thingset_can_reqresp_timeout_handler(struct k_timer *timer) { struct thingset_can_request_response *rr = CONTAINER_OF(timer, struct thingset_can_request_response, timer); - rr->callback(NULL, 0, 0, -ETIMEDOUT, 0, rr->cb_arg); + rr->callback(NULL, 0, 0, -ETIMEDOUT, rr->can_id, rr->cb_arg); thingset_can_reset_request_response(rr); } @@ -549,7 +549,8 @@ static void thingset_can_reqresp_sent_callback(int result, void *arg) { struct thingset_can *ts_can = arg; if (ts_can->request_response.callback != NULL && result != 0) { - ts_can->request_response.callback(NULL, 0, 0, result, 0, ts_can->request_response.cb_arg); + ts_can->request_response.callback(NULL, 0, 0, result, ts_can->request_response.can_id, + ts_can->request_response.cb_arg); thingset_can_reset_request_response(&ts_can->request_response); } else { From 61640b1dc011c05f0e674340414179e474cf7f0f Mon Sep 17 00:00:00 2001 From: Gareth Potter Date: Wed, 24 Jul 2024 11:59:03 +0100 Subject: [PATCH 3/4] always call sent callback --- src/can.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/can.c b/src/can.c index c075d62..5e25641 100644 --- a/src/can.c +++ b/src/can.c @@ -548,10 +548,15 @@ static void thingset_can_reqresp_recv_error_callback(int8_t error, struct isotp_ static void thingset_can_reqresp_sent_callback(int result, void *arg) { struct thingset_can *ts_can = arg; - if (ts_can->request_response.callback != NULL && result != 0) { + if (ts_can->request_response.callback != NULL) { ts_can->request_response.callback(NULL, 0, 0, result, ts_can->request_response.can_id, ts_can->request_response.cb_arg); thingset_can_reset_request_response(&ts_can->request_response); + if (result == 0) { + /* maintain unlocking semantics of previous iteration of this code */ + struct shared_buffer *sbuf = thingset_sdk_shared_buffer(); + k_sem_give(&sbuf->lock); + } } else { struct shared_buffer *sbuf = thingset_sdk_shared_buffer(); From 61de8ff86dbd291a0a49cbf67b24b5f217f235d7 Mon Sep 17 00:00:00 2001 From: Gareth Potter Date: Sun, 11 Aug 2024 20:51:39 +0100 Subject: [PATCH 4/4] code review fixes: callback expects a node address, not a full CAN ID --- src/can.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/can.c b/src/can.c index 5e25641..8c2d164 100644 --- a/src/can.c +++ b/src/can.c @@ -449,7 +449,7 @@ static void thingset_can_reqresp_timeout_handler(struct k_timer *timer) { struct thingset_can_request_response *rr = CONTAINER_OF(timer, struct thingset_can_request_response, timer); - rr->callback(NULL, 0, 0, -ETIMEDOUT, rr->can_id, rr->cb_arg); + rr->callback(NULL, 0, 0, -ETIMEDOUT, THINGSET_CAN_SOURCE_GET(rr->can_id), rr->cb_arg); thingset_can_reset_request_response(rr); } @@ -549,7 +549,8 @@ static void thingset_can_reqresp_sent_callback(int result, void *arg) { struct thingset_can *ts_can = arg; if (ts_can->request_response.callback != NULL) { - ts_can->request_response.callback(NULL, 0, 0, result, ts_can->request_response.can_id, + ts_can->request_response.callback(NULL, 0, 0, result, + THINGSET_CAN_SOURCE_GET(ts_can->request_response.can_id), ts_can->request_response.cb_arg); thingset_can_reset_request_response(&ts_can->request_response); if (result == 0) {