From c023856d4798a7fa296018a3f8c64aaad7dbd7c2 Mon Sep 17 00:00:00 2001 From: Garth Vander Houwen Date: Thu, 7 Oct 2021 12:50:40 -0700 Subject: [PATCH] V 1.25.1 Save Position packet SNR and lastHeard --- Meshtastic Client.xcodeproj/project.pbxproj | 4 +- MeshtasticClient/Helpers/BLEManager.swift | 43 +++++++++++++------ .../Helpers/LocalNotificationManager.swift | 10 ++--- 3 files changed, 38 insertions(+), 19 deletions(-) diff --git a/Meshtastic Client.xcodeproj/project.pbxproj b/Meshtastic Client.xcodeproj/project.pbxproj index 14b5072a..f3659f33 100644 --- a/Meshtastic Client.xcodeproj/project.pbxproj +++ b/Meshtastic Client.xcodeproj/project.pbxproj @@ -659,7 +659,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.24; + MARKETING_VERSION = 1.25.1; PRODUCT_BUNDLE_IDENTIFIER = gvh.MeshtasticClient; PRODUCT_NAME = "$(TARGET_NAME)"; SUPPORTS_MACCATALYST = NO; @@ -686,7 +686,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.24; + MARKETING_VERSION = 1.25.1; PRODUCT_BUNDLE_IDENTIFIER = gvh.MeshtasticClient; PRODUCT_NAME = "$(TARGET_NAME)"; SUPPORTS_MACCATALYST = NO; diff --git a/MeshtasticClient/Helpers/BLEManager.swift b/MeshtasticClient/Helpers/BLEManager.swift index 04df7766..9a0c61ea 100644 --- a/MeshtasticClient/Helpers/BLEManager.swift +++ b/MeshtasticClient/Helpers/BLEManager.swift @@ -315,7 +315,7 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph if decodedInfo.myInfo.myNodeNum != 0 { - print("Save myInfo for \(decodedInfo.myInfo.myNodeNum)") + do { // Create a MyInfoModel @@ -332,9 +332,13 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph // Save it to the connected node connectedNode = meshData.nodes.first(where: {$0.num == myInfoModel.id}) // Since the data is from the device itself we save all myInfo objects since they are always the most update - if connectedNode != nil { + if connectedNode != nil && connectedNode.myInfo == nil { connectedNode.myInfo = myInfoModel - connectedNode.update(from: connectedNode.data) + let nodeIndex = meshData.nodes.firstIndex(where: { $0.id == decodedInfo.myInfo.myNodeNum }) + meshData.nodes.remove(at: nodeIndex!) + meshData.nodes.append(connectedNode) + meshData.save() + print("Saved a myInfo for \(decodedInfo.myInfo.myNodeNum)") // connectedNode.update(from: connectedNode.data) } meshData.save() @@ -440,19 +444,34 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph else if decodedInfo.packet.decoded.portnum == PortNum.nodeinfoApp { var updatedNode = meshData.nodes.first(where: {$0.id == decodedInfo.packet.from }) - updatedNode!.snr = decodedInfo.packet.rxSnr - updatedNode!.lastHeard = decodedInfo.packet.rxTime - // updatedNode!.user.longName = "Node Info updated longname" - updatedNode!.update(from: updatedNode!.data) - //let nodeIndex = meshData.nodes.firstIndex(where: { $0.id == decodedInfo.packet.from }) - //meshData.nodes.remove(at: nodeIndex!) - //meshData.nodes.append(updatedNode!) - meshData.save() - print("Updated NodeInfo SNR and Time from Packet For: \(updatedNode!.user.longName)") + if updatedNode != nil { + updatedNode!.snr = decodedInfo.packet.rxSnr + updatedNode!.lastHeard = decodedInfo.packet.rxTime + //updatedNode!.update(from: updatedNode!.data) + let nodeIndex = meshData.nodes.firstIndex(where: { $0.id == decodedInfo.packet.from }) + meshData.nodes.remove(at: nodeIndex!) + meshData.nodes.append(updatedNode!) + meshData.save() + //meshData.load() + print("Updated NodeInfo SNR and Time from Packet For: \(updatedNode!.user.longName)") + } } else if decodedInfo.packet.decoded.portnum == PortNum.positionApp { + var updatedNode = meshData.nodes.first(where: {$0.id == decodedInfo.packet.from }) + + if updatedNode != nil { + updatedNode!.snr = decodedInfo.packet.rxSnr + updatedNode!.lastHeard = decodedInfo.packet.rxTime + //updatedNode!.update(from: updatedNode!.data) + let nodeIndex = meshData.nodes.firstIndex(where: { $0.id == decodedInfo.packet.from }) + meshData.nodes.remove(at: nodeIndex!) + meshData.nodes.append(updatedNode!) + meshData.save() + + print("Updated Position SNR and Time from Packet For: \(updatedNode!.user.longName)") + } print("Postion Payload") print(try decodedInfo.packet.jsonString()) } diff --git a/MeshtasticClient/Helpers/LocalNotificationManager.swift b/MeshtasticClient/Helpers/LocalNotificationManager.swift index f3e8b668..417090ce 100644 --- a/MeshtasticClient/Helpers/LocalNotificationManager.swift +++ b/MeshtasticClient/Helpers/LocalNotificationManager.swift @@ -20,7 +20,6 @@ class LocalNotificationManager { func schedule() { UNUserNotificationCenter.current().getNotificationSettings { settings in - switch settings.authorizationStatus { case .notDetermined: self.requestAuthorization() @@ -37,10 +36,11 @@ class LocalNotificationManager { { for notification in notifications { - let content = UNMutableNotificationContent() - content.title = notification.title - content.body = notification.content - content.sound = .default + let content = UNMutableNotificationContent() + content.title = notification.title + content.body = notification.content + content.sound = .default + content.interruptionLevel = .timeSensitive let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 1, repeats: false) let request = UNNotificationRequest(identifier: notification.id, content: content, trigger: trigger)