diff --git a/Meshtastic Client.xcodeproj/project.pbxproj b/Meshtastic Client.xcodeproj/project.pbxproj index 33f252fe..f3ede640 100644 --- a/Meshtastic Client.xcodeproj/project.pbxproj +++ b/Meshtastic Client.xcodeproj/project.pbxproj @@ -730,7 +730,7 @@ CODE_SIGN_ENTITLEMENTS = MeshtasticClient/MeshtasticClient.entitlements; "CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 17; + CURRENT_PROJECT_VERSION = 18; DEVELOPMENT_ASSET_PATHS = "\"MeshtasticClient/Preview Content\""; DEVELOPMENT_TEAM = GCH7VS5Y9R; ENABLE_PREVIEWS = YES; @@ -761,7 +761,7 @@ CODE_SIGN_ENTITLEMENTS = MeshtasticClient/MeshtasticClient.entitlements; "CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 17; + CURRENT_PROJECT_VERSION = 18; DEVELOPMENT_ASSET_PATHS = "\"MeshtasticClient/Preview Content\""; DEVELOPMENT_TEAM = GCH7VS5Y9R; ENABLE_PREVIEWS = YES; diff --git a/MeshtasticClient/Helpers/BLEManager.swift b/MeshtasticClient/Helpers/BLEManager.swift index 45daa632..619cf501 100644 --- a/MeshtasticClient/Helpers/BLEManager.swift +++ b/MeshtasticClient/Helpers/BLEManager.swift @@ -52,13 +52,13 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph let FROMRADIO_UUID = CBUUID(string: "0x8BA2BCC2-EE02-4A55-A531-C525C5E454D5") let FROMNUM_UUID = CBUUID(string: "0xED9DA18C-A800-4F66-A670-AA7547E34453") - private var meshLoggingEnabled: Bool = true + private var meshLoggingEnabled: Bool = false let meshLog = documentsFolder.appendingPathComponent("meshlog.txt") // MARK: init BLEManager override init() { - self.meshLoggingEnabled = true // UserDefaults.standard.object(forKey: "meshActivityLog") as? Bool ?? false + self.meshLoggingEnabled = UserDefaults.standard.object(forKey: "meshActivityLog") as? Bool ?? false self.lastConnectionError = "" self.lastConnnectionVersion = "0.0.0" super.init() @@ -624,17 +624,8 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph } let mutablePositions = fetchedNode[0].positions!.mutableCopy() as! NSMutableOrderedSet - mutablePositions.add(position) -// if position.coordinate == nil { -// var newPostions = [PositionEntity]() -// newPostions.append(position) -// fetchedNode[0].positions? = NSOrderedSet(array: newPostions) -// -// } else { - - fetchedNode[0].positions = mutablePositions.copy() as? NSOrderedSet -// } + fetchedNode[0].positions = mutablePositions.copy() as? NSOrderedSet // Look for a MyInfo let fetchMyInfoRequest: NSFetchRequest = NSFetchRequest.init(entityName: "MyInfoEntity") @@ -845,28 +836,27 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph } fetchedNode[0].snr = decodedInfo.packet.rxSnr - if let positionMessage = try? Position(serializedData: decodedInfo.packet.decoded.payload) { + let position = PositionEntity(context: context!) position.latitudeI = positionMessage.latitudeI position.longitudeI = positionMessage.longitudeI position.altitude = positionMessage.altitude position.batteryLevel = positionMessage.batteryLevel - position.time = Date(timeIntervalSince1970: TimeInterval(Int64(positionMessage.time))) + + if positionMessage.time == 0 { + fetchedNode[0].lastHeard = Date() + + } else { + + position.time = Date(timeIntervalSince1970: TimeInterval(Int64(positionMessage.time))) + } let mutablePositions = fetchedNode[0].positions!.mutableCopy() as! NSMutableOrderedSet mutablePositions.add(position) - - if position.coordinate == nil { - var newPostions = [PositionEntity]() - newPostions.append(position) - fetchedNode[0].positions? = NSOrderedSet(array: newPostions) - - } else { - - fetchedNode[0].positions = mutablePositions.copy() as? NSOrderedSet - } + + fetchedNode[0].positions = mutablePositions.copy() as? NSOrderedSet } } else { diff --git a/MeshtasticClient/Views/Nodes/NodeDetail.swift b/MeshtasticClient/Views/Nodes/NodeDetail.swift index 7dc1da84..2e22a879 100644 --- a/MeshtasticClient/Views/Nodes/NodeDetail.swift +++ b/MeshtasticClient/Views/Nodes/NodeDetail.swift @@ -122,7 +122,7 @@ struct NodeDetail: View { .padding(5) } - if node.positions!.count > 0 { + if node.positions?.count ?? 0 > 0 { let mostRecent = node.positions?.lastObject as! PositionEntity