Skip to content

Commit

Permalink
0.8.148
Browse files Browse the repository at this point in the history
* fixed send power limit #1757
* fix redirect after login
  • Loading branch information
lumapu committed Sep 30, 2024
1 parent 0b83e8b commit 4a32188
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 32 deletions.
4 changes: 4 additions & 0 deletions src/CHANGES.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
50 changes: 32 additions & 18 deletions src/hm/CommQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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:
Expand All @@ -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);
Expand All @@ -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<void(bool valid, QueueElement *q)> 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);
Expand Down
29 changes: 17 additions & 12 deletions src/hm/Communication.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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) {
Expand All @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -537,7 +542,7 @@ class Communication : public CommQueue<> {
} else
DBGPRINTLN(F("-> complete retransmit"));
mCompleteRetry = true;
mState = States::RESET;
mState = States::IDLE;
return false;
}

Expand Down Expand Up @@ -650,7 +655,7 @@ class Communication : public CommQueue<> {
q->iv->miMultiParts = 0;
mIsRetransmit = false;
mCompleteRetry = false;
mState = States::RESET;
mState = States::IDLE;
DBGPRINTLN(F("-----"));
}

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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 {
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ platform = [email protected]
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 =
Expand Down

0 comments on commit 4a32188

Please sign in to comment.