From 7bad0e04b1091d7073df2564fc81a92772a9427d Mon Sep 17 00:00:00 2001 From: MichaelDvP Date: Tue, 29 Nov 2022 17:04:05 +0100 Subject: [PATCH] allow raw telegram sending with other src-id --- src/emsesp.cpp | 2 +- src/telegram.cpp | 25 +++++++++++++++++++++---- src/telegram.h | 1 + 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/emsesp.cpp b/src/emsesp.cpp index 5690fc264..769103a79 100644 --- a/src/emsesp.cpp +++ b/src/emsesp.cpp @@ -1255,7 +1255,7 @@ void EMSESP::incoming_telegram(uint8_t * data, const uint8_t length) { } #endif // check for poll to us, if so send top message from Tx queue immediately and quit - if (poll_id == txservice_.ems_bus_id()) { + if (poll_id == txservice_.get_send_id()) { txservice_.send(); } // send remote room temperature if active diff --git a/src/telegram.cpp b/src/telegram.cpp index 45e86a4f9..c7d2869c9 100644 --- a/src/telegram.cpp +++ b/src/telegram.cpp @@ -268,6 +268,21 @@ void TxService::send_poll() const { } } +// get src id from next telegram to check poll in emsesp::incoming_telegram +uint8_t TxService::get_send_id() { + static uint32_t count = 0; + if (!tx_telegrams_.empty() && tx_telegrams_.front().telegram_->src != ems_bus_id()) { + if (++count > 500) { // after 500 polls (~3-10 sec) there will be no master poll for this id + tx_telegrams_.pop_front(); + count = 0; + return tx_telegrams_.empty() ? ems_bus_id() : tx_telegrams_.front().telegram_->src; + } + return tx_telegrams_.front().telegram_->src; + } + count = 0; + return ems_bus_id(); +} + // Process the next telegram on the Tx queue // This is sent when we receive a poll request void TxService::send() { @@ -463,7 +478,7 @@ void TxService::add(uint8_t operation, const uint8_t * data, const uint8_t lengt } // build header. src, dest and offset have fixed positions - uint8_t src = ems_bus_id(); // data[0]; we can only send data with own bus_id. + uint8_t src = operation == Telegram::Operation::TX_RAW ? data[0] : ems_bus_id(); uint8_t dest = data[1]; uint8_t offset = data[3]; @@ -499,7 +514,9 @@ void TxService::add(uint8_t operation, const uint8_t * data, const uint8_t lengt } if (operation == Telegram::Operation::TX_RAW) { - if (dest & 0x80) { + if (src != ems_bus_id()) { + operation = Telegram::Operation::NONE; // do not check reply/ack for other ids + } else if (dest & 0x80) { operation = Telegram::Operation::TX_READ; } else { operation = Telegram::Operation::TX_WRITE; @@ -585,8 +602,8 @@ bool TxService::send_raw(const char * telegram_data) { } } - // check valid length and src - if ((count < 4) || ((data[0] & 0x7F) != ems_bus_id())) { + // check valid length + if (count < 4) { return false; } diff --git a/src/telegram.h b/src/telegram.h index 710558f57..452edcb8b 100644 --- a/src/telegram.h +++ b/src/telegram.h @@ -290,6 +290,7 @@ class TxService : public EMSbus { void start(); void send(); + uint8_t get_send_id(); void add(const uint8_t operation, const uint8_t dest, const uint16_t type_id,