mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 16:29:51 +03:00
small refactoring
This commit is contained in:
@@ -713,7 +713,6 @@ void EMSESP::incoming_telegram(uint8_t * data, const uint8_t length) {
|
||||
if (tx_state != Telegram::Operation::NONE) {
|
||||
bool tx_successful = false;
|
||||
EMSbus::tx_state(Telegram::Operation::NONE); // reset Tx wait state
|
||||
// txservice_.print_last_tx();
|
||||
|
||||
// if we're waiting on a Write operation, we want a single byte 1 or 4
|
||||
if ((tx_state == Telegram::Operation::TX_WRITE) && (length == 1)) {
|
||||
@@ -721,8 +720,7 @@ void EMSESP::incoming_telegram(uint8_t * data, const uint8_t length) {
|
||||
LOG_DEBUG(F("Last Tx write successful"));
|
||||
txservice_.increment_telegram_write_count(); // last tx/write was confirmed ok
|
||||
txservice_.send_poll(); // close the bus
|
||||
publish_id_ = txservice_.get_post_send_query();
|
||||
txservice_.post_send_query(); // follow up with any post-read
|
||||
publish_id_ = txservice_.post_send_query(); // follow up with any post-read if set
|
||||
txservice_.reset_retry_count();
|
||||
tx_successful = true;
|
||||
} else if (first_value == TxService::TX_WRITE_FAIL) {
|
||||
|
||||
@@ -223,7 +223,6 @@ void RxService::add(uint8_t * data, uint8_t length) {
|
||||
}
|
||||
|
||||
rx_telegrams_.emplace_back(rx_telegram_id_++, std::move(telegram)); // add to queue
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
@@ -579,21 +578,20 @@ bool TxService::is_last_tx(const uint8_t src, const uint8_t dest) const {
|
||||
}
|
||||
|
||||
// sends a type_id read request to fetch values after a successful Tx write operation
|
||||
void TxService::post_send_query() {
|
||||
if (telegram_last_post_send_query_) {
|
||||
uint8_t dest = (telegram_last_->dest & 0x7F);
|
||||
// unless the post_send_query has a type_id of 0
|
||||
uint16_t TxService::post_send_query() {
|
||||
uint16_t post_typeid = this->get_post_send_query();
|
||||
|
||||
if (post_typeid) {
|
||||
uint8_t dest = (this->telegram_last_->dest & 0x7F);
|
||||
uint8_t message_data[1] = {EMS_MAX_TELEGRAM_LENGTH}; // request all data, 32 bytes
|
||||
add(Telegram::Operation::TX_READ, dest, telegram_last_post_send_query_, 0, message_data, 1, true);
|
||||
this->add(Telegram::Operation::TX_READ, dest, post_typeid, 0, message_data, 1, true);
|
||||
// read_request(telegram_last_post_send_query_, dest, 0); // no offset
|
||||
LOG_DEBUG(F("Sending post validate read, type ID 0x%02X to dest 0x%02X"), telegram_last_post_send_query_, dest);
|
||||
}
|
||||
LOG_DEBUG(F("Sending post validate read, type ID 0x%02X to dest 0x%02X"), post_typeid, dest);
|
||||
set_post_send_query(0); // reset
|
||||
}
|
||||
|
||||
// print out the last Tx that was sent
|
||||
void TxService::print_last_tx() {
|
||||
LOG_DEBUG(F("Last Tx %s operation: %s"),
|
||||
(telegram_last_->operation == Telegram::Operation::TX_WRITE) ? F("Write") : F("Read"),
|
||||
telegram_last_->to_string().c_str());
|
||||
return post_typeid;
|
||||
}
|
||||
|
||||
} // namespace emsesp
|
||||
|
||||
@@ -182,7 +182,6 @@ class EMSbus {
|
||||
|
||||
private:
|
||||
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 bool bus_connected_; // start assuming the bus hasn't been connected
|
||||
static uint8_t ems_mask_; // unset=0xFF, buderus=0x00, junkers/ht3=0x80
|
||||
@@ -238,14 +237,12 @@ class RxService : public EMSbus {
|
||||
uint32_t telegram_count_ = 0; // # Rx received
|
||||
uint32_t telegram_error_count_ = 0; // # Rx CRC errors
|
||||
std::shared_ptr<const Telegram> rx_telegram; // the incoming Rx telegram
|
||||
|
||||
std::list<QueuedRxTelegram> rx_telegrams_; // the Rx Queue
|
||||
};
|
||||
|
||||
class TxService : public EMSbus {
|
||||
public:
|
||||
static constexpr size_t MAX_TX_TELEGRAMS = 20; // size of Tx queue
|
||||
|
||||
static constexpr uint8_t TX_WRITE_FAIL = 4; // EMS return code for fail
|
||||
static constexpr uint8_t TX_WRITE_SUCCESS = 1; // EMS return code for success
|
||||
|
||||
@@ -254,7 +251,6 @@ class TxService : public EMSbus {
|
||||
|
||||
void start();
|
||||
void send();
|
||||
|
||||
void add(const uint8_t operation,
|
||||
const uint8_t dest,
|
||||
const uint16_t type_id,
|
||||
@@ -263,16 +259,13 @@ class TxService : public EMSbus {
|
||||
const uint8_t message_length,
|
||||
const bool front = false);
|
||||
void add(const uint8_t operation, const uint8_t * data, const uint8_t length, const bool front = false);
|
||||
|
||||
void read_request(const uint16_t type_id, const uint8_t dest, const uint8_t offset = 0);
|
||||
|
||||
void send_raw(const char * telegram_data);
|
||||
|
||||
void send_poll();
|
||||
|
||||
void flush_tx_queue();
|
||||
|
||||
void retry_tx(const uint8_t operation, const uint8_t * data, const uint8_t length);
|
||||
bool is_last_tx(const uint8_t src, const uint8_t dest) const;
|
||||
uint16_t post_send_query();
|
||||
|
||||
uint8_t retry_count() const {
|
||||
return retry_count_;
|
||||
@@ -282,8 +275,6 @@ class TxService : public EMSbus {
|
||||
retry_count_ = 0;
|
||||
}
|
||||
|
||||
bool is_last_tx(const uint8_t src, const uint8_t dest) const;
|
||||
|
||||
void set_post_send_query(uint16_t type_id) {
|
||||
telegram_last_post_send_query_ = type_id;
|
||||
}
|
||||
@@ -328,10 +319,6 @@ class TxService : public EMSbus {
|
||||
telegram_write_count_++;
|
||||
}
|
||||
|
||||
void post_send_query();
|
||||
|
||||
void print_last_tx();
|
||||
|
||||
class QueuedTxTelegram {
|
||||
public:
|
||||
const uint16_t id_;
|
||||
|
||||
@@ -1 +1 @@
|
||||
#define EMSESP_APP_VERSION "2.0.1b2"
|
||||
#define EMSESP_APP_VERSION "2.0.1b3"
|
||||
|
||||
Reference in New Issue
Block a user