Enhance KissModem frame processing and timeout handling#2490
Enhance KissModem frame processing and timeout handling#2490tuzzmaniandevil wants to merge 2 commits intomeshcore-dev:devfrom
Conversation
76be54c to
314d777
Compare
|
@recrof covered some edge cases here, much nicer flow now |
|
@ViezeVingertjes can you review please? |
ViezeVingertjes
left a comment
There was a problem hiding this comment.
Looks like a good improvement, 2 comments though, one that probably should send a done, other which im not sure about if it should. It's quite late here, but if you can clear those up, i'll turn it into an approve first thing when i wake up! 👍🏼
| _tx_timer = millis(); | ||
| _tx_state = TX_SENDING; | ||
| } else { | ||
| _has_pending_tx = false; |
There was a problem hiding this comment.
This branch also should send a HW_RESP_TX_DONE right?
| uint8_t result = 0x00; | ||
| writeHardwareFrame(HW_RESP_TX_DONE, &result, 1); |
There was a problem hiding this comment.
This one might be confusing; let's say one is pending and you send another, now you get a HW_RESP_TX_DONE, but don't know which it was for right? I agree that silently dropping perhaps isnt the right approach, would a HW_RESP_TX_BUSY be more suitable or?
(This one also kinda depends on how the client works, but any gap we can close, the better)
|
Thanks @ViezeVingertjes I've addressed those two comments :-) |
Fixes several bugs in the KISS modem TX state machine that could cause the modem to permanently stop sending packets over serial.
Problem
The KISS modem TX state machine had multiple paths that could lock up permanently, requiring a device reboot:
TX_SENDINGstuck forever — IfisSendComplete()never returns true (missed radio interrupt, SPI glitch), the state machine stays inTX_SENDINGindefinitely. No more packets can be sent or queued.startSendRaw()return value ignored — If the radio fails to start transmitting, the modem entersTX_SENDINGwaiting for a completion that never started.TX_WAIT_CLEARstuck forever — If the radio gets stuck detecting a phantom carrier,isReceiving()returns true indefinitely and the state machine never progresses.Changes
TX_SENDINGusinggetEstAirtimeFor() * 1.5, matching the approach used by the Dispatcher in companion/repeater firmware. Adapts automatically to radio configuration instead of using a fixed 10s constant.startSendRaw()error handling — Check return value; on failure, drop the packet and return toTX_IDLEinstead of entering a dead state.TX_WAIT_CLEARtimeout — If the channel stays busy longer than the worst-case max packet airtime × 1.5, force-proceed toTX_DELAY.TX_SLOT_WAITtimer reset — Reset_tx_timerwhen cycling back toTX_WAIT_CLEARso the channel-busy timeout measures time in that state, not cumulative time since the TX was queued.HW_RESP_TX_DONE(result=0x00) so the host knows the packet was rejected.HW_RESP_TX_DONE(result=0x00) instead of silently dropping.Testing
These are all state machine edge cases triggered by radio hardware faults (missed interrupts, stuck carrier detect). Verified by code review against the Dispatcher's equivalent timeout handling in
src/Dispatcher.cpp.