feat: Implement self advertisement functionality and enhance location broadcasting settings

This commit is contained in:
Janez T
2025-10-14 21:36:50 +02:00
parent 2cb6c34167
commit fd54392d3c
7 changed files with 808 additions and 164 deletions

View File

@@ -415,6 +415,29 @@ class ConnectionProvider with ChangeNotifier {
}
}
/// Send self advertisement to mesh network
///
/// Broadcasts the device's current advertisement data (name, location, etc.)
/// to the mesh network. Use this after updating position or name to notify
/// other nodes of the change.
///
/// [floodMode] - if true, broadcast to entire mesh (default for SAR ops)
/// if false, only send to direct neighbors (zero-hop)
Future<void> sendSelfAdvert({bool floodMode = true}) async {
if (!_bleService.isConnected) {
_error = 'Not connected to device';
notifyListeners();
return;
}
try {
await _bleService.sendSelfAdvert(floodMode: floodMode);
} catch (e) {
_error = 'Failed to send advertisement: $e';
notifyListeners();
}
}
/// Set radio parameters
Future<void> setRadioParams({
required int frequency,

View File

@@ -9,6 +9,31 @@ import '../services/cayenne_lpp_parser.dart';
class ContactsProvider with ChangeNotifier {
final Map<String, Contact> _contacts = {};
// Add default public channel on initialization
ContactsProvider() {
_ensurePublicChannelExists();
}
/// Ensure public channel always exists in the list
void _ensurePublicChannelExists() {
const publicChannelKey = 'public_channel_0';
if (!_contacts.containsKey(publicChannelKey)) {
// Create a pseudo-contact for the public channel
_contacts[publicChannelKey] = Contact(
publicKey: Uint8List.fromList(List.filled(32, 0)), // Zero key for public
type: ContactType.room,
flags: 0,
outPathLen: 0,
outPath: Uint8List(64),
advName: 'Public Channel',
lastAdvert: DateTime.now().millisecondsSinceEpoch ~/ 1000,
advLat: 0,
advLon: 0,
lastMod: DateTime.now().millisecondsSinceEpoch ~/ 1000,
);
}
}
List<Contact> get contacts => _contacts.values.toList();
List<Contact> get chatContacts =>
@@ -17,8 +42,11 @@ class ContactsProvider with ChangeNotifier {
List<Contact> get repeaters =>
contacts.where((c) => c.isRepeater).toList()..sort(_sortByLastSeen);
List<Contact> get rooms =>
contacts.where((c) => c.isRoom).toList()..sort(_sortByLastSeen);
List<Contact> get rooms {
// Always ensure public channel exists when getting rooms
_ensurePublicChannelExists();
return contacts.where((c) => c.isRoom).toList()..sort(_sortByLastSeen);
}
/// Get contacts with location (for map display)
List<Contact> get contactsWithLocation =>