Browse Source

based on .27

- fix MI communication incl. "fastNext"
- further restructuring of tx->rx channel bindings
pull/1284/head
rejoe2 2 years ago
committed by GitHub
parent
commit
fab804309e
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      src/defines.h
  2. 26
      src/hm/CommQueue.h
  3. 55
      src/hm/Communication.h
  4. 18
      src/hm/hmRadio.h

2
src/defines.h

@ -13,7 +13,7 @@
//------------------------------------- //-------------------------------------
#define VERSION_MAJOR 0 #define VERSION_MAJOR 0
#define VERSION_MINOR 8 #define VERSION_MINOR 8
#define VERSION_PATCH 2601 #define VERSION_PATCH 2701
//------------------------------------- //-------------------------------------
typedef struct { typedef struct {

26
src/hm/CommQueue.h

@ -16,22 +16,22 @@ class CommQueue {
public: public:
CommQueue() {} CommQueue() {}
void addImportant(Inverter<> *iv, uint8_t cmd, bool delOnPop = true) { void addImportant(Inverter<> *iv, uint8_t cmd) {
dec(&mRdPtr); dec(&mRdPtr);
mQueue[mRdPtr] = queue_s(iv, cmd, delOnPop, true); mQueue[mRdPtr] = queue_s(iv, cmd, true);
} }
void add(Inverter<> *iv, uint8_t cmd, bool delOnPop = true) { void add(Inverter<> *iv, uint8_t cmd) {
mQueue[mWrPtr] = queue_s(iv, cmd, delOnPop, false); mQueue[mWrPtr] = queue_s(iv, cmd, false);
inc(&mWrPtr); inc(&mWrPtr);
} }
void chgCmd(Inverter<> *iv, uint8_t cmd, bool delOnPop = true) { void chgCmd(Inverter<> *iv, uint8_t cmd) {
mQueue[mWrPtr] = queue_s(iv, cmd, delOnPop, false); mQueue[mWrPtr] = queue_s(iv, cmd, false);
} }
uint8_t getFillState(void) { uint8_t getFillState(void) {
DPRINTLN(DBG_INFO, "wr: " + String(mWrPtr) + ", rd: " + String(mRdPtr)); //DPRINTLN(DBG_INFO, "wr: " + String(mWrPtr) + ", rd: " + String(mRdPtr));
return abs(mRdPtr - mWrPtr); return abs(mRdPtr - mWrPtr);
} }
@ -48,8 +48,8 @@ class CommQueue {
bool delOnPop; bool delOnPop;
bool isDevControl; bool isDevControl;
queue_s() {} queue_s() {}
queue_s(Inverter<> *i, uint8_t c, bool d, bool dev) : queue_s(Inverter<> *i, uint8_t c, bool dev) :
iv(i), cmd(c), attempts(5), ts(0), delOnPop(d), isDevControl(dev) {} iv(i), cmd(c), attempts(5), ts(0), isDevControl(dev) {}
}; };
protected: protected:
@ -78,8 +78,8 @@ class CommQueue {
cb(true, &mQueue[mRdPtr]); cb(true, &mQueue[mRdPtr]);
} }
void cmdDone(bool force = false) { void cmdDone(bool keep = false) {
if(!mQueue[mRdPtr].delOnPop && !force) { if(keep) {
mQueue[mRdPtr].attempts = 5; mQueue[mRdPtr].attempts = 5;
add(mQueue[mRdPtr]); // add to the end again add(mQueue[mRdPtr]); // add to the end again
} }
@ -95,8 +95,8 @@ class CommQueue {
mQueue[mRdPtr].attempts--; mQueue[mRdPtr].attempts--;
} }
void incrAttempt(void) { void incrAttempt(uint8_t nrAttempts = 1) {
mQueue[mRdPtr].attempts++; mQueue[mRdPtr].attempts += nrAttempts ;
} }
void inc(uint8_t *ptr) { void inc(uint8_t *ptr) {

55
src/hm/Communication.h

@ -30,9 +30,9 @@ class Communication : public CommQueue<> {
mInverterGap = inverterGap; mInverterGap = inverterGap;
} }
void addImportant(Inverter<> *iv, uint8_t cmd, bool delOnPop = true) { void addImportant(Inverter<> *iv, uint8_t cmd) {
mState = States::RESET; // cancel current operation mState = States::RESET; // cancel current operation
CommQueue::addImportant(iv, cmd, delOnPop); CommQueue::addImportant(iv, cmd);
} }
void addPayloadListener(payloadListenerType cb) { void addPayloadListener(payloadListenerType cb) {
@ -84,7 +84,7 @@ class Communication : public CommQueue<> {
q->iv->curFrmCnt = 0; q->iv->curFrmCnt = 0;
mIsRetransmit = false; mIsRetransmit = false;
if(NULL == q->iv->radio) if(NULL == q->iv->radio)
cmdDone(true); // can't communicate while radio is not defined! cmdDone(false); // can't communicate while radio is not defined!
mState = States::START; mState = States::START;
q->iv->mCmd = q->cmd; q->iv->mCmd = q->cmd;
@ -165,6 +165,7 @@ class Communication : public CommQueue<> {
closeRequest(q, false); closeRequest(q, false);
break; break;
} }
if ((IV_MI != q->iv->ivGen) || (0 == q->attempts) )
mIsRetransmit = false; mIsRetransmit = false;
mFirstTry = false; // for correct reset mFirstTry = false; // for correct reset
@ -183,6 +184,7 @@ class Communication : public CommQueue<> {
closeRequest(q, true); closeRequest(q, true);
else else
closeRequest(q, false); closeRequest(q, false);
q->iv->radio->mBufCtrl.pop();
return; // don't wait for empty buffer return; // don't wait for empty buffer
} else if(IV_MI == q->iv->ivGen) { } else if(IV_MI == q->iv->ivGen) {
if(parseMiFrame(p, q)) if(parseMiFrame(p, q))
@ -205,6 +207,11 @@ class Communication : public CommQueue<> {
bool fastNext = true; bool fastNext = true;
if(q->iv->miMultiParts < 6) { if(q->iv->miMultiParts < 6) {
mState = States::WAIT; mState = States::WAIT;
if((millis() > mWaitTimeout && mIsRetransmit) || !mIsRetransmit) {
miRepeatRequest(q);
return;
}
} else { } else {
mHeu.evalTxChQuality(q->iv, true, (4 - q->attempts), q->iv->curFrmCnt); mHeu.evalTxChQuality(q->iv, true, (4 - 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))
@ -213,14 +220,17 @@ class Communication : public CommQueue<> {
miComplete(q->iv); miComplete(q->iv);
fastNext = false; fastNext = false;
} }
closeRequest(q, true);
if(fastNext) { if(fastNext) {
DPRINTLN(DBG_INFO, F("we should enqueue sth immediately....")); miNextRequest(q->iv->type == INV_TYPE_4CH ? MI_REQ_4CH : MI_REQ_CH1, q);
//DPRINTLN(DBG_INFO, F("we should enqueue sth immediately...."));
// immediately send out regular production data request // immediately send out regular production data request
// and reset mWaitTimeout // and reset mWaitTimeout
//mWaitTimeout = mWaitTimeout - *mInverterGap; //mWaitTimeout = mWaitTimeout - *mInverterGap;
//chgCmd((q->iv->type == INV_TYPE_4CH) ? MI_REQ_4CH : MI_REQ_CH1); //chgCmd((q->iv->type == INV_TYPE_4CH) ? MI_REQ_4CH : MI_REQ_CH1);
//mState = States::RESET; //mState = States::RESET;
} else {
closeRequest(q, true);
} }
} }
@ -354,8 +364,11 @@ class Communication : public CommQueue<> {
return false; // CRC8 is wrong, frame invalid return false; // CRC8 is wrong, frame invalid
} }
if((*frameId & ALL_FRAMES) == ALL_FRAMES) if((*frameId & ALL_FRAMES) == ALL_FRAMES) {
mMaxFrameId = (*frameId & 0x7f); mMaxFrameId = (*frameId & 0x7f);
if(mMaxFrameId > 8) // large payloads, e.g. AlarmData
incrAttempt(mMaxFrameId - 6);
}
frame_t *f = &mLocalBuf[(*frameId & 0x7f) - 1]; frame_t *f = &mLocalBuf[(*frameId & 0x7f) - 1];
memcpy(f->buf, &p->packet[10], p->len-11); memcpy(f->buf, &p->packet[10], p->len-11);
@ -526,12 +539,15 @@ class Communication : public CommQueue<> {
q->iv->radioStatistics.rxSuccess++; q->iv->radioStatistics.rxSuccess++;
else if(q->iv->mGotFragment) else if(q->iv->mGotFragment)
q->iv->radioStatistics.rxFail++; // got no complete payload q->iv->radioStatistics.rxFail++; // got no complete payload
else { else
q->iv->radioStatistics.rxFailNoAnser++; // got nothing q->iv->radioStatistics.rxFailNoAnser++; // got nothing
}
mWaitTimeout = millis() + *mInverterGap; mWaitTimeout = millis() + *mInverterGap;
cmdDone(q->delOnPop); bool keep = false;
if(q->isDevControl)
keep = !crcPass;
cmdDone(keep);
q->iv->mGotFragment = false; q->iv->mGotFragment = false;
q->iv->mGotLastMsg = false; q->iv->mGotLastMsg = false;
q->iv->miMultiParts = 0; q->iv->miMultiParts = 0;
@ -754,6 +770,25 @@ class Communication : public CommQueue<> {
//mState = States::WAIT; //mState = States::WAIT;
} }
void miRepeatRequest(const queue_s *q) {
setAttempt(); // if function is called, we got something, and we necessarily need more transmissions for MI types...
if(*mSerialDebug) {
DPRINT_IVID(DBG_WARN, q->iv->id);
DBGPRINT(F("resend request ("));
DBGPRINT(String(q->attempts));
DBGPRINT(F(" attempts left): 0x"));
DBGHEXLN(q->cmd);
}
q->iv->radio->sendCmdPacket(q->iv, q->cmd, 0x00, true);
mWaitTimeout = millis() + MI_TIMEOUT;
mWaitTimeout_min = mWaitTimeout;
//mState = States::WAIT;
mIsRetransmit = false;
}
void miStsConsolidate(const queue_s *q, uint8_t stschan, record_t<> *rec, uint8_t uState, uint8_t uEnum, uint8_t lState = 0, uint8_t lEnum = 0) { void miStsConsolidate(const queue_s *q, uint8_t stschan, record_t<> *rec, uint8_t uState, uint8_t uEnum, uint8_t lState = 0, uint8_t lEnum = 0) {
//uint8_t status = (p->packet[11] << 8) + p->packet[12]; //uint8_t status = (p->packet[11] << 8) + p->packet[12];
uint16_t statusMi = 3; // regular status for MI, change to 1 later? uint16_t statusMi = 3; // regular status for MI, change to 1 later?
@ -860,7 +895,7 @@ class Communication : public CommQueue<> {
//closeRequest(iv, iv->miMultiParts > 5); //closeRequest(iv, iv->miMultiParts > 5);
//mHeu.setGotAll(iv); //mHeu.setGotAll(iv);
//cmdDone(true); //cmdDone(false);
if(NULL != mCbPayload) if(NULL != mCbPayload)
(mCbPayload)(RealTimeRunData_Debug, iv); (mCbPayload)(RealTimeRunData_Debug, iv);

18
src/hm/hmRadio.h

@ -121,7 +121,9 @@ class HmRadio : public Radio {
uint32_t startMicros = micros(); uint32_t startMicros = micros();
uint32_t loopMillis = millis(); uint32_t loopMillis = millis();
mRxChIdx = (mTxChIdx + 3) % RF_MAX_CHANNEL_ID; // start with a fixed offset mRxChIdx = mRxChannels - 2; // ensure, we start receiving with first relative channel....
//mRxChannels - 1; //
//(mTxChIdx + mRxChannels) % RF_MAX_CHANNEL_ID; // start with a fixed offset
while ((millis() - loopMillis) < mRxTmoOuterLoop) { while ((millis() - loopMillis) < mRxTmoOuterLoop) {
while ((micros() - startMicros) < mRxTmoInnerLoop) { // listen (4088us or?) 5110us to each channel while ((micros() - startMicros) < mRxTmoInnerLoop) { // listen (4088us or?) 5110us to each channel
if (mIrqRcvd) { if (mIrqRcvd) {
@ -247,7 +249,7 @@ class HmRadio : public Radio {
void prepareReceive(Inverter<> *iv) { void prepareReceive(Inverter<> *iv) {
if (iv->mIsSingleframeReq) { if (iv->mIsSingleframeReq) {
mRxTmoOuterLoop = 65; // SINGLEFR_TIMEOUT mRxTmoOuterLoop = 60; // SINGLEFR_TIMEOUT
return; return;
} }
@ -256,24 +258,24 @@ class HmRadio : public Radio {
if (iv->type == INV_TYPE_4CH) { if (iv->type == INV_TYPE_4CH) {
mRxChannels = 3; mRxChannels = 3;
mRxTmoOuterLoop = 300; mRxTmoOuterLoop = 300;
mRxTmoInnerLoop = 5110; mRxTmoInnerLoop = 5110; //10220; //4088; // 6132; // //
} else if (iv->type == INV_TYPE_2CH) { } else if (iv->type == INV_TYPE_2CH) {
mRxChannels = 2; mRxChannels = 2;
mRxTmoOuterLoop = 250; mRxTmoOuterLoop = 240;
mRxTmoInnerLoop = 10220; mRxTmoInnerLoop = 10220;
} else { // INV_TYPE_1CH } else { // INV_TYPE_1CH
mRxChannels = 2; mRxChannels = 2;
mRxTmoOuterLoop = 200; mRxTmoOuterLoop = 180;
mRxTmoInnerLoop = 5110; mRxTmoInnerLoop = 5110;
} }
} else { //3rd gen defaults } else { //3rd gen defaults
mRxChannels = 3; mRxChannels = 3;
mRxTmoOuterLoop = iv->mCmd == AlarmData ? 600 : 400; mRxTmoOuterLoop = iv->mCmd == AlarmData ? 600 : 420;
mRxTmoInnerLoop = 5110; mRxTmoInnerLoop = 5110;
} }
} else { // 2nd gen defaults } else { // 2nd gen defaults
mRxChannels = 2; mRxChannels = 3;
mRxTmoOuterLoop = 250; mRxTmoOuterLoop = 240;
mRxTmoInnerLoop = 5110; mRxTmoInnerLoop = 5110;
} }
} }

Loading…
Cancel
Save