Browse Source

improved hmSystem

pull/1197/head
lumapu 2 years ago
parent
commit
9b22b1017a
  1. 7
      src/app.cpp
  2. 4
      src/hm/hmInverter.h
  3. 99
      src/hm/hmSystem.h

7
src/app.cpp

@ -59,8 +59,11 @@ void app::setup() {
#endif #endif
#endif /* defined(ETHERNET) */ #endif /* defined(ETHERNET) */
mSys.setup(&mTimestamp); mSys.setup(&mTimestamp, &mConfig->inst);
mSys.addInverters(&mConfig->inst); Inverter<> *iv;
for (uint8_t i = 0; i < MAX_NUM_INVERTERS; i++) {
mSys.addInverter(i);
}
if (mConfig->nrf.enabled) { if (mConfig->nrf.enabled) {
mPayload.setup(this, &mSys, &mNrfRadio, &mNrfStat, mConfig->nrf.maxRetransPerPyld, &mTimestamp); mPayload.setup(this, &mSys, &mNrfRadio, &mNrfStat, mConfig->nrf.maxRetransPerPyld, &mTimestamp);
mPayload.enableSerialDebug(mConfig->serial.debug); mPayload.enableSerialDebug(mConfig->serial.debug);

4
src/hm/hmInverter.h

@ -17,6 +17,7 @@
#include <queue> #include <queue>
#include "../config/settings.h" #include "../config/settings.h"
#include "radio.h"
/** /**
* For values which are of interest and not transmitted by the inverter can be * For values which are of interest and not transmitted by the inverter can be
* calculated automatically. * calculated automatically.
@ -152,7 +153,8 @@ class Inverter {
uint8_t alarmNxtWrPos; // indicates the position in array (rolling buffer) uint8_t alarmNxtWrPos; // indicates the position in array (rolling buffer)
uint16_t alarmCnt; // counts the total number of occurred alarms uint16_t alarmCnt; // counts the total number of occurred alarms
uint16_t alarmLastId; // lastId which was received uint16_t alarmLastId; // lastId which was received
int8_t rssi; // HMS and HMT inverters only int8_t rssi; // RSSI
Radio *radio; // pointer to associated radio class
static uint32_t *timestamp; // system timestamp static uint32_t *timestamp; // system timestamp

99
src/hm/hmSystem.h

@ -7,70 +7,45 @@
#define __HM_SYSTEM_H__ #define __HM_SYSTEM_H__
#include "hmInverter.h" #include "hmInverter.h"
#include <functional>
template <uint8_t MAX_INVERTER=3, class INVERTERTYPE=Inverter<float>> template <uint8_t MAX_INVERTER=3, class INVERTERTYPE=Inverter<float>>
class HmSystem { class HmSystem {
public: public:
HmSystem() {} HmSystem() {}
void setup(uint32_t *timestamp) { void setup(uint32_t *timestamp, cfgInst_t *config) {
mInverter[0].timestamp = timestamp; mInverter[0].timestamp = timestamp;
mNumInv = 0;
}
void addInverters(cfgInst_t *config) {
mInverter[0].generalConfig = config; mInverter[0].generalConfig = config;
Inverter<> *iv; mNumInv = 0;
for (uint8_t i = 0; i < MAX_NUM_INVERTERS; i++) {
iv = addInverter(&config->iv[i]);
if (0ULL != config->iv[i].serial.u64) {
if (NULL != iv) {
DPRINT(DBG_INFO, "added inverter ");
if(iv->config->serial.b[5] == 0x11) {
if((iv->config->serial.b[4] & 0x0f) == 0x04)
DBGPRINT("HMS");
else
DBGPRINT("HM");
} else if(iv->config->serial.b[5] == 0x13)
DBGPRINT("HMT");
else
DBGPRINT(((iv->config->serial.b[4] & 0x03) == 0x01) ? " (2nd Gen) " : " (3rd Gen) ");
DBGPRINTLN(String(iv->config->serial.u64, HEX));
if((iv->config->serial.b[5] == 0x10) && ((iv->config->serial.b[4] & 0x03) == 0x01))
DPRINTLN(DBG_WARN, F("MI Inverter are not fully supported now!!!"));
}
}
}
} }
INVERTERTYPE *addInverter(cfgIv_t *config) { void addInverter(uint8_t id) {
DPRINTLN(DBG_VERBOSE, F("hmSystem.h:addInverter")); DPRINTLN(DBG_VERBOSE, F("hmSystem.h:addInverter"));
if(MAX_INVERTER <= mNumInv) { if(MAX_INVERTER <= mNumInv) {
DPRINT(DBG_WARN, F("max number of inverters reached!")); DPRINT(DBG_WARN, F("max number of inverters reached!"));
return NULL; return;
} }
INVERTERTYPE *p = &mInverter[mNumInv]; INVERTERTYPE *iv = &mInverter[mNumInv];
p->id = mNumInv; iv->id = mNumInv;
p->config = config; iv->config = &mInverter[0].generalConfig->iv[id];
DPRINT(DBG_VERBOSE, "SERIAL: " + String(p->config->serial.b[5], HEX)); DPRINT(DBG_VERBOSE, "SERIAL: " + String(iv->config->serial.b[5], HEX));
DPRINTLN(DBG_VERBOSE, " " + String(p->config->serial.b[4], HEX)); DPRINTLN(DBG_VERBOSE, " " + String(iv->config->serial.b[4], HEX));
if((p->config->serial.b[5] == 0x11) || (p->config->serial.b[5] == 0x10)) { if((iv->config->serial.b[5] == 0x11) || (iv->config->serial.b[5] == 0x10)) {
switch(p->config->serial.b[4]) { switch(iv->config->serial.b[4]) {
case 0x24: // HMS-500 case 0x24: // HMS-500
case 0x22: case 0x22:
case 0x21: p->type = INV_TYPE_1CH; case 0x21: iv->type = INV_TYPE_1CH;
break; break;
case 0x44: // HMS-1000 case 0x44: // HMS-1000
case 0x42: case 0x42:
case 0x41: p->type = INV_TYPE_2CH; case 0x41: iv->type = INV_TYPE_2CH;
break; break;
case 0x64: // HMS-2000 case 0x64: // HMS-2000
case 0x62: case 0x62:
case 0x61: p->type = INV_TYPE_4CH; case 0x61: iv->type = INV_TYPE_4CH;
break; break;
default: default:
@ -78,26 +53,42 @@ class HmSystem {
break; break;
} }
if(p->config->serial.b[5] == 0x11) { if(iv->config->serial.b[5] == 0x11) {
if((p->config->serial.b[4] & 0x0f) == 0x04) if((iv->config->serial.b[4] & 0x0f) == 0x04)
p->ivGen = IV_HMS; iv->ivGen = IV_HMS;
else else
p->ivGen = IV_HM; iv->ivGen = IV_HM;
} }
else if((p->config->serial.b[4] & 0x03) == 0x02) // MI 3rd Gen -> same as HM else if((iv->config->serial.b[4] & 0x03) == 0x02) // MI 3rd Gen -> same as HM
p->ivGen = IV_HM; iv->ivGen = IV_HM;
else // MI 2nd Gen else // MI 2nd Gen
p->ivGen = IV_MI; iv->ivGen = IV_MI;
} else if(p->config->serial.b[5] == 0x13) { } else if(iv->config->serial.b[5] == 0x13) {
p->ivGen = IV_HMT; iv->ivGen = IV_HMT;
p->type = INV_TYPE_6CH; iv->type = INV_TYPE_6CH;
} else if(p->config->serial.u64 != 0ULL) } else if(iv->config->serial.u64 != 0ULL) {
DPRINTLN(DBG_ERROR, F("inverter type can't be detected!")); DPRINTLN(DBG_ERROR, F("inverter type can't be detected!"));
return;
}
p->init(); iv->init();
mNumInv ++; mNumInv ++;
return p;
DPRINT(DBG_INFO, "added inverter ");
if(iv->config->serial.b[5] == 0x11) {
if((iv->config->serial.b[4] & 0x0f) == 0x04)
DBGPRINT("HMS");
else
DBGPRINT("HM");
} else if(iv->config->serial.b[5] == 0x13)
DBGPRINT("HMT");
else
DBGPRINT(((iv->config->serial.b[4] & 0x03) == 0x01) ? " (2nd Gen) " : " (3rd Gen) ");
DBGPRINTLN(String(iv->config->serial.u64, HEX));
if((iv->config->serial.b[5] == 0x10) && ((iv->config->serial.b[4] & 0x03) == 0x01))
DPRINTLN(DBG_WARN, F("MI Inverter are not fully supported now!!!"));
} }
INVERTERTYPE *findInverter(uint8_t buf[]) { INVERTERTYPE *findInverter(uint8_t buf[]) {

Loading…
Cancel
Save