Commit Graph

117 Commits

Author SHA1 Message Date
Jonas Bark
ff9671bfc5 fix: no crash on button press when no keymap is set
The keymap ('app') and the trainer app ('trainer_app') are independent
prefs. When the keymap one is missing while a trainer app is selected,
actionHandler.supportedApp stays null — every button press then threw
"Null check operator used on a null value" and the device registered no
buttons at all, so the SRAM edit screen came up empty.

- RemoteActions/DesktopActions/AndroidActions no longer dereference
  supportedApp (or getKeyPair) with `!`; they return the same
  noKeymapSet / noActionAssigned Error BaseActions already produces.
- Fall back to the selected trainer app when the keymap pref can't be
  resolved (initializeActions, Settings.init, deleteCustomAppProfile).
- BaseDevice.getOrAddButton keeps the created button in availableButtons
  even without a keymap, so the device still renders its buttons.
- The OBC BLE/mDNS emulators evaluated connectedApp.value! before the
  null guard that follows, making the guard dead code — reordered.
- handleButtonsClicked now forwards through recordError, which is why
  this never showed up in crash reporting.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-17 13:14:09 +02:00
jonas.bark@gmx.de
5d16ab6cb5 fix: two BikeControl installs no longer overwrite each other in trainer apps
Running BikeControl on a second device made the one next to the trainer app
unreachable. Each install now advertises its own identity.

Because that identity changes, an app that was already paired will ask to
pair once more.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-10 15:38:46 +02:00
Jonas Bark
782f60895e fix(obc): reset app-info reassembler on disconnect and bound the buffer
A half-received or corrupt app-info write was retained forever (cleared only
on a successful parse), poisoning every later parse so OpenBikeControl never
reported "Connected to app" again until app restart. Reset the reassembler on
disconnect and cap the buffer at 512 bytes so a stuck/corrupt stream recovers
and can't leak. Adds regression tests for reset and the bound.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-26 19:58:26 +02:00
Jonas Bark
b3960ba36c test(obc): cover app-info fragment reassembly; extract AppInfoReassembler
Extract the OpenBikeControl app-info fragment-stitching out of the BLE
emulator's write handler into a small, behavior-preserving AppInfoReassembler
so it can be unit-tested directly (the emulator's startServer() is otherwise
only reachable through the live peripheral platform).

Adds regression tests for the multi-packet app-info write (TrainingPeaks on
macOS), including the three-fragment case the previous single prior-fragment
buffer dropped — it kept only the first failed fragment, so a message split
across three packets never reassembled.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-25 20:45:36 +02:00
Jonas Bark
0f81549740 refactor: share BLE advertising "already started" recovery via mixin
Extracts the recovery added for OpenBikeControl (abe636d4) into
PeripheralAdvertisingRecovery and applies it to ZwiftEmulator too.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-25 09:08:18 +02:00
Jonas Bark
9413a1fc56 fix(obc): resolve "Address already in use" on the OpenBikeControl server
The OpenBikeControl mDNS emulator hit EADDRINUSE on its fixed port 36867
when "Connect directly over network" was toggled off then on: the
un-awaited stop() hadn't released the socket before start() rebound it.

- Bump prop submodule: ResilientTcpServer now supersedes a stale
  same-port instance before binding and defaults to walking ports
  (portAttempts: 5).
- OBC advertises the ACTUAL bound port via mDNS instead of a hardcoded
  36867, so it can walk to a free port and stay reachable (mirrors the
  DirCon emulator). Companion apps read the port from the SRV record.
- Reset isStarted on every start-failure path so a genuinely blocked
  port no longer leaves the feature showing as "running".
