Browse Source

added DBGXXX definitions to all header files

pull/76/head
stefan123t 3 years ago
parent
commit
17b186ee04
  1. 6
      tools/esp8266/app.h
  2. 80
      tools/esp8266/hmInverter.h
  3. 54
      tools/esp8266/hmRadio.h
  4. 26
      tools/esp8266/hmSystem.h
  5. 80
      tools/esp8266/main.cpp
  6. 29
      tools/esp8266/main.h

6
tools/esp8266/app.h

@ -11,6 +11,12 @@
#include "hmSystem.h"
#include "mqtt.h"
#ifdef DEBUG_APP
#define DBGAPP(f,...) do { Serial.printf(PSTR(f), ##__VA_ARGS__); } while (0)
#else
#define DBGAPP(x...) do { (void)0; } while (0)
#endif
typedef CircularBuffer<packet_t, PACKET_BUFFER_SIZE> BufferType;
typedef HmRadio<RF24_CE_PIN, RF24_CS_PIN, RF24_IRQ_PIN, BufferType> RadioType;
typedef Inverter<float> InverterType;

80
tools/esp8266/hmInverter.h

@ -3,6 +3,12 @@
#include "hmDefines.h"
#ifdef DEBUG_HMINVERTER
#define DBGINV(f,...) do { Serial.printf(PSTR(f), ##__VA_ARGS__); } while (0)
#else
#define DBGINV(x...) do { (void)0; } while (0)
#endif
/**
* For values which are of interest and not transmitted by the inverter can be
* calculated automatically.
@ -82,9 +88,7 @@ class Inverter {
}
void init(void) {
#ifdef DEBUG_HMINVERTER
DPRINTLN(F("hmInverter.h:init"));
#endif
DBGINV(F("hmInverter.h:init"));
getAssignment();
toRadioId();
record = new RECORDTYPE[listLen];
@ -94,9 +98,7 @@ class Inverter {
}
uint8_t getPosByChFld(uint8_t channel, uint8_t fieldId) {
#ifdef DEBUG_HMINVERTER
//DPRINTLN(F("hmInverter.h:getPosByChFld"));
#endif
//DBGINV(F("hmInverter.h:getPosByChFld"));
uint8_t pos = 0;
for(; pos < listLen; pos++) {
if((assign[pos].ch == channel) && (assign[pos].fieldId == fieldId))
@ -106,30 +108,22 @@ class Inverter {
}
const char *getFieldName(uint8_t pos) {
#ifdef DEBUG_HMINVERTER
//DPRINTLN(F("hmInverter.h:getFieldName"));
#endif
//DBGINV(F("hmInverter.h:getFieldName"));
return fields[assign[pos].fieldId];
}
const char *getUnit(uint8_t pos) {
#ifdef DEBUG_HMINVERTER
//DPRINTLN(F("hmInverter.h:getUnit"));
#endif
//DBGINV(F("hmInverter.h:getUnit"));
return units[assign[pos].unitId];
}
uint8_t getChannel(uint8_t pos) {
#ifdef DEBUG_HMINVERTER
//DPRINTLN(F("hmInverter.h:getChannel"));
#endif
//DBGINV(F("hmInverter.h:getChannel"));
return assign[pos].ch;
}
void addValue(uint8_t pos, uint8_t buf[]) {
#ifdef DEBUG_HMINVERTER
//DPRINTLN(F("hmInverter.h:addValue"));
#endif
//DBGINV(F("hmInverter.h:addValue"));
uint8_t ptr = assign[pos].start;
uint8_t end = ptr + assign[pos].num;
uint16_t div = assign[pos].div;
@ -146,16 +140,12 @@ class Inverter {
}
RECORDTYPE getValue(uint8_t pos) {
#ifdef DEBUG_HMINVERTER
//DPRINTLN(F("hmInverter.h:getValue"));
#endif
//DBGINV(F("hmInverter.h:getValue"));
return record[pos];
}
void doCalculations(void) {
#ifdef DEBUG_HMINVERTER
//DPRINTLN(F("hmInverter.h:doCalculations"));
#endif
//DBGINV(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);
@ -164,14 +154,12 @@ class Inverter {
}
bool isAvailable(uint32_t timestamp) {
#ifdef DEBUG_HMINVERTER
//DPRINTLN(F("hmInverter.h:isAvailable"));
#endif
//DBGINV(F("hmInverter.h:isAvailable"));
return ((timestamp - ts) < INACT_THRES_SEC);
}
bool isProducing(uint32_t timestamp) {
//DPRINTLN(F("hmInverter.h:isProducing"));
//DBGINV(F("hmInverter.h:isProducing"));
if(isAvailable(timestamp)) {
uint8_t pos = getPosByChFld(CH0, FLD_PAC);
return (getValue(pos) > INACT_PWR_THRESH);
@ -180,17 +168,13 @@ class Inverter {
}
uint32_t getLastTs(void) {
#ifdef DEBUG_HMINVERTER
//DPRINTLN(F("hmInverter.h:getLastTs"));
#endif
//DBGINV(F("hmInverter.h:getLastTs"));
return ts;
}
private:
void toRadioId(void) {
#ifdef DEBUG_HMINVERTER
//DPRINTLN(F("hmInverter.h:toRadioId"));
#endif
//DBGINV(F("hmInverter.h:toRadioId"));
radioId.u64 = 0ULL;
radioId.b[4] = serial.b[0];
radioId.b[3] = serial.b[1];
@ -200,9 +184,7 @@ class Inverter {
}
void getAssignment(void) {
#ifdef DEBUG_HMINVERTER
//DPRINTLN(F("hmInverter.h:getAssignment"));
#endif
//DBGINV(F("hmInverter.h:getAssignment"));
if(INV_TYPE_1CH == type) {
listLen = (uint8_t)(HM1CH_LIST_LEN);
assign = (byteAssign_t*)hm1chAssignment;
@ -235,9 +217,7 @@ class Inverter {
template<class T=float>
static T calcYieldTotalCh0(Inverter<> *iv, uint8_t arg0) {
#ifdef DEBUG_HMINVERTER
//DPRINTLN(F("hmInverter.h:calcYieldTotalCh0"));
#endif
//DBGINV(F("hmInverter.h:calcYieldTotalCh0"));
if(NULL != iv) {
T yield = 0;
for(uint8_t i = 1; i <= iv->channels; i++) {
@ -251,9 +231,7 @@ 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
//DBGINV(F("hmInverter.h:calcYieldDayCh0"));
if(NULL != iv) {
T yield = 0;
for(uint8_t i = 1; i <= iv->channels; i++) {
@ -267,9 +245,7 @@ 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
//DBGINV(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)) {
@ -282,9 +258,7 @@ 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
//DBGINV(F("hmInverter.h:calcPowerDcCh0"));
if(NULL != iv) {
T dcPower = 0;
for(uint8_t i = 1; i <= iv->channels; i++) {
@ -298,9 +272,7 @@ 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
//DBGINV(F("hmInverter.h:calcEfficiencyCh0"));
if(NULL != iv) {
uint8_t pos = iv->getPosByChFld(CH0, FLD_PAC);
T acPower = iv->getValue(pos);
@ -317,9 +289,7 @@ 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
//DBGINV(F("hmInverter.h:calcIrradiation"));
// arg0 = channel
if(NULL != iv) {
uint8_t pos = iv->getPosByChFld(arg0, FLD_PDC);

54
tools/esp8266/hmRadio.h

@ -17,6 +17,12 @@
#define RX_LOOP_CNT 300
#ifdef DEBUG_HMRADIO
#define DBGHMR(f,...) do { Serial.printf(PSTR(f), ##__VA_ARGS__); } while (0)
#else
#define DBGHMR(x...) do { (void)0; } while (0)
#endif
const char* const rf24AmpPower[] = {"MIN", "LOW", "HIGH", "MAX"};
@ -49,9 +55,7 @@ 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
DBGHMR(F("hmRadio.h : HmRadio():mNrf24(CE_PIN: ") + String(CE_PIN) + F(", CS_PIN: ") + String(CS_PIN) + F(", SPI_SPEED: ") + String(SPI_SPEED) + ")");
mTxChLst[0] = 40;
//mTxChIdx = 1;
@ -78,9 +82,7 @@ class HmRadio {
~HmRadio() {}
void setup(BUFFER *ctrl) {
#ifdef DEBUG_HMRADIO
DPRINTLN(F("hmRadio.h:setup"));
#endif
DBGHMR(F("hmRadio.h:setup"));
pinMode(pinIrq, INPUT_PULLUP);
mBufCtrl = ctrl;
@ -145,16 +147,12 @@ class HmRadio {
}
void handleIntr(void) {
#ifdef DEBUG_HMRADIO
//DPRINTLN(F("hmRadio.h:handleIntr"));
#endif
//DBGHMR(F("hmRadio.h:handleIntr"));
mIrqRcvd = true;
}
uint8_t getDefaultChannel(void) {
#ifdef DEBUG_HMRADIO
//DPRINTLN(F("hmRadio.h:getDefaultChannel"));
#endif
//DBGHMR(F("hmRadio.h:getDefaultChannel"));
return mTxChLst[0];
}
/*uint8_t getLastChannel(void) {
@ -168,9 +166,7 @@ class HmRadio {
}*/
void sendTimePacket(uint64_t invId, uint32_t ts) {
#ifdef DEBUG_HMRADIO
//DPRINTLN(F("hmRadio.h:sendTimePacket"));
#endif
//DBGHMR(F("hmRadio.h:sendTimePacket"));
sendCmdPacket(invId, 0x15, 0x80, false);
mTxBuf[10] = 0x0b; // cid
mTxBuf[11] = 0x00;
@ -186,9 +182,7 @@ 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
//DBGHMR(F("hmRadio.h:sendCmdPacket"));
memset(mTxBuf, 0, MAX_RF_PAYLOAD_SIZE);
mTxBuf[0] = mid; // message id
CP_U32_BigEndian(&mTxBuf[1], (invId >> 8));
@ -201,9 +195,7 @@ class HmRadio {
}
bool checkPaketCrc(uint8_t buf[], uint8_t *len, uint8_t rxCh) {
#ifdef DEBUG_HMRADIO
//DPRINTLN(F("hmRadio.h:checkPaketCrc"));
#endif
//DBGHMR(F("hmRadio.h:checkPaketCrc"));
*len = (buf[0] >> 2);
if(*len > (MAX_RF_PAYLOAD_SIZE - 2))
*len = MAX_RF_PAYLOAD_SIZE - 2;
@ -218,10 +210,8 @@ class HmRadio {
}
bool switchRxCh(uint16_t addLoop = 0) {
#ifdef DEBUG_HMRADIO
//DPRINTLN(F("hmRadio.h:switchRxCh"));
//DPRINT(F("R"));
#endif
//DBGHMR(F("hmRadio.h:switchRxCh"));
//DBGHMR(F("R"));
mRxLoopCnt += addLoop;
if(mRxLoopCnt != 0) {
@ -236,9 +226,7 @@ class HmRadio {
}
void dumpBuf(const char *info, uint8_t buf[], uint8_t len) {
#ifdef DEBUG_HMRADIO
//DPRINTLN(F("hmRadio.h:dumpBuf"));
#endif
//DBGHMR(F("hmRadio.h:dumpBuf"));
if(NULL != info)
DPRINT(String(info));
for(uint8_t i = 0; i < len; i++) {
@ -249,9 +237,7 @@ class HmRadio {
}
bool isChipConnected(void) {
#ifdef DEBUG_HMRADIO
//DPRINTLN(F("hmRadio.h:isChipConnected"));
#endif
//DBGHMR(F("hmRadio.h:isChipConnected"));
return mNrf24.isChipConnected();
}
@ -266,11 +252,9 @@ 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));
//DBGHMR(F("hmRadio.h:sendPacket"));
//DBGHMR("sent packet: #" + String(mSendCnt));
//dumpBuf("SEN ", buf, len);
#endif
if(mSerialDebug) {
DPRINT("Transmit " + String(len) + " | ");
dumpBuf(NULL, buf, len);

26
tools/esp8266/hmSystem.h

@ -6,7 +6,11 @@
#include "hmRadio.h"
#endif
#ifdef DEBUG_HMSYSTEM
#define DBGHMS(f,...) do { Serial.printf(PSTR(f), ##__VA_ARGS__); } while (0)
#else
#define DBGHMS(x...) do { (void)0; } while (0)
#endif
template <class RADIO, class BUFFER, uint8_t MAX_INVERTER=3, class INVERTERTYPE=Inverter<float>>
class HmSystem {
@ -24,16 +28,12 @@ class HmSystem {
}
void setup() {
#ifdef DEBUG_HMSYSTEM
DPRINTLN(F("hmSystem.h:setup"));
#endif
DBGHMS(F("hmSystem.h:setup"));
Radio.setup(&BufCtrl);
}
INVERTERTYPE *addInverter(const char *name, uint64_t serial, uint16_t chMaxPwr[]) {
#ifdef DEBUG_HMSYSTEM
DPRINTLN(F("hmSystem.h:addInverter"));
#endif
DBGHMS(F("hmSystem.h:addInverter"));
if(MAX_INVERTER <= mNumInv) {
DPRINT(F("max number of inverters reached!"));
return NULL;
@ -70,9 +70,7 @@ class HmSystem {
}
INVERTERTYPE *findInverter(uint8_t buf[]) {
#ifdef DEBUG_HMSYSTEM
//DPRINTLN(F("hmSystem.h:findInverter"));
#endif
//DBGHMS(F("hmSystem.h:findInverter"));
INVERTERTYPE *p;
for(uint8_t i = 0; i < mNumInv; i++) {
p = &mInverter[i];
@ -86,9 +84,7 @@ class HmSystem {
}
INVERTERTYPE *getInverterByPos(uint8_t pos) {
#ifdef DEBUG_HMSYSTEM
//DPRINTLN(F("hmSystem.h:getInverterByPos"));
#endif
//DBGHMS(F("hmSystem.h:getInverterByPos"));
if(mInverter[pos].serial.u64 != 0ULL)
return &mInverter[pos];
else
@ -96,9 +92,7 @@ class HmSystem {
}
uint8_t getNumInverters(void) {
#ifdef DEBUG_HMSYSTEM
//DPRINTLN(F("hmSystem.h:getNumInverters"));
#endif
//DBGHMS(F("hmSystem.h:getNumInverters"));
return mNumInv;
}

80
tools/esp8266/main.cpp

@ -26,9 +26,7 @@ Main::Main(void) {
mEep = new eep();
Serial.begin(115200);
#ifdef DEBUG_HMMAIN
DPRINTLN(F("Main::Main"));
#endif
DBGMAIN(F("Main::Main"));
mUptimeSecs = 0;
mUptimeTicker = 0xffffffff;
@ -42,9 +40,7 @@ Main::Main(void) {
//-----------------------------------------------------------------------------
void Main::setup(uint32_t timeout) {
#ifdef DEBUG_HMMAIN
DPRINTLN(F("Main::setup"));
#endif
DBGMAIN(F("Main::setup"));
bool startAp = mApActive;
mLimit = timeout;
@ -73,9 +69,7 @@ void Main::setup(uint32_t timeout) {
//-----------------------------------------------------------------------------
void Main::loop(void) {
#ifdef DEBUG_HMMAIN
//DPRINT(F("M"));
#endif
//DBGMAIN(F("M"));
if(mApActive) {
mDns->processNextRequest();
#ifndef AP_ONLY
@ -124,9 +118,7 @@ void Main::loop(void) {
//-----------------------------------------------------------------------------
bool Main::getConfig(void) {
#ifdef DEBUG_HMMAIN
DPRINTLN(F("Main::getConfig"));
#endif
DBGMAIN(F("Main::getConfig"));
bool mApActive = false;
mWifiSettingsValid = checkEEpCrc(ADDR_START, ADDR_WIFI_CRC, ADDR_WIFI_CRC);
@ -149,9 +141,7 @@ bool Main::getConfig(void) {
//-----------------------------------------------------------------------------
void Main::setupAp(const char *ssid, const char *pwd) {
#ifdef DEBUG_HMMAIN
DPRINTLN(F("Main::setupAp"));
#endif
DBGMAIN(F("Main::setupAp"));
IPAddress apIp(192, 168, 1, 1);
DPRINTLN(F("\n---------\nAP MODE\nSSDI: ")
@ -159,9 +149,7 @@ 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
DBGMAIN("DBG: " + String(mNextTryTs));
WiFi.mode(WIFI_AP);
WiFi.softAPConfig(apIp, apIp, IPAddress(255, 255, 255, 0));
@ -180,9 +168,7 @@ void Main::setupAp(const char *ssid, const char *pwd) {
//-----------------------------------------------------------------------------
bool Main::setupStation(uint32_t timeout) {
#ifdef DEBUG_HMMAIN
DPRINTLN(F("Main::setupStation"));
#endif
DBGMAIN(F("Main::setupStation"));
int32_t cnt;
bool startAp = false;
@ -232,9 +218,7 @@ bool Main::setupStation(uint32_t timeout) {
//-----------------------------------------------------------------------------
void Main::showSetup(void) {
#ifdef DEBUG_HMMAIN
DPRINTLN(F("Main::showSetup"));
#endif
DBGMAIN(F("Main::showSetup"));
String html = FPSTR(setup_html);
html.replace(F("{SSID}"), mStationSsid);
// PWD will be left at the default value (for protection)
@ -252,9 +236,7 @@ void Main::showSetup(void) {
//-----------------------------------------------------------------------------
void Main::showCss(void) {
#ifdef DEBUG_HMMAIN
DPRINTLN(F("Main::showCss"));
#endif
DBGMAIN(F("Main::showCss"));
mWeb->send(200, "text/css", FPSTR(style_css));
}
@ -270,9 +252,7 @@ void Main::showSave(void) {
//-----------------------------------------------------------------------------
void Main::saveValues(bool webSend = true) {
#ifdef DEBUG_HMMAIN
DPRINTLN(F("Main::saveValues"));
#endif
DBGMAIN(F("Main::saveValues"));
if(mWeb->args() > 0) {
if(mWeb->arg("ssid") != "") {
memset(mStationSsid, 0, SSID_LEN);
@ -306,9 +286,7 @@ void Main::saveValues(bool webSend = true) {
//-----------------------------------------------------------------------------
void Main::updateCrc(void) {
#ifdef DEBUG_HMMAIN
DPRINTLN(F("Main::updateCrc"));
#endif
DBGMAIN(F("Main::updateCrc"));
uint16_t crc;
crc = buildEEpCrc(ADDR_START, ADDR_WIFI_CRC);
//Serial.println("new CRC: " + String(crc, HEX));
@ -319,9 +297,7 @@ void Main::updateCrc(void) {
//-----------------------------------------------------------------------------
void Main::showUptime(void) {
#ifdef DEBUG_HMMAIN
//DPRINTLN(F("Main::showUptime"));
#endif
//DBGMAIN(F("Main::showUptime"));
char time[20] = {0};
int upTimeSc = uint32_t((mUptimeSecs) % 60);
@ -337,18 +313,14 @@ void Main::showUptime(void) {
//-----------------------------------------------------------------------------
void Main::showTime(void) {
#ifdef DEBUG_HMMAIN
//DPRINTLN(F("Main::showTime"));
#endif
//DBGMAIN(F("Main::showTime"));
mWeb->send(200, "text/plain", getDateTimeStr(mTimestamp));
}
//-----------------------------------------------------------------------------
void Main::showNotFound(void) {
#ifdef DEBUG_HMMAIN
DPRINTLN(F("Main::showNotFound - ") + mWeb->uri());
#endif
DBGMAIN(F("Main::showNotFound - ") + mWeb->uri());
String msg = F("File Not Found\n\nURI: ");
msg += mWeb->uri();
msg += F("\nMethod: ");
@ -367,9 +339,7 @@ void Main::showNotFound(void) {
//-----------------------------------------------------------------------------
void Main::showReboot(void) {
#ifdef DEBUG_HMMAIN
DPRINTLN(F("Main::showReboot"));
#endif
DBGMAIN(F("Main::showReboot"));
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();
@ -379,9 +349,7 @@ void Main::showReboot(void) {
//-----------------------------------------------------------------------------
void Main::showFactoryRst(void) {
#ifdef DEBUG_HMMAIN
DPRINTLN(F("Main::showFactoryRst"));
#endif
DBGMAIN(F("Main::showFactoryRst"));
String content = "";
int refresh = 3;
if(mWeb->args() > 0) {
@ -410,9 +378,7 @@ void Main::showFactoryRst(void) {
//-----------------------------------------------------------------------------
time_t Main::getNtpTime(void) {
#ifdef DEBUG_HMMAIN
//DPRINTLN(F("Main::getNtpTime"));
#endif
//DBGMAIN(F("Main::getNtpTime"));
time_t date = 0;
IPAddress timeServer;
uint8_t buf[NTP_PACKET_SIZE];
@ -450,9 +416,7 @@ time_t Main::getNtpTime(void) {
//-----------------------------------------------------------------------------
void Main::sendNTPpacket(IPAddress& address) {
#ifdef DEBUG_HMMAIN
//DPRINTLN(F("Main::sendNTPpacket"));
#endif
//DBGMAIN(F("Main::sendNTPpacket"));
uint8_t buf[NTP_PACKET_SIZE] = {0};
buf[0] = B11100011; // LI, Version, Mode
@ -473,9 +437,7 @@ void Main::sendNTPpacket(IPAddress& address) {
//-----------------------------------------------------------------------------
String Main::getDateTimeStr(time_t t) {
#ifdef DEBUG_HMMAIN
//DPRINTLN(F("Main::getDateTimeStr"));
#endif
//DBGMAIN(F("Main::getDateTimeStr"));
char str[20] = {0};
if(0 == t)
sprintf(str, "n/a");
@ -489,9 +451,7 @@ 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
//DBGMAIN(F("Main::offsetDayLightSaving"));
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

29
tools/esp8266/main.h

@ -18,6 +18,11 @@
#include "crc.h"
#include "debug.h"
#ifdef DEBUG_HMMAIN
#define DBGMAIN(f,...) do { Serial.printf(PSTR(f), ##__VA_ARGS__); } while (0)
#else
#define DBGMAIN(x...) do { (void)0; } while (0)
#endif
const byte mDnsPort = 53;
@ -41,9 +46,7 @@ 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
DBGMAIN(F("main.h:buildEEpCrc"));
uint8_t buf[32];
uint16_t crc = 0xffff;
uint8_t len;
@ -59,22 +62,16 @@ class Main {
}
bool checkEEpCrc(uint32_t start, uint32_t length, uint32_t crcPos) {
#ifdef DEBUG_HMMAIN
//DPRINTLN(F("main.h:checkEEpCrc"));
#endif
//DBGMAIN(F("main.h:checkEEpCrc"));
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
//DBGMAIN("CRC RD: " + String(crcRd, HEX) + " CRC CALC: " + String(crcCheck, HEX));
return (crcCheck == crcRd);
}
void eraseSettings(bool all = false) {
#ifdef DEBUG_HMMAIN
//DPRINTLN(F("main.h:eraseSettings"));
#endif
//DBGMAIN(F("main.h:eraseSettings"));
uint8_t buf[64] = {0};
uint16_t addr = (all) ? ADDR_START : ADDR_START_SETTINGS;
uint16_t end;
@ -90,9 +87,7 @@ class Main {
}
inline bool checkTicker(uint32_t *ticker, uint32_t interval) {
#ifdef DEBUG_HMMAIN
//DPRINT(F("c"));
#endif
//DBGMAIN(F("c"));
uint32_t mil = millis();
if(mil >= *ticker) {
*ticker = mil + interval;
@ -107,9 +102,7 @@ class Main {
}
void stats(void) {
#ifdef DEBUG_HMMAIN
DPRINTLN(F("main.h:stats"));
#endif
DBGMAIN(F("main.h:stats"));
uint32_t free;
uint16_t max;
uint8_t frag;

Loading…
Cancel
Save