forked from test34/can_wizard
added alerts
This commit is contained in:
parent
d037b1412c
commit
6cb2ec72c3
4 changed files with 15 additions and 6 deletions
16
main/can.c
16
main/can.c
|
@ -73,8 +73,16 @@ void can_task(void* arg) {
|
||||||
twai_message_t rx_msg;
|
twai_message_t rx_msg;
|
||||||
char data_bytes_str[50];
|
char data_bytes_str[50];
|
||||||
for (;;) { // A Task shall never return or exit.
|
for (;;) { // A Task shall never return or exit.
|
||||||
curr_can_state = get_can_state();
|
|
||||||
if (twai_read_alerts(&alerts, 0) == ESP_OK) {
|
if (twai_read_alerts(&alerts, 0) == ESP_OK) {
|
||||||
|
if (alerts & TWAI_ALERT_ERR_ACTIVE) {
|
||||||
|
is_error_passive = false;
|
||||||
|
}
|
||||||
|
if (alerts & TWAI_ALERT_ERR_PASS) {
|
||||||
|
is_error_passive = true;
|
||||||
|
}
|
||||||
|
if (alerts & TWAI_ALERT_BUS_ERROR) {
|
||||||
|
ESP_LOGE(LOG_TAG, "CAN error!");
|
||||||
|
}
|
||||||
if (alerts & TWAI_ALERT_BUS_OFF) {
|
if (alerts & TWAI_ALERT_BUS_OFF) {
|
||||||
ESP_LOGE(LOG_TAG, "CAN went bus-off!");
|
ESP_LOGE(LOG_TAG, "CAN went bus-off!");
|
||||||
// ESP_ERROR_CHECK(twai_initiate_recovery());
|
// ESP_ERROR_CHECK(twai_initiate_recovery());
|
||||||
|
@ -84,12 +92,14 @@ void can_task(void* arg) {
|
||||||
// ESP_ERROR_CHECK(twai_start());
|
// ESP_ERROR_CHECK(twai_start());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
curr_can_state = get_can_state();
|
||||||
if (xSemaphoreTake(can_mutex, 0) == pdTRUE) {
|
if (xSemaphoreTake(can_mutex, 0) == pdTRUE) {
|
||||||
if (twai_receive(&rx_msg, can_task_timeout) == ESP_OK) {
|
while (twai_receive(&rx_msg, 0) == ESP_OK) {
|
||||||
can_msg_to_str(&rx_msg, data_bytes_str);
|
can_msg_to_str(&rx_msg, data_bytes_str);
|
||||||
xprintf(LOG_COLOR(LOG_COLOR_BLUE) "recv %s\n" LOG_RESET_COLOR, data_bytes_str);
|
xprintf(LOG_COLOR(LOG_COLOR_BLUE) "recv %s\n" LOG_RESET_COLOR, data_bytes_str);
|
||||||
}
|
}
|
||||||
xSemaphoreGive(can_mutex);
|
xSemaphoreGive(can_mutex);
|
||||||
} else vTaskDelay(can_task_timeout);
|
}
|
||||||
|
vTaskDelay(can_task_timeout);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
#include "cmd_can.h"
|
#include "cmd_can.h"
|
||||||
#include "esp_log.h"
|
#include "esp_log.h"
|
||||||
#include "freertos/portmacro.h"
|
|
||||||
#include "inttypes.h"
|
#include "inttypes.h"
|
||||||
#include "freertos/projdefs.h"
|
#include "freertos/projdefs.h"
|
||||||
#include "string.h"
|
#include "string.h"
|
||||||
|
|
|
@ -13,7 +13,7 @@ static const twai_general_config_t g_config = {
|
||||||
.bus_off_io = TWAI_IO_UNUSED,
|
.bus_off_io = TWAI_IO_UNUSED,
|
||||||
.tx_queue_len = 5,
|
.tx_queue_len = 5,
|
||||||
.rx_queue_len = 5,
|
.rx_queue_len = 5,
|
||||||
.alerts_enabled = TWAI_ALERT_AND_LOG | TWAI_ALERT_ALL,
|
.alerts_enabled = TWAI_ALERT_ERR_ACTIVE | TWAI_ALERT_BUS_RECOVERED | TWAI_ALERT_BUS_ERROR | TWAI_ALERT_ERR_PASS | TWAI_ALERT_BUS_OFF,
|
||||||
.clkout_divider = 0,
|
.clkout_divider = 0,
|
||||||
.intr_flags = ESP_INTR_FLAG_LEVEL1,
|
.intr_flags = ESP_INTR_FLAG_LEVEL1,
|
||||||
};
|
};
|
||||||
|
|
|
@ -154,7 +154,7 @@ void initialize_console(void) {
|
||||||
console_config.max_cmdline_length = 256;
|
console_config.max_cmdline_length = 256;
|
||||||
if (use_colors) console_config.hint_color = atoi(LOG_COLOR_CYAN);
|
if (use_colors) console_config.hint_color = atoi(LOG_COLOR_CYAN);
|
||||||
ESP_ERROR_CHECK(esp_console_init(&console_config));
|
ESP_ERROR_CHECK(esp_console_init(&console_config));
|
||||||
linenoiseSetMultiLine(1);
|
// linenoiseSetMultiLine(1);
|
||||||
linenoiseSetCompletionCallback(&esp_console_get_completion);
|
linenoiseSetCompletionCallback(&esp_console_get_completion);
|
||||||
linenoiseSetHintsCallback((linenoiseHintsCallback*) &esp_console_get_hint);
|
linenoiseSetHintsCallback((linenoiseHintsCallback*) &esp_console_get_hint);
|
||||||
linenoiseHistorySetMaxLen(100);
|
linenoiseHistorySetMaxLen(100);
|
||||||
|
|
Loading…
Reference in a new issue