feat(nrf): make init a synchronous handshake - #13
Open
teal-bauer wants to merge 1 commit into
Open
teal-bauer wants to merge 1 commit into
teal-bauer wants to merge 1 commit into
Conversation
InitializeNRF52 was fire-and-forget — it wrote 6 frames at the nRF and returned nil unconditionally, with the version reply arriving asynchronously through the readLoop. A non-responsive nRF would leave the service running degraded forever, with no version in Redis and no fault flag. Make init wait for the version reply with a 2-second timeout. On timeout, return an error so callers (Bootstrap.startNormally, ReconnectUSock) surface FaultNRFInit or failed:reconnect respectively. - service.go: new versionRxCh channel (size 1) on Service. - nrf_commands.go: InitializeNRF52 drains versionRxCh before sending the version request, then waits on it after all 6 init commands. Picks up a reply that arrived during the request burst from the buffered channel, so the wait is typically a no-op on healthy hardware. - usock_handlers.go: handleBLEVersionMessage does a non-blocking send on versionRxCh and ClearFault(FaultNRFInit) on every version receipt — a late-arriving version after a handshake-timeout self-heals the fault. Verified on hardware: handshake completes during init (version arrives in-band during steps 3-6, consumed by the wait at the end). FaultNRFInit clear, firmware-update-status idle.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
InitializeNRF52was fire-and-forget — it wrote 6 frames at the nRF and returnednilunconditionally, with the version reply arriving asynchronously through the readLoop. A non-responsive nRF would leave the service running degraded forever, with no version in Redis and no fault flag.Make init wait for the version reply with a 2-second timeout. On timeout, return an error so callers (
Bootstrap.startNormally,ReconnectUSock) surfaceFaultNRFInitorfailed:reconnectrespectively.Changes
pkg/service/service.go: newversionRxCh chan struct{}(size 1) onService.pkg/service/nrf_commands.go:InitializeNRF52drainsversionRxChbefore sending the version request, then waits on it after all 6 init commands. A reply that arrives during the request burst is picked up from the buffered channel — the wait is typically a no-op on healthy hardware.pkg/service/usock_handlers.go:handleBLEVersionMessagedoes a non-blocking send onversionRxChandClearFault(FaultNRFInit)on every version receipt — a late-arriving version after a handshake-timeout self-heals the fault.Out of scope
FaultNRFInitshows up in production with frequency that warrants automation, we can add a probe + recovery on top later.Test plan
go build ./...cleango vet ./...cleango test ./pkg/service/...passesmake buildFaultNRFInitclear,firmware-update-status: idle.