From b7e056653511e38c622f84c3f1429861255dc14f Mon Sep 17 00:00:00 2001 From: lumapu Date: Sun, 29 Sep 2024 23:08:05 +0200 Subject: [PATCH] 0.8.147 code cleanup --- src/hm/CommQueue.h | 125 ++++++++++++++++++++--------------------- src/hm/Communication.h | 8 +-- 2 files changed, 65 insertions(+), 68 deletions(-) diff --git a/src/hm/CommQueue.h b/src/hm/CommQueue.h index bf2be217..c0676158 100644 --- a/src/hm/CommQueue.h +++ b/src/hm/CommQueue.h @@ -60,63 +60,6 @@ class CommQueue { return N; } - protected: - struct QueueElement { - Inverter<> *iv; - uint8_t cmd; - uint8_t attempts; - uint8_t attemptsMax; - uint32_t ts; - bool isDevControl; - - QueueElement() - : iv {nullptr} - , cmd {0} - , attempts {0} - , attemptsMax {0} - , ts {0} - , isDevControl {false} - {} - - QueueElement(Inverter<> *iv, uint8_t cmd, bool devCtrl) - : iv {iv} - , cmd {cmd} - , attempts {DefaultAttempts} - , attemptsMax {DefaultAttempts} - , ts {0} - , isDevControl {devCtrl} - {} - - QueueElement(const QueueElement &other) // copy constructor - : iv {other.iv} - , cmd {other.cmd} - , attempts {other.attempts} - , attemptsMax {other.attemptsMax} - , ts {other.ts} - , isDevControl {other.isDevControl} - {} - - void changeCmd(uint8_t cmd) { - this->cmd = cmd; - this->isDevControl = false; - } - - void setTs(const uint32_t ts) { - this->ts = ts; - } - - void setAttempt() { - if(this->attempts) - this->attempts--; - } - - void incrAttempt(uint8_t attempts = 1) { - this->attempts += attempts; - if (this->attempts > this->attemptsMax) - this->attemptsMax = this->attempts; - } - }; - protected: void add(QueueElement q) { xSemaphoreTake(this->mutex, portMAX_DELAY); @@ -148,13 +91,10 @@ class CommQueue { } } - void cmdDone(QueueElement *q, bool keep = false) { - if(keep) { - q->attempts = DefaultAttempts; - q->attemptsMax = DefaultAttempts; - add(q); // add to the end again - } - //inc(&this->rdPtr); + void cmdReset(QueueElement *q) { + q->attempts = DefaultAttempts; + q->attemptsMax = DefaultAttempts; + add(q); // add to the end again } private: @@ -183,6 +123,63 @@ class CommQueue { return false; } + protected: + struct QueueElement { + Inverter<> *iv; + uint8_t cmd; + uint8_t attempts; + uint8_t attemptsMax; + uint32_t ts; + bool isDevControl; + + QueueElement() + : iv {nullptr} + , cmd {0} + , attempts {0} + , attemptsMax {0} + , ts {0} + , isDevControl {false} + {} + + QueueElement(Inverter<> *iv, uint8_t cmd, bool devCtrl) + : iv {iv} + , cmd {cmd} + , attempts {DefaultAttempts} + , attemptsMax {DefaultAttempts} + , ts {0} + , isDevControl {devCtrl} + {} + + QueueElement(const QueueElement &other) // copy constructor + : iv {other.iv} + , cmd {other.cmd} + , attempts {other.attempts} + , attemptsMax {other.attemptsMax} + , ts {other.ts} + , isDevControl {other.isDevControl} + {} + + void changeCmd(uint8_t cmd) { + this->cmd = cmd; + this->isDevControl = false; + } + + void setTs(const uint32_t ts) { + this->ts = ts; + } + + void setAttempt() { + if(this->attempts) + this->attempts--; + } + + void incrAttempt(uint8_t attempts = 1) { + this->attempts += attempts; + if (this->attempts > this->attemptsMax) + this->attemptsMax = this->attempts; + } + }; + protected: std::array mQueue; diff --git a/src/hm/Communication.h b/src/hm/Communication.h index 48e8840e..df406db5 100644 --- a/src/hm/Communication.h +++ b/src/hm/Communication.h @@ -102,8 +102,6 @@ class Communication : public CommQueue<> { q->iv->curFrmCnt = 0; q->iv->radioStatistics.txCnt++; mIsRetransmit = false; - if(NULL == q->iv->radio) - cmdDone(q, false); // can't communicate while radio is not defined! mFirstTry = (INV_RADIO_TYPE_NRF == q->iv->ivRadioType) && (q->iv->isAvailable()); q->iv->mCmd = q->cmd; q->iv->mIsSingleframeReq = false; @@ -112,7 +110,7 @@ class Communication : public CommQueue<> { if((q->iv->ivGen == IV_MI) && ((q->cmd == MI_REQ_CH1) || (q->cmd == MI_REQ_4CH))) q->incrAttempt(q->iv->channels); // 2 more attempts for 2ch, 4 more for 4ch - mState = States::START; + mState = (NULL == q->iv->radio) ? States::RESET : States::START; break; case States::START: @@ -644,7 +642,9 @@ class Communication : public CommQueue<> { if(q->isDevControl) keep = !crcPass; - cmdDone(q, keep); + if(keep) + cmdReset(q); + q->iv->mGotFragment = false; q->iv->mGotLastMsg = false; q->iv->miMultiParts = 0;