Browse Source

added DEBUG_FLAGs to config.h

pull/76/head
stefan123t 3 years ago
parent
commit
20c145013e
  1. 32
      tools/esp8266/app.cpp
  2. 7
      tools/esp8266/config.h
  3. 36
      tools/esp8266/hmInverter.h
  4. 22
      tools/esp8266/hmRadio.h
  5. 10
      tools/esp8266/hmSystem.h
  6. 42
      tools/esp8266/main.cpp
  7. 12
      tools/esp8266/main.h

32
tools/esp8266/app.cpp

@ -7,7 +7,9 @@
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
app::app() : Main() { app::app() : Main() {
#ifdef DEBUG_APP
DPRINTLN(F("app::app():Main")); DPRINTLN(F("app::app():Main"));
#endif
mSendTicker = 0xffff; mSendTicker = 0xffff;
mSendInterval = 0; mSendInterval = 0;
mMqttTicker = 0xffff; mMqttTicker = 0xffff;
@ -43,7 +45,9 @@ app::~app(void) {
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void app::setup(uint32_t timeout) { void app::setup(uint32_t timeout) {
#ifdef DEBUG_APP
DPRINTLN(F("app::setup")); DPRINTLN(F("app::setup"));
#endif
Main::setup(timeout); Main::setup(timeout);
mWeb->on("/", std::bind(&app::showIndex, this)); mWeb->on("/", std::bind(&app::showIndex, this));
@ -187,9 +191,11 @@ void app::setup(uint32_t timeout) {
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void app::loop(void) { void app::loop(void) {
#ifdef DEBUG_APP
//DPRINT(F("a")); //DPRINT(F("a"));
//DPRINTLN(F("a")); //DPRINTLN(F("a"));
//app_loops++; //app_loops++;
#ifdef DEBUG_APP
Main::loop(); Main::loop();
mSys->Radio.loop(); mSys->Radio.loop();
@ -197,9 +203,11 @@ void app::loop(void) {
yield(); yield();
if(checkTicker(&mRxTicker, 5)) { if(checkTicker(&mRxTicker, 5)) {
#ifdef DEBUG_APP
//DPRINTLN(F("app_loops =") + String(app_loops)); //DPRINTLN(F("app_loops =") + String(app_loops));
//app_loops=0; //app_loops=0;
//DPRINT(F("a")); //DPRINT(F("a"));
#endif
bool rxRdy = mSys->Radio.switchRxCh(); bool rxRdy = mSys->Radio.switchRxCh();
if(!mSys->BufCtrl.empty()) { if(!mSys->BufCtrl.empty()) {
@ -350,14 +358,18 @@ void app::loop(void) {
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void app::handleIntr(void) { void app::handleIntr(void) {
#ifdef DEBUG_APP
//DPRINTLN(F("app::handleIntr")); //DPRINTLN(F("app::handleIntr"));
#endif
mSys->Radio.handleIntr(); mSys->Radio.handleIntr();
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
bool app::buildPayload(uint8_t id) { bool app::buildPayload(uint8_t id) {
#ifdef DEBUG_APP
//DPRINTLN(F("app::buildPayload")); //DPRINTLN(F("app::buildPayload"));
#endif
uint16_t crc = 0xffff, crcRcv; uint16_t crc = 0xffff, crcRcv;
if(mPayload[id].maxPackId > MAX_PAYLOAD_ENTRIES) if(mPayload[id].maxPackId > MAX_PAYLOAD_ENTRIES)
mPayload[id].maxPackId = MAX_PAYLOAD_ENTRIES; mPayload[id].maxPackId = MAX_PAYLOAD_ENTRIES;
@ -382,8 +394,10 @@ bool app::buildPayload(uint8_t id) {
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void app::processPayload(bool retransmit) { void app::processPayload(bool retransmit) {
#ifdef DEBUG_APP
//DPRINTLN(F("app::processPayload")); //DPRINTLN(F("app::processPayload"));
//DPRINT(F("p")); //DPRINT(F("p"));
#endif
for(uint8_t id = 0; id < mSys->getNumInverters(); id++) { for(uint8_t id = 0; id < mSys->getNumInverters(); id++) {
Inverter<> *iv = mSys->getInverterByPos(id); Inverter<> *iv = mSys->getInverterByPos(id);
if(NULL != iv) { if(NULL != iv) {
@ -448,7 +462,9 @@ void app::processPayload(bool retransmit) {
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void app::showIndex(void) { void app::showIndex(void) {
#ifdef DEBUG_APP
DPRINTLN(F("app::showIndex")); DPRINTLN(F("app::showIndex"));
#endif
String html = FPSTR(index_html); String html = FPSTR(index_html);
html.replace(F("{DEVICE}"), mDeviceName); html.replace(F("{DEVICE}"), mDeviceName);
html.replace(F("{VERSION}"), mVersion); html.replace(F("{VERSION}"), mVersion);
@ -460,7 +476,9 @@ void app::showIndex(void) {
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void app::showSetup(void) { void app::showSetup(void) {
#ifdef DEBUG_APP
DPRINTLN(F("app::showSetup")); DPRINTLN(F("app::showSetup"));
#endif
// overrides same method in main.cpp // overrides same method in main.cpp
uint16_t interval; uint16_t interval;
@ -580,14 +598,18 @@ void app::showSetup(void) {
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void app::showSave(void) { void app::showSave(void) {
#ifdef DEBUG_APP
DPRINTLN(F("app::showSave")); DPRINTLN(F("app::showSave"));
#endif
saveValues(true); saveValues(true);
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void app::showErase() { void app::showErase() {
#ifdef DEBUG_APP
DPRINTLN(F("app::showErase")); DPRINTLN(F("app::showErase"));
#endif
eraseSettings(); eraseSettings();
showReboot(); showReboot();
} }
@ -595,7 +617,9 @@ void app::showErase() {
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void app::showStatistics(void) { void app::showStatistics(void) {
#ifdef DEBUG_APP
//DPRINTLN(F("app::showStatistics")); //DPRINTLN(F("app::showStatistics"));
#endif
String content = F("Receive success: ") + String(mRxSuccess) + "\n"; String content = F("Receive success: ") + String(mRxSuccess) + "\n";
content += F("Receive fail: ") + String(mRxFailed) + "\n"; content += F("Receive fail: ") + String(mRxFailed) + "\n";
content += F("Send Cnt: ") + String(mSys->Radio.mSendCnt) + String("\n\n"); content += F("Send Cnt: ") + String(mSys->Radio.mSendCnt) + String("\n\n");
@ -644,7 +668,9 @@ void app::showStatistics(void) {
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void app::showHoymiles(void) { void app::showHoymiles(void) {
#ifdef DEBUG_APP
DPRINTLN(F("app::showHoymiles")); DPRINTLN(F("app::showHoymiles"));
#endif
String html = FPSTR(hoymiles_html); String html = FPSTR(hoymiles_html);
html.replace(F("{DEVICE}"), mDeviceName); html.replace(F("{DEVICE}"), mDeviceName);
html.replace(F("{VERSION}"), mVersion); html.replace(F("{VERSION}"), mVersion);
@ -656,7 +682,9 @@ void app::showHoymiles(void) {
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void app::showLiveData(void) { void app::showLiveData(void) {
#ifdef DEBUG_APP
//DPRINTLN(F("app::showLiveData")); //DPRINTLN(F("app::showLiveData"));
#endif
String modHtml; String modHtml;
for(uint8_t id = 0; id < mSys->getNumInverters(); id++) { for(uint8_t id = 0; id < mSys->getNumInverters(); id++) {
Inverter<> *iv = mSys->getInverterByPos(id); Inverter<> *iv = mSys->getInverterByPos(id);
@ -734,7 +762,9 @@ void app::showLiveData(void) {
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void app::saveValues(bool webSend = true) { void app::saveValues(bool webSend = true) {
#ifdef DEBUG_APP
DPRINTLN(F("app::saveValues")); DPRINTLN(F("app::saveValues"));
#endif
Main::saveValues(false); // general configuration Main::saveValues(false); // general configuration
if(mWeb->args() > 0) { if(mWeb->args() > 0) {
@ -843,7 +873,9 @@ void app::saveValues(bool webSend = true) {
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void app::updateCrc(void) { void app::updateCrc(void) {
#ifdef DEBUG_APP
DPRINTLN(F("app::updateCrc")); DPRINTLN(F("app::updateCrc"));
#endif
Main::updateCrc(); Main::updateCrc();
uint16_t crc; uint16_t crc;

7
tools/esp8266/config.h

@ -53,4 +53,11 @@
// changes the style of "/setup" page, visualized = nicer // changes the style of "/setup" page, visualized = nicer
#define LIVEDATA_VISUALIZED #define LIVEDATA_VISUALIZED
// comment out to disable any of the debug options here
#define DEBUG_APP
#define DEBUG_HMINVERTER
#define DEBUG_HMRADIO
#define DEBUG_HMSYSTEM
#define DEBUG_HMMAIN
#endif /*__CONFIG_H__*/ #endif /*__CONFIG_H__*/

36
tools/esp8266/hmInverter.h

@ -82,7 +82,9 @@ class Inverter {
} }
void init(void) { void init(void) {
#ifdef DEBUG_HMINVERTER
DPRINTLN(F("hmInverter.h:init")); DPRINTLN(F("hmInverter.h:init"));
#endif
getAssignment(); getAssignment();
toRadioId(); toRadioId();
record = new RECORDTYPE[listLen]; record = new RECORDTYPE[listLen];
@ -92,7 +94,9 @@ class Inverter {
} }
uint8_t getPosByChFld(uint8_t channel, uint8_t fieldId) { uint8_t getPosByChFld(uint8_t channel, uint8_t fieldId) {
#ifdef DEBUG_HMINVERTER
//DPRINTLN(F("hmInverter.h:getPosByChFld")); //DPRINTLN(F("hmInverter.h:getPosByChFld"));
#endif
uint8_t pos = 0; uint8_t pos = 0;
for(; pos < listLen; pos++) { for(; pos < listLen; pos++) {
if((assign[pos].ch == channel) && (assign[pos].fieldId == fieldId)) if((assign[pos].ch == channel) && (assign[pos].fieldId == fieldId))
@ -102,22 +106,30 @@ class Inverter {
} }
const char *getFieldName(uint8_t pos) { const char *getFieldName(uint8_t pos) {
#ifdef DEBUG_HMINVERTER
//DPRINTLN(F("hmInverter.h:getFieldName")); //DPRINTLN(F("hmInverter.h:getFieldName"));
#endif
return fields[assign[pos].fieldId]; return fields[assign[pos].fieldId];
} }
const char *getUnit(uint8_t pos) { const char *getUnit(uint8_t pos) {
#ifdef DEBUG_HMINVERTER
//DPRINTLN(F("hmInverter.h:getUnit")); //DPRINTLN(F("hmInverter.h:getUnit"));
#endif
return units[assign[pos].unitId]; return units[assign[pos].unitId];
} }
uint8_t getChannel(uint8_t pos) { uint8_t getChannel(uint8_t pos) {
#ifdef DEBUG_HMINVERTER
//DPRINTLN(F("hmInverter.h:getChannel")); //DPRINTLN(F("hmInverter.h:getChannel"));
#endif
return assign[pos].ch; return assign[pos].ch;
} }
void addValue(uint8_t pos, uint8_t buf[]) { void addValue(uint8_t pos, uint8_t buf[]) {
#ifdef DEBUG_HMINVERTER
//DPRINTLN(F("hmInverter.h:addValue")); //DPRINTLN(F("hmInverter.h:addValue"));
#endif
uint8_t ptr = assign[pos].start; uint8_t ptr = assign[pos].start;
uint8_t end = ptr + assign[pos].num; uint8_t end = ptr + assign[pos].num;
uint16_t div = assign[pos].div; uint16_t div = assign[pos].div;
@ -134,12 +146,16 @@ class Inverter {
} }
RECORDTYPE getValue(uint8_t pos) { RECORDTYPE getValue(uint8_t pos) {
#ifdef DEBUG_HMINVERTER
//DPRINTLN(F("hmInverter.h:getValue")); //DPRINTLN(F("hmInverter.h:getValue"));
#endif
return record[pos]; return record[pos];
} }
void doCalculations(void) { void doCalculations(void) {
#ifdef DEBUG_HMINVERTER
//DPRINTLN(F("hmInverter.h:doCalculations")); //DPRINTLN(F("hmInverter.h:doCalculations"));
#endif
for(uint8_t i = 0; i < listLen; i++) { for(uint8_t i = 0; i < listLen; i++) {
if(CMD_CALC == assign[i].div) { if(CMD_CALC == assign[i].div) {
record[i] = calcFunctions<RECORDTYPE>[assign[i].start].func(this, assign[i].num); record[i] = calcFunctions<RECORDTYPE>[assign[i].start].func(this, assign[i].num);
@ -148,7 +164,9 @@ class Inverter {
} }
bool isAvailable(uint32_t timestamp) { bool isAvailable(uint32_t timestamp) {
#ifdef DEBUG_HMINVERTER
//DPRINTLN(F("hmInverter.h:isAvailable")); //DPRINTLN(F("hmInverter.h:isAvailable"));
#endif
return ((timestamp - ts) < INACT_THRES_SEC); return ((timestamp - ts) < INACT_THRES_SEC);
} }
@ -162,13 +180,17 @@ class Inverter {
} }
uint32_t getLastTs(void) { uint32_t getLastTs(void) {
#ifdef DEBUG_HMINVERTER
//DPRINTLN(F("hmInverter.h:getLastTs")); //DPRINTLN(F("hmInverter.h:getLastTs"));
#endif
return ts; return ts;
} }
private: private:
void toRadioId(void) { void toRadioId(void) {
#ifdef DEBUG_HMINVERTER
//DPRINTLN(F("hmInverter.h:toRadioId")); //DPRINTLN(F("hmInverter.h:toRadioId"));
#endif
radioId.u64 = 0ULL; radioId.u64 = 0ULL;
radioId.b[4] = serial.b[0]; radioId.b[4] = serial.b[0];
radioId.b[3] = serial.b[1]; radioId.b[3] = serial.b[1];
@ -178,7 +200,9 @@ class Inverter {
} }
void getAssignment(void) { void getAssignment(void) {
#ifdef DEBUG_HMINVERTER
//DPRINTLN(F("hmInverter.h:getAssignment")); //DPRINTLN(F("hmInverter.h:getAssignment"));
#endif
if(INV_TYPE_1CH == type) { if(INV_TYPE_1CH == type) {
listLen = (uint8_t)(HM1CH_LIST_LEN); listLen = (uint8_t)(HM1CH_LIST_LEN);
assign = (byteAssign_t*)hm1chAssignment; assign = (byteAssign_t*)hm1chAssignment;
@ -211,7 +235,9 @@ class Inverter {
template<class T=float> template<class T=float>
static T calcYieldTotalCh0(Inverter<> *iv, uint8_t arg0) { static T calcYieldTotalCh0(Inverter<> *iv, uint8_t arg0) {
#ifdef DEBUG_HMINVERTER
//DPRINTLN(F("hmInverter.h:calcYieldTotalCh0")); //DPRINTLN(F("hmInverter.h:calcYieldTotalCh0"));
#endif
if(NULL != iv) { if(NULL != iv) {
T yield = 0; T yield = 0;
for(uint8_t i = 1; i <= iv->channels; i++) { for(uint8_t i = 1; i <= iv->channels; i++) {
@ -225,7 +251,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) {
#ifdef DEBUG_HMINVERTER
//DPRINTLN(F("hmInverter.h:calcYieldDayCh0")); //DPRINTLN(F("hmInverter.h:calcYieldDayCh0"));
#endif
if(NULL != iv) { if(NULL != iv) {
T yield = 0; T yield = 0;
for(uint8_t i = 1; i <= iv->channels; i++) { for(uint8_t i = 1; i <= iv->channels; i++) {
@ -239,7 +267,9 @@ static T calcYieldDayCh0(Inverter<> *iv, uint8_t arg0) {
template<class T=float> template<class T=float>
static T calcUdcCh(Inverter<> *iv, uint8_t arg0) { static T calcUdcCh(Inverter<> *iv, uint8_t arg0) {
#ifdef DEBUG_HMINVERTER
//DPRINTLN(F("hmInverter.h:calcUdcCh")); //DPRINTLN(F("hmInverter.h:calcUdcCh"));
#endif
// arg0 = channel of source // arg0 = channel of source
for(uint8_t i = 0; i < iv->listLen; i++) { for(uint8_t i = 0; i < iv->listLen; i++) {
if((FLD_UDC == iv->assign[i].fieldId) && (arg0 == iv->assign[i].ch)) { if((FLD_UDC == iv->assign[i].fieldId) && (arg0 == iv->assign[i].ch)) {
@ -252,7 +282,9 @@ static T calcUdcCh(Inverter<> *iv, uint8_t arg0) {
template<class T=float> template<class T=float>
static T calcPowerDcCh0(Inverter<> *iv, uint8_t arg0) { static T calcPowerDcCh0(Inverter<> *iv, uint8_t arg0) {
#ifdef DEBUG_HMINVERTER
//DPRINTLN(F("hmInverter.h:calcPowerDcCh0")); //DPRINTLN(F("hmInverter.h:calcPowerDcCh0"));
#endif
if(NULL != iv) { if(NULL != iv) {
T dcPower = 0; T dcPower = 0;
for(uint8_t i = 1; i <= iv->channels; i++) { for(uint8_t i = 1; i <= iv->channels; i++) {
@ -266,7 +298,9 @@ static T calcPowerDcCh0(Inverter<> *iv, uint8_t arg0) {
template<class T=float> template<class T=float>
static T calcEffiencyCh0(Inverter<> *iv, uint8_t arg0) { static T calcEffiencyCh0(Inverter<> *iv, uint8_t arg0) {
#ifdef DEBUG_HMINVERTER
//DPRINTLN(F("hmInverter.h:calcEfficiencyCh0")); //DPRINTLN(F("hmInverter.h:calcEfficiencyCh0"));
#endif
if(NULL != iv) { if(NULL != iv) {
uint8_t pos = iv->getPosByChFld(CH0, FLD_PAC); uint8_t pos = iv->getPosByChFld(CH0, FLD_PAC);
T acPower = iv->getValue(pos); T acPower = iv->getValue(pos);
@ -283,7 +317,9 @@ static T calcEffiencyCh0(Inverter<> *iv, uint8_t arg0) {
template<class T=float> template<class T=float>
static T calcIrradiation(Inverter<> *iv, uint8_t arg0) { static T calcIrradiation(Inverter<> *iv, uint8_t arg0) {
#ifdef DEBUG_HMINVERTER
//DPRINTLN(F("hmInverter.h:calcIrradiation")); //DPRINTLN(F("hmInverter.h:calcIrradiation"));
#endif
// arg0 = channel // arg0 = channel
if(NULL != iv) { if(NULL != iv) {
uint8_t pos = iv->getPosByChFld(arg0, FLD_PDC); uint8_t pos = iv->getPosByChFld(arg0, FLD_PDC);

22
tools/esp8266/hmRadio.h

@ -49,7 +49,9 @@ template <uint8_t CE_PIN, uint8_t CS_PIN, uint8_t IRQ_PIN, class BUFFER, uint64_
class HmRadio { class HmRadio {
public: public:
HmRadio() : mNrf24(CE_PIN, CS_PIN, SPI_SPEED) { HmRadio() : mNrf24(CE_PIN, CS_PIN, SPI_SPEED) {
#ifdef DEBUG_HMRADIO
DPRINTLN(F("hmRadio.h : HmRadio():mNrf24(CE_PIN: ") + String(CE_PIN) + F(", CS_PIN: ") + String(CS_PIN) + F(", SPI_SPEED: ") + String(SPI_SPEED) + ")"); DPRINTLN(F("hmRadio.h : HmRadio():mNrf24(CE_PIN: ") + String(CE_PIN) + F(", CS_PIN: ") + String(CS_PIN) + F(", SPI_SPEED: ") + String(SPI_SPEED) + ")");
#endif
mTxChLst[0] = 40; mTxChLst[0] = 40;
//mTxChIdx = 1; //mTxChIdx = 1;
@ -76,7 +78,9 @@ class HmRadio {
~HmRadio() {} ~HmRadio() {}
void setup(BUFFER *ctrl) { void setup(BUFFER *ctrl) {
#ifdef DEBUG_HMRADIO
DPRINTLN(F("hmRadio.h:setup")); DPRINTLN(F("hmRadio.h:setup"));
#endif
pinMode(pinIrq, INPUT_PULLUP); pinMode(pinIrq, INPUT_PULLUP);
mBufCtrl = ctrl; mBufCtrl = ctrl;
@ -141,12 +145,16 @@ class HmRadio {
} }
void handleIntr(void) { void handleIntr(void) {
#ifdef DEBUG_HMRADIO
//DPRINTLN(F("hmRadio.h:handleIntr")); //DPRINTLN(F("hmRadio.h:handleIntr"));
#endif
mIrqRcvd = true; mIrqRcvd = true;
} }
uint8_t getDefaultChannel(void) { uint8_t getDefaultChannel(void) {
#ifdef DEBUG_HMRADIO
//DPRINTLN(F("hmRadio.h:getDefaultChannel")); //DPRINTLN(F("hmRadio.h:getDefaultChannel"));
#endif
return mTxChLst[0]; return mTxChLst[0];
} }
/*uint8_t getLastChannel(void) { /*uint8_t getLastChannel(void) {
@ -160,7 +168,9 @@ class HmRadio {
}*/ }*/
void sendTimePacket(uint64_t invId, uint32_t ts) { void sendTimePacket(uint64_t invId, uint32_t ts) {
#ifdef DEBUG_HMRADIO
//DPRINTLN(F("hmRadio.h:sendTimePacket")); //DPRINTLN(F("hmRadio.h:sendTimePacket"));
#endif
sendCmdPacket(invId, 0x15, 0x80, false); sendCmdPacket(invId, 0x15, 0x80, false);
mTxBuf[10] = 0x0b; // cid mTxBuf[10] = 0x0b; // cid
mTxBuf[11] = 0x00; mTxBuf[11] = 0x00;
@ -176,7 +186,9 @@ class HmRadio {
} }
void sendCmdPacket(uint64_t invId, uint8_t mid, uint8_t pid, bool calcCrc = true) { void sendCmdPacket(uint64_t invId, uint8_t mid, uint8_t pid, bool calcCrc = true) {
#ifdef DEBUG_HMRADIO
//DPRINTLN(F("hmRadio.h:sendCmdPacket")); //DPRINTLN(F("hmRadio.h:sendCmdPacket"));
#endif
memset(mTxBuf, 0, MAX_RF_PAYLOAD_SIZE); memset(mTxBuf, 0, MAX_RF_PAYLOAD_SIZE);
mTxBuf[0] = mid; // message id mTxBuf[0] = mid; // message id
CP_U32_BigEndian(&mTxBuf[1], (invId >> 8)); CP_U32_BigEndian(&mTxBuf[1], (invId >> 8));
@ -189,7 +201,9 @@ class HmRadio {
} }
bool checkPaketCrc(uint8_t buf[], uint8_t *len, uint8_t rxCh) { bool checkPaketCrc(uint8_t buf[], uint8_t *len, uint8_t rxCh) {
#ifdef DEBUG_HMRADIO
//DPRINTLN(F("hmRadio.h:checkPaketCrc")); //DPRINTLN(F("hmRadio.h:checkPaketCrc"));
#endif
*len = (buf[0] >> 2); *len = (buf[0] >> 2);
if(*len > (MAX_RF_PAYLOAD_SIZE - 2)) if(*len > (MAX_RF_PAYLOAD_SIZE - 2))
*len = MAX_RF_PAYLOAD_SIZE - 2; *len = MAX_RF_PAYLOAD_SIZE - 2;
@ -204,8 +218,10 @@ class HmRadio {
} }
bool switchRxCh(uint16_t addLoop = 0) { bool switchRxCh(uint16_t addLoop = 0) {
#ifdef DEBUG_HMRADIO
//DPRINTLN(F("hmRadio.h:switchRxCh")); //DPRINTLN(F("hmRadio.h:switchRxCh"));
//DPRINT(F("R")); //DPRINT(F("R"));
#endif
mRxLoopCnt += addLoop; mRxLoopCnt += addLoop;
if(mRxLoopCnt != 0) { if(mRxLoopCnt != 0) {
@ -220,7 +236,9 @@ class HmRadio {
} }
void dumpBuf(const char *info, uint8_t buf[], uint8_t len) { void dumpBuf(const char *info, uint8_t buf[], uint8_t len) {
#ifdef DEBUG_HMRADIO
//DPRINTLN(F("hmRadio.h:dumpBuf")); //DPRINTLN(F("hmRadio.h:dumpBuf"));
#endif
if(NULL != info) if(NULL != info)
DPRINT(String(info)); DPRINT(String(info));
for(uint8_t i = 0; i < len; i++) { for(uint8_t i = 0; i < len; i++) {
@ -231,7 +249,9 @@ class HmRadio {
} }
bool isChipConnected(void) { bool isChipConnected(void) {
#ifdef DEBUG_HMRADIO
//DPRINTLN(F("hmRadio.h:isChipConnected")); //DPRINTLN(F("hmRadio.h:isChipConnected"));
#endif
return mNrf24.isChipConnected(); return mNrf24.isChipConnected();
} }
@ -246,9 +266,11 @@ class HmRadio {
private: private:
void sendPacket(uint64_t invId, uint8_t buf[], uint8_t len, bool clear=false) { void sendPacket(uint64_t invId, uint8_t buf[], uint8_t len, bool clear=false) {
#ifdef DEBUG_HMRADIO
//DPRINTLN(F("hmRadio.h:sendPacket")); //DPRINTLN(F("hmRadio.h:sendPacket"));
//DPRINTLN("sent packet: #" + String(mSendCnt)); //DPRINTLN("sent packet: #" + String(mSendCnt));
//dumpBuf("SEN ", buf, len); //dumpBuf("SEN ", buf, len);
#endif
if(mSerialDebug) { if(mSerialDebug) {
DPRINT("Transmit " + String(len) + " | "); DPRINT("Transmit " + String(len) + " | ");
dumpBuf(NULL, buf, len); dumpBuf(NULL, buf, len);

10
tools/esp8266/hmSystem.h

@ -24,12 +24,16 @@ class HmSystem {
} }
void setup() { void setup() {
#ifdef DEBUG_HMSYSTEM
DPRINTLN(F("hmSystem.h:setup")); DPRINTLN(F("hmSystem.h:setup"));
#endif
Radio.setup(&BufCtrl); Radio.setup(&BufCtrl);
} }
INVERTERTYPE *addInverter(const char *name, uint64_t serial, uint16_t chMaxPwr[]) { INVERTERTYPE *addInverter(const char *name, uint64_t serial, uint16_t chMaxPwr[]) {
#ifdef DEBUG_HMSYSTEM
DPRINTLN(F("hmSystem.h:addInverter")); DPRINTLN(F("hmSystem.h:addInverter"));
#endif
if(MAX_INVERTER <= mNumInv) { if(MAX_INVERTER <= mNumInv) {
DPRINT(F("max number of inverters reached!")); DPRINT(F("max number of inverters reached!"));
return NULL; return NULL;
@ -66,7 +70,9 @@ class HmSystem {
} }
INVERTERTYPE *findInverter(uint8_t buf[]) { INVERTERTYPE *findInverter(uint8_t buf[]) {
#ifdef DEBUG_HMSYSTEM
//DPRINTLN(F("hmSystem.h:findInverter")); //DPRINTLN(F("hmSystem.h:findInverter"));
#endif
INVERTERTYPE *p; INVERTERTYPE *p;
for(uint8_t i = 0; i < mNumInv; i++) { for(uint8_t i = 0; i < mNumInv; i++) {
p = &mInverter[i]; p = &mInverter[i];
@ -80,7 +86,9 @@ class HmSystem {
} }
INVERTERTYPE *getInverterByPos(uint8_t pos) { INVERTERTYPE *getInverterByPos(uint8_t pos) {
#ifdef DEBUG_HMSYSTEM
//DPRINTLN(F("hmSystem.h:getInverterByPos")); //DPRINTLN(F("hmSystem.h:getInverterByPos"));
#endif
if(mInverter[pos].serial.u64 != 0ULL) if(mInverter[pos].serial.u64 != 0ULL)
return &mInverter[pos]; return &mInverter[pos];
else else
@ -88,7 +96,9 @@ class HmSystem {
} }
uint8_t getNumInverters(void) { uint8_t getNumInverters(void) {
#ifdef DEBUG_HMSYSTEM
//DPRINTLN(F("hmSystem.h:getNumInverters")); //DPRINTLN(F("hmSystem.h:getNumInverters"));
#endif
return mNumInv; return mNumInv;
} }

42
tools/esp8266/main.cpp

@ -26,7 +26,9 @@ Main::Main(void) {
mEep = new eep(); mEep = new eep();
Serial.begin(115200); Serial.begin(115200);
#ifdef DEBUG_HMMAIN
DPRINTLN(F("Main::Main")); DPRINTLN(F("Main::Main"));
#endif
mUptimeSecs = 0; mUptimeSecs = 0;
mUptimeTicker = 0xffffffff; mUptimeTicker = 0xffffffff;
@ -40,7 +42,9 @@ Main::Main(void) {
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void Main::setup(uint32_t timeout) { void Main::setup(uint32_t timeout) {
#ifdef DEBUG_HMMAIN
DPRINTLN(F("Main::setup")); DPRINTLN(F("Main::setup"));
#endif
bool startAp = mApActive; bool startAp = mApActive;
mLimit = timeout; mLimit = timeout;
@ -69,7 +73,9 @@ void Main::setup(uint32_t timeout) {
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void Main::loop(void) { void Main::loop(void) {
#ifdef DEBUG_HMMAIN
//DPRINT(F("M")); //DPRINT(F("M"));
#endif
if(mApActive) { if(mApActive) {
mDns->processNextRequest(); mDns->processNextRequest();
#ifndef AP_ONLY #ifndef AP_ONLY
@ -118,7 +124,9 @@ void Main::loop(void) {
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
bool Main::getConfig(void) { bool Main::getConfig(void) {
#ifdef DEBUG_HMMAIN
DPRINTLN(F("Main::getConfig")); DPRINTLN(F("Main::getConfig"));
#endif
bool mApActive = false; bool mApActive = false;
mWifiSettingsValid = checkEEpCrc(ADDR_START, ADDR_WIFI_CRC, ADDR_WIFI_CRC); mWifiSettingsValid = checkEEpCrc(ADDR_START, ADDR_WIFI_CRC, ADDR_WIFI_CRC);
@ -141,7 +149,9 @@ bool Main::getConfig(void) {
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void Main::setupAp(const char *ssid, const char *pwd) { void Main::setupAp(const char *ssid, const char *pwd) {
#ifdef DEBUG_HMMAIN
DPRINTLN(F("Main::setupAp")); DPRINTLN(F("Main::setupAp"));
#endif
IPAddress apIp(192, 168, 1, 1); IPAddress apIp(192, 168, 1, 1);
DPRINTLN(F("\n---------\nAP MODE\nSSDI: ") DPRINTLN(F("\n---------\nAP MODE\nSSDI: ")
@ -149,7 +159,9 @@ void Main::setupAp(const char *ssid, const char *pwd) {
+ String(pwd) + F("\nActive for: ") + String(pwd) + F("\nActive for: ")
+ String(WIFI_AP_ACTIVE_TIME) + F(" seconds") + String(WIFI_AP_ACTIVE_TIME) + F(" seconds")
+ F("\n---------\n")); + F("\n---------\n"));
#ifdef DEBUG_HMMAIN
DPRINTLN("DBG: " + String(mNextTryTs)); DPRINTLN("DBG: " + String(mNextTryTs));
#endif
WiFi.mode(WIFI_AP); WiFi.mode(WIFI_AP);
WiFi.softAPConfig(apIp, apIp, IPAddress(255, 255, 255, 0)); WiFi.softAPConfig(apIp, apIp, IPAddress(255, 255, 255, 0));
@ -168,7 +180,9 @@ void Main::setupAp(const char *ssid, const char *pwd) {
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
bool Main::setupStation(uint32_t timeout) { bool Main::setupStation(uint32_t timeout) {
#ifdef DEBUG_HMMAIN
DPRINTLN(F("Main::setupStation")); DPRINTLN(F("Main::setupStation"));
#endif
int32_t cnt; int32_t cnt;
bool startAp = false; bool startAp = false;
@ -218,7 +232,9 @@ bool Main::setupStation(uint32_t timeout) {
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void Main::showSetup(void) { void Main::showSetup(void) {
#ifdef DEBUG_HMMAIN
DPRINTLN(F("Main::showSetup")); DPRINTLN(F("Main::showSetup"));
#endif
String html = FPSTR(setup_html); String html = FPSTR(setup_html);
html.replace(F("{SSID}"), mStationSsid); html.replace(F("{SSID}"), mStationSsid);
// PWD will be left at the default value (for protection) // PWD will be left at the default value (for protection)
@ -236,21 +252,27 @@ void Main::showSetup(void) {
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void Main::showCss(void) { void Main::showCss(void) {
#ifdef DEBUG_HMMAIN
DPRINTLN(F("Main::showCss")); DPRINTLN(F("Main::showCss"));
#endif
mWeb->send(200, "text/css", FPSTR(style_css)); mWeb->send(200, "text/css", FPSTR(style_css));
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void Main::showSave(void) { void Main::showSave(void) {
#ifdef DEBUG_HMMAIN
DPRINTLN(F("Main::showSave")); DPRINTLN(F("Main::showSave"));
#endif
saveValues(true); saveValues(true);
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void Main::saveValues(bool webSend = true) { void Main::saveValues(bool webSend = true) {
#ifdef DEBUG_HMMAIN
DPRINTLN(F("Main::saveValues")); DPRINTLN(F("Main::saveValues"));
#endif
if(mWeb->args() > 0) { if(mWeb->args() > 0) {
if(mWeb->arg("ssid") != "") { if(mWeb->arg("ssid") != "") {
memset(mStationSsid, 0, SSID_LEN); memset(mStationSsid, 0, SSID_LEN);
@ -284,7 +306,9 @@ void Main::saveValues(bool webSend = true) {
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void Main::updateCrc(void) { void Main::updateCrc(void) {
#ifdef DEBUG_HMMAIN
DPRINTLN(F("Main::updateCrc")); DPRINTLN(F("Main::updateCrc"));
#endif
uint16_t crc; uint16_t crc;
crc = buildEEpCrc(ADDR_START, ADDR_WIFI_CRC); crc = buildEEpCrc(ADDR_START, ADDR_WIFI_CRC);
//Serial.println("new CRC: " + String(crc, HEX)); //Serial.println("new CRC: " + String(crc, HEX));
@ -295,7 +319,9 @@ void Main::updateCrc(void) {
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void Main::showUptime(void) { void Main::showUptime(void) {
#ifdef DEBUG_HMMAIN
//DPRINTLN(F("Main::showUptime")); //DPRINTLN(F("Main::showUptime"));
#endif
char time[20] = {0}; char time[20] = {0};
int upTimeSc = uint32_t((mUptimeSecs) % 60); int upTimeSc = uint32_t((mUptimeSecs) % 60);
@ -311,14 +337,18 @@ void Main::showUptime(void) {
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void Main::showTime(void) { void Main::showTime(void) {
#ifdef DEBUG_HMMAIN
//DPRINTLN(F("Main::showTime")); //DPRINTLN(F("Main::showTime"));
#endif
mWeb->send(200, "text/plain", getDateTimeStr(mTimestamp)); mWeb->send(200, "text/plain", getDateTimeStr(mTimestamp));
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void Main::showNotFound(void) { void Main::showNotFound(void) {
#ifdef DEBUG_HMMAIN
DPRINTLN(F("Main::showNotFound - ") + mWeb->uri()); DPRINTLN(F("Main::showNotFound - ") + mWeb->uri());
#endif
String msg = F("File Not Found\n\nURI: "); String msg = F("File Not Found\n\nURI: ");
msg += mWeb->uri(); msg += mWeb->uri();
msg += F("\nMethod: "); msg += F("\nMethod: ");
@ -337,7 +367,9 @@ void Main::showNotFound(void) {
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void Main::showReboot(void) { void Main::showReboot(void) {
#ifdef DEBUG_HMMAIN
DPRINTLN(F("Main::showReboot")); DPRINTLN(F("Main::showReboot"));
#endif
mWeb->send(200, F("text/html"), F("<!doctype html><html><head><title>Rebooting ...</title><meta http-equiv=\"refresh\" content=\"10; URL=/\"></head><body>rebooting ... auto reload after 10s</body></html>")); mWeb->send(200, F("text/html"), F("<!doctype html><html><head><title>Rebooting ...</title><meta http-equiv=\"refresh\" content=\"10; URL=/\"></head><body>rebooting ... auto reload after 10s</body></html>"));
delay(1000); delay(1000);
ESP.restart(); ESP.restart();
@ -347,7 +379,9 @@ void Main::showReboot(void) {
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void Main::showFactoryRst(void) { void Main::showFactoryRst(void) {
#ifdef DEBUG_HMMAIN
DPRINTLN(F("Main::showFactoryRst")); DPRINTLN(F("Main::showFactoryRst"));
#endif
String content = ""; String content = "";
int refresh = 3; int refresh = 3;
if(mWeb->args() > 0) { if(mWeb->args() > 0) {
@ -376,7 +410,9 @@ void Main::showFactoryRst(void) {
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
time_t Main::getNtpTime(void) { time_t Main::getNtpTime(void) {
#ifdef DEBUG_HMMAIN
//DPRINTLN(F("Main::getNtpTime")); //DPRINTLN(F("Main::getNtpTime"));
#endif
time_t date = 0; time_t date = 0;
IPAddress timeServer; IPAddress timeServer;
uint8_t buf[NTP_PACKET_SIZE]; uint8_t buf[NTP_PACKET_SIZE];
@ -414,7 +450,9 @@ time_t Main::getNtpTime(void) {
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void Main::sendNTPpacket(IPAddress& address) { void Main::sendNTPpacket(IPAddress& address) {
#ifdef DEBUG_HMMAIN
//DPRINTLN(F("Main::sendNTPpacket")); //DPRINTLN(F("Main::sendNTPpacket"));
#endif
uint8_t buf[NTP_PACKET_SIZE] = {0}; uint8_t buf[NTP_PACKET_SIZE] = {0};
buf[0] = B11100011; // LI, Version, Mode buf[0] = B11100011; // LI, Version, Mode
@ -435,7 +473,9 @@ void Main::sendNTPpacket(IPAddress& address) {
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
String Main::getDateTimeStr(time_t t) { String Main::getDateTimeStr(time_t t) {
#ifdef DEBUG_HMMAIN
//DPRINTLN(F("Main::getDateTimeStr")); //DPRINTLN(F("Main::getDateTimeStr"));
#endif
char str[20] = {0}; char str[20] = {0};
if(0 == t) if(0 == t)
sprintf(str, "n/a"); sprintf(str, "n/a");
@ -449,7 +489,9 @@ String Main::getDateTimeStr(time_t t) {
// calculates the daylight saving time for middle Europe. Input: Unixtime in UTC // calculates the daylight saving time for middle Europe. Input: Unixtime in UTC
// from: https://forum.arduino.cc/index.php?topic=172044.msg1278536#msg1278536 // from: https://forum.arduino.cc/index.php?topic=172044.msg1278536#msg1278536
time_t Main::offsetDayLightSaving (uint32_t local_t) { time_t Main::offsetDayLightSaving (uint32_t local_t) {
#ifdef DEBUG_HMMAIN
//DPRINTLN(F("Main::offsetDayLightSaving")); //DPRINTLN(F("Main::offsetDayLightSaving"));
#endif
int m = month (local_t); int m = month (local_t);
if(m < 3 || m > 10) return 0; // no DSL in Jan, Feb, Nov, Dez if(m < 3 || m > 10) return 0; // no DSL in Jan, Feb, Nov, Dez
if(m > 3 && m < 10) return 1; // DSL in Apr, May, Jun, Jul, Aug, Sep if(m > 3 && m < 10) return 1; // DSL in Apr, May, Jun, Jul, Aug, Sep

12
tools/esp8266/main.h

@ -41,7 +41,9 @@ class Main {
virtual void updateCrc(void); virtual void updateCrc(void);
inline uint16_t buildEEpCrc(uint32_t start, uint32_t length) { inline uint16_t buildEEpCrc(uint32_t start, uint32_t length) {
#ifdef DEBUG_HMMAIN
DPRINTLN(F("main.h:buildEEpCrc")); DPRINTLN(F("main.h:buildEEpCrc"));
#endif
uint8_t buf[32]; uint8_t buf[32];
uint16_t crc = 0xffff; uint16_t crc = 0xffff;
uint8_t len; uint8_t len;
@ -57,16 +59,22 @@ class Main {
} }
bool checkEEpCrc(uint32_t start, uint32_t length, uint32_t crcPos) { bool checkEEpCrc(uint32_t start, uint32_t length, uint32_t crcPos) {
#ifdef DEBUG_HMMAIN
//DPRINTLN(F("main.h:checkEEpCrc")); //DPRINTLN(F("main.h:checkEEpCrc"));
#endif
uint16_t crcRd, crcCheck; uint16_t crcRd, crcCheck;
crcCheck = buildEEpCrc(start, length); crcCheck = buildEEpCrc(start, length);
mEep->read(crcPos, &crcRd); mEep->read(crcPos, &crcRd);
#ifdef DEBUG_HMMAIN
//DPRINTLN("CRC RD: " + String(crcRd, HEX) + " CRC CALC: " + String(crcCheck, HEX)); //DPRINTLN("CRC RD: " + String(crcRd, HEX) + " CRC CALC: " + String(crcCheck, HEX));
#endif
return (crcCheck == crcRd); return (crcCheck == crcRd);
} }
void eraseSettings(bool all = false) { void eraseSettings(bool all = false) {
#ifdef DEBUG_HMMAIN
//DPRINTLN(F("main.h:eraseSettings")); //DPRINTLN(F("main.h:eraseSettings"));
#endif
uint8_t buf[64] = {0}; uint8_t buf[64] = {0};
uint16_t addr = (all) ? ADDR_START : ADDR_START_SETTINGS; uint16_t addr = (all) ? ADDR_START : ADDR_START_SETTINGS;
uint16_t end; uint16_t end;
@ -82,7 +90,9 @@ class Main {
} }
inline bool checkTicker(uint32_t *ticker, uint32_t interval) { inline bool checkTicker(uint32_t *ticker, uint32_t interval) {
#ifdef DEBUG_HMMAIN
//DPRINT(F("c")); //DPRINT(F("c"));
#endif
uint32_t mil = millis(); uint32_t mil = millis();
if(mil >= *ticker) { if(mil >= *ticker) {
*ticker = mil + interval; *ticker = mil + interval;
@ -97,7 +107,9 @@ class Main {
} }
void stats(void) { void stats(void) {
#ifdef DEBUG_HMMAIN
DPRINTLN(F("main.h:stats")); DPRINTLN(F("main.h:stats"));
#endif
uint32_t free; uint32_t free;
uint16_t max; uint16_t max;
uint8_t frag; uint8_t frag;

Loading…
Cancel
Save