From 1c12f4c141fb47daf00714fc7af33629c2dd5ec6 Mon Sep 17 00:00:00 2001 From: lumapu Date: Mon, 11 Dec 2023 22:38:48 +0100 Subject: [PATCH] 0.8.19 * added ms to serial log * added (debug) option to configure gap between inverter requests --- src/CHANGES.md | 4 ++++ src/app.cpp | 2 +- src/app.h | 9 --------- src/appInterface.h | 1 - src/config/settings.h | 19 +++++++++++++------ src/defines.h | 2 +- src/hm/Communication.h | 10 ++++++---- src/hm/Heuristic.h | 5 ++++- src/utils/helper.cpp | 9 +++++++++ src/utils/helper.h | 1 + src/web/RestApi.h | 1 + src/web/html/setup.html | 6 +++++- src/web/web.h | 8 +++++--- 13 files changed, 50 insertions(+), 27 deletions(-) diff --git a/src/CHANGES.md b/src/CHANGES.md index 472e3c8f..418acb84 100644 --- a/src/CHANGES.md +++ b/src/CHANGES.md @@ -1,5 +1,9 @@ # Development Changes +## 0.8.19 - 2023-12-11 +* added ms to serial log +* added (debug) option to configure gap between inverter requests + ## 0.8.18 - 2023-12-10 * copied even more from the original heuristic code #1259 * added mDNS support #1262 diff --git a/src/app.cpp b/src/app.cpp index 1a4e248c..0d59ab10 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -54,7 +54,7 @@ void app::setup() { #endif #endif /* defined(ETHERNET) */ - mCommunication.setup(&mTimestamp, &mConfig->serial.debug, &mConfig->serial.privacyLog, &mConfig->serial.printWholeTrace); + mCommunication.setup(&mTimestamp, &mConfig->serial.debug, &mConfig->serial.privacyLog, &mConfig->serial.printWholeTrace, &mConfig->inst.gapMs); mCommunication.addPayloadListener(std::bind(&app::payloadEventListener, this, std::placeholders::_1, std::placeholders::_2)); mSys.setup(&mTimestamp, &mConfig->inst); for (uint8_t i = 0; i < MAX_NUM_INVERTERS; i++) { diff --git a/src/app.h b/src/app.h index cb0f8746..f2b4e548 100644 --- a/src/app.h +++ b/src/app.h @@ -211,15 +211,6 @@ class app : public IApp, public ah::Scheduler { return mConfig->cmt.pinIrq; } - String getTimeStr(uint32_t offset = 0) { - char str[10]; - if(0 == mTimestamp) - sprintf(str, "n/a"); - else - sprintf(str, "%02d:%02d:%02d ", hour(mTimestamp + offset), minute(mTimestamp + offset), second(mTimestamp + offset)); - return String(str); - } - uint32_t getTimezoneOffset() { return mApi.getTimezoneOffset(); } diff --git a/src/appInterface.h b/src/appInterface.h index ec0f5437..7814d0e1 100644 --- a/src/appInterface.h +++ b/src/appInterface.h @@ -44,7 +44,6 @@ class IApp { virtual uint32_t getSunrise() = 0; virtual uint32_t getSunset() = 0; virtual void setTimestamp(uint32_t newTime) = 0; - virtual String getTimeStr(uint32_t offset) = 0; virtual uint32_t getTimezoneOffset() = 0; virtual void getSchedulerInfo(uint8_t *max) = 0; virtual void getSchedulerNames() = 0; diff --git a/src/config/settings.h b/src/config/settings.h index 556c7e76..6a8f1dc3 100644 --- a/src/config/settings.h +++ b/src/config/settings.h @@ -30,7 +30,7 @@ * https://arduino-esp8266.readthedocs.io/en/latest/filesystem.html#flash-layout * */ -#define CONFIG_VERSION 3 +#define CONFIG_VERSION 4 #define PROT_MASK_INDEX 0x0001 @@ -159,6 +159,7 @@ typedef struct { bool rstMaxValsMidNight; bool startWithoutTime; float yieldEffiency; + uint16_t gapMs; } cfgInst_t; typedef struct { @@ -443,6 +444,7 @@ class settings { mCfg.inst.startWithoutTime = false; mCfg.inst.rstMaxValsMidNight = false; mCfg.inst.yieldEffiency = 1.0f; + mCfg.inst.gapMs = 2000; for(uint8_t i = 0; i < MAX_NUM_INVERTERS; i++) { mCfg.inst.iv[i].powerLevel = 0xff; // impossible high value @@ -483,6 +485,9 @@ class settings { if(mCfg.configVersion < 3) { mCfg.serial.printWholeTrace = true; } + if(mCfg.configVersion < 4) { + mCfg.inst.gapMs = 2000; + } } } @@ -708,12 +713,13 @@ class settings { void jsonInst(JsonObject obj, bool set = false) { if(set) { obj[F("en")] = (bool)mCfg.inst.enabled; - obj[F("rstMidNight")] = (bool)mCfg.inst.rstYieldMidNight; - obj[F("rstNotAvail")] = (bool)mCfg.inst.rstValsNotAvail; - obj[F("rstComStop")] = (bool)mCfg.inst.rstValsCommStop; - obj[F("strtWthtTime")] = (bool)mCfg.inst.startWithoutTime; + obj[F("rstMidNight")] = (bool)mCfg.inst.rstYieldMidNight; + obj[F("rstNotAvail")] = (bool)mCfg.inst.rstValsNotAvail; + obj[F("rstComStop")] = (bool)mCfg.inst.rstValsCommStop; + obj[F("strtWthtTime")] = (bool)mCfg.inst.startWithoutTime; obj[F("rstMaxMidNight")] = (bool)mCfg.inst.rstMaxValsMidNight; - obj[F("yldEff")] = mCfg.inst.yieldEffiency; + obj[F("yldEff")] = mCfg.inst.yieldEffiency; + obj[F("gap")] = mCfg.inst.gapMs; } else { getVal(obj, F("en"), &mCfg.inst.enabled); @@ -723,6 +729,7 @@ class settings { getVal(obj, F("strtWthtTime"), &mCfg.inst.startWithoutTime); getVal(obj, F("rstMaxMidNight"), &mCfg.inst.rstMaxValsMidNight); getVal(obj, F("yldEff"), &mCfg.inst.yieldEffiency); + getVal(obj, F("gap"), &mCfg.inst.gapMs); if(mCfg.inst.yieldEffiency < 0.5) mCfg.inst.yieldEffiency = 1.0f; diff --git a/src/defines.h b/src/defines.h index ffd3c6ae..24bcc8a5 100644 --- a/src/defines.h +++ b/src/defines.h @@ -13,7 +13,7 @@ //------------------------------------- #define VERSION_MAJOR 0 #define VERSION_MINOR 8 -#define VERSION_PATCH 18 +#define VERSION_PATCH 19 //------------------------------------- typedef struct { diff --git a/src/hm/Communication.h b/src/hm/Communication.h index bf95d44c..e8c17d1e 100644 --- a/src/hm/Communication.h +++ b/src/hm/Communication.h @@ -15,7 +15,6 @@ #define FRSTMSG_TIMEOUT 150 // how long to wait for first msg to be received #define DEFAULT_TIMEOUT 500 // timeout for regular requests #define SINGLEFR_TIMEOUT 65 // timeout for single frame requests -#define WAIT_GAP_TIMEOUT 200 // timeout after no complete payload #define MAX_BUFFER 250 typedef std::function *)> payloadListenerType; @@ -23,11 +22,12 @@ typedef std::function *)> alarmListenerType; class Communication : public CommQueue<> { public: - void setup(uint32_t *timestamp, bool *serialDebug, bool *privacyMode, bool *printWholeTrace) { + void setup(uint32_t *timestamp, bool *serialDebug, bool *privacyMode, bool *printWholeTrace, uint16_t *inverterGap) { mTimestamp = timestamp; mPrivacyMode = privacyMode; mSerialDebug = serialDebug; mPrintWholeTrace = printWholeTrace; + mInverterGap = inverterGap; } void addImportant(Inverter<> *iv, uint8_t cmd, bool delOnPop = true) { @@ -134,7 +134,6 @@ class Communication : public CommQueue<> { DBGPRINT(String(millis() - mWaitTimeout + timeout)); DBGPRINTLN(F("ms")); } - if(!q->iv->mGotFragment) { 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)); @@ -284,6 +283,7 @@ class Communication : public CommQueue<> { DHEX(buf[0]);DHEX(buf[1]);DHEX(buf[2]);DHEX(buf[3]); DBGPRINT(F(", expected: 0x")); DHEX(tmp[0]);DHEX(tmp[1]);DHEX(tmp[2]);DHEX(tmp[3]); + DBGPRINTLN(""); return false; } } @@ -473,8 +473,8 @@ class Communication : public CommQueue<> { q->iv->radioStatistics.rxFail++; // got no complete payload else { q->iv->radioStatistics.rxFailNoAnser++; // got nothing - mWaitTimeout = millis() + WAIT_GAP_TIMEOUT; } + mWaitTimeout = millis() + *mInverterGap; cmdDone(delCmd); q->iv->mGotFragment = false; @@ -483,6 +483,7 @@ class Communication : public CommQueue<> { mIsResend = false; mFirstTry = false; // for correct reset mState = States::RESET; + DBGPRINTLN("-----"); } inline void miHwDecode(packet_t *p, const queue_s *q) { @@ -826,6 +827,7 @@ class Communication : public CommQueue<> { States mState = States::RESET; uint32_t *mTimestamp; bool *mPrivacyMode, *mSerialDebug, *mPrintWholeTrace; + uint16_t *mInverterGap; uint32_t mWaitTimeout = 0; uint32_t mWaitTimeout_min = 0; std::array mLocalBuf; diff --git a/src/hm/Heuristic.h b/src/hm/Heuristic.h index a30436f7..17efe080 100644 --- a/src/hm/Heuristic.h +++ b/src/hm/Heuristic.h @@ -133,7 +133,10 @@ class Heuristic { DBGPRINT(F(", n: ")); DBGPRINT(String(iv->radioStatistics.rxFailNoAnser)); DBGPRINT(F(" | p: ")); // better debugging for helpers... - DBGPRINTLN(String(iv->config->powerLevel)); + if((IV_HMS == iv->ivGen) || (IV_HMT == iv->ivGen)) + DBGPRINTLN(String(iv->config->powerLevel-10)); + else + DBGPRINTLN(String(iv->config->powerLevel)); } private: diff --git a/src/utils/helper.cpp b/src/utils/helper.cpp index 67758f5d..e606ad8b 100644 --- a/src/utils/helper.cpp +++ b/src/utils/helper.cpp @@ -70,6 +70,15 @@ namespace ah { return String(str); } + String getTimeStrMs(time_t t) { + char str[13]; + if(0 == t) + sprintf(str, "n/a"); + else + sprintf(str, "%02d:%02d:%02d.%03d", hour(t), minute(t), second(t), millis() % 1000); + return String(str); + } + uint64_t Serial2u64(const char *val) { char tmp[3]; uint64_t ret = 0ULL; diff --git a/src/utils/helper.h b/src/utils/helper.h index d7c6f34c..60721414 100644 --- a/src/utils/helper.h +++ b/src/utils/helper.h @@ -44,6 +44,7 @@ namespace ah { String getDateTimeStrShort(time_t t); String getDateTimeStrFile(time_t t); String getTimeStr(time_t t); + String getTimeStrMs(time_t t); uint64_t Serial2u64(const char *val); void dumpBuf(uint8_t buf[], uint8_t len, uint8_t firstRepl = 0, uint8_t lastRepl = 0); } diff --git a/src/web/RestApi.h b/src/web/RestApi.h index 61478cc9..d431c474 100644 --- a/src/web/RestApi.h +++ b/src/web/RestApi.h @@ -389,6 +389,7 @@ class RestApi { obj[F("strtWthtTm")] = (bool)mConfig->inst.startWithoutTime; obj[F("rstMaxMid")] = (bool)mConfig->inst.rstMaxValsMidNight; obj[F("yldEff")] = mConfig->inst.yieldEffiency; + obj[F("gap")] = mConfig->inst.gapMs; } void getInverter(JsonObject obj, uint8_t id) { diff --git a/src/web/html/setup.html b/src/web/html/setup.html index 87869fd6..fecebd81 100644 --- a/src/web/html/setup.html +++ b/src/web/html/setup.html @@ -148,6 +148,10 @@
Interval [s]
+
+
Inverter Gap [ms]
+
+
Reset values and YieldDay at midnight
@@ -571,7 +575,7 @@ } function ivGlob(obj) { - for(var i of [["invInterval", "interval"], ["yldEff", "yldEff"]]) + for(var i of [["invInterval", "interval"], ["yldEff", "yldEff"], ["invGap", "gap"]]) document.getElementsByName(i[0])[0].value = obj[i[1]]; for(var i of ["Mid", "ComStop", "NotAvail", "MaxMid"]) document.getElementsByName("invRst"+i)[0].checked = obj["rst" + i]; diff --git a/src/web/web.h b/src/web/web.h index cb5cf72a..75d06e19 100644 --- a/src/web/web.h +++ b/src/web/web.h @@ -208,10 +208,11 @@ class Web { msg.replace("\r\n", ""); if (mSerialAddTime) { - if ((9 + mSerialBufFill) < WEB_SERIAL_BUF_SIZE) { + if ((13 + mSerialBufFill) < WEB_SERIAL_BUF_SIZE) { if (mApp->getTimestamp() > 0) { - strncpy(&mSerialBuf[mSerialBufFill], mApp->getTimeStr(mApp->getTimezoneOffset()).c_str(), 9); - mSerialBufFill += 9; + strncpy(&mSerialBuf[mSerialBufFill], ah::getTimeStrMs(mApp->getTimestamp() + mApp->getTimezoneOffset()).c_str(), 12); + mSerialBuf[mSerialBufFill+12] = ' '; + mSerialBufFill += 13; } } else { mSerialBufFill = 0; @@ -495,6 +496,7 @@ class Web { mConfig->inst.startWithoutTime = (request->arg("strtWthtTm") == "on"); mConfig->inst.rstMaxValsMidNight = (request->arg("invRstMaxMid") == "on"); mConfig->inst.yieldEffiency = (request->arg("yldEff")).toFloat(); + mConfig->inst.gapMs = (request->arg("invGap")).toInt(); // pinout