Add test framework and fix blocking buzzer crash#39
Open
avenstewart wants to merge 11 commits intocolonelpanichacks:mainfrom
Open
Add test framework and fix blocking buzzer crash#39avenstewart wants to merge 11 commits intocolonelpanichacks:mainfrom
avenstewart wants to merge 11 commits intocolonelpanichacks:mainfrom
Conversation
Enable DeFlock mobile app connectivity via BLE GATT notifications, and desktop host detection via USB serial heartbeat. When a companion is connected, WiFi AP is disabled to free radio bandwidth and BLE scan duty cycle is increased for better detection performance. - BLE GATT server advertising service UUID a1b2c3d4-e5f6-7890-abcd-ef0123456789 with TX characteristic (NOTIFY) for streaming detection JSON - Chunked BLE notification sender respecting negotiated MTU - "event":"detection" field added to JSON output for DeFlock parser - Serial host detection via heartbeat timeout (5s) - Companion mode: WiFi AP off + scan duration 2s→3s when connected - Scan interval/duration converted from #define to mutable variables Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…tSpotter Expand MAC prefix detection with entries sourced from: - Flock WiFi (Liteon/USI): f4:6a:dd, f8:a2:d6, e0:0a:f6, 00:f4:8d, d0:39:57, e8:d0:fc — contract manufacturer OUIs (Liteon Technology and USI/Universal Scientific Industrial) identified via the OUI-SPY firmware ecosystem table and cross-referenced against the IEEE OUI registry. These manufacturers produce Flock Safety's WiFi-enabled camera hardware. - Flock Safety direct: b4:1e:52 — registered directly to "Flock Safety" in the IEEE OUI database (MA-L assignment). This is their own prefix rather than a contract manufacturer's. - SoundThinking/ShotSpotter: d4:11:d6 — registered to "SoundThinking Inc" (formerly ShotSpotter) in the IEEE OUI database. Their acoustic gunshot detection sensors use BLE for local diagnostics and provisioning. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
BLE server callbacks run on the NimBLE host task, not the Arduino loop task. Calling WiFi state changes and delay() from that context can stall BLE processing or trip watchdogs, and mutating scan duration creates a cross-task data race. Fix: callbacks now just set a volatile pending flag. The actual WiFi/scan changes are applied in loop() where they're safe. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Collapse the two-branch snprintf into a single call so every detection message includes is_raven (true/false) and raven_fw, making the format self-describing regardless of device type. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Address Copilot review: contract manufacturer OUIs (Liteon/USI) are now in a separate flock_mfr_mac_prefixes[] array emitting "mac_prefix_mfr" as the detection method. SoundThinking/ShotSpotter gets its own array and "mac_prefix_soundthinking" method. Low-confidence detections (mfr OUIs) suppress buzzer/heartbeat but still emit JSON events so consumers can apply their own thresholds. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…uffer Low-confidence mac_prefix_mfr hits no longer update fyLastDetTime/fyLastHB, preventing them from keeping the heartbeat alive after a high-confidence device leaves range. Bump FYDetection::method from 24 to 32 bytes so "mac_prefix_soundthinking" (23 chars) has headroom. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add OUI prefixes for Flock WiFi, Flock Safety direct, and ShotSpotter
Add BLE GATT server, serial host detection, and companion mode
…tion patterns and matching functions into fy_detect.h for host-side testing via PlatformIO native environment. 30 tests covering MAC prefix, device name, manufacturer ID, and Raven UUID detection. No firmware behavior changes.
…ed /api/test/inject endpoint for simulating detections. Fix fyDetectBeep() blocking BLE/HTTP tasks by deferring to loop() via fyDetectBeepPending flag. Rename test dirs for clarity.
…nv breaking pio run with default_envs and build_src_filter.
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
Adds a native test framework and a hardware test injection endpoint, which led to discovering and fixing a crash bug in the BLE detection callback.
Changes
Test framework
src/fy_detect.h(no behavior change, identical compiled binary)pio test -e native— no hardware neededHardware test endpoint
/api/test/inject?type=flock|raven|soundthinking|mfrsimulates detections through the full pipeline (storage, dashboard, buzzer, serial, BLE, SPIFFS)FY_ENABLE_TEST_API— absent from production firmwarepio run -e xiao_esp32s3_testpython3 test/test_buzzer_crash.pyBug fix: watchdog reset under sustained BLE detections
fyDetectBeep()was called directly insideFYBLECallbacks::onResult(), blocking the NimBLE host task for ~500ms withdelay()calls. Under sustained detections this triggers a watchdog reset, rebooting the device and losing all unsaved data.Fixed by deferring the buzzer to
loop()via afyDetectBeepPendingflag, matching the existingfyCompanionChangePendingpattern.Verified with automated testing:
Likely resolves issue #37.