Browse Source

improved multi inverter

fixed setup
improved serial output
pull/935/head
lumapu 2 years ago
parent
commit
23e848d224
  1. 2
      src/hm/hmInverter.h
  2. 16
      src/hms/cmt2300a.h
  3. 20
      src/hms/hmsPayload.h
  4. 18
      src/hms/hmsRadio.h
  5. 28
      src/web/html/setup.html

2
src/hm/hmInverter.h

@ -145,7 +145,7 @@ class Inverter {
void enqueCommand(uint8_t cmd) { void enqueCommand(uint8_t cmd) {
_commandQueue.push(std::make_shared<T>(cmd)); _commandQueue.push(std::make_shared<T>(cmd));
DPRINT_IVID(DBG_INFO, id); DPRINT_IVID(DBG_INFO, id);
DBGPRINTLN(F("enqueCommand: 0x")); DBGPRINT(F("enqueCommand: 0x"));
DBGHEXLN(cmd); DBGHEXLN(cmd);
} }

16
src/hms/cmt2300a.h

@ -1,6 +1,6 @@
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// 2023 Ahoy, https://github.com/lumpapu/ahoy // 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__ #ifndef __CMT2300A_H__
@ -282,7 +282,6 @@ class Cmt2300a {
mSpi.writeReg(CMT2300A_CUS_INT_CLR1, 0x00); mSpi.writeReg(CMT2300A_CUS_INT_CLR1, 0x00);
mSpi.writeReg(CMT2300A_CUS_INT_CLR2, 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_CTL, 0x07);
mSpi.writeReg(CMT2300A_CUS_FIFO_CLR, 0x01); mSpi.writeReg(CMT2300A_CUS_FIFO_CLR, 0x01);
@ -294,8 +293,8 @@ class Cmt2300a {
if(0xff != mRqstCh) { if(0xff != mRqstCh) {
mCurCh = mRqstCh; mCurCh = mRqstCh;
mRqstCh = 0xff; mRqstCh = 0xff;
mSpi.writeReg(CMT2300A_CUS_FREQ_CHNL, mCurCh);
} }
mSpi.writeReg(CMT2300A_CUS_FREQ_CHNL, mCurCh);
if(!cmtSwitchStatus(CMT2300A_GO_TX, CMT2300A_STA_TX)) if(!cmtSwitchStatus(CMT2300A_GO_TX, CMT2300A_STA_TX))
return CMT_ERR_SWITCH_STATE; return CMT_ERR_SWITCH_STATE;
@ -381,12 +380,13 @@ class Cmt2300a {
inline void switchChannel(uint8_t ch) { inline void switchChannel(uint8_t ch) {
mRqstCh = 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: private:

20
src/hms/hmsPayload.h

@ -1,6 +1,6 @@
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// 2023 Ahoy, https://ahoydtu.de // 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__ #ifndef __HMS_PAYLOAD_H__
@ -47,12 +47,13 @@ class HmsPayload {
mTimestamp = timestamp; mTimestamp = timestamp;
for(uint8_t i = 0; i < MAX_NUM_INVERTERS; i++) { for(uint8_t i = 0; i < MAX_NUM_INVERTERS; i++) {
reset(i); reset(i);
mIvCmd56Cnt[i] = 0;
} }
mSerialDebug = false; mSerialDebug = false;
//mHighPrioIv = NULL; //mHighPrioIv = NULL;
mCbAlarm = NULL; mCbAlarm = NULL;
mCbPayload = NULL; mCbPayload = NULL;
mLastRx = 0; //mLastRx = 0;
} }
void enableSerialDebug(bool enable) { void enableSerialDebug(bool enable) {
@ -139,13 +140,17 @@ class HmsPayload {
mRadio->prepareDevInformCmd(iv->radioId.u64, cmd, mPayload[iv->id].ts, iv->alarmMesIndex, false); mRadio->prepareDevInformCmd(iv->radioId.u64, cmd, mPayload[iv->id].ts, iv->alarmMesIndex, false);
mPayload[iv->id].txCmd = cmd; mPayload[iv->id].txCmd = cmd;
}*/ }*/
record_t<> *rec = iv->getRecordStruct(RealTimeRunData_Debug);
DPRINT(DBG_INFO, "LastRx: "); DPRINT(DBG_INFO, "LastRx: ");
DBGPRINTLN(String(mLastRx)); DBGPRINTLN(String(rec->ts));
if((mLastRx + HMS_TIMEOUT_MS) < millis()) { 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, 863000, WORK_FREQ_KHZ);
mRadio->switchFrequency(&iv->radioId.u64, HOY_BOOT_FREQ_KHZ, 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 { } else {
if(++mIvCmd56Cnt[iv->id] == 10)
mIvCmd56Cnt[iv->id] = 0;
uint8_t cmd = iv->getQueuedCmd(); uint8_t cmd = iv->getQueuedCmd();
DPRINT(DBG_INFO, F("(#")); DPRINT(DBG_INFO, F("(#"));
DBGPRINT(String(iv->id)); DBGPRINT(String(iv->id));
@ -156,7 +161,7 @@ class HmsPayload {
} }
void add(Inverter<> *iv, hmsPacket_t *p) { 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 if (p->data[1] == (TX_REQ_INFO + ALL_FRAMES)) { // response from get information command
mPayload[iv->id].txId = p->data[1]; mPayload[iv->id].txId = p->data[1];
DPRINTLN(DBG_DEBUG, F("Response from info request received")); DPRINTLN(DBG_DEBUG, F("Response from info request received"));
@ -404,8 +409,9 @@ class HmsPayload {
statistics_t *mStat; statistics_t *mStat;
uint8_t mMaxRetrans; uint8_t mMaxRetrans;
uint32_t *mTimestamp; uint32_t *mTimestamp;
uint32_t mLastRx; //uint32_t mLastRx;
hmsPayload_t mPayload[MAX_NUM_INVERTERS]; hmsPayload_t mPayload[MAX_NUM_INVERTERS];
uint8_t mIvCmd56Cnt[MAX_NUM_INVERTERS];
bool mSerialDebug; bool mSerialDebug;
Inverter<> *mHighPrioIv; Inverter<> *mHighPrioIv;

18
src/hms/hmsRadio.h

@ -1,6 +1,6 @@
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// 2023 Ahoy, https://github.com/lumpapu/ahoy // 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__ #ifndef __HMS_RADIO_H__
@ -95,8 +95,8 @@ class CmtRadio {
if(mSerialDebug) { if(mSerialDebug) {
DPRINT(DBG_INFO, F("TX ")); DPRINT(DBG_INFO, F("TX "));
DBGPRINT(String(len)); DBGPRINT(String(mCmt.getFreqKhz()/1000.0f));
DBGPRINT(F(" | ")); DBGPRINT(F("Mhz | "));
ah::dumpBuf(mTxBuf, len); ah::dumpBuf(mTxBuf, len);
} }
@ -135,11 +135,13 @@ class CmtRadio {
inline void sendSwitchChCmd(const uint64_t *ivId, uint8_t ch) { inline void sendSwitchChCmd(const uint64_t *ivId, uint8_t ch) {
/** ch: /** ch:
* 0x0c: 863.00 MHz * 0x00: 860.00 MHz
* 0x0d: 863.24 MHz * 0x01: 860.25 MHz
* 0x0e: 863.48 MHz * 0x02: 860.50 MHz
* 0x0f: 863.72 MHz * ...
* 0x10: 863.96 MHz * 0x14: 865.00 MHz
* ...
* 0x28: 870.00 MHz
* */ * */
initPacket(ivId, 0x56, 0x02); initPacket(ivId, 0x56, 0x02);
mTxBuf[10] = 0x15; mTxBuf[10] = 0x15;

28
src/web/html/setup.html

@ -629,7 +629,19 @@
} }
function parseNrfRadio(obj, type) { 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: "row mb-3"}, [
ml("div", {class: "col-12 col-sm-3 my-2"}, "Power Level"), ml("div", {class: "col-12 col-sm-3 my-2"}, "Power Level"),
ml("div", {class: "col-12 col-sm-9"}, ml("div", {class: "col-12 col-sm-9"},
@ -650,14 +662,20 @@
en.checked = obj["en"]; en.checked = obj["en"];
e.append( e.append(
lbl("cmtEnable", "CMT2300A Enable"), ml("div", {class: "row mb-3"}, [
en, br() 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']]; pins = [['csb', 'pinCsb'], ['fcsb', 'pinFcsb'], ['irq', 'pinGpio3']];
for(p of pins) { for(p of pins) {
e.append( e.append(
lbl(p[1], p[0].toUpperCase()), ml("div", {class: "row mb-3"}, [
sel(p[1], ("ESP8266" == type) ? esp8266pins : esp32pins, obj[p[0]]) 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]])
)
])
); );
} }
} }

Loading…
Cancel
Save