From 61abd930b5e50ee73a048daf1563b59376af5936 Mon Sep 17 00:00:00 2001 From: proddy Date: Thu, 20 Aug 2020 20:40:08 +0200 Subject: [PATCH] ESP32 Rx fixes - (v2) ESP8266 & ESP32 UART optimizations #398 --- src/emsesp.cpp | 11 ++++++----- src/telegram.cpp | 13 +++++++++---- src/telegram.h | 4 ++-- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/emsesp.cpp b/src/emsesp.cpp index 1b7167931..a7122ae17 100644 --- a/src/emsesp.cpp +++ b/src/emsesp.cpp @@ -811,11 +811,12 @@ void EMSESP::loop() { return; } - system_.loop(); // does LED and checks system health, and syslog service - shower_.loop(); // check for shower on/off - sensors_.loop(); // this will also send out via MQTT - mqtt_.loop(); // sends out anything in the queue via MQTT - console_.loop(); // telnet/serial console + system_.loop(); // does LED and checks system health, and syslog service + shower_.loop(); // check for shower on/off + sensors_.loop(); // this will also send out via MQTT + mqtt_.loop(); // sends out anything in the queue via MQTT + console_.loop(); // telnet/serial console + rxservice_.loop(); // process any incoming Rx telegrams // force a query on the EMS devices to fetch latest data at a set interval (1 min) if ((uuid::get_uptime() - last_fetch_ > EMS_FETCH_FREQUENCY)) { diff --git a/src/telegram.cpp b/src/telegram.cpp index 02c119a63..649de34bb 100644 --- a/src/telegram.cpp +++ b/src/telegram.cpp @@ -127,6 +127,15 @@ std::string Telegram::to_string_message() const { return Helpers::data_to_hex(this->message_data, this->message_length); } +// checks if we have an Rx telegram that needs processing +void RxService::loop() { + if (rx_telegram) { + EMSESP::process_telegram(rx_telegram); + rx_telegram = nullptr; // telegram has been processed, reset + increment_telegram_count(); // increase rx count + } +} + // add a new rx telegram object // data is the whole telegram, assuming last byte holds the CRC // length includes the CRC @@ -205,10 +214,6 @@ void RxService::add(uint8_t * data, uint8_t length) { // create the telegram rx_telegram = std::make_shared(Telegram::Operation::RX, src, dest, type_id, offset, message_data, message_length); - - // process it immediately - EMSESP::process_telegram(rx_telegram); // further process the telegram - increment_telegram_count(); // increase count } // diff --git a/src/telegram.h b/src/telegram.h index 02a6e29b8..c0c900446 100644 --- a/src/telegram.h +++ b/src/telegram.h @@ -52,8 +52,6 @@ static constexpr uint8_t EMS_MAX_TELEGRAM_MESSAGE_LENGTH = 27; // max length of namespace emsesp { -// creates a telegram -// from Rx (receiving one) or Tx for preparing one for sending class Telegram { public: Telegram(const uint8_t operation, @@ -198,6 +196,8 @@ class RxService : public EMSbus { RxService() = default; ~RxService() = default; + void loop(); + void add(uint8_t * data, uint8_t length); uint16_t telegram_count() const {