Handle new FROMRADIO UUID

This commit is contained in:
Garth Vander Houwen 2022-10-11 14:25:59 -07:00
parent b5b6e41776
commit c3bd5a7300
4 changed files with 61 additions and 85 deletions

View file

@ -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

View file

@ -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)
}

View file

@ -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()
}
}
}

View file

@ -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