Show telemetry GPS fixes on the map and add a map location request

Telemetry replies carried a GPS fix that was only shown on the telemetry
screen, so the map kept the node at its last advert position. The fix now
updates the contact and survives radio contact refreshes until the node
adverts again (compared on the node's own advert clock). The map node card
gains an "Update location" button for companions and sensors; repeaters
and rooms only share GPS with logged-in admins, so they don't get it.
This commit is contained in:
zjs81 committed 2026-10-25 11:10:27 -07:00
1 parent d2eff6eb78
commit f0144ca959
44 files changed
+780 -19

No files matched your search

+110
View File
@@ -0,0 +1,110 @@
import 'dart:typed_data';
import 'package:flutter_test/flutter_test.dart';
import 'package:meshcore_open/connector/meshcore_connector.dart';
import 'package:meshcore_open/connector/meshcore_protocol.dart';
import 'package:meshcore_open/services/telemetry_location_request.dart';
import 'package:meshcore_open/storage/prefs_manager.dart';
import 'package:shared_preferences/shared_preferences.dart';
Uint8List _contactFrame(
Uint8List key, {
required int advertTimestamp,
required double lat,
required double lon,
}) {
final data = ByteData(1 + 32 + 3 + 64 + 32 + 4 + 12);
final bytes = data.buffer.asUint8List();
bytes[0] = respCodeContact;
bytes.setRange(1, 33, key);
bytes[33] = advTypeChat;
bytes[35] = 0xFF; // path unknown
bytes.setRange(100, 103, 'Bob'.codeUnits);
data.setUint32(132, advertTimestamp, Endian.little);
data.setInt32(136, (lat * 1e6).round(), Endian.little);
data.setInt32(140, (lon * 1e6).round(), Endian.little);
return bytes;
}
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
setUp(() async {
SharedPreferences.setMockInitialValues({});
PrefsManager.reset();
await PrefsManager.initialize();
});
final key = Uint8List.fromList(List<int>.generate(32, (i) => i + 1));
test('telemetry fix survives a refresh of the same advert', () {
final connector = MeshCoreConnector();
final frame = _contactFrame(
key,
advertTimestamp: 1700000000,
lat: 10,
lon: 20,
);
connector.handleFrameForTest(frame);
final keyHex = connector.contacts.single.publicKeyHex;
connector.updateContactLocationFromTelemetry(keyHex, 11.5, 21.5);
final fixed = connector.contacts.single;
expect(fixed.latitude, 11.5);
expect(fixed.longitude, 21.5);
expect(fixed.lastSeen.isAfter(DateTime(2024)), isTrue);
connector.handleFrameForTest(frame);
final refreshed = connector.contacts.single;
expect(refreshed.latitude, 11.5);
expect(refreshed.longitude, 21.5);
expect(refreshed.lastSeen, fixed.lastSeen);
});
test('a newer advert replaces the telemetry fix', () {
final connector = MeshCoreConnector();
connector.handleFrameForTest(
_contactFrame(key, advertTimestamp: 1700000000, lat: 10, lon: 20),
);
final keyHex = connector.contacts.single.publicKeyHex;
connector.updateContactLocationFromTelemetry(keyHex, 11.5, 21.5);
connector.handleFrameForTest(
_contactFrame(key, advertTimestamp: 1700000100, lat: 12, lon: 22),
);
final contact = connector.contacts.single;
expect(contact.latitude, 12);
expect(contact.longitude, 22);
expect(contact.telemetryFixAdvertSeen, isNull);
});
test('telemetryGpsFix skips missing and null-island fixes', () {
expect(telemetryGpsFix([]), isNull);
expect(
telemetryGpsFix([
{
'channel': 1,
'values': {
'gps': {'latitude': 0.0, 'longitude': 0.0, 'altitude': 0.0},
},
},
]),
isNull,
);
expect(
telemetryGpsFix([
{
'channel': 1,
'values': {'voltage': 4.1},
},
{
'channel': 2,
'values': {
'gps': {'latitude': 45.5, 'longitude': -122.6, 'altitude': 10.0},
},
},
]),
(latitude: 45.5, longitude: -122.6),
);
});
}