mirror of
https://github.com/lumapu/ahoy.git
synced 2025-05-28 16:26:12 +02:00
improved hmSystem
This commit is contained in:
parent
1d28387d1d
commit
9b22b1017a
3 changed files with 53 additions and 57 deletions
|
@ -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);
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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;
|
||||||
|
mInverter[0].generalConfig = config;
|
||||||
mNumInv = 0;
|
mNumInv = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void addInverters(cfgInst_t *config) {
|
void addInverter(uint8_t id) {
|
||||||
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!!!"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
INVERTERTYPE *addInverter(cfgIv_t *config) {
|
|
||||||
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…
Add table
Add a link
Reference in a new issue