Browse Source

Partly fix retransmit errors

* move gotFragment flag
pull/1234/head
rejoe2 1 year ago
committed by GitHub
parent
commit
08fcbb4e73
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 26
      src/hm/Communication.h
  2. 2
      src/hm/hmInverter.h
  3. 16
      src/hm/hmRadio.h

26
src/hm/Communication.h

@ -14,7 +14,7 @@
#define MI_TIMEOUT 250 // timeout for MI type requests #define MI_TIMEOUT 250 // timeout for MI type requests
#define FRSTMSG_TIMEOUT 150 // how long to wait for first msg to be received #define FRSTMSG_TIMEOUT 150 // how long to wait for first msg to be received
#define DEFAULT_TIMEOUT 500 // timeout for regular requests #define DEFAULT_TIMEOUT 500 // timeout for regular requests
#define SINGLEFR_TIMEOUT 60 // timeout for single frame requests #define SINGLEFR_TIMEOUT 65 // timeout for single frame requests
#define MAX_BUFFER 250 #define MAX_BUFFER 250
typedef std::function<void(uint8_t, Inverter<> *)> payloadListenerType; typedef std::function<void(uint8_t, Inverter<> *)> payloadListenerType;
@ -44,8 +44,8 @@ class Communication : public CommQueue<> {
if(!valid) if(!valid)
return; // empty return; // empty
uint16_t timeout = q->iv->ivGen != IV_MI ? (mGotFragment && q->iv->mGotLastMsg) ? SINGLEFR_TIMEOUT : DEFAULT_TIMEOUT : MI_TIMEOUT; uint16_t timeout = q->iv->ivGen != IV_MI ? (q->iv->mGotFragment && q->iv->mGotLastMsg) ? SINGLEFR_TIMEOUT : DEFAULT_TIMEOUT : MI_TIMEOUT;
uint16_t timeout_min = q->iv->ivGen != IV_MI ? mGotFragment ? SINGLEFR_TIMEOUT : FRSTMSG_TIMEOUT : MI_TIMEOUT; uint16_t timeout_min = q->iv->ivGen != IV_MI ? q->iv->mGotFragment ? SINGLEFR_TIMEOUT : FRSTMSG_TIMEOUT : MI_TIMEOUT;
bool testMode = false; bool testMode = false;
switch(mState) { switch(mState) {
@ -61,7 +61,7 @@ class Communication : public CommQueue<> {
mHeu.printStatus(q->iv); mHeu.printStatus(q->iv);
mHeu.getTxCh(q->iv); mHeu.getTxCh(q->iv);
testMode = mHeu.getTestModeEnabled(); testMode = mHeu.getTestModeEnabled();
mGotFragment = false; q->iv->mGotFragment = false;
q->iv->mGotLastMsg = false; q->iv->mGotLastMsg = false;
mFirstTry = mFirstTry ? false : ( ( (IV_HM == q->iv->ivGen) || (IV_MI == q->iv->ivGen) ) && (q->iv->isAvailable()) || (millis() < 120000) ); mFirstTry = mFirstTry ? false : ( ( (IV_HM == q->iv->ivGen) || (IV_MI == q->iv->ivGen) ) && (q->iv->isAvailable()) || (millis() < 120000) );
if(NULL == q->iv->radio) if(NULL == q->iv->radio)
@ -95,13 +95,10 @@ class Communication : public CommQueue<> {
case States::WAIT: case States::WAIT:
if(millis() > mWaitTimeout_min) { if(millis() > mWaitTimeout_min) {
if(!mGotFragment) { // nothing received yet? if(!q->iv->mGotFragment) { // nothing received yet?
if(q->iv->radio->get()) { // radio received sth.? if(q->iv->mGotLastMsg) {
mGotFragment = true;
if(q->iv->mGotLastMsg) {
//mState = States::CHECK_FRAMES; //mState = States::CHECK_FRAMES;
mWaitTimeout = mWaitTimeout_min; mWaitTimeout = mWaitTimeout_min;
}
} }
} else if(mFirstTry) { } else if(mFirstTry) {
DPRINT_IVID(DBG_INFO, q->iv->id); DPRINT_IVID(DBG_INFO, q->iv->id);
@ -127,7 +124,7 @@ class Communication : public CommQueue<> {
DBGPRINT(String(millis() - mWaitTimeout + timeout)); DBGPRINT(String(millis() - mWaitTimeout + timeout));
DBGPRINTLN(F("ms")); DBGPRINTLN(F("ms"));
if(!mGotFragment) { // && !mFirstTry) { if(!q->iv->mGotFragment) {
if(!testMode) if(!testMode)
q->iv->radioStatistics.rxFailNoAnser++; // got nothing q->iv->radioStatistics.rxFailNoAnser++; // got nothing
mHeu.setGotNothing(q->iv); mHeu.setGotNothing(q->iv);
@ -143,7 +140,6 @@ class Communication : public CommQueue<> {
break; break;
} }
mGotFragment = true;
mFirstTry = false; // for correct reset mFirstTry = false; // for correct reset
States nextState = States::RESET; States nextState = States::RESET;
while(!q->iv->radio->mBufCtrl.empty()) { while(!q->iv->radio->mBufCtrl.empty()) {
@ -207,9 +203,10 @@ class Communication : public CommQueue<> {
if(0 == mMaxFrameId) { if(0 == mMaxFrameId) {
uint8_t i = 0; uint8_t i = 0;
while(i < MAX_PAYLOAD_ENTRIES) { while(i < MAX_PAYLOAD_ENTRIES) {
if(mLocalBuf[i].len == 0) if(mLocalBuf[i].len == 0) {
framnr = i+1; framnr = i+1;
break; break;
}
i++; i++;
} }
} }
@ -280,9 +277,8 @@ class Communication : public CommQueue<> {
return; // CRC8 is wrong, frame invalid return; // CRC8 is wrong, frame invalid
} }
if((*frameId & ALL_FRAMES) == ALL_FRAMES) { if((*frameId & ALL_FRAMES) == ALL_FRAMES)
mMaxFrameId = (*frameId & 0x7f); mMaxFrameId = (*frameId & 0x7f);
}
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);
@ -773,7 +769,7 @@ class Communication : public CommQueue<> {
uint32_t mWaitTimeout = 0; uint32_t mWaitTimeout = 0;
uint32_t mWaitTimeout_min = 0; uint32_t mWaitTimeout_min = 0;
std::array<frame_t, MAX_PAYLOAD_ENTRIES> mLocalBuf; std::array<frame_t, MAX_PAYLOAD_ENTRIES> mLocalBuf;
bool mGotFragment = false; //bool mGotFragment = false;
bool mFirstTry = false; bool mFirstTry = false;
uint8_t mMaxFrameId; uint8_t mMaxFrameId;
uint8_t mPayload[MAX_BUFFER]; uint8_t mPayload[MAX_BUFFER];

2
src/hm/hmInverter.h

@ -126,6 +126,8 @@ class Inverter {
uint16_t alarmLastId; // lastId which was received uint16_t alarmLastId; // lastId which was received
int8_t rssi; // RSSI int8_t rssi; // RSSI
uint8_t miMultiParts; // helper info for MI multiframe msgs uint8_t miMultiParts; // helper info for MI multiframe msgs
uint8_t outstandingFrames; // helper info to count difference between expected and received frames
bool mGotFragment; // shows if inverter has sent at least one fragment
bool mGotLastMsg; // shows if inverter has already finished transmission cycle bool mGotLastMsg; // shows if inverter has already finished transmission cycle
Radio *radio; // pointer to associated radio class Radio *radio; // pointer to associated radio class
statistics_t radioStatistics; // information about transmitted, failed, ... packets statistics_t radioStatistics; // information about transmitted, failed, ... packets

16
src/hm/hmRadio.h

@ -252,6 +252,12 @@ class HmRadio : public Radio {
p.millis = millis() - mMillis; p.millis = millis() - mMillis;
mNrf24.read(p.packet, p.len); mNrf24.read(p.packet, p.len);
if (p.packet[0] != 0x00) { if (p.packet[0] != 0x00) {
if(!checkIvSerial(&p.packet[1], mLastIv)) {
DPRINT(DBG_WARN, "RX other inverter: ");
ah::dumpBuf(p.packet, p.len);
return false;
}
mLastIv->mGotFragment = true;
mBufCtrl.push(p); mBufCtrl.push(p);
if (p.packet[0] == (TX_REQ_INFO + ALL_FRAMES)) // response from get information command if (p.packet[0] == (TX_REQ_INFO + ALL_FRAMES)) // response from get information command
isLastPackage = (p.packet[9] > ALL_FRAMES); // > ALL_FRAMES indicates last packet received isLastPackage = (p.packet[9] > ALL_FRAMES); // > ALL_FRAMES indicates last packet received
@ -302,6 +308,16 @@ class HmRadio : public Radio {
return iv->ivGen; return iv->ivGen;
} }
inline bool checkIvSerial(uint8_t buf[], Inverter<> *iv) {
uint8_t tmp[4];
CP_U32_BigEndian(tmp, iv->radioId.u64 >> 8);
for(uint8_t i = 0; i < 4; i++) {
if(tmp[i] != buf[i])
return false;
}
return true;
}
uint64_t DTU_RADIO_ID; uint64_t DTU_RADIO_ID;
uint8_t mRfChLst[RF_CHANNELS] = {03, 23, 40, 61, 75}; // channel List:2403, 2423, 2440, 2461, 2475MHz uint8_t mRfChLst[RF_CHANNELS] = {03, 23, 40, 61, 75}; // channel List:2403, 2423, 2440, 2461, 2475MHz
uint8_t mTxChIdx = 0; uint8_t mTxChIdx = 0;

Loading…
Cancel
Save