mirror of
https://github.com/zjs81/meshcore-open.git
synced 2026-06-21 01:45:47 +10:00
feat: Add location validation and improve contact latitude/longitude handling
This commit is contained in:
@@ -4913,6 +4913,17 @@ class MeshCoreConnector extends ChangeNotifier {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool hasValidLocation(double? latitude, double? longitude) {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
void _handlePayloadAdvertReceived(
|
void _handlePayloadAdvertReceived(
|
||||||
Uint8List rawPacket,
|
Uint8List rawPacket,
|
||||||
Uint8List payload,
|
Uint8List payload,
|
||||||
@@ -4950,6 +4961,9 @@ class MeshCoreConnector extends ChangeNotifier {
|
|||||||
latitude = advert.readInt32LE() / 1e6;
|
latitude = advert.readInt32LE() / 1e6;
|
||||||
longitude = advert.readInt32LE() / 1e6;
|
longitude = advert.readInt32LE() / 1e6;
|
||||||
}
|
}
|
||||||
|
// Validate location values if present
|
||||||
|
hasLocation = hasValidLocation(latitude, longitude);
|
||||||
|
|
||||||
if (hasName && advert.remaining > 0) {
|
if (hasName && advert.remaining > 0) {
|
||||||
name = advert.readString();
|
name = advert.readString();
|
||||||
}
|
}
|
||||||
@@ -5015,20 +5029,8 @@ 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:
|
latitude: hasLocation ? latitude : existing.latitude,
|
||||||
hasLocation &&
|
longitude: hasLocation ? longitude : existing.longitude,
|
||||||
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,
|
||||||
|
|||||||
@@ -181,12 +181,13 @@ class Contact {
|
|||||||
final lastMod = reader.readUInt32LE();
|
final lastMod = reader.readUInt32LE();
|
||||||
|
|
||||||
double? lat, lon;
|
double? lat, lon;
|
||||||
final latRaw = reader.readInt32LE();
|
if (reader.remaining >= 8) {
|
||||||
final lonRaw = reader.readInt32LE();
|
final latRaw = 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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Contact(
|
return Contact(
|
||||||
|
|||||||
Reference in New Issue
Block a user