mirror of
https://github.com/dz0ny/meshcore-sar.git
synced 2026-08-11 16:30:28 +00:00
fix: ignore zeroed telemetry gps coords
Fixes #4\nRefs #5\n\nref:
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:latlong2/latlong.dart';
|
||||
import '../models/contact.dart';
|
||||
import '../services/cayenne_lpp_parser.dart';
|
||||
import '../services/contact_storage_service.dart';
|
||||
@@ -330,10 +331,28 @@ class ContactsProvider with ChangeNotifier {
|
||||
|
||||
try {
|
||||
// Parse Cayenne LPP data
|
||||
final telemetry = CayenneLppParser.parse(lppData);
|
||||
var telemetry = CayenneLppParser.parse(lppData);
|
||||
debugPrint(' ✅ Parsed new telemetry');
|
||||
debugPrint(' New telemetry timestamp: ${telemetry.timestamp}');
|
||||
|
||||
// Ignore placeholder GPS coordinates (0,0) so we don't overwrite a
|
||||
// previously known/saved position with invalid telemetry data.
|
||||
if (_isInvalidTelemetryGps(telemetry.gpsLocation)) {
|
||||
debugPrint(
|
||||
' ⚠️ Ignoring invalid telemetry GPS coordinates: ${telemetry.gpsLocation}',
|
||||
);
|
||||
telemetry = ContactTelemetry(
|
||||
gpsLocation: null,
|
||||
batteryPercentage: telemetry.batteryPercentage,
|
||||
batteryMilliVolts: telemetry.batteryMilliVolts,
|
||||
temperature: telemetry.temperature,
|
||||
timestamp: telemetry.timestamp,
|
||||
humidity: telemetry.humidity,
|
||||
pressure: telemetry.pressure,
|
||||
extraSensorData: telemetry.extraSensorData,
|
||||
);
|
||||
}
|
||||
|
||||
// Update contact with new telemetry AND last seen time
|
||||
// lastAdvert is Unix timestamp in seconds
|
||||
final currentTimestamp = (DateTime.now().millisecondsSinceEpoch / 1000)
|
||||
@@ -359,6 +378,18 @@ class ContactsProvider with ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
bool _isInvalidTelemetryGps(LatLng? location) {
|
||||
if (location == null) return false;
|
||||
final lat = location.latitude;
|
||||
final lon = location.longitude;
|
||||
|
||||
if (!lat.isFinite || !lon.isFinite) return true;
|
||||
|
||||
// Many devices report "0000" placeholder GPS as (0.0, 0.0).
|
||||
const epsilon = 1e-7;
|
||||
return lat.abs() < epsilon && lon.abs() < epsilon;
|
||||
}
|
||||
|
||||
/// Find contact by public key prefix (6 bytes)
|
||||
Contact? _findContactByPrefix(Uint8List prefix) {
|
||||
if (prefix.length < 6) return null;
|
||||
|
||||
Reference in New Issue
Block a user