Skip to content

Commit a0eca27

Browse files
committed
MP: Start the channel timer at the beginning of receive
1 parent 9ed7a6f commit a0eca27

File tree

4 files changed

+39
-36
lines changed

4 files changed

+39
-36
lines changed

Firmware/LoRaSerial/Commands.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ bool commandAT(const char * commandString)
589589
if (irqFlags & 1)
590590
systemPrintln(" CAD Detected");
591591
systemPrint(" receiveInProcess: ");
592-
systemPrintln(receiveInProcess() ? "True" : "False");
592+
systemPrintln(receiveInProcess(false) ? "True" : "False");
593593
outputSerialData(true);
594594
petWDT();
595595

Firmware/LoRaSerial/Radio.ino

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ void returnToReceiving()
249249
{
250250
radioCallHistory[RADIO_CALL_returnToReceiving] = millis();
251251

252-
if (receiveInProcess() == true) return; //Do not touch the radio if it is already receiving
252+
if (receiveInProcess(false) == true) return; //Do not touch the radio if it is already receiving
253253

254254
int state;
255255
if (settings.radioSpreadFactor > 6)
@@ -617,32 +617,25 @@ unsigned long mSecToChannelZero()
617617
}
618618

619619
//Returns true if the radio indicates we have an ongoing reception
620-
bool receiveInProcess()
620+
bool receiveInProcess(bool startClock)
621621
{
622622
uint8_t radioStatus = radio.getModemStatus();
623623
radioStatus &= 0b11011; //Get bits 0, 1, 3, and 4
624624

625625
//Known states where a reception is in progress
626-
if (radioStatus == 0b00001)
627-
return (true);
628-
else if (radioStatus == 0b00011)
629-
return (true);
630-
else if (radioStatus == 0b01011)
631-
return (true);
632-
633-
// switch (radioStatus)
634-
// {
635-
// default:
636-
// Serial.print("Unknown status: 0b");
637-
// Serial.println(radioStatus, BIN);
638-
// break;
639-
// case (0b00000):
640-
// //No receive in process
641-
// case (0b10000):
642-
// //Modem clear. No receive in process
643-
// break;
644-
// }
645-
626+
switch (radioStatus)
627+
{
628+
case 0b00001:
629+
case 0b00011:
630+
case 0b01011:
631+
if (startClock && (!channelTimerMsec))
632+
{
633+
//Compute the approximate time for the next hop
634+
startChannelTimer(settings.maxDwellTime - ((settings.txToRxUsec * 25) / 4000));
635+
triggerEvent(TRIGGER_RECEIVE_IN_PROCESS);
636+
}
637+
return (true);
638+
}
646639
return (false);
647640
}
648641

@@ -3050,7 +3043,7 @@ bool retransmitDatagram(VIRTUAL_CIRCUIT * vc)
30503043

