diff --git a/documentation/contacts.md b/documentation/contacts.md index 27eace4a..00fc01e5 100644 --- a/documentation/contacts.md +++ b/documentation/contacts.md @@ -80,7 +80,7 @@ Groups are stored per radio identity (scoped by public key). | Add/Remove Favorite | All types | Toggles the favorite flag | | Share Contact | All types | Requests advert from device → copies `meshcore://` URI to clipboard | | Share Contact Zero-Hop | All types | Broadcasts the contact's advertisement one hop | -| Delete Contact | All types | Confirmation dialog → removes from device and clears messages | +| Delete Contact | All types | Confirmation dialog → removes from device and clears messages. If auto-add is on for that type, the radio adds it back the next time it advertises; the dialog warns about this | ## App Bar Menus diff --git a/documentation/map-and-location.md b/documentation/map-and-location.md index 3cfa7a6f..634235ef 100644 --- a/documentation/map-and-location.md +++ b/documentation/map-and-location.md @@ -103,10 +103,18 @@ Shows node count and pin count. Tappable to expand a legend of all marker types. ## Path Trace Map ### How to Access -- From the main map's radar icon +- From the main map's menu → **Path Trace** (build your own route, see below) - From a contact's long-press menu → "Path Trace / Ping" - From a message's path view → radar icon +### Building a Custom Trace on the Map +1. Open the map menu and choose **Path Trace**. A panel appears at the top of the map. +2. Tap nodes on the map in the order the trace should travel. **Remove Last** and **Clear** edit the list. +3. Choose **Round trip** (the trace comes back along the same hops) or **As entered** (the hops are used exactly as listed, so add the return hops yourself). +4. Tap **Run path trace**. Nothing is sent until you press this button. + +Returning from the result keeps your hops, mode and the last result (**View last result** reopens it without sending again). **Close** or the back button hides the panel without discarding the hops; reopening **Path Trace** during the same session resumes where you left off. The hops are dropped when you connect to a different radio. + ### What the User Sees A map with a polyline showing the route from your node through repeater hops to the target: - **Green circles**: Hops with known GPS coordinates diff --git a/lib/connector/meshcore_connector.dart b/lib/connector/meshcore_connector.dart index 49bdcbd8..8a5428ee 100644 --- a/lib/connector/meshcore_connector.dart +++ b/lib/connector/meshcore_connector.dart @@ -684,6 +684,16 @@ class MeshCoreConnector extends ChangeNotifier { bool? get autoAddSensors => _autoAddSensors; bool? get autoAddOverwriteOldest => _overwriteOldest; + /// Whether the radio stores adverts of [type] by itself, so a removed + /// contact of that type returns the next time it advertises. + bool autoAddsContactType(int type) => switch (type) { + advTypeChat => _autoAddUsers, + advTypeRepeater => _autoAddRepeaters, + advTypeRoom => _autoAddRoomServers, + advTypeSensor => _autoAddSensors, + _ => false, + }; + /// autoadd_max_hops from GET_AUTOADD_CONFIG (0 = no limit), null when the /// firmware did not report it (pre-v1.13). int? get autoAddMaxHops => _autoAddMaxHops; @@ -4377,7 +4387,7 @@ class MeshCoreConnector extends ChangeNotifier { _pathOpLock = completer.future; await prev; try { - if (!isConnected) return; + if (!isConnected || !_isKnownContact(contact)) return; final width = pathHashWidth ?? @@ -4420,6 +4430,13 @@ class MeshCoreConnector extends ChangeNotifier { } } + /// Whether [contact] is still in the radio's contact list. The firmware's + /// CMD_ADD_UPDATE_CONTACT adds unknown keys, so path/flag writes for a + /// removed contact (e.g. a repeater screen still open after its old key was + /// deleted) would re-create it on the radio. + bool _isKnownContact(Contact contact) => + _contacts.any((c) => c.publicKeyHex == contact.publicKeyHex); + /// The advert timestamp the firmware holds for [contact] (Contact.lastSeen /// is parsed from that field); the stored copy is freshest. DateTime _deviceLastAdvert(Contact contact) { @@ -4436,7 +4453,7 @@ class MeshCoreConnector extends ChangeNotifier { bool? teleLoc, bool? teleEnv, }) async { - if (!isConnected) return; + if (!isConnected || !_isKnownContact(contact)) return; final latestContact = await _fetchContactSnapshotFromDevice(contact.publicKey) ?? contact; int updatedFlags = isFavorite != null @@ -5055,13 +5072,26 @@ class MeshCoreConnector extends ChangeNotifier { }) async { if (!isConnected) return; + // Only drop the contact locally once the radio confirms; otherwise the + // next contact sync restores it. ERR means the radio does not have it. + try { + await sendFrame( + buildRemoveContactFrame(contact.publicKey), + waitForGenericAck: true, + ); + } on FirmwareCommandException catch (e) { + _appDebugLogService?.warn( + 'Radio has no contact ${contact.publicKeyHex.substring(0, 8)} ' + '(error ${e.errCode}); removing it locally', + tag: 'Connector', + ); + } + _handleDiscovery( contact, contact.rawPacket ?? Uint8List(0), noNotify: true, ); - - await sendFrame(buildRemoveContactFrame(contact.publicKey)); _contactsStorageFull = false; _contacts.removeWhere((c) => c.publicKeyHex == contact.publicKeyHex); _knownContactKeys.remove(contact.publicKeyHex); diff --git a/lib/connector/pending_command_replies.dart b/lib/connector/pending_command_replies.dart index a0dc9b5d..094846e2 100644 --- a/lib/connector/pending_command_replies.dart +++ b/lib/connector/pending_command_replies.dart @@ -5,6 +5,16 @@ import 'package:flutter/foundation.dart'; import '../services/image_chunk_transport.dart' show cmdSendChannelData; import 'meshcore_protocol.dart'; +/// RESP_CODE_ERR received for a command that was waiting for its reply. +class FirmwareCommandException implements Exception { + final int errCode; + + const FirmwareCommandException(this.errCode); + + @override + String toString() => 'Exception: Command failed with error code $errCode'; +} + /// A command waiting for its reply from the companion firmware. class PendingCommandReply { final int commandCode; @@ -203,9 +213,7 @@ class PendingCommandReplies { if (_queue.isEmpty) return null; final pending = _queue.removeAt(0); if (pending.isTombstone) return null; - pending.completer?.completeError( - Exception('Command failed with error code $errCode'), - ); + pending.completer?.completeError(FirmwareCommandException(errCode)); return pending; } diff --git a/lib/helpers/marker_message.dart b/lib/helpers/marker_message.dart new file mode 100644 index 00000000..52f251c6 --- /dev/null +++ b/lib/helpers/marker_message.dart @@ -0,0 +1,30 @@ +import 'package:latlong2/latlong.dart'; + +class MarkerPayload { + final LatLng position; + final String label; + final String flags; + + MarkerPayload({ + required this.position, + required this.label, + required this.flags, + }); +} + +/// Parse a shared marker text message of the form +/// `m:,|