Browse Source

included dev-control again

pull/1219/head
lumapu 1 year ago
parent
commit
5b39d38d86
  1. 14
      src/app.cpp
  2. 9
      src/hm/CommQueue.h
  3. 51
      src/hm/Communication.h
  4. 12
      src/hm/hmInverter.h

14
src/app.cpp

@ -200,8 +200,7 @@ void app::onNetwork(bool gotIp) {
mNetworkConnected = gotIp; mNetworkConnected = gotIp;
ah::Scheduler::resetTicker(); ah::Scheduler::resetTicker();
regularTickers(); //reinstall regular tickers regularTickers(); //reinstall regular tickers
//every(std::bind(&app::tickSend, this), mConfig->nrf.sendInterval, "tSend"); every(std::bind(&app::tickSend, this), mConfig->nrf.sendInterval, "tSend");
once(std::bind(&app::tickSend, this), 20, "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");
@ -406,12 +405,17 @@ void app::tickMidnight(void) {
void app::tickSend(void) { void app::tickSend(void) {
DPRINTLN(DBG_INFO, "tickSend"); DPRINTLN(DBG_INFO, "tickSend");
if(!mIVCommunicationOn) {
DPRINTLN(DBG_WARN, F("Time not set or it is night time, therefore no communication to the inverter!"));
return;
}
for (uint8_t i = 0; i < MAX_NUM_INVERTERS; i++) { for (uint8_t i = 0; i < MAX_NUM_INVERTERS; i++) {
Inverter<> *iv = mSys.getInverterByPos(i); Inverter<> *iv = mSys.getInverterByPos(i);
if(NULL != iv) { if(NULL != iv) {
mCommunication.add(iv, 0x01); iv->tickSend([this, iv](uint8_t cmd) {
mCommunication.add(iv, 0x05); mCommunication.add(iv, cmd);
mCommunication.add(iv, 0x0b, false); });
}; };
} }

9
src/hm/CommQueue.h

@ -17,11 +17,11 @@ class CommQueue {
void addImportant(Inverter<> *iv, uint8_t cmd, bool delOnPop = true) { void addImportant(Inverter<> *iv, uint8_t cmd, bool delOnPop = true) {
dec(&mRdPtr); dec(&mRdPtr);
mQueue[mRdPtr] = queue_s(iv, cmd, delOnPop); mQueue[mRdPtr] = queue_s(iv, cmd, delOnPop, true);
} }
void add(Inverter<> *iv, uint8_t cmd, bool delOnPop = true) { void add(Inverter<> *iv, uint8_t cmd, bool delOnPop = true) {
mQueue[mWrPtr] = queue_s(iv, cmd, delOnPop); mQueue[mWrPtr] = queue_s(iv, cmd, delOnPop, false);
inc(&mWrPtr); inc(&mWrPtr);
} }
@ -31,10 +31,11 @@ class CommQueue {
uint8_t cmd; uint8_t cmd;
uint8_t attempts; uint8_t attempts;
bool delOnPop; bool delOnPop;
bool isDevControl;
uint32_t ts; uint32_t ts;
queue_s() {} queue_s() {}
queue_s(Inverter<> *i, uint8_t c, bool d) : queue_s(Inverter<> *i, uint8_t c, bool d, bool dev) :
iv(i), cmd(c), attempts(5), ts(0), delOnPop(d) {} iv(i), cmd(c), attempts(5), ts(0), delOnPop(d), isDevControl(dev) {}
}; };
protected: protected:

51
src/hm/Communication.h

@ -16,6 +16,11 @@ class Communication : public CommQueue<> {
mTimestamp = timestamp; mTimestamp = timestamp;
} }
void addImportant(Inverter<> *iv, uint8_t cmd, bool delOnPop = true) {
mState = States::RESET; // cancel current operation
CommQueue::addImportant(iv, cmd, delOnPop);
}
void loop() { void loop() {
get([this](bool valid, const queue_s *q) { get([this](bool valid, const queue_s *q) {
if(!valid) if(!valid)
@ -23,6 +28,8 @@ class Communication : public CommQueue<> {
switch(mState) { switch(mState) {
case States::RESET: case States::RESET:
if(millis() < mWaitTimeout)
return;
mMaxFrameId = 0; mMaxFrameId = 0;
for(uint8_t i = 0; i < MAX_PAYLOAD_ENTRIES; i++) { for(uint8_t i = 0; i < MAX_PAYLOAD_ENTRIES; i++) {
mLocalBuf[i].len = 0; mLocalBuf[i].len = 0;
@ -32,8 +39,13 @@ class Communication : public CommQueue<> {
case States::START: case States::START:
setTs(mTimestamp); setTs(mTimestamp);
if(q->isDevControl) {
if(ActivePowerContr == q->cmd)
q->iv->powerLimitAck = false;
q->iv->radio->sendControlPacket(q->iv, q->cmd, q->iv->powerLimit, false);
} else
q->iv->radio->prepareDevInformCmd(q->iv, q->cmd, q->ts, q->iv->alarmLastId, false); q->iv->radio->prepareDevInformCmd(q->iv, q->cmd, q->ts, q->iv->alarmLastId, false);
mWaitTimeout = millis() + 1500; mWaitTimeout = millis() + 500;
setAttempt(); setAttempt();
mState = States::WAIT; mState = States::WAIT;
break; break;
@ -51,14 +63,11 @@ class Communication : public CommQueue<> {
q->iv->radioStatistics.rxFailNoAnser++; // got nothing q->iv->radioStatistics.rxFailNoAnser++; // got nothing
if((IV_HMS == q->iv->ivGen) || (IV_HMT == q->iv->ivGen)) { if((IV_HMS == q->iv->ivGen) || (IV_HMT == q->iv->ivGen)) {
q->iv->radio->switchFrequency(q->iv, HOY_BOOT_FREQ_KHZ, WORK_FREQ_KHZ); q->iv->radio->switchFrequency(q->iv, HOY_BOOT_FREQ_KHZ, WORK_FREQ_KHZ);
mWaitTimeout = millis() + 2000; mWaitTimeout = millis() + 1000;
mState = States::GAP; }
break;
} else {
mState = States::RESET; mState = States::RESET;
break; break;
} }
}
States nextState = States::RESET; States nextState = States::RESET;
while(!q->iv->radio->mBufCtrl.empty()) { while(!q->iv->radio->mBufCtrl.empty()) {
@ -83,7 +92,7 @@ class Communication : public CommQueue<> {
parseFrame(p); parseFrame(p);
nextState = States::CHECK_PACKAGE; nextState = States::CHECK_PACKAGE;
} else if (p->packet[0] == (TX_REQ_DEVCONTROL + ALL_FRAMES)) // response from dev control command } else if (p->packet[0] == (TX_REQ_DEVCONTROL + ALL_FRAMES)) // response from dev control command
parseDevCtrl(p); parseDevCtrl(p, q);
} }
q->iv->radio->mBufCtrl.pop(); q->iv->radio->mBufCtrl.pop();
@ -93,12 +102,6 @@ class Communication : public CommQueue<> {
} }
break; break;
case States::GAP:
if(millis() < mWaitTimeout)
return;
mState = States::RESET;
break;
case States::CHECK_PACKAGE: case States::CHECK_PACKAGE:
if(0 == mMaxFrameId) { if(0 == mMaxFrameId) {
DPRINT_IVID(DBG_WARN, q->iv->id); DPRINT_IVID(DBG_WARN, q->iv->id);
@ -175,8 +178,22 @@ class Communication : public CommQueue<> {
f->rssi = p->rssi; f->rssi = p->rssi;
} }
inline void parseDevCtrl(packet_t *p) { inline void parseDevCtrl(packet_t *p, const queue_s *q) {
//if((p->packet[12] == ActivePowerContr) && (p->packet[13] == 0x00)) if((p->packet[12] != ActivePowerContr) || (p->packet[13] != 0x00))
return;
bool accepted = true;
if((p->packet[10] == 0x00) && (p->packet[11] == 0x00))
q->iv->powerLimitAck = true;
else
accepted = false;
DPRINT_IVID(DBG_INFO, q->iv->id);
DBGPRINT(F(" has "));
if(!accepted) DBGPRINT(F("not "));
DBGPRINT(F("accepted power limit set point "));
DBGPRINT(String(q->iv->powerLimit[0]));
DBGPRINT(F(" with PowerLimitControl "));
DBGPRINTLN(String(q->iv->powerLimit[1]));
} }
inline void compilePayload(const queue_s *q) { inline void compilePayload(const queue_s *q) {
@ -234,7 +251,7 @@ class Communication : public CommQueue<> {
private: private:
enum class States : uint8_t { enum class States : uint8_t {
RESET, START, WAIT, CHECK_FRAMES, CHECK_PACKAGE, GAP RESET, START, WAIT, CHECK_FRAMES, CHECK_PACKAGE
}; };
typedef struct { typedef struct {
@ -246,7 +263,7 @@ class Communication : public CommQueue<> {
private: private:
States mState = States::RESET; States mState = States::RESET;
uint32_t *mTimestamp; uint32_t *mTimestamp;
uint32_t mWaitTimeout; uint32_t mWaitTimeout = 0;
std::array<frame_t, MAX_PAYLOAD_ENTRIES> mLocalBuf; std::array<frame_t, MAX_PAYLOAD_ENTRIES> mLocalBuf;
uint8_t mMaxFrameId; uint8_t mMaxFrameId;
uint8_t mPayload[150]; uint8_t mPayload[150];

12
src/hm/hmInverter.h

@ -15,6 +15,7 @@
#include "../hms/hmsDefines.h" #include "../hms/hmsDefines.h"
#include <memory> #include <memory>
#include <queue> #include <queue>
#include <functional>
#include "../config/settings.h" #include "../config/settings.h"
#include "radio.h" #include "radio.h"
@ -180,6 +181,17 @@ class Inverter {
// TODO: cleanup // TODO: cleanup
} }
void tickSend(std::function<void(uint8_t cmd)> cb) {
if((alarmLastId != alarmMesIndex) && (alarmMesIndex != 0))
cb(AlarmData); // get last alarms
else if(0 == getFwVersion())
cb(InverterDevInform_All); // get firmware version
else if(0 == getHwVersion())
cb(InverterDevInform_Simple); // get hardware version
else
cb(RealTimeRunData_Debug); // get live data
}
template <typename T> template <typename T>
void enqueCommand(uint8_t cmd) { void enqueCommand(uint8_t cmd) {
_commandQueue.push(std::make_shared<T>(cmd)); _commandQueue.push(std::make_shared<T>(cmd));

Loading…
Cancel
Save