30513044
//Drop this datagram if the receiver is active
30523045
if (
3053-
(receiveInProcess() == true)
3046+
(receiveInProcess(false) == true)
30543047
|| (transactionComplete == true)
30553048
|| (
30563049
//If we are in VC mode, and destination is not broadcast,
@@ -3071,7 +3064,7 @@ bool retransmitDatagram(VIRTUAL_CIRCUIT * vc)
30713064
systemPrint("TX failed: ");
30723065
if (transactionComplete)
30733066
systemPrintln("RXTC");
3074-
else if (receiveInProcess())
3067+
else if (receiveInProcess(false))
30753068
systemPrintln("RXIP");
30763069
else
30773070
systemPrintln("VC link down");
@@ -3086,7 +3079,7 @@ bool retransmitDatagram(VIRTUAL_CIRCUIT * vc)
30863079

30873080
if (state == RADIOLIB_ERR_NONE)
30883081
{
3089-
if (receiveInProcess() == true)
3082+
if (receiveInProcess(false) == true)
30903083
{
30913084
//Edge case: if we have started TX, but during the SPI transaction a preamble was detected
30923085
//then return false. This will cause the radio to transmit, then a transactionComplete ISR will trigger.

Firmware/LoRaSerial/Serial.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ bool vcSerialMessageReceived()
606606
do
607607
{
608608
//Determine if the radio is idle
609-
if (receiveInProcess())
609+
if (receiveInProcess(false))
610610
//The radio is busy, wait until it is idle
611611
break;
612612

Firmware/LoRaSerial/States.ino

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ void updateRadioState()
330330
}
331331

332332
//Is it time to send the FIND_PARTNER to the remote system
333-
else if ((receiveInProcess() == false) && ((millis() - heartbeatTimer) >= randomTime))
333+
else if ((receiveInProcess(false) == false) && ((millis() - heartbeatTimer) >= randomTime))
334334
{
335335
//Transmit the FIND_PARTNER
336336
triggerEvent(TRIGGER_TX_FIND_PARTNER);
@@ -814,7 +814,7 @@ void updateRadioState()
814814
}
815815
}
816816

817-
else if (receiveInProcess() == false)
817+
else if (receiveInProcess(false) == false)
818818
{
819819
//----------
820820
//Priority 1: Transmit a HEARTBEAT if necessary
@@ -1182,7 +1182,7 @@ void updateRadioState()
11821182
}
11831183

11841184
//Nothing received
1185-
else if (receiveInProcess() == false)
1185+
else if (receiveInProcess(false) == false)
11861186
{
11871187
//Check for a receive timeout
11881188
timeoutMsec = settings.overheadTime + ((frameAirTimeUsec + txDataAckUsec + settings.txToRxUsec) / 1000);
@@ -1242,9 +1242,20 @@ void updateRadioState()
12421242
//Wait for the Server to transmit a HB on Channel 0
12431243
//====================
12441244
case RADIO_DISCOVER_STANDBY:
1245+
//Hop channels when required
1246+
if (timeToHop == true)
1247+
hopChannel();
1248+
if (channelNumber && (!channelTimerMsec))
1249+
{
1250+
//Return to channel zero
1251+
channelNumber = 0;
1252+
setRadioFrequency(false);
1253+
}
1254+
12451255
rssi = -200; //Force RSSI LEDs off until link is up
12461256

12471257
//Process the receive packet
1258+
receiveInProcess(true);
12481259
if (transactionComplete == true)
12491260
{
12501261
triggerEvent(TRIGGER_MP_PACKET_RECEIVED);
@@ -1308,7 +1319,6 @@ void updateRadioState()
13081319
setRadioFrequency(false);
13091320

13101321
//Start and adjust freq hop ISR based on remote's remaining clock
1311-
startChannelTimer();
13121322
channelTimerStart -= settings.maxDwellTime;
13131323
syncChannelTimer(txSyncClocksUsec, 1);
13141324

@@ -1453,7 +1463,7 @@ void updateRadioState()
14531463
}
14541464

14551465
//If the radio is available, send any data in the serial buffer over the radio
1456-
else if (receiveInProcess() == false)
1466+
else if (receiveInProcess(false) == false)
14571467
{
14581468
heartbeatTimeout = ((millis() - heartbeatTimer) > heartbeatRandomTime);
14591469

@@ -1623,7 +1633,7 @@ void updateRadioState()
16231633
}
16241634

16251635
//Determine if a receive is in process
1626-
else if (receiveInProcess())
1636+
else if (receiveInProcess(false))
16271637
{
16281638
if (!trainingPreviousRxInProgress)
16291639
{
@@ -1783,7 +1793,7 @@ void updateRadioState()
17831793
}
17841794

17851795
//Determine if a receive is in process
1786-
else if (receiveInProcess())
1796+
else if (receiveInProcess(false))
17871797
if (!trainingPreviousRxInProgress)
17881798
{
17891799
trainingPreviousRxInProgress = true;
@@ -2193,7 +2203,7 @@ void updateRadioState()
21932203
}
21942204

21952205
//when not receiving process the pending transmit requests
2196-
else if (!receiveInProcess())
2206+
else if (!receiveInProcess(false))
21972207
{
21982208
//----------
21992209
//Priority 1: Transmit a HEARTBEAT if necessary
@@ -2321,7 +2331,7 @@ void updateRadioState()
23212331
{
23222332
for (index = 0; index < MAX_VC; index++)
23232333
{
2324-
if (receiveInProcess())
2334+
if (receiveInProcess(false))
23252335
break;
23262336

23272337
//Determine the first VC that is walking through connections

0 commit comments

Comments
 (0)