From 145490c8910eeda653abe4e0d3a1f86645e5789b Mon Sep 17 00:00:00 2001 From: Lee Leahy Date: Fri, 24 Mar 2023 10:07:43 -1000 Subject: [PATCH 1/2] MP: Don't change state when not necessary --- Firmware/LoRaSerial/States.ino | 7 ------- 1 file changed, 7 deletions(-) diff --git a/Firmware/LoRaSerial/States.ino b/Firmware/LoRaSerial/States.ino index afdd09ef..613597da 100644 --- a/Firmware/LoRaSerial/States.ino +++ b/Firmware/LoRaSerial/States.ino @@ -1411,10 +1411,6 @@ void updateRadioState() changeState(RADIO_MP_WAIT_TX_DONE); } } - else - { - changeState(RADIO_MP_STANDBY); - } break; case DATAGRAM_HEARTBEAT: @@ -1432,7 +1428,6 @@ void updateRadioState() lastPacketReceived = millis(); //Update timestamp for Link LED blinkHeartbeatLed(true); - changeState(RADIO_MP_STANDBY); } break; @@ -1446,8 +1441,6 @@ void updateRadioState() frequencyCorrection += radio.getFrequencyError() / 1000000.0; lastPacketReceived = millis(); //Update timestamp for Link LED - - changeState(RADIO_MP_STANDBY); break; } } From 5ed8c70e287890dcfbe1401d276f3b829b94a060 Mon Sep 17 00:00:00 2001 From: Lee Leahy Date: Fri, 24 Mar 2023 10:05:49 -1000 Subject: [PATCH 2/2] MP: Make sure large heartbeatTimeout does not overflow link break time --- Firmware/LoRaSerial/States.ino | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Firmware/LoRaSerial/States.ino b/Firmware/LoRaSerial/States.ino index 613597da..57802d11 100644 --- a/Firmware/LoRaSerial/States.ino +++ b/Firmware/LoRaSerial/States.ino @@ -995,7 +995,7 @@ void updateRadioState() //---------- //Always check for link timeout //---------- - if ((millis() - linkDownTimer) >= (LINK_BREAK_MULTIPLIER * settings.heartbeatTimeout)) + if ((millis() - linkDownTimer) >= (LINK_BREAK_MULTIPLIER * (uint32_t)settings.heartbeatTimeout)) //Break the link breakLink(); break; @@ -1475,7 +1475,7 @@ void updateRadioState() //If the client hasn't received a packet in too long, return to scanning else if (settings.server == false) { - if ((millis() - lastPacketReceived) > (settings.heartbeatTimeout * 3)) + if ((millis() - lastPacketReceived) > ((uint32_t)settings.heartbeatTimeout * LINK_BREAK_MULTIPLIER)) { if (settings.debugSync) { @@ -1919,7 +1919,7 @@ void updateRadioState() vcReceiveHeartbeat(millis() - currentMillis); //Delay for a while before sending the HEARTBEAT - heartbeatRandomTime = random((settings.heartbeatTimeout * 2) / 10, settings.heartbeatTimeout); + heartbeatRandomTime = random(((uint32_t)settings.heartbeatTimeout * 2) / 10, settings.heartbeatTimeout); changeState(RADIO_VC_WAIT_RECEIVE); } else @@ -2503,7 +2503,7 @@ void updateRadioState() //Determine if the link has timed out vc = &virtualCircuitList[index]; if ((vc->vcState != VC_STATE_LINK_DOWN) && (serverLinkBroken - || ((currentMillis - vc->lastTrafficMillis) > (LINK_BREAK_MULTIPLIER * settings.heartbeatTimeout)))) + || ((currentMillis - vc->lastTrafficMillis) > (LINK_BREAK_MULTIPLIER * (uint32_t)settings.heartbeatTimeout)))) { if (index == VC_SERVER) {