diff --git a/Firmware/LoRaSerial/States.ino b/Firmware/LoRaSerial/States.ino index afdd09ef..d3208b79 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; @@ -1256,6 +1256,7 @@ void updateRadioState() switch (packetType) { default: + stopChannelTimer(); triggerEvent(TRIGGER_UNKNOWN_PACKET); if (settings.debugDatagrams) { @@ -1268,14 +1269,17 @@ void updateRadioState() break; case DATAGRAM_BAD: + stopChannelTimer(); triggerEvent(TRIGGER_BAD_PACKET); break; case DATAGRAM_CRC_ERROR: + stopChannelTimer(); triggerEvent(TRIGGER_CRC_ERROR); break; case DATAGRAM_NETID_MISMATCH: + stopChannelTimer(); triggerEvent(TRIGGER_NETID_MISMATCH); break; @@ -1286,10 +1290,12 @@ void updateRadioState() case DATAGRAM_REMOTE_COMMAND: case DATAGRAM_REMOTE_COMMAND_RESPONSE: //We should not be receiving these datagrams, but if we do, just ignore + stopChannelTimer(); triggerEvent(TRIGGER_BAD_PACKET); break; case DATAGRAM_FIND_PARTNER: + stopChannelTimer(); triggerEvent(TRIGGER_RX_FIND_PARTNER); break; @@ -1334,6 +1340,7 @@ void updateRadioState() case DATAGRAM_DATA: //Don't deal with data until we are sync'd with server + stopChannelTimer(); triggerEvent(TRIGGER_RX_DATA); break; } @@ -1411,10 +1418,6 @@ void updateRadioState() changeState(RADIO_MP_WAIT_TX_DONE); } } - else - { - changeState(RADIO_MP_STANDBY); - } break; case DATAGRAM_HEARTBEAT: @@ -1432,7 +1435,6 @@ void updateRadioState() lastPacketReceived = millis(); //Update timestamp for Link LED blinkHeartbeatLed(true); - changeState(RADIO_MP_STANDBY); } break; @@ -1446,8 +1448,6 @@ void updateRadioState() frequencyCorrection += radio.getFrequencyError() / 1000000.0; lastPacketReceived = millis(); //Update timestamp for Link LED - - changeState(RADIO_MP_STANDBY); break; } } @@ -1482,7 +1482,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) { @@ -1926,7 +1926,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 @@ -2510,7 +2510,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) {