From b043f4c2ac098491b6d3f5e65ffa3c91d7b882d5 Mon Sep 17 00:00:00 2001 From: lumapu Date: Fri, 29 Dec 2023 15:48:25 +0100 Subject: [PATCH] 0.8.33 * improved communication thx @rejoe2 --- src/CHANGES.md | 3 +++ src/hm/hmRadio.h | 27 ++++++++++++++++++++++----- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/CHANGES.md b/src/CHANGES.md index 8dde956cb..8c1a56f07 100644 --- a/src/CHANGES.md +++ b/src/CHANGES.md @@ -1,5 +1,8 @@ # Development Changes +## 0.8.33 - 2023-12-29 +* improved communication thx @rejoe2 + ## 0.8.32 - 2023-12-29 * fix `start` / `stop` / `restart` commands #1287 * added message, if profile was not read until now #1300 diff --git a/src/hm/hmRadio.h b/src/hm/hmRadio.h index d7ae594b8..0754f83cb 100644 --- a/src/hm/hmRadio.h +++ b/src/hm/hmRadio.h @@ -113,34 +113,51 @@ class HmRadio : public Radio { mNrf24->flush_tx(); // empty TX FIFO // start listening + uint8_t chOffset = 2; + mRxChIdx = (mTxChIdx + chOffset) % RF_CHANNELS; mNrf24->setChannel(mRfChLst[mRxChIdx]); mNrf24->startListening(); if(NULL == mLastIv) // prevent reading on NULL object! return; - uint32_t startMicros = micros(); + uint32_t innerLoopTimeout = 55000; uint32_t loopMillis = millis(); uint32_t outerLoopTimeout = (mLastIv->mIsSingleframeReq) ? 100 : ((mLastIv->mCmd != AlarmData) && (mLastIv->mCmd != GridOnProFilePara)) ? 400 : 600; + bool isRxInit = true; + while ((millis() - loopMillis) < outerLoopTimeout) { - startMicros = micros(); - while ((micros() - startMicros) < 5110) { // listen (4088us or?) 5110us to each channel + uint32_t startMicros = micros(); + while ((micros() - startMicros) < innerLoopTimeout) { // listen (4088us or?) 5110us to each channel if (mIrqRcvd) { mIrqRcvd = false; if (getReceived()) { // everything received return; } + + innerLoopTimeout = 4088*5; + if (isRxInit) { + isRxInit = false; + if (micros() - startMicros < 42000) { + innerLoopTimeout = 4088*12; + mRxChIdx = (mRxChIdx + 4) % RF_CHANNELS; + mNrf24->setChannel(mRfChLst[mRxChIdx]); + } + } + + startMicros = micros(); } yield(); } // switch to next RX channel - mRxChIdx = (mRxChIdx + 1) % RF_CHANNELS; + mRxChIdx = (mRxChIdx + 4) % RF_CHANNELS; mNrf24->setChannel(mRfChLst[mRxChIdx]); + innerLoopTimeout = 4088; + isRxInit = false; } // not finished but time is over - mRxChIdx = (mRxChIdx + 1) % RF_CHANNELS; return; }