diff --git a/src/hm/CommQueue.h b/src/hm/CommQueue.h index d3fe1c69..227e8c33 100644 --- a/src/hm/CommQueue.h +++ b/src/hm/CommQueue.h @@ -12,8 +12,8 @@ #include "../utils/dbg.h" #define DEFAULT_ATTEMPS 5 -#define MORE_ATTEMPS_ALARMDATA 8 -#define MORE_ATTEMPS_GRIDONPROFILEPARA 5 +#define MORE_ATTEMPS_ALARMDATA 0 // 8 +#define MORE_ATTEMPS_GRIDONPROFILEPARA 0 // 5 template class CommQueue { diff --git a/src/hm/Communication.h b/src/hm/Communication.h index 924356e0..bc7f7236 100644 --- a/src/hm/Communication.h +++ b/src/hm/Communication.h @@ -114,11 +114,11 @@ class Communication : public CommQueue<> { q->iv->radioStatistics.txCnt++; q->iv->radio->mRadioWaitTime.startTimeMonitor(mTimeout); + if(!mIsRetransmit && (q->cmd == AlarmData) || (q->cmd == GridOnProFilePara)) + incrAttempt(q->cmd == AlarmData? MORE_ATTEMPS_ALARMDATA : MORE_ATTEMPS_GRIDONPROFILEPARA); mIsRetransmit = false; setAttempt(); - if((q->cmd == AlarmData) || (q->cmd == GridOnProFilePara)) - incrAttempt(q->cmd == AlarmData? MORE_ATTEMPS_ALARMDATA : MORE_ATTEMPS_GRIDONPROFILEPARA); mState = States::WAIT; break; @@ -155,7 +155,8 @@ class Communication : public CommQueue<> { q->iv->mIvTxCnt++; if(mFirstTry) { - mFirstTry = false; + if(q->attempts < 3 || !q->iv->isProducing()) + mFirstTry = false; //setAttempt(); mHeu.evalTxChQuality(q->iv, false, 0, 0); //q->iv->radioStatistics.rxFailNoAnser++; // should only be one of fail or retransmit. @@ -209,7 +210,7 @@ class Communication : public CommQueue<> { if(q->iv->ivGen != IV_MI) { mState = States::CHECK_PACKAGE; } else { - bool fastNext = true; + //bool fastNext = true; if(q->iv->miMultiParts < 6) { mState = States::WAIT; if((q->iv->radio->mRadioWaitTime.isTimeout() && mIsRetransmit) || !mIsRetransmit) { @@ -222,11 +223,11 @@ class Communication : public CommQueue<> { || ((q->cmd == MI_REQ_CH2) && (q->iv->type == INV_TYPE_2CH)) || ((q->cmd == MI_REQ_CH1) && (q->iv->type == INV_TYPE_1CH))) { miComplete(q->iv); - fastNext = false; + //fastNext = false; } - if(fastNext) + /*if(fastNext) miNextRequest(q->iv->type == INV_TYPE_4CH ? MI_REQ_4CH : MI_REQ_CH1, q); - else + else*/ closeRequest(q, true); } } @@ -263,6 +264,25 @@ class Communication : public CommQueue<> { closeRequest(q, false); return; } + //count missing frames + if(!q->iv->mIsSingleframeReq && q->iv->ivRadioType == INV_RADIO_TYPE_NRF) { // already checked? + uint8_t missedFrames = 0; + for(uint8_t i = 0; i < q->iv->radio->mFramesExpected; i++) { + if(mLocalBuf[i].len == 0) + missedFrames++; + } + if(missedFrames > 3 || (q->cmd == RealTimeRunData_Debug && missedFrames > 1) || (missedFrames > 1 && missedFrames + 2 > q->attempts)) { + if(*mSerialDebug) { + DPRINT_IVID(DBG_INFO, q->iv->id); + DBGPRINT(String(missedFrames)); + DBGPRINT(F(" frames missing ")); + DBGPRINTLN(F("-> complete retransmit")); + } + mState = States::RESET; + return; + } + } + setAttempt(); if(*mSerialDebug) { @@ -411,8 +431,8 @@ class Communication : public CommQueue<> { if((*frameId & ALL_FRAMES) == ALL_FRAMES) { mMaxFrameId = (*frameId & 0x7f); - if(mMaxFrameId > 8) // large payloads, e.g. AlarmData - incrAttempt(mMaxFrameId - 6); + /*if(mMaxFrameId > 8) // large payloads, e.g. AlarmData + incrAttempt(mMaxFrameId - 6);*/ } frame_t *f = &mLocalBuf[(*frameId & 0x7f) - 1]; diff --git a/src/hm/hmDefines.h b/src/hm/hmDefines.h index 9235b3f9..6bd66e66 100644 --- a/src/hm/hmDefines.h +++ b/src/hm/hmDefines.h @@ -92,7 +92,7 @@ enum {INV_RADIO_TYPE_NRF = 0, INV_RADIO_TYPE_CMT}; #define DURATION_TXFRAME 85 // timeout parameter for first transmission and first expected frame (time to first channel switch from tx start!) (ms) #define DURATION_LISTEN_MIN 5 // time to stay at least on a listening channel (ms) #define DURATION_PAUSE_LASTFR 45 // how long to pause after last frame (ms) -const uint8_t duration_reserve[2] = {115,115}; +const uint8_t duration_reserve[2] = {65,115}; #define LIMIT_FAST_IV 85 // time limit to qualify an inverter as very fast answering inverter #define LIMIT_VERYFAST_IV 70 // time limit to qualify an inverter as very fast answering inverter diff --git a/src/hm/hmInverter.h b/src/hm/hmInverter.h index 049b5501..5ef3752d 100644 --- a/src/hm/hmInverter.h +++ b/src/hm/hmInverter.h @@ -220,21 +220,21 @@ class Inverter { cb(RealTimeRunData_Debug, false); // get live data } } else { // MI - if(0 == getFwVersion()) { - mIvRxCnt +=2; - cb(0x0f, false); // get firmware version; for MI, this makes part of polling the device software and hardware version number - } else { - record_t<> *rec = getRecordStruct(InverterDevInform_Simple); - if (getChannelFieldValue(CH0, FLD_PART_NUM, rec) == 0) { - cb(0x0f, false); // hard- and firmware version for missing HW part nr, delivered by frame 1 + cb(((type == INV_TYPE_4CH) ? MI_REQ_4CH : MI_REQ_CH1), false); + mGetLossInterval++; + if (type != INV_TYPE_4CH) + mIvRxCnt++; // statistics workaround... + if(isAvailable()) { + if(0 == getFwVersion()) { mIvRxCnt +=2; - } else if((getChannelFieldValue(CH0, FLD_GRID_PROFILE_CODE, rec) == 0) && generalConfig->readGrid) // read grid profile - cb(0x10, false); // legacy GPF command - else { - cb(((type == INV_TYPE_4CH) ? MI_REQ_4CH : MI_REQ_CH1), false); - mGetLossInterval++; - if (type != INV_TYPE_4CH) - mIvRxCnt++; // statistics workaround... + cb(0x0f, false); // get firmware version; for MI, this makes part of polling the device software and hardware version number + } else { + record_t<> *rec = getRecordStruct(InverterDevInform_Simple); + if (getChannelFieldValue(CH0, FLD_PART_NUM, rec) == 0) { + cb(0x0f, false); // hard- and firmware version for missing HW part nr, delivered by frame 1 + mIvRxCnt +=2; + } else if((getChannelFieldValue(CH0, FLD_GRID_PROFILE_CODE, rec) == 0) && generalConfig->readGrid) // read grid profile + cb(0x10, false); // legacy GPF command } } } diff --git a/src/hm/radio.h b/src/hm/radio.h index e6baf792..ec087f47 100644 --- a/src/hm/radio.h +++ b/src/hm/radio.h @@ -79,6 +79,7 @@ class Radio { uint8_t mIrqOk = IRQ_UNKNOWN; TimeMonitor mRadioWaitTime = TimeMonitor(0, true); // start as expired (due to code in RESET state) uint8_t mTxRetriesNext = 15; // let heuristics tell us the next reties count (for nRF type radios only) + uint8_t mFramesExpected = 0x0c; protected: virtual void sendPacket(Inverter<> *iv, uint8_t len, bool isRetransmit, bool appendCrc16=true) = 0; @@ -130,7 +131,6 @@ class Radio { volatile bool mIrqRcvd; bool *mSerialDebug, *mPrivacyMode, *mPrintWholeTrace; uint8_t mTxBuf[MAX_RF_PAYLOAD_SIZE]; - uint8_t mFramesExpected = 0x0c; }; #endif /*__RADIO_H__*/