Browse Source

added DEBUG_FLAGs to config.h

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

7
tools/esp8266/config.h

@ -53,4 +53,11 @@
// changes the style of "/setup" page, visualized = nicer
#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__*/

36
tools/esp8266/hmInverter.h

@ -82,7 +82,9 @@ class Inverter {
}
void init(void) {
#ifdef DEBUG_HMINVERTER
DPRINTLN(F("hmInverter.h:init"));
#endif
getAssignment();
toRadioId();
record = new RECORDTYPE[listLen];
@ -92,7 +94,9 @@ class Inverter {
}
uint8_t getPosByChFld(uint8_t channel, uint8_t fieldId) {
#ifdef DEBUG_HMINVERTER
//DPRINTLN(F("hmInverter.h:getPosByChFld"));
#endif
uint8_t pos = 0;
for(; pos < listLen; pos++) {
if((assign[pos].ch == channel) && (assign[pos].fieldId == fieldId))
@ -102,22 +106,30 @@ class Inverter {
}
const char *getFieldName(uint8_t pos) {
#ifdef DEBUG_HMINVERTER
//DPRINTLN(F("hmInverter.h:getFieldName"));
#endif
return fields[assign[pos].fieldId];
}
const char *getUnit(uint8_t pos) {
#ifdef DEBUG_HMINVERTER
//DPRINTLN(F("hmInverter.h:getUnit"));
#endif
return units[assign[pos].unitId];
}
uint8_t getChannel(uint8_t pos) {
#ifdef DEBUG_HMINVERTER
//DPRINTLN(F("hmInverter.h:getChannel"));
#endif
return assign[pos].ch;
}
void addValue(uint8_t pos, uint8_t buf[]) {
#ifdef DEBUG_HMINVERTER
//DPRINTLN(F("hmInverter.h:addValue"));
#endif
uint8_t ptr = assign[pos].start;
uint8_t end = ptr + assign[pos].num;
uint16_t div = assign[pos].div;
@ -134,12 +146,16 @@ class Inverter {
}
RECORDTYPE getValue(uint8_t pos) {
#ifdef DEBUG_HMINVERTER
//DPRINTLN(F("hmInverter.h:getValue"));
#endif
return record[pos];
}
void doCalculations(void) {
#ifdef DEBUG_HMINVERTER
//DPRINTLN(F("hmInverter.h:doCalculations"));
#endif
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);
@ -148,7 +164,9 @@ class Inverter {
}
bool isAvailable(uint32_t timestamp) {
#ifdef DEBUG_HMINVERTER
//DPRINTLN(F("hmInverter.h:isAvailable"));
#endif
return ((timestamp - ts) < INACT_THRES_SEC);
}
@ -162,13 +180,17 @@ class Inverter {
}
uint32_t getLastTs(void) {
#ifdef DEBUG_HMINVERTER
//DPRINTLN(F("hmInverter.h:getLastTs"));
#endif
return ts;
}
private:
void toRadioId(void) {
#ifdef DEBUG_HMINVERTER
//DPRINTLN(F("hmInverter.h:toRadioId"));
#endif
radioId.u64 = 0ULL;
radioId.b[4] = serial.b[0];
radioId.b[3] = serial.b[1];
@ -178,7 +200,9 @@ class Inverter {
}
void getAssignment(void) {
#ifdef DEBUG_HMINVERTER
//DPRINTLN(F("hmInverter.h:getAssignment"));
#endif
if(INV_TYPE_1CH == type) {
listLen = (uint8_t)(HM1CH_LIST_LEN);
assign = (byteAssign_t*)hm1chAssignment;
@ -211,7 +235,9 @@ class Inverter {
template<class T=float>
static T calcYieldTotalCh0(Inverter<> *iv, uint8_t arg0) {
#ifdef DEBUG_HMINVERTER
//DPRINTLN(F("hmInverter.h:calcYieldTotalCh0"));
#endif
if(NULL != iv) {
T yield = 0;
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>
static T calcYieldDayCh0(Inverter<> *iv, uint8_t arg0) {
#ifdef DEBUG_HMINVERTER
//DPRINTLN(F("hmInverter.h:calcYieldDayCh0"));
#endif
if(NULL != iv) {
T yield = 0;
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>
static T calcUdcCh(Inverter<> *iv, uint8_t arg0) {
#ifdef DEBUG_HMINVERTER
//DPRINTLN(F("hmInverter.h:calcUdcCh"));
#endif
// 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)) {
@ -252,7 +282,9 @@ static T calcUdcCh(Inverter<> *iv, uint8_t arg0) {
template<class T=float>
static T calcPowerDcCh0(Inverter<> *iv, uint8_t arg0) {
#ifdef DEBUG_HMINVERTER
//DPRINTLN(F("hmInverter.h:calcPowerDcCh0"));
#endif
if(NULL != iv) {
T dcPower = 0;
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>
static T calcEffiencyCh0(Inverter<> *iv, uint8_t arg0) {
#ifdef DEBUG_HMINVERTER
//DPRINTLN(F("hmInverter.h:calcEfficiencyCh0"));
#endif
if(NULL != iv) {
uint8_t pos = iv->getPosByChFld(CH0, FLD_PAC);
T acPower = iv->getValue(pos);
@ -283,7 +317,9 @@ static T calcEffiencyCh0(Inverter<> *iv, uint8_t arg0) {
template<class T=float>
static T calcIrradiation(Inverter<> *iv, uint8_t arg0) {
#ifdef DEBUG_HMINVERTER
//DPRINTLN(F("hmInverter.h:calcIrradiation"));
#endif
// arg0 = channel
if(NULL != iv) {
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 {
public:
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) + ")");
#endif
mTxChLst[0] = 40;
//mTxChIdx = 1;
@ -76,7 +78,9 @@ class HmRadio {
~HmRadio() {}
void setup(BUFFER *ctrl) {
#ifdef DEBUG_HMRADIO
DPRINTLN(F("hmRadio.h:setup"));
#endif
pinMode(pinIrq, INPUT_PULLUP);
mBufCtrl = ctrl;
@ -141,12 +145,16 @@ class HmRadio {
}
void handleIntr(void) {
#ifdef DEBUG_HMRADIO
//DPRINTLN(F("hmRadio.h:handleIntr"));
#endif
mIrqRcvd = true;
}
uint8_t getDefaultChannel(void) {
#ifdef DEBUG_HMRADIO
//DPRINTLN(F("hmRadio.h:getDefaultChannel"));
#endif
return mTxChLst[0];
}
/*uint8_t getLastChannel(void) {
@ -160,7 +168,9 @@ class HmRadio {
}*/
void sendTimePacket(uint64_t invId, uint32_t ts) {
#ifdef DEBUG_HMRADIO
//DPRINTLN(F("hmRadio.h:sendTimePacket"));
#endif
sendCmdPacket(invId, 0x15, 0x80, false);
mTxBuf[10] = 0x0b; // cid
mTxBuf[11] = 0x00;
@ -176,7 +186,9 @@ class HmRadio {
}
void sendCmdPacket(uint64_t invId, uint8_t mid, uint8_t pid, bool calcCrc = true) {
#ifdef DEBUG_HMRADIO
//DPRINTLN(F("hmRadio.h:sendCmdPacket"));
#endif
memset(mTxBuf, 0, MAX_RF_PAYLOAD_SIZE);
mTxBuf[0] = mid; // message id
CP_U32_BigEndian(&mTxBuf[1], (invId >> 8));
@ -189,7 +201,9 @@ class HmRadio {
}
bool checkPaketCrc(uint8_t buf[], uint8_t *len, uint8_t rxCh) {
#ifdef DEBUG_HMRADIO
//DPRINTLN(F("hmRadio.h:checkPaketCrc"));
#endif
*len = (buf[0] >> 2);
if(*len > (MAX_RF_PAYLOAD_SIZE - 2))
*len = MAX_RF_PAYLOAD_SIZE - 2;
@ -204,8 +218,10 @@ class HmRadio {
}
bool switchRxCh(uint16_t addLoop = 0) {
#ifdef DEBUG_HMRADIO
//DPRINTLN(F("hmRadio.h:switchRxCh"));
//DPRINT(F("R"));
#endif
mRxLoopCnt += addLoop;
if(mRxLoopCnt != 0) {
@ -220,7 +236,9 @@ class HmRadio {
}
void dumpBuf(const char *info, uint8_t buf[], uint8_t len) {
#ifdef DEBUG_HMRADIO
//DPRINTLN(F("hmRadio.h:dumpBuf"));
#endif
if(NULL != info)
DPRINT(String(info));
for(uint8_t i = 0; i < len; i++) {
@ -231,7 +249,9 @@ class HmRadio {
}
bool isChipConnected(void) {
#ifdef DEBUG_HMRADIO
//DPRINTLN(F("hmRadio.h:isChipConnected"));
#endif
return mNrf24.isChipConnected();
}
@ -246,9 +266,11 @@ class HmRadio {
private:
void sendPacket(uint64_t invId, uint8_t buf[], uint8_t len, bool clear=false) {
#ifdef DEBUG_HMRADIO
//DPRINTLN(F("hmRadio.h:sendPacket"));
//DPRINTLN("sent packet: #" + String(mSendCnt));
//dumpBuf("SEN ", buf, len);
#endif
if(mSerialDebug) {
DPRINT("Transmit " + String(len) + " | ");
dumpBuf(NULL, buf, len);

10
tools/esp8266/hmSystem.h

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

42
tools/esp8266/main.cpp

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

12
tools/esp8266/main.h

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

Loading…
Cancel
Save