mirror of
https://github.com/lumapu/ahoy.git
synced 2025-05-31 01:36:11 +02:00
included dev-control again
This commit is contained in:
parent
b34e5a7416
commit
5b39d38d86
4 changed files with 62 additions and 28 deletions
14
src/app.cpp
14
src/app.cpp
|
@ -200,8 +200,7 @@ void app::onNetwork(bool gotIp) {
|
|||
mNetworkConnected = gotIp;
|
||||
ah::Scheduler::resetTicker();
|
||||
regularTickers(); //reinstall regular tickers
|
||||
//every(std::bind(&app::tickSend, this), mConfig->nrf.sendInterval, "tSend");
|
||||
once(std::bind(&app::tickSend, this), 20, "tSend");
|
||||
every(std::bind(&app::tickSend, this), mConfig->nrf.sendInterval, "tSend");
|
||||
mMqttReconnect = true;
|
||||
mSunrise = 0; // needs to be set to 0, to reinstall sunrise and ivComm tickers!
|
||||
//once(std::bind(&app::tickNtpUpdate, this), 2, "ntp2");
|
||||
|
@ -406,12 +405,17 @@ void app::tickMidnight(void) {
|
|||
void app::tickSend(void) {
|
||||
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++) {
|
||||
Inverter<> *iv = mSys.getInverterByPos(i);
|
||||
if(NULL != iv) {
|
||||
mCommunication.add(iv, 0x01);
|
||||
mCommunication.add(iv, 0x05);
|
||||
mCommunication.add(iv, 0x0b, false);
|
||||
iv->tickSend([this, iv](uint8_t cmd) {
|
||||
mCommunication.add(iv, cmd);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -17,11 +17,11 @@ class CommQueue {
|
|||
|
||||
void addImportant(Inverter<> *iv, uint8_t cmd, bool delOnPop = true) {
|
||||
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) {
|
||||
mQueue[mWrPtr] = queue_s(iv, cmd, delOnPop);
|
||||
mQueue[mWrPtr] = queue_s(iv, cmd, delOnPop, false);
|
||||
inc(&mWrPtr);
|
||||
}
|
||||
|
||||
|
@ -31,10 +31,11 @@ class CommQueue {
|
|||
uint8_t cmd;
|
||||
uint8_t attempts;
|
||||
bool delOnPop;
|
||||
bool isDevControl;
|
||||
uint32_t ts;
|
||||
queue_s() {}
|
||||
queue_s(Inverter<> *i, uint8_t c, bool d) :
|
||||
iv(i), cmd(c), attempts(5), ts(0), delOnPop(d) {}
|
||||
queue_s(Inverter<> *i, uint8_t c, bool d, bool dev) :
|
||||
iv(i), cmd(c), attempts(5), ts(0), delOnPop(d), isDevControl(dev) {}
|
||||
};
|
||||
|
||||
protected:
|
||||
|
|
|
@ -16,6 +16,11 @@ class Communication : public CommQueue<> {
|
|||
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() {
|
||||
get([this](bool valid, const queue_s *q) {
|
||||
if(!valid)
|
||||
|
@ -23,6 +28,8 @@ class Communication : public CommQueue<> {
|
|||
|
||||
switch(mState) {
|
||||
case States::RESET:
|
||||
if(millis() < mWaitTimeout)
|
||||
return;
|
||||
mMaxFrameId = 0;
|
||||
for(uint8_t i = 0; i < MAX_PAYLOAD_ENTRIES; i++) {
|
||||
mLocalBuf[i].len = 0;
|
||||
|
@ -32,8 +39,13 @@ class Communication : public CommQueue<> {
|
|||
|
||||
case States::START:
|
||||
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);
|
||||
mWaitTimeout = millis() + 1500;
|
||||
mWaitTimeout = millis() + 500;
|
||||
setAttempt();
|
||||
mState = States::WAIT;
|
||||
break;
|
||||
|
@ -51,14 +63,11 @@ class Communication : public CommQueue<> {
|
|||
q->iv->radioStatistics.rxFailNoAnser++; // got nothing
|
||||
if((IV_HMS == q->iv->ivGen) || (IV_HMT == q->iv->ivGen)) {
|
||||
q->iv->radio->switchFrequency(q->iv, HOY_BOOT_FREQ_KHZ, WORK_FREQ_KHZ);
|
||||
mWaitTimeout = millis() + 2000;
|
||||
mState = States::GAP;
|
||||
break;
|
||||
} else {
|
||||
mWaitTimeout = millis() + 1000;
|
||||
}
|
||||
mState = States::RESET;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
States nextState = States::RESET;
|
||||
while(!q->iv->radio->mBufCtrl.empty()) {
|
||||
|
@ -83,7 +92,7 @@ class Communication : public CommQueue<> {
|
|||
parseFrame(p);
|
||||
nextState = States::CHECK_PACKAGE;
|
||||
} 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();
|
||||
|
@ -93,12 +102,6 @@ class Communication : public CommQueue<> {
|
|||
}
|
||||
break;
|
||||
|
||||
case States::GAP:
|
||||
if(millis() < mWaitTimeout)
|
||||
return;
|
||||
mState = States::RESET;
|
||||
break;
|
||||
|
||||
case States::CHECK_PACKAGE:
|
||||
if(0 == mMaxFrameId) {
|
||||
DPRINT_IVID(DBG_WARN, q->iv->id);
|
||||
|
@ -175,8 +178,22 @@ class Communication : public CommQueue<> {
|
|||
f->rssi = p->rssi;
|
||||
}
|
||||
|
||||
inline void parseDevCtrl(packet_t *p) {
|
||||
//if((p->packet[12] == ActivePowerContr) && (p->packet[13] == 0x00))
|
||||
inline void parseDevCtrl(packet_t *p, const queue_s *q) {
|
||||
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) {
|
||||
|
@ -234,7 +251,7 @@ class Communication : public CommQueue<> {
|
|||
|
||||
private:
|
||||
enum class States : uint8_t {
|
||||
RESET, START, WAIT, CHECK_FRAMES, CHECK_PACKAGE, GAP
|
||||
RESET, START, WAIT, CHECK_FRAMES, CHECK_PACKAGE
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
|
@ -246,7 +263,7 @@ class Communication : public CommQueue<> {
|
|||
private:
|
||||
States mState = States::RESET;
|
||||
uint32_t *mTimestamp;
|
||||
uint32_t mWaitTimeout;
|
||||
uint32_t mWaitTimeout = 0;
|
||||
std::array<frame_t, MAX_PAYLOAD_ENTRIES> mLocalBuf;
|
||||
uint8_t mMaxFrameId;
|
||||
uint8_t mPayload[150];
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#include "../hms/hmsDefines.h"
|
||||
#include <memory>
|
||||
#include <queue>
|
||||
#include <functional>
|
||||
#include "../config/settings.h"
|
||||
|
||||
#include "radio.h"
|
||||
|
@ -180,6 +181,17 @@ class Inverter {
|
|||
// 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>
|
||||
void enqueCommand(uint8_t cmd) {
|
||||
_commandQueue.push(std::make_shared<T>(cmd));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue