mirror of
https://github.com/lumapu/ahoy.git
synced 2025-05-01 03:06:21 +02:00
0.8.147
* improved queue, added mutex
This commit is contained in:
parent
4c5c088607
commit
2558b058c2
7 changed files with 39 additions and 15 deletions
|
@ -1,5 +1,8 @@
|
||||||
# Development Changes
|
# Development Changes
|
||||||
|
|
||||||
|
## 0.8.147 - 2024-09-29
|
||||||
|
* improved queue, added mutex
|
||||||
|
|
||||||
## 0.8.146 - 2024-09-23
|
## 0.8.146 - 2024-09-23
|
||||||
* fix reset ticker #1754
|
* fix reset ticker #1754
|
||||||
* disable MqTT second and minute ticker on network loss
|
* disable MqTT second and minute ticker on network loss
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
//-------------------------------------
|
//-------------------------------------
|
||||||
#define VERSION_MAJOR 0
|
#define VERSION_MAJOR 0
|
||||||
#define VERSION_MINOR 8
|
#define VERSION_MINOR 8
|
||||||
#define VERSION_PATCH 146
|
#define VERSION_PATCH 147
|
||||||
//-------------------------------------
|
//-------------------------------------
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint8_t ch;
|
uint8_t ch;
|
||||||
|
|
|
@ -18,20 +18,35 @@
|
||||||
template <uint8_t N=100>
|
template <uint8_t N=100>
|
||||||
class CommQueue {
|
class CommQueue {
|
||||||
public:
|
public:
|
||||||
|
CommQueue() {
|
||||||
|
mutex = xSemaphoreCreateBinaryStatic(&mutex_buffer);
|
||||||
|
xSemaphoreGive(mutex);
|
||||||
|
}
|
||||||
|
|
||||||
|
~CommQueue() {
|
||||||
|
vSemaphoreDelete(mutex);
|
||||||
|
}
|
||||||
|
|
||||||
void addImportant(Inverter<> *iv, uint8_t cmd) {
|
void addImportant(Inverter<> *iv, uint8_t cmd) {
|
||||||
queue_s q(iv, cmd, true);
|
queue_s q(iv, cmd, true);
|
||||||
|
xSemaphoreTake(mutex, portMAX_DELAY);
|
||||||
if(!isIncluded(&q)) {
|
if(!isIncluded(&q)) {
|
||||||
dec(&mRdPtr);
|
dec(&mRdPtr);
|
||||||
mQueue[mRdPtr] = q;
|
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) {
|
void add(Inverter<> *iv, uint8_t cmd) {
|
||||||
|
xSemaphoreTake(mutex, portMAX_DELAY);
|
||||||
queue_s q(iv, cmd, false);
|
queue_s q(iv, cmd, false);
|
||||||
if(!isIncluded(&q)) {
|
if(!isIncluded(&q)) {
|
||||||
mQueue[mWrPtr] = q;
|
mQueue[mWrPtr] = q;
|
||||||
inc(&mWrPtr);
|
inc(&mWrPtr);
|
||||||
}
|
}
|
||||||
|
xSemaphoreGive(mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void chgCmd(Inverter<> *iv, uint8_t cmd) {
|
void chgCmd(Inverter<> *iv, uint8_t cmd) {
|
||||||
|
@ -62,17 +77,21 @@ class CommQueue {
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void add(queue_s q) {
|
void add(queue_s q) {
|
||||||
|
xSemaphoreTake(mutex, portMAX_DELAY);
|
||||||
mQueue[mWrPtr] = q;
|
mQueue[mWrPtr] = q;
|
||||||
inc(&mWrPtr);
|
inc(&mWrPtr);
|
||||||
|
xSemaphoreGive(mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void add(const queue_s *q, bool rstAttempts = false) {
|
void add(const queue_s *q, bool rstAttempts = false) {
|
||||||
mQueue[mWrPtr] = *q;
|
mQueue[mWrPtr] = *q;
|
||||||
|
xSemaphoreTake(mutex, portMAX_DELAY);
|
||||||
if(rstAttempts) {
|
if(rstAttempts) {
|
||||||
mQueue[mWrPtr].attempts = DEFAULT_ATTEMPS;
|
mQueue[mWrPtr].attempts = DEFAULT_ATTEMPS;
|
||||||
mQueue[mWrPtr].attemptsMax = DEFAULT_ATTEMPS;
|
mQueue[mWrPtr].attemptsMax = DEFAULT_ATTEMPS;
|
||||||
}
|
}
|
||||||
inc(&mWrPtr);
|
inc(&mWrPtr);
|
||||||
|
xSemaphoreGive(mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void chgCmd(uint8_t cmd) {
|
void chgCmd(uint8_t cmd) {
|
||||||
|
@ -81,20 +100,21 @@ class CommQueue {
|
||||||
}
|
}
|
||||||
|
|
||||||
void get(std::function<void(bool valid, const queue_s *q)> cb) {
|
void get(std::function<void(bool valid, const queue_s *q)> cb) {
|
||||||
if(mRdPtr == mWrPtr) {
|
if(mRdPtr == mWrPtr)
|
||||||
cb(false, &mQueue[mRdPtr]); // empty
|
cb(false, &mQueue[mRdPtr]); // empty
|
||||||
return;
|
else
|
||||||
}
|
|
||||||
cb(true, &mQueue[mRdPtr]);
|
cb(true, &mQueue[mRdPtr]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmdDone(bool keep = false) {
|
void cmdDone(bool keep = false) {
|
||||||
|
xSemaphoreTake(mutex, portMAX_DELAY);
|
||||||
if(keep) {
|
if(keep) {
|
||||||
mQueue[mRdPtr].attempts = DEFAULT_ATTEMPS;
|
mQueue[mRdPtr].attempts = DEFAULT_ATTEMPS;
|
||||||
mQueue[mRdPtr].attemptsMax = DEFAULT_ATTEMPS;
|
mQueue[mRdPtr].attemptsMax = DEFAULT_ATTEMPS;
|
||||||
add(mQueue[mRdPtr]); // add to the end again
|
add(mQueue[mRdPtr]); // add to the end again
|
||||||
}
|
}
|
||||||
inc(&mRdPtr);
|
inc(&mRdPtr);
|
||||||
|
xSemaphoreGive(mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setTs(const uint32_t *ts) {
|
void setTs(const uint32_t *ts) {
|
||||||
|
@ -140,6 +160,10 @@ class CommQueue {
|
||||||
std::array<queue_s, N> mQueue;
|
std::array<queue_s, N> mQueue;
|
||||||
uint8_t mWrPtr = 0;
|
uint8_t mWrPtr = 0;
|
||||||
uint8_t mRdPtr = 0;
|
uint8_t mRdPtr = 0;
|
||||||
|
|
||||||
|
private:
|
||||||
|
SemaphoreHandle_t mutex;
|
||||||
|
StaticSemaphore_t mutex_buffer;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,10 @@ typedef std::function<void(Inverter<> *)> alarmListenerType;
|
||||||
|
|
||||||
class Communication : public CommQueue<> {
|
class Communication : public CommQueue<> {
|
||||||
public:
|
public:
|
||||||
|
Communication() : CommQueue() {}
|
||||||
|
|
||||||
|
~Communication() {}
|
||||||
|
|
||||||
void setup(uint32_t *timestamp, bool *serialDebug, bool *privacyMode, bool *printWholeTrace) {
|
void setup(uint32_t *timestamp, bool *serialDebug, bool *privacyMode, bool *printWholeTrace) {
|
||||||
mTimestamp = timestamp;
|
mTimestamp = timestamp;
|
||||||
mPrivacyMode = privacyMode;
|
mPrivacyMode = privacyMode;
|
||||||
|
|
|
@ -53,7 +53,8 @@ class CmtRadio : public Radio {
|
||||||
if(!mCfg->enabled)
|
if(!mCfg->enabled)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
DPRINT(DBG_INFO, F("sendControlPacket cmd: "));
|
DPRINT_IVID(DBG_INFO, iv->id);
|
||||||
|
DBGPRINT(F("sendControlPacket cmd: "));
|
||||||
DBGHEXLN(cmd);
|
DBGHEXLN(cmd);
|
||||||
initPacket(iv->radioId.u64, TX_REQ_DEVCONTROL, SINGLE_FRAME);
|
initPacket(iv->radioId.u64, TX_REQ_DEVCONTROL, SINGLE_FRAME);
|
||||||
uint8_t cnt = 10;
|
uint8_t cnt = 10;
|
||||||
|
|
|
@ -7,11 +7,6 @@
|
||||||
#define __WEB_API_H__
|
#define __WEB_API_H__
|
||||||
|
|
||||||
#include "../utils/dbg.h"
|
#include "../utils/dbg.h"
|
||||||
#ifdef ESP32
|
|
||||||
#include "AsyncTCP.h"
|
|
||||||
#else
|
|
||||||
#include "ESPAsyncTCP.h"
|
|
||||||
#endif
|
|
||||||
#include "../appInterface.h"
|
#include "../appInterface.h"
|
||||||
#include "../hm/hmSystem.h"
|
#include "../hm/hmSystem.h"
|
||||||
#include "../utils/helper.h"
|
#include "../utils/helper.h"
|
||||||
|
|
|
@ -8,10 +8,7 @@
|
||||||
|
|
||||||
#include "../utils/dbg.h"
|
#include "../utils/dbg.h"
|
||||||
#ifdef ESP32
|
#ifdef ESP32
|
||||||
#include "AsyncTCP.h"
|
|
||||||
#include "Update.h"
|
#include "Update.h"
|
||||||
#else
|
|
||||||
#include "ESPAsyncTCP.h"
|
|
||||||
#endif
|
#endif
|
||||||
#include "../appInterface.h"
|
#include "../appInterface.h"
|
||||||
#include "../hm/hmSystem.h"
|
#include "../hm/hmSystem.h"
|
||||||
|
|
Loading…
Add table
Reference in a new issue