Implement sparse location logging feature and update related services

This commit is contained in:
Winston Lowe
2026-02-08 17:01:28 -08:00
parent fac062a100
commit cedbe1dd6c
11 changed files with 405 additions and 13 deletions
+26
View File
@@ -2,6 +2,8 @@ import 'dart:async';
import 'dart:convert';
import 'package:crypto/crypto.dart' as crypto;
import 'package:geolocator_platform_interface/src/models/position.dart';
import 'package:meshcore_open/services/sparse_location_logger.dart';
import 'package:pointycastle/export.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter_blue_plus/flutter_blue_plus.dart';
@@ -130,6 +132,7 @@ class MeshCoreConnector extends ChangeNotifier {
PathHistoryService? _pathHistoryService;
AppSettingsService? _appSettingsService;
BackgroundService? _backgroundService;
SparseLocationLogger? _sparseLocationLogger;
final NotificationService _notificationService = NotificationService();
BleDebugLogService? _bleDebugLogService;
AppDebugLogService? _appDebugLogService;
@@ -502,6 +505,7 @@ class MeshCoreConnector extends ChangeNotifier {
BleDebugLogService? bleDebugLogService,
AppDebugLogService? appDebugLogService,
BackgroundService? backgroundService,
SparseLocationLogger? sparseLocationLogger,
}) {
_retryService = retryService;
_pathHistoryService = pathHistoryService;
@@ -509,11 +513,14 @@ class MeshCoreConnector extends ChangeNotifier {
_bleDebugLogService = bleDebugLogService;
_appDebugLogService = appDebugLogService;
_backgroundService = backgroundService;
_sparseLocationLogger = sparseLocationLogger;
// Initialize notification service
_notificationService.initialize();
_loadChannelOrder();
_sparseLocationLogger?.initialize(_updateLocationandAdvert);
// Initialize retry service callbacks
_retryService?.initialize(
sendMessageCallback: _sendMessageDirect,
@@ -828,6 +835,8 @@ class MeshCoreConnector extends ChangeNotifier {
return result;
}
SparseLocationLogger? get sparseLocationLogger => _sparseLocationLogger;
bool get _shouldAutoReconnect => !_manualDisconnect && _lastDeviceId != null;
void _cancelReconnectTimer() {
@@ -3285,6 +3294,23 @@ class MeshCoreConnector extends ChangeNotifier {
super.dispose();
}
_updateLocationandAdvert(Position position) async {
double lat = position.latitude;
double lon = position.longitude;
if (lat == 0.0 && lon == 0.0) {
// Invalid location
return;
}
lat = double.parse(lat.toStringAsFixed(3)) - 0.00015;
lon = double.parse(lon.toStringAsFixed(3)) - 0.00015;
print('Updating location to lat: $lat, lon: $lon');
await sendFrame(buildSetOtherParamsFrame(true, 0, 1, 0));
await setNodeLocation(lat: lat, lon: lon);
await sendSelfAdvert(flood: true);
await sendFrame(buildDeviceQueryFrame());
}
}
const int _phRouteMask = 0x03;
+20
View File
@@ -151,6 +151,7 @@ const int cmdGetContactByKey = 30;
const int cmdGetChannel = 31;
const int cmdSetChannel = 32;
const int cmdSendTracePath = 36;
const int cmdSetOtherParams = 38;
const int cmdGetRadioSettings = 57;
const int cmdGetTelemetryReq = 39;
const int cmdGetCustomVar = 40;
@@ -777,3 +778,22 @@ Uint8List buildZeroHopContact(Uint8List pubKey) {
writer.writeBytes(pubKey);
return writer.toBytes();
}
// Build CMD_SET_OTHER_PARAMS frame
// Format: [cmd][allowAutoAddContacts][allowTelemetryFlags][advert_loc_policy][multi_acks]
Uint8List buildSetOtherParamsFrame(
bool allowAutoAddContacts,
int allowTelemetryFlags,
int advert_loc_policy,
int multi_acks,
) {
final writer = BufferWriter();
writer.writeByte(cmdSetOtherParams);
writer.writeByte(
allowAutoAddContacts ? 0x01 : 0x00,
); // Allow Auto Add Contacts
writer.writeByte(allowTelemetryFlags); // Allow Telemetry Flags
writer.writeByte(advert_loc_policy); // Advertisement Location Policy
writer.writeByte(multi_acks); // Multi Acknowledgements
return writer.toBytes();
}