mirror of
https://github.com/zjs81/meshcore-open.git
synced 2026-06-18 00:16:26 +10:00
Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 60e8ee0130 | |||
| 6dfb7a4b69 | |||
| 28a423e0a8 | |||
| 3593cfa843 | |||
| dc85e7a41c | |||
| 9265daaf16 | |||
| 4b744184c2 | |||
| 06a906f4f7 | |||
| 24fa78741b | |||
| 79a45c527b |
@@ -289,6 +289,10 @@ class MeshCoreConnector extends ChangeNotifier {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<Contact> get allContacts => List.unmodifiable([
|
||||||
|
..._contacts,
|
||||||
|
..._discoveredContacts.where((c) => !c.isActive),
|
||||||
|
]);
|
||||||
List<Contact> get discoveredContacts {
|
List<Contact> get discoveredContacts {
|
||||||
return List.unmodifiable(_discoveredContacts);
|
return List.unmodifiable(_discoveredContacts);
|
||||||
}
|
}
|
||||||
@@ -704,6 +708,9 @@ class MeshCoreConnector extends ChangeNotifier {
|
|||||||
_knownContactKeys
|
_knownContactKeys
|
||||||
..clear()
|
..clear()
|
||||||
..addAll(cached.map((c) => c.publicKeyHex));
|
..addAll(cached.map((c) => c.publicKeyHex));
|
||||||
|
_contacts
|
||||||
|
..clear()
|
||||||
|
..addAll(cached);
|
||||||
for (final contact in cached) {
|
for (final contact in cached) {
|
||||||
_ensureContactSmazSettingLoaded(contact.publicKeyHex);
|
_ensureContactSmazSettingLoaded(contact.publicKeyHex);
|
||||||
}
|
}
|
||||||
@@ -1536,6 +1543,10 @@ class MeshCoreConnector extends ChangeNotifier {
|
|||||||
|
|
||||||
if (_activeTransport == MeshCoreTransportType.usb) {
|
if (_activeTransport == MeshCoreTransportType.usb) {
|
||||||
await _usbManager.write(data);
|
await _usbManager.write(data);
|
||||||
|
// Brief pause so the device firmware can process each frame before the
|
||||||
|
// next arrives. Without this, rapid-fire frames over USB can cause the
|
||||||
|
// device to miss responses (especially on reconnect).
|
||||||
|
await Future<void>.delayed(const Duration(milliseconds: 10));
|
||||||
} else if (_activeTransport == MeshCoreTransportType.tcp) {
|
} else if (_activeTransport == MeshCoreTransportType.tcp) {
|
||||||
await _tcpConnector.write(data);
|
await _tcpConnector.write(data);
|
||||||
} else {
|
} else {
|
||||||
@@ -2909,6 +2920,8 @@ class MeshCoreConnector extends ChangeNotifier {
|
|||||||
void _handleContact(Uint8List frame, {bool isContact = true}) {
|
void _handleContact(Uint8List frame, {bool isContact = true}) {
|
||||||
final contact = Contact.fromFrame(frame);
|
final contact = Contact.fromFrame(frame);
|
||||||
if (contact != null) {
|
if (contact != null) {
|
||||||
|
_handleDiscovery(contact, frame, noNotify: true, addActive: true);
|
||||||
|
|
||||||
if (contact.type == advTypeRepeater) {
|
if (contact.type == advTypeRepeater) {
|
||||||
_contactUnreadCount.remove(contact.publicKeyHex);
|
_contactUnreadCount.remove(contact.publicKeyHex);
|
||||||
_unreadStore.saveContactUnreadCount(
|
_unreadStore.saveContactUnreadCount(
|
||||||
@@ -4717,6 +4730,12 @@ class MeshCoreConnector extends ChangeNotifier {
|
|||||||
(_autoAddRoomServers && type == advTypeRoom) ||
|
(_autoAddRoomServers && type == advTypeRoom) ||
|
||||||
(_autoAddSensors && type == advTypeSensor)) {
|
(_autoAddSensors && type == advTypeSensor)) {
|
||||||
_handleContactAdvert(newContact);
|
_handleContactAdvert(newContact);
|
||||||
|
_handleDiscovery(
|
||||||
|
newContact,
|
||||||
|
rawPacket,
|
||||||
|
noNotify: true,
|
||||||
|
addActive: true,
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
_handleDiscovery(newContact, rawPacket);
|
_handleDiscovery(newContact, rawPacket);
|
||||||
}
|
}
|
||||||
@@ -4741,8 +4760,20 @@ class MeshCoreConnector extends ChangeNotifier {
|
|||||||
|
|
||||||
// CRITICAL: Preserve user's path override when contact is refreshed from device
|
// CRITICAL: Preserve user's path override when contact is refreshed from device
|
||||||
_contacts[existingIndex] = existing.copyWith(
|
_contacts[existingIndex] = existing.copyWith(
|
||||||
latitude: hasLocation ? latitude : existing.latitude,
|
latitude:
|
||||||
longitude: hasLocation ? longitude : existing.longitude,
|
hasLocation &&
|
||||||
|
latitude != null &&
|
||||||
|
latitude.abs() <= 90 &&
|
||||||
|
(latitude != 0 || longitude != 0)
|
||||||
|
? latitude
|
||||||
|
: existing.latitude,
|
||||||
|
longitude:
|
||||||
|
hasLocation &&
|
||||||
|
longitude != null &&
|
||||||
|
longitude.abs() <= 180 &&
|
||||||
|
(latitude != 0 || longitude != 0)
|
||||||
|
? longitude
|
||||||
|
: existing.longitude,
|
||||||
name: hasName ? name : existing.name,
|
name: hasName ? name : existing.name,
|
||||||
path: Uint8List.fromList(path.reversed.toList()),
|
path: Uint8List.fromList(path.reversed.toList()),
|
||||||
pathLength: path.length,
|
pathLength: path.length,
|
||||||
@@ -4813,11 +4844,11 @@ class MeshCoreConnector extends ChangeNotifier {
|
|||||||
try {
|
try {
|
||||||
reader.skipBytes(1); // Skip the response code byte
|
reader.skipBytes(1); // Skip the response code byte
|
||||||
final flags = reader.readByte();
|
final flags = reader.readByte();
|
||||||
_autoAddUsers = flags & autoAddChatFlag != 0;
|
_autoAddUsers = (flags & autoAddChatFlag) != 0;
|
||||||
_autoAddRepeaters = flags & autoAddRepeaterFlag != 0;
|
_autoAddRepeaters = (flags & autoAddRepeaterFlag) != 0;
|
||||||
_autoAddRoomServers = flags & autoAddRoomServerFlag != 0;
|
_autoAddRoomServers = (flags & autoAddRoomServerFlag) != 0;
|
||||||
_autoAddSensors = flags & autoAddSensorFlag != 0;
|
_autoAddSensors = (flags & autoAddSensorFlag) != 0;
|
||||||
_overwriteOldest = flags & autoAddOverwriteOldestFlag != 0;
|
_overwriteOldest = (flags & autoAddOverwriteOldestFlag) != 0;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
appLogger.error('Failed to parse auto-add config: $e', tag: 'Connector');
|
appLogger.error('Failed to parse auto-add config: $e', tag: 'Connector');
|
||||||
}
|
}
|
||||||
@@ -4827,6 +4858,7 @@ class MeshCoreConnector extends ChangeNotifier {
|
|||||||
Contact contact,
|
Contact contact,
|
||||||
Uint8List rawPacket, {
|
Uint8List rawPacket, {
|
||||||
bool noNotify = false,
|
bool noNotify = false,
|
||||||
|
bool addActive = false,
|
||||||
}) {
|
}) {
|
||||||
appLogger.info('Discovered new contact: ${contact.name}', tag: 'Connector');
|
appLogger.info('Discovered new contact: ${contact.name}', tag: 'Connector');
|
||||||
|
|
||||||
@@ -4847,7 +4879,7 @@ class MeshCoreConnector extends ChangeNotifier {
|
|||||||
longitude: contact.longitude,
|
longitude: contact.longitude,
|
||||||
lastSeen: contact.lastSeen,
|
lastSeen: contact.lastSeen,
|
||||||
flags: 0,
|
flags: 0,
|
||||||
isActive: false,
|
isActive: addActive,
|
||||||
);
|
);
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
unawaited(_persistDiscoveredContacts());
|
unawaited(_persistDiscoveredContacts());
|
||||||
@@ -4865,7 +4897,7 @@ class MeshCoreConnector extends ChangeNotifier {
|
|||||||
longitude: contact.longitude,
|
longitude: contact.longitude,
|
||||||
lastSeen: contact.lastSeen,
|
lastSeen: contact.lastSeen,
|
||||||
lastMessageAt: contact.lastMessageAt,
|
lastMessageAt: contact.lastMessageAt,
|
||||||
isActive: false,
|
isActive: addActive,
|
||||||
flags: 0,
|
flags: 0,
|
||||||
);
|
);
|
||||||
_discoveredContacts.add(disContact);
|
_discoveredContacts.add(disContact);
|
||||||
|
|||||||
@@ -64,6 +64,8 @@ class MeshCoreUsbManager {
|
|||||||
|
|
||||||
Future<void> write(Uint8List data) => _service.write(data);
|
Future<void> write(Uint8List data) => _service.write(data);
|
||||||
|
|
||||||
|
Future<void> writeRaw(Uint8List data) => _service.writeRaw(data);
|
||||||
|
|
||||||
// --- Label management ---
|
// --- Label management ---
|
||||||
void updateConnectedLabel(String selfName) {
|
void updateConnectedLabel(String selfName) {
|
||||||
_service.updateConnectedLabel(selfName);
|
_service.updateConnectedLabel(selfName);
|
||||||
|
|||||||
@@ -40,6 +40,8 @@ class AppSettings {
|
|||||||
final UnitSystem unitSystem;
|
final UnitSystem unitSystem;
|
||||||
final Set<String> mutedChannels;
|
final Set<String> mutedChannels;
|
||||||
final bool mapShowDiscoveryContacts;
|
final bool mapShowDiscoveryContacts;
|
||||||
|
final String tcpServerAddress;
|
||||||
|
final int tcpServerPort;
|
||||||
|
|
||||||
AppSettings({
|
AppSettings({
|
||||||
this.clearPathOnMaxRetry = false,
|
this.clearPathOnMaxRetry = false,
|
||||||
@@ -68,6 +70,8 @@ class AppSettings {
|
|||||||
this.unitSystem = UnitSystem.metric,
|
this.unitSystem = UnitSystem.metric,
|
||||||
Set<String>? mutedChannels,
|
Set<String>? mutedChannels,
|
||||||
this.mapShowDiscoveryContacts = true,
|
this.mapShowDiscoveryContacts = true,
|
||||||
|
this.tcpServerAddress = '',
|
||||||
|
this.tcpServerPort = 0,
|
||||||
}) : batteryChemistryByDeviceId = batteryChemistryByDeviceId ?? {},
|
}) : batteryChemistryByDeviceId = batteryChemistryByDeviceId ?? {},
|
||||||
batteryChemistryByRepeaterId = batteryChemistryByRepeaterId ?? {},
|
batteryChemistryByRepeaterId = batteryChemistryByRepeaterId ?? {},
|
||||||
mutedChannels = mutedChannels ?? {};
|
mutedChannels = mutedChannels ?? {};
|
||||||
@@ -100,6 +104,8 @@ class AppSettings {
|
|||||||
'unit_system': unitSystem.value,
|
'unit_system': unitSystem.value,
|
||||||
'muted_channels': mutedChannels.toList(),
|
'muted_channels': mutedChannels.toList(),
|
||||||
'map_show_discovery_contacts': mapShowDiscoveryContacts,
|
'map_show_discovery_contacts': mapShowDiscoveryContacts,
|
||||||
|
'tcp_server_address': tcpServerAddress,
|
||||||
|
'tcp_server_port': tcpServerPort,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -157,6 +163,8 @@ class AppSettings {
|
|||||||
{},
|
{},
|
||||||
mapShowDiscoveryContacts:
|
mapShowDiscoveryContacts:
|
||||||
json['map_show_discovery_contacts'] as bool? ?? true,
|
json['map_show_discovery_contacts'] as bool? ?? true,
|
||||||
|
tcpServerAddress: json['tcp_server_address'] as String? ?? '',
|
||||||
|
tcpServerPort: json['tcp_server_port'] as int? ?? 0,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -187,6 +195,8 @@ class AppSettings {
|
|||||||
UnitSystem? unitSystem,
|
UnitSystem? unitSystem,
|
||||||
Set<String>? mutedChannels,
|
Set<String>? mutedChannels,
|
||||||
bool? mapShowDiscoveryContacts,
|
bool? mapShowDiscoveryContacts,
|
||||||
|
String? tcpServerAddress,
|
||||||
|
int? tcpServerPort,
|
||||||
}) {
|
}) {
|
||||||
return AppSettings(
|
return AppSettings(
|
||||||
clearPathOnMaxRetry: clearPathOnMaxRetry ?? this.clearPathOnMaxRetry,
|
clearPathOnMaxRetry: clearPathOnMaxRetry ?? this.clearPathOnMaxRetry,
|
||||||
@@ -225,6 +235,8 @@ class AppSettings {
|
|||||||
mutedChannels: mutedChannels ?? this.mutedChannels,
|
mutedChannels: mutedChannels ?? this.mutedChannels,
|
||||||
mapShowDiscoveryContacts:
|
mapShowDiscoveryContacts:
|
||||||
mapShowDiscoveryContacts ?? this.mapShowDiscoveryContacts,
|
mapShowDiscoveryContacts ?? this.mapShowDiscoveryContacts,
|
||||||
|
tcpServerAddress: tcpServerAddress ?? this.tcpServerAddress,
|
||||||
|
tcpServerPort: tcpServerPort ?? this.tcpServerPort,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+14
-39
@@ -65,7 +65,17 @@ class Contact {
|
|||||||
return '$pathLength hops';
|
return '$pathLength hops';
|
||||||
}
|
}
|
||||||
|
|
||||||
bool get hasLocation => latitude != null && longitude != null;
|
bool get hasLocation {
|
||||||
|
const double epsilon = 1e-6;
|
||||||
|
final lat = latitude ?? 0.0;
|
||||||
|
final lon = longitude ?? 0.0;
|
||||||
|
return (lat.abs() > epsilon || lon.abs() > epsilon) &&
|
||||||
|
lat >= -90.0 &&
|
||||||
|
lat <= 90.0 &&
|
||||||
|
lon >= -180.0 &&
|
||||||
|
lon <= 180.0;
|
||||||
|
}
|
||||||
|
|
||||||
bool get isFavorite => (flags & contactFlagFavorite) != 0;
|
bool get isFavorite => (flags & contactFlagFavorite) != 0;
|
||||||
|
|
||||||
Contact copyWith({
|
Contact copyWith({
|
||||||
@@ -108,7 +118,7 @@ class Contact {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String get pathIdList {
|
String get pathIdList {
|
||||||
final pathBytes = _pathBytesForDisplay;
|
final pathBytes = pathBytesForDisplay;
|
||||||
if (pathBytes.isEmpty) return '';
|
if (pathBytes.isEmpty) return '';
|
||||||
final parts = <String>[];
|
final parts = <String>[];
|
||||||
final groupSize = pathHashSize;
|
final groupSize = pathHashSize;
|
||||||
@@ -130,43 +140,7 @@ class Contact {
|
|||||||
return "<${publicKeyHex.substring(0, 8)}...${publicKeyHex.substring(publicKeyHex.length - 8)}>";
|
return "<${publicKeyHex.substring(0, 8)}...${publicKeyHex.substring(publicKeyHex.length - 8)}>";
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint8List? get traceRouteBytes {
|
Uint8List get pathBytesForDisplay {
|
||||||
final pathBytes = _pathBytesForDisplay;
|
|
||||||
Uint8List? traceBytes;
|
|
||||||
|
|
||||||
if (pathBytes.isEmpty) {
|
|
||||||
traceBytes = Uint8List(1);
|
|
||||||
traceBytes[0] = publicKey[0];
|
|
||||||
return traceBytes;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (type == advTypeRepeater || type == advTypeRoom) {
|
|
||||||
final len = (pathBytes.length + pathBytes.length + 1);
|
|
||||||
traceBytes = Uint8List(len);
|
|
||||||
traceBytes[pathBytes.length] = publicKey[0];
|
|
||||||
for (int i = 0; i < pathBytes.length; i++) {
|
|
||||||
traceBytes[i] = pathBytes[i];
|
|
||||||
if (i < pathBytes.length) {
|
|
||||||
traceBytes[len - 1 - i] = pathBytes[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (pathBytes.length < 2) {
|
|
||||||
return pathBytes[0] == 0 ? null : pathBytes;
|
|
||||||
}
|
|
||||||
final len = (pathBytes.length + pathBytes.length - 1);
|
|
||||||
traceBytes = Uint8List(len);
|
|
||||||
for (int i = 0; i < pathBytes.length; i++) {
|
|
||||||
traceBytes[i] = pathBytes[i];
|
|
||||||
if (i < pathBytes.length - 1) {
|
|
||||||
traceBytes[len - 1 - i] = pathBytes[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return traceBytes;
|
|
||||||
}
|
|
||||||
|
|
||||||
Uint8List get _pathBytesForDisplay {
|
|
||||||
if (pathOverride != null) {
|
if (pathOverride != null) {
|
||||||
if (pathOverride! < 0) return Uint8List(0);
|
if (pathOverride! < 0) return Uint8List(0);
|
||||||
return pathOverrideBytes ?? Uint8List(0);
|
return pathOverrideBytes ?? Uint8List(0);
|
||||||
@@ -197,6 +171,7 @@ class Contact {
|
|||||||
double? lat, lon;
|
double? lat, lon;
|
||||||
final latRaw = reader.readInt32LE();
|
final latRaw = reader.readInt32LE();
|
||||||
final lonRaw = reader.readInt32LE();
|
final lonRaw = reader.readInt32LE();
|
||||||
|
|
||||||
if (latRaw != 0 || lonRaw != 0) {
|
if (latRaw != 0 || lonRaw != 0) {
|
||||||
lat = latRaw / 1e6;
|
lat = latRaw / 1e6;
|
||||||
lon = lonRaw / 1e6;
|
lon = lonRaw / 1e6;
|
||||||
|
|||||||
@@ -40,10 +40,7 @@ class ChannelMessagePathScreen extends StatelessWidget {
|
|||||||
final primaryPath = !channelMessage && !message.isOutgoing
|
final primaryPath = !channelMessage && !message.isOutgoing
|
||||||
? Uint8List.fromList(primaryPathTmp.reversed.toList())
|
? Uint8List.fromList(primaryPathTmp.reversed.toList())
|
||||||
: primaryPathTmp;
|
: primaryPathTmp;
|
||||||
final contacts = <Contact>[
|
final contacts = connector.allContacts;
|
||||||
...connector.contacts,
|
|
||||||
...connector.discoveredContacts,
|
|
||||||
];
|
|
||||||
final hops = _buildPathHops(primaryPath, contacts, l10n);
|
final hops = _buildPathHops(primaryPath, contacts, l10n);
|
||||||
final hasHopDetails = primaryPath.isNotEmpty;
|
final hasHopDetails = primaryPath.isNotEmpty;
|
||||||
final observedLabel = _formatObservedHops(
|
final observedLabel = _formatObservedHops(
|
||||||
@@ -65,8 +62,9 @@ class ChannelMessagePathScreen extends StatelessWidget {
|
|||||||
builder: (context) => PathTraceMapScreen(
|
builder: (context) => PathTraceMapScreen(
|
||||||
title: context.l10n.contacts_repeaterPathTrace,
|
title: context.l10n.contacts_repeaterPathTrace,
|
||||||
path: primaryPath,
|
path: primaryPath,
|
||||||
flipPathRound: true,
|
flipPathAround: true,
|
||||||
reversePathRound: !message.isOutgoing && !channelMessage,
|
reversePathAround:
|
||||||
|
!(!channelMessage && !message.isOutgoing),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -367,10 +365,7 @@ class _ChannelMessagePathMapScreenState
|
|||||||
: selectedPathTmp;
|
: selectedPathTmp;
|
||||||
|
|
||||||
final selectedIndex = _indexForPath(selectedPath, observedPaths);
|
final selectedIndex = _indexForPath(selectedPath, observedPaths);
|
||||||
final contacts = <Contact>[
|
final contacts = connector.allContacts;
|
||||||
...connector.contacts,
|
|
||||||
...connector.discoveredContacts,
|
|
||||||
];
|
|
||||||
final hops = _buildPathHops(selectedPath, contacts, context.l10n);
|
final hops = _buildPathHops(selectedPath, contacts, context.l10n);
|
||||||
|
|
||||||
final points = <LatLng>[];
|
final points = <LatLng>[];
|
||||||
|
|||||||
@@ -858,7 +858,7 @@ class _ChatScreenState extends State<ChatScreen> {
|
|||||||
builder: (context) => PathTraceMapScreen(
|
builder: (context) => PathTraceMapScreen(
|
||||||
title: context.l10n.contacts_repeaterPathTrace,
|
title: context.l10n.contacts_repeaterPathTrace,
|
||||||
path: Uint8List.fromList(pathBytes),
|
path: Uint8List.fromList(pathBytes),
|
||||||
flipPathRound: true,
|
flipPathAround: true,
|
||||||
targetContact: widget.contact,
|
targetContact: widget.contact,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -1027,7 +1027,7 @@ class _ChatScreenState extends State<ChatScreen> {
|
|||||||
final currentPathLabel = _currentPathLabel(currentContact);
|
final currentPathLabel = _currentPathLabel(currentContact);
|
||||||
|
|
||||||
// Filter out the current contact from available contacts
|
// Filter out the current contact from available contacts
|
||||||
final availableContacts = connector.contacts
|
final availableContacts = connector.allContacts
|
||||||
.where((c) => c != widget.contact)
|
.where((c) => c != widget.contact)
|
||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
|
|||||||
@@ -1064,7 +1064,7 @@ class _ContactsScreenState extends State<ContactsScreen>
|
|||||||
if (isRepeater) ...[
|
if (isRepeater) ...[
|
||||||
ListTile(
|
ListTile(
|
||||||
leading: const Icon(Icons.radar, color: Colors.green),
|
leading: const Icon(Icons.radar, color: Colors.green),
|
||||||
title: contact.pathLength > 0
|
title: contact.pathBytesForDisplay.isNotEmpty
|
||||||
? Text(context.l10n.contacts_pathTrace)
|
? Text(context.l10n.contacts_pathTrace)
|
||||||
: Text(context.l10n.contacts_ping),
|
: Text(context.l10n.contacts_ping),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
@@ -1072,10 +1072,12 @@ class _ContactsScreenState extends State<ContactsScreen>
|
|||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
builder: (context) => PathTraceMapScreen(
|
builder: (context) => PathTraceMapScreen(
|
||||||
title: contact.pathLength > 0
|
title: contact.pathBytesForDisplay.isNotEmpty
|
||||||
? context.l10n.contacts_repeaterPathTrace
|
? context.l10n.contacts_repeaterPathTrace
|
||||||
: context.l10n.contacts_repeaterPing,
|
: context.l10n.contacts_repeaterPing,
|
||||||
path: contact.traceRouteBytes ?? Uint8List(0),
|
path: contact.pathBytesForDisplay,
|
||||||
|
flipPathAround: true,
|
||||||
|
targetContact: contact,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@@ -1100,10 +1102,12 @@ class _ContactsScreenState extends State<ContactsScreen>
|
|||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
builder: (context) => PathTraceMapScreen(
|
builder: (context) => PathTraceMapScreen(
|
||||||
title: contact.pathLength > 0
|
title: contact.pathBytesForDisplay.isNotEmpty
|
||||||
? context.l10n.contacts_roomPathTrace
|
? context.l10n.contacts_roomPathTrace
|
||||||
: context.l10n.contacts_roomPing,
|
: context.l10n.contacts_roomPing,
|
||||||
path: contact.traceRouteBytes ?? Uint8List(0),
|
path: contact.pathBytesForDisplay,
|
||||||
|
flipPathAround: contact.pathBytesForDisplay.isNotEmpty,
|
||||||
|
targetContact: contact,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@@ -1145,7 +1149,8 @@ class _ContactsScreenState extends State<ContactsScreen>
|
|||||||
title: context.l10n.contacts_pathTraceTo(
|
title: context.l10n.contacts_pathTraceTo(
|
||||||
contact.name,
|
contact.name,
|
||||||
),
|
),
|
||||||
path: contact.traceRouteBytes ?? Uint8List(0),
|
path: contact.pathBytesForDisplay,
|
||||||
|
flipPathAround: true,
|
||||||
targetContact: contact,
|
targetContact: contact,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -137,10 +137,7 @@ class _MapScreenState extends State<MapScreen> {
|
|||||||
builder: (context, connector, settingsService, pathHistory, child) {
|
builder: (context, connector, settingsService, pathHistory, child) {
|
||||||
final tileCache = context.read<MapTileCacheService>();
|
final tileCache = context.read<MapTileCacheService>();
|
||||||
final settings = settingsService.settings;
|
final settings = settingsService.settings;
|
||||||
final allContacts = <Contact>[
|
final allContacts = connector.allContacts;
|
||||||
...connector.contacts,
|
|
||||||
...connector.discoveredContacts.where((c) => !c.isActive),
|
|
||||||
];
|
|
||||||
|
|
||||||
final contacts = settings.mapShowDiscoveryContacts
|
final contacts = settings.mapShowDiscoveryContacts
|
||||||
? allContacts
|
? allContacts
|
||||||
@@ -179,20 +176,13 @@ class _MapScreenState extends State<MapScreen> {
|
|||||||
|
|
||||||
// Filter by location
|
// Filter by location
|
||||||
final contactsWithLocation = filteredByKeyPrefix.where((c) {
|
final contactsWithLocation = filteredByKeyPrefix.where((c) {
|
||||||
if (!c.hasLocation) {
|
return c.hasLocation;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return _checkLocationPlausibility(c.latitude!, c.longitude!);
|
|
||||||
}).toList();
|
}).toList();
|
||||||
|
|
||||||
// All contacts with a known location — used as anchors regardless of
|
// All contacts with a known location — used as anchors regardless of
|
||||||
// time/key-prefix filters so that repeaters are always available.
|
// time/key-prefix filters so that repeaters are always available.
|
||||||
final allContactsWithLocation = allContacts
|
final allContactsWithLocation = allContacts
|
||||||
.where(
|
.where((c) => c.hasLocation)
|
||||||
(c) =>
|
|
||||||
c.hasLocation &&
|
|
||||||
_checkLocationPlausibility(c.latitude!, c.longitude!),
|
|
||||||
)
|
|
||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
// Compute guessed locations with caching
|
// Compute guessed locations with caching
|
||||||
|
|||||||
@@ -124,10 +124,7 @@ class _NeighborsScreenState extends State<NeighborsScreen> {
|
|||||||
|
|
||||||
void _handleNeighborsResponse(MeshCoreConnector connector, Uint8List frame) {
|
void _handleNeighborsResponse(MeshCoreConnector connector, Uint8List frame) {
|
||||||
final buffer = BufferReader(frame);
|
final buffer = BufferReader(frame);
|
||||||
final contacts = <Contact>[
|
final contacts = connector.allContacts;
|
||||||
...connector.contacts,
|
|
||||||
...connector.discoveredContacts,
|
|
||||||
];
|
|
||||||
try {
|
try {
|
||||||
final neighborCount = buffer.readUInt16LE();
|
final neighborCount = buffer.readUInt16LE();
|
||||||
final parsedNeighbors = parseNeighborsData(buffer, buffer.readUInt16LE());
|
final parsedNeighbors = parseNeighborsData(buffer, buffer.readUInt16LE());
|
||||||
|
|||||||
@@ -52,8 +52,8 @@ class PathTraceMapScreen extends StatefulWidget {
|
|||||||
final String title;
|
final String title;
|
||||||
final Uint8List path;
|
final Uint8List path;
|
||||||
final int? repeaterId;
|
final int? repeaterId;
|
||||||
final bool flipPathRound;
|
final bool flipPathAround;
|
||||||
final bool reversePathRound;
|
final bool reversePathAround;
|
||||||
final Contact? targetContact;
|
final Contact? targetContact;
|
||||||
|
|
||||||
const PathTraceMapScreen({
|
const PathTraceMapScreen({
|
||||||
@@ -61,8 +61,8 @@ class PathTraceMapScreen extends StatefulWidget {
|
|||||||
required this.title,
|
required this.title,
|
||||||
required this.path,
|
required this.path,
|
||||||
this.repeaterId,
|
this.repeaterId,
|
||||||
this.flipPathRound = false,
|
this.flipPathAround = false,
|
||||||
this.reversePathRound = false,
|
this.reversePathAround = false,
|
||||||
this.targetContact,
|
this.targetContact,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -93,6 +93,7 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen> {
|
|||||||
ValueKey<String> _mapKey = const ValueKey('initial');
|
ValueKey<String> _mapKey = const ValueKey('initial');
|
||||||
double _pathDistanceMeters = 0.0;
|
double _pathDistanceMeters = 0.0;
|
||||||
bool _showNodeLabels = true;
|
bool _showNodeLabels = true;
|
||||||
|
Contact? _targetContact;
|
||||||
|
|
||||||
String _formatPathPrefixes(Uint8List pathBytes) {
|
String _formatPathPrefixes(Uint8List pathBytes) {
|
||||||
return pathBytes
|
return pathBytes
|
||||||
@@ -158,21 +159,16 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
final Uint8List path;
|
final pathTmp = widget.reversePathAround
|
||||||
|
|
||||||
Uint8List pathTmp = widget.reversePathRound
|
|
||||||
? Uint8List.fromList(widget.path.reversed.toList())
|
? Uint8List.fromList(widget.path.reversed.toList())
|
||||||
: widget.path;
|
: widget.path;
|
||||||
|
|
||||||
if (widget.flipPathRound) {
|
final path = widget.flipPathAround ? buildPath(pathTmp) : pathTmp;
|
||||||
path = buildPath(pathTmp);
|
|
||||||
} else {
|
|
||||||
path = pathTmp;
|
|
||||||
}
|
|
||||||
|
|
||||||
appLogger.info(
|
appLogger.info(
|
||||||
'Initiating path trace with path: ${_formatPathPrefixes(path)}',
|
'Initiating path trace with path: ${_formatPathPrefixes(path)}',
|
||||||
tag: 'PathTraceMapScreen',
|
tag: 'PathTraceMapScreen',
|
||||||
|
noNotify: !mounted,
|
||||||
);
|
);
|
||||||
|
|
||||||
final connector = Provider.of<MeshCoreConnector>(context, listen: false);
|
final connector = Provider.of<MeshCoreConnector>(context, listen: false);
|
||||||
@@ -263,10 +259,7 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen> {
|
|||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
Map<int, Contact> pathContacts = {};
|
Map<int, Contact> pathContacts = {};
|
||||||
final contacts = <Contact>[
|
final contacts = connector.allContacts;
|
||||||
...connector.contacts,
|
|
||||||
...connector.discoveredContacts,
|
|
||||||
];
|
|
||||||
contacts.where((c) => c.type != advTypeChat).forEach((repeater) {
|
contacts.where((c) => c.type != advTypeChat).forEach((repeater) {
|
||||||
for (var repeaterData in pathData) {
|
for (var repeaterData in pathData) {
|
||||||
if (listEquals(
|
if (listEquals(
|
||||||
@@ -312,18 +305,21 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen> {
|
|||||||
// Compute endpoint position for the target contact.
|
// Compute endpoint position for the target contact.
|
||||||
LatLng? targetPos;
|
LatLng? targetPos;
|
||||||
bool targetGuessed = false;
|
bool targetGuessed = false;
|
||||||
final target = widget.targetContact;
|
_targetContact = widget.targetContact;
|
||||||
if (target != null) {
|
|
||||||
if (target.hasLocation) {
|
if (_targetContact != null) {
|
||||||
targetPos = LatLng(target.latitude!, target.longitude!);
|
final tc = _targetContact!;
|
||||||
} else if (pathData.isNotEmpty) {
|
if (tc.hasLocation) {
|
||||||
|
targetPos = LatLng(tc.latitude!, tc.longitude!);
|
||||||
|
} else if (widget.path.length > 1) {
|
||||||
// Infer from the last hop: average GPS contacts sharing that hop.
|
// Infer from the last hop: average GPS contacts sharing that hop.
|
||||||
// For a round-trip path (flipPathRound), the target-side hop sits
|
// For a round-trip path (flipPathAround/reversePathAround), the target-side hop
|
||||||
// in the middle of the symmetric sequence; .last is the local side.
|
// sits in the middle of the symmetric sequence; .last is the local side.
|
||||||
final lastHop = (widget.flipPathRound && pathData.length > 1)
|
final lastHop = widget.reversePathAround
|
||||||
? pathData[(pathData.length - 1) ~/ 2]
|
? widget.path.first
|
||||||
: pathData.last;
|
: widget.path.last;
|
||||||
final peers = connector.contacts
|
|
||||||
|
final peers = connector.allContacts
|
||||||
.where(
|
.where(
|
||||||
(c) =>
|
(c) =>
|
||||||
c.hasLocation &&
|
c.hasLocation &&
|
||||||
@@ -339,12 +335,34 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen> {
|
|||||||
peers.map((c) => c.longitude!).reduce((a, b) => a + b) /
|
peers.map((c) => c.longitude!).reduce((a, b) => a + b) /
|
||||||
peers.length;
|
peers.length;
|
||||||
const offsetDeg = 0.003;
|
const offsetDeg = 0.003;
|
||||||
final angle = (target.publicKey[1] / 255.0) * 2 * pi;
|
final angle = (tc.publicKey[1] / 255.0) * 2 * pi;
|
||||||
targetPos = LatLng(
|
targetPos = LatLng(
|
||||||
lat + offsetDeg * cos(angle),
|
lat + offsetDeg * cos(angle),
|
||||||
lon + offsetDeg * sin(angle),
|
lon + offsetDeg * sin(angle),
|
||||||
);
|
);
|
||||||
targetGuessed = true;
|
targetGuessed = true;
|
||||||
|
} else if (inferredPositions.containsKey(lastHop)) {
|
||||||
|
final lat = inferredPositions[lastHop]!.latitude;
|
||||||
|
final lon = inferredPositions[lastHop]!.longitude;
|
||||||
|
const offsetDeg = 0.003;
|
||||||
|
final angle = (tc.publicKey[1] / 255.0) * 2 * pi;
|
||||||
|
targetPos = LatLng(
|
||||||
|
lat + offsetDeg * cos(angle),
|
||||||
|
lon + offsetDeg * sin(angle),
|
||||||
|
);
|
||||||
|
targetGuessed = true;
|
||||||
|
} else {
|
||||||
|
// As a last resort, just place it at the same position as the last hop.
|
||||||
|
final contact = pathContacts[lastHop];
|
||||||
|
if (contact != null && contact.hasLocation) {
|
||||||
|
const offsetDeg = 0.003;
|
||||||
|
final angle = (tc.publicKey[1] / 255.0) * 2 * pi;
|
||||||
|
targetPos = LatLng(
|
||||||
|
contact.latitude! + offsetDeg * cos(angle),
|
||||||
|
contact.longitude! + offsetDeg * sin(angle),
|
||||||
|
);
|
||||||
|
targetGuessed = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -353,7 +371,12 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen> {
|
|||||||
|
|
||||||
_points = <LatLng>[];
|
_points = <LatLng>[];
|
||||||
_points.add(LatLng(connector.selfLatitude!, connector.selfLongitude!));
|
_points.add(LatLng(connector.selfLatitude!, connector.selfLongitude!));
|
||||||
|
int hopLast = 0;
|
||||||
|
int hopLastLast = 0;
|
||||||
for (final hop in _traceData!.pathData) {
|
for (final hop in _traceData!.pathData) {
|
||||||
|
if (hop == hopLastLast && widget.flipPathAround) {
|
||||||
|
break; //skip duplicate hops in round-trip paths
|
||||||
|
}
|
||||||
final contact = _traceData!.pathContacts[hop];
|
final contact = _traceData!.pathContacts[hop];
|
||||||
if (contact != null && contact.hasLocation) {
|
if (contact != null && contact.hasLocation) {
|
||||||
_points.add(LatLng(contact.latitude!, contact.longitude!));
|
_points.add(LatLng(contact.latitude!, contact.longitude!));
|
||||||
@@ -361,8 +384,14 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen> {
|
|||||||
final inferred = inferredPositions[hop];
|
final inferred = inferredPositions[hop];
|
||||||
if (inferred != null) _points.add(inferred);
|
if (inferred != null) _points.add(inferred);
|
||||||
}
|
}
|
||||||
|
hopLastLast = hopLast;
|
||||||
|
hopLast = hop;
|
||||||
|
}
|
||||||
|
if (targetPos != null) {
|
||||||
|
if (_targetContact != null && _targetContact!.type == advTypeChat) {
|
||||||
|
_points.add(targetPos);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (targetPos != null) _points.add(targetPos);
|
|
||||||
_polylines = _points.length > 1
|
_polylines = _points.length > 1
|
||||||
? [
|
? [
|
||||||
Polyline(
|
Polyline(
|
||||||
@@ -451,7 +480,8 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen> {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
if (_hasData) _buildMapPathTrace(context, tileCache),
|
if (_hasData)
|
||||||
|
_buildMapPathTrace(context, tileCache, _targetContact),
|
||||||
if (_points.isEmpty &&
|
if (_points.isEmpty &&
|
||||||
!_hasData &&
|
!_hasData &&
|
||||||
!_isLoading &&
|
!_isLoading &&
|
||||||
@@ -480,17 +510,28 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen> {
|
|||||||
List<Marker> _buildHopMarkers(
|
List<Marker> _buildHopMarkers(
|
||||||
List<int> pathData, {
|
List<int> pathData, {
|
||||||
required bool showLabels,
|
required bool showLabels,
|
||||||
|
required Contact? target,
|
||||||
}) {
|
}) {
|
||||||
final markers = <Marker>[];
|
final markers = <Marker>[];
|
||||||
|
int hopLast = 0;
|
||||||
|
int hopLastLast = 0;
|
||||||
for (final hop in pathData) {
|
for (final hop in pathData) {
|
||||||
final contact = _traceData!.pathContacts[hop];
|
final contact = _traceData!.pathContacts[hop];
|
||||||
final inferred = _inferredHopPositions[hop];
|
final inferred = _inferredHopPositions[hop];
|
||||||
final hasGps = contact != null && contact.hasLocation;
|
final hasGps = contact != null && contact.hasLocation;
|
||||||
if (!hasGps && inferred == null) continue;
|
if (hop == hopLastLast && widget.flipPathAround) {
|
||||||
|
continue; //skip duplicate hops in round-trip paths
|
||||||
|
}
|
||||||
|
if (!hasGps && inferred == null) {
|
||||||
|
hopLastLast = hopLast;
|
||||||
|
hopLast = hop;
|
||||||
|
continue; //skip hops with no GPS and no inferred position
|
||||||
|
}
|
||||||
final point = hasGps
|
final point = hasGps
|
||||||
? LatLng(contact.latitude!, contact.longitude!)
|
? LatLng(contact.latitude!, contact.longitude!)
|
||||||
: inferred!;
|
: inferred!;
|
||||||
final label = hop.toRadixString(16).padLeft(2, '0').toUpperCase();
|
final label = hop.toRadixString(16).padLeft(2, '0').toUpperCase();
|
||||||
|
|
||||||
markers.add(
|
markers.add(
|
||||||
Marker(
|
Marker(
|
||||||
point: point,
|
point: point,
|
||||||
@@ -532,6 +573,8 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen> {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
hopLastLast = hopLast;
|
||||||
|
hopLast = hop;
|
||||||
}
|
}
|
||||||
|
|
||||||
final selfLat = context.read<MeshCoreConnector>().selfLatitude;
|
final selfLat = context.read<MeshCoreConnector>().selfLatitude;
|
||||||
@@ -581,9 +624,9 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen> {
|
|||||||
|
|
||||||
// Add target contact endpoint marker.
|
// Add target contact endpoint marker.
|
||||||
final targetPos = _targetContactPosition;
|
final targetPos = _targetContactPosition;
|
||||||
if (targetPos != null) {
|
if (targetPos != null && target != null && target.type == advTypeChat) {
|
||||||
final isGuessed = _targetContactIsGuessed;
|
final isGuessed = _targetContactIsGuessed;
|
||||||
final targetName = widget.targetContact?.name ?? '?';
|
final targetName = target.name;
|
||||||
markers.add(
|
markers.add(
|
||||||
Marker(
|
Marker(
|
||||||
point: targetPos,
|
point: targetPos,
|
||||||
@@ -719,6 +762,7 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen> {
|
|||||||
Widget _buildMapPathTrace(
|
Widget _buildMapPathTrace(
|
||||||
BuildContext context,
|
BuildContext context,
|
||||||
MapTileCacheService tileCache,
|
MapTileCacheService tileCache,
|
||||||
|
Contact? target,
|
||||||
) {
|
) {
|
||||||
return FlutterMap(
|
return FlutterMap(
|
||||||
key: _mapKey,
|
key: _mapKey,
|
||||||
@@ -757,6 +801,7 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen> {
|
|||||||
markers: _buildHopMarkers(
|
markers: _buildHopMarkers(
|
||||||
_traceData!.pathData,
|
_traceData!.pathData,
|
||||||
showLabels: _showNodeLabels,
|
showLabels: _showNodeLabels,
|
||||||
|
target: target,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import 'package:provider/provider.dart';
|
|||||||
|
|
||||||
import '../connector/meshcore_connector.dart';
|
import '../connector/meshcore_connector.dart';
|
||||||
import '../l10n/l10n.dart';
|
import '../l10n/l10n.dart';
|
||||||
|
import '../services/app_settings_service.dart';
|
||||||
import '../utils/platform_info.dart';
|
import '../utils/platform_info.dart';
|
||||||
import '../widgets/adaptive_app_bar_title.dart';
|
import '../widgets/adaptive_app_bar_title.dart';
|
||||||
import 'contacts_screen.dart';
|
import 'contacts_screen.dart';
|
||||||
@@ -27,8 +28,14 @@ class _TcpScreenState extends State<TcpScreen> {
|
|||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
_hostController = TextEditingController();
|
_hostController = TextEditingController(
|
||||||
_portController = TextEditingController(text: '5000');
|
text: context.read<AppSettingsService>().settings.tcpServerAddress,
|
||||||
|
);
|
||||||
|
_portController = TextEditingController(
|
||||||
|
text: context.read<AppSettingsService>().settings.tcpServerPort > 0
|
||||||
|
? context.read<AppSettingsService>().settings.tcpServerPort.toString()
|
||||||
|
: '',
|
||||||
|
);
|
||||||
_connector = context.read<MeshCoreConnector>();
|
_connector = context.read<MeshCoreConnector>();
|
||||||
|
|
||||||
_connectionListener = () {
|
_connectionListener = () {
|
||||||
@@ -39,6 +46,12 @@ class _TcpScreenState extends State<TcpScreen> {
|
|||||||
if (_connector.state == MeshCoreConnectionState.connected &&
|
if (_connector.state == MeshCoreConnectionState.connected &&
|
||||||
_connector.isTcpTransportConnected &&
|
_connector.isTcpTransportConnected &&
|
||||||
!_navigatedToContacts) {
|
!_navigatedToContacts) {
|
||||||
|
context.read<AppSettingsService>().setTcpServerAddress(
|
||||||
|
_hostController.text,
|
||||||
|
);
|
||||||
|
context.read<AppSettingsService>().setTcpServerPort(
|
||||||
|
int.tryParse(_portController.text) ?? 0,
|
||||||
|
);
|
||||||
_navigatedToContacts = true;
|
_navigatedToContacts = true;
|
||||||
Navigator.of(context).pushReplacement(
|
Navigator.of(context).pushReplacement(
|
||||||
MaterialPageRoute(builder: (_) => const ContactsScreen()),
|
MaterialPageRoute(builder: (_) => const ContactsScreen()),
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ class AppDebugLogService extends ChangeNotifier {
|
|||||||
String message, {
|
String message, {
|
||||||
String tag = 'App',
|
String tag = 'App',
|
||||||
AppDebugLogLevel level = AppDebugLogLevel.info,
|
AppDebugLogLevel level = AppDebugLogLevel.info,
|
||||||
|
bool noNotify = false,
|
||||||
}) {
|
}) {
|
||||||
if (!_enabled && !kDebugMode) return;
|
if (!_enabled && !kDebugMode) return;
|
||||||
if (!_enabled) {
|
if (!_enabled) {
|
||||||
@@ -72,22 +73,24 @@ class AppDebugLogService extends ChangeNotifier {
|
|||||||
_entries.removeRange(0, _entries.length - maxEntries);
|
_entries.removeRange(0, _entries.length - maxEntries);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!noNotify) {
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
|
}
|
||||||
|
|
||||||
// Also print to console for development
|
// Also print to console for development
|
||||||
debugPrint('[$tag] $message');
|
debugPrint('[$tag] $message');
|
||||||
}
|
}
|
||||||
|
|
||||||
void info(String message, {String tag = 'App'}) {
|
void info(String message, {String tag = 'App', bool noNotify = false}) {
|
||||||
log(message, tag: tag, level: AppDebugLogLevel.info);
|
log(message, tag: tag, level: AppDebugLogLevel.info, noNotify: noNotify);
|
||||||
}
|
}
|
||||||
|
|
||||||
void warn(String message, {String tag = 'App'}) {
|
void warn(String message, {String tag = 'App', bool noNotify = false}) {
|
||||||
log(message, tag: tag, level: AppDebugLogLevel.warning);
|
log(message, tag: tag, level: AppDebugLogLevel.warning, noNotify: noNotify);
|
||||||
}
|
}
|
||||||
|
|
||||||
void error(String message, {String tag = 'App'}) {
|
void error(String message, {String tag = 'App', bool noNotify = false}) {
|
||||||
log(message, tag: tag, level: AppDebugLogLevel.error);
|
log(message, tag: tag, level: AppDebugLogLevel.error, noNotify: noNotify);
|
||||||
}
|
}
|
||||||
|
|
||||||
void clear() {
|
void clear() {
|
||||||
|
|||||||
@@ -182,4 +182,12 @@ class AppSettingsService extends ChangeNotifier {
|
|||||||
..remove(channelName);
|
..remove(channelName);
|
||||||
await updateSettings(_settings.copyWith(mutedChannels: updated));
|
await updateSettings(_settings.copyWith(mutedChannels: updated));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> setTcpServerAddress(String value) async {
|
||||||
|
await updateSettings(_settings.copyWith(tcpServerAddress: value));
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> setTcpServerPort(int value) async {
|
||||||
|
await updateSettings(_settings.copyWith(tcpServerPort: value));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -189,6 +189,10 @@ class UsbSerialService {
|
|||||||
serial.setStopBits1();
|
serial.setStopBits1();
|
||||||
serial.setFlowControlNone();
|
serial.setFlowControlNone();
|
||||||
serial.setRTS(false);
|
serial.setRTS(false);
|
||||||
|
// Toggle DTR low→high so the device sees a fresh connection even
|
||||||
|
// if the previous disconnect didn't cleanly signal DTR drop.
|
||||||
|
serial.setDTR(false);
|
||||||
|
await Future<void>.delayed(const Duration(milliseconds: 50));
|
||||||
serial.setDTR(true);
|
serial.setDTR(true);
|
||||||
_serial = serial;
|
_serial = serial;
|
||||||
// Update the normalized port name to whichever candidate succeeded.
|
// Update the normalized port name to whichever candidate succeeded.
|
||||||
@@ -249,6 +253,21 @@ class UsbSerialService {
|
|||||||
_status = UsbSerialStatus.connected;
|
_status = UsbSerialStatus.connected;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> writeRaw(Uint8List data) async {
|
||||||
|
if (!isConnected) {
|
||||||
|
throw StateError('USB serial port is not open');
|
||||||
|
}
|
||||||
|
if (_useAndroidUsbHost) {
|
||||||
|
try {
|
||||||
|
await _androidMethodChannel.invokeMethod<void>('write', {'data': data});
|
||||||
|
} on PlatformException catch (error) {
|
||||||
|
throw StateError(error.message ?? error.code);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
_serial!.write(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> write(Uint8List data) async {
|
Future<void> write(Uint8List data) async {
|
||||||
if (!isConnected) {
|
if (!isConnected) {
|
||||||
throw StateError('USB serial port is not open');
|
throw StateError('USB serial port is not open');
|
||||||
@@ -300,6 +319,7 @@ class UsbSerialService {
|
|||||||
_serial = null;
|
_serial = null;
|
||||||
try {
|
try {
|
||||||
if (serial?.isOpen() == FlOpenStatus.open) {
|
if (serial?.isOpen() == FlOpenStatus.open) {
|
||||||
|
serial?.setDTR(false);
|
||||||
serial?.closePort();
|
serial?.closePort();
|
||||||
}
|
}
|
||||||
} catch (_) {
|
} catch (_) {
|
||||||
@@ -350,6 +370,7 @@ class UsbSerialService {
|
|||||||
final serial = _serial;
|
final serial = _serial;
|
||||||
try {
|
try {
|
||||||
if (serial?.isOpen() == FlOpenStatus.open) {
|
if (serial?.isOpen() == FlOpenStatus.open) {
|
||||||
|
serial?.setDTR(false);
|
||||||
serial?.closePort(); // synchronous C call — kills the SerialThread
|
serial?.closePort(); // synchronous C call — kills the SerialThread
|
||||||
}
|
}
|
||||||
} catch (_) {}
|
} catch (_) {}
|
||||||
|
|||||||
@@ -127,6 +127,17 @@ class UsbSerialService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> writeRaw(Uint8List data) async {
|
||||||
|
if (!isConnected || _writer == null) {
|
||||||
|
throw StateError('USB serial port is not open');
|
||||||
|
}
|
||||||
|
final promise = _writer!.callMethod<JSPromise<JSAny?>>(
|
||||||
|
'write'.toJS,
|
||||||
|
data.toJS,
|
||||||
|
);
|
||||||
|
await promise.toDart;
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> write(Uint8List data) async {
|
Future<void> write(Uint8List data) async {
|
||||||
if (!isConnected || _writer == null) {
|
if (!isConnected || _writer == null) {
|
||||||
throw StateError('USB serial port is not open');
|
throw StateError('USB serial port is not open');
|
||||||
|
|||||||
@@ -23,23 +23,23 @@ class AppLogger {
|
|||||||
bool get isEnabled => _enabled;
|
bool get isEnabled => _enabled;
|
||||||
|
|
||||||
/// Log an info message
|
/// Log an info message
|
||||||
void info(String message, {String tag = 'App'}) {
|
void info(String message, {String tag = 'App', bool noNotify = false}) {
|
||||||
if (_enabled && _service != null) {
|
if (_enabled && _service != null) {
|
||||||
_service!.info(message, tag: tag);
|
_service!.info(message, tag: tag, noNotify: noNotify);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Log a warning message
|
/// Log a warning message
|
||||||
void warn(String message, {String tag = 'App'}) {
|
void warn(String message, {String tag = 'App', bool noNotify = false}) {
|
||||||
if (_enabled && _service != null) {
|
if (_enabled && _service != null) {
|
||||||
_service!.warn(message, tag: tag);
|
_service!.warn(message, tag: tag, noNotify: noNotify);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Log an error message
|
/// Log an error message
|
||||||
void error(String message, {String tag = 'App'}) {
|
void error(String message, {String tag = 'App', bool noNotify = false}) {
|
||||||
if (_enabled && _service != null) {
|
if (_enabled && _service != null) {
|
||||||
_service!.error(message, tag: tag);
|
_service!.error(message, tag: tag, noNotify: noNotify);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,9 +48,10 @@ class AppLogger {
|
|||||||
String message, {
|
String message, {
|
||||||
String tag = 'App',
|
String tag = 'App',
|
||||||
AppDebugLogLevel level = AppDebugLogLevel.info,
|
AppDebugLogLevel level = AppDebugLogLevel.info,
|
||||||
|
bool noNotify = false,
|
||||||
}) {
|
}) {
|
||||||
if (_enabled && _service != null) {
|
if (_enabled && _service != null) {
|
||||||
_service!.log(message, tag: tag, level: level);
|
_service!.log(message, tag: tag, level: level, noNotify: noNotify);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ class _PathManagementDialogState extends State<_PathManagementDialog> {
|
|||||||
builder: (context) => PathTraceMapScreen(
|
builder: (context) => PathTraceMapScreen(
|
||||||
title: context.l10n.contacts_repeaterPathTrace,
|
title: context.l10n.contacts_repeaterPathTrace,
|
||||||
path: Uint8List.fromList(pathBytes),
|
path: Uint8List.fromList(pathBytes),
|
||||||
flipPathRound: true,
|
flipPathAround: true,
|
||||||
targetContact: widget.contact,
|
targetContact: widget.contact,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -107,7 +107,7 @@ class _PathManagementDialogState extends State<_PathManagementDialog> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final pathForInput = currentContact.pathIdList;
|
final pathForInput = currentContact.pathIdList;
|
||||||
final availableContacts = connector.contacts
|
final availableContacts = connector.allContacts
|
||||||
.where((c) => c.publicKeyHex != currentContact.publicKeyHex)
|
.where((c) => c.publicKeyHex != currentContact.publicKeyHex)
|
||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import 'dart:typed_data';
|
import 'dart:typed_data';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:meshcore_open/connector/meshcore_protocol.dart';
|
||||||
import '../l10n/l10n.dart';
|
import '../l10n/l10n.dart';
|
||||||
import '../models/contact.dart';
|
import '../models/contact.dart';
|
||||||
|
|
||||||
@@ -65,7 +66,7 @@ class _PathSelectionDialogState extends State<PathSelectionDialog> {
|
|||||||
|
|
||||||
void _filterValidContacts() {
|
void _filterValidContacts() {
|
||||||
_validContacts = widget.availableContacts
|
_validContacts = widget.availableContacts
|
||||||
.where((c) => c.type == 2 || c.type == 3)
|
.where((c) => c.type == advTypeRepeater || c.type == advTypeRoom)
|
||||||
.toList();
|
.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -157,10 +157,7 @@ class _SNRIndicatorState extends State<SNRIndicator> {
|
|||||||
repeater.snr,
|
repeater.snr,
|
||||||
widget.connector.currentSf,
|
widget.connector.currentSf,
|
||||||
);
|
);
|
||||||
final allContacts = [
|
final allContacts = widget.connector.allContacts;
|
||||||
...widget.connector.contacts,
|
|
||||||
...widget.connector.discoveredContacts,
|
|
||||||
];
|
|
||||||
final name = allContacts
|
final name = allContacts
|
||||||
.where((c) => c.publicKey.first == repeater.pubkeyFirstByte)
|
.where((c) => c.publicKey.first == repeater.pubkeyFirstByte)
|
||||||
.map((c) => c.name)
|
.map((c) => c.name)
|
||||||
|
|||||||
Reference in New Issue
Block a user