diff --git a/src/CHANGES.md b/src/CHANGES.md index 9ea5ff5d..6c905aaa 100644 --- a/src/CHANGES.md +++ b/src/CHANGES.md @@ -1,5 +1,10 @@ # Development Changes +## 0.8.10 - 2023-11-19 +* fix Mi and HM inverter communication #1235 +* added privacy mode option #1211 +* changed serial debug option to work without reboot + ## 0.8.9 - 2023-11-19 * merged PR #1234 * added new alarm codes diff --git a/src/app.cpp b/src/app.cpp index 5226f5ac..daa13307 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -32,13 +32,11 @@ void app::setup() { DBGPRINTLN(F("false")); if(mConfig->nrf.enabled) { - mNrfRadio.setup(mConfig->nrf.pinIrq, mConfig->nrf.pinCe, mConfig->nrf.pinCs, mConfig->nrf.pinSclk, mConfig->nrf.pinMosi, mConfig->nrf.pinMiso); - mNrfRadio.enableDebug(); + mNrfRadio.setup(&mConfig->serial.debug, &mConfig->serial.privacyLog, mConfig->nrf.pinIrq, mConfig->nrf.pinCe, mConfig->nrf.pinCs, mConfig->nrf.pinSclk, mConfig->nrf.pinMosi, mConfig->nrf.pinMiso); } #if defined(ESP32) if(mConfig->cmt.enabled) { - mCmtRadio.setup(mConfig->cmt.pinSclk, mConfig->cmt.pinSdio, mConfig->cmt.pinCsb, mConfig->cmt.pinFcsb, false); - mCmtRadio.enableDebug(); + mCmtRadio.setup(&mConfig->serial.debug, &mConfig->serial.privacyLog, mConfig->cmt.pinSclk, mConfig->cmt.pinSdio, mConfig->cmt.pinCsb, mConfig->cmt.pinFcsb, false); } #endif #ifdef ETHERNET @@ -57,7 +55,7 @@ void app::setup() { #endif #endif /* defined(ETHERNET) */ - mCommunication.setup(&mTimestamp); + mCommunication.setup(&mTimestamp, &mConfig->serial.debug, &mConfig->serial.privacyLog); 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/config/settings.h b/src/config/settings.h index 50632d0a..1fe7be00 100644 --- a/src/config/settings.h +++ b/src/config/settings.h @@ -116,6 +116,7 @@ typedef struct { typedef struct { bool showIv; bool debug; + bool privacyLog; } cfgSerial_t; typedef struct { @@ -424,6 +425,7 @@ class settings { mCfg.serial.showIv = false; mCfg.serial.debug = false; + mCfg.serial.privacyLog = true; mCfg.mqtt.port = DEF_MQTT_PORT; snprintf(mCfg.mqtt.broker, MQTT_ADDR_LEN, "%s", DEF_MQTT_BROKER); @@ -617,9 +619,11 @@ class settings { if(set) { obj[F("show")] = mCfg.serial.showIv; obj[F("debug")] = mCfg.serial.debug; + obj[F("prv")] = (bool) mCfg.serial.privacyLog; } else { getVal(obj, F("show"), &mCfg.serial.showIv); getVal(obj, F("debug"), &mCfg.serial.debug); + getVal(obj, F("prv"), &mCfg.serial.privacyLog); } } diff --git a/src/defines.h b/src/defines.h index 72f2887f..124aa817 100644 --- a/src/defines.h +++ b/src/defines.h @@ -13,7 +13,7 @@ //------------------------------------- #define VERSION_MAJOR 0 #define VERSION_MINOR 8 -#define VERSION_PATCH 9 +#define VERSION_PATCH 10 //------------------------------------- typedef struct { diff --git a/src/hm/Communication.h b/src/hm/Communication.h index c599cadc..6d2d0e1a 100644 --- a/src/hm/Communication.h +++ b/src/hm/Communication.h @@ -22,8 +22,10 @@ typedef std::function *)> alarmListenerType; class Communication : public CommQueue<> { public: - void setup(uint32_t *timestamp) { + void setup(uint32_t *timestamp, bool *serialDebug, bool *privacyMode) { mTimestamp = timestamp; + mPrivacyMode = privacyMode; + mSerialDebug = serialDebug; } void addImportant(Inverter<> *iv, uint8_t cmd, bool delOnPop = true) { @@ -57,13 +59,13 @@ class Communication : public CommQueue<> { mLocalBuf[i].len = 0; } - if(q->iv->radio->isSerialDebug()) + if(*mSerialDebug) mHeu.printStatus(q->iv); mHeu.getTxCh(q->iv); testMode = mHeu.getTestModeEnabled(); q->iv->mGotFragment = false; q->iv->mGotLastMsg = false; - mFirstTry = mFirstTry ? false : (((IV_HM == q->iv->ivGen) || (IV_MI == q->iv->ivGen) ) && (q->iv->isAvailable()) || (millis() < 120000)); + mFirstTry = mFirstTry ? false : (((IV_HM == q->iv->ivGen) || (IV_MI == q->iv->ivGen)) && ((q->iv->isAvailable()) || (millis() < 120000))); if(NULL == q->iv->radio) cmdDone(true); // can't communicate while radio is not defined! mState = States::START; @@ -161,7 +163,10 @@ class Communication : public CommQueue<> { DBGPRINT(F(", ")); DBGPRINT(String(p->rssi)); DBGPRINT(F("dBm | ")); - ah::dumpBuf(p->packet, p->len, 1, 8, "#"+String(q->iv->id)); + if(*mPrivacyMode) + ah::dumpBuf(p->packet, p->len, 1, 8); + else + ah::dumpBuf(p->packet, p->len); if(checkIvSerial(&p->packet[1], q->iv)) { if(!testMode) @@ -717,7 +722,7 @@ class Communication : public CommQueue<> { inline void miComplete(Inverter<> *iv) { - if (iv->radio->isSerialDebug()) { + if (*mSerialDebug) { DPRINT_IVID(DBG_INFO, iv->id); DBGPRINTLN(F("got all data msgs")); } @@ -766,6 +771,7 @@ class Communication : public CommQueue<> { private: States mState = States::RESET; uint32_t *mTimestamp; + bool *mPrivacyMode, *mSerialDebug; uint32_t mWaitTimeout = 0; uint32_t mWaitTimeout_min = 0; std::array mLocalBuf; diff --git a/src/hm/hmRadio.h b/src/hm/hmRadio.h index 88e62f8f..a36935f8 100644 --- a/src/hm/hmRadio.h +++ b/src/hm/hmRadio.h @@ -29,7 +29,19 @@ template > 24) & 0xFF) | ((mDtuSn >> 8) & 0xFF00) | ((mDtuSn << 8) & 0xFF0000) | ((mDtuSn << 24) & 0xFF000000)) << 8) | 0x01; @@ -252,9 +254,12 @@ class HmRadio : public Radio { p.millis = millis() - mMillis; mNrf24.read(p.packet, p.len); if (p.packet[0] != 0x00) { - if(!checkIvSerial(&p.packet[1], mLastIv)) { - DPRINT(DBG_WARN, "RX other inverter: "); - ah::dumpBuf(p.packet, p.len); + if(!checkIvSerial(p.packet, mLastIv)) { + DPRINT(DBG_WARN, "RX other inverter "); + if(*mPrivacyMode) + ah::dumpBuf(p.packet, p.len, 1, 4); + else + ah::dumpBuf(p.packet, p.len); return false; } mLastIv->mGotFragment = true; @@ -281,14 +286,17 @@ class HmRadio : public Radio { // set TX and RX channels mTxChIdx = mRfChLst[iv->txRfChId]; - if(mSerialDebug) { + if(*mSerialDebug) { DPRINT_IVID(DBG_INFO, iv->id); DBGPRINT(F("TX ")); DBGPRINT(String(len)); DBGPRINT(" CH"); DBGPRINT(String(mTxChIdx)); DBGPRINT(F(" | ")); - ah::dumpBuf(mTxBuf, len, 1, 4, "#"+String(iv->id)); + if(*mPrivacyMode) + ah::dumpBuf(mTxBuf, len, 1, 4); + else + ah::dumpBuf(mTxBuf, len); } mNrf24.stopListening(); @@ -309,8 +317,8 @@ class HmRadio : public Radio { } inline bool checkIvSerial(uint8_t buf[], Inverter<> *iv) { - for(uint8_t i = 0; i < 4; i++) { - if(buf[3-i] != iv->radioId.b[i]) + for(uint8_t i = 1; i < 5; i++) { + if(buf[i] != iv->radioId.b[i]) return false; } return true; diff --git a/src/hm/radio.h b/src/hm/radio.h index e4beb071..ddba0b50 100644 --- a/src/hm/radio.h +++ b/src/hm/radio.h @@ -34,14 +34,6 @@ class Radio { mIrqRcvd = true; } - void enableDebug() { - mSerialDebug = true; - } - - bool isSerialDebug() { - return mSerialDebug; - } - void sendCmdPacket(Inverter<> *iv, uint8_t mid, uint8_t pid, bool isRetransmit, bool appendCrc16=true) { initPacket(getIvId(iv), mid, pid); sendPacket(iv, 10, isRetransmit, appendCrc16); @@ -55,7 +47,7 @@ class Radio { return; } - if(mSerialDebug) { + if(*mSerialDebug) { DPRINT(DBG_DEBUG, F("prepareDevInformCmd 0x")); DPRINTLN(DBG_DEBUG,String(cmd, HEX)); } @@ -115,7 +107,8 @@ class Radio { uint32_t mDtuSn; volatile bool mIrqRcvd; - bool mSerialDebug; + bool *mSerialDebug; + bool *mPrivacyMode; uint8_t mTxBuf[MAX_RF_PAYLOAD_SIZE]; }; diff --git a/src/hms/hmsRadio.h b/src/hms/hmsRadio.h index bcb08c3f..1f6044bb 100644 --- a/src/hms/hmsRadio.h +++ b/src/hms/hmsRadio.h @@ -19,14 +19,18 @@ class CmtRadio : public Radio { mCmtAvail = false; } - void setup(uint8_t pinSclk, uint8_t pinSdio, uint8_t pinCsb, uint8_t pinFcsb, bool genDtuSn = true) { + void setup(bool *serialDebug, bool *privacyMode, uint8_t pinSclk, uint8_t pinSdio, uint8_t pinCsb, uint8_t pinFcsb, bool genDtuSn = true) { mCmt.setup(pinSclk, pinSdio, pinCsb, pinFcsb); reset(genDtuSn); + mPrivacyMode = privacyMode; + mSerialDebug = serialDebug; } - void setup(bool genDtuSn = true) { + void setup(bool *serialDebug, bool *privacyMode, bool genDtuSn = true) { mCmt.setup(); reset(genDtuSn); + mPrivacyMode = privacyMode; + mSerialDebug = serialDebug; } void loop() { @@ -88,12 +92,15 @@ class CmtRadio : public Radio { updateCrcs(&len, appendCrc16); - if(mSerialDebug) { + if(*mSerialDebug) { DPRINT_IVID(DBG_INFO, iv->id); DBGPRINT(F("TX ")); DBGPRINT(String(mCmt.getFreqKhz()/1000.0f)); DBGPRINT(F("Mhz | ")); - ah::dumpBuf(mTxBuf, len); + if(*mPrivacyMode) + ah::dumpBuf(mTxBuf, len, 1, 4); + else + ah::dumpBuf(mTxBuf, len); } uint8_t status = mCmt.tx(mTxBuf, len); @@ -125,7 +132,6 @@ class CmtRadio : public Radio { mCmt.goRx(); } - mSerialDebug = false; mIrqRcvd = false; mRqstGetRx = false; } diff --git a/src/utils/helper.cpp b/src/utils/helper.cpp index c7aefc1c..67758f5d 100644 --- a/src/utils/helper.cpp +++ b/src/utils/helper.cpp @@ -86,12 +86,12 @@ namespace ah { return ret; } - void dumpBuf(uint8_t buf[], uint8_t len, uint8_t firstRepl, uint8_t lastRepl, String repl) { + void dumpBuf(uint8_t buf[], uint8_t len, uint8_t firstRepl, uint8_t lastRepl) { for(uint8_t i = 0; i < len; i++) { - if(i < firstRepl || i > lastRepl) + if((i < firstRepl) || (i > lastRepl) || (0 == firstRepl)) DHEX(buf[i]); else - DBGPRINT(repl); + DBGPRINT(F(" *")); DBGPRINT(" "); } DBGPRINTLN(""); diff --git a/src/utils/helper.h b/src/utils/helper.h index 296729db..d7c6f34c 100644 --- a/src/utils/helper.h +++ b/src/utils/helper.h @@ -45,7 +45,7 @@ namespace ah { String getDateTimeStrFile(time_t t); String getTimeStr(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, String repl = ""); + void dumpBuf(uint8_t buf[], uint8_t len, uint8_t firstRepl = 0, uint8_t lastRepl = 0); } #endif /*__HELPER_H__*/ diff --git a/src/web/RestApi.h b/src/web/RestApi.h index 2378819c..f6d40a3a 100644 --- a/src/web/RestApi.h +++ b/src/web/RestApi.h @@ -561,6 +561,7 @@ class RestApi { void getSerial(JsonObject obj) { obj[F("show_live_data")] = mConfig->serial.showIv; obj[F("debug")] = mConfig->serial.debug; + obj[F("priv")] = mConfig->serial.privacyLog; } void getStaticIp(JsonObject obj) { diff --git a/src/web/html/setup.html b/src/web/html/setup.html index aa0f5435..b4d5749d 100644 --- a/src/web/html/setup.html +++ b/src/web/html/setup.html @@ -48,6 +48,10 @@
Serial Debug
+
+
Privacy Mode
+
+
@@ -933,7 +937,7 @@ /*ENDIF_ESP32*/ function parseSerial(obj) { - for(var i of [["serEn", "show_live_data"], ["serDbg", "debug"]]) + for(var i of [["serEn", "show_live_data"], ["serDbg", "debug"], ["priv", "priv"]]) document.getElementsByName(i[0])[0].checked = obj[i[1]]; } diff --git a/src/web/web.h b/src/web/web.h index a795d5ed..8c9be435 100644 --- a/src/web/web.h +++ b/src/web/web.h @@ -559,6 +559,7 @@ class Web { // serial console mConfig->serial.debug = (request->arg("serDbg") == "on"); + mConfig->serial.privacyLog = (request->arg("priv") == "on"); mConfig->serial.showIv = (request->arg("serEn") == "on"); // display @@ -634,7 +635,6 @@ class Web { { Inverter<> *iv; record_t<> *rec; - statistics_t *stat; String promUnit, promType; String metrics; char type[60], topic[100], val[25];