Browse Source

Update app.cpp

pull/652/head
beegee3 2 years ago
committed by GitHub
parent
commit
5fb45f1b20
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 69
      src/app.cpp

69
src/app.cpp

@ -82,40 +82,26 @@ void app::loop(void) {
void app::loopStandard(void) { void app::loopStandard(void) {
ah::Scheduler::loop(); ah::Scheduler::loop();
mSys->Radio.loop(); if (mSys->Radio.loop()) {
mPayload.loop(); while (!mSys->Radio.mBufCtrl.empty()) {
packet_t *p = &mSys->Radio.mBufCtrl.front();
yield();
if (ah::checkTicker(&mRxTicker, 4)) {
bool rxRdy = mSys->Radio.switchRxCh();
if (!mSys->BufCtrl.empty()) {
uint8_t len;
packet_t *p = mSys->BufCtrl.getBack();
if (mSys->Radio.checkPaketCrc(p->packet, &len, p->rxCh)) {
if (mConfig->serial.debug) { if (mConfig->serial.debug) {
DPRINT(DBG_INFO, "RX " + String(len) + "B Ch" + String(p->rxCh) + " | "); DPRINT(DBG_INFO, "RX " + String(p->len) + "B Ch" + String(p->ch) + " | ");
mSys->Radio.dumpBuf(NULL, p->packet, len); mSys->Radio.dumpBuf(p->packet, p->len);
} }
mStat.frmCnt++; mStat.frmCnt++;
if (0 != len) mPayload.add(p);
mPayload.add(p, len); mSys->Radio.mBufCtrl.pop();
}
mSys->BufCtrl.popBack();
}
yield(); yield();
}
if (rxRdy)
mPayload.process(true); mPayload.process(true);
} }
mPayload.loop();
#if !defined(AP_ONLY)
if(mMqttEnabled) if(mMqttEnabled)
mMqtt.loop(); mMqtt.loop();
#endif
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -131,13 +117,15 @@ void app::onWifi(bool gotIp) {
regularTickers(); // reinstall regular tickers regularTickers(); // reinstall regular tickers
if (gotIp) { if (gotIp) {
mInnerLoopCb = std::bind(&app::loopStandard, this); mInnerLoopCb = std::bind(&app::loopStandard, this);
mSendTickerId = every(std::bind(&app::tickSend, this), mConfig->nrf.sendInterval, "tSend"); every(std::bind(&app::tickSend, this), mConfig->nrf.sendInterval, "tSend");
mMqttReconnect = true; mMqttReconnect = true;
mSunrise = 0; // needs to be set to 0, to reinstall sunrise and ivComm tickers! mSunrise = 0; // needs to be set to 0, to reinstall sunrise and ivComm tickers!
once(std::bind(&app::tickNtpUpdate, this), 2, "ntp2"); once(std::bind(&app::tickNtpUpdate, this), 2, "ntp2");
if(WIFI_AP == WiFi.getMode()) if(WIFI_AP == WiFi.getMode()) {
mMqttEnabled = false;
everySec(std::bind(&ahoywifi::tickWifiLoop, &mWifi), "wifiL"); everySec(std::bind(&ahoywifi::tickWifiLoop, &mWifi), "wifiL");
} }
}
else { else {
mInnerLoopCb = std::bind(&app::loopWifi, this); mInnerLoopCb = std::bind(&app::loopWifi, this);
everySec(std::bind(&ahoywifi::tickWifiLoop, &mWifi), "wifiL"); everySec(std::bind(&ahoywifi::tickWifiLoop, &mWifi), "wifiL");
@ -232,6 +220,15 @@ void app::tickComm(void) {
once(std::bind(&app::tickComm, this), 1, "mqCom"); // MQTT not connected, retry once(std::bind(&app::tickComm, this), 1, "mqCom"); // MQTT not connected, retry
} }
//-----------------------------------------------------------------------------
void app::tickMidnight(void) {
// only used and enabled by MQTT (see setup())
uint32_t nxtTrig = mTimestamp - ((mTimestamp - 1) % 86400) + 86400; // next midnight
onceAt(std::bind(&app::tickMidnight, this), nxtTrig, "mid2");
mMqtt.tickerMidnight();
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void app::tickSend(void) { void app::tickSend(void) {
if(!mSys->Radio.isChipConnected()) { if(!mSys->Radio.isChipConnected()) {
@ -239,9 +236,9 @@ void app::tickSend(void) {
return; return;
} }
if (mIVCommunicationOn) { if (mIVCommunicationOn) {
if (!mSys->BufCtrl.empty()) { if (!mSys->Radio.mBufCtrl.empty()) {
if (mConfig->serial.debug) if (mConfig->serial.debug)
DPRINTLN(DBG_DEBUG, F("recbuf not empty! #") + String(mSys->BufCtrl.getFill())); DPRINTLN(DBG_DEBUG, F("recbuf not empty! #") + String(mSys->Radio.mBufCtrl.size()));
} }
int8_t maxLoop = MAX_NUM_INVERTERS; int8_t maxLoop = MAX_NUM_INVERTERS;
@ -264,21 +261,6 @@ void app::tickSend(void) {
updateLed(); updateLed();
} }
//-----------------------------------------------------------------------------
void app::tickMidnight(void) {
// only used and enabled by MQTT (see setup())
uint32_t nxtTrig = mTimestamp - ((mTimestamp - 1) % 86400) + 86400; // next midnight
onceAt(std::bind(&app::tickMidnight, this), nxtTrig, "mid2");
mMqtt.tickerMidnight();
}
//-----------------------------------------------------------------------------
void app::handleIntr(void) {
DPRINTLN(DBG_VERBOSE, F("app::handleIntr"));
mSys->Radio.handleIntr();
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void app::resetSystem(void) { void app::resetSystem(void) {
snprintf(mVersion, 12, "%d.%d.%d", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH); snprintf(mVersion, 12, "%d.%d.%d", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH);
@ -290,8 +272,7 @@ void app::resetSystem(void) {
mSunrise = 0; mSunrise = 0;
mSunset = 0; mSunset = 0;
mRxTicker = 0; mMqttEnabled = false;
mSendTickerId = 0xff; // invalid id
mSendLastIvId = 0; mSendLastIvId = 0;
mShowRebootRequest = false; mShowRebootRequest = false;

Loading…
Cancel
Save