diff --git a/src/app.cpp b/src/app.cpp index 44d8ab30..9cbe06a1 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -413,13 +413,15 @@ void app::tickSend(void) { for (uint8_t i = 0; i < MAX_NUM_INVERTERS; i++) { Inverter<> *iv = mSys.getInverterByPos(i); if(NULL != iv) { - iv->tickSend([this, iv](uint8_t cmd, bool isDevControl) { - if(isDevControl) - mCommunication.addImportant(iv, cmd); - else - mCommunication.add(iv, cmd); - }); - }; + if(iv->config->enabled) { + iv->tickSend([this, iv](uint8_t cmd, bool isDevControl) { + if(isDevControl) + mCommunication.addImportant(iv, cmd); + else + mCommunication.add(iv, cmd); + }); + } + } } /*if(mConfig->nrf.enabled) { @@ -468,9 +470,9 @@ void app::tickSend(void) { if (mConfig->serial.debug) DPRINTLN(DBG_WARN, F("Time not set or it is night time, therefore no communication to the inverter!")); } - yield(); + yield();*/ - updateLed();*/ + updateLed(); } //----------------------------------------------------------------------------- diff --git a/src/hm/CommQueue.h b/src/hm/CommQueue.h index 9c9da707..94cc63bd 100644 --- a/src/hm/CommQueue.h +++ b/src/hm/CommQueue.h @@ -44,6 +44,13 @@ class CommQueue { inc(&mWrPtr); } + void add(const queue_s *q, bool rstAttempts = false) { + mQueue[mWrPtr] = *q; + if(rstAttempts) + mQueue[mWrPtr].attempts = 5; + inc(&mWrPtr); + } + void get(std::function cb) { if(mRdPtr == mWrPtr) { cb(false, &mQueue[mRdPtr]); // empty diff --git a/src/hm/Communication.h b/src/hm/Communication.h index 4cdf0beb..81dc763c 100644 --- a/src/hm/Communication.h +++ b/src/hm/Communication.h @@ -112,7 +112,8 @@ class Communication : public CommQueue<> { parseDevCtrl(p, q); cmdDone(true); // remove done request } - } + } else + DPRINTLN(DBG_WARN, F("Inverter serial does not match")); q->iv->radio->mBufCtrl.pop(); yield(); @@ -126,7 +127,7 @@ class Communication : public CommQueue<> { setAttempt(); DPRINT_IVID(DBG_WARN, q->iv->id); - DBGPRINT(F("last frame missing: request retransmit (")); + DBGPRINT(F("frame missing: request retransmit (")); DBGPRINT(String(q->attempts)); DBGPRINTLN(F(" attempts left)")); @@ -136,11 +137,17 @@ class Communication : public CommQueue<> { break; } - q->iv->radio->sendCmdPacket(q->iv, TX_REQ_INFO, (ALL_FRAMES + i), true); - q->iv->radioStatistics.retransmits++; - mWaitTimeout = millis() + 500; - mState = States::WAIT; - break; + if(q->attempts) { + q->iv->radio->sendCmdPacket(q->iv, TX_REQ_INFO, (ALL_FRAMES + i), true); + q->iv->radioStatistics.retransmits++; + mWaitTimeout = millis() + 500; + mState = States::WAIT; + } else { + add(q, true); + cmdDone(q); + mState = States::RESET; + } + return; } for(uint8_t i = 0; i < mMaxFrameId; i++) { @@ -154,10 +161,16 @@ class Communication : public CommQueue<> { DBGPRINT(String(q->attempts)); DBGPRINTLN(F(" attempts left)")); - q->iv->radio->sendCmdPacket(q->iv, TX_REQ_INFO, (ALL_FRAMES + i), true); - q->iv->radioStatistics.retransmits++; - mWaitTimeout = millis() + 500; - mState = States::WAIT; + if(q->attempts) { + q->iv->radio->sendCmdPacket(q->iv, TX_REQ_INFO, (ALL_FRAMES + i), true); + q->iv->radioStatistics.retransmits++; + mWaitTimeout = millis() + 500; + mState = States::WAIT; + } else { + add(q, true); + cmdDone(q); + mState = States::RESET; + } return; } } diff --git a/src/hm/hmInverter.h b/src/hm/hmInverter.h index 5e3e4266..45b861a7 100644 --- a/src/hm/hmInverter.h +++ b/src/hm/hmInverter.h @@ -617,9 +617,9 @@ class Inverter { uint32_t startTimeOffset = 0, endTimeOffset = 0; uint32_t start, endTime; - if (((wCode >> 13) & 0x01) == 1) // check if is AM or PM - startTimeOffset = 12 * 60 * 60; - if (((wCode >> 12) & 0x01) == 1) // check if is AM or PM + // check if is AM or PM + startTimeOffset = ((wCode >> 13) & 0x01) * 12 * 60 * 60; + if (((wCode >> 12) & 0x03) != 0) endTimeOffset = 12 * 60 * 60; start = (((uint16_t)pyld[startOff + 4] << 8) | ((uint16_t)pyld[startOff + 5])) + startTimeOffset;