mirror of
https://github.com/lumapu/ahoy.git
synced 2025-05-10 07:26:38 +02:00
* PR #76 updated debug messages: now 5 different levels are available
* fixed CRC loop issue
This commit is contained in:
parent
7e2df351d9
commit
0347a3df44
10 changed files with 245 additions and 196 deletions
|
@ -8,12 +8,6 @@
|
|||
|
||||
#include "hmDefines.h"
|
||||
|
||||
#ifdef DEBUG_HMINVERTER
|
||||
#define DBGINV(f) (DPRINTLN(f))
|
||||
#else
|
||||
#define DBGINV(f)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* For values which are of interest and not transmitted by the inverter can be
|
||||
* calculated automatically.
|
||||
|
@ -92,7 +86,7 @@ class Inverter {
|
|||
}
|
||||
|
||||
void init(void) {
|
||||
DBGINV(F("hmInverter.h:init"));
|
||||
DPRINTLN(DBG_VERBOSE, F("hmInverter.h:init"));
|
||||
getAssignment();
|
||||
toRadioId();
|
||||
record = new RECORDTYPE[listLen];
|
||||
|
@ -102,7 +96,7 @@ class Inverter {
|
|||
}
|
||||
|
||||
uint8_t getPosByChFld(uint8_t channel, uint8_t fieldId) {
|
||||
//DBGINV(F("hmInverter.h:getPosByChFld"));
|
||||
DPRINTLN(DBG_VERBOSE, F("hmInverter.h:getPosByChFld"));
|
||||
uint8_t pos = 0;
|
||||
for(; pos < listLen; pos++) {
|
||||
if((assign[pos].ch == channel) && (assign[pos].fieldId == fieldId))
|
||||
|
@ -112,22 +106,22 @@ class Inverter {
|
|||
}
|
||||
|
||||
const char *getFieldName(uint8_t pos) {
|
||||
//DBGINV(F("hmInverter.h:getFieldName"));
|
||||
DPRINTLN(DBG_VERBOSE, F("hmInverter.h:getFieldName"));
|
||||
return fields[assign[pos].fieldId];
|
||||
}
|
||||
|
||||
const char *getUnit(uint8_t pos) {
|
||||
//DBGINV(F("hmInverter.h:getUnit"));
|
||||
DPRINTLN(DBG_VERBOSE, F("hmInverter.h:getUnit"));
|
||||
return units[assign[pos].unitId];
|
||||
}
|
||||
|
||||
uint8_t getChannel(uint8_t pos) {
|
||||
//DBGINV(F("hmInverter.h:getChannel"));
|
||||
DPRINTLN(DBG_VERBOSE, F("hmInverter.h:getChannel"));
|
||||
return assign[pos].ch;
|
||||
}
|
||||
|
||||
void addValue(uint8_t pos, uint8_t buf[]) {
|
||||
//DBGINV(F("hmInverter.h:addValue"));
|
||||
DPRINTLN(DBG_VERBOSE, F("hmInverter.h:addValue"));
|
||||
uint8_t ptr = assign[pos].start;
|
||||
uint8_t end = ptr + assign[pos].num;
|
||||
uint16_t div = assign[pos].div;
|
||||
|
@ -144,12 +138,12 @@ class Inverter {
|
|||
}
|
||||
|
||||
RECORDTYPE getValue(uint8_t pos) {
|
||||
//DBGINV(F("hmInverter.h:getValue"));
|
||||
DPRINTLN(DBG_VERBOSE, F("hmInverter.h:getValue"));
|
||||
return record[pos];
|
||||
}
|
||||
|
||||
void doCalculations(void) {
|
||||
//DBGINV(F("hmInverter.h:doCalculations"));
|
||||
DPRINTLN(DBG_VERBOSE, F("hmInverter.h:doCalculations"));
|
||||
for(uint8_t i = 0; i < listLen; i++) {
|
||||
if(CMD_CALC == assign[i].div) {
|
||||
record[i] = calcFunctions<RECORDTYPE>[assign[i].start].func(this, assign[i].num);
|
||||
|
@ -159,12 +153,12 @@ class Inverter {
|
|||
}
|
||||
|
||||
bool isAvailable(uint32_t timestamp) {
|
||||
//DBGINV(F("hmInverter.h:isAvailable"));
|
||||
DPRINTLN(DBG_VERBOSE, F("hmInverter.h:isAvailable"));
|
||||
return ((timestamp - ts) < INACT_THRES_SEC);
|
||||
}
|
||||
|
||||
bool isProducing(uint32_t timestamp) {
|
||||
//DBGINV(F("hmInverter.h:isProducing"));
|
||||
DPRINTLN(DBG_VERBOSE, F("hmInverter.h:isProducing"));
|
||||
if(isAvailable(timestamp)) {
|
||||
uint8_t pos = getPosByChFld(CH0, FLD_PAC);
|
||||
return (getValue(pos) > INACT_PWR_THRESH);
|
||||
|
@ -173,13 +167,13 @@ class Inverter {
|
|||
}
|
||||
|
||||
uint32_t getLastTs(void) {
|
||||
//DBGINV(F("hmInverter.h:getLastTs"));
|
||||
DPRINTLN(DBG_VERBOSE, F("hmInverter.h:getLastTs"));
|
||||
return ts;
|
||||
}
|
||||
|
||||
private:
|
||||
void toRadioId(void) {
|
||||
//DBGINV(F("hmInverter.h:toRadioId"));
|
||||
DPRINTLN(DBG_VERBOSE, F("hmInverter.h:toRadioId"));
|
||||
radioId.u64 = 0ULL;
|
||||
radioId.b[4] = serial.b[0];
|
||||
radioId.b[3] = serial.b[1];
|
||||
|
@ -189,7 +183,7 @@ class Inverter {
|
|||
}
|
||||
|
||||
void getAssignment(void) {
|
||||
//DBGINV(F("hmInverter.h:getAssignment"));
|
||||
DPRINTLN(DBG_VERBOSE, F("hmInverter.h:getAssignment"));
|
||||
if(INV_TYPE_1CH == type) {
|
||||
listLen = (uint8_t)(HM1CH_LIST_LEN);
|
||||
assign = (byteAssign_t*)hm1chAssignment;
|
||||
|
@ -222,7 +216,7 @@ class Inverter {
|
|||
|
||||
template<class T=float>
|
||||
static T calcYieldTotalCh0(Inverter<> *iv, uint8_t arg0) {
|
||||
//DBGINV(F("hmInverter.h:calcYieldTotalCh0"));
|
||||
DPRINTLN(DBG_VERBOSE, F("hmInverter.h:calcYieldTotalCh0"));
|
||||
if(NULL != iv) {
|
||||
T yield = 0;
|
||||
for(uint8_t i = 1; i <= iv->channels; i++) {
|
||||
|
@ -236,7 +230,7 @@ static T calcYieldTotalCh0(Inverter<> *iv, uint8_t arg0) {
|
|||
|
||||
template<class T=float>
|
||||
static T calcYieldDayCh0(Inverter<> *iv, uint8_t arg0) {
|
||||
//DBGINV(F("hmInverter.h:calcYieldDayCh0"));
|
||||
DPRINTLN(DBG_VERBOSE, F("hmInverter.h:calcYieldDayCh0"));
|
||||
if(NULL != iv) {
|
||||
T yield = 0;
|
||||
for(uint8_t i = 1; i <= iv->channels; i++) {
|
||||
|
@ -250,7 +244,7 @@ static T calcYieldDayCh0(Inverter<> *iv, uint8_t arg0) {
|
|||
|
||||
template<class T=float>
|
||||
static T calcUdcCh(Inverter<> *iv, uint8_t arg0) {
|
||||
//DBGINV(F("hmInverter.h:calcUdcCh"));
|
||||
DPRINTLN(DBG_VERBOSE, F("hmInverter.h:calcUdcCh"));
|
||||
// arg0 = channel of source
|
||||
for(uint8_t i = 0; i < iv->listLen; i++) {
|
||||
if((FLD_UDC == iv->assign[i].fieldId) && (arg0 == iv->assign[i].ch)) {
|
||||
|
@ -263,7 +257,7 @@ static T calcUdcCh(Inverter<> *iv, uint8_t arg0) {
|
|||
|
||||
template<class T=float>
|
||||
static T calcPowerDcCh0(Inverter<> *iv, uint8_t arg0) {
|
||||
//DBGINV(F("hmInverter.h:calcPowerDcCh0"));
|
||||
DPRINTLN(DBG_VERBOSE, F("hmInverter.h:calcPowerDcCh0"));
|
||||
if(NULL != iv) {
|
||||
T dcPower = 0;
|
||||
for(uint8_t i = 1; i <= iv->channels; i++) {
|
||||
|
@ -277,7 +271,7 @@ static T calcPowerDcCh0(Inverter<> *iv, uint8_t arg0) {
|
|||
|
||||
template<class T=float>
|
||||
static T calcEffiencyCh0(Inverter<> *iv, uint8_t arg0) {
|
||||
//DBGINV(F("hmInverter.h:calcEfficiencyCh0"));
|
||||
DPRINTLN(DBG_VERBOSE, F("hmInverter.h:calcEfficiencyCh0"));
|
||||
if(NULL != iv) {
|
||||
uint8_t pos = iv->getPosByChFld(CH0, FLD_PAC);
|
||||
T acPower = iv->getValue(pos);
|
||||
|
@ -294,7 +288,7 @@ static T calcEffiencyCh0(Inverter<> *iv, uint8_t arg0) {
|
|||
|
||||
template<class T=float>
|
||||
static T calcIrradiation(Inverter<> *iv, uint8_t arg0) {
|
||||
//DBGINV(F("hmInverter.h:calcIrradiation"));
|
||||
DPRINTLN(DBG_VERBOSE, F("hmInverter.h:calcIrradiation"));
|
||||
// arg0 = channel
|
||||
if(NULL != iv) {
|
||||
uint8_t pos = iv->getPosByChFld(arg0, FLD_PDC);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue