From 4a32188bb262e4da0e3d48cdf85b71b3639f4118 Mon Sep 17 00:00:00 2001 From: lumapu Date: Mon, 30 Sep 2024 23:30:30 +0200 Subject: [PATCH] 0.8.148 * fixed send power limit #1757 * fix redirect after login --- src/CHANGES.md | 4 ++++ src/defines.h | 2 +- src/hm/CommQueue.h | 50 +++++++++++++++++++++++++++--------------- src/hm/Communication.h | 29 ++++++++++++++---------- src/platformio.ini | 2 +- 5 files changed, 55 insertions(+), 32 deletions(-) diff --git a/src/CHANGES.md b/src/CHANGES.md index e52d899c..c035bcba 100644 --- a/src/CHANGES.md +++ b/src/CHANGES.md @@ -1,5 +1,9 @@ # Development Changes +## 0.8.148 - 2024-09-30 +* fixed send power limit #1757 +* fix redirect after login + ## 0.8.147 - 2024-09-29 * improved queue, added mutex * fixed send power limit #1757 diff --git a/src/defines.h b/src/defines.h index f88e5682..a8f1a345 100644 --- a/src/defines.h +++ b/src/defines.h @@ -13,7 +13,7 @@ //------------------------------------- #define VERSION_MAJOR 0 #define VERSION_MINOR 8 -#define VERSION_PATCH 147 +#define VERSION_PATCH 148 //------------------------------------- typedef struct { uint8_t ch; diff --git a/src/hm/CommQueue.h b/src/hm/CommQueue.h index 90e61071..dd82e82e 100644 --- a/src/hm/CommQueue.h +++ b/src/hm/CommQueue.h @@ -51,14 +51,11 @@ class CommQueue { , 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} - {} + QueueElement(const QueueElement&) = delete; + + QueueElement(QueueElement&& other) : QueueElement{} { + this->swap(other); + } void changeCmd(uint8_t cmd) { this->cmd = cmd; @@ -79,6 +76,22 @@ class CommQueue { if (this->attempts > this->attemptsMax) this->attemptsMax = this->attempts; } + + QueueElement& operator=(const QueueElement&) = delete; + + QueueElement& operator = (QueueElement&& other) { + this->swap(other); + return *this; + } + + void swap(QueueElement& other) { + std::swap(this->iv, other.iv); + std::swap(this->cmd, other.cmd); + std::swap(this->attempts, other.attempts); + std::swap(this->attemptsMax, other.attemptsMax); + std::swap(this->ts, other.ts); + std::swap(this->isDevControl, other.isDevControl); + } }; public: @@ -101,16 +114,16 @@ class CommQueue { xSemaphoreTake(this->mutex, portMAX_DELAY); if(!isIncluded(&q)) { dec(&this->rdPtr); - mQueue[this->rdPtr] = q; + mQueue[this->rdPtr] = std::move(q); } xSemaphoreGive(this->mutex); } void add(Inverter<> *iv, uint8_t cmd) { - xSemaphoreTake(this->mutex, portMAX_DELAY); QueueElement q(iv, cmd, false); + xSemaphoreTake(this->mutex, portMAX_DELAY); if(!isIncluded(&q)) { - mQueue[this->wrPtr] = q; + mQueue[this->wrPtr] = std::move(q); inc(&this->wrPtr); } xSemaphoreGive(this->mutex); @@ -135,21 +148,22 @@ class CommQueue { void add(QueueElement *q, bool rstAttempts = false) { xSemaphoreTake(this->mutex, portMAX_DELAY); - mQueue[this->wrPtr] = *q; if(rstAttempts) { - mQueue[this->wrPtr].attempts = DefaultAttempts; - mQueue[this->wrPtr].attemptsMax = DefaultAttempts; + q->attempts = DefaultAttempts; + q->attemptsMax = DefaultAttempts; } + mQueue[this->wrPtr] = std::move(*q); inc(&this->wrPtr); xSemaphoreGive(this->mutex); } void get(std::function cb) { - if(this->rdPtr == this->wrPtr) + xSemaphoreTake(this->mutex, portMAX_DELAY); + if(this->rdPtr == this->wrPtr) { + xSemaphoreGive(this->mutex); cb(false, nullptr); // empty - else { - xSemaphoreTake(this->mutex, portMAX_DELAY); - QueueElement el = mQueue[this->rdPtr]; + } else { + QueueElement el = std::move(mQueue[this->rdPtr]); inc(&this->rdPtr); xSemaphoreGive(this->mutex); cb(true, &el); diff --git a/src/hm/Communication.h b/src/hm/Communication.h index df406db5..1abaa9fd 100644 --- a/src/hm/Communication.h +++ b/src/hm/Communication.h @@ -36,7 +36,7 @@ class Communication : public CommQueue<> { void addImportant(Inverter<> *iv, uint8_t cmd) { if(!mIsDevControl) // only reset communication once there is no other devcontrol command - mState = States::RESET; // cancel current operation + mState = States::IDLE; // cancel current operation mIsDevControl = true; CommQueue::addImportant(iv, cmd); } @@ -54,7 +54,7 @@ class Communication : public CommQueue<> { } void loop() { - if(States::RESET == mState) { + if(States::IDLE == mState) { get([this](bool valid, QueueElement *q) { if(!valid) { if(mPrintSequenceDuration) { @@ -63,12 +63,12 @@ class Communication : public CommQueue<> { DBGPRINT(String(millis() - mLastEmptyQueueMillis)); DBGPRINTLN(F("ms")); DBGPRINTLN(F("-----")); - el.iv = nullptr; } return; // empty } - el = *q; + el = std::move(*q); + mState = States::INIT; if(!mPrintSequenceDuration) // entry was added to the queue mLastEmptyQueueMillis = millis(); mPrintSequenceDuration = true; @@ -82,7 +82,11 @@ class Communication : public CommQueue<> { private: inline void innerLoop(QueueElement *q) { switch(mState) { - case States::RESET: + default: + case States::IDLE: + break; + + case States::INIT: if (!mWaitTime.isTimeout()) return; @@ -110,7 +114,8 @@ 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 = (NULL == q->iv->radio) ? States::RESET : States::START; + if(NULL != q->iv->radio) + mState = States::START; break; case States::START: @@ -293,7 +298,7 @@ class Communication : public CommQueue<> { q->iv->radioStatistics.txCnt--; q->iv->radioStatistics.retransmits++; mCompleteRetry = true; - mState = States::RESET; + mState = States::IDLE; return; } } @@ -537,7 +542,7 @@ class Communication : public CommQueue<> { } else DBGPRINTLN(F("-> complete retransmit")); mCompleteRetry = true; - mState = States::RESET; + mState = States::IDLE; return false; } @@ -650,7 +655,7 @@ class Communication : public CommQueue<> { q->iv->miMultiParts = 0; mIsRetransmit = false; mCompleteRetry = false; - mState = States::RESET; + mState = States::IDLE; DBGPRINTLN(F("-----")); } @@ -797,7 +802,7 @@ class Communication : public CommQueue<> { inline void miDataDecode(packet_t *p, QueueElement *q) { record_t<> *rec = q->iv->getRecordStruct(RealTimeRunData_Debug); // choose the parser rec->ts = q->ts; - //mState = States::RESET; + //mState = States::IDLE; if(q->iv->miMultiParts < 6) q->iv->miMultiParts += 6; @@ -1031,7 +1036,7 @@ class Communication : public CommQueue<> { private: enum class States : uint8_t { - RESET, START, WAIT, CHECK_FRAMES, CHECK_PACKAGE + IDLE, INIT, START, WAIT, CHECK_FRAMES, CHECK_PACKAGE }; typedef struct { @@ -1041,7 +1046,7 @@ class Communication : public CommQueue<> { } frame_t; private: - States mState = States::RESET; + States mState = States::IDLE; uint32_t *mTimestamp = nullptr; QueueElement el; bool *mPrivacyMode = nullptr, *mSerialDebug = nullptr, *mPrintWholeTrace = nullptr; diff --git a/src/platformio.ini b/src/platformio.ini index bf789ed9..2c0af1d7 100644 --- a/src/platformio.ini +++ b/src/platformio.ini @@ -154,7 +154,7 @@ platform = espressif32@6.7.0 board = lolin_d32 lib_deps = ${env.lib_deps} - https://github.com/mathieucarbou/ESPAsyncWebServer#v3.3.1 + https://github.com/mathieucarbou/ESPAsyncWebServer#v3.2.4 build_flags = ${env.build_flags} -DSPI_HAL monitor_filters =