From f06e56c14fbbda986424b79826b986889e96cab8 Mon Sep 17 00:00:00 2001 From: lumapu Date: Thu, 3 Oct 2024 17:06:12 +0200 Subject: [PATCH] 0.8.151 * add button for CMT inverters to catch them independend on which frequency they were before #1749 --- src/CHANGES.md | 1 + src/app.h | 23 +++++++++++++++++++++++ src/appInterface.h | 2 ++ src/hm/Radio.h | 1 + src/hms/CmtRadio.h | 37 +++++++++++++++++++++++++++++++------ src/hms/cmt2300a.h | 4 ++++ src/web/RestApi.h | 5 +++++ src/web/html/setup.html | 13 ++++++++++++- src/web/lang.json | 10 ++++++++++ 9 files changed, 89 insertions(+), 7 deletions(-) diff --git a/src/CHANGES.md b/src/CHANGES.md index c3918c4d..c2e50d58 100644 --- a/src/CHANGES.md +++ b/src/CHANGES.md @@ -2,6 +2,7 @@ ## 0.8.151 - 2024-10-03 * don't interrupt current command by setting a new limit #1757 +* add button for CMT inverters to catch them independend on which frequency they were before #1749 ## 0.8.150 - 2024-10-02 * fix nullptr exception diff --git a/src/app.h b/src/app.h index d954df35..58101a59 100644 --- a/src/app.h +++ b/src/app.h @@ -291,6 +291,29 @@ class app : public IApp, public ah::Scheduler { return mConfig->cmt.enabled; } + bool cmtSearch(uint8_t id, uint8_t toCh) override { + #if defined(ESP32) + Inverter<> *iv; + + for(uint8_t i = 0; i < MAX_NUM_INVERTERS; i++) { + iv = mSys.getInverterByPos(i, true); + if(nullptr != iv) { + if(i == id) + break; + else + iv = nullptr; + } + } + + if(nullptr != iv) { + mCmtRadio.catchInverter(iv, toCh); + return true; + } + #endif + + return false; + } + uint8_t getNrfIrqPin(void) { return mConfig->nrf.pinIrq; } diff --git a/src/appInterface.h b/src/appInterface.h index ca0fc172..e03bc84f 100644 --- a/src/appInterface.h +++ b/src/appInterface.h @@ -56,6 +56,8 @@ class IApp { virtual bool getNrfEnabled() = 0; virtual bool getCmtEnabled() = 0; + virtual bool cmtSearch(uint8_t id, uint8_t toCh) = 0; + virtual uint32_t getMqttRxCnt() = 0; virtual uint32_t getMqttTxCnt() = 0; diff --git a/src/hm/Radio.h b/src/hm/Radio.h index 12e80850..f6a9b8d3 100644 --- a/src/hm/Radio.h +++ b/src/hm/Radio.h @@ -29,6 +29,7 @@ class Radio { virtual void sendControlPacket(Inverter<> *iv, uint8_t cmd, uint16_t *data, bool isRetransmit) = 0; virtual bool switchFrequency(Inverter<> *iv, uint32_t fromkHz, uint32_t tokHz) { return true; } virtual bool switchFrequencyCh(Inverter<> *iv, uint8_t fromCh, uint8_t toCh) { return true; } + virtual void catchInverter(Inverter<> *iv, uint8_t toCh) {} virtual bool isChipConnected(void) const { return false; } virtual uint16_t getBaseFreqMhz() { return 0; } virtual uint16_t getBootFreqMhz() { return 0; } diff --git a/src/hms/CmtRadio.h b/src/hms/CmtRadio.h index fd49e8f8..a5684a36 100644 --- a/src/hms/CmtRadio.h +++ b/src/hms/CmtRadio.h @@ -35,6 +35,11 @@ class CmtRadio : public Radio { return; mCmt.loop(); + if(nullptr != mCatchIv) { + if(mCmt.isTxReady()) + catchInverterLoop(); + } + if((!mIrqRcvd) && (!mRqstGetRx)) return; getRx(); @@ -93,6 +98,28 @@ class CmtRadio : public Radio { return true; } + void catchInverter(Inverter<> *iv, uint8_t toCh) override { + if(!isChipConnected()) + return; + + mCatchIv = iv; + mCatchIvCh = 1; + mCatchIvToCh = toCh; + + mCmt.switchChannel(0); + sendSwitchChCmd(iv, toCh); + } + + void catchInverterLoop() { + mCmt.switchChannel(mCatchIvCh); + sendSwitchChCmd(mCatchIv, mCatchIvToCh); + + if(++mCatchIvCh == 0x29) { + mCmt.switchChannel(mCatchIvToCh); + mCatchIv = nullptr; + } + } + uint16_t getBaseFreqMhz(void) override { return mCmt.getBaseFreqMhz(); } @@ -168,10 +195,6 @@ class CmtRadio : public Radio { } inline void sendSwitchChCmd(Inverter<> *iv, uint8_t ch) { - //if(CMT_SWITCH_CHANNEL_CYCLE > ++mSwitchCycle) - // return; - //mSwitchCycle = 0; - /** ch: * 0x00: 860.00 MHz * 0x01: 860.25 MHz @@ -194,7 +217,6 @@ class CmtRadio : public Radio { packet_t p; p.millis = millis() - mMillis; if(CmtStatus::SUCCESS == mCmt.getRx(p.packet, &p.len, 28, &p.rssi)) { - //mSwitchCycle = 0; p.ch = 0; // not used for CMT inverters mBufCtrl.push(p); } @@ -210,7 +232,10 @@ class CmtRadio : public Radio { bool mCmtAvail = false; bool mRqstGetRx = false; uint32_t mMillis = 0; - //uint8_t mSwitchCycle = 0; + + Inverter<> *mCatchIv = nullptr; + uint8_t mCatchIvCh = 0; + uint8_t mCatchIvToCh = 0; }; #endif /*__HMS_RADIO_H__*/ diff --git a/src/hms/cmt2300a.h b/src/hms/cmt2300a.h index ed3aab54..626d3e79 100644 --- a/src/hms/cmt2300a.h +++ b/src/hms/cmt2300a.h @@ -188,6 +188,10 @@ class Cmt2300a { } } + bool isTxReady() { + return !mTxPending; + } + CmtStatus goRx(void) { if(mTxPending) return CmtStatus::ERR_TX_PENDING; diff --git a/src/web/RestApi.h b/src/web/RestApi.h index 099dc13b..c6859386 100644 --- a/src/web/RestApi.h +++ b/src/web/RestApi.h @@ -1131,6 +1131,11 @@ class RestApi { iv->setDevCommand(jsonIn[F("val")].as()); } else if(F("restart_ahoy") == jsonIn[F("cmd")]) { mApp->setRebootFlag(); + } else if(F("cmt_search") == jsonIn[F("cmd")]) { + if(!mApp->cmtSearch(jsonIn[F("id")], jsonIn[F("to_ch")])) { + jsonOut[F("error")] = F("ERR_INVERTER_NOT_FOUND"); + return false; + } } else { jsonOut[F("error")] = F("ERR_UNKNOWN_CMD"); return false; diff --git a/src/web/html/setup.html b/src/web/html/setup.html index 4d99331e..ef9e06f5 100644 --- a/src/web/html/setup.html +++ b/src/web/html/setup.html @@ -817,7 +817,8 @@ ml("input", {type: "hidden", name: "isnrf"}, null), ml("div", {id: "setcmt"}, [ divRow("{#INV_FREQUENCY}", sel("freq", esp32cmtFreq, obj.freq)), - divRow("{#INV_POWER_LEVEL}", sel("cmtpa", esp32cmtPa, obj.pa)) + divRow("{#INV_POWER_LEVEL}", sel("cmtpa", esp32cmtPa, obj.pa)), + divRow("{#INV_SEARCH}", ml("input", {type: "button", value: "{#BTN_SEARCH}", class: "btn", onclick: function() { cmtSearch(); }}, null)) ]), ml("div", {id: "setnrf"}, divRow("{#INV_POWER_LEVEL}", sel("nrfpa", nrfPa, obj.pa)) @@ -902,6 +903,16 @@ getAjax("/api/setup", cb, "POST", JSON.stringify(o)); } + function cmtSearch() { + var o = {} + o.cmd = "cmt_search" + o.token = "*" + o.id = obj.id + o.to_ch = document.getElementsByName("freq")[0].value; + + getAjax("/api/ctrl", cb, "POST", JSON.stringify(o)); + } + function convHerf(sn) { let sn_int = 0n; const CHARS = "0123456789ABCDEFGHJKLMNPRSTUVWXY"; diff --git a/src/web/lang.json b/src/web/lang.json index 2cf9139d..a1f15451 100644 --- a/src/web/lang.json +++ b/src/web/lang.json @@ -698,6 +698,16 @@ "en": "Pause communication during night (lat. and lon. need to be set)", "de": "Kommunikation während der Nacht pausieren (Breiten- und Längengrad müssen gesetzt sein" }, + { + "token": "INV_SEARCH", + "en": "Catch Inverter", + "de": "Wechselrichter suchen" + }, + { + "token": "BTN_SEARCH", + "en": "start", + "de": "starten" + }, { "token": "BTN_SAVE", "en": "save",