Skip to content

Commit

Permalink
0.8.151
Browse files Browse the repository at this point in the history
* add button for CMT inverters to catch them independend on which frequency they were before #1749
  • Loading branch information
lumapu committed Oct 3, 2024
1 parent 28b303c commit f06e56c
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions src/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 2 additions & 0 deletions src/appInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
1 change: 1 addition & 0 deletions src/hm/Radio.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
37 changes: 31 additions & 6 deletions src/hms/CmtRadio.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ class CmtRadio : public Radio {
return;

mCmt.loop();
if(nullptr != mCatchIv) {
if(mCmt.isTxReady())
catchInverterLoop();
}

if((!mIrqRcvd) && (!mRqstGetRx))
return;
getRx();
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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
Expand All @@ -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);
}
Expand All @@ -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__*/
4 changes: 4 additions & 0 deletions src/hms/cmt2300a.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@ class Cmt2300a {
}
}

bool isTxReady() {
return !mTxPending;
}

CmtStatus goRx(void) {
if(mTxPending)
return CmtStatus::ERR_TX_PENDING;
Expand Down
5 changes: 5 additions & 0 deletions src/web/RestApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -1131,6 +1131,11 @@ class RestApi {
iv->setDevCommand(jsonIn[F("val")].as<int>());
} 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;
Expand Down
13 changes: 12 additions & 1 deletion src/web/html/setup.html
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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";
Expand Down
10 changes: 10 additions & 0 deletions src/web/lang.json
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,16 @@
"en": "Pause communication during night (lat. and lon. need to be set)",
"de": "Kommunikation w&auml;hrend der Nacht pausieren (Breiten- und L&auml;ngengrad m&uuml;ssen gesetzt sein"
},
{
"token": "INV_SEARCH",
"en": "Catch Inverter",
"de": "Wechselrichter suchen"
},
{
"token": "BTN_SEARCH",
"en": "start",
"de": "starten"
},
{
"token": "BTN_SAVE",
"en": "save",
Expand Down

0 comments on commit f06e56c

Please sign in to comment.