|
|
@ -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[]) { |
|
|
|