From af4960f1c4816b74ec301a61c0076f4649dae680 Mon Sep 17 00:00:00 2001 From: lumapu Date: Sat, 30 Apr 2022 02:02:41 +0200 Subject: [PATCH] * fixed issues (found during unit test) --- tools/esp8266/debug.h | 2 -- tools/esp8266/hmDefines.h | 8 ++++---- tools/esp8266/hmInverter.h | 35 ++++++++++++++++++++++------------- tools/esp8266/hmSystem.h | 5 ++++- 4 files changed, 30 insertions(+), 20 deletions(-) diff --git a/tools/esp8266/debug.h b/tools/esp8266/debug.h index 26bf1d89..2699b943 100644 --- a/tools/esp8266/debug.h +++ b/tools/esp8266/debug.h @@ -1,8 +1,6 @@ #ifndef __DEBUG_H__ #define __DEBUG_H__ -#include "Arduino.h" - #ifdef NDEBUG #define DPRINT(str) #define DPRINTLN(str) diff --git a/tools/esp8266/hmDefines.h b/tools/esp8266/hmDefines.h index 169a8d09..e66d6fce 100644 --- a/tools/esp8266/hmDefines.h +++ b/tools/esp8266/hmDefines.h @@ -145,10 +145,10 @@ const byteAssign_t hm1200assignment[] = { { FLD_F, UNIT_HZ, CH0, CMD84, 1, 2, 100 }, { FLD_PCT, UNIT_PCT, CH0, CMD84, 9, 2, 10 }, { FLD_T, UNIT_C, CH0, CMD84, 11, 2, 10 }, - { FLD_YT, UNIT_KWH, CH0, CMDFF, CALC_YT_CH0, 0, 1000 }, - { FLD_YD, UNIT_KWH, CH0, CMDFF, CALC_YD_CH0, 0, 1 }, - { FLD_UDC, UNIT_KWH, CH2, CMDFF, CALC_UDC_CH, CH1, 1000 }, - { FLD_UDC, UNIT_KWH, CH4, CMDFF, CALC_UDC_CH, CH3, 1000 } + { FLD_YT, UNIT_KWH, CH0, CMDFF, CALC_YT_CH0, 0, 0 }, + { FLD_YD, UNIT_KWH, CH0, CMDFF, CALC_YD_CH0, 0, 0 }, + { FLD_UDC, UNIT_V, CH2, CMDFF, CALC_UDC_CH, CH1, 0 }, + { FLD_UDC, UNIT_V, CH4, CMDFF, CALC_UDC_CH, CH3, 0 } }; #define HM1200_LIST_LEN (sizeof(hm1200assignment) / sizeof(byteAssign_t)) diff --git a/tools/esp8266/hmInverter.h b/tools/esp8266/hmInverter.h index 06a307e6..f5e823e8 100644 --- a/tools/esp8266/hmInverter.h +++ b/tools/esp8266/hmInverter.h @@ -23,6 +23,9 @@ static T calcYieldTotalCh0(Inverter<> *iv, uint8_t arg0); template static T calcYieldDayCh0(Inverter<> *iv, uint8_t arg0); +template +static T calcUdcCh(Inverter<> *iv, uint8_t arg0); + template using func_t = T (Inverter<> *, uint8_t); @@ -37,7 +40,8 @@ struct calcFunc_t { template const calcFunc_t calcFunctions[] = { { CALC_YT_CH0, &calcYieldTotalCh0 }, - { CALC_YD_CH0, &calcYieldDayCh0 } + { CALC_YD_CH0, &calcYieldDayCh0 }, + { CALC_UDC_CH, &calcUdcCh } }; @@ -55,16 +59,21 @@ class Inverter { RECORDTYPE *record; // pointer for values Inverter() { - getAssignment(); - toRadioId(); - record = new RECORDTYPE[listLen]; - memset(record, 0, sizeof(RECORDTYPE) * listLen); + } ~Inverter() { // TODO: cleanup } + void init(void) { + getAssignment(); + toRadioId(); + record = new RECORDTYPE[listLen]; + memset(name, 0, MAX_NAME_LENGTH); + memset(record, 0, sizeof(RECORDTYPE) * listLen); + } + uint8_t getPosByChFld(uint8_t channel, uint8_t fieldId) { uint8_t pos = 0; for(; pos < listLen; pos++) { @@ -108,6 +117,14 @@ class Inverter { return record[pos]; } + void doCalculations(void) { + for(uint8_t i = 0; i < listLen; i++) { + if(CMDFF == assign[i].cmdId) { + record[i] = calcFunctions[assign[i].start].func(this, assign[i].num); + } + } + } + private: void toRadioId(void) { radioId.u64 = 0ULL; @@ -145,14 +162,6 @@ class Inverter { assign = NULL; } } - - void doCalculations(void) { - for(uint8_t i = 0; i < listLen; i++) { - if(CMDFF == assign[i].cmdId) { - calcFunctions[assign[i].start].func(this, assign[i].num); - } - } - } }; diff --git a/tools/esp8266/hmSystem.h b/tools/esp8266/hmSystem.h index 62a76cc3..c418fb08 100644 --- a/tools/esp8266/hmSystem.h +++ b/tools/esp8266/hmSystem.h @@ -2,7 +2,9 @@ #define __HM_SYSTEM_H__ #include "hmInverter.h" +#ifndef NO_RADIO #include "hmRadio.h" +#endif @@ -34,7 +36,8 @@ class HmSystem { p->id = mNumInv; p->serial.u64 = serial; p->type = type; - uint8_t len = strlen(name); + p->init(); + uint8_t len = (uint8_t)strlen(name); strncpy(p->name, name, (len > MAX_NAME_LENGTH) ? MAX_NAME_LENGTH : len); if(NULL == p->assign) {