From 23e848d2241995df126ce0185d84a1d10a56f5b0 Mon Sep 17 00:00:00 2001 From: lumapu Date: Sun, 26 Mar 2023 00:47:49 +0100 Subject: [PATCH] improved multi inverter fixed setup improved serial output --- src/hm/hmInverter.h | 2 +- src/hms/cmt2300a.h | 16 ++++++++-------- src/hms/hmsPayload.h | 20 +++++++++++++------- src/hms/hmsRadio.h | 18 ++++++++++-------- src/web/html/setup.html | 28 +++++++++++++++++++++++----- 5 files changed, 55 insertions(+), 29 deletions(-) diff --git a/src/hm/hmInverter.h b/src/hm/hmInverter.h index 898df40a..01eb5700 100644 --- a/src/hm/hmInverter.h +++ b/src/hm/hmInverter.h @@ -145,7 +145,7 @@ class Inverter { void enqueCommand(uint8_t cmd) { _commandQueue.push(std::make_shared(cmd)); DPRINT_IVID(DBG_INFO, id); - DBGPRINTLN(F("enqueCommand: 0x")); + DBGPRINT(F("enqueCommand: 0x")); DBGHEXLN(cmd); } diff --git a/src/hms/cmt2300a.h b/src/hms/cmt2300a.h index 5c1746de..95d62191 100644 --- a/src/hms/cmt2300a.h +++ b/src/hms/cmt2300a.h @@ -1,6 +1,6 @@ //----------------------------------------------------------------------------- // 2023 Ahoy, https://github.com/lumpapu/ahoy -// Creative Commons - http://creativecommons.org/licenses/by-nc-sa/3.0/de/ +// Creative Commons - https://creativecommons.org/licenses/by-nc-sa/4.0/deed //----------------------------------------------------------------------------- #ifndef __CMT2300A_H__ @@ -282,7 +282,6 @@ class Cmt2300a { mSpi.writeReg(CMT2300A_CUS_INT_CLR1, 0x00); mSpi.writeReg(CMT2300A_CUS_INT_CLR2, 0x00); - //mSpi.readReg(CMT2300A_CUS_FIFO_CTL); // necessary? mSpi.writeReg(CMT2300A_CUS_FIFO_CTL, 0x07); mSpi.writeReg(CMT2300A_CUS_FIFO_CLR, 0x01); @@ -294,8 +293,8 @@ class Cmt2300a { if(0xff != mRqstCh) { mCurCh = mRqstCh; mRqstCh = 0xff; + mSpi.writeReg(CMT2300A_CUS_FREQ_CHNL, mCurCh); } - mSpi.writeReg(CMT2300A_CUS_FREQ_CHNL, mCurCh); if(!cmtSwitchStatus(CMT2300A_GO_TX, CMT2300A_STA_TX)) return CMT_ERR_SWITCH_STATE; @@ -381,12 +380,13 @@ class Cmt2300a { inline void switchChannel(uint8_t ch) { mRqstCh = ch; - /*DPRINTLN(DBG_INFO, "switchChannel: 0x" + String(ch, HEX)); - if(mInRxMode) - mInRxMode = false; - cmtSwitchStatus(CMT2300A_GO_STBY, CMT2300A_STA_SLEEP); + } - mSpi.writeReg(CMT2300A_CUS_FREQ_CHNL, ch);*/ + inline uint32_t getFreqKhz(void) { + if(0xff != mRqstCh) + return HOY_BASE_FREQ_KHZ + (mRqstCh * FREQ_STEP_KHZ); + else + return HOY_BASE_FREQ_KHZ + (mCurCh * FREQ_STEP_KHZ); } private: diff --git a/src/hms/hmsPayload.h b/src/hms/hmsPayload.h index bd87f181..ec2c492c 100644 --- a/src/hms/hmsPayload.h +++ b/src/hms/hmsPayload.h @@ -1,6 +1,6 @@ //----------------------------------------------------------------------------- // 2023 Ahoy, https://ahoydtu.de -// Creative Commons - http://creativecommons.org/licenses/by-nc-sa/3.0/de/ +// Creative Commons - https://creativecommons.org/licenses/by-nc-sa/4.0/deed //----------------------------------------------------------------------------- #ifndef __HMS_PAYLOAD_H__ @@ -47,12 +47,13 @@ class HmsPayload { mTimestamp = timestamp; for(uint8_t i = 0; i < MAX_NUM_INVERTERS; i++) { reset(i); + mIvCmd56Cnt[i] = 0; } mSerialDebug = false; //mHighPrioIv = NULL; mCbAlarm = NULL; mCbPayload = NULL; - mLastRx = 0; + //mLastRx = 0; } void enableSerialDebug(bool enable) { @@ -139,13 +140,17 @@ class HmsPayload { mRadio->prepareDevInformCmd(iv->radioId.u64, cmd, mPayload[iv->id].ts, iv->alarmMesIndex, false); mPayload[iv->id].txCmd = cmd; }*/ + record_t<> *rec = iv->getRecordStruct(RealTimeRunData_Debug); DPRINT(DBG_INFO, "LastRx: "); - DBGPRINTLN(String(mLastRx)); - if((mLastRx + HMS_TIMEOUT_MS) < millis()) { + DBGPRINTLN(String(rec->ts)); + if(((rec->ts + HMS_TIMEOUT_MS) < millis()) && (mIvCmd56Cnt[iv->id] < 3)) { //mRadio->switchFrequency(&iv->radioId.u64, 863000, WORK_FREQ_KHZ); mRadio->switchFrequency(&iv->radioId.u64, HOY_BOOT_FREQ_KHZ, WORK_FREQ_KHZ); - mLastRx = millis() - (HMS_TIMEOUT_MS / 6); + mIvCmd56Cnt[iv->id]++; + //mLastRx = millis() - (HMS_TIMEOUT_MS / 6); } else { + if(++mIvCmd56Cnt[iv->id] == 10) + mIvCmd56Cnt[iv->id] = 0; uint8_t cmd = iv->getQueuedCmd(); DPRINT(DBG_INFO, F("(#")); DBGPRINT(String(iv->id)); @@ -156,7 +161,7 @@ class HmsPayload { } void add(Inverter<> *iv, hmsPacket_t *p) { - mLastRx = millis(); + //mLastRx = millis(); if (p->data[1] == (TX_REQ_INFO + ALL_FRAMES)) { // response from get information command mPayload[iv->id].txId = p->data[1]; DPRINTLN(DBG_DEBUG, F("Response from info request received")); @@ -404,8 +409,9 @@ class HmsPayload { statistics_t *mStat; uint8_t mMaxRetrans; uint32_t *mTimestamp; - uint32_t mLastRx; + //uint32_t mLastRx; hmsPayload_t mPayload[MAX_NUM_INVERTERS]; + uint8_t mIvCmd56Cnt[MAX_NUM_INVERTERS]; bool mSerialDebug; Inverter<> *mHighPrioIv; diff --git a/src/hms/hmsRadio.h b/src/hms/hmsRadio.h index 3c26263d..ae376758 100644 --- a/src/hms/hmsRadio.h +++ b/src/hms/hmsRadio.h @@ -1,6 +1,6 @@ //----------------------------------------------------------------------------- // 2023 Ahoy, https://github.com/lumpapu/ahoy -// Creative Commons - http://creativecommons.org/licenses/by-nc-sa/3.0/de/ +// Creative Commons - https://creativecommons.org/licenses/by-nc-sa/4.0/deed //----------------------------------------------------------------------------- #ifndef __HMS_RADIO_H__ @@ -95,8 +95,8 @@ class CmtRadio { if(mSerialDebug) { DPRINT(DBG_INFO, F("TX ")); - DBGPRINT(String(len)); - DBGPRINT(F(" | ")); + DBGPRINT(String(mCmt.getFreqKhz()/1000.0f)); + DBGPRINT(F("Mhz | ")); ah::dumpBuf(mTxBuf, len); } @@ -135,11 +135,13 @@ class CmtRadio { inline void sendSwitchChCmd(const uint64_t *ivId, uint8_t ch) { /** ch: - * 0x0c: 863.00 MHz - * 0x0d: 863.24 MHz - * 0x0e: 863.48 MHz - * 0x0f: 863.72 MHz - * 0x10: 863.96 MHz + * 0x00: 860.00 MHz + * 0x01: 860.25 MHz + * 0x02: 860.50 MHz + * ... + * 0x14: 865.00 MHz + * ... + * 0x28: 870.00 MHz * */ initPacket(ivId, 0x56, 0x02); mTxBuf[10] = 0x15; diff --git a/src/web/html/setup.html b/src/web/html/setup.html index 8d47abc6..13de33e6 100644 --- a/src/web/html/setup.html +++ b/src/web/html/setup.html @@ -629,7 +629,19 @@ } function parseNrfRadio(obj, type) { - var e = document.getElementById("rf24").append( + var e = document.getElementById("rf24"); + pins = [['cs', 'pinCs'], ['ce', 'pinCe'], ['irq', 'pinIrq']]; + for(p of pins) { + e.append( + ml("div", {class: "row mb-3"}, [ + ml("div", {class: "col-12 col-sm-3 my-2"}, p[0].toUpperCase()), + ml("div", {class: "col-12 col-sm-9"}, + sel(p[1], ("ESP8266" == type) ? esp8266pins : esp32pins, obj[p[0]]) + ) + ]) + ); + } + e.append( ml("div", {class: "row mb-3"}, [ ml("div", {class: "col-12 col-sm-3 my-2"}, "Power Level"), ml("div", {class: "col-12 col-sm-9"}, @@ -650,14 +662,20 @@ en.checked = obj["en"]; e.append( - lbl("cmtEnable", "CMT2300A Enable"), - en, br() + ml("div", {class: "row mb-3"}, [ + ml("div", {class: "col-8 col-sm-3 my-2"}, "CMT2300A Enable"), + ml("div", {class: "col-4 col-sm-9"}, en) + ]) ); pins = [['csb', 'pinCsb'], ['fcsb', 'pinFcsb'], ['irq', 'pinGpio3']]; for(p of pins) { e.append( - lbl(p[1], p[0].toUpperCase()), - sel(p[1], ("ESP8266" == type) ? esp8266pins : esp32pins, obj[p[0]]) + ml("div", {class: "row mb-3"}, [ + ml("div", {class: "col-12 col-sm-3 my-2"}, p[0].toUpperCase()), + ml("div", {class: "col-12 col-sm-9"}, + sel(p[1], ("ESP8266" == type) ? esp8266pins : esp32pins, obj[p[0]]) + ) + ]) ); } }