mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-08 00:39:50 +03:00
added back Rx queue - (v2) occasional Rx incomplete telegrams #460
This commit is contained in:
@@ -222,6 +222,19 @@ void EMSESP::show_ems(uuid::console::Shell & shell) {
|
|||||||
|
|
||||||
shell.println();
|
shell.println();
|
||||||
|
|
||||||
|
// Rx queue
|
||||||
|
auto rx_telegrams = rxservice_.queue();
|
||||||
|
if (rx_telegrams.empty()) {
|
||||||
|
shell.printfln(F("Rx Queue is empty"));
|
||||||
|
} else {
|
||||||
|
shell.printfln(F("Rx Queue (%ld telegram%s):"), rx_telegrams.size(), rx_telegrams.size() == 1 ? "" : "s");
|
||||||
|
for (const auto & it : rx_telegrams) {
|
||||||
|
shell.printfln(F(" [%02d] %s"), it.id_, pretty_telegram(it.telegram_).c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
shell.println();
|
||||||
|
|
||||||
// Tx queue
|
// Tx queue
|
||||||
auto tx_telegrams = txservice_.queue();
|
auto tx_telegrams = txservice_.queue();
|
||||||
if (tx_telegrams.empty()) {
|
if (tx_telegrams.empty()) {
|
||||||
@@ -270,7 +283,7 @@ void EMSESP::show_sensor_values(uuid::console::Shell & shell) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
char valuestr[8] = {0}; // for formatting temp
|
char valuestr[8] = {0}; // for formatting temp
|
||||||
shell.printfln(F("External temperature sensors:"));
|
shell.printfln(F("Dallas temperature sensors:"));
|
||||||
for (const auto & device : sensor_devices()) {
|
for (const auto & device : sensor_devices()) {
|
||||||
shell.printfln(F(" ID: %s, Temperature: %s°C"), device.to_string().c_str(), Helpers::render_value(valuestr, device.temperature_c, 2));
|
shell.printfln(F(" ID: %s, Temperature: %s°C"), device.to_string().c_str(), Helpers::render_value(valuestr, device.temperature_c, 2));
|
||||||
}
|
}
|
||||||
@@ -774,7 +787,7 @@ void EMSESP::send_raw_telegram(const char * data) {
|
|||||||
// the services must be loaded in the correct order
|
// the services must be loaded in the correct order
|
||||||
void EMSESP::start() {
|
void EMSESP::start() {
|
||||||
// Load our library of known devices. Names are stored in Flash mem.
|
// Load our library of known devices. Names are stored in Flash mem.
|
||||||
device_library_.reserve(100);
|
device_library_.reserve(80);
|
||||||
device_library_ = {
|
device_library_ = {
|
||||||
#include "device_library.h"
|
#include "device_library.h"
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -129,10 +129,11 @@ std::string Telegram::to_string_message() const {
|
|||||||
|
|
||||||
// checks if we have an Rx telegram that needs processing
|
// checks if we have an Rx telegram that needs processing
|
||||||
void RxService::loop() {
|
void RxService::loop() {
|
||||||
if (rx_telegram) {
|
while (!rx_telegrams_.empty()) {
|
||||||
EMSESP::process_telegram(rx_telegram);
|
auto telegram = rx_telegrams_.front().telegram_;
|
||||||
rx_telegram = nullptr; // telegram has been processed, reset
|
(void)EMSESP::process_telegram(telegram); // further process the telegram
|
||||||
increment_telegram_count(); // increase rx count
|
increment_telegram_count(); // increase rx count
|
||||||
|
rx_telegrams_.pop_front(); // remove it from the queue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -212,8 +213,16 @@ void RxService::add(uint8_t * data, uint8_t length) {
|
|||||||
// if we receive a hc2.. telegram from 0x19.. match it to master_thermostat if master is 0x18
|
// if we receive a hc2.. telegram from 0x19.. match it to master_thermostat if master is 0x18
|
||||||
src = EMSESP::check_master_device(src, type_id, true);
|
src = EMSESP::check_master_device(src, type_id, true);
|
||||||
|
|
||||||
// create the telegram
|
// create the telegram
|
||||||
rx_telegram = std::make_shared<Telegram>(Telegram::Operation::RX, src, dest, type_id, offset, message_data, message_length);
|
auto telegram = std::make_shared<Telegram>(Telegram::Operation::RX, src, dest, type_id, offset, message_data, message_length);
|
||||||
|
|
||||||
|
// check if queue is full, if so remove top item to make space
|
||||||
|
if (rx_telegrams_.size() >= MAX_RX_TELEGRAMS) {
|
||||||
|
rx_telegrams_.pop_front();
|
||||||
|
}
|
||||||
|
|
||||||
|
rx_telegrams_.emplace_back(rx_telegram_id_++, std::move(telegram)); // add to queue
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -192,12 +192,13 @@ class EMSbus {
|
|||||||
};
|
};
|
||||||
|
|
||||||
class RxService : public EMSbus {
|
class RxService : public EMSbus {
|
||||||
|
static constexpr size_t MAX_RX_TELEGRAMS = 10;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
RxService() = default;
|
RxService() = default;
|
||||||
~RxService() = default;
|
~RxService() = default;
|
||||||
|
|
||||||
void loop();
|
void loop();
|
||||||
|
|
||||||
void add(uint8_t * data, uint8_t length);
|
void add(uint8_t * data, uint8_t length);
|
||||||
|
|
||||||
uint16_t telegram_count() const {
|
uint16_t telegram_count() const {
|
||||||
@@ -216,10 +217,29 @@ class RxService : public EMSbus {
|
|||||||
telegram_error_count_++;
|
telegram_error_count_++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class QueuedRxTelegram {
|
||||||
|
public:
|
||||||
|
const uint16_t id_;
|
||||||
|
const std::shared_ptr<const Telegram> telegram_;
|
||||||
|
|
||||||
|
~QueuedRxTelegram() = default;
|
||||||
|
QueuedRxTelegram(uint16_t id, std::shared_ptr<Telegram> && telegram)
|
||||||
|
: id_(id)
|
||||||
|
, telegram_(std::move(telegram)) {
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const std::list<QueuedRxTelegram> queue() const {
|
||||||
|
return rx_telegrams_;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
uint8_t rx_telegram_id_ = 0; // queue counter
|
||||||
uint16_t telegram_count_ = 0; // # Rx received
|
uint16_t telegram_count_ = 0; // # Rx received
|
||||||
uint16_t telegram_error_count_ = 0; // # Rx CRC errors
|
uint16_t telegram_error_count_ = 0; // # Rx CRC errors
|
||||||
std::shared_ptr<const Telegram> rx_telegram; // the incoming Rx telegram
|
std::shared_ptr<const Telegram> rx_telegram; // the incoming Rx telegram
|
||||||
|
|
||||||
|
std::list<QueuedRxTelegram> rx_telegrams_; // the Rx Queue
|
||||||
};
|
};
|
||||||
|
|
||||||
class TxService : public EMSbus {
|
class TxService : public EMSbus {
|
||||||
@@ -341,9 +361,9 @@ class TxService : public EMSbus {
|
|||||||
|
|
||||||
std::shared_ptr<Telegram> telegram_last_;
|
std::shared_ptr<Telegram> telegram_last_;
|
||||||
uint16_t telegram_last_post_send_query_; // which type ID to query after a successful send, to read back the values just written
|
uint16_t telegram_last_post_send_query_; // which type ID to query after a successful send, to read back the values just written
|
||||||
uint8_t retry_count_ = 0; // count for # Tx retries
|
uint8_t retry_count_ = 0; // count for # Tx retries
|
||||||
|
|
||||||
uint8_t tx_telegram_id_ = 0; // queue counter
|
uint8_t tx_telegram_id_ = 0; // queue counter
|
||||||
|
|
||||||
void send_telegram(const QueuedTxTelegram & tx_telegram);
|
void send_telegram(const QueuedTxTelegram & tx_telegram);
|
||||||
void send_telegram(const uint8_t * data, const uint8_t length);
|
void send_telegram(const uint8_t * data, const uint8_t length);
|
||||||
|
|||||||
Reference in New Issue
Block a user