From 2f19e70852463219635a8f92e6ee1f2e0217eed0 Mon Sep 17 00:00:00 2001 From: lumapu Date: Sun, 1 Jan 2023 23:49:31 +0100 Subject: [PATCH] payload: if last frame is missing, request all frames again --- src/CHANGES.md | 1 + src/hm/payload.h | 88 +++++++++++++++++++++++------------------------- 2 files changed, 43 insertions(+), 46 deletions(-) diff --git a/src/CHANGES.md b/src/CHANGES.md index e62f1333..0ba677a3 100644 --- a/src/CHANGES.md +++ b/src/CHANGES.md @@ -5,3 +5,4 @@ ## 0.5.67 * changed calculation of start / stop communication to 1 min after last comm. stop #515 * moved payload send to `payload.h`, function `ivSend` #515 +* payload: if last frame is missing, request all frames again diff --git a/src/hm/payload.h b/src/hm/payload.h index 9a23fbfe..bc8b4949 100644 --- a/src/hm/payload.h +++ b/src/hm/payload.h @@ -21,6 +21,7 @@ typedef struct { uint8_t len[MAX_PAYLOAD_ENTRIES]; bool complete; uint8_t maxPackId; + bool lastFound; uint8_t retransmits; bool requested; } invPayload_t; @@ -56,43 +57,43 @@ class Payload : public Handler { void ivSend(Inverter<> *iv) { if (!mPayload[iv->id].complete) - process(false); + process(false); - if (!mPayload[iv->id].complete) { - if (0 == mPayload[iv->id].maxPackId) - mStat->rxFailNoAnser++; - else - mStat->rxFail++; - - iv->setQueuedCmdFinished(); // command failed - if (mSerialDebug) - DPRINTLN(DBG_INFO, F("enqueued cmd failed/timeout")); - if (mSerialDebug) { - DPRINT(DBG_INFO, F("(#") + String(iv->id) + ") "); - DPRINTLN(DBG_INFO, F("no Payload received! (retransmits: ") + String(mPayload[iv->id].retransmits) + ")"); - } + if (!mPayload[iv->id].complete) { + if (0 == mPayload[iv->id].maxPackId) + mStat->rxFailNoAnser++; + else + mStat->rxFail++; + + iv->setQueuedCmdFinished(); // command failed + if (mSerialDebug) + DPRINTLN(DBG_INFO, F("enqueued cmd failed/timeout")); + if (mSerialDebug) { + DPRINT(DBG_INFO, F("(#") + String(iv->id) + ") "); + DPRINTLN(DBG_INFO, F("no Payload received! (retransmits: ") + String(mPayload[iv->id].retransmits) + ")"); } + } - reset(iv); - mPayload[iv->id].requested = true; + reset(iv); + mPayload[iv->id].requested = true; - yield(); + yield(); + if (mSerialDebug) + DPRINTLN(DBG_INFO, F("(#") + String(iv->id) + F(") Requesting Inv SN ") + String(iv->config->serial.u64, HEX)); + + if (iv->devControlRequest) { if (mSerialDebug) - DPRINTLN(DBG_INFO, F("(#") + String(iv->id) + F(") Requesting Inv SN ") + String(iv->config->serial.u64, HEX)); - - if (iv->devControlRequest) { - if (mSerialDebug) - DPRINTLN(DBG_INFO, F("(#") + String(iv->id) + F(") Devcontrol request ") + String(iv->devControlCmd) + F(" power limit ") + String(iv->powerLimit[0])); - mSys->Radio.sendControlPacket(iv->radioId.u64, iv->devControlCmd, iv->powerLimit); - mPayload[iv->id].txCmd = iv->devControlCmd; - iv->clearCmdQueue(); - iv->enqueCommand(SystemConfigPara); // read back power limit - } else { - uint8_t cmd = iv->getQueuedCmd(); - DPRINTLN(DBG_INFO, F("(#") + String(iv->id) + F(") sendTimePacket")); - mSys->Radio.sendTimePacket(iv->radioId.u64, cmd, mPayload[iv->id].ts, iv->alarmMesIndex); - mPayload[iv->id].txCmd = cmd; - } + DPRINTLN(DBG_INFO, F("(#") + String(iv->id) + F(") Devcontrol request ") + String(iv->devControlCmd) + F(" power limit ") + String(iv->powerLimit[0])); + mSys->Radio.sendControlPacket(iv->radioId.u64, iv->devControlCmd, iv->powerLimit); + mPayload[iv->id].txCmd = iv->devControlCmd; + iv->clearCmdQueue(); + iv->enqueCommand(SystemConfigPara); // read back power limit + } else { + uint8_t cmd = iv->getQueuedCmd(); + DPRINTLN(DBG_INFO, F("(#") + String(iv->id) + F(") sendTimePacket")); + mSys->Radio.sendTimePacket(iv->radioId.u64, cmd, mPayload[iv->id].ts, iv->alarmMesIndex); + mPayload[iv->id].txCmd = cmd; + } } void add(packet_t *p, uint8_t len) { @@ -115,7 +116,7 @@ class Payload : public Handler { if ((*pid & 0x7f) > mPayload[iv->id].maxPackId) { mPayload[iv->id].maxPackId = (*pid & 0x7f); if (*pid > 0x81) - mLastPacketId = *pid; + mPayload[iv->id].lastFound = true; } } } @@ -162,7 +163,6 @@ class Payload : public Handler { if ((mPayload[iv->id].txId != (TX_REQ_INFO + ALL_FRAMES)) && (0 != mPayload[iv->id].txId)) { // no processing needed if txId is not 0x95 - // DPRINTLN(DBG_INFO, F("processPayload - set complete, txId: ") + String(mPayload[iv->id].txId, HEX)); mPayload[iv->id].complete = true; } @@ -176,24 +176,20 @@ class Payload : public Handler { } else { if (mPayload[iv->id].retransmits < mMaxRetrans) { mPayload[iv->id].retransmits++; - if (mPayload[iv->id].maxPackId != 0) { + if(false == mPayload[iv->id].lastFound) { + DPRINTLN(DBG_WARN, F("while retrieving data: last frame missing: Request Complete Retransmit")); + mPayload[iv->id].txCmd = iv->getQueuedCmd(); + DPRINTLN(DBG_INFO, F("(#") + String(iv->id) + F(") sendTimePacket")); + mSys->Radio.sendTimePacket(iv->radioId.u64, mPayload[iv->id].txCmd, mPayload[iv->id].ts, iv->alarmMesIndex); + } else if (mPayload[iv->id].maxPackId != 0) { for (uint8_t i = 0; i < (mPayload[iv->id].maxPackId - 1); i++) { if (mPayload[iv->id].len[i] == 0) { DPRINTLN(DBG_WARN, F("while retrieving data: Frame ") + String(i + 1) + F(" missing: Request Retransmit")); mSys->Radio.sendCmdPacket(iv->radioId.u64, TX_REQ_INFO, (SINGLE_FRAME + i), true); - break; // only retransmit one frame per loop + break; // only request retransmit one frame per loop } yield(); } - } else { - DPRINTLN(DBG_WARN, F("while retrieving data: last frame missing: Request Retransmit")); - if (0x00 != mLastPacketId) - mSys->Radio.sendCmdPacket(iv->radioId.u64, TX_REQ_INFO, mLastPacketId, true); - else { - mPayload[iv->id].txCmd = iv->getQueuedCmd(); - DPRINTLN(DBG_INFO, F("(#") + String(iv->id) + F(") sendTimePacket")); - mSys->Radio.sendTimePacket(iv->radioId.u64, mPayload[iv->id].txCmd, mPayload[iv->id].ts, iv->alarmMesIndex); - } } mSys->Radio.switchRxCh(100); } @@ -256,6 +252,7 @@ class Payload : public Handler { mPayload[iv->id].txCmd = 0; mPayload[iv->id].retransmits = 0; mPayload[iv->id].maxPackId = 0; + mPayload[iv->id].lastFound = false; mPayload[iv->id].complete = false; mPayload[iv->id].requested = false; mPayload[iv->id].ts = *mTimestamp; @@ -267,7 +264,6 @@ class Payload : public Handler { uint8_t mMaxRetrans; uint32_t *mTimestamp; invPayload_t mPayload[MAX_NUM_INVERTERS]; - uint8_t mLastPacketId; bool mSerialDebug; };