while((micros()-startMicros)<innerLoopTimeout){// listen (4088us or?) 5110us to each channel
isRxInit=false;
if(mIrqRcvd){
return;
}
// here we got news from the nRF
mNrf24->whatHappened(tx_ok,tx_fail,rx_ready);// resets the IRQ pin to HIGH
mIrqRcvd=false;
mIrqRcvd=false;
if(getReceived()){// everything received
if(tx_ok||tx_fail){// tx related interrupt, basically we should start listening
mNrf24->flush_tx();// empty TX FIFO
if(mNRFisInRX){
DPRINTLN(DBG_WARN,F("unexpected tx irq!"));
return;
return;
}
}
innerLoopTimeout=4088*5;
mNRFisInRX=true;
if(isRxInit){
if(tx_ok)
isRxInit=false;
mLastIv->mAckCount++;
if(micros()-startMicros<42000){
innerLoopTimeout=4088*12;
// start listening
mRxChIdx=(mRxChIdx+4)%RF_CHANNELS;
mRxChIdx=(mTxChIdx+chOffset)%RF_CHANNELS;
mNrf24->setChannel(mRfChLst[mRxChIdx]);
mNrf24->setChannel(mRfChLst[mRxChIdx]);
mNrf24->startListening();
mTimeslotStart=millis();
tempRxChIdx=mRxChIdx;
chOffset2=mLastIv->ivGen==IV_HM?4:(mLastIv->mCmd==MI_REQ_CH1||mLastIv->mCmd==MI_REQ_CH2)?1:4;// reversed channel order for everything apart from 1/2ch MI Data requests
rxPendular=false;
innerLoopTimeout=DURATION_TXFRAME;
}
}
}
startMicros=micros();
if(rx_ready){
if(getReceived()){// check what we got, returns true for last package
mNRFisInRX=false;
mRadioWaitTime.startTimeMonitor(DURATION_PAUSE_LASTFR);// let the inverter first end his transmissions
// add stop listening?
}else{
//rxPendular = true; // stay longer on the next rx channel
if(isRxInit){
isRxInit=false;
tempRxChIdx=(mRxChIdx+chOffset2)%RF_CHANNELS;
mNrf24->setChannel(mRfChLst[tempRxChIdx]);
}else{
mRxChIdx=tempRxChIdx;
}
}
yield();
innerLoopTimeout=DURATION_LISTEN_MIN;
mTimeslotStart=millis();
}
}
// switch to next RX channel
return;
mRxChIdx=(mRxChIdx+4)%RF_CHANNELS;
mNrf24->setChannel(mRfChLst[mRxChIdx]);
innerLoopTimeout=4088;
isRxInit=false;
}
}
// not finished but time is over
return;
}
}
boolisChipConnected(void){
boolisChipConnected(void){
@ -264,16 +291,15 @@ class HmRadio : public Radio {
private:
private:
inlineboolgetReceived(void){
inlineboolgetReceived(void){
booltx_ok,tx_fail,rx_ready;
mNrf24->whatHappened(tx_ok,tx_fail,rx_ready);// resets the IRQ pin to HIGH
boolisLastPackage=false;
boolisLastPackage=false;
rx_ready=false;// reset for ACK case
while(mNrf24->available()){
while(mNrf24->available()){
uint8_tlen;
uint8_tlen;
len=mNrf24->getDynamicPayloadSize();// if payload size > 32, corrupt payload has been flushed
len=mNrf24->getDynamicPayloadSize();// if payload size > 32, corrupt payload has been flushed