Konfigurator updates to support fully automatic operation #1
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "konfigurator_updates"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Konfigurator updates
This pull request makes changes to the Konfigurator subapp to support fully automatic operation. It also fixes a longstanding BLE bug.
Changes to support fully automatic operation (and limited ammunition)
Three new device parameters are now configured via the Apply Settings flow, sent as two additional BLE packets per device (packet keys 7–9):
Shot Capacity and Reload on Reentry are paired in one packet (keys 7+8); Min Time Between Shots is sent separately (key 9 +
PARAMETER_KEY_NONE). Both the global game config editor and the per-device detail dialog expose the new fields.allSettingsMatch()onDevicenow checks all five configurable parameters (team, max health, special weapons on reentry, shot capacity, reload on reentry, min time between shots) so the "Ready All Devices" button is only offered once every field has been ACK'd.Also on this branch:
SYSTEMK_STATE_*constants toPacket.java(replacing magic numbers 3, 7, 9 in state comparisons).readyAllDevices(): advertising was never stopped between loop iterations, preventing the scan from receiving STATUS packets. Now advertises for 500 ms then scans for 1500 ms per cycle.addOrRefreshDevice(): new devices now getDeviceState.Configurableassigned here rather than unconditionally in the Hello packet handler, which was overridingReadystate on every subsequent Hello broadcast.DeviceListnow uses device address as a stableLazyColumnitem key.Fix BLE scan throttling during multi-device configuration
Problem
Configuring more than one device in sequence would reliably fail on the second (and any subsequent) device — all retry attempts timed out with no ACK received.
The root cause was Android's BLE scan throttle. The OS silently rejects
startScancalls (returningstatus=6, "registration failed because app is scanning too frequently") when an app starts and stops scans too many times within a 30-second window. The previousconfigureDeviceimplementation stopped the background scan and started a dedicated ACK scan for every attempt. WithMAX_CONFIGURE_RETRIES = 3and the potential for multiple packets per device, the quota was exhausted before the second device was reached. BecausestartScanfails silently (noonScanFailedcallback), the ACK scan never started, so no ACK was ever received, and every attempt timed out after 5 seconds.Confirmed in logcat:
Fix
Replace the dedicated per-attempt ACK scan with a lightweight hook on the already-running background scan.
BleManager— added apendingAckDetectorlambda and anotifyScanResult()method.configureDevicenow only advertises the config packet; it registers the ACK-matching logic inpendingAckDetectorbefore advertising and clears it in thefinallyblock. No scan is started or stopped during configuration.StateMachineViewModel—scanCallbackDefault.onScanResultnow callsbleManager.notifyScanResult(result)for every packet, routing results to the ACK detector when a configuration is in progress.BleManager.startScanning— added an early-return guard when the same callback is already registered and scanning, preventing a redundant scan cycle from thestartScanningcall at the end ofconfigureDevices().Result
The background scan runs uninterrupted throughout the entire multi-device configuration sequence. Zero scan start/stop cycles are consumed by
configureDevice, so the Android throttle is never triggered regardless of how many devices or retries are needed.