From c3bd5a73003dc04a91e6aa1950b320e7968568bf Mon Sep 17 00:00:00 2001 From: Garth Vander Houwen Date: Tue, 11 Oct 2022 14:25:59 -0700 Subject: [PATCH] Handle new FROMRADIO UUID --- Meshtastic/Helpers/BLEManager.swift | 44 ++++++--------- Meshtastic/MeshtasticApp.swift | 2 +- .../Views/Bluetooth/InvalidVersion.swift | 55 ++++++++----------- .../Views/Settings/SaveChannelQRCode.swift | 45 ++++++++------- 4 files changed, 61 insertions(+), 85 deletions(-) diff --git a/Meshtastic/Helpers/BLEManager.swift b/Meshtastic/Helpers/BLEManager.swift index 2b74a13a..76b43972 100644 --- a/Meshtastic/Helpers/BLEManager.swift +++ b/Meshtastic/Helpers/BLEManager.swift @@ -43,9 +43,6 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph var timeoutTimer: Timer? var timeoutTimerCount = 0 - - var configTimeoutTimer: Timer? - var positionTimer: Timer? let broadcastNodeNum: UInt32 = 4294967295 @@ -57,7 +54,8 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph let meshtasticServiceCBUUID = CBUUID(string: "0x6BA1B218-15A8-461F-9FA8-5DCAE273EAFD") let TORADIO_UUID = CBUUID(string: "0xF75C76D2-129E-4DAD-A1DD-7866124401E7") - let FROMRADIO_UUID = CBUUID(string: "0x8BA2BCC2-EE02-4A55-A531-C525C5E454D5") + let FROMRADIO_UUID = CBUUID(string: "2c55e69e-4993-11ed-b878-0242ac120002") + let EOL_FROMRADIO_UUID = CBUUID(string: "0x8BA2BCC2-EE02-4A55-A531-C525C5E454D5") let FROMNUM_UUID = CBUUID(string: "0xED9DA18C-A800-4F66-A670-AA7547E34453") // Meshtastic DFU details @@ -160,20 +158,6 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph if meshLoggingEnabled { MeshLogger.log("🚨 BLE Connecting 2 Second Timeout Timer Fired \(timeoutTimerCount) Time(s): \(name)") } } } - - // MARK: BLE Connect functions - /// The action after the timeout-timer has fired - /// - /// - Parameters: - /// - timer: The time that fired the event - /// - @objc func configTimeoutTimerFired(timer: Timer) { - - self.lastConnectionError = "🚨 Update your firmware" - self.connectedVersion = "1.2.65" - self.invalidVersion = true - self.timeoutTimer!.invalidate() - } // Connect to a specific peripheral func connectTo(peripheral: CBPeripheral) { @@ -209,6 +193,7 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph guard let connectedPeripheral = connectedPeripheral else { return } centralManager?.cancelPeripheralConnection(connectedPeripheral.peripheral) + FROMRADIO_characteristic = nil isConnected = false invalidVersion = false connectedVersion = "0.0.0" @@ -393,6 +378,10 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph for characteristic in characteristics { switch characteristic.uuid { + case EOL_FROMRADIO_UUID: + if meshLoggingEnabled { MeshLogger.log("🚨 BLE did discover EOL_TORADIO characteristic for Meshtastic by \(peripheral.name ?? "Unknown")") } + invalidVersion = true + case TORADIO_UUID: if meshLoggingEnabled { MeshLogger.log("✅ BLE did discover TORADIO characteristic for Meshtastic by \(peripheral.name ?? "Unknown")") } @@ -444,12 +433,9 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph break } } - if (![FROMNUM_characteristic, FROMNUM_characteristic, TORADIO_characteristic].contains(nil)) { + if (![FROMNUM_characteristic, TORADIO_characteristic].contains(nil)) { sendWantConfig() - - self.configTimeoutTimer = Timer.scheduledTimer(timeInterval: TimeInterval(30), target: self, selector: #selector(configTimeoutTimerFired), userInfo: context, repeats: false) - RunLoop.current.add(self.configTimeoutTimer!, forMode: .common) } } @@ -487,6 +473,11 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph func sendWantConfig() { guard (connectedPeripheral!.peripheral.state == CBPeripheralState.connected) else { return } + if FROMRADIO_characteristic == nil { + invalidVersion = true + return + + } else { MeshLogger.log("â„šī¸ Issuing wantConfig to \(connectedPeripheral!.peripheral.name ?? "Unknown")") //BLE Characteristics discovered, issue wantConfig var toRadio: ToRadio = ToRadio() @@ -495,8 +486,9 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph let binaryData: Data = try! toRadio.serializedData() connectedPeripheral!.peripheral.writeValue(binaryData, for: TORADIO_characteristic, type: .withResponse) - // Either Read the config complete value or from num notify value - connectedPeripheral!.peripheral.readValue(for: FROMRADIO_characteristic) + // Either Read the config complete value or from num notify value + connectedPeripheral!.peripheral.readValue(for: FROMRADIO_characteristic) + } } func peripheral(_ peripheral: CBPeripheral, didUpdateNotificationStateFor characteristic: CBCharacteristic, error: Error?) { @@ -740,10 +732,6 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph invalidVersion = false lastConnectionError = "" - if configTimeoutTimer != nil { - - configTimeoutTimer?.invalidate() - } if meshLoggingEnabled { MeshLogger.log("🤜 BLE Config Complete Packet Id: \(decodedInfo.configCompleteID)") } self.connectedPeripheral.subscribed = true diff --git a/Meshtastic/MeshtasticApp.swift b/Meshtastic/MeshtasticApp.swift index a4f99ec7..7f7f787d 100644 --- a/Meshtastic/MeshtasticApp.swift +++ b/Meshtastic/MeshtasticApp.swift @@ -43,7 +43,7 @@ struct MeshtasticAppleApp: App { } .sheet(isPresented: $saveChannels) { - SaveChannelQRCode(channelHash: channelSettings ?? "Empty Channel URL") + SaveChannelQRCode(channelHash: channelSettings ?? "Empty Channel URL", validUrl: true) .presentationDetents([.medium, .large]) .presentationDragIndicator(.visible) } diff --git a/Meshtastic/Views/Bluetooth/InvalidVersion.swift b/Meshtastic/Views/Bluetooth/InvalidVersion.swift index 5d5d674e..b001d95f 100644 --- a/Meshtastic/Views/Bluetooth/InvalidVersion.swift +++ b/Meshtastic/Views/Bluetooth/InvalidVersion.swift @@ -22,19 +22,11 @@ struct InvalidVersion: View { Divider() VStack { - - if version != "1.2.65" { + - Text("The Meshtastic Apple apps support firmware version \(minimumVersion) and above. You are running version \(version)") + Text("The Meshtastic Apple apps support firmware version \(minimumVersion) and above.") .font(.title2) .padding(.bottom) - - } else { - - Text("The Meshtastic Apple apps support firmware version \(minimumVersion) and above.") - .font(.title2) - .padding(.bottom) - } Link("Firmware update docs", destination: URL(string: "https://meshtastic.org/docs/getting-started/flashing-firmware/")!) .font(.title) @@ -47,32 +39,29 @@ struct InvalidVersion: View { } .padding() + + Divider() + .padding(.top) - if version == "1.2.65" { + VStack{ - Divider() - .padding(.top) + Text("đŸĻ• End of life Version đŸĻ– â˜„ī¸") + .font(.title3) + .foregroundColor(.orange) + .padding(.bottom) - VStack{ - - Text("đŸĻ• End of life Version đŸĻ– â˜„ī¸") - .font(.title3) - .foregroundColor(.orange) - .padding(.bottom) - - Text("Version \(minimumVersion) includes breaking changes to devices and the client apps. Only nodes version \(minimumVersion) and above are supported.") - .font(.caption) - .padding([.leading, .trailing]) - - Text("There is a build for 1.2 EOL under Other Versions in TestFlight that will be available until the end of November 2022.") - .font(.caption) - .padding() - - Link("Version 1.2 End of life (EOL) Info", destination: URL(string: "https://meshtastic.org/docs/1.2-End-of-life/")!) - .font(.callout) - - }.padding() - } + Text("Version \(minimumVersion) includes breaking changes to devices and the client apps. Only nodes version \(minimumVersion) and above are supported.") + .font(.caption) + .padding([.leading, .trailing]) + + Text("There is a build for 1.2 EOL under Other Versions in TestFlight that will be available until the end of November 2022.") + .font(.caption) + .padding() + + Link("Version 1.2 End of life (EOL) Info", destination: URL(string: "https://meshtastic.org/docs/1.2-End-of-life/")!) + .font(.callout) + + }.padding() } } } diff --git a/Meshtastic/Views/Settings/SaveChannelQRCode.swift b/Meshtastic/Views/Settings/SaveChannelQRCode.swift index 5ff03068..feacdb70 100644 --- a/Meshtastic/Views/Settings/SaveChannelQRCode.swift +++ b/Meshtastic/Views/Settings/SaveChannelQRCode.swift @@ -7,33 +7,32 @@ import SwiftUI struct SaveChannelQRCode: View { - var channelHash: String + var validUrl: Bool var body: some View { - VStack { - - Text("Save Channel Settings?") - .font(.title) - - Text("These settings will replace the current settings on your radio.") - .foregroundColor(.gray) - .font(.callout) - .padding() - - Text(channelHash) - .font(.caption2) - .padding() - - Text("Error Message") - .font(.callout) - .foregroundColor(.red) - .padding() - - - Text("Swipe down to dismiss.") - .padding() + if validUrl { + Text("Save Channel Settings?") + .font(.title) + Text("These settings will replace the current settings on your radio.") + .foregroundColor(.gray) + .font(.callout) + .padding() + + Text(channelHash) + .font(.caption2) + .padding() + + } else { + Text("Invalid Channel Settings Url") + .font(.title) + + Text("Error Message") + .font(.callout) + .foregroundColor(.red) + .padding() + } } .onChange(of: channelHash) { newSettings in