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 /* defined(ETHERNET) */
mSys.setup(&mTimestamp);
mSys.addInverters(&mConfig->inst);
mSys.setup(&mTimestamp, &mConfig->inst);
Inverter<> *iv;
for (uint8_t i = 0; i < MAX_NUM_INVERTERS; i++) {
mSys.addInverter(i);
}
if (mConfig->nrf.enabled) {
mPayload.setup(this, &mSys, &mNrfRadio, &mNrfStat, mConfig->nrf.maxRetransPerPyld, &mTimestamp);
mPayload.enableSerialDebug(mConfig->serial.debug);

4
src/hm/hmInverter.h

@ -17,6 +17,7 @@
#include <queue>
#include "../config/settings.h"
#include "radio.h"
/**
* For values which are of interest and not transmitted by the inverter can be
* calculated automatically.
@ -152,7 +153,8 @@ class Inverter {
uint8_t alarmNxtWrPos; // indicates the position in array (rolling buffer)
uint16_t alarmCnt; // counts the total number of occurred alarms
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

99
src/hm/hmSystem.h

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

Loading…
Cancel
Save