From 3534cde47f8248603a95aa9032ed7c01f9dd93fa 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 15:02:00 +0300 Subject: [PATCH] improve some docs, impove candown --- main/cmd_can.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/main/cmd_can.c b/main/cmd_can.c index 9bcd812..14763c9 100644 --- a/main/cmd_can.c +++ b/main/cmd_can.c @@ -1,5 +1,6 @@ #include "cmd_can.h" #include "can.h" +#include "esp_err.h" #include "esp_log.h" #include "inttypes.h" #include "freertos/projdefs.h" @@ -162,7 +163,15 @@ static int canstart(int argc, char **argv) { static int candown(int argc, char **argv) { xSemaphoreTake(can_mutex, portMAX_DELAY); - ESP_ERROR_CHECK(twai_stop()); + if (curr_can_state.state != CAN_BUF_OFF) { + esp_err_t res = twai_stop(); + if (res == ESP_OK) print_w_clr_time("CAN was stopped.", LOG_COLOR_GREEN, false); + else { + print_w_clr_time("Driver is not in running state, or is not installed.", LOG_COLOR_RED, false); + xSemaphoreGive(can_mutex); + return 1; + } + } ESP_ERROR_CHECK(twai_driver_uninstall()); xSemaphoreGive(can_mutex); return 0; @@ -184,14 +193,14 @@ static void register_send_can_frame(void) { } static void register_canup(void) { - canup_args.speed = arg_str1(NULL, NULL, "<25|50|100|125|250|500|800|1000>", "CAN bus speed, in kbits."); - canup_args.mode = arg_str0("m", "mode", "", "CAN bus speed, in bps. See helo for supported speeds."); + canup_args.mode = arg_str0("m", "mode", "", "CAN filters to receive only selected frames."); - canup_args.autorecover = arg_str0("r", "auto-recovery", "<1|0>", "Set 1 to enable auto-recovery of CAN bus if case of bus-off event."); + canup_args.autorecover = arg_str0("r", "auto-recovery", "<1|0>", "Set 1 to enable auto-recovery of CAN bus if case of bus-off event, disabled by default."); canup_args.end = arg_end(2); const esp_console_cmd_t cmd = { .command = "canup", - .help = "Install can drivers and start can interface. Used right after board start or during runtime for changing CAN configuration.", + .help = "Install can drivers and start can interface. Used right after board start or during runtime for changing CAN configuration. Supported speeds: 1mbits, 800kbits, 500kbits, 250kbits, 125kbits, 100kbits, 50kbits, 25kbits, 20kbits, 16kbits, 12.5kbits, 10kbits, 5kbits, 1kbits.", .hint = NULL, .func = &canup, .argtable = &canup_args, @@ -222,7 +231,7 @@ static void register_canstats(void) { static void register_canstart(void) { const esp_console_cmd_t cmd = { .command = "canstart", - .help = "Start CAN interface, used after buf recovery, otherwise see canup command.", + .help = "Start CAN interface, used after bus recovery, otherwise see canup command.", .hint = NULL, .func = &canstart, };