Browse Source

fix statistics

- based on 0.8.65!
pull/1394/head
rejoe2 1 year ago
committed by GitHub
parent
commit
626ca86d0d
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 6
      src/hm/CommQueue.h
  2. 41
      src/hm/Communication.h
  3. 22
      src/hm/hmRadio.h
  4. 10
      src/hm/radio.h
  5. 14
      src/hms/hmsRadio.h

6
src/hm/CommQueue.h

@ -18,8 +18,6 @@
template <uint8_t N=100>
class CommQueue {
public:
CommQueue() {}
void addImportant(Inverter<> *iv, uint8_t cmd) {
dec(&mRdPtr);
mQueue[mRdPtr] = queue_s(iv, cmd, true);
@ -34,12 +32,12 @@ class CommQueue {
mQueue[mWrPtr] = queue_s(iv, cmd, false);
}
uint8_t getFillState(void) {
uint8_t getFillState(void) const {
//DPRINTLN(DBG_INFO, "wr: " + String(mWrPtr) + ", rd: " + String(mRdPtr));
return abs(mRdPtr - mWrPtr);
}
uint8_t getMaxFill(void) {
uint8_t getMaxFill(void) const {
return N;
}

41
src/hm/Communication.h

@ -83,6 +83,7 @@ class Communication : public CommQueue<> {
q->iv->mGotFragment = false;
q->iv->mGotLastMsg = false;
q->iv->curFrmCnt = 0;
q->iv->radioStatistics.txCnt++;
mIsRetransmit = false;
if(NULL == q->iv->radio)
cmdDone(false); // can't communicate while radio is not defined!
@ -112,7 +113,7 @@ class Communication : public CommQueue<> {
} else
q->iv->radio->prepareDevInformCmd(q->iv, q->cmd, q->ts, q->iv->alarmLastId, false);
q->iv->radioStatistics.txCnt++;
//q->iv->radioStatistics.txCnt++;
q->iv->radio->mRadioWaitTime.startTimeMonitor(mTimeout);
if(!mIsRetransmit && (q->cmd == AlarmData) || (q->cmd == GridOnProFilePara))
incrAttempt(q->cmd == AlarmData? MORE_ATTEMPS_ALARMDATA : MORE_ATTEMPS_GRIDONPROFILEPARA);
@ -129,22 +130,13 @@ class Communication : public CommQueue<> {
break;
case States::CHECK_FRAMES: {
if((q->iv->radio->mBufCtrl.empty() && !mIsRetransmit) ) { // || (0 == q->attempts)) { // radio buffer empty or no more answers
if((q->iv->radio->mBufCtrl.empty() && !mIsRetransmit) ) { // || (0 == q->attempts)) { // radio buffer empty. No more answers will be checked later
if(*mSerialDebug) {
DPRINT_IVID(DBG_INFO, q->iv->id);
DBGPRINT(F("request timeout: "));
DBGPRINT(String(q->iv->radio->mRadioWaitTime.getRunTime()));
DBGPRINTLN(F("ms"));
/*if(INV_RADIO_TYPE_NRF == q->iv->ivRadioType) {
DBGPRINT(F(", retries "));
DBGPRINTLN(String(q->iv->radio->mTxRetriesNext));
DBGPRINT(F(", ARC "));
DBGPRINT(String(q->iv->radio->getARC()));
DBGPRINT(F(", PLOS "));
DBGPRINTLN(String(q->iv->radio->getPLOS()));
} else
DBGPRINTLN("");*/
}
}
if(!q->iv->mGotFragment) {
if(INV_RADIO_TYPE_CMT == q->iv->ivRadioType) {
q->iv->radio->switchFrequency(q->iv, HOY_BOOT_FREQ_KHZ, (q->iv->config->frequency*FREQ_STEP_KHZ + HOY_BASE_FREQ_KHZ));
@ -157,14 +149,13 @@ class Communication : public CommQueue<> {
if(mFirstTry) {
if(q->attempts < 3 || !q->iv->isProducing())
mFirstTry = false;
//setAttempt();
mHeu.evalTxChQuality(q->iv, false, 0, 0);
mHeu.getTxCh(q->iv);
//q->iv->radioStatistics.rxFailNoAnser++; // should only be one of fail or retransmit.
q->iv->radioStatistics.txCnt--;
//q->iv->radioStatistics.txCnt--;
q->iv->radioStatistics.retransmits++;
q->iv->radio->mRadioWaitTime.stopTimeMonitor();
mState = States::START;
return;
}
}
@ -210,7 +201,6 @@ class Communication : public CommQueue<> {
if(q->iv->ivGen != IV_MI) {
mState = States::CHECK_PACKAGE;
} else {
//bool fastNext = true;
if(q->iv->miMultiParts < 6) {
mState = States::WAIT;
if((q->iv->radio->mRadioWaitTime.isTimeout() && mIsRetransmit) || !mIsRetransmit) {
@ -223,12 +213,8 @@ class Communication : public CommQueue<> {
|| ((q->cmd == MI_REQ_CH2) && (q->iv->type == INV_TYPE_2CH))
|| ((q->cmd == MI_REQ_CH1) && (q->iv->type == INV_TYPE_1CH))) {
miComplete(q->iv);
//fastNext = false;
}
/*if(fastNext)
miNextRequest(q->iv->type == INV_TYPE_4CH ? MI_REQ_4CH : MI_REQ_CH1, q);
else*/
closeRequest(q, true);
closeRequest(q, true);
}
}
@ -278,6 +264,8 @@ class Communication : public CommQueue<> {
DBGPRINT(F(" frames missing "));
DBGPRINTLN(F("-> complete retransmit"));
}
q->iv->radioStatistics.txCnt--;
q->iv->radioStatistics.retransmits++;
mState = States::RESET;
return;
}
@ -318,11 +306,6 @@ class Communication : public CommQueue<> {
DBGPRINT(String(p->millis));
DBGPRINT(F("ms | "));
DBGPRINT(String(p->len));
/*DBGPRINT(F(", ARC "));
DBGPRINT(String(p->arc));
DBGPRINT(F(", PLOS "));
DBGPRINT(String(p->plos));*/
DBGPRINT(F(" |"));
if(INV_RADIO_TYPE_NRF == q->iv->ivRadioType) {
DBGPRINT(F(" CH"));
if(3 == p->ch)
@ -555,7 +538,7 @@ class Communication : public CommQueue<> {
len -= 2;
//DPRINT_IVID(DBG_INFO, q->iv->id);
//DPRINT_IVID(DBG_INFO, q->iv->id); // it's already above "for"-loop
DBGPRINT(F("Payload ("));
DBGPRINT(String(len));
if(*mPrintWholeTrace) {
@ -856,8 +839,8 @@ class Communication : public CommQueue<> {
DBGHEXLN(cmd);
}
//if(q->iv->miMultiParts > 5) //if(q->iv->miMultiParts == 7)
q->iv->radioStatistics.rxSuccess++;
/*if(q->iv->miMultiParts > 5) //if(q->iv->miMultiParts == 7)
q->iv->radioStatistics.rxSuccess++;*/
q->iv->radioStatistics.ivSent++;
mFramesExpected = getFramesExpected(q);

22
src/hm/hmRadio.h

@ -15,7 +15,6 @@
#endif
#define SPI_SPEED 1000000
#define RF_CHANNELS 5
const char* const rf24AmpPowerNames[] = {"MIN", "LOW", "HIGH", "MAX"};
@ -194,8 +193,7 @@ class HmRadio : public Radio {
return false;
}
bool isChipConnected(void) {
//DPRINTLN(DBG_VERBOSE, F("hmRadio.h:isChipConnected"));
bool isChipConnected(void) const {
return mNrf24->isChipConnected();
}
@ -285,24 +283,16 @@ class HmRadio : public Radio {
sendPacket(iv, cnt, isRetransmit, (IV_MI != iv->ivGen));
}
uint8_t getDataRate(void) {
uint8_t getDataRate(void) const {
if(!mNrf24->isChipConnected())
return 3; // unknown
return mNrf24->getDataRate();
}
bool isPVariant(void) {
bool isPVariant(void) const {
return mNrf24->isPVariant();
}
/*uint8_t getARC(void) {
return mNrf24->getARC();
}
uint8_t getPLOS(void) {
return mNrf24->getPLOS();
}*/
private:
inline bool getReceived(void) {
bool isLastPackage = false;
@ -318,8 +308,6 @@ class HmRadio : public Radio {
p.len = (len > MAX_RF_PAYLOAD_SIZE) ? MAX_RF_PAYLOAD_SIZE : len;
p.rssi = mNrf24->testRPD() ? -64 : -75;
p.millis = millis() - mMillis;
//p.arc = mNrf24->getARC();
//p.plos = mNrf24->getPLOS();
mNrf24->read(p.packet, p.len);
if (p.packet[0] != 0x00) {
@ -411,11 +399,11 @@ class HmRadio : public Radio {
mNRFisInRX = false;
}
uint64_t getIvId(Inverter<> *iv) {
uint64_t getIvId(Inverter<> *iv) const {
return iv->radioId.u64;
}
uint8_t getIvGen(Inverter<> *iv) {
uint8_t getIvGen(Inverter<> *iv) const {
return iv->ivGen;
}

10
src/hm/radio.h

@ -27,10 +27,8 @@ class Radio {
virtual void sendControlPacket(Inverter<> *iv, uint8_t cmd, uint16_t *data, bool isRetransmit) = 0;
virtual bool switchFrequency(Inverter<> *iv, uint32_t fromkHz, uint32_t tokHz) { return true; }
virtual bool switchFrequencyCh(Inverter<> *iv, uint8_t fromCh, uint8_t toCh) { return true; }
virtual bool isChipConnected(void) { return false; }
virtual bool isChipConnected(void) const { return false; }
virtual bool loop(void) = 0;
//virtual uint8_t getARC(void) { return 0xff; }
//virtual uint8_t getPLOS(void) { return 0xff; }
void handleIntr(void) {
mIrqRcvd = true;
@ -66,7 +64,7 @@ class Radio {
sendPacket(iv, 24, isRetransmit);
}
uint32_t getDTUSn(void) {
uint32_t getDTUSn(void) const {
return mDtuSn;
}
@ -83,8 +81,8 @@ class Radio {
protected:
virtual void sendPacket(Inverter<> *iv, uint8_t len, bool isRetransmit, bool appendCrc16=true) = 0;
virtual uint64_t getIvId(Inverter<> *iv) = 0;
virtual uint8_t getIvGen(Inverter<> *iv) = 0;
virtual uint64_t getIvId(Inverter<> *iv) const = 0;
virtual uint8_t getIvGen(Inverter<> *iv) const = 0;
void initPacket(uint64_t ivId, uint8_t mid, uint8_t pid) {
mTxBuf[0] = mid;

14
src/hms/hmsRadio.h

@ -14,8 +14,7 @@ class CmtRadio : public Radio {
typedef Cmt2300a CmtType;
public:
CmtRadio() {
mDtuSn = DTU_SN;
mCmtAvail = false;
mDtuSn = DTU_SN;
}
void setup(bool *serialDebug, bool *privacyMode, bool *printWholeTrace, uint8_t pinSclk, uint8_t pinSdio, uint8_t pinCsb, uint8_t pinFcsb, bool genDtuSn = true) {
@ -38,7 +37,7 @@ class CmtRadio : public Radio {
return false;
}
bool isChipConnected(void) {
bool isChipConnected(void) const {
return mCmtAvail;
}
@ -116,11 +115,11 @@ class CmtRadio : public Radio {
iv->mDtuTxCnt++;
}
uint64_t getIvId(Inverter<> *iv) {
uint64_t getIvId(Inverter<> *iv) const {
return iv->radioId.u64;
}
uint8_t getIvGen(Inverter<> *iv) {
uint8_t getIvGen(Inverter<> *iv) const {
return iv->ivGen;
}
@ -165,11 +164,10 @@ class CmtRadio : public Radio {
if(CMT_SUCCESS == status)
mBufCtrl.push(p);
// this code completly stops communication!
if(p.packet[9] > ALL_FRAMES) // indicates last frame
// mRadioWaitTime.stopTimeMonitor(); // we got everything we expected and can exit rx mode...
//optionally instead:
mRadioWaitTime.startTimeMonitor(DURATION_PAUSE_LASTFR); // let the inverter first get back to rx mode?
// optionally instead:
// mRadioWaitTime.stopTimeMonitor(); // we got everything we expected and can exit rx mode...
}
CmtType mCmt;

Loading…
Cancel
Save