Browse Source

add method entry debug statements

pull/63/head
Stefan Thieme 3 years ago
parent
commit
b1906f0f31
  1. 21
      tools/esp8266/app.cpp
  2. 1
      tools/esp8266/app.h
  3. 19
      tools/esp8266/hmInverter.h
  4. 11
      tools/esp8266/hmRadio.h
  5. 5
      tools/esp8266/hmSystem.h
  6. 20
      tools/esp8266/main.cpp
  7. 5
      tools/esp8266/main.h
  8. 8
      tools/esp8266/mqtt.h

21
tools/esp8266/app.cpp

@ -7,6 +7,7 @@
//-----------------------------------------------------------------------------
app::app() : Main() {
DPRINTLN(F("app::app():Main"));
mSendTicker = 0xffff;
mSendInterval = 0;
mMqttTicker = 0xffff;
@ -40,6 +41,7 @@ app::~app(void) {
//-----------------------------------------------------------------------------
void app::setup(uint32_t timeout) {
DPRINTLN(F("app::setup"));
Main::setup(timeout);
mWeb->on("/", std::bind(&app::showIndex, this));
@ -150,9 +152,15 @@ void app::setup(uint32_t timeout) {
//-----------------------------------------------------------------------------
void app::loop(void) {
//DPRINT(F("a"));
//DPRINTLN(F("a"));
//app_loops++;
Main::loop();
if(checkTicker(&mRxTicker, 5)) {
//DPRINTLN(F("app_loops =") + String(app_loops));
//app_loops=0;
//DPRINT(F("a"));
bool rxRdy = mSys->Radio.switchRxCh();
if(!mSys->BufCtrl.empty()) {
@ -288,6 +296,7 @@ void app::loop(void) {
//-----------------------------------------------------------------------------
void app::handleIntr(void) {
DPRINTLN(F("app::handleIntr"));
mSys->Radio.handleIntr();
}
@ -295,6 +304,7 @@ void app::handleIntr(void) {
//-----------------------------------------------------------------------------
bool app::buildPayload(uint8_t id) {
//DPRINTLN("Payload");
DPRINTLN(F("app::buildPayload"));
uint16_t crc = 0xffff, crcRcv;
if(mPayload[id].maxPackId > MAX_PAYLOAD_ENTRIES)
mPayload[id].maxPackId = MAX_PAYLOAD_ENTRIES;
@ -318,6 +328,8 @@ bool app::buildPayload(uint8_t id) {
//-----------------------------------------------------------------------------
void app::processPayload(bool retransmit) {
//DPRINTLN(F("app::processPayload"));
//DPRINT(F("p"));
for(uint8_t id = 0; id < mSys->getNumInverters(); id++) {
Inverter<> *iv = mSys->getInverterByPos(id);
if(NULL != iv) {
@ -373,6 +385,7 @@ void app::processPayload(bool retransmit) {
//-----------------------------------------------------------------------------
void app::showIndex(void) {
DPRINTLN(F("app::showIndex"));
String html = FPSTR(index_html);
html.replace(F("{DEVICE}"), mDeviceName);
html.replace(F("{VERSION}"), mVersion);
@ -384,6 +397,7 @@ void app::showIndex(void) {
//-----------------------------------------------------------------------------
void app::showSetup(void) {
DPRINTLN(F("app::showSetup"));
// overrides same method in main.cpp
uint16_t interval;
@ -512,12 +526,14 @@ void app::showSetup(void) {
//-----------------------------------------------------------------------------
void app::showSave(void) {
DPRINTLN(F("app::showSave"));
saveValues(true);
}
//-----------------------------------------------------------------------------
void app::showErase() {
DPRINTLN(F("app::showErase"));
eraseSettings();
showReboot();
}
@ -525,6 +541,7 @@ void app::showErase() {
//-----------------------------------------------------------------------------
void app::showStatistics(void) {
DPRINTLN(F("app::showStatistics"));
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");
@ -573,6 +590,7 @@ void app::showStatistics(void) {
//-----------------------------------------------------------------------------
void app::showHoymiles(void) {
DPRINTLN(F("app::showHoymiles"));
String html = FPSTR(hoymiles_html);
html.replace(F("{DEVICE}"), mDeviceName);
html.replace(F("{VERSION}"), mVersion);
@ -584,6 +602,7 @@ void app::showHoymiles(void) {
//-----------------------------------------------------------------------------
void app::showLiveData(void) {
DPRINTLN(F("app::showLiveData"));
String modHtml;
for(uint8_t id = 0; id < mSys->getNumInverters(); id++) {
Inverter<> *iv = mSys->getInverterByPos(id);
@ -655,6 +674,7 @@ void app::showLiveData(void) {
//-----------------------------------------------------------------------------
void app::saveValues(bool webSend = true) {
DPRINTLN(F("app::saveValues"));
Main::saveValues(false); // general configuration
if(mWeb->args() > 0) {
@ -756,6 +776,7 @@ void app::saveValues(bool webSend = true) {
//-----------------------------------------------------------------------------
void app::updateCrc(void) {
DPRINTLN(F("app::updateCrc"));
Main::updateCrc();
uint16_t crc;

1
tools/esp8266/app.h

@ -43,6 +43,7 @@ class app : public Main {
void loop(void);
void handleIntr(void);
uint8_t app_loops;
uint8_t getIrqPin(void) {
return mSys->Radio.pinIrq;
}

19
tools/esp8266/hmInverter.h

@ -81,6 +81,7 @@ class Inverter {
}
void init(void) {
DPRINTLN(F("hmInverter.h:init"));
getAssignment();
toRadioId();
record = new RECORDTYPE[listLen];
@ -89,6 +90,7 @@ class Inverter {
}
uint8_t getPosByChFld(uint8_t channel, uint8_t fieldId) {
DPRINTLN(F("hmInverter.h:getPosByChFld"));
uint8_t pos = 0;
for(; pos < listLen; pos++) {
if((assign[pos].ch == channel) && (assign[pos].fieldId == fieldId))
@ -98,18 +100,22 @@ class Inverter {
}
const char *getFieldName(uint8_t pos) {
DPRINTLN(F("hmInverter.h:getFieldName"));
return fields[assign[pos].fieldId];
}
const char *getUnit(uint8_t pos) {
DPRINTLN(F("hmInverter.h:getUnit"));
return units[assign[pos].unitId];
}
uint8_t getChannel(uint8_t pos) {
DPRINTLN(F("hmInverter.h:getChannel"));
return assign[pos].ch;
}
void addValue(uint8_t pos, uint8_t buf[]) {
DPRINTLN(F("hmInverter.h:addValue"));
uint8_t ptr = assign[pos].start;
uint8_t end = ptr + assign[pos].num;
uint16_t div = assign[pos].div;
@ -126,10 +132,12 @@ class Inverter {
}
RECORDTYPE getValue(uint8_t pos) {
DPRINTLN(F("hmInverter.h:getValue"));
return record[pos];
}
void doCalculations(void) {
DPRINTLN(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);
@ -138,10 +146,12 @@ class Inverter {
}
bool isAvailable(uint32_t timestamp) {
DPRINTLN(F("hmInverter.h:isAvailable"));
return ((timestamp - ts) < INACT_THRES_SEC);
}
bool isProducing(uint32_t timestamp) {
DPRINTLN(F("hmInverter.h:isProducing"));
if(isAvailable(timestamp)) {
uint8_t pos = getPosByChFld(CH0, FLD_PAC);
return (getValue(pos) > INACT_PWR_THRESH);
@ -150,11 +160,13 @@ class Inverter {
}
uint32_t getLastTs(void) {
DPRINTLN(F("hmInverter.h:getLastTs"));
return ts;
}
private:
void toRadioId(void) {
DPRINTLN(F("hmInverter.h:toRadioId"));
radioId.u64 = 0ULL;
radioId.b[4] = serial.b[0];
radioId.b[3] = serial.b[1];
@ -164,6 +176,7 @@ class Inverter {
}
void getAssignment(void) {
DPRINTLN(F("hmInverter.h:getAssignment"));
if(INV_TYPE_1CH == type) {
listLen = (uint8_t)(HM1CH_LIST_LEN);
assign = (byteAssign_t*)hm1chAssignment;
@ -196,6 +209,7 @@ class Inverter {
template<class T=float>
static T calcYieldTotalCh0(Inverter<> *iv, uint8_t arg0) {
DPRINTLN(F("hmInverter.h:calcYieldTotalCh0"));
if(NULL != iv) {
T yield = 0;
for(uint8_t i = 1; i <= iv->channels; i++) {
@ -209,6 +223,7 @@ static T calcYieldTotalCh0(Inverter<> *iv, uint8_t arg0) {
template<class T=float>
static T calcYieldDayCh0(Inverter<> *iv, uint8_t arg0) {
DPRINTLN(F("hmInverter.h:calcYieldDayCh0"));
if(NULL != iv) {
T yield = 0;
for(uint8_t i = 1; i <= iv->channels; i++) {
@ -222,6 +237,7 @@ static T calcYieldDayCh0(Inverter<> *iv, uint8_t arg0) {
template<class T=float>
static T calcUdcCh(Inverter<> *iv, uint8_t arg0) {
DPRINTLN(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)) {
@ -234,6 +250,7 @@ static T calcUdcCh(Inverter<> *iv, uint8_t arg0) {
template<class T=float>
static T calcPowerDcCh0(Inverter<> *iv, uint8_t arg0) {
DPRINTLN(F("hmInverter.h:calcPowerDcCh0"));
if(NULL != iv) {
T dcPower = 0;
for(uint8_t i = 1; i <= iv->channels; i++) {
@ -247,6 +264,7 @@ static T calcPowerDcCh0(Inverter<> *iv, uint8_t arg0) {
template<class T=float>
static T calcEffiencyCh0(Inverter<> *iv, uint8_t arg0) {
DPRINTLN(F("hmInverter.h:calcEfficiencyCh0"));
if(NULL != iv) {
uint8_t pos = iv->getPosByChFld(CH0, FLD_PAC);
T acPower = iv->getValue(pos);
@ -263,6 +281,7 @@ static T calcEffiencyCh0(Inverter<> *iv, uint8_t arg0) {
template<class T=float>
static T calcIrradiation(Inverter<> *iv, uint8_t arg0) {
DPRINTLN(F("hmInverter.h:calcIrradiation"));
// arg0 = channel
if(NULL != iv) {
uint8_t pos = iv->getPosByChFld(arg0, FLD_PDC);

11
tools/esp8266/hmRadio.h

@ -74,6 +74,7 @@ class HmRadio {
~HmRadio() {}
void setup(BUFFER *ctrl) {
DPRINTLN(F("hmRadio.h:setup"));
pinMode(pinIrq, INPUT_PULLUP);
mBufCtrl = ctrl;
@ -107,6 +108,7 @@ class HmRadio {
}
void handleIntr(void) {
DPRINTLN(F("hmRadio.h:handleIntr"));
uint8_t pipe, len;
packet_t *p;
@ -134,6 +136,7 @@ class HmRadio {
}
uint8_t getDefaultChannel(void) {
//DPRINTLN(F("hmRadio.h:getDefaultChannel"));
return mTxChLst[0];
}
/*uint8_t getLastChannel(void) {
@ -147,6 +150,7 @@ class HmRadio {
}*/
void sendTimePacket(uint64_t invId, uint32_t ts) {
DPRINTLN(F("hmRadio.h:sendTimePacket"));
sendCmdPacket(invId, 0x15, 0x80, false);
mTxBuf[10] = 0x0b; // cid
mTxBuf[11] = 0x00;
@ -162,6 +166,7 @@ class HmRadio {
}
void sendCmdPacket(uint64_t invId, uint8_t mid, uint8_t pid, bool calcCrc = true) {
DPRINTLN(F("hmRadio.h:sendCmdPacket"));
memset(mTxBuf, 0, MAX_RF_PAYLOAD_SIZE);
mTxBuf[0] = mid; // message id
CP_U32_BigEndian(&mTxBuf[1], (invId >> 8));
@ -174,6 +179,7 @@ class HmRadio {
}
bool checkPaketCrc(uint8_t buf[], uint8_t *len, uint8_t rxCh) {
DPRINTLN(F("hmRadio.h:checkPaketCrc"));
*len = (buf[0] >> 2);
if(*len > (MAX_RF_PAYLOAD_SIZE - 2))
*len = MAX_RF_PAYLOAD_SIZE - 2;
@ -188,6 +194,8 @@ class HmRadio {
}
bool switchRxCh(uint8_t addLoop = 0) {
//DPRINTLN(F("hmRadio.h:switchRxCh"));
//DPRINT(F("R"));
mRxLoopCnt += addLoop;
if(mRxLoopCnt != 0) {
mRxLoopCnt--;
@ -201,6 +209,7 @@ class HmRadio {
}
void dumpBuf(const char *info, uint8_t buf[], uint8_t len) {
//DPRINTLN(F("hmRadio.h:dumpBuf"));
if(NULL != info)
DPRINT(String(info));
for(uint8_t i = 0; i < len; i++) {
@ -211,6 +220,7 @@ class HmRadio {
}
bool isChipConnected(void) {
DPRINTLN(F("hmRadio.h:isChipConnected"));
return mNrf24.isChipConnected();
}
@ -225,6 +235,7 @@ class HmRadio {
private:
void sendPacket(uint64_t invId, uint8_t buf[], uint8_t len, bool clear=false) {
DPRINTLN(F("hmRadio.h:sendPacket"));
//DPRINTLN("sent packet: #" + String(mSendCnt));
//dumpBuf("SEN ", buf, len);
if(mSerialDebug) {

5
tools/esp8266/hmSystem.h

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

20
tools/esp8266/main.cpp

@ -26,6 +26,7 @@ Main::Main(void) {
mEep = new eep();
Serial.begin(115200);
DPRINTLN(F("Main::Main"));
mUptimeSecs = 0;
mUptimeTicker = 0xffffffff;
@ -39,6 +40,7 @@ Main::Main(void) {
//-----------------------------------------------------------------------------
void Main::setup(uint32_t timeout) {
DPRINTLN(F("Main::setup"));
bool startAp = mApActive;
mLimit = timeout;
@ -67,6 +69,7 @@ void Main::setup(uint32_t timeout) {
//-----------------------------------------------------------------------------
void Main::loop(void) {
//DPRINT(F("M"));
if(mApActive) {
mDns->processNextRequest();
#ifndef AP_ONLY
@ -115,6 +118,7 @@ void Main::loop(void) {
//-----------------------------------------------------------------------------
bool Main::getConfig(void) {
DPRINTLN(F("Main::getConfig"));
bool mApActive = false;
mWifiSettingsValid = checkEEpCrc(ADDR_START, ADDR_WIFI_CRC, ADDR_WIFI_CRC);
@ -137,6 +141,7 @@ bool Main::getConfig(void) {
//-----------------------------------------------------------------------------
void Main::setupAp(const char *ssid, const char *pwd) {
DPRINTLN(F("Main::setupAp"));
IPAddress apIp(192, 168, 1, 1);
DPRINTLN(F("\n---------\nAP MODE\nSSDI: ")
@ -163,6 +168,7 @@ void Main::setupAp(const char *ssid, const char *pwd) {
//-----------------------------------------------------------------------------
bool Main::setupStation(uint32_t timeout) {
DPRINTLN(F("Main::setupStation"));
int32_t cnt;
bool startAp = false;
@ -212,6 +218,7 @@ bool Main::setupStation(uint32_t timeout) {
//-----------------------------------------------------------------------------
void Main::showSetup(void) {
DPRINTLN(F("Main::showSetup"));
String html = FPSTR(setup_html);
html.replace(F("{SSID}"), mStationSsid);
// PWD will be left at the default value (for protection)
@ -229,18 +236,21 @@ void Main::showSetup(void) {
//-----------------------------------------------------------------------------
void Main::showCss(void) {
DPRINTLN(F("Main::showCss"));
mWeb->send(200, "text/css", FPSTR(style_css));
}
//-----------------------------------------------------------------------------
void Main::showSave(void) {
DPRINTLN(F("Main::showSave"));
saveValues(true);
}
//-----------------------------------------------------------------------------
void Main::saveValues(bool webSend = true) {
DPRINTLN(F("Main::saveValues"));
if(mWeb->args() > 0) {
if(mWeb->arg("ssid") != "") {
memset(mStationSsid, 0, SSID_LEN);
@ -273,6 +283,7 @@ void Main::saveValues(bool webSend = true) {
//-----------------------------------------------------------------------------
void Main::updateCrc(void) {
DPRINTLN(F("Main::updateCrc"));
uint16_t crc;
crc = buildEEpCrc(ADDR_START, ADDR_WIFI_CRC);
//Serial.println("new CRC: " + String(crc, HEX));
@ -282,6 +293,7 @@ void Main::updateCrc(void) {
//-----------------------------------------------------------------------------
void Main::showUptime(void) {
DPRINTLN(F("Main::showUptime"));
char time[20] = {0};
int upTimeSc = uint32_t((mUptimeSecs) % 60);
@ -297,12 +309,14 @@ void Main::showUptime(void) {
//-----------------------------------------------------------------------------
void Main::showTime(void) {
DPRINTLN(F("Main::showTime"));
mWeb->send(200, "text/plain", getDateTimeStr(mTimestamp));
}
//-----------------------------------------------------------------------------
void Main::showNotFound(void) {
DPRINTLN(F("Main::showNotFound"));
String msg = F("File Not Found\n\nURI: ");
msg += mWeb->uri();
msg += F("\nMethod: ");
@ -321,6 +335,7 @@ void Main::showNotFound(void) {
//-----------------------------------------------------------------------------
void Main::showReboot(void) {
DPRINTLN(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();
@ -330,6 +345,7 @@ void Main::showReboot(void) {
//-----------------------------------------------------------------------------
void Main::showFactoryRst(void) {
DPRINTLN(F("Main::showFactoryRst"));
String content = "";
int refresh = 3;
if(mWeb->args() > 0) {
@ -358,6 +374,7 @@ void Main::showFactoryRst(void) {
//-----------------------------------------------------------------------------
time_t Main::getNtpTime(void) {
DPRINTLN(F("Main::getNtpTime"));
time_t date = 0;
IPAddress timeServer;
uint8_t buf[NTP_PACKET_SIZE];
@ -395,6 +412,7 @@ time_t Main::getNtpTime(void) {
//-----------------------------------------------------------------------------
void Main::sendNTPpacket(IPAddress& address) {
DPRINTLN(F("Main::sendNTPpacket"));
uint8_t buf[NTP_PACKET_SIZE] = {0};
buf[0] = B11100011; // LI, Version, Mode
@ -415,6 +433,7 @@ void Main::sendNTPpacket(IPAddress& address) {
//-----------------------------------------------------------------------------
String Main::getDateTimeStr(time_t t) {
DPRINTLN(F("Main::getDateTimeStr"));
char str[20] = {0};
sprintf(str, "%04d-%02d-%02d %02d:%02d:%02d", year(t), month(t), day(t), hour(t), minute(t), second(t));
return String(str);
@ -425,6 +444,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) {
DPRINTLN(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

5
tools/esp8266/main.h

@ -41,12 +41,14 @@ class Main {
virtual void updateCrc(void);
inline uint16_t buildEEpCrc(uint32_t start, uint32_t length) {
DPRINTLN(F("main.h:buildEEpCrc"));
uint8_t buf[length];
mEep->read(start, buf, length);
return crc16(buf, length);
}
bool checkEEpCrc(uint32_t start, uint32_t length, uint32_t crcPos) {
DPRINTLN(F("main.h:checkEEpCrc"));
uint16_t crcRd, crcCheck;
crcCheck = buildEEpCrc(start, length);
mEep->read(crcPos, &crcRd);
@ -55,6 +57,7 @@ class Main {
}
void eraseSettings(bool all = false) {
DPRINTLN(F("main.h:eraseSettings"));
uint8_t buf[64] = {0};
uint16_t addr = (all) ? ADDR_START : ADDR_START_SETTINGS;
uint16_t end;
@ -69,6 +72,7 @@ class Main {
}
inline bool checkTicker(uint32_t *ticker, uint32_t interval) {
//DPRINT(F("c"));
uint32_t mil = millis();
if(mil >= *ticker) {
*ticker = mil + interval;
@ -83,6 +87,7 @@ class Main {
}
void stats(void) {
DPRINTLN(F("main.h:stats"));
uint32_t free;
uint16_t max;
uint8_t frag;

8
tools/esp8266/mqtt.h

@ -21,6 +21,7 @@ class mqtt {
}
void setup(const char *broker, const char *topic, const char *user, const char *pwd, uint16_t port) {
DPRINTLN(F("mqtt.h:setup"));
mAddressSet = true;
mClient->setServer(broker, port);
@ -30,6 +31,7 @@ class mqtt {
}
void sendMsg(const char *topic, const char *msg) {
DPRINTLN(F("mqtt.h:sendMsg"));
if(mAddressSet) {
char top[64];
snprintf(top, 64, "%s/%s", mTopic, topic);
@ -41,24 +43,29 @@ class mqtt {
}
bool isConnected(bool doRecon = false) {
DPRINTLN(F("mqtt.h:isConnected"));
if(doRecon)
reconnect();
return mClient->connected();
}
char *getUser(void) {
DPRINTLN(F("mqtt.h:getUser"));
return mUser;
}
char *getPwd(void) {
DPRINTLN(F("mqtt.h:getPwd"));
return mPwd;
}
char *getTopic(void) {
DPRINTLN(F("mqtt.h:getTopic"));
return mTopic;
}
void loop() {
//DPRINT(F("m"));
//if(!mClient->connected())
// reconnect();
mClient->loop();
@ -66,6 +73,7 @@ class mqtt {
private:
void reconnect(void) {
DPRINTLN(F("mqtt.h:reconnect"));
if(!mClient->connected()) {
String mqttId = "ESP-" + String(random(0xffff), HEX);
if((strlen(mUser) > 0) && (strlen(mPwd) > 0))

Loading…
Cancel
Save