Browse Source

0.8.31

* added class to handle timeouts PR #1298
pull/1299/head
lumapu 1 year ago
parent
commit
7c08d934a9
  1. 3
      src/CHANGES.md
  2. 2
      src/defines.h
  3. 22
      src/hm/Communication.h
  4. 2
      src/plugins/Display/Display_Mono.h
  5. 4
      src/utils/timemonitor.h

3
src/CHANGES.md

@ -1,5 +1,8 @@
# Development Changes # Development Changes
## 0.8.31 - 2023-12-29
* added class to handle timeouts PR #1298
## 0.8.30 - 2023-12-28 ## 0.8.30 - 2023-12-28
* added info if grid profile was not found * added info if grid profile was not found
* merge PR #1293 * merge PR #1293

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 30 #define VERSION_PATCH 31
//------------------------------------- //-------------------------------------
typedef struct { typedef struct {

22
src/hm/Communication.h

@ -9,8 +9,8 @@
#include "CommQueue.h" #include "CommQueue.h"
#include <Arduino.h> #include <Arduino.h>
#include "../utils/crc.h" #include "../utils/crc.h"
#include "Heuristic.h"
#include "../utils/timemonitor.h" #include "../utils/timemonitor.h"
#include "Heuristic.h"
#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
@ -61,7 +61,6 @@ class Communication : public CommQueue<> {
mPrintSequenceDuration = true; mPrintSequenceDuration = true;
uint16_t timeout = (q->iv->ivGen == IV_MI) ? MI_TIMEOUT : (((q->iv->mGotFragment && q->iv->mGotLastMsg) || mIsRetransmit) ? SINGLEFR_TIMEOUT : ((q->cmd != AlarmData) && (q->cmd != GridOnProFilePara) ? DEFAULT_TIMEOUT : (1.5 * DEFAULT_TIMEOUT))); uint16_t timeout = (q->iv->ivGen == IV_MI) ? MI_TIMEOUT : (((q->iv->mGotFragment && q->iv->mGotLastMsg) || mIsRetransmit) ? SINGLEFR_TIMEOUT : ((q->cmd != AlarmData) && (q->cmd != GridOnProFilePara) ? DEFAULT_TIMEOUT : (1.5 * DEFAULT_TIMEOUT)));
// uint16_t timeout_min = (q->iv->ivGen == IV_MI) ? MI_TIMEOUT : ((q->iv->mGotFragment || mIsRetransmit)) ? SINGLEFR_TIMEOUT : FRSTMSG_TIMEOUT; // not used
/*if(mDebugState != mState) { /*if(mDebugState != mState) {
DPRINT(DBG_INFO, F("State: ")); DPRINT(DBG_INFO, F("State: "));
@ -70,7 +69,6 @@ class Communication : public CommQueue<> {
}*/ }*/
switch(mState) { switch(mState) {
case States::RESET: case States::RESET:
//if(millis() < mWaitTimeout) // replaced by TimeMonitor
if (!mWaitTime.isTimeout()) if (!mWaitTime.isTimeout())
return; return;
@ -111,11 +109,8 @@ class Communication : public CommQueue<> {
q->iv->radio->prepareDevInformCmd(q->iv, q->cmd, q->ts, q->iv->alarmLastId, false); q->iv->radio->prepareDevInformCmd(q->iv, q->cmd, q->ts, q->iv->alarmLastId, false);
q->iv->radioStatistics.txCnt++; q->iv->radioStatistics.txCnt++;
// mWaitTimeout = millis() + timeout; // replaced by Timemonitor
mWaitTime.startTimeMonitor(timeout); mWaitTime.startTimeMonitor(timeout);
// mWaitTimeout_min = millis() + timeout_min; // not used
mIsRetransmit = false; mIsRetransmit = false;
// mlastTO_min = timeout_min; // not used
setAttempt(); setAttempt();
if((q->cmd == AlarmData) || (q->cmd == GridOnProFilePara)) if((q->cmd == AlarmData) || (q->cmd == GridOnProFilePara))
incrAttempt(q->cmd == AlarmData? 5 : 3); incrAttempt(q->cmd == AlarmData? 5 : 3);
@ -124,7 +119,6 @@ class Communication : public CommQueue<> {
break; break;
case States::WAIT: case States::WAIT:
// if(millis() < mWaitTimeout) // replaced by Timemonitor
if (!mWaitTime.isTimeout()) if (!mWaitTime.isTimeout())
return; return;
mState = States::CHECK_FRAMES; mState = States::CHECK_FRAMES;
@ -135,15 +129,13 @@ class Communication : public CommQueue<> {
if(*mSerialDebug) { if(*mSerialDebug) {
DPRINT_IVID(DBG_INFO, q->iv->id); DPRINT_IVID(DBG_INFO, q->iv->id);
DBGPRINT(F("request timeout: ")); DBGPRINT(F("request timeout: "));
// DBGPRINT(String(millis() - mWaitTimeout + timeout)); // replaced by Timemonitor
DBGPRINT(String(mWaitTime.getRunTime())); DBGPRINT(String(mWaitTime.getRunTime()));
DBGPRINTLN(F("ms")); DBGPRINTLN(F("ms"));
} }
if(!q->iv->mGotFragment) { if(!q->iv->mGotFragment) {
if((IV_HMS == q->iv->ivGen) || (IV_HMT == q->iv->ivGen)) { if((IV_HMS == q->iv->ivGen) || (IV_HMT == q->iv->ivGen)) {
q->iv->radio->switchFrequency(q->iv, HOY_BOOT_FREQ_KHZ, (q->iv->config->frequency*FREQ_STEP_KHZ + HOY_BASE_FREQ_KHZ)); q->iv->radio->switchFrequency(q->iv, HOY_BOOT_FREQ_KHZ, (q->iv->config->frequency*FREQ_STEP_KHZ + HOY_BASE_FREQ_KHZ));
//mWaitTimeout = millis() + 1000; // replaced by Timemonitor mWaitTime.startTimeMonitor(1000);
mWaitTime.startTimeMonitor(1000UL);
} }
} }
closeRequest(q, false); closeRequest(q, false);
@ -192,7 +184,6 @@ 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) { // replaced by TimeMonitor
if((mWaitTime.isTimeout() && mIsRetransmit) || !mIsRetransmit) { if((mWaitTime.isTimeout() && mIsRetransmit) || !mIsRetransmit) {
miRepeatRequest(q); miRepeatRequest(q);
return; return;
@ -253,7 +244,6 @@ class Communication : public CommQueue<> {
q->iv->mIsSingleframeReq = true; q->iv->mIsSingleframeReq = true;
sendRetransmit(q, (framnr-1)); sendRetransmit(q, (framnr-1));
mIsRetransmit = true; mIsRetransmit = true;
// mlastTO_min = timeout_min; // not used
return; return;
} }
@ -500,7 +490,6 @@ class Communication : public CommQueue<> {
if(q->attempts) { if(q->attempts) {
q->iv->radio->sendCmdPacket(q->iv, TX_REQ_INFO, (SINGLE_FRAME + i), true); q->iv->radio->sendCmdPacket(q->iv, TX_REQ_INFO, (SINGLE_FRAME + i), true);
q->iv->radioStatistics.retransmits++; q->iv->radioStatistics.retransmits++;
// mWaitTimeout = millis() + SINGLEFR_TIMEOUT; // timeout replaced by Timemonitor
mWaitTime.startTimeMonitor(SINGLEFR_TIMEOUT); // timeout mWaitTime.startTimeMonitor(SINGLEFR_TIMEOUT); // timeout
mState = States::WAIT; mState = States::WAIT;
} else { } else {
@ -518,7 +507,6 @@ class Communication : public CommQueue<> {
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; // replaced by Timemonitor
mWaitTime.startTimeMonitor(*mInverterGap); mWaitTime.startTimeMonitor(*mInverterGap);
bool keep = false; bool keep = false;
@ -741,8 +729,6 @@ class Communication : public CommQueue<> {
//q->iv->radioStatistics.retransmits++; //q->iv->radioStatistics.retransmits++;
q->iv->radio->sendCmdPacket(q->iv, cmd, 0x00, true); q->iv->radio->sendCmdPacket(q->iv, cmd, 0x00, true);
// mWaitTimeout = millis() + MI_TIMEOUT; // replaced by TimeMonitor
// mWaitTimeout_min = mWaitTimeout; // not used
mWaitTime.startTimeMonitor(MI_TIMEOUT); mWaitTime.startTimeMonitor(MI_TIMEOUT);
q->iv->miMultiParts = 0; q->iv->miMultiParts = 0;
q->iv->mGotFragment = 0; q->iv->mGotFragment = 0;
@ -763,8 +749,6 @@ class Communication : public CommQueue<> {
q->iv->radio->sendCmdPacket(q->iv, q->cmd, 0x00, true); q->iv->radio->sendCmdPacket(q->iv, q->cmd, 0x00, true);
// mWaitTimeout = millis() + MI_TIMEOUT; // replaced by TimeMonitor
// mWaitTimeout_min = mWaitTimeout; // not used
mWaitTime.startTimeMonitor(MI_TIMEOUT); mWaitTime.startTimeMonitor(MI_TIMEOUT);
//mState = States::WAIT; //mState = States::WAIT;
mIsRetransmit = false; mIsRetransmit = false;
@ -900,11 +884,9 @@ class Communication : public CommQueue<> {
bool *mPrivacyMode, *mSerialDebug, *mPrintWholeTrace; bool *mPrivacyMode, *mSerialDebug, *mPrintWholeTrace;
uint16_t *mInverterGap; uint16_t *mInverterGap;
TimeMonitor mWaitTime = TimeMonitor(0, true); // start as expired (due to code in RESET state) TimeMonitor mWaitTime = TimeMonitor(0, true); // start as expired (due to code in RESET state)
// uint32_t mWaitTimeout_min = 0; // not used
std::array<frame_t, MAX_PAYLOAD_ENTRIES> mLocalBuf; std::array<frame_t, MAX_PAYLOAD_ENTRIES> mLocalBuf;
bool mFirstTry = false; // see, if we should do a second try bool mFirstTry = false; // see, if we should do a second try
bool mIsRetransmit = false; // we already had waited one complete cycle bool mIsRetransmit = false; // we already had waited one complete cycle
// uint16_t mlastTO_min = DEFAULT_TIMEOUT; // remember timeout_min for correct calculation not used
uint8_t mMaxFrameId; uint8_t mMaxFrameId;
uint8_t mPayload[MAX_BUFFER]; uint8_t mPayload[MAX_BUFFER];
payloadListenerType mCbPayload = NULL; payloadListenerType mCbPayload = NULL;

2
src/plugins/Display/Display_Mono.h

@ -80,7 +80,7 @@ class DisplayMono {
uint8_t mExtra; uint8_t mExtra;
int8_t mPixelshift=0; int8_t mPixelshift=0;
TimeMonitor mDisplayTime = TimeMonitor(1000ul * 15, true); TimeMonitor mDisplayTime = TimeMonitor(1000 * 15, true);
bool mDisplayActive = true; // always start with display on bool mDisplayActive = true; // always start with display on
char mFmtText[DISP_FMT_TEXT_LEN]; char mFmtText[DISP_FMT_TEXT_LEN];

4
src/utils/timemonitor.h

@ -23,7 +23,7 @@ class TimeMonitor {
* A constructor for initializing a TimeMonitor * A constructor for initializing a TimeMonitor
* @note TimeMonitor witch default constructor is stopped * @note TimeMonitor witch default constructor is stopped
*/ */
TimeMonitor(void) {}; TimeMonitor(void) {}
/** /**
* A constructor for initializing a TimeMonitor * A constructor for initializing a TimeMonitor
@ -36,7 +36,7 @@ class TimeMonitor {
startTimeMonitor(timeout); startTimeMonitor(timeout);
else else
configureTimeMonitor(timeout); configureTimeMonitor(timeout);
}; }
/** /**
* Start the TimeMonitor with new timeout configuration * Start the TimeMonitor with new timeout configuration

Loading…
Cancel
Save