Browse Source

* fixed issues (found during unit test)

pull/21/head
lumapu 3 years ago
parent
commit
af4960f1c4
  1. 2
      tools/esp8266/debug.h
  2. 8
      tools/esp8266/hmDefines.h
  3. 35
      tools/esp8266/hmInverter.h
  4. 5
      tools/esp8266/hmSystem.h

2
tools/esp8266/debug.h

@ -1,8 +1,6 @@
#ifndef __DEBUG_H__ #ifndef __DEBUG_H__
#define __DEBUG_H__ #define __DEBUG_H__
#include "Arduino.h"
#ifdef NDEBUG #ifdef NDEBUG
#define DPRINT(str) #define DPRINT(str)
#define DPRINTLN(str) #define DPRINTLN(str)

8
tools/esp8266/hmDefines.h

@ -145,10 +145,10 @@ const byteAssign_t hm1200assignment[] = {
{ FLD_F, UNIT_HZ, CH0, CMD84, 1, 2, 100 }, { FLD_F, UNIT_HZ, CH0, CMD84, 1, 2, 100 },
{ FLD_PCT, UNIT_PCT, CH0, CMD84, 9, 2, 10 }, { FLD_PCT, UNIT_PCT, CH0, CMD84, 9, 2, 10 },
{ FLD_T, UNIT_C, CH0, CMD84, 11, 2, 10 }, { FLD_T, UNIT_C, CH0, CMD84, 11, 2, 10 },
{ FLD_YT, UNIT_KWH, CH0, CMDFF, CALC_YT_CH0, 0, 1000 }, { FLD_YT, UNIT_KWH, CH0, CMDFF, CALC_YT_CH0, 0, 0 },
{ FLD_YD, UNIT_KWH, CH0, CMDFF, CALC_YD_CH0, 0, 1 }, { FLD_YD, UNIT_KWH, CH0, CMDFF, CALC_YD_CH0, 0, 0 },
{ FLD_UDC, UNIT_KWH, CH2, CMDFF, CALC_UDC_CH, CH1, 1000 }, { FLD_UDC, UNIT_V, CH2, CMDFF, CALC_UDC_CH, CH1, 0 },
{ FLD_UDC, UNIT_KWH, CH4, CMDFF, CALC_UDC_CH, CH3, 1000 } { FLD_UDC, UNIT_V, CH4, CMDFF, CALC_UDC_CH, CH3, 0 }
}; };
#define HM1200_LIST_LEN (sizeof(hm1200assignment) / sizeof(byteAssign_t)) #define HM1200_LIST_LEN (sizeof(hm1200assignment) / sizeof(byteAssign_t))

35
tools/esp8266/hmInverter.h

@ -23,6 +23,9 @@ static T calcYieldTotalCh0(Inverter<> *iv, uint8_t arg0);
template<class T=float> template<class T=float>
static T calcYieldDayCh0(Inverter<> *iv, uint8_t arg0); static T calcYieldDayCh0(Inverter<> *iv, uint8_t arg0);
template<class T=float>
static T calcUdcCh(Inverter<> *iv, uint8_t arg0);
template<class T=float> template<class T=float>
using func_t = T (Inverter<> *, uint8_t); using func_t = T (Inverter<> *, uint8_t);
@ -37,7 +40,8 @@ struct calcFunc_t {
template<class T=float> template<class T=float>
const calcFunc_t<T> calcFunctions[] = { const calcFunc_t<T> calcFunctions[] = {
{ CALC_YT_CH0, &calcYieldTotalCh0 }, { 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 RECORDTYPE *record; // pointer for values
Inverter() { Inverter() {
getAssignment();
toRadioId();
record = new RECORDTYPE[listLen];
memset(record, 0, sizeof(RECORDTYPE) * listLen);
} }
~Inverter() { ~Inverter() {
// TODO: cleanup // 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 getPosByChFld(uint8_t channel, uint8_t fieldId) {
uint8_t pos = 0; uint8_t pos = 0;
for(; pos < listLen; pos++) { for(; pos < listLen; pos++) {
@ -108,6 +117,14 @@ class Inverter {
return record[pos]; return record[pos];
} }
void doCalculations(void) {
for(uint8_t i = 0; i < listLen; i++) {
if(CMDFF == assign[i].cmdId) {
record[i] = calcFunctions<RECORDTYPE>[assign[i].start].func(this, assign[i].num);
}
}
}
private: private:
void toRadioId(void) { void toRadioId(void) {
radioId.u64 = 0ULL; radioId.u64 = 0ULL;
@ -145,14 +162,6 @@ class Inverter {
assign = NULL; assign = NULL;
} }
} }
void doCalculations(void) {
for(uint8_t i = 0; i < listLen; i++) {
if(CMDFF == assign[i].cmdId) {
calcFunctions<RECORDTYPE>[assign[i].start].func(this, assign[i].num);
}
}
}
}; };

5
tools/esp8266/hmSystem.h

@ -2,7 +2,9 @@
#define __HM_SYSTEM_H__ #define __HM_SYSTEM_H__
#include "hmInverter.h" #include "hmInverter.h"
#ifndef NO_RADIO
#include "hmRadio.h" #include "hmRadio.h"
#endif
@ -34,7 +36,8 @@ class HmSystem {
p->id = mNumInv; p->id = mNumInv;
p->serial.u64 = serial; p->serial.u64 = serial;
p->type = type; 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); strncpy(p->name, name, (len > MAX_NAME_LENGTH) ? MAX_NAME_LENGTH : len);
if(NULL == p->assign) { if(NULL == p->assign) {

Loading…
Cancel
Save