From c054fb8a2c5a60da3961728222d66ebbadfb50c3 Mon Sep 17 00:00:00 2001 From: Felix Storm Date: Thu, 17 Feb 2022 05:00:14 +0100 Subject: [PATCH] CAN bus: read all queued messages (#3194) --- esphome/components/canbus/canbus.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/esphome/components/canbus/canbus.cpp b/esphome/components/canbus/canbus.cpp index 731682c277..d9f6ded85d 100644 --- a/esphome/components/canbus/canbus.cpp +++ b/esphome/components/canbus/canbus.cpp @@ -56,13 +56,15 @@ void Canbus::add_trigger(CanbusTrigger *trigger) { void Canbus::loop() { struct CanFrame can_message; - // readmessage - if (this->read_message(&can_message) == canbus::ERROR_OK) { + // read all messages until queue is empty + int message_counter = 0; + while (this->read_message(&can_message) == canbus::ERROR_OK) { + message_counter++; if (can_message.use_extended_id) { - ESP_LOGD(TAG, "received can message extended can_id=0x%x size=%d", can_message.can_id, + ESP_LOGD(TAG, "received can message (#%d) extended can_id=0x%x size=%d", message_counter, can_message.can_id, can_message.can_data_length_code); } else { - ESP_LOGD(TAG, "received can message std can_id=0x%x size=%d", can_message.can_id, + ESP_LOGD(TAG, "received can message (#%d) std can_id=0x%x size=%d", message_counter, can_message.can_id, can_message.can_data_length_code); }