Skip to content

Commit 5ed8c70

Browse files
committed
MP: Make sure large heartbeatTimeout does not overflow link break time
1 parent 145490c commit 5ed8c70

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

Firmware/LoRaSerial/States.ino

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -995,7 +995,7 @@ void updateRadioState()
995995
//----------
996996
//Always check for link timeout
997997
//----------
998-
if ((millis() - linkDownTimer) >= (LINK_BREAK_MULTIPLIER * settings.heartbeatTimeout))
998+
if ((millis() - linkDownTimer) >= (LINK_BREAK_MULTIPLIER * (uint32_t)settings.heartbeatTimeout))
999999
//Break the link
10001000
breakLink();
10011001
break;
@@ -1475,7 +1475,7 @@ void updateRadioState()
14751475
//If the client hasn't received a packet in too long, return to scanning
14761476
else if (settings.server == false)
14771477
{
1478-
if ((millis() - lastPacketReceived) > (settings.heartbeatTimeout * 3))
1478+
if ((millis() - lastPacketReceived) > ((uint32_t)settings.heartbeatTimeout * LINK_BREAK_MULTIPLIER))
14791479
{
14801480
if (settings.debugSync)
14811481
{
@@ -1919,7 +1919,7 @@ void updateRadioState()
19191919
vcReceiveHeartbeat(millis() - currentMillis);
19201920

19211921
//Delay for a while before sending the HEARTBEAT
1922-
heartbeatRandomTime = random((settings.heartbeatTimeout * 2) / 10, settings.heartbeatTimeout);
1922+
heartbeatRandomTime = random(((uint32_t)settings.heartbeatTimeout * 2) / 10, settings.heartbeatTimeout);
19231923
changeState(RADIO_VC_WAIT_RECEIVE);
19241924
}
19251925
else
@@ -2503,7 +2503,7 @@ void updateRadioState()
25032503
//Determine if the link has timed out
25042504
vc = &virtualCircuitList[index];
25052505
if ((vc->vcState != VC_STATE_LINK_DOWN) && (serverLinkBroken
2506-
|| ((currentMillis - vc->lastTrafficMillis) > (LINK_BREAK_MULTIPLIER * settings.heartbeatTimeout))))
2506+
|| ((currentMillis - vc->lastTrafficMillis) > (LINK_BREAK_MULTIPLIER * (uint32_t)settings.heartbeatTimeout))))
25072507
{
25082508
if (index == VC_SERVER)
25092509
{

0 commit comments

Comments
 (0)