Browse Source

Merge branch 'development03' of https://github.com/tictrick/ahoy into tictrick-development03

pull/1330/head
lumapu 9 months ago
parent
commit
2e6599ef7b
  1. 18
      src/hm/CommQueue.h
  2. 12
      src/hm/Communication.h

18
src/hm/CommQueue.h

@ -11,6 +11,10 @@
#include "hmInverter.h" #include "hmInverter.h"
#include "../utils/dbg.h" #include "../utils/dbg.h"
#define DEFAULT_ATTEMPS 10
#define MORE_ATTEMPS_ALARMDATA 15
#define MORE_ATTEMPS_GRIDONPROFILEPARA 15
template <uint8_t N=100> template <uint8_t N=100>
class CommQueue { class CommQueue {
public: public:
@ -44,11 +48,12 @@ class CommQueue {
Inverter<> *iv; Inverter<> *iv;
uint8_t cmd; uint8_t cmd;
uint8_t attempts; uint8_t attempts;
uint8_t attemptsMax;
uint32_t ts; uint32_t ts;
bool isDevControl; bool isDevControl;
queue_s() {} queue_s() {}
queue_s(Inverter<> *i, uint8_t c, bool dev) : queue_s(Inverter<> *i, uint8_t c, bool dev) :
iv(i), cmd(c), attempts(5), ts(0), isDevControl(dev) {} iv(i), cmd(c), attempts(DEFAULT_ATTEMPS), attemptsMax(DEFAULT_ATTEMPS), ts(0), isDevControl(dev) {}
}; };
protected: protected:
@ -59,8 +64,10 @@ class CommQueue {
void add(const queue_s *q, bool rstAttempts = false) { void add(const queue_s *q, bool rstAttempts = false) {
mQueue[mWrPtr] = *q; mQueue[mWrPtr] = *q;
if(rstAttempts) if(rstAttempts) {
mQueue[mWrPtr].attempts = 5; mQueue[mWrPtr].attempts = DEFAULT_ATTEMPS;
mQueue[mWrPtr].attemptsMax = DEFAULT_ATTEMPS;
}
inc(&mWrPtr); inc(&mWrPtr);
} }
@ -79,7 +86,8 @@ class CommQueue {
void cmdDone(bool keep = false) { void cmdDone(bool keep = false) {
if(keep) { if(keep) {
mQueue[mRdPtr].attempts = 5; mQueue[mRdPtr].attempts = 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);
@ -96,6 +104,8 @@ class CommQueue {
void incrAttempt(uint8_t attempts = 1) { void incrAttempt(uint8_t attempts = 1) {
mQueue[mRdPtr].attempts += attempts; mQueue[mRdPtr].attempts += attempts;
if (mQueue[mRdPtr].attempts > mQueue[mRdPtr].attemptsMax)
mQueue[mRdPtr].attemptsMax = mQueue[mRdPtr].attempts;
} }
void inc(uint8_t *ptr) { void inc(uint8_t *ptr) {

12
src/hm/Communication.h

@ -118,8 +118,8 @@ class Communication : public CommQueue<> {
mIsRetransmit = false; mIsRetransmit = false;
setAttempt(); setAttempt();
if((q->cmd == AlarmData) || (q->cmd == GridOnProFilePara)) if((q->cmd == AlarmData) || (q->cmd == GridOnProFilePara))
incrAttempt(15); incrAttempt(q->cmd == AlarmData? MORE_ATTEMPS_ALARMDATA : MORE_ATTEMPS_GRIDONPROFILEPARA);
/// statt 5:3
mState = States::WAIT; mState = States::WAIT;
break; break;
@ -194,7 +194,7 @@ class Communication : public CommQueue<> {
return; return;
} }
} else { } else {
mHeu.evalTxChQuality(q->iv, true, (4 - q->attempts), q->iv->curFrmCnt); mHeu.evalTxChQuality(q->iv, true, (q->attemptsMax - 1 - q->attempts), q->iv->curFrmCnt);
if(((q->cmd == 0x39) && (q->iv->type == INV_TYPE_4CH)) if(((q->cmd == 0x39) && (q->iv->type == INV_TYPE_4CH))
|| ((q->cmd == MI_REQ_CH2) && (q->iv->type == INV_TYPE_2CH)) || ((q->cmd == MI_REQ_CH2) && (q->iv->type == INV_TYPE_2CH))
|| ((q->cmd == MI_REQ_CH1) && (q->iv->type == INV_TYPE_1CH))) { || ((q->cmd == MI_REQ_CH1) && (q->iv->type == INV_TYPE_1CH))) {
@ -529,7 +529,7 @@ class Communication : public CommQueue<> {
private: private:
void closeRequest(const queue_s *q, bool crcPass) { void closeRequest(const queue_s *q, bool crcPass) {
mHeu.evalTxChQuality(q->iv, crcPass, (4 - q->attempts), q->iv->curFrmCnt); mHeu.evalTxChQuality(q->iv, crcPass, (q->attemptsMax - 1 - q->attempts), q->iv->curFrmCnt);
if(crcPass) if(crcPass)
q->iv->radioStatistics.rxSuccess++; q->iv->radioStatistics.rxSuccess++;
else if(q->iv->mGotFragment) else if(q->iv->mGotFragment)
@ -730,7 +730,7 @@ class Communication : public CommQueue<> {
miStsConsolidate(q, datachan, rec, p->packet[23], p->packet[24]); miStsConsolidate(q, datachan, rec, p->packet[23], p->packet[24]);
if (p->packet[0] < (0x39 + ALL_FRAMES) ) { if (p->packet[0] < (0x39 + ALL_FRAMES) ) {
mHeu.evalTxChQuality(q->iv, true, (4 - q->attempts), 1); mHeu.evalTxChQuality(q->iv, true, (q->attemptsMax - 1 - q->attempts), 1);
miNextRequest((p->packet[0] - ALL_FRAMES + 1), q); miNextRequest((p->packet[0] - ALL_FRAMES + 1), q);
} else { } else {
q->iv->miMultiParts = 7; // indicate we are ready q->iv->miMultiParts = 7; // indicate we are ready
@ -739,7 +739,7 @@ class Communication : public CommQueue<> {
} else if((p->packet[0] == (MI_REQ_CH1 + ALL_FRAMES)) && (q->iv->type == INV_TYPE_2CH)) { } else if((p->packet[0] == (MI_REQ_CH1 + ALL_FRAMES)) && (q->iv->type == INV_TYPE_2CH)) {
//addImportant(q->iv, MI_REQ_CH2); //addImportant(q->iv, MI_REQ_CH2);
miNextRequest(MI_REQ_CH2, q); miNextRequest(MI_REQ_CH2, q);
mHeu.evalTxChQuality(q->iv, true, (4 - q->attempts), q->iv->curFrmCnt); mHeu.evalTxChQuality(q->iv, true, (q->attemptsMax - 1 - q->attempts), q->iv->curFrmCnt);
//use also miMultiParts here for better statistics? //use also miMultiParts here for better statistics?
//mHeu.setGotFragment(q->iv); //mHeu.setGotFragment(q->iv);
} else { // first data msg for 1ch, 2nd for 2ch } else { // first data msg for 1ch, 2nd for 2ch

Loading…
Cancel
Save