Browse Source

restructure logic for fast next requests for HM

- use regular retransmission logic instead of mHighPrioIv flag
- most "side requests" will be followed by the next request
Note: this might have some impact on tx/rx statistics?

+ some changes to serial output
pull/1145/head
rejoe2 2 years ago
committed by GitHub
parent
commit
28d5726007
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 98
      src/hm/hmPayload.h

98
src/hm/hmPayload.h

@ -232,8 +232,9 @@ class HmPayload {
} }
if (!mPayload[iv->id].complete) { if (!mPayload[iv->id].complete) {
bool crcPass, pyldComplete; bool crcPass, pyldComplete, fastNext;
crcPass = build(iv->id, &pyldComplete);
crcPass = build(iv, &pyldComplete, &fastNext);
if (!crcPass && !pyldComplete) { // payload not complete if (!crcPass && !pyldComplete) { // payload not complete
if ((mPayload[iv->id].requested) && (retransmit)) { if ((mPayload[iv->id].requested) && (retransmit)) {
if (mPayload[iv->id].retransmits < mMaxRetrans) { if (mPayload[iv->id].retransmits < mMaxRetrans) {
@ -260,10 +261,12 @@ class HmPayload {
} else { } else {
for (uint8_t i = 0; i < (mPayload[iv->id].maxPackId - 1); i++) { for (uint8_t i = 0; i < (mPayload[iv->id].maxPackId - 1); i++) {
if (mPayload[iv->id].len[i] == 0) { if (mPayload[iv->id].len[i] == 0) {
DPRINT_IVID(DBG_WARN, iv->id); if (mSerialDebug) {
DBGPRINT(F("Frame ")); DPRINT_IVID(DBG_WARN, iv->id);
DBGPRINT(String(i + 1)); DBGPRINT(F("Frame "));
DBGPRINTLN(F(" missing: Request Retransmit")); DBGPRINT(String(i + 1));
DBGPRINTLN(F(" missing: Request Retransmit"));
}
mRadio->sendCmdPacket(iv->radioId.u64, TX_REQ_INFO, (SINGLE_FRAME + i), true); mRadio->sendCmdPacket(iv->radioId.u64, TX_REQ_INFO, (SINGLE_FRAME + i), true);
break; // only request retransmit one frame per loop break; // only request retransmit one frame per loop
} }
@ -276,20 +279,25 @@ class HmPayload {
} else if(!crcPass && pyldComplete) { // crc error on complete Payload } else if(!crcPass && pyldComplete) { // crc error on complete Payload
if (mPayload[iv->id].retransmits < mMaxRetrans) { if (mPayload[iv->id].retransmits < mMaxRetrans) {
mPayload[iv->id].retransmits++; mPayload[iv->id].retransmits++;
DPRINTLN(DBG_WARN, F("CRC Error: Request Complete Retransmit"));
mPayload[iv->id].txCmd = iv->getQueuedCmd(); mPayload[iv->id].txCmd = iv->getQueuedCmd();
DPRINT_IVID(DBG_INFO, iv->id); if (mSerialDebug) {
DBGPRINT(F("prepareDevInformCmd 0x")); DPRINTLN(DBG_WARN, F("CRC Error: Request Complete Retransmit"));
DBGHEXLN(mPayload[iv->id].txCmd); DPRINT_IVID(DBG_INFO, iv->id);
DBGPRINT(F("prepareDevInformCmd 0x"));
DBGHEXLN(mPayload[iv->id].txCmd);
}
mRadio->prepareDevInformCmd(iv->radioId.u64, mPayload[iv->id].txCmd, mPayload[iv->id].ts, iv->alarmMesIndex, true); mRadio->prepareDevInformCmd(iv->radioId.u64, mPayload[iv->id].txCmd, mPayload[iv->id].ts, iv->alarmMesIndex, true);
} }
} else { // payload complete } else { // payload complete
DPRINT(DBG_INFO, F("procPyld: cmd: 0x")); if (mSerialDebug) {
DBGHEXLN(mPayload[iv->id].txCmd); DPRINT_IVID(DBG_INFO, iv->id);
//DPRINT(DBG_DEBUG, F("procPyld: txid: 0x")); DBGPRINT(F("procPyld: cmd: 0x"));
//DBGHEXLN(mPayload[iv->id].txId); DBGHEXLN(mPayload[iv->id].txCmd);
DPRINT(DBG_DEBUG, F("procPyld: max: ")); //DPRINT(DBG_DEBUG, F("procPyld: txid: 0x"));
DPRINTLN(DBG_DEBUG, String(mPayload[iv->id].maxPackId)); //DBGHEXLN(mPayload[iv->id].txId);
DPRINT(DBG_DEBUG, F("procPyld: max: "));
DPRINTLN(DBG_DEBUG, String(mPayload[iv->id].maxPackId));
}
record_t<> *rec = iv->getRecordStruct(mPayload[iv->id].txCmd); // choose the parser record_t<> *rec = iv->getRecordStruct(mPayload[iv->id].txCmd); // choose the parser
mPayload[iv->id].complete = true; mPayload[iv->id].complete = true;
@ -347,13 +355,24 @@ class HmPayload {
yield(); yield();
} }
} }
if( (InverterDevInform_All == mPayload[iv->id].txCmd) && (mHighPrioIv == NULL) ) // process next request immediately if possible if (fastNext) {
mHighPrioIv = iv; uint8_t cmd = iv->getQueuedCmd();
if (mSerialDebug) {
DPRINT_IVID(DBG_INFO, iv->id);
DBGPRINT(F("fast mode "));
DBGPRINT(F("prepareDevInformCmd 0x"));
DBGHEXLN(cmd);
}
mRadio->prepareDevInformCmd(iv->radioId.u64, cmd, mPayload[iv->id].ts, iv->alarmMesIndex, false);
mPayload[iv->id].txCmd = cmd;
}
} else { } else {
DPRINT(DBG_ERROR, F("plausibility check failed, expected ")); if (mSerialDebug) {
DBGPRINT(String(rec->pyldLen)); DPRINT(DBG_ERROR, F("plausibility check failed, expected "));
DBGPRINTLN(F(" bytes")); DBGPRINT(String(rec->pyldLen));
DBGPRINTLN(F(" bytes"));
}
mStat->rxFail++; mStat->rxFail++;
} }
@ -370,33 +389,46 @@ class HmPayload {
(mCbPayload)(val, iv); (mCbPayload)(val, iv);
} }
bool build(uint8_t id, bool *complete) { bool build(Inverter<> *iv, bool *complete, bool *fastNext ) {
DPRINTLN(DBG_VERBOSE, F("build")); DPRINTLN(DBG_VERBOSE, F("build"));
uint16_t crc = 0xffff, crcRcv = 0x0000; uint16_t crc = 0xffff, crcRcv = 0x0000;
if (mPayload[id].maxPackId > MAX_PAYLOAD_ENTRIES) if (mPayload[iv->id].maxPackId > MAX_PAYLOAD_ENTRIES)
mPayload[id].maxPackId = MAX_PAYLOAD_ENTRIES; mPayload[iv->id].maxPackId = MAX_PAYLOAD_ENTRIES;
// check if all fragments are there // check if all fragments are there
*complete = true; *complete = true;
for (uint8_t i = 0; i < mPayload[id].maxPackId; i++) { *fastNext = false;
if(mPayload[id].len[i] == 0) for (uint8_t i = 0; i < mPayload[iv->id].maxPackId; i++) {
if(mPayload[iv->id].len[i] == 0) {
*complete = false; *complete = false;
}
} }
if(!*complete) if(!*complete)
return false; return false;
for (uint8_t i = 0; i < mPayload[id].maxPackId; i++) { for (uint8_t i = 0; i < mPayload[iv->id].maxPackId; i++) {
if (mPayload[id].len[i] > 0) { if (mPayload[iv->id].len[i] > 0) {
if (i == (mPayload[id].maxPackId - 1)) { if (i == (mPayload[iv->id].maxPackId - 1)) {
crc = ah::crc16(mPayload[id].data[i], mPayload[id].len[i] - 2, crc); crc = ah::crc16(mPayload[iv->id].data[i], mPayload[iv->id].len[i] - 2, crc);
crcRcv = (mPayload[id].data[i][mPayload[id].len[i] - 2] << 8) | (mPayload[id].data[i][mPayload[id].len[i] - 1]); crcRcv = (mPayload[iv->id].data[i][mPayload[iv->id].len[i] - 2] << 8) | (mPayload[iv->id].data[i][mPayload[iv->id].len[i] - 1]);
} else } else
crc = ah::crc16(mPayload[id].data[i], mPayload[id].len[i], crc); crc = ah::crc16(mPayload[iv->id].data[i], mPayload[iv->id].len[i], crc);
} }
yield(); yield();
} }
return (crc == crcRcv) ? true : false; //return (crc == crcRcv) ? true : false;
if (crc != crcRcv)
return false;
//requests to cause the next request to be executed immediately
if ( mPayload[iv->id].txCmd < 11 || mPayload[iv->id].txCmd > 18 ) {
*fastNext = true;
//DPRINT_IVID(DBG_INFO, iv->id);
//DBGPRINTLN(F("fast next req"));
}
return true;
} }
void reset(uint8_t id) { void reset(uint8_t id) {

Loading…
Cancel
Save