From 091874a9f22a9603b083dffb7755d72de42dd85e Mon Sep 17 00:00:00 2001 From: Garth Vander Houwen Date: Sat, 22 Oct 2022 08:45:53 -0700 Subject: [PATCH 1/6] Add flip screen display config option --- Meshtastic/Helpers/BLEManager.swift | 4 ---- Meshtastic/Helpers/MeshPackets.swift | 2 ++ .../MeshtasticDataModel.xcdatamodel/contents | 1 + .../Views/Settings/Config/DisplayConfig.swift | 17 ++++++++++++++++- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/Meshtastic/Helpers/BLEManager.swift b/Meshtastic/Helpers/BLEManager.swift index decabcfc..d1908a5d 100644 --- a/Meshtastic/Helpers/BLEManager.swift +++ b/Meshtastic/Helpers/BLEManager.swift @@ -1091,13 +1091,10 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph toRadio.packet = meshPacket let binaryData: Data = try! toRadio.serializedData() if connectedPeripheral!.peripheral.state == CBPeripheralState.connected { - - //let timer1 = Timer.scheduledTimer(withTimeInterval: 0.1, repeats: false) { timer in self.connectedPeripheral.peripheral.writeValue(binaryData, for: self.TORADIO_characteristic, type: .withResponse) MeshLogger.log("💾 Saved a Channel for: \(String(self.connectedPeripheral.num))") //} - } print(chan) } @@ -1124,7 +1121,6 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph toRadio.packet = meshPacket let binaryData: Data = try! toRadio.serializedData() if connectedPeripheral!.peripheral.state == CBPeripheralState.connected { - // let timer1 = Timer.scheduledTimer(withTimeInterval: 2, repeats: false) { timer in self.connectedPeripheral.peripheral.writeValue(binaryData, for: self.TORADIO_characteristic, type: .withResponse) MeshLogger.log("💾 Saved a LoRaConfig for: \(String(self.connectedPeripheral.num))") diff --git a/Meshtastic/Helpers/MeshPackets.swift b/Meshtastic/Helpers/MeshPackets.swift index 584e325d..87f53ad3 100644 --- a/Meshtastic/Helpers/MeshPackets.swift +++ b/Meshtastic/Helpers/MeshPackets.swift @@ -122,6 +122,7 @@ func localConfig (config: Config, context:NSManagedObjectContext, nodeNum: Int64 newDisplayConfig.screenOnSeconds = Int32(config.display.screenOnSecs) newDisplayConfig.screenCarouselInterval = Int32(config.display.autoScreenCarouselSecs) newDisplayConfig.compassNorthTop = config.display.compassNorthTop + newDisplayConfig.flipScreen = config.display.flipScreen fetchedNode[0].displayConfig = newDisplayConfig } else { @@ -130,6 +131,7 @@ func localConfig (config: Config, context:NSManagedObjectContext, nodeNum: Int64 fetchedNode[0].displayConfig?.screenOnSeconds = Int32(config.display.screenOnSecs) fetchedNode[0].displayConfig?.screenCarouselInterval = Int32(config.display.autoScreenCarouselSecs) fetchedNode[0].displayConfig?.compassNorthTop = config.display.compassNorthTop + fetchedNode[0].displayConfig?.flipScreen = config.display.flipScreen } do { diff --git a/Meshtastic/Meshtastic.xcdatamodeld/MeshtasticDataModel.xcdatamodel/contents b/Meshtastic/Meshtastic.xcdatamodeld/MeshtasticDataModel.xcdatamodel/contents index 71ff5a04..335db518 100644 --- a/Meshtastic/Meshtastic.xcdatamodeld/MeshtasticDataModel.xcdatamodel/contents +++ b/Meshtastic/Meshtastic.xcdatamodeld/MeshtasticDataModel.xcdatamodel/contents @@ -42,6 +42,7 @@ + diff --git a/Meshtastic/Views/Settings/Config/DisplayConfig.swift b/Meshtastic/Views/Settings/Config/DisplayConfig.swift index edea736f..49c77a31 100644 --- a/Meshtastic/Views/Settings/Config/DisplayConfig.swift +++ b/Meshtastic/Views/Settings/Config/DisplayConfig.swift @@ -21,6 +21,7 @@ struct DisplayConfig: View { @State var screenCarouselInterval = 0 @State var gpsFormat = 0 @State var compassNorthTop = false + @State var flipScreen = false var body: some View { @@ -45,7 +46,6 @@ struct DisplayConfig: View { } } .pickerStyle(DefaultPickerStyle()) - Text("Automatically toggles to the next page on the screen like a carousel, based the specified interval.") .font(.caption) @@ -57,6 +57,14 @@ struct DisplayConfig: View { Text("The compass heading on the screen outside of the circle will always point north.") .font(.caption) + Toggle(isOn: $flipScreen) { + + Label("Flip Screen", systemImage: "pip.swap") + } + .toggleStyle(SwitchToggleStyle(tint: .accentColor)) + Text("Flip screen vertically") + .font(.caption) + } Section(header: Text("Format")) { Picker("GPS Format", selection: $gpsFormat ) { @@ -98,6 +106,7 @@ struct DisplayConfig: View { dc.screenOnSecs = UInt32(screenOnSeconds) dc.autoScreenCarouselSecs = UInt32(screenCarouselInterval) dc.compassNorthTop = compassNorthTop + dc.flipScreen = flipScreen let adminMessageId = bleManager.saveDisplayConfig(config: dc, fromUser: node!.user!, toUser: node!.user!) @@ -124,6 +133,7 @@ struct DisplayConfig: View { self.screenOnSeconds = Int(node?.displayConfig?.screenOnSeconds ?? 0) self.screenCarouselInterval = Int(node?.displayConfig?.screenCarouselInterval ?? 0) self.compassNorthTop = node?.displayConfig?.compassNorthTop ?? false + self.flipScreen = node?.displayConfig?.flipScreen ?? false self.hasChanges = false } .onChange(of: screenOnSeconds) { newScreenSecs in @@ -146,6 +156,11 @@ struct DisplayConfig: View { if newGpsFormat != node!.displayConfig!.gpsFormat { hasChanges = true } } } + .onChange(of: flipScreen) { newFlipScreen in + if node != nil && node!.displayConfig != nil { + if newFlipScreen != node!.displayConfig!.flipScreen { hasChanges = true } + } + } .navigationViewStyle(StackNavigationViewStyle()) } } From 288b35d6fc01efe256335c4842d7d3a294d3051d Mon Sep 17 00:00:00 2001 From: Garth Vander Houwen Date: Sat, 22 Oct 2022 13:05:54 -0700 Subject: [PATCH 2/6] QR Code fixes --- Meshtastic/Helpers/BLEManager.swift | 3 --- Meshtastic/Helpers/MeshPackets.swift | 5 +++++ Meshtastic/Views/Settings/ShareChannels.swift | 1 + 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Meshtastic/Helpers/BLEManager.swift b/Meshtastic/Helpers/BLEManager.swift index d1908a5d..75b0fa4c 100644 --- a/Meshtastic/Helpers/BLEManager.swift +++ b/Meshtastic/Helpers/BLEManager.swift @@ -410,11 +410,9 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph guard (connectedPeripheral!.peripheral.state == CBPeripheralState.connected) else { return } if FROMRADIO_characteristic == nil { - MeshLogger.log("🚨 Unsupported Firmware Version Detected, unable to connect to device.") invalidVersion = true return - } else { MeshLogger.log("ℹ️ Issuing wantConfig to \(connectedPeripheral!.peripheral.name ?? "Unknown")") //BLE Characteristics discovered, issue wantConfig @@ -423,7 +421,6 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph toRadio.wantConfigID = configNonce 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) } diff --git a/Meshtastic/Helpers/MeshPackets.swift b/Meshtastic/Helpers/MeshPackets.swift index 87f53ad3..ce9222e8 100644 --- a/Meshtastic/Helpers/MeshPackets.swift +++ b/Meshtastic/Helpers/MeshPackets.swift @@ -773,8 +773,13 @@ func channelPacket (channel: Channel, fromNum: Int64, context: NSManagedObjectCo newChannel.name = channel.settings.name newChannel.role = Int32(channel.role.rawValue) newChannel.psk = channel.settings.psk + let mutableChannels = fetchedMyInfo[0].channels!.mutableCopy() as! NSMutableOrderedSet + if channel.role.rawValue == 1 { + mutableChannels.removeAllObjects() + } + mutableChannels.add(newChannel) fetchedMyInfo[0].channels = mutableChannels.copy() as? NSOrderedSet diff --git a/Meshtastic/Views/Settings/ShareChannels.swift b/Meshtastic/Views/Settings/ShareChannels.swift index e4b8fa2e..dc9d3eb8 100644 --- a/Meshtastic/Views/Settings/ShareChannels.swift +++ b/Meshtastic/Views/Settings/ShareChannels.swift @@ -282,6 +282,7 @@ struct ShareChannels: View { loRaConfig.hopLimit = UInt32(node?.loRaConfig?.hopLimit ?? 3) loRaConfig.txEnabled = node?.loRaConfig?.txEnabled ?? false loRaConfig.txPower = node?.loRaConfig?.txPower ?? 0 + loRaConfig.usePreset = node?.loRaConfig?.usePreset ?? true loRaConfig.channelNum = UInt32(node?.loRaConfig?.channelNum ?? 0) channelSet.loraConfig = loRaConfig if node != nil { From d157cc8d08df44bb21e0e03f9247818b5085dfc2 Mon Sep 17 00:00:00 2001 From: Garth Vander Houwen Date: Tue, 25 Oct 2022 19:46:51 -0700 Subject: [PATCH 3/6] Proto updates, spelling fix --- Meshtastic/Protobufs/config.pb.swift | 181 ++++++++++++++++-- Meshtastic/Protobufs/mesh.pb.swift | 2 +- .../Settings/Config/PositionConfig.swift | 2 +- 3 files changed, 172 insertions(+), 13 deletions(-) diff --git a/Meshtastic/Protobufs/config.pb.swift b/Meshtastic/Protobufs/config.pb.swift index d6942ade..0d7d062e 100644 --- a/Meshtastic/Protobufs/config.pb.swift +++ b/Meshtastic/Protobufs/config.pb.swift @@ -437,11 +437,6 @@ struct Config { /// Enable WiFi (disables Bluetooth) var wifiEnabled: Bool = false - /// - /// If set, this node will try to join the specified wifi network and - /// acquire an address via DHCP - var wifiMode: Config.NetworkConfig.WiFiMode = .client - /// /// If set, this node will try to join the specified wifi network and /// acquire an address via DHCP @@ -455,6 +450,25 @@ struct Config { /// NTP server to use if WiFi is conneced, defaults to `0.pool.ntp.org` var ntpServer: String = String() + /// + /// Enable Ethernet + var ethEnabled: Bool = false + + /// + /// acquire an address via DHCP or assign static + var ethMode: Config.NetworkConfig.EthMode = .dhcp + + /// + /// struct to keep static address + var ethConfig: Config.NetworkConfig.NetworkConfig { + get {return _ethConfig ?? Config.NetworkConfig.NetworkConfig()} + set {_ethConfig = newValue} + } + /// Returns true if `ethConfig` has been explicitly set. + var hasEthConfig: Bool {return self._ethConfig != nil} + /// Clears the value of `ethConfig`. Subsequent reads from it will return its default value. + mutating func clearEthConfig() {self._ethConfig = nil} + var unknownFields = SwiftProtobuf.UnknownStorage() enum WiFiMode: SwiftProtobuf.Enum { @@ -497,7 +511,69 @@ struct Config { } + enum EthMode: SwiftProtobuf.Enum { + typealias RawValue = Int + + /// + /// obtain ip address via DHCP + case dhcp // = 0 + + /// + /// use static ip address + case `static` // = 1 + case UNRECOGNIZED(Int) + + init() { + self = .dhcp + } + + init?(rawValue: Int) { + switch rawValue { + case 0: self = .dhcp + case 1: self = .static + default: self = .UNRECOGNIZED(rawValue) + } + } + + var rawValue: Int { + switch self { + case .dhcp: return 0 + case .static: return 1 + case .UNRECOGNIZED(let i): return i + } + } + + } + + struct NetworkConfig { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + /// + /// Static IP address + var ip: UInt32 = 0 + + /// + /// Static gateway address + var gateway: UInt32 = 0 + + /// + /// Static subnet mask + var subnet: UInt32 = 0 + + /// + /// Static DNS server address + var dns: UInt32 = 0 + + var unknownFields = SwiftProtobuf.UnknownStorage() + + init() {} + } + init() {} + + fileprivate var _ethConfig: Config.NetworkConfig.NetworkConfig? = nil } /// @@ -1002,6 +1078,14 @@ extension Config.NetworkConfig.WiFiMode: CaseIterable { ] } +extension Config.NetworkConfig.EthMode: CaseIterable { + // The compiler won't synthesize support with the UNRECOGNIZED case. + static var allCases: [Config.NetworkConfig.EthMode] = [ + .dhcp, + .static, + ] +} + extension Config.DisplayConfig.GpsCoordinateFormat: CaseIterable { // The compiler won't synthesize support with the UNRECOGNIZED case. static var allCases: [Config.DisplayConfig.GpsCoordinateFormat] = [ @@ -1076,6 +1160,8 @@ extension Config.PositionConfig.PositionFlags: @unchecked Sendable {} extension Config.PowerConfig: @unchecked Sendable {} extension Config.NetworkConfig: @unchecked Sendable {} extension Config.NetworkConfig.WiFiMode: @unchecked Sendable {} +extension Config.NetworkConfig.EthMode: @unchecked Sendable {} +extension Config.NetworkConfig.NetworkConfig: @unchecked Sendable {} extension Config.DisplayConfig: @unchecked Sendable {} extension Config.DisplayConfig.GpsCoordinateFormat: @unchecked Sendable {} extension Config.DisplayConfig.DisplayUnits: @unchecked Sendable {} @@ -1463,10 +1549,12 @@ extension Config.NetworkConfig: SwiftProtobuf.Message, SwiftProtobuf._MessageImp static let protoMessageName: String = Config.protoMessageName + ".NetworkConfig" static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ 1: .standard(proto: "wifi_enabled"), - 2: .standard(proto: "wifi_mode"), 3: .standard(proto: "wifi_ssid"), 4: .standard(proto: "wifi_psk"), 5: .standard(proto: "ntp_server"), + 6: .standard(proto: "eth_enabled"), + 7: .standard(proto: "eth_mode"), + 8: .standard(proto: "eth_config"), ] mutating func decodeMessage(decoder: inout D) throws { @@ -1476,22 +1564,25 @@ extension Config.NetworkConfig: SwiftProtobuf.Message, SwiftProtobuf._MessageImp // enabled. https://github.com/apple/swift-protobuf/issues/1034 switch fieldNumber { case 1: try { try decoder.decodeSingularBoolField(value: &self.wifiEnabled) }() - case 2: try { try decoder.decodeSingularEnumField(value: &self.wifiMode) }() case 3: try { try decoder.decodeSingularStringField(value: &self.wifiSsid) }() case 4: try { try decoder.decodeSingularStringField(value: &self.wifiPsk) }() case 5: try { try decoder.decodeSingularStringField(value: &self.ntpServer) }() + case 6: try { try decoder.decodeSingularBoolField(value: &self.ethEnabled) }() + case 7: try { try decoder.decodeSingularEnumField(value: &self.ethMode) }() + case 8: try { try decoder.decodeSingularMessageField(value: &self._ethConfig) }() default: break } } } func traverse(visitor: inout V) throws { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every if/case branch local when no optimizations + // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and + // https://github.com/apple/swift-protobuf/issues/1182 if self.wifiEnabled != false { try visitor.visitSingularBoolField(value: self.wifiEnabled, fieldNumber: 1) } - if self.wifiMode != .client { - try visitor.visitSingularEnumField(value: self.wifiMode, fieldNumber: 2) - } if !self.wifiSsid.isEmpty { try visitor.visitSingularStringField(value: self.wifiSsid, fieldNumber: 3) } @@ -1501,15 +1592,26 @@ extension Config.NetworkConfig: SwiftProtobuf.Message, SwiftProtobuf._MessageImp if !self.ntpServer.isEmpty { try visitor.visitSingularStringField(value: self.ntpServer, fieldNumber: 5) } + if self.ethEnabled != false { + try visitor.visitSingularBoolField(value: self.ethEnabled, fieldNumber: 6) + } + if self.ethMode != .dhcp { + try visitor.visitSingularEnumField(value: self.ethMode, fieldNumber: 7) + } + try { if let v = self._ethConfig { + try visitor.visitSingularMessageField(value: v, fieldNumber: 8) + } }() try unknownFields.traverse(visitor: &visitor) } static func ==(lhs: Config.NetworkConfig, rhs: Config.NetworkConfig) -> Bool { if lhs.wifiEnabled != rhs.wifiEnabled {return false} - if lhs.wifiMode != rhs.wifiMode {return false} if lhs.wifiSsid != rhs.wifiSsid {return false} if lhs.wifiPsk != rhs.wifiPsk {return false} if lhs.ntpServer != rhs.ntpServer {return false} + if lhs.ethEnabled != rhs.ethEnabled {return false} + if lhs.ethMode != rhs.ethMode {return false} + if lhs._ethConfig != rhs._ethConfig {return false} if lhs.unknownFields != rhs.unknownFields {return false} return true } @@ -1523,6 +1625,63 @@ extension Config.NetworkConfig.WiFiMode: SwiftProtobuf._ProtoNameProviding { ] } +extension Config.NetworkConfig.EthMode: SwiftProtobuf._ProtoNameProviding { + static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 0: .same(proto: "DHCP"), + 1: .same(proto: "STATIC"), + ] +} + +extension Config.NetworkConfig.NetworkConfig: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + static let protoMessageName: String = Config.NetworkConfig.protoMessageName + ".NetworkConfig" + static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "ip"), + 2: .same(proto: "gateway"), + 3: .same(proto: "subnet"), + 4: .same(proto: "dns"), + ] + + mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularFixed32Field(value: &self.ip) }() + case 2: try { try decoder.decodeSingularFixed32Field(value: &self.gateway) }() + case 3: try { try decoder.decodeSingularFixed32Field(value: &self.subnet) }() + case 4: try { try decoder.decodeSingularFixed32Field(value: &self.dns) }() + default: break + } + } + } + + func traverse(visitor: inout V) throws { + if self.ip != 0 { + try visitor.visitSingularFixed32Field(value: self.ip, fieldNumber: 1) + } + if self.gateway != 0 { + try visitor.visitSingularFixed32Field(value: self.gateway, fieldNumber: 2) + } + if self.subnet != 0 { + try visitor.visitSingularFixed32Field(value: self.subnet, fieldNumber: 3) + } + if self.dns != 0 { + try visitor.visitSingularFixed32Field(value: self.dns, fieldNumber: 4) + } + try unknownFields.traverse(visitor: &visitor) + } + + static func ==(lhs: Config.NetworkConfig.NetworkConfig, rhs: Config.NetworkConfig.NetworkConfig) -> Bool { + if lhs.ip != rhs.ip {return false} + if lhs.gateway != rhs.gateway {return false} + if lhs.subnet != rhs.subnet {return false} + if lhs.dns != rhs.dns {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + extension Config.DisplayConfig: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { static let protoMessageName: String = Config.protoMessageName + ".DisplayConfig" static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ diff --git a/Meshtastic/Protobufs/mesh.pb.swift b/Meshtastic/Protobufs/mesh.pb.swift index a548b47f..25cafa14 100644 --- a/Meshtastic/Protobufs/mesh.pb.swift +++ b/Meshtastic/Protobufs/mesh.pb.swift @@ -437,7 +437,7 @@ struct Position { // methods supported on all messages. /// - /// The new preferred location encoding, divide by 1e-7 to get degrees + /// The new preferred location encoding, multiply by 1e-7 to get degrees /// in floating point var latitudeI: Int32 { get {return _storage._latitudeI} diff --git a/Meshtastic/Views/Settings/Config/PositionConfig.swift b/Meshtastic/Views/Settings/Config/PositionConfig.swift index cfd14be3..71db978d 100644 --- a/Meshtastic/Views/Settings/Config/PositionConfig.swift +++ b/Meshtastic/Views/Settings/Config/PositionConfig.swift @@ -138,7 +138,7 @@ struct PositionConfig: View { } .toggleStyle(SwitchToggleStyle(tint: .accentColor)) Toggle(isOn: $includeGeoidalSeparation) { - Label("Altitude Geoidal Seperation", systemImage: "globe.americas") + Label("Altitude Geoidal Separation", systemImage: "globe.americas") } .toggleStyle(SwitchToggleStyle(tint: .accentColor)) } From 8e3a438dbef4d764c863680738d548b9d3ae5e6d Mon Sep 17 00:00:00 2001 From: Garth Vander Houwen Date: Tue, 25 Oct 2022 19:53:25 -0700 Subject: [PATCH 4/6] Remove wifi mode --- Meshtastic.xcodeproj/project.pbxproj | 4 -- Meshtastic/Enums/WiFiModes.swift | 42 ------------------- Meshtastic/Helpers/MeshPackets.swift | 3 -- .../Views/Settings/Config/NetworkConfig.swift | 11 +---- 4 files changed, 1 insertion(+), 59 deletions(-) delete mode 100644 Meshtastic/Enums/WiFiModes.swift diff --git a/Meshtastic.xcodeproj/project.pbxproj b/Meshtastic.xcodeproj/project.pbxproj index 9c794975..48934957 100644 --- a/Meshtastic.xcodeproj/project.pbxproj +++ b/Meshtastic.xcodeproj/project.pbxproj @@ -86,7 +86,6 @@ DDB6ABE228B13FB500384BA1 /* PositionConfigEnums.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDB6ABE128B13FB500384BA1 /* PositionConfigEnums.swift */; }; DDB6ABE428B13FFF00384BA1 /* DisplayEnums.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDB6ABE328B13FFF00384BA1 /* DisplayEnums.swift */; }; DDB6ABE628B1406100384BA1 /* LoraConfigEnums.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDB6ABE528B1406100384BA1 /* LoraConfigEnums.swift */; }; - DDB6ABE828B141AF00384BA1 /* WiFiModes.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDB6ABE728B141AF00384BA1 /* WiFiModes.swift */; }; DDC2E15826CE248E0042C5E4 /* MeshtasticApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDC2E15726CE248E0042C5E4 /* MeshtasticApp.swift */; }; DDC2E15C26CE248F0042C5E4 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = DDC2E15B26CE248F0042C5E4 /* Assets.xcassets */; }; DDC2E15F26CE248F0042C5E4 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = DDC2E15E26CE248F0042C5E4 /* Preview Assets.xcassets */; }; @@ -199,7 +198,6 @@ DDB6ABE128B13FB500384BA1 /* PositionConfigEnums.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PositionConfigEnums.swift; sourceTree = ""; }; DDB6ABE328B13FFF00384BA1 /* DisplayEnums.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DisplayEnums.swift; sourceTree = ""; }; DDB6ABE528B1406100384BA1 /* LoraConfigEnums.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoraConfigEnums.swift; sourceTree = ""; }; - DDB6ABE728B141AF00384BA1 /* WiFiModes.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WiFiModes.swift; sourceTree = ""; }; DDC2E15426CE248E0042C5E4 /* Meshtastic.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Meshtastic.app; sourceTree = BUILT_PRODUCTS_DIR; }; DDC2E15726CE248E0042C5E4 /* MeshtasticApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MeshtasticApp.swift; sourceTree = ""; }; DDC2E15B26CE248F0042C5E4 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; name = Assets.xcassets; path = ../Assets.xcassets; sourceTree = ""; }; @@ -352,7 +350,6 @@ DDB6ABE128B13FB500384BA1 /* PositionConfigEnums.swift */, DD8ED9C7289CE4B900B3B0AB /* RoutingError.swift */, DDB6ABE328B13FFF00384BA1 /* DisplayEnums.swift */, - DDB6ABE728B141AF00384BA1 /* WiFiModes.swift */, DD1925B628CDA5A400720036 /* CannedMessagesConfigEnums.swift */, DD1925B828CDA93900720036 /* SerialConfigEnums.swift */, DDA1C48D28DB49D3009933EC /* ChannelRoles.swift */, @@ -708,7 +705,6 @@ DD5394FE276BA0EF00AD86B1 /* PositionEntityExtension.swift in Sources */, DD913639270DFF4C00D7ACF3 /* LocalNotificationManager.swift in Sources */, DD4C158C2824A91E0032668E /* module_config.pb.swift in Sources */, - DDB6ABE828B141AF00384BA1 /* WiFiModes.swift in Sources */, DD4F23CD28779A3C001D37CB /* EnvironmentMetricsLog.swift in Sources */, DDB6ABD628AE742000384BA1 /* BluetoothConfig.swift in Sources */, DD769E0328D18BF1001A3F05 /* DeviceMetricsLog.swift in Sources */, diff --git a/Meshtastic/Enums/WiFiModes.swift b/Meshtastic/Enums/WiFiModes.swift deleted file mode 100644 index fa229735..00000000 --- a/Meshtastic/Enums/WiFiModes.swift +++ /dev/null @@ -1,42 +0,0 @@ -// -// WiFiModes.swift -// Meshtastic -// -// Copyright(c) Garth Vander Houwen 8/20/22. -// - -import Foundation - -enum WiFiModes: Int, CaseIterable, Identifiable { - - case client = 0 - case accessPoint = 1 - case accessPointHidden = 2 - - var id: Int { self.rawValue } - var description: String { - get { - switch self { - case .client: - return "Client" - case .accessPoint: - return "Software Access Point" - case .accessPointHidden: - return "Software Access Point (Hidden)" - - } - } - } - func protoEnumValue() -> Config.NetworkConfig.WiFiMode { - - switch self { - - case .client: - return Config.NetworkConfig.WiFiMode.client - case .accessPoint: - return Config.NetworkConfig.WiFiMode.accessPoint - case .accessPointHidden: - return Config.NetworkConfig.WiFiMode.accessPointHidden - } - } -} diff --git a/Meshtastic/Helpers/MeshPackets.swift b/Meshtastic/Helpers/MeshPackets.swift index ce9222e8..6f357b41 100644 --- a/Meshtastic/Helpers/MeshPackets.swift +++ b/Meshtastic/Helpers/MeshPackets.swift @@ -242,15 +242,12 @@ func localConfig (config: Config, context:NSManagedObjectContext, nodeNum: Int64 newNetworkConfig.wifiSsid = config.network.wifiSsid newNetworkConfig.wifiPsk = config.network.wifiPsk - newNetworkConfig.wifiMode = Int32(config.network.wifiMode.rawValue) - fetchedNode[0].networkConfig = newNetworkConfig } else { fetchedNode[0].networkConfig?.wifiSsid = config.network.wifiSsid fetchedNode[0].networkConfig?.wifiPsk = config.network.wifiPsk - fetchedNode[0].networkConfig?.wifiMode = Int32(config.network.wifiMode.rawValue) } do { diff --git a/Meshtastic/Views/Settings/Config/NetworkConfig.swift b/Meshtastic/Views/Settings/Config/NetworkConfig.swift index 89ae09fb..fb1939d7 100644 --- a/Meshtastic/Views/Settings/Config/NetworkConfig.swift +++ b/Meshtastic/Views/Settings/Config/NetworkConfig.swift @@ -34,21 +34,13 @@ struct NetworkConfig: View { Text("Enabling WiFi will disable the bluetooth connection to the app.") .font(.title3) - + Toggle(isOn: $wifiEnabled) { Label("Enabled", systemImage: "wifi") } .toggleStyle(SwitchToggleStyle(tint: .accentColor)) - - Picker("Mode", selection: $wifiMode ) { - ForEach(WiFiModes.allCases) { lu in - Text(lu.description) - } - } - .pickerStyle(DefaultPickerStyle()) - HStack { Label("SSID", systemImage: "network") TextField("SSID", text: $wifiSsid) @@ -132,7 +124,6 @@ struct NetworkConfig: View { network.wifiEnabled = self.wifiEnabled network.wifiSsid = self.wifiSsid network.wifiPsk = self.wifiPsk - network.wifiMode = WiFiModes(rawValue: self.wifiMode)?.protoEnumValue() ?? WiFiModes.client.protoEnumValue() let adminMessageId = bleManager.saveWiFiConfig(config: network, fromUser: node!.user!, toUser: node!.user!) From a798699008fd54f7b91e77d7a6da6f4457f63a5d Mon Sep 17 00:00:00 2001 From: Garth Vander Houwen Date: Wed, 26 Oct 2022 09:08:03 -0700 Subject: [PATCH 5/6] Bump version number --- Meshtastic/Helpers/BLEManager.swift | 2 +- Meshtastic/Helpers/MeshPackets.swift | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Meshtastic/Helpers/BLEManager.swift b/Meshtastic/Helpers/BLEManager.swift index 75b0fa4c..c044a005 100644 --- a/Meshtastic/Helpers/BLEManager.swift +++ b/Meshtastic/Helpers/BLEManager.swift @@ -28,7 +28,7 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph @Published var peripherals: [Peripheral] @Published var connectedPeripheral: Peripheral! @Published var lastConnectionError: String - @Published var minimumVersion = "1.3.43" + @Published var minimumVersion = "1.3.48" @Published var connectedVersion: String @Published var invalidVersion = false @Published var preferredPeripheral = false diff --git a/Meshtastic/Helpers/MeshPackets.swift b/Meshtastic/Helpers/MeshPackets.swift index 6f357b41..deabbd53 100644 --- a/Meshtastic/Helpers/MeshPackets.swift +++ b/Meshtastic/Helpers/MeshPackets.swift @@ -773,9 +773,9 @@ func channelPacket (channel: Channel, fromNum: Int64, context: NSManagedObjectCo let mutableChannels = fetchedMyInfo[0].channels!.mutableCopy() as! NSMutableOrderedSet - if channel.role.rawValue == 1 { - mutableChannels.removeAllObjects() - } +// if channel.role.rawValue == 1 { +// mutableChannels.removeAllObjects() +// } mutableChannels.add(newChannel) From dd5bb334974c9b973d9a1283edc4f8ba46acb8a7 Mon Sep 17 00:00:00 2001 From: Garth Vander Houwen Date: Wed, 26 Oct 2022 09:11:07 -0700 Subject: [PATCH 6/6] Peer info proto update --- Meshtastic/Protobufs/mesh.pb.swift | 100 ----------------------------- 1 file changed, 100 deletions(-) diff --git a/Meshtastic/Protobufs/mesh.pb.swift b/Meshtastic/Protobufs/mesh.pb.swift index 25cafa14..8735aca7 100644 --- a/Meshtastic/Protobufs/mesh.pb.swift +++ b/Meshtastic/Protobufs/mesh.pb.swift @@ -1976,17 +1976,6 @@ struct ToRadio { set {payloadVariant = .packet(newValue)} } - /// - /// Information about the peer, sent after the phone sneds want_config_id. - /// Old clients do not send this, which is fine. - var peerInfo: ToRadio.PeerInfo { - get { - if case .peerInfo(let v)? = payloadVariant {return v} - return ToRadio.PeerInfo() - } - set {payloadVariant = .peerInfo(newValue)} - } - /// /// Phone wants radio to send full node db to the phone, This is /// typically the first packet sent to the radio when the phone gets a @@ -2025,10 +2014,6 @@ struct ToRadio { /// Send this packet on the mesh case packet(MeshPacket) /// - /// Information about the peer, sent after the phone sneds want_config_id. - /// Old clients do not send this, which is fine. - case peerInfo(ToRadio.PeerInfo) - /// /// Phone wants radio to send full node db to the phone, This is /// typically the first packet sent to the radio when the phone gets a /// bluetooth connection. The radio will respond by sending back a @@ -2054,10 +2039,6 @@ struct ToRadio { guard case .packet(let l) = lhs, case .packet(let r) = rhs else { preconditionFailure() } return l == r }() - case (.peerInfo, .peerInfo): return { - guard case .peerInfo(let l) = lhs, case .peerInfo(let r) = rhs else { preconditionFailure() } - return l == r - }() case (.wantConfigID, .wantConfigID): return { guard case .wantConfigID(let l) = lhs, case .wantConfigID(let r) = rhs else { preconditionFailure() } return l == r @@ -2072,30 +2053,6 @@ struct ToRadio { #endif } - /// - /// Instead of sending want_config_id as a uint32, newer clients send this structure with information about the client. - struct PeerInfo { - // SwiftProtobuf.Message conformance is added in an extension below. See the - // `Message` and `Message+*Additions` files in the SwiftProtobuf library for - // methods supported on all messages. - - /// - /// The numeric version code for the client application, which in some cases are used to control device behavior (so the device can - /// make assumptions about who is using the API. - var appVersion: UInt32 = 0 - - /// - /// True if the peer device can gateway MQTT packets. - /// If true, the device will not try to send packets to the internet directly, - /// instead it will pass the packets to the peer for dispatching. - /// This feature is optional, if set to false the device will assume the client can not gateway to MQTT. - var mqttGateway: Bool = false - - var unknownFields = SwiftProtobuf.UnknownStorage() - - init() {} - } - init() {} } @@ -2145,7 +2102,6 @@ extension FromRadio: @unchecked Sendable {} extension FromRadio.OneOf_PayloadVariant: @unchecked Sendable {} extension ToRadio: @unchecked Sendable {} extension ToRadio.OneOf_PayloadVariant: @unchecked Sendable {} -extension ToRadio.PeerInfo: @unchecked Sendable {} extension Compressed: @unchecked Sendable {} #endif // swift(>=5.5) && canImport(_Concurrency) @@ -3479,7 +3435,6 @@ extension ToRadio: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBa static let protoMessageName: String = "ToRadio" static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ 1: .same(proto: "packet"), - 2: .standard(proto: "peer_info"), 3: .standard(proto: "want_config_id"), 4: .same(proto: "disconnect"), ] @@ -3503,19 +3458,6 @@ extension ToRadio: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBa self.payloadVariant = .packet(v) } }() - case 2: try { - var v: ToRadio.PeerInfo? - var hadOneofValue = false - if let current = self.payloadVariant { - hadOneofValue = true - if case .peerInfo(let m) = current {v = m} - } - try decoder.decodeSingularMessageField(value: &v) - if let v = v { - if hadOneofValue {try decoder.handleConflictingOneOf()} - self.payloadVariant = .peerInfo(v) - } - }() case 3: try { var v: UInt32? try decoder.decodeSingularUInt32Field(value: &v) @@ -3547,10 +3489,6 @@ extension ToRadio: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBa guard case .packet(let v)? = self.payloadVariant else { preconditionFailure() } try visitor.visitSingularMessageField(value: v, fieldNumber: 1) }() - case .peerInfo?: try { - guard case .peerInfo(let v)? = self.payloadVariant else { preconditionFailure() } - try visitor.visitSingularMessageField(value: v, fieldNumber: 2) - }() case .wantConfigID?: try { guard case .wantConfigID(let v)? = self.payloadVariant else { preconditionFailure() } try visitor.visitSingularUInt32Field(value: v, fieldNumber: 3) @@ -3571,44 +3509,6 @@ extension ToRadio: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBa } } -extension ToRadio.PeerInfo: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { - static let protoMessageName: String = ToRadio.protoMessageName + ".PeerInfo" - static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ - 1: .standard(proto: "app_version"), - 2: .standard(proto: "mqtt_gateway"), - ] - - mutating func decodeMessage(decoder: inout D) throws { - while let fieldNumber = try decoder.nextFieldNumber() { - // The use of inline closures is to circumvent an issue where the compiler - // allocates stack space for every case branch when no optimizations are - // enabled. https://github.com/apple/swift-protobuf/issues/1034 - switch fieldNumber { - case 1: try { try decoder.decodeSingularUInt32Field(value: &self.appVersion) }() - case 2: try { try decoder.decodeSingularBoolField(value: &self.mqttGateway) }() - default: break - } - } - } - - func traverse(visitor: inout V) throws { - if self.appVersion != 0 { - try visitor.visitSingularUInt32Field(value: self.appVersion, fieldNumber: 1) - } - if self.mqttGateway != false { - try visitor.visitSingularBoolField(value: self.mqttGateway, fieldNumber: 2) - } - try unknownFields.traverse(visitor: &visitor) - } - - static func ==(lhs: ToRadio.PeerInfo, rhs: ToRadio.PeerInfo) -> Bool { - if lhs.appVersion != rhs.appVersion {return false} - if lhs.mqttGateway != rhs.mqttGateway {return false} - if lhs.unknownFields != rhs.unknownFields {return false} - return true - } -} - extension Compressed: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { static let protoMessageName: String = "Compressed" static let _protobuf_nameMap: SwiftProtobuf._NameMap = [