Flex network: auto-discover & connect (no IP typing)#328
Closed
patrickrb wants to merge 4 commits into
Closed
Conversation
Selecting Network + FlexRadio dropped the user on a manual "IP Address" field. Discovery code existed (FlexRadioFactory listens for the Flex UDP broadcast on 4992) and the picker even rendered found radios — but the list was always empty, so typing the IP was the only thing that worked. Root cause: Android's Wi-Fi chip filters out incoming broadcast/multicast packets unless an app holds a WifiManager.MulticastLock, and we never took one (nor held the CHANGE_WIFI_MULTICAST_STATE permission needed for it). So the discovery socket received nothing. - Add CHANGE_WIFI_MULTICAST_STATE and acquire a MulticastLock while the Flex picker is open (released on dismiss, so no battery cost otherwise). - Lead the picker with discovery: a "Searching…" state, the found radios as the primary list, and manual IP entry collapsed behind a link as a fallback (different subnet / VPN / broadcast blocked). - Auto-connect when discovery finds exactly one radio and the user hasn't started typing — connect to your Flex with zero input. The decision (shouldAutoConnectFlex) is a pure, unit-tested one-shot. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev #328 +/- ##
============================================
+ Coverage 11.51% 11.53% +0.02%
Complexity 113 113
============================================
Files 88 89 +1
Lines 12466 12537 +71
Branches 2230 2245 +15
============================================
+ Hits 1435 1446 +11
- Misses 10900 10960 +60
Partials 131 131
🚀 New features to boost your workflow:
|
…session Field report: the picker "closes the instant you open it" and the rig stops connecting. Cause: FlexRadioFactory is a singleton, so once a radio is cached, reopening the picker seeds the list with it and the auto-connect LaunchedEffect fired immediately — dismissing the dialog and, worse, reconnecting an already-connected rig, which tears down the working session. Gate auto-connect so it only fires on a genuinely fresh discovery: - startedEmpty: the picker must have opened with no cached radios, so we never auto-connect to a stale singleton entry. - rigAlreadyConnected: never reconnect over a live session. (plus the existing single-radio / not-typing / one-shot guards.) Also add debug.log diagnostics (multicastLock.held, seeded count, each radio added, and connect path) so we can confirm whether discovery actually receives the UDP broadcasts on the user's network. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
"If my Flex settings are set, I should just click the CAT button near CQ and have it connect." Two gaps stopped that: the Flex address was never persisted, and reconnectRig() no-ops when no connector exists yet (a cold start) — so the CAT chip did nothing until you'd already connected once via the picker. - Persist the Flex address (flexLastIp) whenever we connect — discovered, tapped, or typed — and load it at startup. - Route the CAT chip tap (catTapAction): reconnect an existing connector if one's live; otherwise, on a cold start with a saved network Flex, connect straight to the remembered address; with nothing saved, point the user to setup. Pure routing (catTapAction) is unit-tested. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Field test on a real FLEX-6400 exposed two bugs behind "it never found the radio / didn't connect until I hit CAT": 1. Discovery worked (MulticastLock fine — debug.log showed the radio found in 0.4s) but the picker kept spinning. FlexRadioFactory fires OnFlexRadioAdded BEFORE appending to its list, so the listener re-read an empty list and dropped the radio (logged "total=0"). It also meant the discoveredRadios count stayed 0, so auto-connect never fired. Now we include the radio handed to the callback (mergeDiscovered, deduped by address) — so it shows and auto-connect can fire. 2. The Flex connect never reported success: FlexConnector.onConnectSuccess didn't notify the rig state, so onConnected() (which sets CONNECTED + toasts) never ran — the CAT chip stayed idle and there was no confirmation. Added an OnConnectionResult callback; connectFlexRadioRig now sets CONNECTING up front and CONNECTED + a "connected" toast on success (ERROR on failure). mergeDiscovered is pure + unit-tested. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Owner
Author
|
Folded into #327 (single combined PR), as requested. The flex-discovery branch was merged into feat/meters-hud. |
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.
Problem
Picking Network + FlexRadio dropped you on a manual IP Address field. Discovery already existed —
FlexRadioFactorylistens for the Flex UDP discovery broadcast (port 4992) and the picker rendered any radios it found — but the list was always empty, so typing the IP was the only thing that worked.Root cause
Android's Wi-Fi chip filters out incoming broadcast/multicast packets unless an app holds a
WifiManager.MulticastLock— and the app never took one (nor declaredCHANGE_WIFI_MULTICAST_STATE, which is required to acquire it). The discovery socket was bound and listening, but the OS delivered nothing to it.Fix
CHANGE_WIFI_MULTICAST_STATEand acquire aMulticastLockwhile the Flex picker is open (released on dismiss → no battery cost otherwise). This is the load-bearing change that makes discovery actually receive the broadcasts.shouldAutoConnectFlex) is a pure, one-shot, unit-tested helper.Testing
FlexDiscoveryLogicTest— auto-connect fires only on a single found radio, not on zero / multiple / mid-typing / already-fired. Green.installDebugon the Pixel 8 — builds (incl. NDK) and installs clean.🤖 Generated with Claude Code