Check for last postion before sending phone location

This commit is contained in:
Garth Vander Houwen 2024-05-26 10:37:22 -07:00
parent 3046361dd0
commit 3aefd67d06
4 changed files with 20 additions and 29 deletions

View file

@ -573,13 +573,6 @@
path = CoreData;
sourceTree = "<group>";
};
DD17C4D42BE7EC2200D45AC7 /* SwiftData */ = {
isa = PBXGroup;
children = (
);
path = SwiftData;
sourceTree = "<group>";
};
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 */,

View file

@ -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)

View file

@ -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)
}
}

@ -1 +1 @@
Subproject commit dd7d64cc038a6365c119ec7508762cc45f405948
Subproject commit f92900c5f884b04388fb7abf61d4df66783015e4