From 3306550a16e6db738d5f9691b69ab79688d7d154 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BD=D0=B8=D0=BB=D0=B0=20=D0=93=D0=BE=D1=80?= =?UTF-8?q?=D0=BD=D1=83=D1=88=D0=BA=D0=BE?= Date: Tue, 28 Nov 2023 14:45:51 +0300 Subject: [PATCH] Impove cansend --- main/cmd_can.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/main/cmd_can.c b/main/cmd_can.c index acb50e9..9bcd812 100644 --- a/main/cmd_can.c +++ b/main/cmd_can.c @@ -71,9 +71,22 @@ static int send_can_frame(int argc, char **argv) { } msg.data_length_code = dt_l / 2; msg.identifier = msg_id; - twai_transmit(&msg, pdMS_TO_TICKS(1000)); - can_msg_to_str(&msg, "sent ", printf_str); - print_w_clr_time(printf_str, NULL, true); + esp_err_t res = twai_transmit(&msg, pdMS_TO_TICKS(1000)); + switch(res) { + case ESP_OK: + can_msg_to_str(&msg, "sent ", printf_str); + print_w_clr_time(printf_str, NULL, true); + break; + case ESP_ERR_TIMEOUT: + print_w_clr_time("Timeout!", LOG_COLOR_RED, false); + break; + case ESP_ERR_NOT_SUPPORTED: + print_w_clr_time("Can't sent in Listen-Only mode!", LOG_COLOR_RED, false); + break; + default: + print_w_clr_time("Invalid state!", LOG_COLOR_RED, false); + break; + } free(can_msg_str_buf); return 0; invalid_args: