Browse Source

restrict rx channels

and change timings for hmRadio-rx
pull/1284/head
rejoe2 2 years ago
committed by GitHub
parent
commit
2d65854dfb
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      src/defines.h
  2. 8
      src/hm/Communication.h
  3. 9
      src/hm/hmInverter.h
  4. 54
      src/hm/hmRadio.h
  5. 1
      src/hm/radio.h
  6. 4
      src/hms/hmsRadio.h

2
src/defines.h

@ -13,7 +13,7 @@
//-------------------------------------
#define VERSION_MAJOR 0
#define VERSION_MINOR 8
#define VERSION_PATCH 23
#define VERSION_PATCH 2301
//-------------------------------------
typedef struct {

8
src/hm/Communication.h

@ -86,6 +86,9 @@ class Communication : public CommQueue<> {
if(NULL == q->iv->radio)
cmdDone(true); // can't communicate while radio is not defined!
mState = States::START;
q->iv->radio->prepareReceive(q->iv, q->cmd, false);
break;
case States::START:
@ -246,6 +249,9 @@ class Communication : public CommQueue<> {
DBGPRINT(String(q->attempts));
DBGPRINTLN(F(" attempts left)"));
}
if (!mIsRetransmit)
q->iv->radio->prepareReceive(q->iv, q->cmd, true);
sendRetransmit(q, (framnr-1));
mIsRetransmit = true;
mlastTO_min = timeout_min;
@ -505,7 +511,7 @@ class Communication : public CommQueue<> {
q->iv->mGotFragment = false;
q->iv->mGotLastMsg = false;
q->iv->miMultiParts = 0;
mIsRetransmit = false;
mIsRetransmit = false;
mFirstTry = false; // for correct reset
mState = States::RESET;
DBGPRINTLN(F("-----"));

9
src/hm/hmInverter.h

@ -131,6 +131,11 @@ class Inverter {
bool mGotFragment; // shows if inverter has sent at least one fragment
uint8_t curFrmCnt; // count received frames in current loop
bool mGotLastMsg; // shows if inverter has already finished transmission cycle
uint8_t mRxChannels; // number of rx channels to listen to, defaults to 3;
uint32_t mRxTmoOuterLoop; // timeout for entire listening loop after sending, defaults to 400 (ms);
uint32_t mRxTmoInnerLoop; // timeout for each listening channel, defaults to 5110 (us)
uint8_t lastCmd; // holds the last sent command, defaults to 0xFF
Radio *radio; // pointer to associated radio class
statistics_t radioStatistics; // information about transmitted, failed, ... packets
HeuristicInv heuristics;
@ -156,7 +161,11 @@ class Inverter {
alarmLastId = 0;
rssi = -127;
miMultiParts = 0;
lastCmd = 0xFF;
mGotLastMsg = false;
mRxChannels = 3;
mRxTmoOuterLoop = 400;
mRxTmoInnerLoop = 5110;
radio = NULL;
commEnabled = true;

54
src/hm/hmRadio.h

@ -104,6 +104,41 @@ class HmRadio : public Radio {
DPRINTLN(DBG_WARN, F("WARNING! your NRF24 module can't be reached, check the wiring"));
}
void prepareReceive(Inverter<> *iv, uint8_t cmd, bool singleframe = false) {
if (singleframe) {
iv->mRxTmoOuterLoop = 65; // SINGLEFR_TIMEOUT
iv->lastCmd = 0xFF;
return;
}
if ( (iv->lastCmd == cmd) || ((iv->ivGen == IV_MI) && (iv->lastCmd != 0xFF)) )
return; // nothing to be changed....
iv->lastCmd = cmd;
if (iv->ivGen != IV_MI) {
if (cmd == RealTimeRunData_Debug) {
if (iv->type == INV_TYPE_4CH) {
iv->mRxChannels = 3;
iv->mRxTmoOuterLoop = 300;
iv->mRxTmoInnerLoop = 5110;
} else {
iv->mRxChannels = 2;
iv->mRxTmoOuterLoop = 250;
iv->mRxTmoInnerLoop = 10220;
}
} else { //3rd gen defaults
iv->mRxChannels = 3;
iv->mRxTmoOuterLoop = 500;
iv->mRxTmoInnerLoop = 5110;
}
} else { // 2nd gen defaults
iv->mRxChannels = 2;
iv->mRxTmoOuterLoop = 250;
iv->mRxTmoInnerLoop = 5110;
}
}
void loop(void) {
if (!mIrqRcvd)
return; // nothing to do
@ -121,8 +156,8 @@ class HmRadio : public Radio {
uint32_t startMicros = micros();
uint32_t loopMillis = millis();
while ((millis() - loopMillis) < 400) {
while ((micros() - startMicros) < 5110) { // listen (4088us or?) 5110us to each channel
while ((millis() - loopMillis) < mLastIv->mRxTmoOuterLoop) {
while ((micros() - startMicros) < mLastIv->mRxTmoInnerLoop) { // listen (4088us or?) 5110us to each channel
if (mIrqRcvd) {
mIrqRcvd = false;
@ -133,9 +168,16 @@ class HmRadio : public Radio {
yield();
}
// switch to next RX channel
if(++mRxChIdx >= RF_CHANNELS)
/*if(++mRxChIdx >= RF_CHANNELS)
mRxChIdx = 0;*/
if(++mRxChIdx >= mLastIv->mRxChannels)
mRxChIdx = 0;
mNrf24->setChannel(mRfChLst[mRxChIdx]);
uint8_t nextRxCh = (mRxChIdx + mTxChIdx + 1) % RF_MAX_CHANNEL_ID;
//mNrf24->setChannel(mRfChLst[mRxChIdx]);
mNrf24->setChannel(mRfChLst[nextRxCh]);
startMicros = micros();
}
// not finished but time is over
@ -337,8 +379,8 @@ class HmRadio : public Radio {
uint64_t DTU_RADIO_ID;
uint8_t mRfChLst[RF_CHANNELS] = {03, 23, 40, 61, 75}; // channel List:2403, 2423, 2440, 2461, 2475MHz
uint8_t mTxChIdx = 0;
uint8_t mRxChIdx = 0;
uint8_t mTxChIdx = 0;
uint8_t mRxChIdx = 0;
bool mGotLastMsg = false;
uint32_t mMillis;

1
src/hm/radio.h

@ -22,6 +22,7 @@ class Inverter;
class Radio {
public:
virtual void sendControlPacket(Inverter<> *iv, uint8_t cmd, uint16_t *data, bool isRetransmit) = 0;
virtual void prepareReceive(Inverter<> *iv, uint8_t cmd, bool singleframe = false) = 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; }

4
src/hms/hmsRadio.h

@ -26,6 +26,10 @@ class CmtRadio : public Radio {
mPrintWholeTrace = printWholeTrace;
}
void prepareReceive(Inverter<> *iv, uint8_t cmd, bool singleframe = false) {
return; // only relevant for nRF type inverters
}
void loop() {
mCmt.loop();
if((!mIrqRcvd) && (!mRqstGetRx))

Loading…
Cancel
Save