diff --git a/src/emsesp.cpp b/src/emsesp.cpp index 128f16a8f..699156b82 100644 --- a/src/emsesp.cpp +++ b/src/emsesp.cpp @@ -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) { diff --git a/src/telegram.cpp b/src/telegram.cpp index f6f3eb9ea..19eb66243 100644 --- a/src/telegram.cpp +++ b/src/telegram.cpp @@ -213,7 +213,7 @@ 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 src = EMSESP::check_master_device(src, type_id, true); - // create the telegram + // create the telegram auto telegram = std::make_shared(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 @@ -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); - 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); - // 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); - } -} +// 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(); -// 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()); + 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 + 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"), post_typeid, dest); + set_post_send_query(0); // reset + } + + return post_typeid; } } // namespace emsesp diff --git a/src/telegram.h b/src/telegram.h index 18fbcb6e9..54e83676c 100644 --- a/src/telegram.h +++ b/src/telegram.h @@ -182,13 +182,12 @@ 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 - static uint8_t ems_bus_id_; // the bus id, which configurable and stored in settings - static uint8_t tx_mode_; // local copy of the tx mode - static uint8_t tx_state_; // state of the Tx line (NONE or waiting on a TX_READ or TX_WRITE) + 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 + static uint8_t ems_bus_id_; // the bus id, which configurable and stored in settings + static uint8_t tx_mode_; // local copy of the tx mode + static uint8_t tx_state_; // state of the Tx line (NONE or waiting on a TX_READ or TX_WRITE) }; class RxService : public EMSbus { @@ -238,41 +237,35 @@ class RxService : public EMSbus { uint32_t telegram_count_ = 0; // # Rx received uint32_t telegram_error_count_ = 0; // # Rx CRC errors std::shared_ptr rx_telegram; // the incoming Rx telegram - - std::list rx_telegrams_; // the Rx Queue + std::list 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 + 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 TxService() = default; ~TxService() = default; - void start(); - void send(); - - void add(const uint8_t operation, - const uint8_t dest, - const uint16_t type_id, - const uint8_t offset, - uint8_t * message_data, - 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); + void start(); + void send(); + void add(const uint8_t operation, + const uint8_t dest, + const uint16_t type_id, + const uint8_t offset, + uint8_t * message_data, + 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_; diff --git a/src/version.h b/src/version.h index 785350975..3dc78b972 100644 --- a/src/version.h +++ b/src/version.h @@ -1 +1 @@ -#define EMSESP_APP_VERSION "2.0.1b2" +#define EMSESP_APP_VERSION "2.0.1b3"