From 0fa95d89ec15a98476d277326486895a27b77ae3 Mon Sep 17 00:00:00 2001 From: Garth Vander Houwen Date: Tue, 20 Sep 2022 19:32:29 -0700 Subject: [PATCH] Channel updates, require 1.3.41 version --- Meshtastic.xcodeproj/project.pbxproj | 8 ----- Meshtastic/Enums/SerialConfigEnums.swift | 28 ++++++++++------ Meshtastic/Helpers/BLEManager.swift | 17 +++++++++- Meshtastic/Helpers/MeshPackets.swift | 33 ++----------------- Meshtastic/Model/PeripheralModel.swift | 4 ++- Meshtastic/Views/Bluetooth/Connect.swift | 2 +- .../Config/Module/CannedMessagesConfig.swift | 8 ++--- 7 files changed, 45 insertions(+), 55 deletions(-) diff --git a/Meshtastic.xcodeproj/project.pbxproj b/Meshtastic.xcodeproj/project.pbxproj index a30f1345..2e3a87f1 100644 --- a/Meshtastic.xcodeproj/project.pbxproj +++ b/Meshtastic.xcodeproj/project.pbxproj @@ -269,13 +269,6 @@ path = Custom; sourceTree = ""; }; - DD2160AC28C5019400C17253 /* Messages */ = { - isa = PBXGroup; - children = ( - ); - path = Messages; - sourceTree = ""; - }; DD47E3CA26F0E50300029299 /* Nodes */ = { isa = PBXGroup; children = ( @@ -507,7 +500,6 @@ DDC2E18D26CE25CB0042C5E4 /* Helpers */ = { isa = PBXGroup; children = ( - DD2160AC28C5019400C17253 /* Messages */, DD47E3D526F17ED900029299 /* CircleText.swift */, DD47E3D826F3093800029299 /* MessageBubble.swift */, DD90860B26F684AF00DC5189 /* BatteryIcon.swift */, diff --git a/Meshtastic/Enums/SerialConfigEnums.swift b/Meshtastic/Enums/SerialConfigEnums.swift index ab82e01a..4b27c5a0 100644 --- a/Meshtastic/Enums/SerialConfigEnums.swift +++ b/Meshtastic/Enums/SerialConfigEnums.swift @@ -107,20 +107,23 @@ enum SerialBaudRates: Int, CaseIterable, Identifiable { enum SerialModeTypes: Int, CaseIterable, Identifiable { - case modeDefault = 0 - case modeSimple = 1 - case modeProto = 2 - + case `default` = 0 + case simple = 1 + case proto = 2 + case txtmsg = 3 + var id: Int { self.rawValue } var description: String { get { switch self { - case .modeDefault: + case .default: return "Default" - case .modeSimple: + case .simple: return "Simple" - case .modeProto: + case .proto: return "Protobufs" + case .txtmsg: + return "Text Message" } } } @@ -128,12 +131,14 @@ enum SerialModeTypes: Int, CaseIterable, Identifiable { switch self { - case .modeDefault: + case .default: return ModuleConfig.SerialConfig.Serial_Mode.default - case .modeSimple: + case .simple: return ModuleConfig.SerialConfig.Serial_Mode.simple - case .modeProto: + case .proto: return ModuleConfig.SerialConfig.Serial_Mode.proto + case .txtmsg: + return ModuleConfig.SerialConfig.Serial_Mode.textmsg } } } @@ -141,6 +146,7 @@ enum SerialModeTypes: Int, CaseIterable, Identifiable { enum SerialTimeoutIntervals: Int, CaseIterable, Identifiable { case unset = 0 + case oneSecond = 1 case fiveSeconds = 5 case tenSeconds = 10 case fifteenSeconds = 15 @@ -154,6 +160,8 @@ enum SerialTimeoutIntervals: Int, CaseIterable, Identifiable { switch self { case .unset: return "Unset" + case .oneSecond: + return "One Second" case .fiveSeconds: return "Five Seconds" case .tenSeconds: diff --git a/Meshtastic/Helpers/BLEManager.swift b/Meshtastic/Helpers/BLEManager.swift index a7337c94..109c3340 100644 --- a/Meshtastic/Helpers/BLEManager.swift +++ b/Meshtastic/Helpers/BLEManager.swift @@ -204,7 +204,7 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph peripheralName = name } - let newPeripheral = Peripheral(id: peripheral.identifier.uuidString, num: 0, name: peripheralName, shortName: last4Code, longName: peripheralName, lastFourCode: last4Code, firmwareVersion: "Unknown", rssi: RSSI.intValue, bitrate: nil, channelUtilization: nil, airTime: nil, lastUpdate: Date(), subscribed: false, peripheral: peripheral) + let newPeripheral = Peripheral(id: peripheral.identifier.uuidString, num: 0, name: peripheralName, shortName: last4Code, longName: peripheralName, lastFourCode: last4Code, firmwareVersion: "Unknown", rssi: RSSI.intValue, bitrate: nil, channelUtilization: nil, airTime: nil, maxChannels: 0, lastUpdate: Date(), subscribed: false, peripheral: peripheral) let peripheralIndex = peripherals.firstIndex(where: { $0.id == newPeripheral.id }) if peripheralIndex != nil && newPeripheral.peripheral.state != CBPeripheralState.connected { @@ -514,6 +514,7 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph self.connectedPeripheral.firmwareVersion = myInfo!.firmwareVersion ?? "Unknown" self.connectedPeripheral.name = myInfo!.bleName ?? "Unknown" self.connectedPeripheral.longName = myInfo!.bleName ?? "Unknown" + self.connectedPeripheral.maxChannels = myInfo!.maxChannels } } @@ -640,6 +641,20 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph self.connectedPeripheral.subscribed = true peripherals.removeAll(where: { $0.peripheral.state == CBPeripheralState.disconnected }) // Config conplete returns so we don't read the characteristic again + + // Get all the channels + var i: UInt32 = 1; + + Timer.scheduledTimer(withTimeInterval: 0.4, + repeats: true) { timer in + if i == (self.connectedPeripheral.maxChannels + 1) { + timer.invalidate() // invalidate the timer + } else { + + _ = self.getChannel(channelIndex: i, wantResponse: true) + i+=1; + } + } return } diff --git a/Meshtastic/Helpers/MeshPackets.swift b/Meshtastic/Helpers/MeshPackets.swift index af928ad7..cf1fa2d8 100644 --- a/Meshtastic/Helpers/MeshPackets.swift +++ b/Meshtastic/Helpers/MeshPackets.swift @@ -1065,37 +1065,10 @@ func nodeInfoAppPacket (packet: MeshPacket, meshLogging: Bool, context: NSManage func adminAppPacket (packet: MeshPacket, meshLogging: Bool, context: NSManagedObjectContext) { - if let deviceConfig = try? Config.DeviceConfig(serializedData: packet.decoded.payload) { - - print(try! deviceConfig.jsonString()) - - } else if let displayConfig = try? Config.DisplayConfig(serializedData: packet.decoded.payload) { - - print(try! displayConfig.jsonUTF8Data()) - print(displayConfig.gpsFormat) - - } else if let loraConfig = try? Config.LoRaConfig(serializedData: packet.decoded.payload) { - - print(try! loraConfig.jsonUTF8Data()) - print(loraConfig.region) - - } else if let positionConfig = try? Config.PositionConfig(serializedData: packet.decoded.payload) { - - print(try! positionConfig.jsonUTF8Data()) - print(positionConfig.positionBroadcastSecs) - - } else if let powerConfig = try? Config.PowerConfig(serializedData: packet.decoded.payload) { - - print(try! powerConfig.jsonUTF8Data()) - - } else if let channel = try? Channel(serializedData: packet.decoded.payload) { - print(try! channel.jsonUTF8Data()) - print("channel settings:", channel.settings) + if let channelMessage = try? Channel(serializedData: packet.decoded.payload) { + + if meshLogging { MeshLogger.log("ℹ️ Channel Message received for Admin App \(try! channelMessage.jsonString())") } } - - - if meshLogging { MeshLogger.log("ℹ️ MESH PACKET received for Admin App UNHANDLED \(try! packet.jsonString())") } - } func positionPacket (packet: MeshPacket, meshLogging: Bool, context: NSManagedObjectContext) { diff --git a/Meshtastic/Model/PeripheralModel.swift b/Meshtastic/Model/PeripheralModel.swift index cfdadc44..8587a795 100644 --- a/Meshtastic/Model/PeripheralModel.swift +++ b/Meshtastic/Model/PeripheralModel.swift @@ -13,11 +13,12 @@ struct Peripheral: Identifiable { var bitrate: Float? var channelUtilization: Float? var airTime: Float? + var maxChannels: Int32 var lastUpdate: Date var subscribed: Bool var peripheral: CBPeripheral - init(id: String, num: Int64, name: String, shortName: String, longName: String, lastFourCode: String, firmwareVersion: String, rssi: Int, bitrate: Float?, channelUtilization: Float?, airTime: Float?, lastUpdate: Date, subscribed: Bool, peripheral: CBPeripheral) { + init(id: String, num: Int64, name: String, shortName: String, longName: String, lastFourCode: String, firmwareVersion: String, rssi: Int, bitrate: Float?, channelUtilization: Float?, airTime: Float?, maxChannels: Int32, lastUpdate: Date, subscribed: Bool, peripheral: CBPeripheral) { self.id = id self.num = num self.name = name @@ -29,6 +30,7 @@ struct Peripheral: Identifiable { self.bitrate = bitrate self.channelUtilization = channelUtilization self.airTime = airTime + self.maxChannels = maxChannels self.lastUpdate = lastUpdate self.subscribed = subscribed self.peripheral = peripheral diff --git a/Meshtastic/Views/Bluetooth/Connect.swift b/Meshtastic/Views/Bluetooth/Connect.swift index 405cff0d..c6e6de9d 100644 --- a/Meshtastic/Views/Bluetooth/Connect.swift +++ b/Meshtastic/Views/Bluetooth/Connect.swift @@ -20,7 +20,7 @@ struct Connect: View { @State var isPreferredRadio: Bool = false @State var firmwareVersion = "0.0.0" - @State var minimumVersion = "1.3.40" + @State var minimumVersion = "1.3.41" @State var invalidVersion = false var body: some View { diff --git a/Meshtastic/Views/Settings/Config/Module/CannedMessagesConfig.swift b/Meshtastic/Views/Settings/Config/Module/CannedMessagesConfig.swift index 02ca60df..ef2c77a1 100644 --- a/Meshtastic/Views/Settings/Config/Module/CannedMessagesConfig.swift +++ b/Meshtastic/Views/Settings/Config/Module/CannedMessagesConfig.swift @@ -309,11 +309,11 @@ struct CannedMessagesConfig: View { if newPreset == 1 { // RAK Rotary Encoder - updown1Enabled = true + updown1Enabled = false rotary1Enabled = false - inputbrokerPinA = 4 - inputbrokerPinB = 10 - inputbrokerPinPress = 3 + inputbrokerPinA = 32 + inputbrokerPinB = 38 + inputbrokerPinPress = 37 inputbrokerEventCw = InputEventChars.keyUp.rawValue inputbrokerEventCcw = InputEventChars.keyDown.rawValue inputbrokerEventPress = InputEventChars.keySelect.rawValue