Browse Source

0.8.147

* improved queue, added mutex
pull/1759/head
lumapu 4 months ago
parent
commit
2558b058c2
  1. 3
      src/CHANGES.md
  2. 2
      src/defines.h
  3. 34
      src/hm/CommQueue.h
  4. 4
      src/hm/Communication.h
  5. 3
      src/hms/CmtRadio.h
  6. 5
      src/web/RestApi.h
  7. 3
      src/web/web.h

3
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

2
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;

34
src/hm/CommQueue.h

@ -18,20 +18,35 @@
template <uint8_t N=100>
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<void(bool valid, const queue_s *q)> 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<queue_s, N> mQueue;
uint8_t mWrPtr = 0;
uint8_t mRdPtr = 0;
private:
SemaphoreHandle_t mutex;
StaticSemaphore_t mutex_buffer;
};

4
src/hm/Communication.h

@ -21,6 +21,10 @@ typedef std::function<void(Inverter<> *)> alarmListenerType;
class Communication : public CommQueue<> {
public:
Communication() : CommQueue() {}
~Communication() {}
void setup(uint32_t *timestamp, bool *serialDebug, bool *privacyMode, bool *printWholeTrace) {
mTimestamp = timestamp;
mPrivacyMode = privacyMode;

3
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;

5
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"

3
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"

Loading…
Cancel
Save