mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-08 00:39:50 +03:00
Merge remote-tracking branch 'origin/v3.4' into dev
This commit is contained in:
104
src/telegram.h
104
src/telegram.h
@@ -34,7 +34,7 @@
|
||||
#include "helpers.h"
|
||||
|
||||
#define MAX_RX_TELEGRAMS 10 // size of Rx queue
|
||||
#define MAX_TX_TELEGRAMS 30 // size of Tx queue
|
||||
#define MAX_TX_TELEGRAMS 50 // size of Tx queue
|
||||
|
||||
// default values for null values
|
||||
static constexpr uint8_t EMS_VALUE_BOOL = 0xFF; // used to mark that something is a boolean
|
||||
@@ -166,6 +166,7 @@ class EMSbus {
|
||||
ems_bus_id_ = ems_bus_id;
|
||||
}
|
||||
|
||||
// checks every 30 seconds if the EMS bus is still alive
|
||||
static bool bus_connected() {
|
||||
#ifndef EMSESP_STANDALONE
|
||||
if ((uuid::get_uptime() - last_bus_activity_) > EMS_BUS_TIMEOUT) {
|
||||
@@ -179,8 +180,22 @@ class EMSbus {
|
||||
|
||||
// sets the flag for EMS bus connected
|
||||
static void last_bus_activity(uint32_t timestamp) {
|
||||
// record the first time we connected to the BUS, as this will be our uptime
|
||||
if (!last_bus_activity_) {
|
||||
bus_uptime_start_ = timestamp;
|
||||
}
|
||||
|
||||
last_bus_activity_ = timestamp;
|
||||
bus_connected_ = true;
|
||||
|
||||
bus_connected_ = true;
|
||||
}
|
||||
|
||||
// return bus uptime in seconds
|
||||
static uint32_t bus_uptime() {
|
||||
if (!bus_uptime_start_) {
|
||||
return 0; // not yet initialized
|
||||
}
|
||||
return (uint32_t)((uuid::get_uptime() - bus_uptime_start_) / 1000ULL);
|
||||
}
|
||||
|
||||
static uint8_t tx_state() {
|
||||
@@ -196,6 +211,7 @@ class EMSbus {
|
||||
static constexpr uint32_t EMS_BUS_TIMEOUT = 30000; // timeout in ms before recognizing the ems bus is offline (30 seconds)
|
||||
|
||||
static uint32_t last_bus_activity_; // timestamp of last time a valid Rx came in
|
||||
static uint32_t bus_uptime_start_; // timestamp of first time we connected to the bus
|
||||
static bool bus_connected_; // start assuming the bus hasn't been connected
|
||||
static uint8_t ems_mask_; // unset=0xFF, buderus=0x00, junkers/ht3=0x80
|
||||
static uint8_t ems_bus_id_; // the bus id, which configurable and stored in settings
|
||||
@@ -224,6 +240,7 @@ class RxService : public EMSbus {
|
||||
return telegram_error_count_;
|
||||
}
|
||||
|
||||
// returns a %
|
||||
uint8_t quality() const {
|
||||
if (telegram_error_count_ == 0) {
|
||||
return 100; // all good, 100%
|
||||
@@ -308,49 +325,61 @@ class TxService : public EMSbus {
|
||||
uint32_t telegram_read_count() const {
|
||||
return telegram_read_count_;
|
||||
}
|
||||
uint32_t telegram_write_count() const {
|
||||
return telegram_write_count_;
|
||||
}
|
||||
|
||||
void telegram_read_count(uint8_t telegram_read_count) {
|
||||
void telegram_read_count(uint32_t telegram_read_count) {
|
||||
telegram_read_count_ = telegram_read_count;
|
||||
}
|
||||
|
||||
void telegram_write_count(uint32_t telegram_write_count) {
|
||||
telegram_write_count_ = telegram_write_count;
|
||||
}
|
||||
|
||||
void increment_telegram_read_count() {
|
||||
telegram_read_count_++;
|
||||
}
|
||||
|
||||
uint32_t telegram_fail_count() const {
|
||||
return telegram_fail_count_;
|
||||
}
|
||||
|
||||
void telegram_fail_count(uint8_t telegram_fail_count) {
|
||||
telegram_fail_count_ = telegram_fail_count;
|
||||
}
|
||||
|
||||
uint8_t quality() const {
|
||||
if (telegram_fail_count_ == 0) {
|
||||
return 100; // all good, 100%
|
||||
}
|
||||
if (telegram_fail_count_ >= telegram_read_count_) {
|
||||
return 100;
|
||||
}
|
||||
return (100 - (uint8_t)(((float)telegram_fail_count_ / telegram_read_count_ * 100)));
|
||||
}
|
||||
|
||||
void increment_telegram_fail_count() {
|
||||
telegram_fail_count_++;
|
||||
}
|
||||
|
||||
uint32_t telegram_write_count() const {
|
||||
return telegram_write_count_;
|
||||
}
|
||||
|
||||
void telegram_write_count(uint8_t telegram_write_count) {
|
||||
telegram_write_count_ = telegram_write_count;
|
||||
}
|
||||
|
||||
void increment_telegram_write_count() {
|
||||
telegram_write_count_++;
|
||||
}
|
||||
|
||||
uint32_t telegram_read_fail_count() const {
|
||||
return telegram_read_fail_count_;
|
||||
}
|
||||
|
||||
uint32_t telegram_write_fail_count() const {
|
||||
return telegram_write_fail_count_;
|
||||
}
|
||||
|
||||
void telegram_fail_count(uint32_t telegram_fail_count) {
|
||||
telegram_read_fail_count_ = telegram_fail_count;
|
||||
telegram_write_fail_count_ = telegram_fail_count;
|
||||
}
|
||||
|
||||
uint8_t read_quality() const {
|
||||
if (telegram_read_fail_count_ == 0) {
|
||||
return 100; // all good, 100%
|
||||
}
|
||||
return (100 - (uint8_t)((telegram_read_fail_count_ * 100 / (telegram_read_fail_count_ + telegram_read_count_))));
|
||||
}
|
||||
|
||||
uint8_t write_quality() const {
|
||||
if (telegram_write_fail_count_ == 0) {
|
||||
return 100; // all good, 100%
|
||||
}
|
||||
return (100 - (uint8_t)((telegram_write_fail_count_ * 100 / (telegram_write_fail_count_ + telegram_write_count_))));
|
||||
}
|
||||
|
||||
void increment_telegram_read_fail_count() {
|
||||
telegram_read_fail_count_++;
|
||||
}
|
||||
|
||||
void increment_telegram_write_fail_count() {
|
||||
telegram_write_fail_count_++;
|
||||
}
|
||||
|
||||
struct QueuedTxTelegram {
|
||||
const uint16_t id_;
|
||||
const std::shared_ptr<const Telegram> telegram_;
|
||||
@@ -381,9 +410,10 @@ class TxService : public EMSbus {
|
||||
private:
|
||||
std::deque<QueuedTxTelegram> tx_telegrams_; // the Tx queue
|
||||
|
||||
uint32_t telegram_read_count_ = 0; // # Tx successful reads
|
||||
uint32_t telegram_write_count_ = 0; // # Tx successful writes
|
||||
uint32_t telegram_fail_count_ = 0; // # Tx unsuccessful transmits
|
||||
uint32_t telegram_read_count_ = 0; // # Tx successful reads
|
||||
uint32_t telegram_write_count_ = 0; // # Tx successful writes
|
||||
uint32_t telegram_read_fail_count_ = 0; // # Tx unsuccessful transmits
|
||||
uint32_t telegram_write_fail_count_ = 0; // # Tx unsuccessful transmits
|
||||
|
||||
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
|
||||
@@ -392,9 +422,7 @@ class TxService : public EMSbus {
|
||||
|
||||
uint8_t tx_telegram_id_ = 0; // queue counter
|
||||
|
||||
|
||||
void send_telegram(const QueuedTxTelegram & tx_telegram);
|
||||
// void send_telegram(const uint8_t * data, const uint8_t length);
|
||||
};
|
||||
|
||||
} // namespace emsesp
|
||||
|
||||
Reference in New Issue
Block a user