From 2d65854dfbb9a5488543f1b808deca87c0211354 Mon Sep 17 00:00:00 2001 From: rejoe2 Date: Fri, 15 Dec 2023 08:59:48 +0100 Subject: [PATCH] restrict rx channels and change timings for hmRadio-rx --- src/defines.h | 2 +- src/hm/Communication.h | 8 ++++++- src/hm/hmInverter.h | 9 +++++++ src/hm/hmRadio.h | 54 +++++++++++++++++++++++++++++++++++++----- src/hm/radio.h | 1 + src/hms/hmsRadio.h | 4 ++++ 6 files changed, 70 insertions(+), 8 deletions(-) diff --git a/src/defines.h b/src/defines.h index c4559891..8939a8f8 100644 --- a/src/defines.h +++ b/src/defines.h @@ -13,7 +13,7 @@ //------------------------------------- #define VERSION_MAJOR 0 #define VERSION_MINOR 8 -#define VERSION_PATCH 23 +#define VERSION_PATCH 2301 //------------------------------------- typedef struct { diff --git a/src/hm/Communication.h b/src/hm/Communication.h index 51db6418..43b57426 100644 --- a/src/hm/Communication.h +++ b/src/hm/Communication.h @@ -86,6 +86,9 @@ class Communication : public CommQueue<> { if(NULL == q->iv->radio) cmdDone(true); // can't communicate while radio is not defined! mState = States::START; + + q->iv->radio->prepareReceive(q->iv, q->cmd, false); + break; case States::START: @@ -246,6 +249,9 @@ class Communication : public CommQueue<> { DBGPRINT(String(q->attempts)); DBGPRINTLN(F(" attempts left)")); } + if (!mIsRetransmit) + q->iv->radio->prepareReceive(q->iv, q->cmd, true); + sendRetransmit(q, (framnr-1)); mIsRetransmit = true; mlastTO_min = timeout_min; @@ -505,7 +511,7 @@ class Communication : public CommQueue<> { q->iv->mGotFragment = false; q->iv->mGotLastMsg = false; q->iv->miMultiParts = 0; - mIsRetransmit = false; + mIsRetransmit = false; mFirstTry = false; // for correct reset mState = States::RESET; DBGPRINTLN(F("-----")); diff --git a/src/hm/hmInverter.h b/src/hm/hmInverter.h index 3e3e1c08..34024f0d 100644 --- a/src/hm/hmInverter.h +++ b/src/hm/hmInverter.h @@ -131,6 +131,11 @@ class Inverter { bool mGotFragment; // shows if inverter has sent at least one fragment uint8_t curFrmCnt; // count received frames in current loop bool mGotLastMsg; // shows if inverter has already finished transmission cycle + uint8_t mRxChannels; // number of rx channels to listen to, defaults to 3; + uint32_t mRxTmoOuterLoop; // timeout for entire listening loop after sending, defaults to 400 (ms); + uint32_t mRxTmoInnerLoop; // timeout for each listening channel, defaults to 5110 (us) + uint8_t lastCmd; // holds the last sent command, defaults to 0xFF + Radio *radio; // pointer to associated radio class statistics_t radioStatistics; // information about transmitted, failed, ... packets HeuristicInv heuristics; @@ -156,7 +161,11 @@ class Inverter { alarmLastId = 0; rssi = -127; miMultiParts = 0; + lastCmd = 0xFF; mGotLastMsg = false; + mRxChannels = 3; + mRxTmoOuterLoop = 400; + mRxTmoInnerLoop = 5110; radio = NULL; commEnabled = true; diff --git a/src/hm/hmRadio.h b/src/hm/hmRadio.h index 14146830..a2094d86 100644 --- a/src/hm/hmRadio.h +++ b/src/hm/hmRadio.h @@ -104,6 +104,41 @@ class HmRadio : public Radio { DPRINTLN(DBG_WARN, F("WARNING! your NRF24 module can't be reached, check the wiring")); } + void prepareReceive(Inverter<> *iv, uint8_t cmd, bool singleframe = false) { + if (singleframe) { + iv->mRxTmoOuterLoop = 65; // SINGLEFR_TIMEOUT + iv->lastCmd = 0xFF; + return; + } + + if ( (iv->lastCmd == cmd) || ((iv->ivGen == IV_MI) && (iv->lastCmd != 0xFF)) ) + return; // nothing to be changed.... + + iv->lastCmd = cmd; + if (iv->ivGen != IV_MI) { + if (cmd == RealTimeRunData_Debug) { + if (iv->type == INV_TYPE_4CH) { + iv->mRxChannels = 3; + iv->mRxTmoOuterLoop = 300; + iv->mRxTmoInnerLoop = 5110; + } else { + iv->mRxChannels = 2; + iv->mRxTmoOuterLoop = 250; + iv->mRxTmoInnerLoop = 10220; + } + } else { //3rd gen defaults + iv->mRxChannels = 3; + iv->mRxTmoOuterLoop = 500; + iv->mRxTmoInnerLoop = 5110; + } + } else { // 2nd gen defaults + iv->mRxChannels = 2; + iv->mRxTmoOuterLoop = 250; + iv->mRxTmoInnerLoop = 5110; + } + } + + void loop(void) { if (!mIrqRcvd) return; // nothing to do @@ -121,8 +156,8 @@ class HmRadio : public Radio { uint32_t startMicros = micros(); uint32_t loopMillis = millis(); - while ((millis() - loopMillis) < 400) { - while ((micros() - startMicros) < 5110) { // listen (4088us or?) 5110us to each channel + while ((millis() - loopMillis) < mLastIv->mRxTmoOuterLoop) { + while ((micros() - startMicros) < mLastIv->mRxTmoInnerLoop) { // listen (4088us or?) 5110us to each channel if (mIrqRcvd) { mIrqRcvd = false; @@ -133,9 +168,16 @@ class HmRadio : public Radio { yield(); } // switch to next RX channel - if(++mRxChIdx >= RF_CHANNELS) + /*if(++mRxChIdx >= RF_CHANNELS) + mRxChIdx = 0;*/ + + if(++mRxChIdx >= mLastIv->mRxChannels) mRxChIdx = 0; - mNrf24->setChannel(mRfChLst[mRxChIdx]); + + uint8_t nextRxCh = (mRxChIdx + mTxChIdx + 1) % RF_MAX_CHANNEL_ID; + + //mNrf24->setChannel(mRfChLst[mRxChIdx]); + mNrf24->setChannel(mRfChLst[nextRxCh]); startMicros = micros(); } // not finished but time is over @@ -337,8 +379,8 @@ class HmRadio : public Radio { uint64_t DTU_RADIO_ID; uint8_t mRfChLst[RF_CHANNELS] = {03, 23, 40, 61, 75}; // channel List:2403, 2423, 2440, 2461, 2475MHz - uint8_t mTxChIdx = 0; - uint8_t mRxChIdx = 0; + uint8_t mTxChIdx = 0; + uint8_t mRxChIdx = 0; bool mGotLastMsg = false; uint32_t mMillis; diff --git a/src/hm/radio.h b/src/hm/radio.h index 2fe4f640..19e891c3 100644 --- a/src/hm/radio.h +++ b/src/hm/radio.h @@ -22,6 +22,7 @@ class Inverter; class Radio { public: virtual void sendControlPacket(Inverter<> *iv, uint8_t cmd, uint16_t *data, bool isRetransmit) = 0; + virtual void prepareReceive(Inverter<> *iv, uint8_t cmd, bool singleframe = false) = 0; virtual bool switchFrequency(Inverter<> *iv, uint32_t fromkHz, uint32_t tokHz) { return true; } virtual bool switchFrequencyCh(Inverter<> *iv, uint8_t fromCh, uint8_t toCh) { return true; } virtual bool isChipConnected(void) { return false; } diff --git a/src/hms/hmsRadio.h b/src/hms/hmsRadio.h index 40200085..c7b031e0 100644 --- a/src/hms/hmsRadio.h +++ b/src/hms/hmsRadio.h @@ -26,6 +26,10 @@ class CmtRadio : public Radio { mPrintWholeTrace = printWholeTrace; } + void prepareReceive(Inverter<> *iv, uint8_t cmd, bool singleframe = false) { + return; // only relevant for nRF type inverters + } + void loop() { mCmt.loop(); if((!mIrqRcvd) && (!mRqstGetRx))