diff --git a/Meshtastic/Helpers/BLEManager.swift b/Meshtastic/Helpers/BLEManager.swift index b04f5cb6..b7b3a602 100644 --- a/Meshtastic/Helpers/BLEManager.swift +++ b/Meshtastic/Helpers/BLEManager.swift @@ -462,9 +462,9 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph decodedInfo = try FromRadio(serializedData: characteristic.value!) } catch { - print(characteristic.value!) } + switch decodedInfo.packet.decoded.portnum { // Handle Any local only packets we get over BLE @@ -1280,6 +1280,55 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph return 0 } + public func getChannel(channelIndex: UInt32, wantResponse: Bool) -> Bool { + + var adminPacket = AdminMessage() + adminPacket.getChannelRequest = channelIndex + + + var meshPacket: MeshPacket = MeshPacket() + meshPacket.to = UInt32(connectedPeripheral.num) + meshPacket.from = 0 //UInt32(connectedPeripheral.num) + meshPacket.id = UInt32.random(in: UInt32(UInt8.max).. Bool { var adminPacket = AdminMessage() diff --git a/Meshtastic/Helpers/MeshPackets.swift b/Meshtastic/Helpers/MeshPackets.swift index 332d1a1f..a024ad3c 100644 --- a/Meshtastic/Helpers/MeshPackets.swift +++ b/Meshtastic/Helpers/MeshPackets.swift @@ -1355,6 +1355,9 @@ func adminAppPacket (packet: MeshPacket, meshLogging: Bool, context: NSManagedOb print(try! powerConfig.jsonUTF8Data()) print(powerConfig.meshSdsTimeoutSecs) + } else if let channel = try? Channel(serializedData: packet.decoded.payload) { + print(try! channel.jsonUTF8Data()) + print("channel settings:", channel.settings) } @@ -1429,6 +1432,7 @@ func positionPacket (packet: MeshPacket, meshLogging: Bool, context: NSManagedOb } func routingPacket (packet: MeshPacket, meshLogging: Bool, context: NSManagedObjectContext) { + print("Routing packet", packet) if let routingMessage = try? Routing(serializedData: packet.decoded.payload) { diff --git a/Meshtastic/MeshtasticApp.swift b/Meshtastic/MeshtasticApp.swift index e59de623..679ebb1d 100644 --- a/Meshtastic/MeshtasticApp.swift +++ b/Meshtastic/MeshtasticApp.swift @@ -12,7 +12,7 @@ struct MeshtasticAppleApp: App { @ObservedObject private var userSettings: UserSettings = UserSettings() @State var saveQR = false - @State private var channelUrl: URL? + @State var channelUrl: URL? @Environment(\.scenePhase) var scenePhase @@ -26,20 +26,28 @@ struct MeshtasticAppleApp: App { .onContinueUserActivity(NSUserActivityTypeBrowsingWeb) { userActivity in print("QR Code URL received from the Camera \(userActivity)") - guard let channelUrl = userActivity.webpageURL else { - return + channelUrl = userActivity.webpageURL + if channelUrl!.absoluteString.lowercased().contains("https://meshtastic.org/e/#") { + saveQR = true } - - print("User wants to open URL: \(channelUrl)") - saveQR = true + + print("User wants to open URL: \(channelUrl?.relativeString)") } .sheet(isPresented: $saveQR) { - SaveChannelQRCode(channelHash: channelUrl) + SaveChannelQRCode(channelHash: channelUrl?.absoluteString ?? "Empty Channel URL") } .onOpenURL(perform: { (url) in + print("QR Code URL received from the Camera \(url)") + channelUrl = url + print("User wants to open URL: \(channelUrl?.absoluteString ?? "No QR Code Link")") + + if url.absoluteString.lowercased().contains("https://meshtastic.org/e/#") { + saveQR = true + } + //we are expecting a .mbtiles map file that contains raster data //save it to the documents directory, and name it offline_map.mbtiles let fileManager = FileManager.default diff --git a/Meshtastic/Views/Settings/SaveChannelQRCode.swift b/Meshtastic/Views/Settings/SaveChannelQRCode.swift index 650a0e9d..4024f861 100644 --- a/Meshtastic/Views/Settings/SaveChannelQRCode.swift +++ b/Meshtastic/Views/Settings/SaveChannelQRCode.swift @@ -8,7 +8,7 @@ import SwiftUI struct SaveChannelQRCode: View { - var channelHash: URL? + var channelHash: String var body: some View { @@ -22,7 +22,7 @@ struct SaveChannelQRCode: View { .font(.callout) .padding() - Text(String(channelHash?.path ?? "URL did not pass through properly")) + Text(channelHash) .font(.title2) .padding() diff --git a/Meshtastic/Views/Settings/ShareChannel.swift b/Meshtastic/Views/Settings/ShareChannel.swift index d2eb08e0..36a85f2e 100644 --- a/Meshtastic/Views/Settings/ShareChannel.swift +++ b/Meshtastic/Views/Settings/ShareChannel.swift @@ -87,6 +87,13 @@ struct ShareChannel: View { .onAppear { self.bleManager.context = context + let i: UInt32 = 1; +// while i < 9 { // this should actually loop over MyNodeInfo.maxChannels to get all channels + print("requesting channel",i) + let resp = self.bleManager.getChannel(channelIndex: i, wantResponse: true) + print("resp from getChannel", resp) +// i+=1; +// } } }