Browse Source

0.8.10

* fix Mi and HM inverter communication #1235
* added privacy mode option #1211
* changed serial debug option to work without reboot
pull/1239/head
lumapu 1 year ago
parent
commit
b7f0e683ec
  1. 5
      src/CHANGES.md
  2. 8
      src/app.cpp
  3. 4
      src/config/settings.h
  4. 2
      src/defines.h
  5. 16
      src/hm/Communication.h
  6. 42
      src/hm/hmRadio.h
  7. 13
      src/hm/radio.h
  8. 14
      src/hms/hmsRadio.h
  9. 6
      src/utils/helper.cpp
  10. 2
      src/utils/helper.h
  11. 1
      src/web/RestApi.h
  12. 6
      src/web/html/setup.html
  13. 2
      src/web/web.h

5
src/CHANGES.md

@ -1,5 +1,10 @@
# Development Changes # 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 ## 0.8.9 - 2023-11-19
* merged PR #1234 * merged PR #1234
* added new alarm codes * added new alarm codes

8
src/app.cpp

@ -32,13 +32,11 @@ void app::setup() {
DBGPRINTLN(F("false")); DBGPRINTLN(F("false"));
if(mConfig->nrf.enabled) { 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.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);
mNrfRadio.enableDebug();
} }
#if defined(ESP32) #if defined(ESP32)
if(mConfig->cmt.enabled) { if(mConfig->cmt.enabled) {
mCmtRadio.setup(mConfig->cmt.pinSclk, mConfig->cmt.pinSdio, mConfig->cmt.pinCsb, mConfig->cmt.pinFcsb, false); mCmtRadio.setup(&mConfig->serial.debug, &mConfig->serial.privacyLog, mConfig->cmt.pinSclk, mConfig->cmt.pinSdio, mConfig->cmt.pinCsb, mConfig->cmt.pinFcsb, false);
mCmtRadio.enableDebug();
} }
#endif #endif
#ifdef ETHERNET #ifdef ETHERNET
@ -57,7 +55,7 @@ void app::setup() {
#endif #endif
#endif /* defined(ETHERNET) */ #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)); mCommunication.addPayloadListener(std::bind(&app::payloadEventListener, this, std::placeholders::_1, std::placeholders::_2));
mSys.setup(&mTimestamp, &mConfig->inst); mSys.setup(&mTimestamp, &mConfig->inst);
for (uint8_t i = 0; i < MAX_NUM_INVERTERS; i++) { for (uint8_t i = 0; i < MAX_NUM_INVERTERS; i++) {

4
src/config/settings.h

@ -116,6 +116,7 @@ typedef struct {
typedef struct { typedef struct {
bool showIv; bool showIv;
bool debug; bool debug;
bool privacyLog;
} cfgSerial_t; } cfgSerial_t;
typedef struct { typedef struct {
@ -424,6 +425,7 @@ class settings {
mCfg.serial.showIv = false; mCfg.serial.showIv = false;
mCfg.serial.debug = false; mCfg.serial.debug = false;
mCfg.serial.privacyLog = true;
mCfg.mqtt.port = DEF_MQTT_PORT; mCfg.mqtt.port = DEF_MQTT_PORT;
snprintf(mCfg.mqtt.broker, MQTT_ADDR_LEN, "%s", DEF_MQTT_BROKER); snprintf(mCfg.mqtt.broker, MQTT_ADDR_LEN, "%s", DEF_MQTT_BROKER);
@ -617,9 +619,11 @@ class settings {
if(set) { if(set) {
obj[F("show")] = mCfg.serial.showIv; obj[F("show")] = mCfg.serial.showIv;
obj[F("debug")] = mCfg.serial.debug; obj[F("debug")] = mCfg.serial.debug;
obj[F("prv")] = (bool) mCfg.serial.privacyLog;
} else { } else {
getVal<bool>(obj, F("show"), &mCfg.serial.showIv); getVal<bool>(obj, F("show"), &mCfg.serial.showIv);
getVal<bool>(obj, F("debug"), &mCfg.serial.debug); getVal<bool>(obj, F("debug"), &mCfg.serial.debug);
getVal<bool>(obj, F("prv"), &mCfg.serial.privacyLog);
} }
} }

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 9 #define VERSION_PATCH 10
//------------------------------------- //-------------------------------------
typedef struct { typedef struct {

16
src/hm/Communication.h

@ -22,8 +22,10 @@ typedef std::function<void(Inverter<> *)> alarmListenerType;
class Communication : public CommQueue<> { class Communication : public CommQueue<> {
public: public:
void setup(uint32_t *timestamp) { void setup(uint32_t *timestamp, bool *serialDebug, bool *privacyMode) {
mTimestamp = timestamp; mTimestamp = timestamp;
mPrivacyMode = privacyMode;
mSerialDebug = serialDebug;
} }
void addImportant(Inverter<> *iv, uint8_t cmd, bool delOnPop = true) { void addImportant(Inverter<> *iv, uint8_t cmd, bool delOnPop = true) {
@ -57,13 +59,13 @@ class Communication : public CommQueue<> {
mLocalBuf[i].len = 0; mLocalBuf[i].len = 0;
} }
if(q->iv->radio->isSerialDebug()) if(*mSerialDebug)
mHeu.printStatus(q->iv); mHeu.printStatus(q->iv);
mHeu.getTxCh(q->iv); mHeu.getTxCh(q->iv);
testMode = mHeu.getTestModeEnabled(); testMode = mHeu.getTestModeEnabled();
q->iv->mGotFragment = false; q->iv->mGotFragment = false;
q->iv->mGotLastMsg = 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) if(NULL == q->iv->radio)
cmdDone(true); // can't communicate while radio is not defined! cmdDone(true); // can't communicate while radio is not defined!
mState = States::START; mState = States::START;
@ -161,7 +163,10 @@ class Communication : public CommQueue<> {
DBGPRINT(F(", ")); DBGPRINT(F(", "));
DBGPRINT(String(p->rssi)); DBGPRINT(String(p->rssi));
DBGPRINT(F("dBm | ")); 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(checkIvSerial(&p->packet[1], q->iv)) {
if(!testMode) if(!testMode)
@ -717,7 +722,7 @@ class Communication : public CommQueue<> {
inline void miComplete(Inverter<> *iv) { inline void miComplete(Inverter<> *iv) {
if (iv->radio->isSerialDebug()) { if (*mSerialDebug) {
DPRINT_IVID(DBG_INFO, iv->id); DPRINT_IVID(DBG_INFO, iv->id);
DBGPRINTLN(F("got all data msgs")); DBGPRINTLN(F("got all data msgs"));
} }
@ -766,6 +771,7 @@ class Communication : public CommQueue<> {
private: private:
States mState = States::RESET; States mState = States::RESET;
uint32_t *mTimestamp; uint32_t *mTimestamp;
bool *mPrivacyMode, *mSerialDebug;
uint32_t mWaitTimeout = 0; uint32_t mWaitTimeout = 0;
uint32_t mWaitTimeout_min = 0; uint32_t mWaitTimeout_min = 0;
std::array<frame_t, MAX_PAYLOAD_ENTRIES> mLocalBuf; std::array<frame_t, MAX_PAYLOAD_ENTRIES> mLocalBuf;

42
src/hm/hmRadio.h

@ -29,7 +29,19 @@ template <uint8_t IRQ_PIN = DEF_NRF_IRQ_PIN, uint8_t CE_PIN = DEF_NRF_CE_PIN, ui
class HmRadio : public Radio { class HmRadio : public Radio {
public: public:
HmRadio() : mNrf24(CE_PIN, CS_PIN, SPI_SPEED) { HmRadio() : mNrf24(CE_PIN, CS_PIN, SPI_SPEED) {
if(mSerialDebug) { mDtuSn = DTU_SN;
mIrqRcvd = false;
}
~HmRadio() {}
void setup(bool *serialDebug, bool *privacyMode, uint8_t irq = IRQ_PIN, uint8_t ce = CE_PIN, uint8_t cs = CS_PIN, uint8_t sclk = SCLK_PIN, uint8_t mosi = MOSI_PIN, uint8_t miso = MISO_PIN) {
DPRINTLN(DBG_VERBOSE, F("hmRadio.h:setup"));
pinMode(irq, INPUT_PULLUP);
mSerialDebug = serialDebug;
mPrivacyMode = privacyMode;
if(*mSerialDebug) {
DPRINT(DBG_VERBOSE, F("hmRadio.h : HmRadio():mNrf24(CE_PIN: ")); DPRINT(DBG_VERBOSE, F("hmRadio.h : HmRadio():mNrf24(CE_PIN: "));
DBGPRINT(String(CE_PIN)); DBGPRINT(String(CE_PIN));
DBGPRINT(F(", CS_PIN: ")); DBGPRINT(F(", CS_PIN: "));
@ -38,16 +50,6 @@ class HmRadio : public Radio {
DBGPRINT(String(SPI_SPEED)); DBGPRINT(String(SPI_SPEED));
DBGPRINTLN(F(")")); DBGPRINTLN(F(")"));
} }
mDtuSn = DTU_SN;
mSerialDebug = false;
mIrqRcvd = false;
}
~HmRadio() {}
void setup(uint8_t irq = IRQ_PIN, uint8_t ce = CE_PIN, uint8_t cs = CS_PIN, uint8_t sclk = SCLK_PIN, uint8_t mosi = MOSI_PIN, uint8_t miso = MISO_PIN) {
DPRINTLN(DBG_VERBOSE, F("hmRadio.h:setup"));
pinMode(irq, INPUT_PULLUP);
generateDtuSn(); generateDtuSn();
DTU_RADIO_ID = ((uint64_t)(((mDtuSn >> 24) & 0xFF) | ((mDtuSn >> 8) & 0xFF00) | ((mDtuSn << 8) & 0xFF0000) | ((mDtuSn << 24) & 0xFF000000)) << 8) | 0x01; DTU_RADIO_ID = ((uint64_t)(((mDtuSn >> 24) & 0xFF) | ((mDtuSn >> 8) & 0xFF00) | ((mDtuSn << 8) & 0xFF0000) | ((mDtuSn << 24) & 0xFF000000)) << 8) | 0x01;
@ -252,8 +254,11 @@ class HmRadio : public Radio {
p.millis = millis() - mMillis; p.millis = millis() - mMillis;
mNrf24.read(p.packet, p.len); mNrf24.read(p.packet, p.len);
if (p.packet[0] != 0x00) { if (p.packet[0] != 0x00) {
if(!checkIvSerial(&p.packet[1], mLastIv)) { if(!checkIvSerial(p.packet, mLastIv)) {
DPRINT(DBG_WARN, "RX other inverter: "); DPRINT(DBG_WARN, "RX other inverter ");
if(*mPrivacyMode)
ah::dumpBuf(p.packet, p.len, 1, 4);
else
ah::dumpBuf(p.packet, p.len); ah::dumpBuf(p.packet, p.len);
return false; return false;
} }
@ -281,14 +286,17 @@ class HmRadio : public Radio {
// set TX and RX channels // set TX and RX channels
mTxChIdx = mRfChLst[iv->txRfChId]; mTxChIdx = mRfChLst[iv->txRfChId];
if(mSerialDebug) { if(*mSerialDebug) {
DPRINT_IVID(DBG_INFO, iv->id); DPRINT_IVID(DBG_INFO, iv->id);
DBGPRINT(F("TX ")); DBGPRINT(F("TX "));
DBGPRINT(String(len)); DBGPRINT(String(len));
DBGPRINT(" CH"); DBGPRINT(" CH");
DBGPRINT(String(mTxChIdx)); DBGPRINT(String(mTxChIdx));
DBGPRINT(F(" | ")); 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(); mNrf24.stopListening();
@ -309,8 +317,8 @@ class HmRadio : public Radio {
} }
inline bool checkIvSerial(uint8_t buf[], Inverter<> *iv) { inline bool checkIvSerial(uint8_t buf[], Inverter<> *iv) {
for(uint8_t i = 0; i < 4; i++) { for(uint8_t i = 1; i < 5; i++) {
if(buf[3-i] != iv->radioId.b[i]) if(buf[i] != iv->radioId.b[i])
return false; return false;
} }
return true; return true;

13
src/hm/radio.h

@ -34,14 +34,6 @@ class Radio {
mIrqRcvd = true; 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) { void sendCmdPacket(Inverter<> *iv, uint8_t mid, uint8_t pid, bool isRetransmit, bool appendCrc16=true) {
initPacket(getIvId(iv), mid, pid); initPacket(getIvId(iv), mid, pid);
sendPacket(iv, 10, isRetransmit, appendCrc16); sendPacket(iv, 10, isRetransmit, appendCrc16);
@ -55,7 +47,7 @@ class Radio {
return; return;
} }
if(mSerialDebug) { if(*mSerialDebug) {
DPRINT(DBG_DEBUG, F("prepareDevInformCmd 0x")); DPRINT(DBG_DEBUG, F("prepareDevInformCmd 0x"));
DPRINTLN(DBG_DEBUG,String(cmd, HEX)); DPRINTLN(DBG_DEBUG,String(cmd, HEX));
} }
@ -115,7 +107,8 @@ class Radio {
uint32_t mDtuSn; uint32_t mDtuSn;
volatile bool mIrqRcvd; volatile bool mIrqRcvd;
bool mSerialDebug; bool *mSerialDebug;
bool *mPrivacyMode;
uint8_t mTxBuf[MAX_RF_PAYLOAD_SIZE]; uint8_t mTxBuf[MAX_RF_PAYLOAD_SIZE];
}; };

14
src/hms/hmsRadio.h

@ -19,14 +19,18 @@ class CmtRadio : public Radio {
mCmtAvail = false; 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); mCmt.setup(pinSclk, pinSdio, pinCsb, pinFcsb);
reset(genDtuSn); reset(genDtuSn);
mPrivacyMode = privacyMode;
mSerialDebug = serialDebug;
} }
void setup(bool genDtuSn = true) { void setup(bool *serialDebug, bool *privacyMode, bool genDtuSn = true) {
mCmt.setup(); mCmt.setup();
reset(genDtuSn); reset(genDtuSn);
mPrivacyMode = privacyMode;
mSerialDebug = serialDebug;
} }
void loop() { void loop() {
@ -88,11 +92,14 @@ class CmtRadio : public Radio {
updateCrcs(&len, appendCrc16); updateCrcs(&len, appendCrc16);
if(mSerialDebug) { if(*mSerialDebug) {
DPRINT_IVID(DBG_INFO, iv->id); DPRINT_IVID(DBG_INFO, iv->id);
DBGPRINT(F("TX ")); DBGPRINT(F("TX "));
DBGPRINT(String(mCmt.getFreqKhz()/1000.0f)); DBGPRINT(String(mCmt.getFreqKhz()/1000.0f));
DBGPRINT(F("Mhz | ")); DBGPRINT(F("Mhz | "));
if(*mPrivacyMode)
ah::dumpBuf(mTxBuf, len, 1, 4);
else
ah::dumpBuf(mTxBuf, len); ah::dumpBuf(mTxBuf, len);
} }
@ -125,7 +132,6 @@ class CmtRadio : public Radio {
mCmt.goRx(); mCmt.goRx();
} }
mSerialDebug = false;
mIrqRcvd = false; mIrqRcvd = false;
mRqstGetRx = false; mRqstGetRx = false;
} }

6
src/utils/helper.cpp

@ -86,12 +86,12 @@ namespace ah {
return ret; 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++) { for(uint8_t i = 0; i < len; i++) {
if(i < firstRepl || i > lastRepl) if((i < firstRepl) || (i > lastRepl) || (0 == firstRepl))
DHEX(buf[i]); DHEX(buf[i]);
else else
DBGPRINT(repl); DBGPRINT(F(" *"));
DBGPRINT(" "); DBGPRINT(" ");
} }
DBGPRINTLN(""); DBGPRINTLN("");

2
src/utils/helper.h

@ -45,7 +45,7 @@ namespace ah {
String getDateTimeStrFile(time_t t); String getDateTimeStrFile(time_t t);
String getTimeStr(time_t t); String getTimeStr(time_t t);
uint64_t Serial2u64(const char *val); 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__*/ #endif /*__HELPER_H__*/

1
src/web/RestApi.h

@ -561,6 +561,7 @@ class RestApi {
void getSerial(JsonObject obj) { void getSerial(JsonObject obj) {
obj[F("show_live_data")] = mConfig->serial.showIv; obj[F("show_live_data")] = mConfig->serial.showIv;
obj[F("debug")] = mConfig->serial.debug; obj[F("debug")] = mConfig->serial.debug;
obj[F("priv")] = mConfig->serial.privacyLog;
} }
void getStaticIp(JsonObject obj) { void getStaticIp(JsonObject obj) {

6
src/web/html/setup.html

@ -48,6 +48,10 @@
<div class="col-8 col-sm-3">Serial Debug</div> <div class="col-8 col-sm-3">Serial Debug</div>
<div class="col-4 col-sm-9"><input type="checkbox" name="serDbg"/></div> <div class="col-4 col-sm-9"><input type="checkbox" name="serDbg"/></div>
</div> </div>
<div class="row mb-3">
<div class="col-8 col-sm-3">Privacy Mode</div>
<div class="col-4 col-sm-9"><input type="checkbox" name="priv"/></div>
</div>
</fieldset> </fieldset>
</div> </div>
@ -933,7 +937,7 @@
/*ENDIF_ESP32*/ /*ENDIF_ESP32*/
function parseSerial(obj) { 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]]; document.getElementsByName(i[0])[0].checked = obj[i[1]];
} }

2
src/web/web.h

@ -559,6 +559,7 @@ class Web {
// serial console // serial console
mConfig->serial.debug = (request->arg("serDbg") == "on"); mConfig->serial.debug = (request->arg("serDbg") == "on");
mConfig->serial.privacyLog = (request->arg("priv") == "on");
mConfig->serial.showIv = (request->arg("serEn") == "on"); mConfig->serial.showIv = (request->arg("serEn") == "on");
// display // display
@ -634,7 +635,6 @@ class Web {
{ {
Inverter<> *iv; Inverter<> *iv;
record_t<> *rec; record_t<> *rec;
statistics_t *stat;
String promUnit, promType; String promUnit, promType;
String metrics; String metrics;
char type[60], topic[100], val[25]; char type[60], topic[100], val[25];

Loading…
Cancel
Save