|
@ -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]; |
|
|