mirror of
https://github.com/lumapu/ahoy.git
synced 2025-05-11 16:06:38 +02:00
* fixed issues (found during unit test)
This commit is contained in:
parent
32e58c98c0
commit
af4960f1c4
4 changed files with 30 additions and 20 deletions
|
@ -1,8 +1,6 @@
|
|||
#ifndef __DEBUG_H__
|
||||
#define __DEBUG_H__
|
||||
|
||||
#include "Arduino.h"
|
||||
|
||||
#ifdef NDEBUG
|
||||
#define DPRINT(str)
|
||||
#define DPRINTLN(str)
|
||||
|
|
|
@ -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))
|
||||
|
||||
|
|
|
@ -23,6 +23,9 @@ static T calcYieldTotalCh0(Inverter<> *iv, uint8_t arg0);
|
|||
template<class T=float>
|
||||
static T calcYieldDayCh0(Inverter<> *iv, uint8_t arg0);
|
||||
|
||||
template<class T=float>
|
||||
static T calcUdcCh(Inverter<> *iv, uint8_t arg0);
|
||||
|
||||
template<class T=float>
|
||||
using func_t = T (Inverter<> *, uint8_t);
|
||||
|
||||
|
@ -37,7 +40,8 @@ struct calcFunc_t {
|
|||
template<class T=float>
|
||||
const calcFunc_t<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<RECORDTYPE>[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<RECORDTYPE>[assign[i].start].func(this, assign[i].num);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue