improved hmSystem

This commit is contained in:
lumapu 2023-09-30 01:05:34 +02:00
parent 1d28387d1d
commit 9b22b1017a
3 changed files with 53 additions and 57 deletions

View file

@ -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);

View file

@ -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

View file

@ -7,24 +7,73 @@
#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;
mInverter[0].generalConfig = config;
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) {
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;
}
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: iv->type = INV_TYPE_1CH;
break;
case 0x44: // HMS-1000
case 0x42:
case 0x41: iv->type = INV_TYPE_2CH;
break;
case 0x64: // HMS-2000
case 0x62:
case 0x61: iv->type = INV_TYPE_4CH;
break;
default:
DPRINTLN(DBG_ERROR, F("unknown inverter type"));
break;
}
if(iv->config->serial.b[5] == 0x11) {
if((iv->config->serial.b[4] & 0x0f) == 0x04)
iv->ivGen = IV_HMS;
else
iv->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
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;
}
iv->init();
mNumInv ++;
DPRINT(DBG_INFO, "added inverter ");
if(iv->config->serial.b[5] == 0x11) {
if((iv->config->serial.b[4] & 0x0f) == 0x04)
@ -41,64 +90,6 @@ class HmSystem {
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) {
DPRINTLN(DBG_VERBOSE, F("hmSystem.h:addInverter"));
if(MAX_INVERTER <= mNumInv) {
DPRINT(DBG_WARN, F("max number of inverters reached!"));
return NULL;
}
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]) {
case 0x24: // HMS-500
case 0x22:
case 0x21: p->type = INV_TYPE_1CH;
break;
case 0x44: // HMS-1000
case 0x42:
case 0x41: p->type = INV_TYPE_2CH;
break;
case 0x64: // HMS-2000
case 0x62:
case 0x61: p->type = INV_TYPE_4CH;
break;
default:
DPRINTLN(DBG_ERROR, F("unknown inverter type"));
break;
}
if(p->config->serial.b[5] == 0x11) {
if((p->config->serial.b[4] & 0x0f) == 0x04)
p->ivGen = IV_HMS;
else
p->ivGen = IV_HM;
}
else if((p->config->serial.b[4] & 0x03) == 0x02) // MI 3rd Gen -> same as HM
p->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)
DPRINTLN(DBG_ERROR, F("inverter type can't be detected!"));
p->init();
mNumInv ++;
return p;
}
INVERTERTYPE *findInverter(uint8_t buf[]) {
DPRINTLN(DBG_VERBOSE, F("hmSystem.h:findInverter"));