- Pin MyWhoosh Link to portAttempts: 1 (fixed-port contract preserved).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-25 07:34:47 +02:00
Jonas Bark
abe636d40f fix OpenBikeControl failed to advertise: Advertising has already started 2026-06-24 14:23:35 +02:00
Jonas Bark
0008e173a2 feat: label OpenBikeControl TCP server; gate iOS local-network inference to iOS 2026-06-22 10:53:56 +02:00
Jonas Bark
786621a11b Localize TrainerConnection titles (re-evaluate per locale)
The connection titles ("Connect using Bluetooth", "Connect directly over
Network", "Connect using MyWhoosh Link", ...) were captured once at object
construction in English, so they didn't follow the active locale. Back the
title with a builder (String Function()) and expose it via a getter so it
re-localizes — fixing the English titles in the localized store screenshots.
Updated all 10 subclasses and the fake connection in the bridge-transport test.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-18 11:47:43 +02:00
Jonas Bark
c41683421e Merge remote-tracking branch 'origin/6.0.1' into custom-mdns-responder
# Conflicts:
#	.gitignore
#	lib/bluetooth/devices/openbikecontrol/obc_mdns_emulator.dart
#	prop
2026-06-12 12:03:37 +02:00
Jonas Bark
e736425331 Keep Zwift/Rouvy controller connection alive when idle (#367)
Zwift and Rouvy drop a wired LAN controller after ~30s without traffic. The Ftms/Rouvy mDNS emulators only emit on a button press, so an idle rider (pedalling, not shifting) goes silent and gets disconnected.

Add a ControllerKeepAlive timer that re-emits the neutral "released" controller frame every 5s while a client is connected, started/stopped from each emulator's isConnected listener. It's the same frame a key-up sends, so it resets the peer's inactivity watchdog without registering a phantom press.

Also drops an earlier keepalive attempt from OpenBikeControlMdnsEmulator — that path speaks the OpenBikeControl protocol, which Zwift doesn't use.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-12 11:03:42 +02:00
Jonas Bark
b2de1d56f0 OBC emulator: pick the advertised IPv4 via AdvertisedAddressPicker
Replaces 'first non-loopback IPv4', which on Android advertised the
phone-internal CLAT dummy address (192.0.0.8) when the 464XLAT
interface enumerated before wlan0.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-12 10:42:11 +02:00
Jonas Bark
44ed08070f Use the custom mDNS responder on desktop (TrainingPeaks IPv6 fix)
Switch the OBC/DirCon advertisement to prop's ServiceAdvertiser seam and
select the in-process responder backend on macOS/Windows/Linux at app
startup. The advertisement now carries a dedicated hostname with a
single A record, so Mono-based trainer apps (TrainingPeaks) no longer
pick a scope-less IPv6 link-local and fail with 'No route to host'.
iOS/Android keep the OS responder via nsd.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-11 20:46:19 +02:00
Jonas Bark
2f98f0c7fc Move OpenBikeControl + MyWhoosh Link servers onto ResilientTcpServer
Both had the fragile accept-loop copy: no teardown identity check (a
reconnecting app's old socket killed the new session), no onError
(abrupt resets became uncaught async errors), shared: true (a second
app instance silently stole connections). They keep their fixed
protocol ports (36867 / 21587) — no port fallback; a blocked port now
fails loudly instead of misbehaving.

Bumps prop with the shared ResilientTcpServer, its tests, and the
in-flight custom mDNS responder work.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-11 20:44:35 +02:00
Jonas Bark
02c8da29f6 Use the shared advertised-address policy in the OBC mDNS emulator
Replaces the copy-pasted "first non-loopback IPv4" interface selection
with prop's AdvertisedAddressPicker (prefers the real LAN interface over
VPN tunnels, virtualization bridges and link-local adapters) and bumps
the prop submodule with the DirCon TCP/mDNS hardening: reconnect
supersede, socket onError handling, port-bind fallback with
actually-bound-port advertising, dual-stack listener.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-11 20:09:23 +02:00
Jonas Bark
df18e4ff2f advertisement fix 2026-06-10 11:09:35 +02:00
Jonas Bark
a60a1384e3 Merge origin/universal-ble-2-peripheral: universal_ble 2.0.0 peripheral mode
Brings the BLE peripheral-mode migration to universal_ble 2.0.0 into the
WiFi DirCon trainer-discovery branch and bumps universal_ble to the latest
fork commit (ref: changes, 2.0.0).

Conflict resolutions:
- prop submodule: merged the universal_ble 2.0 transporter migration with
  the WiFi DirCon TrainerTransport refactor; kept the '0x' short-UUID
  normalisation on startAdvertising. Updated BleCharacteristic call sites
  to the new 3-arg (uuid, properties, descriptors) constructor.
- obc_ble_emulator.dart: took the PeripheralServer / universal_ble 2.0
  write-handler migration; kept the richer Error(button:) context on
  sendAction (using _currentDeviceId, the migrated connection tracker).
- unlock.dart: kept the main.dart import.
- pubspec.yaml: kept version 6.0.0+135; took ref: changes for universal_ble.

Pre-existing prop test failures (composite/dircon/fitness serviceUUIDs) are
unchanged by this merge — they fail identically on the pre-merge branch.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-10 09:19:58 +02:00
Jonas Bark
4e2a922760 feat: use shared BikeControl mDNS marker constants; register obc advertisement
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-10 07:10:40 +02:00
Jonas Bark
e3985611cf fix bluetooth parsing - fixes https://github.com/OpenBikeControl/bikecontrol/issues/366 2026-06-06 21:59:13 +02:00
Jonas Bark
a68b68a1b4 fix button mapping popup 2026-06-01 11:53:55 +02:00
Jonas Bark
29741e520f migrate peripheral mode to universal_ble 2.0.0
Drop bluetooth_low_energy. Move OBC BLE emulator, Zwift emulator, and
the remote mouse / keyboard pairing flows onto a new PeripheralServer
wrapper around UniversalBlePeripheral that routes per-characteristic
read/write handlers, so multiple peripheral instances coexist without
clobbering universal_ble's process-wide handlers.

Also: onValueChange callback gains a timestamp param (v1.0.0 breaking
change), PeripheralManager().showAppSettings() → openAppSettings(),
UUID.short(0x12) → literal UUID, and prop submodule bumped to the
matching universal_ble peripheral rewrite.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-18 09:28:39 +02:00
Jonas Bark
618aa01204 IPV6 is not the cause of the issues 2026-05-14 18:11:53 +02:00
Jonas Bark
1561ab5e90 IPV6 is not the cause of the issues 2026-05-14 18:11:53 +02:00
Jonas Bark
ce92f655f3 use IPV4 only for MyWhoosh 2026-05-14 15:05:47 +02:00
Jonas Bark
d98f59a9a5 use IPV4 only for MyWhoosh 2026-05-14 15:05:47 +02:00
Jonas Bark
75dd10371a show default OBP actions 2026-05-11 20:53:25 +02:00
Jonas Bark
952f866b9f show default OBP actions 2026-05-11 20:53:25 +02:00
Jonas Bark
642fc754a1 UI adjustments, BLE advertisement fix 2026-04-26 09:14:00 +02:00
Jonas Bark
c47667af94 UI adjustments, BLE advertisement fix 2026-04-26 09:14:00 +02:00
Jonas Bark
9d6aeed78f refactor: tighten OBC BLE TrainerConnectionType import 2026-04-25 20:27:46 +02:00
Jonas Bark
dec8791961 refactor: tighten OBC BLE TrainerConnectionType import 2026-04-25 20:27:46 +02:00
Jonas Bark
44e3cfd56d feat: declare OBC emulator transports for VS resolution 2026-04-25 20:23:38 +02:00
Jonas Bark
4b492f260f feat: declare OBC emulator transports for VS resolution 2026-04-25 20:23:38 +02:00
Jonas Bark
362f6521fa cleanup, fixes 2026-04-15 13:50:04 +02:00
Jonas Bark
43ab8837fc cleanup, fixes 2026-04-15 13:50:04 +02:00
Jonas Bark
a87a862c86 refactor: rename Dircon classes to BikeDefinition, split transport layer
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-15 13:06:13 +02:00
Jonas Bark
0432b83a10 refactor: rename Dircon classes to BikeDefinition, split transport layer
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-15 13:06:13 +02:00
Jonas Bark
6b5db30e03 proxy adjustments 2026-04-14 13:27:46 +02:00
Jonas Bark
eed7b21b23 proxy adjustments 2026-04-14 13:27:46 +02:00
Jonas Bark
40f171e935 new openbikecontrol actions 2026-04-12 12:06:37 +02:00
Jonas Bark
1f306ef0f3 new openbikecontrol actions 2026-04-12 12:06:37 +02:00
Jonas Bark
e0adb536a8 OBC adjustments 2026-04-10 15:21:02 +02:00
Jonas Bark
89dbec72ef OBC adjustments 2026-04-10 15:21:02 +02:00
Jonas Bark
f1c45bf6fa fix server not closing 2026-03-26 08:58:20 +01:00
Jonas Bark
cdd837cfeb fix server not closing 2026-03-26 08:58:20 +01:00
Jonas Bark
cfcdb0203f UI adjustments 2026-03-25 11:28:03 +01:00
Jonas Bark
8f3b090b3a UI adjustments 2026-03-25 11:28:03 +01:00
Jonas Bark
2f628c7345 revise connection methods 2026-03-25 09:27:48 +01:00
Jonas Bark
ab5a712c9e revise connection methods 2026-03-25 09:27:48 +01:00
Jonas Bark
5ed2bce59b revise connection methods 2026-03-25 09:27:37 +01:00