better alarms and can recovery

This commit is contained in:
Данила Горнушко 2023-11-28 14:40:41 +03:00
parent c0d8d19051
commit b95a972949
4 changed files with 16 additions and 4 deletions

View file

@ -2,7 +2,6 @@ TODO:
add caninstall and canstart
canup/caninstall parameters (without filtering)
add filtering (software and hardware)
better alarms handling, can recovering
better history
clear history and clear screen commands
code refactoring

View file

@ -10,6 +10,7 @@
#include "xvprintf.h"
bool is_error_passive = false;
bool auto_recovery = false;
SemaphoreHandle_t can_mutex;
volatile can_status_t curr_can_state = { 0 };
@ -86,11 +87,17 @@ void can_task(void* arg) {
}
if (alerts & TWAI_ALERT_BUS_OFF) {
print_w_clr_time("CAN went bus-off!", LOG_COLOR_RED, false);
// ESP_ERROR_CHECK(twai_initiate_recovery());
if (auto_recovery) {
print_w_clr_time("Initiating auto-recovery...", LOG_COLOR_GREEN, false);
twai_initiate_recovery();
}
}
if (alerts & TWAI_ALERT_BUS_RECOVERED) {
print_w_clr_time("CAN recovered!", LOG_COLOR_BLUE, false);
// ESP_ERROR_CHECK(twai_start());
if (auto_recovery) {
print_w_clr_time("Starting CAN...", LOG_COLOR_GREEN, false);
twai_start();
}
}
}
curr_can_state = get_can_state();

View file

@ -40,6 +40,7 @@ typedef struct {
extern SemaphoreHandle_t can_mutex;
extern volatile can_status_t curr_can_state;
extern bool timestamp_enabled;
extern bool auto_recovery;
// functions

View file

@ -1,4 +1,5 @@
#include "cmd_can.h"
#include "can.h"
#include "esp_log.h"
#include "inttypes.h"
#include "freertos/projdefs.h"
@ -83,6 +84,10 @@ invalid_args:
static int canrecover(int argc, char **argv) {
esp_err_t res = twai_initiate_recovery();
if (res == ESP_OK) print_w_clr_time("Started CAN recovery.", LOG_COLOR_GREEN, false);
else if (curr_can_state.state == CAN_NOT_INSTALLED) print_w_clr_time("CAN driver is not installed!", LOG_COLOR_RED, false);
else print_w_clr_time("Can't start recovery - not in bus-off state!", LOG_COLOR_RED, false);
return 0;
}
@ -169,7 +174,7 @@ 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", "<normal|no_ack|listen_only", "Set CAN mode. Normal, No Ack (for self-testing) or Listen Only (to prevent transmitting, for monitoring).");
canup_args.filters = arg_str0("f", "filters", "<filters>", "CAN filters to receive only selected frames.");
canup_args.autorecover = arg_str0("r", "auto-recover", "<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.");
canup_args.end = arg_end(2);
const esp_console_cmd_t cmd = {
.command = "canup",