mirror of
https://github.com/lumapu/ahoy.git
synced 2025-05-17 02:46:11 +02:00
loop readable and shorten if
This commit is contained in:
parent
5762002a53
commit
7dd13cf530
1 changed files with 34 additions and 18 deletions
|
@ -86,37 +86,47 @@ void app::loop(void) {
|
||||||
|
|
||||||
yield();
|
yield();
|
||||||
|
|
||||||
if(checkTicker(&mRxTicker, 5)) {
|
if(checkTicker(&mRxTicker, 5))
|
||||||
|
{
|
||||||
bool rxRdy = mSys->Radio.switchRxCh();
|
bool rxRdy = mSys->Radio.switchRxCh();
|
||||||
|
|
||||||
if(!mSys->BufCtrl.empty()) {
|
if(!mSys->BufCtrl.empty())
|
||||||
|
{
|
||||||
uint8_t len;
|
uint8_t len;
|
||||||
packet_t *p = mSys->BufCtrl.getBack();
|
packet_t *p = mSys->BufCtrl.getBack();
|
||||||
|
|
||||||
if(mSys->Radio.checkPaketCrc(p->packet, &len, p->rxCh)) {
|
if(mSys->Radio.checkPaketCrc(p->packet, &len, p->rxCh))
|
||||||
|
{
|
||||||
// process buffer only on first occurrence
|
// process buffer only on first occurrence
|
||||||
if(mConfig.serialDebug) {
|
if(mConfig.serialDebug) {
|
||||||
DPRINT(DBG_INFO, "RX " + String(len) + "B Ch" + String(p->rxCh) + " | ");
|
DPRINT(DBG_INFO, "RX " + String(len) + "B Ch" + String(p->rxCh) + " | ");
|
||||||
mSys->Radio.dumpBuf(NULL, p->packet, len);
|
mSys->Radio.dumpBuf(NULL, p->packet, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
mStat.frmCnt++;
|
mStat.frmCnt++;
|
||||||
|
|
||||||
if(0 != len) {
|
if(0 != len)
|
||||||
|
{
|
||||||
Inverter<> *iv = mSys->findInverter(&p->packet[1]);
|
Inverter<> *iv = mSys->findInverter(&p->packet[1]);
|
||||||
if((NULL != iv) && (p->packet[0] == (TX_REQ_INFO + ALL_FRAMES))) { // response from get information command
|
if((NULL != iv) && (p->packet[0] == (TX_REQ_INFO + ALL_FRAMES))) // response from get information command
|
||||||
|
{
|
||||||
mPayload[iv->id].txId = p->packet[0];
|
mPayload[iv->id].txId = p->packet[0];
|
||||||
DPRINTLN(DBG_DEBUG, F("Response from info request received"));
|
DPRINTLN(DBG_DEBUG, F("Response from info request received"));
|
||||||
uint8_t *pid = &p->packet[9];
|
uint8_t *pid = &p->packet[9];
|
||||||
if (*pid == 0x00)
|
if (*pid == 0x00)
|
||||||
DPRINT(DBG_DEBUG, "fragment number zero received and ignored");
|
{
|
||||||
else {
|
DPRINT(DBG_DEBUG, F("fragment number zero received and ignored"));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
DPRINTLN(DBG_DEBUG, "PID: 0x" + String(*pid, HEX));
|
DPRINTLN(DBG_DEBUG, "PID: 0x" + String(*pid, HEX));
|
||||||
if ((*pid & 0x7F) < 5) {
|
if ((*pid & 0x7F) < 5) {
|
||||||
memcpy(mPayload[iv->id].data[(*pid & 0x7F) - 1], &p->packet[10], len - 11);
|
memcpy(mPayload[iv->id].data[(*pid & 0x7F) - 1], &p->packet[10], len - 11);
|
||||||
mPayload[iv->id].len[(*pid & 0x7F) - 1] = len - 11;
|
mPayload[iv->id].len[(*pid & 0x7F) - 1] = len - 11;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((*pid & ALL_FRAMES) == ALL_FRAMES) {
|
if ((*pid & ALL_FRAMES) == ALL_FRAMES)
|
||||||
|
{
|
||||||
// Last packet
|
// Last packet
|
||||||
if ((*pid & 0x7f) > mPayload[iv->id].maxPackId) {
|
if ((*pid & 0x7f) > mPayload[iv->id].maxPackId) {
|
||||||
mPayload[iv->id].maxPackId = (*pid & 0x7f);
|
mPayload[iv->id].maxPackId = (*pid & 0x7f);
|
||||||
|
@ -126,15 +136,17 @@ void app::loop(void) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if((NULL != iv) && (p->packet[0] == (TX_REQ_DEVCONTROL + ALL_FRAMES))) { // response from dev control command
|
if((NULL != iv) && (p->packet[0] == (TX_REQ_DEVCONTROL + ALL_FRAMES))) // response from dev control command
|
||||||
mPayload[iv->id].txId = p->packet[0];
|
{
|
||||||
DPRINTLN(DBG_DEBUG, F("Response from devcontrol request received"));
|
DPRINTLN(DBG_DEBUG, F("Response from devcontrol request received"));
|
||||||
|
|
||||||
|
mPayload[iv->id].txId = p->packet[0];
|
||||||
iv->devControlRequest = false;
|
iv->devControlRequest = false;
|
||||||
if ((p->packet[12] == ActivePowerContr) && (p->packet[13] == 0x00)) {
|
|
||||||
if (p->packet[10] == 0x00 && p->packet[11] == 0x00)
|
if ((p->packet[12] == ActivePowerContr) && (p->packet[13] == 0x00))
|
||||||
DPRINTLN(DBG_INFO, F("Inverter ") + String(iv->id) + F(" has accepted power limit set point ") + String(iv->powerLimit[0]) + F(" with PowerLimitControl ") + String(iv->powerLimit[1]));
|
{
|
||||||
else
|
String msg = (p->packet[10] == 0x00 && p->packet[11] == 0x00) ? "" : "NOT ";
|
||||||
DPRINTLN(DBG_INFO, F("Inverter ") + String(iv->id) + F(" has NOT accepted power limit set point") + String(iv->powerLimit[0]) + F(" with PowerLimitControl ") + String(iv->powerLimit[1]));
|
DPRINTLN(DBG_INFO, F("Inverter ") + String(iv->id) + msg + String(iv->powerLimit[0]) + F(" with PowerLimitControl ") + String(iv->powerLimit[1]));
|
||||||
}
|
}
|
||||||
iv->devControlCmd = Init;
|
iv->devControlCmd = Init;
|
||||||
}
|
}
|
||||||
|
@ -241,7 +253,9 @@ void app::loop(void) {
|
||||||
DPRINTLN(DBG_DEBUG, F("app:loop WiFi WiFi.status ") + String(WiFi.status()));
|
DPRINTLN(DBG_DEBUG, F("app:loop WiFi WiFi.status ") + String(WiFi.status()));
|
||||||
DPRINTLN(DBG_INFO, F("Requesting Inverter SN ") + String(iv->serial.u64, HEX));
|
DPRINTLN(DBG_INFO, F("Requesting Inverter SN ") + String(iv->serial.u64, HEX));
|
||||||
}
|
}
|
||||||
if(iv->devControlRequest) {
|
|
||||||
|
if(iv->devControlRequest)
|
||||||
|
{
|
||||||
if(mConfig.serialDebug)
|
if(mConfig.serialDebug)
|
||||||
DPRINTLN(DBG_INFO, F("Devcontrol request ") + String(iv->devControlCmd) + F(" power limit ") + String(iv->powerLimit[0]));
|
DPRINTLN(DBG_INFO, F("Devcontrol request ") + String(iv->devControlCmd) + F(" power limit ") + String(iv->powerLimit[0]));
|
||||||
mSys->Radio.sendControlPacket(iv->radioId.u64, iv->devControlCmd, iv->powerLimit);
|
mSys->Radio.sendControlPacket(iv->radioId.u64, iv->devControlCmd, iv->powerLimit);
|
||||||
|
@ -249,7 +263,8 @@ void app::loop(void) {
|
||||||
iv->clearCmdQueue();
|
iv->clearCmdQueue();
|
||||||
iv->enqueCommand<InfoCommand>(SystemConfigPara);
|
iv->enqueCommand<InfoCommand>(SystemConfigPara);
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
uint8_t cmd = iv->getQueuedCmd();
|
uint8_t cmd = iv->getQueuedCmd();
|
||||||
mSys->Radio.sendTimePacket(iv->radioId.u64, cmd, mPayload[iv->id].ts, iv->alarmMesIndex);
|
mSys->Radio.sendTimePacket(iv->radioId.u64, cmd, mPayload[iv->id].ts, iv->alarmMesIndex);
|
||||||
mPayload[iv->id].txCmd = cmd;
|
mPayload[iv->id].txCmd = cmd;
|
||||||
|
@ -257,8 +272,9 @@ void app::loop(void) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(mConfig.serialDebug)
|
else if(mConfig.serialDebug) {
|
||||||
DPRINTLN(DBG_WARN, F("time not set, can't request inverter!"));
|
DPRINTLN(DBG_WARN, F("time not set, can't request inverter!"));
|
||||||
|
}
|
||||||
yield();
|
yield();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue