From dcb4b49fa02909574305abfa7a1422025a34ae18 Mon Sep 17 00:00:00 2001 From: lumapu Date: Wed, 10 Jul 2024 23:13:43 +0200 Subject: [PATCH] 0.8.128 * add environments for 16MB flash size ESP32-S3 aka opendtufusion * prevent duplicate alarms, update end time once it is received --- src/CHANGES.md | 3 ++- src/hm/hmInverter.h | 21 ++++++++++++++++++++- src/web/html/visualization.html | 2 +- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/CHANGES.md b/src/CHANGES.md index e93e7f02..dfd4ca2a 100644 --- a/src/CHANGES.md +++ b/src/CHANGES.md @@ -1,7 +1,8 @@ # Development Changes -## 0.8.128 - 2024-07-02 +## 0.8.128 - 2024-07-10 * add environments for 16MB flash size ESP32-S3 aka opendtufusion +* prevent duplicate alarms, update end time once it is received ## 0.8.127 - 2024-06-21 * add grid file #1677 diff --git a/src/hm/hmInverter.h b/src/hm/hmInverter.h index b72ec5ab..e1b99bc8 100644 --- a/src/hm/hmInverter.h +++ b/src/hm/hmInverter.h @@ -670,7 +670,6 @@ class Inverter { DPRINTLN(DBG_DEBUG, "Alarm #" + String(pyld[startOff+1]) + " '" + String(getAlarmStr(pyld[startOff+1])) + "' start: " + ah::getTimeStr(start) + ", end: " + ah::getTimeStr(endTime)); addAlarm(pyld[startOff+1], start, endTime); - alarmCnt++; alarmLastId = alarmMesIndex; return pyld[startOff+1]; @@ -818,6 +817,26 @@ class Inverter { private: inline void addAlarm(uint16_t code, uint32_t start, uint32_t end) { + bool found = false; + uint8_t i = 0; + + if(start > end) + end = 0; + + for(; i < 10; i++) { + mAlarmNxtWrPos = (++mAlarmNxtWrPos) % 10; + + if(lastAlarm[mAlarmNxtWrPos].code == code && lastAlarm[mAlarmNxtWrPos].start == start) { + // replace with same or update end time + if(lastAlarm[mAlarmNxtWrPos].end == 0 || lastAlarm[mAlarmNxtWrPos].end == end) { + break; + } + } + } + + if(alarmCnt < 10 && alarmCnt < mAlarmNxtWrPos) + alarmCnt = mAlarmNxtWrPos + 1; + lastAlarm[mAlarmNxtWrPos] = alarm_t(code, start, end); if(++mAlarmNxtWrPos >= 10) // rolling buffer mAlarmNxtWrPos = 0; diff --git a/src/web/html/visualization.html b/src/web/html/visualization.html index 0fdaf89e..507a6f9f 100644 --- a/src/web/html/visualization.html +++ b/src/web/html/visualization.html @@ -276,7 +276,7 @@ ml("div", {class: "col mt-3"}, String(a.str)), ml("div", {class: "col mt-3"}, String(a.code)), ml("div", {class: "col mt-3"}, String(toIsoTimeStr(new Date((a.start + offs) * 1000)))), - ml("div", {class: "col mt-3"}, String(toIsoTimeStr(new Date((a.end + offs) * 1000)))) + ml("div", {class: "col mt-3"}, (a.end == 0) ? "-" : String(toIsoTimeStr(new Date((a.end + offs) * 1000)))) ]) ); }