From 7cd075fbad0b4b835b83ce1fbb7d6a3c2e9d515b Mon Sep 17 00:00:00 2001 From: lumapu Date: Tue, 11 Oct 2022 13:21:29 +0200 Subject: [PATCH] added receive no answer counter #332 corrected resetPayload in app loop --- tools/esp8266/app.cpp | 27 ++++++++++++++++----------- tools/esp8266/defines.h | 1 + tools/esp8266/html/index.html | 1 + tools/esp8266/webApi.cpp | 9 +++++---- 4 files changed, 23 insertions(+), 15 deletions(-) diff --git a/tools/esp8266/app.cpp b/tools/esp8266/app.cpp index 897f5bda..d8f6321e 100644 --- a/tools/esp8266/app.cpp +++ b/tools/esp8266/app.cpp @@ -226,25 +226,29 @@ void app::loop(void) { mSendLastIvId = ((MAX_NUM_INVERTERS-1) == mSendLastIvId) ? 0 : mSendLastIvId + 1; iv = mSys->getInverterByPos(mSendLastIvId); } while((NULL == iv) && ((maxLoop--) > 0)); - resetPayload(iv); - mPayload[iv->id].requested = true; if(NULL != iv) { if(!mPayload[iv->id].complete) processPayload(false); if(!mPayload[iv->id].complete) { - mStat.rxFail++; + if(0 == mPayload[iv->id].maxPackId) + mStat.rxFailNoAnser++; + else + mStat.rxFail++; + iv->setQueuedCmdFinished(); // command failed - if(mConfig.serialDebug) { + if(mConfig.serialDebug) DPRINTLN(DBG_INFO, F("enqueued cmd failed/timeout")); - } if(mConfig.serialDebug) { DPRINT(DBG_INFO, F("Inverter #") + String(iv->id) + " "); DPRINTLN(DBG_INFO, F("no Payload received! (retransmits: ") + String(mPayload[iv->id].retransmits) + ")"); } } + resetPayload(iv); + mPayload[iv->id].requested = true; + yield(); if(mConfig.serialDebug) { DPRINTLN(DBG_DEBUG, F("app:loop WiFi WiFi.status ") + String(WiFi.status())); @@ -257,7 +261,8 @@ void app::loop(void) { mPayload[iv->id].txCmd = iv->devControlCmd; iv->clearCmdQueue(); iv->enqueCommand(SystemConfigPara); - } else { + } + else { uint8_t cmd = iv->getQueuedCmd(); mSys->Radio.sendTimePacket(iv->radioId.u64, cmd, mPayload[iv->id].ts, iv->alarmMesIndex); mPayload[iv->id].txCmd = cmd; @@ -316,11 +321,12 @@ void app::processPayload(bool retransmit) { for(uint8_t id = 0; id < mSys->getNumInverters(); id++) { Inverter<> *iv = mSys->getInverterByPos(id); if(NULL != iv) { - if(mPayload[iv->id].txId != (TX_REQ_INFO + 0x80)) { + if((mPayload[iv->id].txId != (TX_REQ_INFO + 0x80)) && (0 != mPayload[iv->id].txId)) { // no processing needed if txId is not 0x95 - DPRINTLN(DBG_DEBUG, F("processPayload - set complete")); + //DPRINTLN(DBG_INFO, F("processPayload - set complete, txId: ") + String(mPayload[iv->id].txId, HEX)); mPayload[iv->id].complete = true; } + if(!mPayload[iv->id].complete ) { if(!buildPayload(iv->id)) { // payload not complete if(mPayload[iv->id].requested) { @@ -365,7 +371,8 @@ void app::processPayload(bool retransmit) { DPRINTLN(DBG_DEBUG, F("procPyld: max: ") + String(mPayload[iv->id].maxPackId)); record_t<> *rec = iv->getRecordStruct(mPayload[iv->id].txCmd); // choose the parser mPayload[iv->id].complete = true; - mStat.rxSuccess++; + if(mPayload[iv->id].txId == (TX_REQ_INFO + 0x80)) + mStat.rxSuccess++; uint8_t payload[128]; uint8_t offs = 0; @@ -466,8 +473,6 @@ void app::processPayload(bool retransmit) { iv->setQueuedCmdFinished(); - //resetPayload(iv); - #ifdef __MQTT_AFTER_RX__ doMQTT = true; #endif diff --git a/tools/esp8266/defines.h b/tools/esp8266/defines.h index 0d767f70..f866dad0 100644 --- a/tools/esp8266/defines.h +++ b/tools/esp8266/defines.h @@ -142,6 +142,7 @@ typedef struct { typedef struct { uint32_t rxFail; + uint32_t rxFailNoAnser; uint32_t rxSuccess; uint32_t frmCnt; } statistics_t; diff --git a/tools/esp8266/html/index.html b/tools/esp8266/html/index.html index c6db6ec9..ad436326 100644 --- a/tools/esp8266/html/index.html +++ b/tools/esp8266/html/index.html @@ -67,6 +67,7 @@ function parseStat(obj) { document.getElementById("stat").innerHTML = "RX success: " + obj["rx_success"] + "\nRX fail: " + obj["rx_fail"] + + "\nRX no anwser: " + obj["rx_fail_answer"] + "\nFrames received: " + obj["frame_cnt"] + "\nTX Cnt: " + obj["tx_cnt"]; } diff --git a/tools/esp8266/webApi.cpp b/tools/esp8266/webApi.cpp index 9d8baa59..5461ab2a 100644 --- a/tools/esp8266/webApi.cpp +++ b/tools/esp8266/webApi.cpp @@ -129,10 +129,11 @@ void webApi::getSystem(JsonObject obj) { //----------------------------------------------------------------------------- void webApi::getStatistics(JsonObject obj) { - obj[F("rx_success")] = mStat->rxSuccess; - obj[F("rx_fail")] = mStat->rxFail; - obj[F("frame_cnt")] = mStat->frmCnt; - obj[F("tx_cnt")] = mApp->mSys->Radio.mSendCnt; + obj[F("rx_success")] = mStat->rxSuccess; + obj[F("rx_fail")] = mStat->rxFail; + obj[F("rx_fail_answer")] = mStat->rxFailNoAnser; + obj[F("frame_cnt")] = mStat->frmCnt; + obj[F("tx_cnt")] = mApp->mSys->Radio.mSendCnt; }