diff --git a/src/CHANGES.md b/src/CHANGES.md index d3295e71..ca5c40e8 100644 --- a/src/CHANGES.md +++ b/src/CHANGES.md @@ -1,5 +1,8 @@ # Development Changes +## 0.8.147 - 2024-09-29 +* improved queue, added mutex + ## 0.8.146 - 2024-09-23 * fix reset ticker #1754 * disable MqTT second and minute ticker on network loss diff --git a/src/defines.h b/src/defines.h index 3095b7a1..f88e5682 100644 --- a/src/defines.h +++ b/src/defines.h @@ -13,7 +13,7 @@ //------------------------------------- #define VERSION_MAJOR 0 #define VERSION_MINOR 8 -#define VERSION_PATCH 146 +#define VERSION_PATCH 147 //------------------------------------- typedef struct { uint8_t ch; diff --git a/src/hm/CommQueue.h b/src/hm/CommQueue.h index bf6f6861..bfb1e130 100644 --- a/src/hm/CommQueue.h +++ b/src/hm/CommQueue.h @@ -18,20 +18,35 @@ template class CommQueue { public: + CommQueue() { + mutex = xSemaphoreCreateBinaryStatic(&mutex_buffer); + xSemaphoreGive(mutex); + } + + ~CommQueue() { + vSemaphoreDelete(mutex); + } + void addImportant(Inverter<> *iv, uint8_t cmd) { queue_s q(iv, cmd, true); + xSemaphoreTake(mutex, portMAX_DELAY); if(!isIncluded(&q)) { dec(&mRdPtr); mQueue[mRdPtr] = q; - } + DPRINTLN(DBG_INFO, "addI, not incl.: " + String(iv->id)); + } else + DPRINTLN(DBG_INFO, "addI, incl.: " + String(iv->id)); + xSemaphoreGive(mutex); } void add(Inverter<> *iv, uint8_t cmd) { + xSemaphoreTake(mutex, portMAX_DELAY); queue_s q(iv, cmd, false); if(!isIncluded(&q)) { mQueue[mWrPtr] = q; inc(&mWrPtr); } + xSemaphoreGive(mutex); } void chgCmd(Inverter<> *iv, uint8_t cmd) { @@ -62,17 +77,21 @@ class CommQueue { protected: void add(queue_s q) { + xSemaphoreTake(mutex, portMAX_DELAY); mQueue[mWrPtr] = q; inc(&mWrPtr); + xSemaphoreGive(mutex); } void add(const queue_s *q, bool rstAttempts = false) { mQueue[mWrPtr] = *q; + xSemaphoreTake(mutex, portMAX_DELAY); if(rstAttempts) { mQueue[mWrPtr].attempts = DEFAULT_ATTEMPS; mQueue[mWrPtr].attemptsMax = DEFAULT_ATTEMPS; } inc(&mWrPtr); + xSemaphoreGive(mutex); } void chgCmd(uint8_t cmd) { @@ -81,20 +100,21 @@ class CommQueue { } void get(std::function cb) { - if(mRdPtr == mWrPtr) { + if(mRdPtr == mWrPtr) cb(false, &mQueue[mRdPtr]); // empty - return; - } - cb(true, &mQueue[mRdPtr]); + else + cb(true, &mQueue[mRdPtr]); } void cmdDone(bool keep = false) { + xSemaphoreTake(mutex, portMAX_DELAY); if(keep) { mQueue[mRdPtr].attempts = DEFAULT_ATTEMPS; mQueue[mRdPtr].attemptsMax = DEFAULT_ATTEMPS; add(mQueue[mRdPtr]); // add to the end again } inc(&mRdPtr); + xSemaphoreGive(mutex); } void setTs(const uint32_t *ts) { @@ -140,6 +160,10 @@ class CommQueue { std::array mQueue; uint8_t mWrPtr = 0; uint8_t mRdPtr = 0; + + private: + SemaphoreHandle_t mutex; + StaticSemaphore_t mutex_buffer; }; diff --git a/src/hm/Communication.h b/src/hm/Communication.h index e5a18858..90462b2c 100644 --- a/src/hm/Communication.h +++ b/src/hm/Communication.h @@ -21,6 +21,10 @@ typedef std::function *)> alarmListenerType; class Communication : public CommQueue<> { public: + Communication() : CommQueue() {} + + ~Communication() {} + void setup(uint32_t *timestamp, bool *serialDebug, bool *privacyMode, bool *printWholeTrace) { mTimestamp = timestamp; mPrivacyMode = privacyMode; diff --git a/src/hms/CmtRadio.h b/src/hms/CmtRadio.h index b6405329..fd49e8f8 100644 --- a/src/hms/CmtRadio.h +++ b/src/hms/CmtRadio.h @@ -53,7 +53,8 @@ class CmtRadio : public Radio { if(!mCfg->enabled) return; - DPRINT(DBG_INFO, F("sendControlPacket cmd: ")); + DPRINT_IVID(DBG_INFO, iv->id); + DBGPRINT(F("sendControlPacket cmd: ")); DBGHEXLN(cmd); initPacket(iv->radioId.u64, TX_REQ_DEVCONTROL, SINGLE_FRAME); uint8_t cnt = 10; diff --git a/src/web/RestApi.h b/src/web/RestApi.h index a868b31c..099dc13b 100644 --- a/src/web/RestApi.h +++ b/src/web/RestApi.h @@ -7,11 +7,6 @@ #define __WEB_API_H__ #include "../utils/dbg.h" -#ifdef ESP32 -#include "AsyncTCP.h" -#else -#include "ESPAsyncTCP.h" -#endif #include "../appInterface.h" #include "../hm/hmSystem.h" #include "../utils/helper.h" diff --git a/src/web/web.h b/src/web/web.h index 4a2544fd..95ef7af1 100644 --- a/src/web/web.h +++ b/src/web/web.h @@ -8,10 +8,7 @@ #include "../utils/dbg.h" #ifdef ESP32 -#include "AsyncTCP.h" #include "Update.h" -#else -#include "ESPAsyncTCP.h" #endif #include "../appInterface.h" #include "../hm/hmSystem.h"