mirror of
https://github.com/dz0ny/meshcore-sar.git
synced 2026-08-11 16:30:28 +00:00
feat: Configure default public channel with well-known secret and enhance channel message handling
This commit is contained in:
@@ -6,6 +6,7 @@ import '../models/contact.dart';
|
||||
import '../models/message.dart';
|
||||
import '../models/room_login_state.dart';
|
||||
import '../services/meshcore_ble_service.dart';
|
||||
import '../services/meshcore_constants.dart';
|
||||
import '../utils/sar_message_parser.dart';
|
||||
import 'helpers/room_login_manager.dart';
|
||||
import 'helpers/message_delivery_tracker.dart';
|
||||
@@ -673,6 +674,39 @@ class ConnectionProvider with ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
/// Configure the default public channel (channel 0) with the well-known secret
|
||||
///
|
||||
/// This MUST be called after connecting to the device and before sending any
|
||||
/// channel messages. Without this configuration, channel messages will fail
|
||||
/// with ERR_CODE_NOT_FOUND.
|
||||
///
|
||||
/// The public channel uses a well-known pre-shared key that all MeshCore
|
||||
/// devices use for the default public channel.
|
||||
Future<void> configureDefaultPublicChannel() async {
|
||||
if (!_bleService.isConnected) {
|
||||
_error = 'Not connected to device';
|
||||
notifyListeners();
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
debugPrint('📻 [Provider] Configuring default public channel (channel 0)');
|
||||
debugPrint(' Using secret: ${MeshCoreConstants.defaultPublicChannelSecret.map((b) => b.toRadixString(16).padLeft(2, '0')).join('')}');
|
||||
await _bleService.setChannel(
|
||||
channelIdx: 0,
|
||||
channelName: 'Public Channel',
|
||||
secret: MeshCoreConstants.defaultPublicChannelSecret,
|
||||
);
|
||||
debugPrint('✅ [Provider] Public channel configured successfully');
|
||||
} catch (e) {
|
||||
_error = 'Failed to configure public channel: $e';
|
||||
debugPrint('❌ [Provider] Public channel configuration failed: $e');
|
||||
debugPrint(' This may be normal if the channel is pre-configured in firmware');
|
||||
notifyListeners();
|
||||
rethrow; // Re-throw to notify caller of failure
|
||||
}
|
||||
}
|
||||
|
||||
/// Add or update a contact on the companion radio
|
||||
///
|
||||
/// This manually adds a contact to the radio's internal contact table.
|
||||
|
||||
Reference in New Issue
Block a user