feat: Implement command queue for BLE command handling

- Added BleCommandQueue to manage command serialization and responses in BleCommandSender.
- Updated writeData, writeDataAndWaitForAck, and writeDataAndWaitForResponse methods to utilize the command queue.
- Enhanced BleResponseHandler to complete commands based on responses received from the BLE device.
- Introduced new commands for channel management, including getChannel and setChannel.
- Created LocationTrailLayer and TrailControls widgets for displaying and managing location trails on the map.
- Added PermissionRequestDialog to handle location permission requests on app startup.
- Updated LocationTrackingService to allow GPS tracking without a BLE connection.
This commit is contained in:
Janez T
2025-10-18 21:12:02 +02:00
parent f88c9cfdd3
commit c50a260263
35 changed files with 1854 additions and 59 deletions

View File

@@ -123,6 +123,7 @@ class ConnectionProvider with ChangeNotifier {
Function(List<Contact>)? onContactsComplete;
Function(Message)? onMessageReceived;
Function(Uint8List publicKey, Uint8List lppData)? onTelemetryReceived;
Function(int channelIdx, String channelName)? onChannelInfoReceived;
Function(Uint8List publicKeyPrefix, int tag, Uint8List responseData)?
onBinaryResponse;
Function(Uint8List publicKey)? onPathUpdated;
@@ -249,6 +250,10 @@ class ConnectionProvider with ChangeNotifier {
onContactsComplete?.call(contacts);
};
_bleService.onChannelInfoReceived = (channelIdx, channelName) {
onChannelInfoReceived?.call(channelIdx, channelName);
};
_bleService.onMessageReceived = (message) {
// Parse SAR markers
final enhancedMessage = SarMessageParser.enhanceMessage(message);
@@ -628,6 +633,24 @@ class ConnectionProvider with ChangeNotifier {
}
}
/// Sync all channels from device
Future<void> syncChannels({int? maxChannels}) async {
if (!_bleService.isConnected) {
_error = 'Not connected to device';
notifyListeners();
return;
}
try {
// Use maxChannels from device info if available, otherwise default to 40
final channelCount = maxChannels ?? _deviceInfo.maxChannels ?? 40;
await _bleService.syncAllChannels(maxChannels: channelCount);
} catch (e) {
_error = 'Failed to sync channels: $e';
notifyListeners();
}
}
/// Add or update a contact on the companion radio
///
/// This manually adds a contact to the radio's internal contact table.