Merge pull request #194 from bobbycar-graz/fix_can_reset

Fix can reset
This commit is contained in:
Peter Pötzi
2021-12-29 04:02:38 +01:00
committed by GitHub

View File

@ -280,9 +280,6 @@ void parseCanInput()
break;
}
uint32_t can_total_error_cnt = 0;
uint32_t can_sequential_error_cnt = 0;
void sendCanCommands()
{
constexpr auto send = [](uint32_t addr, auto value){
@ -302,9 +299,13 @@ void sendCanCommands()
ESP_LOGE(TAG, "ERROR: twai_transmit() failed with %s", esp_err_to_name(result));
}
static uint32_t can_total_error_cnt = 0;
static uint32_t can_sequential_error_cnt = 0;
if (result == ESP_ERR_TIMEOUT) {
can_sequential_error_cnt++;
can_total_error_cnt++;
++can_sequential_error_cnt;
++can_total_error_cnt;
ESP_LOGW(TAG, "twai_transmit() took %lld ms, seq err: %d, total err: %d",
espchrono::ago(timestamp_before).count(),
can_sequential_error_cnt,
@ -317,10 +318,10 @@ void sendCanCommands()
if (can_sequential_error_cnt > 3) {
can_sequential_error_cnt = 0;
if (configs.canBusResetOnError.value) {
if (const auto err = twai_stop(); err != ESP_OK || true)
if (const auto err = twai_stop(); err != ESP_OK)
ESP_LOGE(TAG, "ERROR: twai_stop() failed with %s", esp_err_to_name(err));
if (const auto err = twai_start(); err != ESP_OK || true)
if (const auto err = twai_start(); err != ESP_OK)
ESP_LOGE(TAG, "ERROR: twai_start() failed with %s", esp_err_to_name(err));
}