Repository navigation
bt: keep the BLE trainer link stable with a headtracker - #5
Merged
Merged
Conversation
Descriptor discovery runs from the trainer value handle to the end of the service, so every 0x2902 in that range overwrote s_cccd_handle and the module enabled the override-channel CCCD (0xAFF1) instead of the trainer one. Keep only the CCCD whose characteristic is the trainer and clear the handle on every connect.
parserATCommand() pauses the trainer passthrough for every AT command and only AT+ROLE1/AT+CON resumed it, so a headtracker reset silently stopped the trainer stream until the link was cycled. Resume forwarding after the command.
bt_client_connect() needs the peer address type, which is only known for devices kept in the last scan list. When the address was unknown (for instance after the headtracker powered off) it returned silently, but the state machine had already moved to WAITING_CONNECTION and only that state's scan-complete flag could leave it. With no scan running, the module waited forever and the radio kept waiting for a Connected: line until the trainer mode was toggled. Connect now reports whether an attempt started: when it did not, the state machine rescans through the auto-connect path. WAITING_CONNECTION also gives up after 10 s on a directed attempt, so a peer that is off or out of range can no longer wedge the link.
With a headtracker the UART carried about 2.5 kB/s: the trainer frame plus a 14-byte block of zeros (the tracker notifies its override channels between frames) and a full Connected:/MTU/PHY/Board text block every 2 s. EdgeTX drains its 256-byte Bluetooth FIFO once per 50 ms and declares the trainer lost after one second without a valid frame, so that extra traffic made the trainer drop and come back over and over while the BLE link stayed up. Forward only the 0x7E-framed part of each notification (dropping padding and the zeroed override block) and re-announce the connection at most three times per link instead of forever.
Add the measured headtracker results: boot timing, reconnect after a power cycle, the stream shape before and after dropping the zeroed override notifications, the capped Connected: announcements and the HT reset from an EdgeTX Special Function. Update the AT+CON notes now that an unknown address falls back to scanning.
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.
bt: keep the BLE trainer link stable with a headtracker
Summary
Four fixes for the central (trainer master) path, found while validating the
headtracker reset (EdgeTX/edgetx#8136) end to end with a BLE headtracker inside
a TX16S MKII.
handle to the end of the service, and every
0x2902in that rangeoverwrote
s_cccd_handle. The last descriptor in the service belongs to theoverride-channel characteristic (
0xAFF1), so the module enablednotifications there instead of on the trainer characteristic (
0xFFF6).AT+HTRESETsilently stopped the trainer passthrough.parserATCommand()setsbt_client_forwardHt = falsefor every AT commandand only
AT+ROLE1/AT+CONset it back to true, so a reset paused theBLE -> UART forwarding until the trainer mode was toggled.
bt_client_connect()needs the peer address type, which is only known fordevices kept in the last scan list. With an unknown address it returned
silently, but the state machine had already moved to
WAITING_CONNECTION,which only leaves on that state's scan-complete flag. With no scan running
the module waited forever and the radio kept waiting for a
Connected:line.channels as a block of zeros between frames (some append padding too), and
the module re-announced
Connected:/MTU/PHY/Boardevery 2 s forever.That came to about 2.5 kB/s plus a ~121 B text burst every 2 s, while EdgeTX
drains its 256-byte Bluetooth FIFO once per 50 ms and declares the trainer
lost after one second without a valid frame. The radio reported "trainer
signal lost" and "recovered" in a loop while the BLE link was up the whole
time (the headtracker's LED stayed solid and the module never disconnected).
Symptom (before the fix)
starts announcing trainer lost/recovered every couple of seconds.
handshake and the passthrough.
later sometimes never connected until the trainer mode was toggled.
Fix
bt_client.c: only accept the CCCD whose characteristic is the trainer(
chr_val_handle == s_data_handle) and clears_cccd_handleon everyconnect.
terminal.c: resume forwarding afterAT+HTRESET, since the link itself isnot touched.
bt_client.c/terminal.c:bt_client_connect()reports whether an attemptstarted; when it did not, the state machine rescans through the auto-connect
path.
WAITING_CONNECTIONgives up after 10 s (CONNECT_TIMEOUT_US) on adirected attempt, so an absent peer can no longer wedge the link.
bt_client.c: forward only the0x7E-framed part of each notification,dropping padding and the zeroed override block.
terminal.c: re-announceConnected:at mostANNOUNCE_REPEATS(3) timesper link instead of every 2 s forever.
No protocol change: the AT responses and the trainer wire format are unchanged.
Testing
pio test -e native: 23/23.C3SuperMini,C3SuperMini_nimble,ESP32_DEV38P,ESP32_DEV38P_nimble.on stock 2.40, EdgeTX 2.12.5 for the link tests.
20 s, ~1.3 kB/s (was 2.5 kB/s with 14 zero bytes between frames).
manual trainer toggle.
AT+HTRESETfrom an EdgeTX Special Function: instant recenter, streamuninterrupted.
rst:0x1 POWERONonly when theradio powers it).
doc/BENCH.mdandREADME.mdupdated with the measured values.Notes
AT+STATUShandler on the port branch needs the sameforwardHtrestore; it is not part of this PR because
AT+STATUSdoes not exist indevelop.is active, they should follow the same rule: either leave the passthrough
running or restore
bt_client_forwardHtexplicitly.HT Reseton a momentary switch) isfeat: add a special function to reset the BLE headtracker edgetx#8136.