diff --git a/prop_public/lib/devices/shimano/shimano_config.dart b/prop_public/lib/devices/shimano/shimano_config.dart index 1c5540b2..9491a70b 100644 --- a/prop_public/lib/devices/shimano/shimano_config.dart +++ b/prop_public/lib/devices/shimano/shimano_config.dart @@ -70,6 +70,7 @@ class ShimanoConfig { void Function(ShimanoWiredSwitchEvent event)? onWiredSwitch, void Function(Uint8List frame)? onUnknownFrame, required void Function(String step, Object error, StackTrace stack) onStepError, + ShimanoShifterSides? sides, }) => throw UnsupportedError('Shimano Di2 button mode is not available in this build'); @@ -91,7 +92,7 @@ class ShimanoConfig { /// Decodes the paddle presses a Di2 relays. The stub never finds any. class ShimanoButtons { - static List decode(Uint8List frame) => const []; + static List decode(Uint8List frame, {ShimanoShifterSides? sides}) => const []; } /// A press of a wired switch, reported by the Di2. @@ -139,6 +140,18 @@ enum ShimanoSwitchFunction { } } +/// Which shifter is on which pairing slot. The stub learns nothing: slot 0 is +/// the left. +class ShimanoShifterSides { + ShimanoShifter of(int slot) => slot == 0 ? ShimanoShifter.left : ShimanoShifter.right; + + void learn(ShimanoShifterSwitches switches) {} + + void learnAll(Iterable switches) {} + + void learnFrame(Uint8List frame) {} +} + /// The four switches of one wireless shifter, by its pairing [slot]. class ShimanoShifterSwitches { const ShimanoShifterSwitches({ @@ -164,7 +177,7 @@ class ShimanoShifterSwitches { bool get paddlesOnDfly => (a, b) == dflyPaddles; - ShimanoShifterSwitches withDflyPaddles() { + ShimanoShifterSwitches withDflyPaddles({ShimanoShifter? side}) { final (pa, pb) = dflyPaddles; return ShimanoShifterSwitches(slot: slot, a: pa, b: pb, c: c, s: s); } diff --git a/prop_public/lib/emulators/click_emulator.dart b/prop_public/lib/emulators/click_emulator.dart index 825e0264..a998d166 100644 --- a/prop_public/lib/emulators/click_emulator.dart +++ b/prop_public/lib/emulators/click_emulator.dart @@ -1,11 +1,20 @@ //INFO: This is a stub - contact me if you need the full implementation. import 'package:flutter/foundation.dart'; +import 'package:flutter/services.dart' show Uint8List; class ClickEmulator { final ValueNotifier isStarted = ValueNotifier(false); final ValueNotifier isConnected = ValueNotifier(false); + /// Called with the controller's answer to a relayed unlock challenge. + void Function(Uint8List authResponse)? onAuthResponse; + + /// Relays an unlock challenge to the connected app. No-op in the stub. + void sendChallenge(List challenge) {} + + void clearChallenge() {} + Future startServer(bool hello, {String? name}) async { isStarted.value = true; } diff --git a/prop_public/lib/emulators/dircon_emulator.dart b/prop_public/lib/emulators/dircon_emulator.dart index 6ac73871..769197f7 100644 --- a/prop_public/lib/emulators/dircon_emulator.dart +++ b/prop_public/lib/emulators/dircon_emulator.dart @@ -87,7 +87,13 @@ class DirconEmulator { /// trainer-app / trial / device-name callbacks. String get advertisementName => 'BikeControl'; - bool processCharacteristic(String characteristic, Uint8List bytes) => false; + /// The name the Bluetooth bridge advertises under, once it advertises. + ValueListenable get bluetoothLocalName => _bluetoothLocalName; + final ValueNotifier _bluetoothLocalName = ValueNotifier(null); + + /// [from] is the definition the frame came from, when several trainers + /// share the bridge. + bool processCharacteristic(String characteristic, Uint8List bytes, {FitnessBikeDefinition? from}) => false; Future startServer({ required RetrofitMode mode, diff --git a/prop_public/lib/emulators/transporter/bluetooth_transporter.dart b/prop_public/lib/emulators/transporter/bluetooth_transporter.dart index fbfb2704..4cb5ae3e 100644 --- a/prop_public/lib/emulators/transporter/bluetooth_transporter.dart +++ b/prop_public/lib/emulators/transporter/bluetooth_transporter.dart @@ -28,3 +28,12 @@ class BluetoothTransporter extends Transporter { @override void dispose() {} } + +/// The platform refuses the BLE peripheral role (on Android: no +/// BLUETOOTH_ADVERTISE permission). +class BluetoothPeripheralUnauthorizedException implements Exception { + const BluetoothPeripheralUnauthorizedException(); + + @override + String toString() => 'Bluetooth advertise permission not granted'; +} diff --git a/prop_public/lib/mdns/service_advertiser.dart b/prop_public/lib/mdns/service_advertiser.dart index 3aeb0733..8347d17c 100644 --- a/prop_public/lib/mdns/service_advertiser.dart +++ b/prop_public/lib/mdns/service_advertiser.dart @@ -62,6 +62,21 @@ abstract class ServiceAdvertiser { static final ValueListenable untrackedAddress = ValueNotifier(null); } +/// An advertiser that can check its advertisement and publish it again. +abstract interface class RecoverableAdvertiser { + Future recover({bool force = false}); + + String? get recoveryStatus; + + /// [recover] on [ServiceAdvertiser.instance] when it supports it. + static Future recoverInstance({bool force = false}) async { + final advertiser = ServiceAdvertiser.instance; + if (advertiser is RecoverableAdvertiser) { + await (advertiser as RecoverableAdvertiser).recover(force: force); + } + } +} + /// Hostname-label rules shared by the backends that publish their own host /// record. Stubbed here. abstract final class MdnsHostLabel { diff --git a/prop_public/lib/utils/ble_connection_options.dart b/prop_public/lib/utils/ble_connection_options.dart new file mode 100644 index 00000000..f6060f1a --- /dev/null +++ b/prop_public/lib/utils/ble_connection_options.dart @@ -0,0 +1,17 @@ +import 'package:universal_ble/universal_ble.dart'; + +/// Platform options for every BLE central connect BikeControl makes. +/// +/// iOS/macOS: ask CoreBluetooth to wake a suspended app for connection, +/// disconnection and notification events, so controllers and trainers keep +/// working while BikeControl is in the background behind the trainer app. +/// Ignored on the other platforms. +/// +/// A fresh instance per call: the pigeon config classes are mutable. +ConnectionPlatformConfig bleConnectionPlatformConfig() => ConnectionPlatformConfig( + apple: AppleConnectionOptions( + notifyOnConnection: true, + notifyOnDisconnection: true, + notifyOnNotification: true, + ), +); diff --git a/prop_public/lib/utils/resilient_tcp_server.dart b/prop_public/lib/utils/resilient_tcp_server.dart index 65fa175d..41882174 100644 --- a/prop_public/lib/utils/resilient_tcp_server.dart +++ b/prop_public/lib/utils/resilient_tcp_server.dart @@ -6,6 +6,20 @@ import 'dart:io'; +/// One client connection, for the support diagnostics. The stub records none. +class TcpConnectionLogEntry { + TcpConnectionLogEntry({required this.at, required this.server, required this.port, required this.remote}); + + final DateTime at; + final String server; + final int port; + final String remote; + + DateTime? closedAt; + int bytesReceived = 0; + String? note; +} + class ResilientTcpServer { ResilientTcpServer({ required this.preferredPort, @@ -36,6 +50,12 @@ class ResilientTcpServer { /// Every currently-running server, for the diagnostics block. static final List activeServers = []; + /// Recent client connections. Always empty in the stub. + static List get connectionLog => const []; + + /// Binds every running server's listeners again. No-op in the stub. + static Future rebindAllListeners() async {} + final void Function(Socket socket) onClientConnected; final void Function(Socket socket, List data) onData; final void Function() onClientDisconnected; diff --git a/prop_public/lib/utils/shared.dart b/prop_public/lib/utils/shared.dart index 3fd599be..b179f715 100644 --- a/prop_public/lib/utils/shared.dart +++ b/prop_public/lib/utils/shared.dart @@ -13,6 +13,10 @@ class SharedLogic { static void keepAlive() {} static void stopKeepAlive() {} + + static void refreshKeepAlive() {} + + static String get keepAliveStatus => 'not available in this build'; } class Logger { diff --git a/prop_public/lib/utils/suspension_watch.dart b/prop_public/lib/utils/suspension_watch.dart new file mode 100644 index 00000000..857f0727 --- /dev/null +++ b/prop_public/lib/utils/suspension_watch.dart @@ -0,0 +1,39 @@ +//INFO: This is a stub - contact me if you need the full implementation. +// +// The full implementation notices when the process stood still (suspended, +// machine asleep) and tells its listeners how long. The stub never sees one. + +import 'dart:async'; + +class SuspensionWatch { + SuspensionWatch({ + this.tick = const Duration(seconds: 5), + this.threshold = const Duration(seconds: 20), + DateTime Function() now = DateTime.now, + }); + + static final SuspensionWatch instance = SuspensionWatch(); + + final Duration tick; + final Duration threshold; + + DateTime? lastGapEndedAt; + Duration? lastGap; + int gapCount = 0; + + bool get isRunning => false; + + void addListener(FutureOr Function(Duration gap) listener) {} + + void removeListener(FutureOr Function(Duration gap) listener) {} + + void start() {} + + void stop() {} + + void check() {} + + String get status => 'not running'; + + void reset() {} +}