Skip to content

Commit 3cf302a

Browse files
authored
Merge pull request #557 from LeeLeahy2/mp-start-clock
MP: Start the channel timer at the beginning of receive
2 parents 28ec08b + a0eca27 commit 3cf302a

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
@@ -287,7 +287,7 @@ void returnToReceiving()
287287
{
288288
radioCallHistory[RADIO_CALL_returnToReceiving] = millis();
289289

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

292292
int state;
293293
if (settings.radioSpreadFactor > 6)
@@ -655,32 +655,25 @@ unsigned long mSecToChannelZero()
655655
}
656656

657657
//Returns true if the radio indicates we have an ongoing reception
658-
bool receiveInProcess()
658+
bool receiveInProcess(bool startClock)
659659
{
660660
uint8_t radioStatus = radio.getModemStatus();
661661
radioStatus &= 0b11011; //Get bits 0, 1, 3, and 4
662662

663663
//Known states where a reception is in progress
664-
if (radioStatus == 0b00001)
665-
return (true);
666-
else if (radioStatus == 0b00011)
667-
return (true);
668-
else if (radioStatus == 0b01011)
669-
return (true);
670-
671-
// switch (radioStatus)
672-
// {
673-
// default:
674-
// Serial.print("Unknown status: 0b");
675-
// Serial.println(radioStatus, BIN);
676-
// break;
677-
// case (0b00000):
678-
// //No receive in process
679-
// case (0b10000):
680-
// //Modem clear. No receive in process
681-
// break;
682-
// }
683-
664+
switch (radioStatus)
665+
{
666+
case 0b00001:
667+
case 0b00011:
668+
case 0b01011:
669+
if (startClock && (!channelTimerMsec))
670+
{
671+
//Compute the approximate time for the next hop
672+
startChannelTimer(settings.maxDwellTime - ((settings.txToRxUsec * 25) / 4000));
673+
triggerEvent(TRIGGER_RECEIVE_IN_PROCESS);
674+
}
675+
return (true);
676+
}
684677
return (false);
685678
}
686679

@@ -3088,7 +3081,7 @@ bool retransmitDatagram(VIRTUAL_CIRCUIT * vc)
30883081

30893082
//Drop this datagram if the receiver is active
30903083
if (
3091-
(receiveInProcess() == true)
3084+
(receiveInProcess(false) == true)
30923085
|| (transactionComplete == true)
30933086
|| (
30943087
//If we are in VC mode, and destination is not broadcast,
@@ -3109,7 +3102,7 @@ bool retransmitDatagram(VIRTUAL_CIRCUIT * vc)
31093102
systemPrint("TX failed: ");
31103103
if (transactionComplete)
31113104
systemPrintln("RXTC");
3112-
else if (receiveInProcess())
3105+
else if (receiveInProcess(false))
31133106
systemPrintln("RXIP");
31143107
else
31153108
systemPrintln("VC link down");
@@ -3124,7 +3117,7 @@ bool retransmitDatagram(VIRTUAL_CIRCUIT * vc)
31243117

31253118
if (state == RADIOLIB_ERR_NONE)
31263119
{
3127-
if (receiveInProcess() == true)
3120+
if (receiveInProcess(false) == true)
31283121
{
31293122
//Edge case: if we have started TX, but during the SPI transaction a preamble was detected
31303123
//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
@@ -607,7 +607,7 @@ bool vcSerialMessageReceived()
607607
do
608608
{
609609
//Determine if the radio is idle
610-
if (receiveInProcess())
610+
if (receiveInProcess(false))
611611
//The radio is busy, wait until it is idle
612612
break;
613613

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)