From 349184a11331463b6e80363ea11b6f59e376d9a8 Mon Sep 17 00:00:00 2001 From: lumapu Date: Wed, 31 Jan 2024 22:24:08 +0100 Subject: [PATCH] 0.8.69 * fix brackets --- src/hm/Communication.h | 12 ++++++------ src/hm/Heuristic.h | 2 +- src/hm/HeuristicInv.h | 10 +++++++--- src/hm/hmDefines.h | 2 +- src/hm/hmInverter.h | 2 +- src/hm/hmRadio.h | 9 +++++---- src/hm/hmSystem.h | 6 +++--- 7 files changed, 24 insertions(+), 19 deletions(-) diff --git a/src/hm/Communication.h b/src/hm/Communication.h index 5725f2eca..923bffe16 100644 --- a/src/hm/Communication.h +++ b/src/hm/Communication.h @@ -87,7 +87,7 @@ class Communication : public CommQueue<> { mIsRetransmit = false; if(NULL == q->iv->radio) cmdDone(false); // can't communicate while radio is not defined! - mFirstTry = INV_RADIO_TYPE_NRF == q->iv->ivRadioType && q->iv->isAvailable(); + mFirstTry = (INV_RADIO_TYPE_NRF == q->iv->ivRadioType) && (q->iv->isAvailable()); q->iv->mCmd = q->cmd; q->iv->mIsSingleframeReq = false; mFramesExpected = getFramesExpected(q); // function to get expected frame count. @@ -116,7 +116,7 @@ class Communication : public CommQueue<> { //q->iv->radioStatistics.txCnt++; q->iv->radio->mRadioWaitTime.startTimeMonitor(mTimeout); if(!mIsRetransmit && (q->cmd == AlarmData) || (q->cmd == GridOnProFilePara)) - incrAttempt(q->cmd == AlarmData? MORE_ATTEMPS_ALARMDATA : MORE_ATTEMPS_GRIDONPROFILEPARA); + incrAttempt((q->cmd == AlarmData)? MORE_ATTEMPS_ALARMDATA : MORE_ATTEMPS_GRIDONPROFILEPARA); mIsRetransmit = false; setAttempt(); @@ -184,7 +184,7 @@ class Communication : public CommQueue<> { if (p->packet[0] == (TX_REQ_INFO + ALL_FRAMES)) { // response from get information command if(parseFrame(p)) { q->iv->curFrmCnt++; - if(!mIsRetransmit && (p->packet[9] == 0x02 || p->packet[9] == 0x82) && p->millis < LIMIT_FAST_IV) + if(!mIsRetransmit && ((p->packet[9] == 0x02) || (p->packet[9] == 0x82)) && (p->millis < LIMIT_FAST_IV)) mHeu.setIvRetriesGood(q->iv,p->millis < LIMIT_VERYFAST_IV); } } else if (p->packet[0] == (TX_REQ_DEVCONTROL + ALL_FRAMES)) { // response from dev control command @@ -257,13 +257,13 @@ class Communication : public CommQueue<> { return; } //count missing frames - if(!q->iv->mIsSingleframeReq && q->iv->ivRadioType == INV_RADIO_TYPE_NRF) { // already checked? + if(!q->iv->mIsSingleframeReq && (q->iv->ivRadioType == INV_RADIO_TYPE_NRF)) { // already checked? uint8_t missedFrames = 0; for(uint8_t i = 0; i < q->iv->radio->mFramesExpected; i++) { if(mLocalBuf[i].len == 0) missedFrames++; } - if(missedFrames > 3 || (q->cmd == RealTimeRunData_Debug && missedFrames > 1) || (missedFrames > 1 && missedFrames + 2 > q->attempts)) { + if(missedFrames > 3 || (q->cmd == RealTimeRunData_Debug && missedFrames > 1) || ((missedFrames > 1) && ((missedFrames + 2) > q->attempts))) { if(*mSerialDebug) { DPRINT_IVID(DBG_INFO, q->iv->id); DBGPRINT(String(missedFrames)); @@ -435,7 +435,7 @@ class Communication : public CommQueue<> { } inline bool parseMiFrame(packet_t *p, const queue_s *q) { - if(!mIsRetransmit && p->packet[9] == 0x00 && p->millis < LIMIT_FAST_IV_MI) //first frame is fast? + if((!mIsRetransmit && p->packet[9] == 0x00) && (p->millis < LIMIT_FAST_IV_MI)) //first frame is fast? mHeu.setIvRetriesGood(q->iv,p->millis < LIMIT_VERYFAST_IV_MI); if ((p->packet[0] == MI_REQ_CH1 + ALL_FRAMES) || (p->packet[0] == MI_REQ_CH2 + ALL_FRAMES) diff --git a/src/hm/Heuristic.h b/src/hm/Heuristic.h index 3fb866149..fa4512b50 100644 --- a/src/hm/Heuristic.h +++ b/src/hm/Heuristic.h @@ -1,5 +1,5 @@ //----------------------------------------------------------------------------- -// 2023 Ahoy, https://github.com/lumpapu/ahoy +// 2024 Ahoy, https://github.com/lumpapu/ahoy // Creative Commons - http://creativecommons.org/licenses/by-nc-sa/4.0/deed //----------------------------------------------------------------------------- diff --git a/src/hm/HeuristicInv.h b/src/hm/HeuristicInv.h index 89099ca87..913732bcb 100644 --- a/src/hm/HeuristicInv.h +++ b/src/hm/HeuristicInv.h @@ -26,6 +26,11 @@ class HeuristicInv { testChId = 0; saveOldTestQuality = -6; lastRxFragments = 0; + + rxSpeeds[0] = false; + rxSpeeds[1] = false; + rxSpeedCnt[0] = 0; + rxSpeedCnt[1] = 0; } bool isTxAtMax(void) const { @@ -42,9 +47,8 @@ class HeuristicInv { uint8_t testChId = 0; int8_t saveOldTestQuality = -6; uint8_t lastRxFragments = 0; - bool rxSpeeds[2] = {false,false}; // is inverter responding very fast respective fast? - uint8_t rxSpeedCnt[2] = {0,0}; // count how many messages had been received very fast respective fast (10 max) - + bool rxSpeeds[2] = {false, false}; // is inverter responding very fast respective fast? + uint8_t rxSpeedCnt[2] = {0, 0}; // count how many messages had been received very fast respective fast (10 max) }; #endif /*__HEURISTIC_INV_H__*/ diff --git a/src/hm/hmDefines.h b/src/hm/hmDefines.h index f06c06fe3..0b42aeae9 100644 --- a/src/hm/hmDefines.h +++ b/src/hm/hmDefines.h @@ -84,7 +84,7 @@ enum {INV_RADIO_TYPE_NRF = 0, INV_RADIO_TYPE_CMT}; #define DURATION_TXFRAME 85 // timeout parameter for first transmission and first expected frame (time to first channel switch from tx start!) (ms) #define DURATION_LISTEN_MIN 5 // time to stay at least on a listening channel (ms) #define DURATION_PAUSE_LASTFR 45 // how long to pause after last frame (ms) -const uint8_t duration_reserve[2] = {65,115}; +const uint8_t duration_reserve[2] = {65, 115}; #define LIMIT_FAST_IV 85 // time limit to qualify an inverter as very fast answering inverter #define LIMIT_VERYFAST_IV 70 // time limit to qualify an inverter as very fast answering inverter diff --git a/src/hm/hmInverter.h b/src/hm/hmInverter.h index e6e22fb71..e40151100 100644 --- a/src/hm/hmInverter.h +++ b/src/hm/hmInverter.h @@ -464,7 +464,7 @@ class Inverter { status = InverterStatus::OFF; actPowerLimit = 0xffff; // power limit will be read once inverter becomes available alarmMesIndex = 0; - if(ivRadioType == INV_RADIO_TYPE_NRF) { + if(INV_RADIO_TYPE_NRF == ivRadioType) { heuristics.clear(); #ifdef DYNAMIC_OFFSET rxOffset = ivGen == IV_HM ? 13 : 12; // effective 3 (or 2), but can easily be recognized as default setting diff --git a/src/hm/hmRadio.h b/src/hm/hmRadio.h index d1dd42d56..ca96a3330 100644 --- a/src/hm/hmRadio.h +++ b/src/hm/hmRadio.h @@ -328,12 +328,13 @@ class HmRadio : public Radio { isLastPackage = (p.packet[9] > ALL_FRAMES); // > ALL_FRAMES indicates last packet received if(mLastIv->mIsSingleframeReq) // we only expect one frame here... isRetransmitAnswer = true; + if(isLastPackage) setExpectedFrames(p.packet[9] - ALL_FRAMES); #ifdef DYNAMIC_OFFSET - if(p.packet[9] == 1 && p.millis < DURATION_ONEFRAME) + if((p.packet[9] == 1) && (p.millis < DURATION_ONEFRAME)) mLastIv->rxOffset = (RF_CHANNELS + mTxChIdx - tempRxChIdx + 1) % RF_CHANNELS; - else if(mNRFloopChannels && mLastIv->rxOffset > RF_CHANNELS) { // unsure setting? + else if(mNRFloopChannels && (mLastIv->rxOffset > RF_CHANNELS)) { // unsure setting? mLastIv->rxOffset = (RF_CHANNELS + mTxChIdx - tempRxChIdx + (isLastPackage ? mFramesExpected : p.packet[9])); // make clear it's not sure, start with one more offset mNRFloopChannels = false; } @@ -346,7 +347,7 @@ class HmRadio : public Radio { else if ((p.packet[0] != 0x88) && (p.packet[0] != 0x92)) // ignore MI status messages //#0 was p.packet[0] != 0x00 && isLastPackage = true; // response from dev control command #ifdef DYNAMIC_OFFSET - if(p.packet[9] == 0x00 && p.millis < DURATION_ONEFRAME) + if((p.packet[9] == 0x00) && (p.millis < DURATION_ONEFRAME)) mLastIv->rxOffset = (RF_CHANNELS + mTxChIdx - tempRxChIdx - 1) % RF_CHANNELS; #endif } @@ -408,7 +409,7 @@ class HmRadio : public Radio { mNrf24->stopListening(); mNrf24->flush_rx(); - if(!isRetransmit && mTxRetries != mTxRetriesNext) { + if(!isRetransmit && (mTxRetries != mTxRetriesNext)) { mNrf24->setRetries(3, mTxRetriesNext); mTxRetries = mTxRetriesNext; } diff --git a/src/hm/hmSystem.h b/src/hm/hmSystem.h index aa5d74920..aa2910e54 100644 --- a/src/hm/hmSystem.h +++ b/src/hm/hmSystem.h @@ -96,10 +96,10 @@ class HmSystem { DPRINTLN(DBG_WARN, F("MI Inverter, has some restrictions!")); #ifdef DYNAMIC_OFFSET - iv->rxOffset = iv->ivGen == IV_HM ? 13 : 12; // effective 3 (or 2), but can easily be recognized as default setting + iv->rxOffset = (iv->ivGen == IV_HM) ? 13 : 12; // effective 3 (or 2), but can easily be recognized as default setting #else - iv->rxOffset = (iv->ivGen == IV_HM && iv->type == INV_TYPE_4CH) ? 3 : 2; - iv->rxOffset = iv->ivGen == IV_HM ? 3 : 2; + iv->rxOffset = ((iv->ivGen == IV_HM) && (iv->type == INV_TYPE_4CH)) ? 3 : 2; + iv->rxOffset = (iv->ivGen == IV_HM) ? 3 : 2; #endif cb(iv);