From b6054fdc25b0d45c82f9a12f7b6066942cf9c16f Mon Sep 17 00:00:00 2001 From: Garth Vander Houwen Date: Mon, 7 Mar 2022 21:30:18 -0800 Subject: [PATCH 1/4] Check for messages --- MeshtasticClient/Views/Messages/UserMessageList.swift | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/MeshtasticClient/Views/Messages/UserMessageList.swift b/MeshtasticClient/Views/Messages/UserMessageList.swift index f9308824..d45cf3c9 100644 --- a/MeshtasticClient/Views/Messages/UserMessageList.swift +++ b/MeshtasticClient/Views/Messages/UserMessageList.swift @@ -335,17 +335,20 @@ struct UserMessageList: View { self.bleManager.context = context self.bleManager.userSettings = userSettings - if allMessages.count > 0 { + if allMessages.count > 1 { - withAnimation(Animation.spring().delay(0.5)) { + withAnimation(Animation.spring().delay(1)) { scrollView.scrollTo(allMessages.firstIndex(of: allMessages.last! ), anchor: .bottom) } } }) .onChange(of: allMessages.count, perform: { count in - withAnimation(Animation.spring().delay(0.5)) { - scrollView.scrollTo(allMessages.firstIndex(of: allMessages.last! ), anchor: .bottom) + if count > 1 { + + withAnimation(Animation.spring().delay(1)) { + scrollView.scrollTo(allMessages.firstIndex(of: allMessages.last! ), anchor: .bottom) + } } }) } From d9a682fc9b2a3c5c536f3df1e2b8946a233d0823 Mon Sep 17 00:00:00 2001 From: Garth Vander Houwen Date: Sun, 13 Mar 2022 20:09:42 -0700 Subject: [PATCH 2/4] Fix times and asks --- Meshtastic Client.xcodeproj/project.pbxproj | 4 +- MeshtasticClient/Helpers/BLEManager.swift | 88 +++++++++++-------- .../contents | 3 +- .../Views/Messages/UserMessageList.swift | 8 ++ 4 files changed, 64 insertions(+), 39 deletions(-) diff --git a/Meshtastic Client.xcodeproj/project.pbxproj b/Meshtastic Client.xcodeproj/project.pbxproj index 1620757e..69d44840 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 = 15; + CURRENT_PROJECT_VERSION = 16; 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 = 15; + CURRENT_PROJECT_VERSION = 16; 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 31c5bfef..a174364d 100644 --- a/MeshtasticClient/Helpers/BLEManager.swift +++ b/MeshtasticClient/Helpers/BLEManager.swift @@ -548,8 +548,14 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph position.altitude = decodedInfo.nodeInfo.position.altitude position.batteryLevel = decodedInfo.nodeInfo.position.batteryLevel - position.time = Date(timeIntervalSince1970: TimeInterval(Int64(decodedInfo.nodeInfo.position.time))) - + if decodedInfo.nodeInfo.position.time > 0 { + + position.time = Date(timeIntervalSince1970: TimeInterval(Int64(decodedInfo.nodeInfo.position.time))) + } + else { + position.time = Date() + } + var newPostions = [PositionEntity]() newPostions.append(position) newNode.positions? = NSOrderedSet(array: newPostions) @@ -609,20 +615,26 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph position.longitudeI = decodedInfo.nodeInfo.position.longitudeI position.altitude = decodedInfo.nodeInfo.position.altitude position.batteryLevel = decodedInfo.nodeInfo.position.batteryLevel - position.time = Date(timeIntervalSince1970: TimeInterval(Int64(decodedInfo.nodeInfo.position.time))) + if decodedInfo.nodeInfo.position.time > 0 { + + position.time = Date(timeIntervalSince1970: TimeInterval(Int64(decodedInfo.nodeInfo.position.time))) + } + else { + position.time = Date() + } 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 { +// if position.coordinate == nil { +// var newPostions = [PositionEntity]() +// newPostions.append(position) +// fetchedNode[0].positions? = NSOrderedSet(array: newPostions) +// +// } else { fetchedNode[0].positions = mutablePositions.copy() as? NSOrderedSet - } +// } // Look for a MyInfo let fetchMyInfoRequest: NSFetchRequest = NSFetchRequest.init(entityName: "MyInfoEntity") @@ -883,39 +895,43 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph } // MARK: Incoming ROUTING_APP Packet } else if decodedInfo.packet.decoded.portnum == PortNum.routingApp { - - if decodedInfo.packet.priority == MeshPacket.Priority.ack { - let fetchMessageRequest: NSFetchRequest = NSFetchRequest.init(entityName: "MessageEntity") - fetchMessageRequest.predicate = NSPredicate(format: "messageId == %lld", Int64(decodedInfo.packet.decoded.requestID)) + let fetchMessageRequest: NSFetchRequest = NSFetchRequest.init(entityName: "MessageEntity") + fetchMessageRequest.predicate = NSPredicate(format: "messageId == %lld", Int64(decodedInfo.packet.decoded.requestID)) - do { + do { - let fetchedMessage = try context?.fetch(fetchMessageRequest)[0] as? MessageEntity + let fetchedMessage = try context?.fetch(fetchMessageRequest)[0] as? MessageEntity + + if fetchedMessage != nil { - if fetchedMessage != nil { - fetchedMessage!.receivedACK = true + + fetchedMessage!.receivedACK = true + fetchedMessage!.ackSNR = decodedInfo.packet.rxSnr + if decodedInfo.packet.rxTime <= 0 { fetchedMessage!.ackTimestamp = Int32(Date().timeIntervalSince1970) + } else { + fetchedMessage!.ackTimestamp = Int32(decodedInfo.packet.rxTime) } - - try context!.save() - - if meshLoggingEnabled { - MeshLogger.log("💾 ACK Received and saved for MessageID \(decodedInfo.packet.id)") - } - print("💾 ACK Received and saved for MessageID \(decodedInfo.packet.id)") - - } catch { - - context!.rollback() - - let nsError = error as NSError - print("💥 Error Saving ACK for message MessageID \(decodedInfo.packet.id) Error: \(nsError)") + } else { + + if meshLoggingEnabled { MeshLogger.log("ℹ️ MESH PACKET received for Routing App UNHANDLED \(try decodedInfo.packet.jsonString())") } + print("ℹ️ MESH PACKET received for Routing App UNHANDLED \(try decodedInfo.packet.jsonString())") } - } else { - - if meshLoggingEnabled { MeshLogger.log("ℹ️ MESH PACKET received for Routing App UNHANDLED \(try decodedInfo.packet.jsonString())") } - print("ℹ️ MESH PACKET received for Routing App UNHANDLED \(try decodedInfo.packet.jsonString())") + + try context!.save() + + if meshLoggingEnabled { + MeshLogger.log("💾 ACK Received and saved for MessageID \(decodedInfo.packet.id)") + } + print("💾 ACK Received and saved for MessageID \(decodedInfo.packet.id)") + + } catch { + + context!.rollback() + + let nsError = error as NSError + print("💥 Error Saving ACK for message MessageID \(decodedInfo.packet.id) Error: \(nsError)") } } else if decodedInfo.packet.decoded.portnum == PortNum.environmentalMeasurementApp { diff --git a/MeshtasticClient/Meshtastic.xcdatamodeld/MeshtasticDataModel v2.xcdatamodel/contents b/MeshtasticClient/Meshtastic.xcdatamodeld/MeshtasticDataModel v2.xcdatamodel/contents index c9b0d9b9..ff52705d 100644 --- a/MeshtasticClient/Meshtastic.xcdatamodeld/MeshtasticDataModel v2.xcdatamodel/contents +++ b/MeshtasticClient/Meshtastic.xcdatamodeld/MeshtasticDataModel v2.xcdatamodel/contents @@ -1,6 +1,7 @@ + @@ -77,7 +78,7 @@ - + diff --git a/MeshtasticClient/Views/Messages/UserMessageList.swift b/MeshtasticClient/Views/Messages/UserMessageList.swift index d45cf3c9..08f8f482 100644 --- a/MeshtasticClient/Views/Messages/UserMessageList.swift +++ b/MeshtasticClient/Views/Messages/UserMessageList.swift @@ -235,6 +235,14 @@ struct UserMessageList: View { Text("ACK \(ackDate, style: .date) \(ackDate, style: .time)").font(.caption2).foregroundColor(.gray) } } + if message.ackSNR != 0 { + VStack { + + Text("ACK SNR \(String(message.ackSNR))") + .font(.caption2) + .foregroundColor(.gray) + } + } } Divider() Button(role: .destructive, action: { From 13360c484817f7b0fbdbc5dd16a0acba6e1d238a Mon Sep 17 00:00:00 2001 From: Garth Vander Houwen Date: Sun, 13 Mar 2022 20:09:58 -0700 Subject: [PATCH 3/4] Bump version --- Meshtastic Client.xcodeproj/project.pbxproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Meshtastic Client.xcodeproj/project.pbxproj b/Meshtastic Client.xcodeproj/project.pbxproj index 69d44840..33f252fe 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 = 16; + CURRENT_PROJECT_VERSION = 17; 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 = 16; + CURRENT_PROJECT_VERSION = 17; DEVELOPMENT_ASSET_PATHS = "\"MeshtasticClient/Preview Content\""; DEVELOPMENT_TEAM = GCH7VS5Y9R; ENABLE_PREVIEWS = YES; From 2d9b448ee6cb68323fbe094576423b29e26fc2a0 Mon Sep 17 00:00:00 2001 From: Garth Vander Houwen Date: Mon, 14 Mar 2022 20:14:27 -0700 Subject: [PATCH 4/4] Show messaged instead of packetid in ACK logging, change delivered to acknowledged. --- MeshtasticClient/Helpers/BLEManager.swift | 6 ++++-- .../Views/Messages/UserMessageList.swift | 21 +++++++------------ 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/MeshtasticClient/Helpers/BLEManager.swift b/MeshtasticClient/Helpers/BLEManager.swift index a174364d..45daa632 100644 --- a/MeshtasticClient/Helpers/BLEManager.swift +++ b/MeshtasticClient/Helpers/BLEManager.swift @@ -913,6 +913,8 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph } else { fetchedMessage!.ackTimestamp = Int32(decodedInfo.packet.rxTime) } + + fetchedMessage!.objectWillChange.send() } else { if meshLoggingEnabled { MeshLogger.log("ℹ️ MESH PACKET received for Routing App UNHANDLED \(try decodedInfo.packet.jsonString())") } @@ -922,9 +924,9 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph try context!.save() if meshLoggingEnabled { - MeshLogger.log("💾 ACK Received and saved for MessageID \(decodedInfo.packet.id)") + MeshLogger.log("💾 ACK Received and saved for MessageID \(decodedInfo.packet.decoded.requestID)") } - print("💾 ACK Received and saved for MessageID \(decodedInfo.packet.id)") + print("💾 ACK Received and saved for MessageID \(decodedInfo.packet.decoded.requestID)") } catch { diff --git a/MeshtasticClient/Views/Messages/UserMessageList.swift b/MeshtasticClient/Views/Messages/UserMessageList.swift index 08f8f482..801668c7 100644 --- a/MeshtasticClient/Views/Messages/UserMessageList.swift +++ b/MeshtasticClient/Views/Messages/UserMessageList.swift @@ -291,13 +291,9 @@ struct UserMessageList: View { HStack { - let time = Int32(message.messageTimestamp) - let messageDate = Date(timeIntervalSince1970: TimeInterval(time)) - let showUntil = Date().addingTimeInterval(3600) - - if messageDate <= showUntil && message.receivedACK { + if message.receivedACK { - Text("Delivered").font(.caption2).foregroundColor(.gray) + Text("Acknowledged").font(.caption2).foregroundColor(.gray) } } @@ -345,18 +341,15 @@ struct UserMessageList: View { if allMessages.count > 1 { - withAnimation(Animation.spring().delay(1)) { - scrollView.scrollTo(allMessages.firstIndex(of: allMessages.last! ), anchor: .bottom) - } + scrollView.scrollTo(allMessages.firstIndex(of: allMessages.last! ), anchor: .bottom) } }) - .onChange(of: allMessages.count, perform: { count in + .onChange(of: allMessages, perform: { message in - if count > 1 { + if allMessages.count > 1 { - withAnimation(Animation.spring().delay(1)) { - scrollView.scrollTo(allMessages.firstIndex(of: allMessages.last! ), anchor: .bottom) - } + scrollView.scrollTo(allMessages.firstIndex(of: allMessages.last! ), anchor: .bottom) + } }) }