Browse Source

MI - alarms and control and other

* reduce last_success MQTT messages (#1124)
* add re-request if inverter is known to be online and first try fails
* add alarm reporting to MI (might need review!)
* rebuild MI limiting code closer to DTUSimMI example
pull/1170/head
rejoe2 1 year ago
committed by GitHub
parent
commit
afa96506a3
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      src/CHANGES.md
  2. 1
      src/hm/hmDefines.h
  3. 17
      src/hm/hmInverter.h
  4. 70
      src/hm/hmPayload.h
  5. 24
      src/hm/hmRadio.h
  6. 62
      src/hm/miPayload.h
  7. 2
      src/publisher/pubMqttIvData.h

6
src/CHANGES.md

@ -1,5 +1,11 @@
# Development Changes # Development Changes
## 0.5.59
* reduce last_success MQTT messages (#1124)
* add re-request if inverter is known to be online and first try fails
* add alarm reporting to MI (might need review!)
* rebuild MI limiting code closer to DTUSimMI example
## 0.5.58 ## 0.5.58
* fix ESP8266 save settings issue #1166 * fix ESP8266 save settings issue #1166

1
src/hm/hmDefines.h

@ -307,6 +307,7 @@ const devInfo_t devInfo[] = {
{ 0x101010, 300 }, { 0x101010, 300 },
{ 0x101020, 350 }, { 0x101020, 350 },
{ 0x101030, 400 }, { 0x101030, 400 },
{ 0x101040, 400 }, // https://github.com/lumapu/ahoy/issues/1111#issuecomment-1726515824
{ 0x101110, 600 }, // [TSOL800(DE) ..20, HWv=2.66], [HM-600 ..20, HWv=2.66] { 0x101110, 600 }, // [TSOL800(DE) ..20, HWv=2.66], [HM-600 ..20, HWv=2.66]
{ 0x101120, 700 }, { 0x101120, 700 },
{ 0x101130, 800 }, { 0x101130, 800 },

17
src/hm/hmInverter.h

@ -202,7 +202,7 @@ class Inverter {
} }
} }
uint8_t getQueuedCmd() { uint8_t getQueuedCmd() {
if (_commandQueue.empty()) { if (_commandQueue.empty()) {
if (ivGen != IV_MI) { if (ivGen != IV_MI) {
if (getFwVersion() == 0) if (getFwVersion() == 0)
@ -217,13 +217,11 @@ class Inverter {
enqueCommand<InfoCommand>(InverterDevInform_All); // hard- and firmware version enqueCommand<InfoCommand>(InverterDevInform_All); // hard- and firmware version
} else { } else {
record_t<> *rec = getRecordStruct(InverterDevInform_Simple); record_t<> *rec = getRecordStruct(InverterDevInform_Simple);
if (getChannelFieldValue(CH0, FLD_PART_NUM, rec) == 0) if (getChannelFieldValue(CH0, FLD_PART_NUM, rec) == 0) {
enqueCommand<InfoCommand>(InverterDevInform_All); // hard- and firmware version for missing HW part nr, delivered by frame 1 enqueCommand<InfoCommand>(InverterDevInform_All); // hard- and firmware version for missing HW part nr, delivered by frame 1
} } else {
if (type == INV_TYPE_4CH) { enqueCommand<InfoCommand>( type == INV_TYPE_4CH ? 0x36 : 0x09 );
enqueCommand<InfoCommand>(0x36); }
} else {
enqueCommand<InfoCommand>(0x09);
} }
} }
@ -523,10 +521,7 @@ class Inverter {
rec->length = (uint8_t)(HMS1CH_LIST_LEN); rec->length = (uint8_t)(HMS1CH_LIST_LEN);
rec->assign = (byteAssign_t *)hms1chAssignment; rec->assign = (byteAssign_t *)hms1chAssignment;
rec->pyldLen = HMS1CH_PAYLOAD_LEN; rec->pyldLen = HMS1CH_PAYLOAD_LEN;
} /*else if(IV_MI == ivGen) { }
rec->length = (uint8_t)(HM1CH_LIST_LEN);
rec->assign = (byteAssign_t *)hm1chAssignment;
}*/
channels = 1; channels = 1;
} }
else if (INV_TYPE_2CH == type) { else if (INV_TYPE_2CH == type) {

70
src/hm/hmPayload.h

@ -26,6 +26,7 @@ typedef struct {
uint8_t retransmits; uint8_t retransmits;
bool requested; bool requested;
bool gotFragment; bool gotFragment;
bool rxTmo;
} invPayload_t; } invPayload_t;
@ -126,7 +127,7 @@ class HmPayload {
} }
} }
reset(iv->id); reset(iv->id, !iv->isConnected);
mPayload[iv->id].requested = true; mPayload[iv->id].requested = true;
yield(); yield();
@ -151,9 +152,11 @@ class HmPayload {
//iv->enqueCommand<InfoCommand>(SystemConfigPara); // read back power limit //iv->enqueCommand<InfoCommand>(SystemConfigPara); // read back power limit
} else { } else {
uint8_t cmd = iv->getQueuedCmd(); uint8_t cmd = iv->getQueuedCmd();
DPRINT_IVID(DBG_INFO, iv->id); if (mSerialDebug) {
DBGPRINT(F("prepareDevInformCmd 0x")); DPRINT_IVID(DBG_INFO, iv->id);
DBGHEXLN(cmd); DBGPRINT(F("prepareDevInformCmd 0x"));
DBGHEXLN(cmd);
}
mRadio->prepareDevInformCmd(iv->radioId.u64, cmd, mPayload[iv->id].ts, iv->alarmLastId, false); mRadio->prepareDevInformCmd(iv->radioId.u64, cmd, mPayload[iv->id].ts, iv->alarmLastId, false);
mPayload[iv->id].txCmd = cmd; mPayload[iv->id].txCmd = cmd;
} }
@ -199,13 +202,15 @@ class HmPayload {
} else } else
ok = false; ok = false;
DPRINT_IVID(DBG_INFO, iv->id); if (mSerialDebug) {
DBGPRINT(F(" has ")); DPRINT_IVID(DBG_INFO, iv->id);
if(!ok) DBGPRINT(F("not ")); DBGPRINT(F(" has "));
DBGPRINT(F("accepted power limit set point ")); if(!ok) DBGPRINT(F("not "));
DBGPRINT(String(iv->powerLimit[0])); DBGPRINT(F("accepted power limit set point "));
DBGPRINT(F(" with PowerLimitControl ")); DBGPRINT(String(iv->powerLimit[0]));
DBGPRINTLN(String(iv->powerLimit[1])); DBGPRINT(F(" with PowerLimitControl "));
DBGPRINTLN(String(iv->powerLimit[1]));
}
iv->clearCmdQueue(); iv->clearCmdQueue();
iv->enqueCommand<InfoCommand>(SystemConfigPara); // read back power limit iv->enqueCommand<InfoCommand>(SystemConfigPara); // read back power limit
@ -249,15 +254,16 @@ class HmPayload {
mRadio->sendControlPacket(iv->radioId.u64, iv->devControlCmd, iv->powerLimit, true); mRadio->sendControlPacket(iv->radioId.u64, iv->devControlCmd, iv->powerLimit, true);
} else { } else {
if(false == mPayload[iv->id].gotFragment) { if(false == mPayload[iv->id].gotFragment) {
/* DPRINT_IVID(DBG_WARN, iv->id);
DPRINTLN(DBG_WARN, F("nothing received: Request Complete Retransmit")); if (mPayload[iv->id].rxTmo) {
mPayload[iv->id].txCmd = iv->getQueuedCmd(); DBGPRINTLN(F("nothing received"));
DPRINTLN(DBG_INFO, F("(#") + String(iv->id) + F(") prepareDevInformCmd 0x") + String(mPayload[iv->id].txCmd, HEX)); mPayload[iv->id].retransmits = mMaxRetrans;
mRadio->prepareDevInformCmd(iv->radioId.u64, mPayload[iv->id].txCmd, mPayload[iv->id].ts, iv->alarmLastId, true); } else {
*/ DBGPRINTLN(F("nothing received: complete retransmit"));
DPRINT_IVID(DBG_INFO, iv->id); mPayload[iv->id].txCmd = iv->getQueuedCmd();
DBGPRINTLN(F("nothing received")); DPRINTLN(DBG_INFO, F("(#") + String(iv->id) + F(") prepareDevInformCmd 0x") + String(mPayload[iv->id].txCmd, HEX));
mPayload[iv->id].retransmits = mMaxRetrans; mRadio->prepareDevInformCmd(iv->radioId.u64, mPayload[iv->id].txCmd, mPayload[iv->id].ts, iv->alarmMesIndex, true);
}
} 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) {
@ -275,6 +281,9 @@ class HmPayload {
} }
} }
} }
} else if (false == mPayload[iv->id].gotFragment) {
// only if there is no sign of life
mPayload[iv->id].rxTmo = true; // inv might be down, no complete retransmit anymore
} }
} 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) {
@ -292,14 +301,16 @@ class HmPayload {
if (mSerialDebug) { if (mSerialDebug) {
DPRINT_IVID(DBG_INFO, iv->id); DPRINT_IVID(DBG_INFO, iv->id);
DBGPRINT(F("procPyld: cmd: 0x")); DBGPRINT(F("procPyld: cmd: 0x"));
DBGHEXLN(mPayload[iv->id].txCmd); DHEX(mPayload[iv->id].txCmd);
//DPRINT(DBG_DEBUG, F("procPyld: txid: 0x")); DBGPRINT(F("; procPyld: txid: 0x"));
//DBGHEXLN(mPayload[iv->id].txId); DBGHEXLN(mPayload[iv->id].txId);
DPRINT(DBG_DEBUG, F("procPyld: max: ")); DPRINT(DBG_DEBUG, F("procPyld: max: "));
DPRINTLN(DBG_DEBUG, String(mPayload[iv->id].maxPackId)); 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;
mPayload[iv->id].requested = false;
mPayload[iv->id].rxTmo = false;
uint8_t payload[150]; uint8_t payload[150];
uint8_t payloadLen = 0; uint8_t payloadLen = 0;
@ -355,7 +366,8 @@ class HmPayload {
yield(); yield();
} }
} }
if (fastNext) { if (fastNext && mHighPrioIv == NULL) {
/*iv->setQueuedCmdFinished();
uint8_t cmd = iv->getQueuedCmd(); uint8_t cmd = iv->getQueuedCmd();
if (mSerialDebug) { if (mSerialDebug) {
DPRINT_IVID(DBG_INFO, iv->id); DPRINT_IVID(DBG_INFO, iv->id);
@ -366,6 +378,8 @@ class HmPayload {
mStat->rxSuccess++; mStat->rxSuccess++;
mRadio->prepareDevInformCmd(iv->radioId.u64, cmd, mPayload[iv->id].ts, iv->alarmLastId, false); mRadio->prepareDevInformCmd(iv->radioId.u64, cmd, mPayload[iv->id].ts, iv->alarmLastId, false);
mPayload[iv->id].txCmd = cmd; mPayload[iv->id].txCmd = cmd;
*/
mHighPrioIv = iv;
} }
} else { } else {
@ -377,6 +391,7 @@ class HmPayload {
mStat->rxFail++; mStat->rxFail++;
} }
//if (!fastNext)
iv->setQueuedCmdFinished(); iv->setQueuedCmdFinished();
} }
} }
@ -423,16 +438,14 @@ class HmPayload {
return false; return false;
//requests to cause the next request to be executed immediately //requests to cause the next request to be executed immediately
if ( mPayload[iv->id].txCmd < 11 || mPayload[iv->id].txCmd > 18 ) { if ( mPayload[iv->id].gotFragment && ( mPayload[iv->id].txCmd < 11 || mPayload[iv->id].txCmd > 18 ) ) {
*fastNext = true; *fastNext = true;
//DPRINT_IVID(DBG_INFO, iv->id);
//DBGPRINTLN(F("fast next req"));
} }
return true; return true;
} }
void reset(uint8_t id) { void reset(uint8_t id, bool setTxTmo = true) {
//DPRINT_IVID(DBG_INFO, id); //DPRINT_IVID(DBG_INFO, id);
//DBGPRINTLN(F("resetPayload")); //DBGPRINTLN(F("resetPayload"));
memset(mPayload[id].len, 0, MAX_PAYLOAD_ENTRIES); memset(mPayload[id].len, 0, MAX_PAYLOAD_ENTRIES);
@ -444,6 +457,7 @@ class HmPayload {
mPayload[id].complete = false; mPayload[id].complete = false;
mPayload[id].requested = false; mPayload[id].requested = false;
mPayload[id].ts = *mTimestamp; mPayload[id].ts = *mTimestamp;
mPayload[id].rxTmo = setTxTmo; // design: don't start with complete retransmit
} }
IApp *mApp; IApp *mApp;

24
src/hm/hmRadio.h

@ -32,7 +32,7 @@ class HmRadio {
public: public:
HmRadio() : mNrf24(CE_PIN, CS_PIN, SPI_SPEED) { HmRadio() : mNrf24(CE_PIN, CS_PIN, SPI_SPEED) {
if(mSerialDebug) { if(mSerialDebug) {
DPRINT(DBG_VERBOSE, F("hmRadio.h : HmRadio():mNrf24(CE_PIN: ")); DPRINT(DBG_VERBOSE, F("hmRadio.h : HmRadio():mNrf24(CE_PIN: "));
DBGPRINT(String(CE_PIN)); DBGPRINT(String(CE_PIN));
DBGPRINT(F(", CS_PIN: ")); DBGPRINT(F(", CS_PIN: "));
DBGPRINT(String(CS_PIN)); DBGPRINT(String(CS_PIN));
@ -100,6 +100,7 @@ class HmRadio {
mNrf24.startListening(); mNrf24.startListening();
mNrf24.setDataRate(RF24_250KBPS); mNrf24.setDataRate(RF24_250KBPS);
mNrf24.setAutoAck(true); mNrf24.setAutoAck(true);
mNrf24.enableDynamicAck();
mNrf24.enableDynamicPayloads(); mNrf24.enableDynamicPayloads();
mNrf24.setCRCLength(RF24_CRC_16); mNrf24.setCRCLength(RF24_CRC_16);
mNrf24.setAddressWidth(5); mNrf24.setAddressWidth(5);
@ -130,7 +131,7 @@ class HmRadio {
mNrf24.flush_tx(); // empty TX FIFO mNrf24.flush_tx(); // empty TX FIFO
// start listening // start listening
mNrf24.setChannel(mRfChLst[mRxChIdx]); mNrf24.setChannel(mRfChLst[mRxChIdx]);
mNrf24.startListening(); mNrf24.startListening();
uint32_t startMicros = micros(); uint32_t startMicros = micros();
@ -168,7 +169,7 @@ class HmRadio {
mSerialDebug = true; mSerialDebug = true;
} }
void sendControlPacket(uint64_t invId, uint8_t cmd, uint16_t *data, bool isRetransmit, bool isNoMI = true) { void sendControlPacket(uint64_t invId, uint8_t cmd, uint16_t *data, bool isRetransmit, bool isNoMI = true, bool is4chMI = false) {
DPRINT(DBG_INFO, F("sendControlPacket cmd: 0x")); DPRINT(DBG_INFO, F("sendControlPacket cmd: 0x"));
DBGHEXLN(cmd); DBGHEXLN(cmd);
initPacket(invId, TX_REQ_DEVCONTROL, SINGLE_FRAME); initPacket(invId, TX_REQ_DEVCONTROL, SINGLE_FRAME);
@ -194,10 +195,21 @@ class HmRadio {
mTxBuf[10] = 0x55; mTxBuf[10] = 0x55;
break; break;
case ActivePowerContr: case ActivePowerContr:
cnt++;
mTxBuf[9] = 0x5a; mTxBuf[9] = 0x5a;
mTxBuf[10] = 0x5a; mTxBuf[10] = 0x5a;
mTxBuf[11] = data[0]; // power limit //Testing only! Original NRF24_DTUMIesp.ino code #L612-L613:
//UsrData[0]=0x5A;UsrData[1]=0x5A;UsrData[2]=100;//0x0a;// 10% limit
//UsrData[3]=((Limit*10) >> 8) & 0xFF; UsrData[4]= (Limit*10) & 0xFF; //WR needs 1 dec= zB 100.1 W
if (is4chMI) {
mTxBuf[cnt++] = 100; //10% limit, seems to be necessary to send sth. at all, but for MI-1500 this has no effect
//works (if ever!) only for absulute power limits!
mTxBuf[cnt++] = ((data[0] * 10) >> 8) & 0xff; // power limit
mTxBuf[cnt++] = ((data[0] * 10) ) & 0xff; // power limit
} else {
mTxBuf[cnt++] = data[0]*10; // power limit
}
break; break;
default: default:
return; return;
@ -242,7 +254,7 @@ class HmRadio {
bool mSerialDebug; bool mSerialDebug;
private: private:
bool getReceived(void) { bool getReceived(void) {
bool tx_ok, tx_fail, rx_ready; bool tx_ok, tx_fail, rx_ready;
mNrf24.whatHappened(tx_ok, tx_fail, rx_ready); // resets the IRQ pin to HIGH mNrf24.whatHappened(tx_ok, tx_fail, rx_ready); // resets the IRQ pin to HIGH

62
src/hm/miPayload.h

@ -28,6 +28,7 @@ typedef struct {
bool gotFragment; bool gotFragment;
uint8_t rtrRes; // for limiting resets uint8_t rtrRes; // for limiting resets
uint8_t multi_parts; // for quality uint8_t multi_parts; // for quality
bool rxTmo;
} miPayload_t; } miPayload_t;
@ -47,7 +48,7 @@ class MiPayload {
mMaxRetrans = maxRetransmits; mMaxRetrans = maxRetransmits;
mTimestamp = timestamp; mTimestamp = timestamp;
for(uint8_t i = 0; i < MAX_NUM_INVERTERS; i++) { for(uint8_t i = 0; i < MAX_NUM_INVERTERS; i++) {
reset(i, true); reset(i, false, true);
mPayload[i].limitrequested = true; mPayload[i].limitrequested = true;
} }
mSerialDebug = false; mSerialDebug = false;
@ -84,7 +85,7 @@ class MiPayload {
if (!mPayload[iv->id].complete) if (!mPayload[iv->id].complete)
process(false); // no retransmit process(false); // no retransmit
if (!mPayload[iv->id].complete) { if (!mPayload[iv->id].complete && mPayload[iv->id].rxTmo) {
if (mSerialDebug) if (mSerialDebug)
DPRINT_IVID(DBG_INFO, iv->id); DPRINT_IVID(DBG_INFO, iv->id);
if (!mPayload[iv->id].gotFragment) { if (!mPayload[iv->id].gotFragment) {
@ -100,13 +101,14 @@ class MiPayload {
DBGPRINTLN(F(")")); DBGPRINTLN(F(")"));
} }
} }
mPayload[iv->id].rxTmo = true;
mPayload[iv->id].complete = true; mPayload[iv->id].complete = true;
iv->setQueuedCmdFinished(); // command failed iv->setQueuedCmdFinished(); // command failed
} }
} }
} }
reset(iv->id); reset(iv->id, !iv->isConnected);
mPayload[iv->id].requested = true; mPayload[iv->id].requested = true;
yield(); yield();
@ -125,12 +127,11 @@ class MiPayload {
DBGPRINTLN(String(iv->powerLimit[0])); DBGPRINTLN(String(iv->powerLimit[0]));
} }
iv->powerLimitAck = false; iv->powerLimitAck = false;
mRadio->sendControlPacket(iv->radioId.u64, iv->devControlCmd, iv->powerLimit, false, false); mRadio->sendControlPacket(iv->radioId.u64, iv->devControlCmd, iv->powerLimit, false, false, iv->type == INV_TYPE_4CH);
mPayload[iv->id].txCmd = iv->devControlCmd; mPayload[iv->id].txCmd = iv->devControlCmd;
mPayload[iv->id].limitrequested = true; mPayload[iv->id].limitrequested = true;
iv->clearCmdQueue(); iv->clearCmdQueue();
//iv->enqueCommand<InfoCommand>(SystemConfigPara); // read back power limit is not possible with MI
} else { } else {
uint8_t cmd = iv->getQueuedCmd(); uint8_t cmd = iv->getQueuedCmd();
uint8_t cmd2 = cmd; uint8_t cmd2 = cmd;
@ -311,6 +312,7 @@ class MiPayload {
mPayload[iv->id].txCmd != 0x0f)) { mPayload[iv->id].txCmd != 0x0f)) {
// no processing needed if txId is not one of 0x95, 0x88, 0x89, 0x91, 0x92 or response to 0x36ff // no processing needed if txId is not one of 0x95, 0x88, 0x89, 0x91, 0x92 or response to 0x36ff
mPayload[iv->id].complete = true; mPayload[iv->id].complete = true;
mPayload[iv->id].rxTmo = true;
continue; // skip to next inverter continue; // skip to next inverter
} }
@ -324,6 +326,7 @@ class MiPayload {
DPRINT_IVID(DBG_INFO, iv->id); DPRINT_IVID(DBG_INFO, iv->id);
DBGPRINTLN(F("Prevent retransmit on Restart / CleanState_LockAndAlarm...")); DBGPRINTLN(F("Prevent retransmit on Restart / CleanState_LockAndAlarm..."));
mPayload[iv->id].retransmits = mMaxRetrans; mPayload[iv->id].retransmits = mMaxRetrans;
mPayload[iv->id].rxTmo = true;
} else if(iv->devControlCmd == ActivePowerContr) { } else if(iv->devControlCmd == ActivePowerContr) {
DPRINT_IVID(DBG_INFO, iv->id); DPRINT_IVID(DBG_INFO, iv->id);
DBGPRINTLN(F("retransmit power limit")); DBGPRINTLN(F("retransmit power limit"));
@ -332,10 +335,15 @@ class MiPayload {
uint8_t cmd = mPayload[iv->id].txCmd; uint8_t cmd = mPayload[iv->id].txCmd;
if (mPayload[iv->id].retransmits < mMaxRetrans) { if (mPayload[iv->id].retransmits < mMaxRetrans) {
mPayload[iv->id].retransmits++; mPayload[iv->id].retransmits++;
if( !mPayload[iv->id].gotFragment ) { if( !mPayload[iv->id].gotFragment && mPayload[iv->id].rxTmo ) {
DPRINT_IVID(DBG_INFO, iv->id); DPRINT_IVID(DBG_INFO, iv->id);
DBGPRINTLN(F("nothing received")); DBGPRINTLN(F("nothing received"));
mPayload[iv->id].retransmits = mMaxRetrans; mPayload[iv->id].retransmits = mMaxRetrans;
} else if( !mPayload[iv->id].gotFragment && !mPayload[iv->id].rxTmo ) {
DPRINT_IVID(DBG_INFO, iv->id);
DBGPRINTLN(F("retransmit on failed first request"));
mPayload[iv->id].rxTmo = true;
mRadio->sendCmdPacket(iv->radioId.u64, cmd, cmd, true, false);
} else if ( cmd == 0x0f ) { } else if ( cmd == 0x0f ) {
//hard/firmware request //hard/firmware request
mRadio->sendCmdPacket(iv->radioId.u64, 0x0f, 0x00, true, false); mRadio->sendCmdPacket(iv->radioId.u64, 0x0f, 0x00, true, false);
@ -379,6 +387,8 @@ class MiPayload {
mRadio->sendCmdPacket(iv->radioId.u64, cmd, cmd, true, false); mRadio->sendCmdPacket(iv->radioId.u64, cmd, cmd, true, false);
yield(); yield();
} }
} else {
mPayload[iv->id].rxTmo = true;
} }
} }
} }
@ -395,9 +405,14 @@ class MiPayload {
DBGHEXLN(mPayload[iv->id].txCmd); DBGHEXLN(mPayload[iv->id].txCmd);
} }
mRadio->sendCmdPacket(iv->radioId.u64, mPayload[iv->id].txCmd, mPayload[iv->id].txCmd, false, false); mRadio->sendCmdPacket(iv->radioId.u64, mPayload[iv->id].txCmd, mPayload[iv->id].txCmd, false, false);
} else {
mPayload[iv->id].rxTmo = true;
} }
} else { } else {
if (fastNext) { if (!fastNext) {
mPayload[iv->id].rxTmo = true;
} else {
/*iv->setQueuedCmdFinished();
uint8_t cmd = iv->getQueuedCmd(); uint8_t cmd = iv->getQueuedCmd();
if (mSerialDebug) { if (mSerialDebug) {
DPRINT_IVID(DBG_INFO, iv->id); DPRINT_IVID(DBG_INFO, iv->id);
@ -406,11 +421,16 @@ class MiPayload {
DBGHEXLN(cmd); DBGHEXLN(cmd);
} }
mStat->rxSuccess++; mStat->rxSuccess++;
mRadio->prepareDevInformCmd(iv->radioId.u64, cmd, mPayload[iv->id].ts, iv->alarmMesIndex, false); //mRadio->prepareDevInformCmd(iv->radioId.u64, cmd, mPayload[iv->id].ts, iv->alarmMesIndex, false);
mPayload[iv->id].txCmd = cmd; mRadio->prepareDevInformCmd(iv->radioId.u64, iv->getType(),
iv->getNextTxChanIndex(), cmd, mPayload[iv->id].ts, iv->alarmMesIndex, false);
mPayload[iv->id].txCmd = cmd; */
if (mHighPrioIv == NULL)
mHighPrioIv = iv;
} }
} }
} else {
mPayload[iv->id].rxTmo = true;
} }
yield(); yield();
} }
@ -456,6 +476,15 @@ class MiPayload {
uint16_t prntsts = statusMi == 3 ? 1 : statusMi; uint16_t prntsts = statusMi == 3 ? 1 : statusMi;
if ( statusMi != mPayload[iv->id].sts[stschan] ) { //sth.'s changed? if ( statusMi != mPayload[iv->id].sts[stschan] ) { //sth.'s changed?
iv->alarmCnt = 1; // minimum...
if (iv->type != INV_TYPE_1CH && ( statusMi != 3 //sth is or was wrong!
|| mPayload[iv->id].sts[stschan] && statusMi == 3 && mPayload[iv->id].sts[stschan] != 3)
) {
iv->lastAlarm[stschan] = alarm_t(prntsts, mPayload[iv->id].ts,mPayload[iv->id].ts);
iv->alarmCnt = iv->type == INV_TYPE_2CH ? 3 : 5;
iv->alarmLastId = iv->alarmMesIndex;
}
mPayload[iv->id].sts[stschan] = statusMi; mPayload[iv->id].sts[stschan] = statusMi;
if (mSerialDebug) { if (mSerialDebug) {
DPRINT(DBG_WARN, F("New state on CH")); DPRINT(DBG_WARN, F("New state on CH"));
@ -477,6 +506,7 @@ class MiPayload {
DBGPRINT(F("alarm ID incremented to ")); DBGPRINT(F("alarm ID incremented to "));
DBGPRINTLN(String(iv->alarmMesIndex)); DBGPRINTLN(String(iv->alarmMesIndex));
} }
iv->lastAlarm[0] = alarm_t(prntsts, mPayload[iv->id].ts, mPayload[iv->id].ts);
} }
/*if(AlarmData == mPayload[iv->id].txCmd) { /*if(AlarmData == mPayload[iv->id].txCmd) {
uint8_t i = 0; uint8_t i = 0;
@ -584,6 +614,7 @@ class MiPayload {
uint8_t txCmd = mPayload[iv->id].txCmd; uint8_t txCmd = mPayload[iv->id].txCmd;
if(!*complete) { if(!*complete) {
DPRINTLN(DBG_VERBOSE, F("incomlete, txCmd is 0x") + String(txCmd, HEX));
//we got some delayed status msgs?!? //we got some delayed status msgs?!?
if ((txCmd == 0x09) || (txCmd == 0x11)) { if ((txCmd == 0x09) || (txCmd == 0x11)) {
if (mPayload[iv->id].stsAB[CH0] && mPayload[iv->id].dataAB[CH0]) { if (mPayload[iv->id].stsAB[CH0] && mPayload[iv->id].dataAB[CH0]) {
@ -592,8 +623,6 @@ class MiPayload {
} }
return false; return false;
} }
DPRINTLN(DBG_VERBOSE, F("incomlete, txCmd is 0x") + String(txCmd, HEX));
if (txCmd >= 0x36 && txCmd <= 0x39) { if (txCmd >= 0x36 && txCmd <= 0x39) {
return false; return false;
} }
@ -607,7 +636,7 @@ class MiPayload {
} }
//check if we want the next request to be executed faster //check if we want the next request to be executed faster
if (txCmd == 0x0f) if (mPayload[iv->id].gotFragment && txCmd == 0x0f)
*fastNext = true; *fastNext = true;
return true; return true;
} }
@ -725,16 +754,18 @@ const byteAssign_t InfoAssignment[] = {
if (mPayload[iv->id].multi_parts > 5) { if (mPayload[iv->id].multi_parts > 5) {
iv->setQueuedCmdFinished(); iv->setQueuedCmdFinished();
mPayload[iv->id].complete = true; mPayload[iv->id].complete = true;
mPayload[iv->id].rxTmo = true;
mPayload[iv->id].requested= false; mPayload[iv->id].requested= false;
mStat->rxSuccess++; mStat->rxSuccess++;
} }
} }
void reset(uint8_t id, bool clrSts = false) { void reset(uint8_t id, bool setTxTmo = true, bool clrSts = false) {
memset(mPayload[id].len, 0, MAX_PAYLOAD_ENTRIES); memset(mPayload[id].len, 0, MAX_PAYLOAD_ENTRIES);
mPayload[id].gotFragment = false; mPayload[id].gotFragment = false;
mPayload[id].rxTmo = setTxTmo;// design: don't start with complete retransmit
mPayload[id].rtrRes = 0; mPayload[id].rtrRes = 0;
mPayload[id].multi_parts = 0; mPayload[id].multi_parts = 0;
mPayload[id].retransmits = 0; mPayload[id].retransmits = 0;
mPayload[id].complete = false; mPayload[id].complete = false;
mPayload[id].dataAB[CH0] = true; //required for 1CH and 2CH devices mPayload[id].dataAB[CH0] = true; //required for 1CH and 2CH devices
@ -744,7 +775,6 @@ const byteAssign_t InfoAssignment[] = {
mPayload[id].stsAB[CH1] = true; //required for 1CH and 2CH devices mPayload[id].stsAB[CH1] = true; //required for 1CH and 2CH devices
mPayload[id].stsAB[CH2] = true; //only required for 2CH devices mPayload[id].stsAB[CH2] = true; //only required for 2CH devices
mPayload[id].txCmd = 0; mPayload[id].txCmd = 0;
//mPayload[id].skipfirstrepeat = 0;
mPayload[id].requested = false; mPayload[id].requested = false;
mPayload[id].ts = *mTimestamp; mPayload[id].ts = *mTimestamp;
mPayload[id].sts[0] = 0; mPayload[id].sts[0] = 0;

2
src/publisher/pubMqttIvData.h

@ -103,7 +103,7 @@ class PubMqttIvData {
mPos = 0; mPos = 0;
if(found) { if(found) {
record_t<> *rec = mIv->getRecordStruct(mCmd); record_t<> *rec = mIv->getRecordStruct(mCmd);
if(mIv->getLastTs(rec) != mIvLastPublish[mIv->id]) { if(mIv->getLastTs(rec) != mIvLastPublish[mIv->id] && mIv->getLastTs(rec) != 0 ) { //workaround for startup. Suspect, mCmd might cause to much messages....
snprintf(mSubTopic, 32 + MAX_NAME_LENGTH, "%s/last_success", mIv->config->name); snprintf(mSubTopic, 32 + MAX_NAME_LENGTH, "%s/last_success", mIv->config->name);
snprintf(mVal, 40, "%d", mIv->getLastTs(rec)); snprintf(mVal, 40, "%d", mIv->getLastTs(rec));
mPublish(mSubTopic, mVal, true, QOS_0); mPublish(mSubTopic, mVal, true, QOS_0);

Loading…
Cancel
Save