Skip to content

Commit b7e0566

Browse files
committed
0.8.147
code cleanup
1 parent 08bc773 commit b7e0566

File tree

2 files changed

+65
-68
lines changed

2 files changed

+65
-68
lines changed

src/hm/CommQueue.h

+61-64
Original file line numberDiff line numberDiff line change
@@ -60,63 +60,6 @@ class CommQueue {
6060
return N;
6161
}
6262

63-
protected:
64-
struct QueueElement {
65-
Inverter<> *iv;
66-
uint8_t cmd;
67-
uint8_t attempts;
68-
uint8_t attemptsMax;
69-
uint32_t ts;
70-
bool isDevControl;
71-
72-
QueueElement()
73-
: iv {nullptr}
74-
, cmd {0}
75-
, attempts {0}
76-
, attemptsMax {0}
77-
, ts {0}
78-
, isDevControl {false}
79-
{}
80-
81-
QueueElement(Inverter<> *iv, uint8_t cmd, bool devCtrl)
82-
: iv {iv}
83-
, cmd {cmd}
84-
, attempts {DefaultAttempts}
85-
, attemptsMax {DefaultAttempts}
86-
, ts {0}
87-
, isDevControl {devCtrl}
88-
{}
89-
90-
QueueElement(const QueueElement &other) // copy constructor
91-
: iv {other.iv}
92-
, cmd {other.cmd}
93-
, attempts {other.attempts}
94-
, attemptsMax {other.attemptsMax}
95-
, ts {other.ts}
96-
, isDevControl {other.isDevControl}
97-
{}
98-
99-
void changeCmd(uint8_t cmd) {
100-
this->cmd = cmd;
101-
this->isDevControl = false;
102-
}
103-
104-
void setTs(const uint32_t ts) {
105-
this->ts = ts;
106-
}
107-
108-
void setAttempt() {
109-
if(this->attempts)
110-
this->attempts--;
111-
}
112-
113-
void incrAttempt(uint8_t attempts = 1) {
114-
this->attempts += attempts;
115-
if (this->attempts > this->attemptsMax)
116-
this->attemptsMax = this->attempts;
117-
}
118-
};
119-
12063
protected:
12164
void add(QueueElement q) {
12265
xSemaphoreTake(this->mutex, portMAX_DELAY);
@@ -148,13 +91,10 @@ class CommQueue {
14891
}
14992
}
15093

151-
void cmdDone(QueueElement *q, bool keep = false) {
152-
if(keep) {
153-
q->attempts = DefaultAttempts;
154-
q->attemptsMax = DefaultAttempts;
155-
add(q); // add to the end again
156-
}
157-
//inc(&this->rdPtr);
94+
void cmdReset(QueueElement *q) {
95+
q->attempts = DefaultAttempts;
96+
q->attemptsMax = DefaultAttempts;
97+
add(q); // add to the end again
15898
}
15999

160100
private:
@@ -183,6 +123,63 @@ class CommQueue {
183123
return false;
184124
}
185125

126+
protected:
127+
struct QueueElement {
128+
Inverter<> *iv;
129+
uint8_t cmd;
130+
uint8_t attempts;
131+
uint8_t attemptsMax;
132+
uint32_t ts;
133+
bool isDevControl;
134+
135+
QueueElement()
136+
: iv {nullptr}
137+
, cmd {0}
138+
, attempts {0}
139+
, attemptsMax {0}
140+
, ts {0}
141+
, isDevControl {false}
142+
{}
143+
144+
QueueElement(Inverter<> *iv, uint8_t cmd, bool devCtrl)
145+
: iv {iv}
146+
, cmd {cmd}
147+
, attempts {DefaultAttempts}
148+
, attemptsMax {DefaultAttempts}
149+
, ts {0}
150+
, isDevControl {devCtrl}
151+
{}
152+
153+
QueueElement(const QueueElement &other) // copy constructor
154+
: iv {other.iv}
155+
, cmd {other.cmd}
156+
, attempts {other.attempts}
157+
, attemptsMax {other.attemptsMax}
158+
, ts {other.ts}
159+
, isDevControl {other.isDevControl}
160+
{}
161+
162+
void changeCmd(uint8_t cmd) {
163+
this->cmd = cmd;
164+
this->isDevControl = false;
165+
}
166+
167+
void setTs(const uint32_t ts) {
168+
this->ts = ts;
169+
}
170+
171+
void setAttempt() {
172+
if(this->attempts)
173+
this->attempts--;
174+
}
175+
176+
void incrAttempt(uint8_t attempts = 1) {
177+
this->attempts += attempts;
178+
if (this->attempts > this->attemptsMax)
179+
this->attemptsMax = this->attempts;
180+
}
181+
};
182+
186183
protected:
187184
std::array<QueueElement, N> mQueue;
188185

src/hm/Communication.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,6 @@ class Communication : public CommQueue<> {
102102
q->iv->curFrmCnt = 0;
103103
q->iv->radioStatistics.txCnt++;
104104
mIsRetransmit = false;
105-
if(NULL == q->iv->radio)
106-
cmdDone(q, false); // can't communicate while radio is not defined!
107105
mFirstTry = (INV_RADIO_TYPE_NRF == q->iv->ivRadioType) && (q->iv->isAvailable());
108106
q->iv->mCmd = q->cmd;
109107
q->iv->mIsSingleframeReq = false;
@@ -112,7 +110,7 @@ class Communication : public CommQueue<> {
112110
if((q->iv->ivGen == IV_MI) && ((q->cmd == MI_REQ_CH1) || (q->cmd == MI_REQ_4CH)))
113111
q->incrAttempt(q->iv->channels); // 2 more attempts for 2ch, 4 more for 4ch
114112

115-
mState = States::START;
113+
mState = (NULL == q->iv->radio) ? States::RESET : States::START;
116114
break;
117115

118116
case States::START:
@@ -644,7 +642,9 @@ class Communication : public CommQueue<> {
644642
if(q->isDevControl)
645643
keep = !crcPass;
646644

647-
cmdDone(q, keep);
645+
if(keep)
646+
cmdReset(q);
647+
648648
q->iv->mGotFragment = false;
649649
q->iv->mGotLastMsg = false;
650650
q->iv->miMultiParts = 0;

0 commit comments

Comments
 (0)