diff --git a/Meshtastic Client.xcodeproj/project.pbxproj b/Meshtastic Client.xcodeproj/project.pbxproj index af7c9c5e..5f4628ec 100644 --- a/Meshtastic Client.xcodeproj/project.pbxproj +++ b/Meshtastic Client.xcodeproj/project.pbxproj @@ -23,6 +23,7 @@ DD8169FB271F1F3A00F4AB02 /* MeshLog.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD8169FA271F1F3A00F4AB02 /* MeshLog.swift */; }; DD8169FF272476C700F4AB02 /* LogDocument.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD8169FE272476C700F4AB02 /* LogDocument.swift */; }; DD836AE726F6B38600ABCC23 /* Connect.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD836AE626F6B38600ABCC23 /* Connect.swift */; }; + DD882F5D2772E4640005BF05 /* Contacts.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD882F5C2772E4640005BF05 /* Contacts.swift */; }; DD90860C26F684AF00DC5189 /* BatteryIcon.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD90860B26F684AF00DC5189 /* BatteryIcon.swift */; }; DD90860E26F69BAE00DC5189 /* NodeMap.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD90860D26F69BAE00DC5189 /* NodeMap.swift */; }; DD913639270DFF4C00D7ACF3 /* LocalNotificationManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD913638270DFF4C00D7ACF3 /* LocalNotificationManager.swift */; }; @@ -82,6 +83,7 @@ DD8169FA271F1F3A00F4AB02 /* MeshLog.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MeshLog.swift; sourceTree = ""; }; DD8169FE272476C700F4AB02 /* LogDocument.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LogDocument.swift; sourceTree = ""; }; DD836AE626F6B38600ABCC23 /* Connect.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Connect.swift; sourceTree = ""; }; + DD882F5C2772E4640005BF05 /* Contacts.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Contacts.swift; sourceTree = ""; }; DD90860A26F645B700DC5189 /* MeshtasticClient.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = MeshtasticClient.entitlements; sourceTree = ""; }; DD90860B26F684AF00DC5189 /* BatteryIcon.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BatteryIcon.swift; sourceTree = ""; }; DD90860D26F69BAE00DC5189 /* NodeMap.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NodeMap.swift; sourceTree = ""; }; @@ -293,6 +295,7 @@ children = ( DD47E3DA26F3901A00029299 /* Channels.swift */, DD47E3DC26F390A000029299 /* Messages.swift */, + DD882F5C2772E4640005BF05 /* Contacts.swift */, ); path = Messages; sourceTree = ""; @@ -506,6 +509,7 @@ DDAF8C5D26ED09490058C060 /* portnums.pb.swift in Sources */, DD9D8F2F2764403B00080993 /* Meshtastic.xcdatamodeld in Sources */, DD23A50F26FD1B4400D9B90C /* PeripheralModel.swift in Sources */, + DD882F5D2772E4640005BF05 /* Contacts.swift in Sources */, DD47E3CE26F103C600029299 /* NodeList.swift in Sources */, DD47E3D626F17ED900029299 /* CircleText.swift in Sources */, DDC2E18F26CE25FE0042C5E4 /* ContentView.swift in Sources */, @@ -691,7 +695,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.32; + MARKETING_VERSION = 1.33; PRODUCT_BUNDLE_IDENTIFIER = gvh.MeshtasticClient; PRODUCT_NAME = "$(TARGET_NAME)"; SUPPORTS_MACCATALYST = YES; @@ -718,7 +722,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.32; + MARKETING_VERSION = 1.33; PRODUCT_BUNDLE_IDENTIFIER = gvh.MeshtasticClient; PRODUCT_NAME = "$(TARGET_NAME)"; SUPPORTS_MACCATALYST = YES; diff --git a/Meshtastic Client.xcodeproj/xcuserdata/garthvanderhouwen.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/Meshtastic Client.xcodeproj/xcuserdata/garthvanderhouwen.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist index a69d2766..bd8f0435 100644 --- a/Meshtastic Client.xcodeproj/xcuserdata/garthvanderhouwen.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ b/Meshtastic Client.xcodeproj/xcuserdata/garthvanderhouwen.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -80,22 +80,6 @@ landmarkType = "24"> - - - - @@ -122,11 +106,43 @@ filePath = "MeshtasticClient/Helpers/BLEManager.swift" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "893" - endingLineNumber = "893" + startingLineNumber = "894" + endingLineNumber = "894" landmarkName = "sendMessage(message:toUserNum:)" landmarkType = "7"> + + + + + + + + diff --git a/MeshtasticClient/Helpers/BLEManager.swift b/MeshtasticClient/Helpers/BLEManager.swift index 7ad8f118..ea483441 100644 --- a/MeshtasticClient/Helpers/BLEManager.swift +++ b/MeshtasticClient/Helpers/BLEManager.swift @@ -55,7 +55,7 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph // MARK: init BLEManager override init() { - self.meshLoggingEnabled = UserDefaults.standard.object(forKey: "meshActivityLog") as? Bool ?? false + self.meshLoggingEnabled = true // UserDefaults.standard.object(forKey: "meshActivityLog") as? Bool ?? true self.lastConnectedPeripheral = "" self.lastConnectionError = "" super.init() @@ -341,7 +341,7 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph case FROMNUM_UUID: print("FROMNUM (Notify) characteristic OK") - if meshLoggingEnabled { MeshLogger.log("βœ…BLE did discover FROMNUM (Notify) characteristic for Meshtastic by \(peripheral.name ?? "Unknown")") } + if meshLoggingEnabled { MeshLogger.log("βœ… BLE did discover FROMNUM (Notify) characteristic for Meshtastic by \(peripheral.name ?? "Unknown")") } FROMNUM_characteristic = characteristic peripheral.setNotifyValue(true, for: characteristic) @@ -457,7 +457,7 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph let fetchedNode = try context?.fetch(fetchNodeRequest) as! [NodeInfoEntity] // Not Found Insert - if fetchedNode.isEmpty { + if fetchedNode.isEmpty && decodedInfo.nodeInfo.hasUser { let newNode = NodeInfoEntity(context: context!) newNode.id = Int64(decodedInfo.nodeInfo.num) @@ -517,7 +517,7 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph print("πŸ’₯ Fetch MyInfo Error") } - } else { + } else if decodedInfo.nodeInfo.hasUser { fetchedNode[0].id = Int64(decodedInfo.nodeInfo.num) fetchedNode[0].num = Int64(decodedInfo.nodeInfo.num) @@ -600,17 +600,15 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph // Handle assorted app packets if decodedInfo.packet.id != 0 { - print("Handle a Packet") do { - //!!!: Switch Messages Tab to coredata // Text Message App - Primary Broadcast Channel if decodedInfo.packet.decoded.portnum == PortNum.textMessageApp { if let messageText = String(bytes: decodedInfo.packet.decoded.payload, encoding: .utf8) { - print("Message Text: \(messageText)") - if meshLoggingEnabled { MeshLogger.log("BLE FROMRADIO received for text message app \(messageText)") } + print("πŸ’¬ BLE FROMRADIO received for text message app \(messageText)") + if meshLoggingEnabled { MeshLogger.log("πŸ’¬ BLE FROMRADIO received for text message app \(messageText)") } let messageUsers:NSFetchRequest = NSFetchRequest.init(entityName: "UserEntity") messageUsers.predicate = NSPredicate(format:"num IN %@", [decodedInfo.packet.to, decodedInfo.packet.from]) @@ -624,7 +622,6 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph newMessage.messageTimestamp = Int32(bitPattern: decodedInfo.packet.rxTime) newMessage.receivedACK = false newMessage.direction = "IN" - //newMessage.toUser = Int64(decodedInfo.packet.to) if decodedInfo.packet.to == broadcastNodeNum && fetchedUsers.count == 1 { @@ -647,7 +644,8 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph do { try context!.save() - print("Saved a new message for \(decodedInfo.packet.id)") + print("πŸ’Ύ Saved a new message for \(decodedInfo.packet.id)") + if meshLoggingEnabled { MeshLogger.log("πŸ’Ύ Saved a new message for \(decodedInfo.packet.id)") } // Create an iOS Notification for the received message and schedule it immediately let manager = LocalNotificationManager() @@ -660,19 +658,19 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph content: messageText) ] manager.schedule() - if meshLoggingEnabled { MeshLogger.log("iOS Notification Scheduled for text message from \(newMessage.fromUser?.longName ?? "Unknown") \(messageText)") } + if meshLoggingEnabled { MeshLogger.log("πŸ’¬ iOS Notification Scheduled for text message from \(newMessage.fromUser?.longName ?? "Unknown") \(messageText)") } } catch { context!.rollback() let nsError = error as NSError - print("Failed to save new MessageEntity \(nsError)") + print("πŸ’₯ Failed to save new MessageEntity \(nsError)") } } catch { - print("Fetch Message To and From Users Error") + print("πŸ’₯ Fetch Message To and From Users Error") } } } else if decodedInfo.packet.decoded.portnum == PortNum.nodeinfoApp { @@ -699,21 +697,21 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph try context!.save() if meshLoggingEnabled { - MeshLogger.log("MESH PACKET Updated NodeInfo SNR and Time from Node Info App Packet For: \(Int64(decodedInfo.nodeInfo.num))") + MeshLogger.log("πŸ’Ύ Updated NodeInfo SNR and Time from Node Info App Packet For: \(Int64(decodedInfo.nodeInfo.num))") } - print("Updated NodeInfo SNR and Time from Packet For: \(fetchedNode[0].num)") + print("πŸ’Ύ Updated NodeInfo SNR and Time from Packet For: \(fetchedNode[0].num)") } catch { context!.rollback() let nsError = error as NSError - print("Error Saving NodeInfoEntity from NODEINFO_APP \(nsError)") + print("πŸ’₯ Error Saving NodeInfoEntity from NODEINFO_APP \(nsError)") } } catch { - print("Error Fetching NodeInfoEntity for NODEINFO_APP") + print("πŸ’₯ Error Fetching NodeInfoEntity for NODEINFO_APP") } print(decodedInfo.packet.decoded.payload) @@ -760,32 +758,33 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph context!.rollback() let nsError = error as NSError - print("Error Saving NodeInfoEntity from NODEINFO_APP \(nsError)") + print("πŸ’₯ Error Saving NodeInfoEntity from NODEINFO_APP \(nsError)") } } catch { - print("Error Fetching NodeInfoEntity for NODEINFO_APP") + print("πŸ’₯ Error Fetching NodeInfoEntity for NODEINFO_APP") } } else if decodedInfo.packet.decoded.portnum == PortNum.adminApp { - if meshLoggingEnabled { MeshLogger.log("MESH PACKET received for Admin App UNHANDLED \(try decodedInfo.packet.jsonString())") } - print("Admin App Packet") - print(try decodedInfo.packet.jsonString()) + if meshLoggingEnabled { MeshLogger.log("🚨 MESH PACKET received for Admin App UNHANDLED \(try decodedInfo.packet.jsonString())") } + print("🚨 MESH PACKET received for Admin App UNHANDLED \(try decodedInfo.packet.jsonString())") + } else if decodedInfo.packet.decoded.portnum == PortNum.routingApp { - if meshLoggingEnabled { MeshLogger.log("MESH PACKET received for Routing App UNHANDLED \(try decodedInfo.packet.jsonString())") } - print("Routing App Packet") - print(try decodedInfo.packet.jsonString()) + 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 Other App UNHANDLED \(try decodedInfo.packet.jsonString())") } - print("Other App Packet") - print(try decodedInfo.packet.jsonString()) + + if meshLoggingEnabled { MeshLogger.log("🚨 MESH PACKET received for Other App UNHANDLED \(try decodedInfo.packet.jsonString())") } + print("🚨 MESH PACKET received for Other App UNHANDLED \(try decodedInfo.packet.jsonString())") + } } catch { - if meshLoggingEnabled { MeshLogger.log("Fatal Error: Failed to decode json") } - fatalError("Failed to decode json") + if meshLoggingEnabled { MeshLogger.log("⚰️ Fatal Error: Failed to decode json") } + print("⚰️ Fatal Error: Failed to decode json") } } @@ -798,8 +797,8 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph } default: - if meshLoggingEnabled { MeshLogger.log("Unhandled Characteristic UUID: \(characteristic.uuid)") } - print("Unhandled Characteristic UUID: \(characteristic.uuid)") + if meshLoggingEnabled { MeshLogger.log("🚨 Unhandled Characteristic UUID: \(characteristic.uuid)") } + print("🚨 Unhandled Characteristic UUID: \(characteristic.uuid)") } peripheral.readValue(for: FROMRADIO_characteristic) } @@ -826,7 +825,9 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph connectTo(peripheral: lastConnectedPeripheral!.peripheral) } } - print("Failed in the top message condition") + print("🚫 Message Send Failed, not properly connected to \(lastConnectedPeripheral)") + if meshLoggingEnabled { MeshLogger.log("🚫 Message Send Failed, not properly connected to \(lastConnectedPeripheral)") } + success = false } else if message.count < 1 { // Don's send an empty message @@ -892,7 +893,8 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph do { try context!.save() - print("Saved a new sent message from \(connectedPeripheral.num)") + print("πŸ’Ύ Saved a new sent message from \(newMessage.fromUser?.longName! ?? "Unknown")") + if meshLoggingEnabled { MeshLogger.log("πŸ’Ύ Saved a new sent message from \(connectedPeripheral.num)") } success = true nextSentMessageId+=1 diff --git a/MeshtasticClient/Views/Messages/Contacts.swift b/MeshtasticClient/Views/Messages/Contacts.swift new file mode 100644 index 00000000..66093924 --- /dev/null +++ b/MeshtasticClient/Views/Messages/Contacts.swift @@ -0,0 +1,20 @@ +// +// Contacts.swift +// MeshtasticClient +// +// Created by Garth Vander Houwen on 12/21/21. +// + +import SwiftUI + +struct Contacts: View { + var body: some View { + Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/) + } +} + +struct Contacts_Previews: PreviewProvider { + static var previews: some View { + Contacts() + } +} diff --git a/MeshtasticClient/Views/Messages/Messages.swift b/MeshtasticClient/Views/Messages/Messages.swift index 92a1d1a6..990f13a4 100644 --- a/MeshtasticClient/Views/Messages/Messages.swift +++ b/MeshtasticClient/Views/Messages/Messages.swift @@ -49,7 +49,6 @@ struct Messages: View { HStack(alignment: .top) { let currentUser: Bool = (bleManager.connectedPeripheral == nil) ? false : ((bleManager.connectedPeripheral != nil && bleManager.connectedPeripheral.num == message.fromUser?.num) ? true : false ) - //let currentUser: (Bool = message.fromUser == nil : false : (message.fromUser != nil && bleManager.connectedPeripheral.num == message.fromUser!.num : true) CircleText(text: (message.fromUser?.shortName ?? "???"), color: currentUser ? .accentColor : Color(.darkGray)).padding(.all, 5) .gesture(LongPressGesture(minimumDuration: 2)