From 3aefd67d067fc95c56df4ac3b58f5a37feb51545 Mon Sep 17 00:00:00 2001 From: Garth Vander Houwen Date: Sun, 26 May 2024 10:37:22 -0700 Subject: [PATCH] Check for last postion before sending phone location --- Meshtastic.xcodeproj/project.pbxproj | 8 ----- Meshtastic/Helpers/BLEManager.swift | 38 ++++++++++----------- Meshtastic/Persistence/UpdateCoreData.swift | 1 - protobufs | 2 +- 4 files changed, 20 insertions(+), 29 deletions(-) diff --git a/Meshtastic.xcodeproj/project.pbxproj b/Meshtastic.xcodeproj/project.pbxproj index c1a9f681..a96e3707 100644 --- a/Meshtastic.xcodeproj/project.pbxproj +++ b/Meshtastic.xcodeproj/project.pbxproj @@ -573,13 +573,6 @@ path = CoreData; sourceTree = ""; }; - DD17C4D42BE7EC2200D45AC7 /* SwiftData */ = { - isa = PBXGroup; - children = ( - ); - path = SwiftData; - sourceTree = ""; - }; DD47E3CA26F0E50300029299 /* Nodes */ = { isa = PBXGroup; children = ( @@ -957,7 +950,6 @@ DDC4D5662754996200A4208E /* Persistence */ = { isa = PBXGroup; children = ( - DD17C4D42BE7EC2200D45AC7 /* SwiftData */, DDC4D567275499A500A4208E /* Persistence.swift */, DD964FC52975DBFD007C176F /* QueryCoreData.swift */, DD3CC6C128EB9D4900FA9159 /* UpdateCoreData.swift */, diff --git a/Meshtastic/Helpers/BLEManager.swift b/Meshtastic/Helpers/BLEManager.swift index 578daa8d..729a6fa0 100644 --- a/Meshtastic/Helpers/BLEManager.swift +++ b/Meshtastic/Helpers/BLEManager.swift @@ -1002,26 +1002,26 @@ class BLEManager: NSObject, CBPeripheralDelegate, MqttClientProxyManagerDelegate var positionPacket = Position() if #available(iOS 17.0, macOS 14.0, *) { - if let lastLocation = LocationsHandler.shared.locationsArray.last { - - positionPacket.latitudeI = Int32(lastLocation.coordinate.latitude * 1e7) - positionPacket.longitudeI = Int32(lastLocation.coordinate.longitude * 1e7) - let timestamp = lastLocation.timestamp - positionPacket.time = UInt32(timestamp.timeIntervalSince1970) - positionPacket.timestamp = UInt32(timestamp.timeIntervalSince1970) - positionPacket.altitude = Int32(lastLocation.altitude) - positionPacket.satsInView = UInt32(LocationsHandler.satsInView) - - let currentSpeed = lastLocation.speed - if currentSpeed > 0 && (!currentSpeed.isNaN || !currentSpeed.isInfinite) { - positionPacket.groundSpeed = UInt32(currentSpeed) - } - let currentHeading = lastLocation.course - if (currentHeading > 0 && currentHeading <= 360) && (!currentHeading.isNaN || !currentHeading.isInfinite) { - positionPacket.groundTrack = UInt32(currentHeading) - } + guard let lastLocation = LocationsHandler.shared.locationsArray.last else { + return nil } - + positionPacket.latitudeI = Int32(lastLocation.coordinate.latitude * 1e7) + positionPacket.longitudeI = Int32(lastLocation.coordinate.longitude * 1e7) + let timestamp = lastLocation.timestamp + positionPacket.time = UInt32(timestamp.timeIntervalSince1970) + positionPacket.timestamp = UInt32(timestamp.timeIntervalSince1970) + positionPacket.altitude = Int32(lastLocation.altitude) + positionPacket.satsInView = UInt32(LocationsHandler.satsInView) + + let currentSpeed = lastLocation.speed + if currentSpeed > 0 && (!currentSpeed.isNaN || !currentSpeed.isInfinite) { + positionPacket.groundSpeed = UInt32(currentSpeed) + } + let currentHeading = lastLocation.course + if (currentHeading > 0 && currentHeading <= 360) && (!currentHeading.isNaN || !currentHeading.isInfinite) { + positionPacket.groundTrack = UInt32(currentHeading) + } + } else { positionPacket.latitudeI = Int32(LocationHelper.currentLocation.latitude * 1e7) diff --git a/Meshtastic/Persistence/UpdateCoreData.swift b/Meshtastic/Persistence/UpdateCoreData.swift index 093e8872..491ba4b5 100644 --- a/Meshtastic/Persistence/UpdateCoreData.swift +++ b/Meshtastic/Persistence/UpdateCoreData.swift @@ -120,7 +120,6 @@ public func clearCoreDataDatabase(context: NSManagedObjectContext, includeRoutes deleteRequest = NSBatchDeleteRequest(fetchRequest: query) } else if !includeRoutes { if !(entityName.contains("RouteEntity") || entityName.contains("LocationEntity")) { - print(entity.name?.lowercased()) deleteRequest = NSBatchDeleteRequest(fetchRequest: query) } } diff --git a/protobufs b/protobufs index dd7d64cc..f92900c5 160000 --- a/protobufs +++ b/protobufs @@ -1 +1 @@ -Subproject commit dd7d64cc038a6365c119ec7508762cc45f405948 +Subproject commit f92900c5f884b04388fb7abf61d4df66783015e4