From 7e163c863cc0dcc6c3ef2df07bffc376a622912d Mon Sep 17 00:00:00 2001 From: Garth Vander Houwen Date: Tue, 24 May 2022 07:19:40 -0700 Subject: [PATCH] Update Protobufs Add GPS Timestamp to LocationHelper Use GPS Timestamp for position updates --- .../xcshareddata/swiftpm/Package.resolved | 4 +- MeshtasticClient/Helpers/BLEManager.swift | 6 +- MeshtasticClient/Helpers/LocationHelper.swift | 10 + MeshtasticClient/Protobufs/admin.pb.swift | 110 +- MeshtasticClient/Protobufs/channel.pb.swift | 161 +- MeshtasticClient/Protobufs/config.pb.swift | 2059 ++++++++++------- .../Protobufs/deviceonly.pb.swift | 197 +- MeshtasticClient/Protobufs/mesh.pb.swift | 698 +++--- MeshtasticClient/Protobufs/portnums.pb.swift | 9 +- 9 files changed, 1783 insertions(+), 1471 deletions(-) diff --git a/Meshtastic Client.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Meshtastic Client.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 55b7b56c..6685f05b 100644 --- a/Meshtastic Client.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/Meshtastic Client.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -6,8 +6,8 @@ "repositoryURL": "https://github.com/stephencelis/SQLite.swift.git", "state": { "branch": null, - "revision": "4d543d811ee644fa4cc4bfa0be996b4dd6ba0f54", - "version": "0.13.3" + "revision": "60a65015f6402b7c34b9a924f755ca0a73afeeaa", + "version": "0.13.1" } }, { diff --git a/MeshtasticClient/Helpers/BLEManager.swift b/MeshtasticClient/Helpers/BLEManager.swift index 9a1969b2..1c401b24 100644 --- a/MeshtasticClient/Helpers/BLEManager.swift +++ b/MeshtasticClient/Helpers/BLEManager.swift @@ -1057,7 +1057,7 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph var decodedInfo = FromRadio() - decodedInfo = try! FromRadio(serializedData: characteristic.value!) + //decodedInfo = try! FromRadio(serializedData: characteristic.value!) default: print("🚨 Unhandled Characteristic UUID: \(characteristic.uuid)") @@ -1216,7 +1216,7 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph var positionPacket = Position() positionPacket.latitudeI = Int32(LocationHelper.currentLocation.latitude * 1e7) positionPacket.longitudeI = Int32(LocationHelper.currentLocation.longitude * 1e7) - positionPacket.time = UInt32(Date().timeIntervalSince1970) + positionPacket.time = UInt32(LocationHelper.currentTimestamp.timeIntervalSince1970) positionPacket.altitude = Int32(LocationHelper.currentAltitude) var meshPacket = MeshPacket() @@ -1274,7 +1274,7 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph public func getSettings() -> Bool { var adminPacket = AdminMessage() - adminPacket.getRadioRequest = true + //adminPacket.getRadioRequest = true var meshPacket: MeshPacket = MeshPacket() meshPacket.to = UInt32(connectedPeripheral.num) diff --git a/MeshtasticClient/Helpers/LocationHelper.swift b/MeshtasticClient/Helpers/LocationHelper.swift index 3210680b..b4ec565d 100644 --- a/MeshtasticClient/Helpers/LocationHelper.swift +++ b/MeshtasticClient/Helpers/LocationHelper.swift @@ -24,6 +24,16 @@ class LocationHelper: NSObject, ObservableObject { } return altitude } + + static var currentTimestamp: Date { + + guard let timestamp = shared.locationManager.location?.timestamp else { + return Date.now + } + return timestamp + } + + private let locationManager = CLLocationManager() diff --git a/MeshtasticClient/Protobufs/admin.pb.swift b/MeshtasticClient/Protobufs/admin.pb.swift index e6d15c24..0e69a453 100644 --- a/MeshtasticClient/Protobufs/admin.pb.swift +++ b/MeshtasticClient/Protobufs/admin.pb.swift @@ -33,16 +33,6 @@ struct AdminMessage { /// TODO: REPLACE var variant: AdminMessage.OneOf_Variant? = nil - /// - /// Set the radio provisioning for this node - var setRadio: RadioConfig { - get { - if case .setRadio(let v)? = variant {return v} - return RadioConfig() - } - set {variant = .setRadio(newValue)} - } - /// /// Set the owner for this node var setOwner: User { @@ -67,26 +57,6 @@ struct AdminMessage { set {variant = .setChannel(newValue)} } - /// - /// Send the current RadioConfig in the response to this message. - var getRadioRequest: Bool { - get { - if case .getRadioRequest(let v)? = variant {return v} - return false - } - set {variant = .getRadioRequest(newValue)} - } - - /// - /// TODO: REPLACE - var getRadioResponse: RadioConfig { - get { - if case .getRadioResponse(let v)? = variant {return v} - return RadioConfig() - } - set {variant = .getRadioResponse(newValue)} - } - /// /// Send the specified channel in the response to this message /// NOTE: This field is sent with the channel index + 1 (to ensure we never try to send 'zero' - which protobufs treats as not present) @@ -387,9 +357,6 @@ struct AdminMessage { /// /// TODO: REPLACE enum OneOf_Variant: Equatable { - /// - /// Set the radio provisioning for this node - case setRadio(RadioConfig) /// /// Set the owner for this node case setOwner(User) @@ -401,12 +368,6 @@ struct AdminMessage { /// If the client sets a particular channel to be primary, the previous channel will be set to SECONDARY automatically. case setChannel(Channel) /// - /// Send the current RadioConfig in the response to this message. - case getRadioRequest(Bool) - /// - /// TODO: REPLACE - case getRadioResponse(RadioConfig) - /// /// Send the specified channel in the response to this message /// NOTE: This field is sent with the channel index + 1 (to ensure we never try to send 'zero' - which protobufs treats as not present) case getChannelRequest(UInt32) @@ -505,10 +466,6 @@ struct AdminMessage { // allocates stack space for every case branch when no optimizations are // enabled. https://github.com/apple/swift-protobuf/issues/1034 switch (lhs, rhs) { - case (.setRadio, .setRadio): return { - guard case .setRadio(let l) = lhs, case .setRadio(let r) = rhs else { preconditionFailure() } - return l == r - }() case (.setOwner, .setOwner): return { guard case .setOwner(let l) = lhs, case .setOwner(let r) = rhs else { preconditionFailure() } return l == r @@ -517,14 +474,6 @@ struct AdminMessage { guard case .setChannel(let l) = lhs, case .setChannel(let r) = rhs else { preconditionFailure() } return l == r }() - case (.getRadioRequest, .getRadioRequest): return { - guard case .getRadioRequest(let l) = lhs, case .getRadioRequest(let r) = rhs else { preconditionFailure() } - return l == r - }() - case (.getRadioResponse, .getRadioResponse): return { - guard case .getRadioResponse(let l) = lhs, case .getRadioResponse(let r) = rhs else { preconditionFailure() } - return l == r - }() case (.getChannelRequest, .getChannelRequest): return { guard case .getChannelRequest(let l) = lhs, case .getChannelRequest(let r) = rhs else { preconditionFailure() } return l == r @@ -658,7 +607,7 @@ struct AdminMessage { /// /// TODO: REPLACE - case gpsConfig // = 1 + case positionConfig // = 1 /// /// TODO: REPLACE @@ -684,7 +633,7 @@ struct AdminMessage { init?(rawValue: Int) { switch rawValue { case 0: self = .deviceConfig - case 1: self = .gpsConfig + case 1: self = .positionConfig case 2: self = .powerConfig case 3: self = .wifiConfig case 4: self = .displayConfig @@ -696,7 +645,7 @@ struct AdminMessage { var rawValue: Int { switch self { case .deviceConfig: return 0 - case .gpsConfig: return 1 + case .positionConfig: return 1 case .powerConfig: return 2 case .wifiConfig: return 3 case .displayConfig: return 4 @@ -782,7 +731,7 @@ extension AdminMessage.ConfigType: CaseIterable { // The compiler won't synthesize support with the UNRECOGNIZED case. static var allCases: [AdminMessage.ConfigType] = [ .deviceConfig, - .gpsConfig, + .positionConfig, .powerConfig, .wifiConfig, .displayConfig, @@ -817,11 +766,8 @@ extension AdminMessage.ModuleConfigType: @unchecked Sendable {} extension AdminMessage: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { static let protoMessageName: String = "AdminMessage" static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ - 1: .standard(proto: "set_radio"), 2: .standard(proto: "set_owner"), 3: .standard(proto: "set_channel"), - 4: .standard(proto: "get_radio_request"), - 5: .standard(proto: "get_radio_response"), 6: .standard(proto: "get_channel_request"), 7: .standard(proto: "get_channel_response"), 8: .standard(proto: "get_owner_request"), @@ -859,19 +805,6 @@ extension AdminMessage: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementat // 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 { - var v: RadioConfig? - var hadOneofValue = false - if let current = self.variant { - hadOneofValue = true - if case .setRadio(let m) = current {v = m} - } - try decoder.decodeSingularMessageField(value: &v) - if let v = v { - if hadOneofValue {try decoder.handleConflictingOneOf()} - self.variant = .setRadio(v) - } - }() case 2: try { var v: User? var hadOneofValue = false @@ -898,27 +831,6 @@ extension AdminMessage: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementat self.variant = .setChannel(v) } }() - case 4: try { - var v: Bool? - try decoder.decodeSingularBoolField(value: &v) - if let v = v { - if self.variant != nil {try decoder.handleConflictingOneOf()} - self.variant = .getRadioRequest(v) - } - }() - case 5: try { - var v: RadioConfig? - var hadOneofValue = false - if let current = self.variant { - hadOneofValue = true - if case .getRadioResponse(let m) = current {v = m} - } - try decoder.decodeSingularMessageField(value: &v) - if let v = v { - if hadOneofValue {try decoder.handleConflictingOneOf()} - self.variant = .getRadioResponse(v) - } - }() case 6: try { var v: UInt32? try decoder.decodeSingularUInt32Field(value: &v) @@ -1192,10 +1104,6 @@ extension AdminMessage: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementat // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and // https://github.com/apple/swift-protobuf/issues/1182 switch self.variant { - case .setRadio?: try { - guard case .setRadio(let v)? = self.variant else { preconditionFailure() } - try visitor.visitSingularMessageField(value: v, fieldNumber: 1) - }() case .setOwner?: try { guard case .setOwner(let v)? = self.variant else { preconditionFailure() } try visitor.visitSingularMessageField(value: v, fieldNumber: 2) @@ -1204,14 +1112,6 @@ extension AdminMessage: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementat guard case .setChannel(let v)? = self.variant else { preconditionFailure() } try visitor.visitSingularMessageField(value: v, fieldNumber: 3) }() - case .getRadioRequest?: try { - guard case .getRadioRequest(let v)? = self.variant else { preconditionFailure() } - try visitor.visitSingularBoolField(value: v, fieldNumber: 4) - }() - case .getRadioResponse?: try { - guard case .getRadioResponse(let v)? = self.variant else { preconditionFailure() } - try visitor.visitSingularMessageField(value: v, fieldNumber: 5) - }() case .getChannelRequest?: try { guard case .getChannelRequest(let v)? = self.variant else { preconditionFailure() } try visitor.visitSingularUInt32Field(value: v, fieldNumber: 6) @@ -1343,7 +1243,7 @@ extension AdminMessage: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementat extension AdminMessage.ConfigType: SwiftProtobuf._ProtoNameProviding { static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ 0: .same(proto: "DEVICE_CONFIG"), - 1: .same(proto: "GPS_CONFIG"), + 1: .same(proto: "POSITION_CONFIG"), 2: .same(proto: "POWER_CONFIG"), 3: .same(proto: "WIFI_CONFIG"), 4: .same(proto: "DISPLAY_CONFIG"), diff --git a/MeshtasticClient/Protobufs/channel.pb.swift b/MeshtasticClient/Protobufs/channel.pb.swift index bb901196..ec08f301 100644 --- a/MeshtasticClient/Protobufs/channel.pb.swift +++ b/MeshtasticClient/Protobufs/channel.pb.swift @@ -45,38 +45,6 @@ struct ChannelSettings { // `Message` and `Message+*Additions` files in the SwiftProtobuf library for // methods supported on all messages. - /// - /// If zero then, use default max legal continuous power (ie. something that won't - /// burn out the radio hardware) - /// In most cases you should use zero here. - /// Units are in dBm. - var txPower: Int32 = 0 - - /// - /// Note: This is the 'old' mechanism for specifying channel parameters. - /// Either modem_config or bandwidth/spreading/coding will be specified - NOT BOTH. - /// As a heuristic: If bandwidth is specified, do not use modem_config. - /// Because protobufs take ZERO space when the value is zero this works out nicely. - /// This value is replaced by bandwidth/spread_factor/coding_rate. - /// If you'd like to experiment with other options add them to MeshRadio.cpp in the device code. - var modemConfig: ChannelSettings.ModemConfig = .vlongSlow - - /// - /// Bandwidth in MHz - /// Certain bandwidth numbers are 'special' and will be converted to the - /// appropriate floating point value: 31 -> 31.25MHz - var bandwidth: UInt32 = 0 - - /// - /// A number from 7 to 12. - /// Indicates number of chirps per symbol as 1<=4.2) - -extension ChannelSettings.ModemConfig: CaseIterable { - // The compiler won't synthesize support with the UNRECOGNIZED case. - static var allCases: [ChannelSettings.ModemConfig] = [ - .vlongSlow, - .longSlow, - .longFast, - .midSlow, - .midFast, - .shortSlow, - .shortFast, - ] -} - -#endif // swift(>=4.2) - /// /// A pair of a channel number, mode and the (sharable) settings for that channel struct Channel { @@ -334,7 +218,6 @@ extension Channel.Role: CaseIterable { #if swift(>=5.5) && canImport(_Concurrency) extension ChannelSettings: @unchecked Sendable {} -extension ChannelSettings.ModemConfig: @unchecked Sendable {} extension Channel: @unchecked Sendable {} extension Channel.Role: @unchecked Sendable {} #endif // swift(>=5.5) && canImport(_Concurrency) @@ -344,11 +227,6 @@ extension Channel.Role: @unchecked Sendable {} extension ChannelSettings: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { static let protoMessageName: String = "ChannelSettings" static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ - 1: .standard(proto: "tx_power"), - 3: .standard(proto: "modem_config"), - 6: .same(proto: "bandwidth"), - 7: .standard(proto: "spread_factor"), - 8: .standard(proto: "coding_rate"), 9: .standard(proto: "channel_num"), 4: .same(proto: "psk"), 5: .same(proto: "name"), @@ -363,13 +241,8 @@ extension ChannelSettings: SwiftProtobuf.Message, SwiftProtobuf._MessageImplemen // 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.decodeSingularInt32Field(value: &self.txPower) }() - case 3: try { try decoder.decodeSingularEnumField(value: &self.modemConfig) }() case 4: try { try decoder.decodeSingularBytesField(value: &self.psk) }() case 5: try { try decoder.decodeSingularStringField(value: &self.name) }() - case 6: try { try decoder.decodeSingularUInt32Field(value: &self.bandwidth) }() - case 7: try { try decoder.decodeSingularUInt32Field(value: &self.spreadFactor) }() - case 8: try { try decoder.decodeSingularUInt32Field(value: &self.codingRate) }() case 9: try { try decoder.decodeSingularUInt32Field(value: &self.channelNum) }() case 10: try { try decoder.decodeSingularFixed32Field(value: &self.id) }() case 16: try { try decoder.decodeSingularBoolField(value: &self.uplinkEnabled) }() @@ -380,27 +253,12 @@ extension ChannelSettings: SwiftProtobuf.Message, SwiftProtobuf._MessageImplemen } func traverse(visitor: inout V) throws { - if self.txPower != 0 { - try visitor.visitSingularInt32Field(value: self.txPower, fieldNumber: 1) - } - if self.modemConfig != .vlongSlow { - try visitor.visitSingularEnumField(value: self.modemConfig, fieldNumber: 3) - } if !self.psk.isEmpty { try visitor.visitSingularBytesField(value: self.psk, fieldNumber: 4) } if !self.name.isEmpty { try visitor.visitSingularStringField(value: self.name, fieldNumber: 5) } - if self.bandwidth != 0 { - try visitor.visitSingularUInt32Field(value: self.bandwidth, fieldNumber: 6) - } - if self.spreadFactor != 0 { - try visitor.visitSingularUInt32Field(value: self.spreadFactor, fieldNumber: 7) - } - if self.codingRate != 0 { - try visitor.visitSingularUInt32Field(value: self.codingRate, fieldNumber: 8) - } if self.channelNum != 0 { try visitor.visitSingularUInt32Field(value: self.channelNum, fieldNumber: 9) } @@ -417,11 +275,6 @@ extension ChannelSettings: SwiftProtobuf.Message, SwiftProtobuf._MessageImplemen } static func ==(lhs: ChannelSettings, rhs: ChannelSettings) -> Bool { - if lhs.txPower != rhs.txPower {return false} - if lhs.modemConfig != rhs.modemConfig {return false} - if lhs.bandwidth != rhs.bandwidth {return false} - if lhs.spreadFactor != rhs.spreadFactor {return false} - if lhs.codingRate != rhs.codingRate {return false} if lhs.channelNum != rhs.channelNum {return false} if lhs.psk != rhs.psk {return false} if lhs.name != rhs.name {return false} @@ -433,18 +286,6 @@ extension ChannelSettings: SwiftProtobuf.Message, SwiftProtobuf._MessageImplemen } } -extension ChannelSettings.ModemConfig: SwiftProtobuf._ProtoNameProviding { - static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ - 0: .same(proto: "VLongSlow"), - 1: .same(proto: "LongSlow"), - 2: .same(proto: "LongFast"), - 3: .same(proto: "MidSlow"), - 4: .same(proto: "MidFast"), - 5: .same(proto: "ShortSlow"), - 6: .same(proto: "ShortFast"), - ] -} - extension Channel: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { static let protoMessageName: String = "Channel" static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ diff --git a/MeshtasticClient/Protobufs/config.pb.swift b/MeshtasticClient/Protobufs/config.pb.swift index 97689ce2..b2d08a49 100644 --- a/MeshtasticClient/Protobufs/config.pb.swift +++ b/MeshtasticClient/Protobufs/config.pb.swift @@ -31,72 +31,62 @@ struct Config { /// /// TODO: REPLACE - var deviceConfig: Config.DeviceConfig { + var device: Config.DeviceConfig { get { - if case .deviceConfig(let v)? = payloadVariant {return v} + if case .device(let v)? = payloadVariant {return v} return Config.DeviceConfig() } - set {payloadVariant = .deviceConfig(newValue)} + set {payloadVariant = .device(newValue)} } /// /// TODO: REPLACE - var gpsConfig: Config.GpsConfig { + var position: Config.PositionConfig { get { - if case .gpsConfig(let v)? = payloadVariant {return v} - return Config.GpsConfig() + if case .position(let v)? = payloadVariant {return v} + return Config.PositionConfig() } - set {payloadVariant = .gpsConfig(newValue)} + set {payloadVariant = .position(newValue)} } /// /// TODO: REPLACE - var powerConfig: Config.PowerConfig { + var power: Config.PowerConfig { get { - if case .powerConfig(let v)? = payloadVariant {return v} + if case .power(let v)? = payloadVariant {return v} return Config.PowerConfig() } - set {payloadVariant = .powerConfig(newValue)} + set {payloadVariant = .power(newValue)} } /// /// TODO: REPLACE - var wifiConfig: Config.WiFiConfig { + var wifi: Config.WiFiConfig { get { - if case .wifiConfig(let v)? = payloadVariant {return v} + if case .wifi(let v)? = payloadVariant {return v} return Config.WiFiConfig() } - set {payloadVariant = .wifiConfig(newValue)} + set {payloadVariant = .wifi(newValue)} } /// /// TODO: REPLACE - var displayConfig: Config.DisplayConfig { + var display: Config.DisplayConfig { get { - if case .displayConfig(let v)? = payloadVariant {return v} + if case .display(let v)? = payloadVariant {return v} return Config.DisplayConfig() } - set {payloadVariant = .displayConfig(newValue)} + set {payloadVariant = .display(newValue)} } /// /// TODO: REPLACE - var loraConfig: Config.LoRaConfig { + var lora: Config.LoRaConfig { get { - if case .loraConfig(let v)? = payloadVariant {return v} + if case .lora(let v)? = payloadVariant {return v} return Config.LoRaConfig() } - set {payloadVariant = .loraConfig(newValue)} - } - - /// - /// TODO: REPLACE - var moduleConfig: Config.ModuleConfig { - get { - if case .moduleConfig(let v)? = payloadVariant {return v} - return Config.ModuleConfig() - } - set {payloadVariant = .moduleConfig(newValue)} + set {payloadVariant = .lora(newValue)} } var unknownFields = SwiftProtobuf.UnknownStorage() @@ -106,25 +96,22 @@ struct Config { enum OneOf_PayloadVariant: Equatable { /// /// TODO: REPLACE - case deviceConfig(Config.DeviceConfig) + case device(Config.DeviceConfig) /// /// TODO: REPLACE - case gpsConfig(Config.GpsConfig) + case position(Config.PositionConfig) /// /// TODO: REPLACE - case powerConfig(Config.PowerConfig) + case power(Config.PowerConfig) /// /// TODO: REPLACE - case wifiConfig(Config.WiFiConfig) + case wifi(Config.WiFiConfig) /// /// TODO: REPLACE - case displayConfig(Config.DisplayConfig) + case display(Config.DisplayConfig) /// /// TODO: REPLACE - case loraConfig(Config.LoRaConfig) - /// - /// TODO: REPLACE - case moduleConfig(Config.ModuleConfig) + case lora(Config.LoRaConfig) #if !swift(>=4.1) static func ==(lhs: Config.OneOf_PayloadVariant, rhs: Config.OneOf_PayloadVariant) -> Bool { @@ -132,32 +119,28 @@ struct Config { // allocates stack space for every case branch when no optimizations are // enabled. https://github.com/apple/swift-protobuf/issues/1034 switch (lhs, rhs) { - case (.deviceConfig, .deviceConfig): return { - guard case .deviceConfig(let l) = lhs, case .deviceConfig(let r) = rhs else { preconditionFailure() } + case (.device, .device): return { + guard case .device(let l) = lhs, case .device(let r) = rhs else { preconditionFailure() } return l == r }() - case (.gpsConfig, .gpsConfig): return { - guard case .gpsConfig(let l) = lhs, case .gpsConfig(let r) = rhs else { preconditionFailure() } + case (.position, .position): return { + guard case .position(let l) = lhs, case .position(let r) = rhs else { preconditionFailure() } return l == r }() - case (.powerConfig, .powerConfig): return { - guard case .powerConfig(let l) = lhs, case .powerConfig(let r) = rhs else { preconditionFailure() } + case (.power, .power): return { + guard case .power(let l) = lhs, case .power(let r) = rhs else { preconditionFailure() } return l == r }() - case (.wifiConfig, .wifiConfig): return { - guard case .wifiConfig(let l) = lhs, case .wifiConfig(let r) = rhs else { preconditionFailure() } + case (.wifi, .wifi): return { + guard case .wifi(let l) = lhs, case .wifi(let r) = rhs else { preconditionFailure() } return l == r }() - case (.displayConfig, .displayConfig): return { - guard case .displayConfig(let l) = lhs, case .displayConfig(let r) = rhs else { preconditionFailure() } + case (.display, .display): return { + guard case .display(let l) = lhs, case .display(let r) = rhs else { preconditionFailure() } return l == r }() - case (.loraConfig, .loraConfig): return { - guard case .loraConfig(let l) = lhs, case .loraConfig(let r) = rhs else { preconditionFailure() } - return l == r - }() - case (.moduleConfig, .moduleConfig): return { - guard case .moduleConfig(let l) = lhs, case .moduleConfig(let r) = rhs else { preconditionFailure() } + case (.lora, .lora): return { + guard case .lora(let l) = lhs, case .lora(let r) = rhs else { preconditionFailure() } return l == r }() default: return false @@ -173,20 +156,240 @@ struct Config { // `Message` and `Message+*Additions` files in the SwiftProtobuf library for // methods supported on all messages. + /// + /// Sets the role of node + var role: Config.DeviceConfig.Role = .client + + /// + /// If set, this will disable the SerialConsole by not initilizing the StreamAPI + var serialDisabled: Bool = false + + /// + /// This setting is never saved to disk, but if set, all device settings will be returned to factory defaults. + /// (Region, serial number etc... will be preserved) + var factoryReset: Bool = false + + /// + /// By default we turn off logging as soon as an API client connects (to keep shared serial link quiet). + /// Set this to true to leave the debug log outputting even when API is active. + var debugLogEnabled: Bool = false + + /// + /// NTP server to use if WiFi is conneced, defaults to `0.pool.ntp.org` + var ntpServer: String = String() + var unknownFields = SwiftProtobuf.UnknownStorage() + /// + /// Defines the device's role on the Mesh network + /// unset + /// Behave normally. + /// Router + /// Functions as a router + enum Role: SwiftProtobuf.Enum { + typealias RawValue = Int + + /// + /// Client device role + case client // = 0 + + /// + /// ClientMute device role + /// This is like the client but packets will not hop over this node. Would be + /// useful if you want to save power by not contributing to the mesh. + case clientMute // = 1 + + /// + /// Router device role. + /// Uses an agressive algirithem for the flood networking so packets will + /// prefer to be routed over this node. Also assume that this will be generally + /// unattended and so will turn off the wifi/ble radio as well as the oled screen. + case router // = 2 + + /// + /// RouterClient device role + /// Uses an agressive algirithem for the flood networking so packets will + /// prefer to be routed over this node. Similiar power management as a regular + /// client, so the RouterClient can be used as both a Router and a Client. Useful + /// as a well placed base station that you could also use to send messages. + case routerClient // = 3 + case UNRECOGNIZED(Int) + + init() { + self = .client + } + + init?(rawValue: Int) { + switch rawValue { + case 0: self = .client + case 1: self = .clientMute + case 2: self = .router + case 3: self = .routerClient + default: self = .UNRECOGNIZED(rawValue) + } + } + + var rawValue: Int { + switch self { + case .client: return 0 + case .clientMute: return 1 + case .router: return 2 + case .routerClient: return 3 + case .UNRECOGNIZED(let i): return i + } + } + + } + init() {} } /// /// TODO: REPLACE - struct GpsConfig { + struct PositionConfig { // 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. + /// + /// We should send our position this often (but only if it has changed significantly) + /// Defaults to 15 minutes + var positionBroadcastSecs: UInt32 = 0 + + /// + /// We should send our position this often (but only if it has changed significantly) + var positionBroadcastSmartDisabled: Bool = false + + /// + /// If set, this node is at a fixed position. + /// We will generate GPS position updates at the regular interval, but use whatever the last lat/lon/alt we have for the node. + /// The lat/lon/alt can be set by an internal GPS or with the help of the app. + var fixedPosition: Bool = false + + /// + /// Should we disbale location sharing with other nodes (or the local phone) + var locationShareDisabled: Bool = false + + /// + /// Should the GPS be disabled for this node? + var gpsDisabled: Bool = false + + /// + /// How often should we try to get GPS position (in seconds) + /// or zero for the default of once every 30 seconds + /// or a very large value (maxint) to update only once at boot. + var gpsUpdateInterval: UInt32 = 0 + + /// + /// How long should we try to get our position during each gps_update_interval attempt? (in seconds) + /// Or if zero, use the default of 30 seconds. + /// If we don't get a new gps fix in that time, the gps will be put into sleep until the next gps_update_rate + /// window. + var gpsAttemptTime: UInt32 = 0 + + /// + /// Shall we accept 2D GPS fixes? By default, only 3D fixes are accepted + /// (during a 2D fix, altitude values are unreliable and will be excluded) + var gpsAccept2D: Bool = false + + /// + /// GPS maximum DOP accepted (dilution of precision) + /// Set a rejection threshold for GPS readings based on their precision, + /// relative to the GPS rated accuracy (which is typically ~3m) + /// Solutions above this value will be treated as retryable errors! + /// Useful range is between 1 - 64 (3m - <~200m) + /// By default (if zero), accept all GPS readings + var gpsMaxDop: UInt32 = 0 + + /// + /// Bit field of boolean configuration options for POSITION messages + /// (bitwise OR of PositionFlags) + var positionFlags: UInt32 = 0 + var unknownFields = SwiftProtobuf.UnknownStorage() + /// + /// Bit field of boolean configuration options, indicating which optional + /// fields to include when assembling POSITION messages + /// Longitude and latitude are always included (also time if GPS-synced) + /// NOTE: the more fields are included, the larger the message will be - + /// leading to longer airtime and a higher risk of packet loss + enum PositionFlags: SwiftProtobuf.Enum { + typealias RawValue = Int + + /// + /// Required for compilation + case posUndefined // = 0 + + /// + /// Include an altitude value (if available) + case posAltitude // = 1 + + /// + /// Altitude value is MSL + case posAltMsl // = 2 + + /// + /// Include geoidal separation + case posGeoSep // = 4 + + /// + /// Include the DOP value ; PDOP used by default, see below + case posDop // = 8 + + /// + /// If POS_DOP set, send separate HDOP / VDOP values instead of PDOP + case posHvdop // = 16 + + /// + /// Include number of "satellites in view" + case posSatinview // = 32 + + /// + /// Include a sequence number incremented per packet + case posSeqNos // = 64 + + /// + /// Include positional timestamp (from GPS solution) + case posTimestamp // = 128 + case UNRECOGNIZED(Int) + + init() { + self = .posUndefined + } + + init?(rawValue: Int) { + switch rawValue { + case 0: self = .posUndefined + case 1: self = .posAltitude + case 2: self = .posAltMsl + case 4: self = .posGeoSep + case 8: self = .posDop + case 16: self = .posHvdop + case 32: self = .posSatinview + case 64: self = .posSeqNos + case 128: self = .posTimestamp + default: self = .UNRECOGNIZED(rawValue) + } + } + + var rawValue: Int { + switch self { + case .posUndefined: return 0 + case .posAltitude: return 1 + case .posAltMsl: return 2 + case .posGeoSep: return 4 + case .posDop: return 8 + case .posHvdop: return 16 + case .posSatinview: return 32 + case .posSeqNos: return 64 + case .posTimestamp: return 128 + case .UNRECOGNIZED(let i): return i + } + } + + } + init() {} } @@ -197,8 +400,200 @@ struct Config { // `Message` and `Message+*Additions` files in the SwiftProtobuf library for // methods supported on all messages. + /// + /// Sets the current of the battery charger + var chargeCurrent: Config.PowerConfig.ChargeCurrent = .maunset + + /// + /// If set, we are powered from a low-current source (i.e. solar), so even if it looks like we have power flowing in + /// we should try to minimize power consumption as much as possible. + /// YOU DO NOT NEED TO SET THIS IF YOU'VE set is_router (it is implied in that case). + var isLowPower: Bool = false + + /// + /// Circumvents the logic block for determining whether the device is powered or not. + /// Useful for devices with finicky ADC issues on the battery sense pins. + var isAlwaysPowered: Bool = false + + /// + /// If non-zero, the device will fully power off this many seconds after external power is removed. + var onBatteryShutdownAfterSecs: UInt32 = 0 + + /// + /// If set to true, enable power saving features of the esp32 + var isPowerSaving: Bool = false + + /// + /// Ratio of voltage divider for battery pin eg. 3.20 (R1=100k, R2=220k) + /// Overrides the ADC_MULTIPLIER defined in variant for battery voltage calculation. + var adcMultiplierOverride: Float = 0 + + /// + /// Power management state machine option. + /// See [power management](/docs/software/other/power) for details. + /// 0 for default of 1 minute + var waitBluetoothSecs: UInt32 = 0 + + /// + /// Power management state machine option. + /// See [power management](/docs/software/other/power) for details. + /// 0 for default of 15 minutes + /// IMPORTANT NOTE FOR DEVICE CLIENTS: YOU MUST SEND SOME SORT OF PACKET TO THE PHONE AT LEAST THIS OFTEN OR THE DEVICE WILL DECIDE YOU ARE GONE! + var phoneTimeoutSecs: UInt32 = 0 + + /// + /// Power management state machine option. + /// See [power management](/docs/software/other/power) for details. + /// 0 for default of two hours, MAXUINT for disabled + var meshSdsTimeoutSecs: UInt32 = 0 + + /// + /// Power management state machine option. + /// See [power management](/docs/software/other/power) for details. + /// 0 for default of one year + var sdsSecs: UInt32 = 0 + + /// + /// Power management state machine option. + /// See [power management](/docs/software/other/power) for details. + /// 0 for default of 3600 + var lsSecs: UInt32 = 0 + + /// + /// Power management state machine option. + /// See [power management](/docs/software/other/power) for details. + /// 0 for default of 10 seconds + var minWakeSecs: UInt32 = 0 + var unknownFields = SwiftProtobuf.UnknownStorage() + /// + /// Sets the charge control current of devices with a battery charger that can be + /// configured. This is passed into the axp power management chip like on the tbeam. + enum ChargeCurrent: SwiftProtobuf.Enum { + typealias RawValue = Int + + /// + /// TODO: REPLACE + case maunset // = 0 + + /// + /// TODO: REPLACE + case ma100 // = 1 + + /// + /// TODO: REPLACE + case ma190 // = 2 + + /// + /// TODO: REPLACE + case ma280 // = 3 + + /// + /// TODO: REPLACE + case ma360 // = 4 + + /// + /// TODO: REPLACE + case ma450 // = 5 + + /// + /// TODO: REPLACE + case ma550 // = 6 + + /// + /// TODO: REPLACE + case ma630 // = 7 + + /// + /// TODO: REPLACE + case ma700 // = 8 + + /// + /// TODO: REPLACE + case ma780 // = 9 + + /// + /// TODO: REPLACE + case ma880 // = 10 + + /// + /// TODO: REPLACE + case ma960 // = 11 + + /// + /// TODO: REPLACE + case ma1000 // = 12 + + /// + /// TODO: REPLACE + case ma1080 // = 13 + + /// + /// TODO: REPLACE + case ma1160 // = 14 + + /// + /// TODO: REPLACE + case ma1240 // = 15 + + /// + /// TODO: REPLACE + case ma1320 // = 16 + case UNRECOGNIZED(Int) + + init() { + self = .maunset + } + + init?(rawValue: Int) { + switch rawValue { + case 0: self = .maunset + case 1: self = .ma100 + case 2: self = .ma190 + case 3: self = .ma280 + case 4: self = .ma360 + case 5: self = .ma450 + case 6: self = .ma550 + case 7: self = .ma630 + case 8: self = .ma700 + case 9: self = .ma780 + case 10: self = .ma880 + case 11: self = .ma960 + case 12: self = .ma1000 + case 13: self = .ma1080 + case 14: self = .ma1160 + case 15: self = .ma1240 + case 16: self = .ma1320 + default: self = .UNRECOGNIZED(rawValue) + } + } + + var rawValue: Int { + switch self { + case .maunset: return 0 + case .ma100: return 1 + case .ma190: return 2 + case .ma280: return 3 + case .ma360: return 4 + case .ma450: return 5 + case .ma550: return 6 + case .ma630: return 7 + case .ma700: return 8 + case .ma780: return 9 + case .ma880: return 10 + case .ma960: return 11 + case .ma1000: return 12 + case .ma1080: return 13 + case .ma1160: return 14 + case .ma1240: return 15 + case .ma1320: return 16 + case .UNRECOGNIZED(let i): return i + } + } + + } + init() {} } @@ -212,16 +607,16 @@ struct Config { /// /// If set, this node will try to join the specified wifi network and /// acquire an address via DHCP - var wifiSsid: String = String() + var ssid: String = String() /// /// If set, will be use to authenticate to the named wifi - var wifiPassword: String = String() + var psk: String = String() /// /// If set, the node will operate as an AP (and DHCP server), otherwise it /// will be a station - var wifiApMode: Bool = false + var apMode: Bool = false var unknownFields = SwiftProtobuf.UnknownStorage() @@ -235,8 +630,90 @@ struct Config { // `Message` and `Message+*Additions` files in the SwiftProtobuf library for // methods supported on all messages. + /// + /// Power management state machine option. + /// See [power management](/docs/software/other/power) for details. + /// 0 for default of one minute + var screenOnSecs: UInt32 = 0 + + /// + /// How the GPS coordinates are displayed on the OLED screen. + var gpsFormat: Config.DisplayConfig.GpsCoordinateFormat = .gpsFormatDec + + /// + /// Automatically toggles to the next page on the screen like a carousel, based the specified interval in seconds. + /// Potentially useful for devices without user buttons. + var autoScreenCarouselSecs: UInt32 = 0 + var unknownFields = SwiftProtobuf.UnknownStorage() + /// + /// How the GPS coordinates are displayed on the OLED screen. + enum GpsCoordinateFormat: SwiftProtobuf.Enum { + typealias RawValue = Int + + /// + /// GPS coordinates are displayed in the normal decimal degrees format: + /// DD.DDDDDD DDD.DDDDDD + case gpsFormatDec // = 0 + + /// + /// GPS coordinates are displayed in the degrees minutes seconds format: + /// DD°MM'SS"C DDD°MM'SS"C, where C is the compass point representing the locations quadrant + case gpsFormatDms // = 1 + + /// + /// GPS coordinates are displayed in Universal Transverse Mercator format: + /// ZZB EEEEEE NNNNNNN, where Z is zone, B is band, E is easting, N is northing + case gpsFormatUtm // = 2 + + /// + /// GPS coordinates are displayed in Military Grid Reference System format: + /// ZZB CD EEEEE NNNNN, where Z is zone, B is band, C is the east 100k square, D is the north 100k square, + /// E is easting, N is northing + case gpsFormatMgrs // = 3 + + /// + /// GPS coordinates are displayed in Open Location Code (aka Plus Codes). + case gpsFormatOlc // = 4 + + /// + /// GPS coordinates are displayed in Ordnance Survey Grid Reference (the National Grid System of the UK). + /// Format: AB EEEEE NNNNN, where A is the east 100k square, B is the north 100k square, E is the easting, + /// N is the northing + case gpsFormatOsgr // = 5 + case UNRECOGNIZED(Int) + + init() { + self = .gpsFormatDec + } + + init?(rawValue: Int) { + switch rawValue { + case 0: self = .gpsFormatDec + case 1: self = .gpsFormatDms + case 2: self = .gpsFormatUtm + case 3: self = .gpsFormatMgrs + case 4: self = .gpsFormatOlc + case 5: self = .gpsFormatOsgr + default: self = .UNRECOGNIZED(rawValue) + } + } + + var rawValue: Int { + switch self { + case .gpsFormatDec: return 0 + case .gpsFormatDms: return 1 + case .gpsFormatUtm: return 2 + case .gpsFormatMgrs: return 3 + case .gpsFormatOlc: return 4 + case .gpsFormatOsgr: return 5 + case .UNRECOGNIZED(let i): return i + } + } + + } + init() {} } @@ -247,285 +724,237 @@ struct Config { // `Message` and `Message+*Additions` files in the SwiftProtobuf library for // methods supported on all messages. - var unknownFields = SwiftProtobuf.UnknownStorage() - - init() {} - } - - /// - /// TODO: REPLACE - struct ModuleConfig { - // 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. + /// + /// If zero then, use default max legal continuous power (ie. something that won't + /// burn out the radio hardware) + /// In most cases you should use zero here. + /// Units are in dBm. + var txPower: Int32 = 0 /// - /// TODO: REPLACE - var payloadVariant: Config.ModuleConfig.OneOf_PayloadVariant? = nil + /// Note: This is the 'old' mechanism for specifying channel parameters. + /// Either modem_config or bandwidth/spreading/coding will be specified - NOT BOTH. + /// As a heuristic: If bandwidth is specified, do not use modem_config. + /// Because protobufs take ZERO space when the value is zero this works out nicely. + /// This value is replaced by bandwidth/spread_factor/coding_rate. + /// If you'd like to experiment with other options add them to MeshRadio.cpp in the device code. + var modemPreset: Config.LoRaConfig.ModemPreset = .vlongSlow /// - /// TODO: REPLACE - var mqttConfig: Config.ModuleConfig.MQTTConfig { - get { - if case .mqttConfig(let v)? = payloadVariant {return v} - return Config.ModuleConfig.MQTTConfig() - } - set {payloadVariant = .mqttConfig(newValue)} - } + /// Bandwidth in MHz + /// Certain bandwidth numbers are 'special' and will be converted to the + /// appropriate floating point value: 31 -> 31.25MHz + var bandwidth: UInt32 = 0 /// - /// TODO: REPLACE - var serialConfig: Config.ModuleConfig.SerialConfig { - get { - if case .serialConfig(let v)? = payloadVariant {return v} - return Config.ModuleConfig.SerialConfig() - } - set {payloadVariant = .serialConfig(newValue)} - } + /// A number from 7 to 12. + /// Indicates number of chirps per symbol as 1<=4.1) - static func ==(lhs: Config.ModuleConfig.OneOf_PayloadVariant, rhs: Config.ModuleConfig.OneOf_PayloadVariant) -> Bool { - // 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 (lhs, rhs) { - case (.mqttConfig, .mqttConfig): return { - guard case .mqttConfig(let l) = lhs, case .mqttConfig(let r) = rhs else { preconditionFailure() } - return l == r - }() - case (.serialConfig, .serialConfig): return { - guard case .serialConfig(let l) = lhs, case .serialConfig(let r) = rhs else { preconditionFailure() } - return l == r - }() - case (.externalNotificationConfig, .externalNotificationConfig): return { - guard case .externalNotificationConfig(let l) = lhs, case .externalNotificationConfig(let r) = rhs else { preconditionFailure() } - return l == r - }() - case (.storeForwardConfig, .storeForwardConfig): return { - guard case .storeForwardConfig(let l) = lhs, case .storeForwardConfig(let r) = rhs else { preconditionFailure() } - return l == r - }() - case (.rangeTestConfig, .rangeTestConfig): return { - guard case .rangeTestConfig(let l) = lhs, case .rangeTestConfig(let r) = rhs else { preconditionFailure() } - return l == r - }() - case (.telemetryConfig, .telemetryConfig): return { - guard case .telemetryConfig(let l) = lhs, case .telemetryConfig(let r) = rhs else { preconditionFailure() } - return l == r - }() - case (.cannedMessageConfig, .cannedMessageConfig): return { - guard case .cannedMessageConfig(let l) = lhs, case .cannedMessageConfig(let r) = rhs else { preconditionFailure() } - return l == r - }() - default: return false + /// + /// TODO: REPLACE + case unset // = 0 + + /// + /// TODO: REPLACE + case us // = 1 + + /// + /// TODO: REPLACE + case eu433 // = 2 + + /// + /// TODO: REPLACE + case eu868 // = 3 + + /// + /// TODO: REPLACE + case cn // = 4 + + /// + /// TODO: REPLACE + case jp // = 5 + + /// + /// TODO: REPLACE + case anz // = 6 + + /// + /// TODO: REPLACE + case kr // = 7 + + /// + /// TODO: REPLACE + case tw // = 8 + + /// + /// TODO: REPLACE + case ru // = 9 + + /// + /// TODO: REPLACE + case `in` // = 10 + + /// + /// TODO: REPLACE + case nz865 // = 11 + + /// + /// TODO: REPLACE + case th // = 12 + case UNRECOGNIZED(Int) + + init() { + self = .unset + } + + init?(rawValue: Int) { + switch rawValue { + case 0: self = .unset + case 1: self = .us + case 2: self = .eu433 + case 3: self = .eu868 + case 4: self = .cn + case 5: self = .jp + case 6: self = .anz + case 7: self = .kr + case 8: self = .tw + case 9: self = .ru + case 10: self = .in + case 11: self = .nz865 + case 12: self = .th + default: self = .UNRECOGNIZED(rawValue) } } - #endif + + var rawValue: Int { + switch self { + case .unset: return 0 + case .us: return 1 + case .eu433: return 2 + case .eu868: return 3 + case .cn: return 4 + case .jp: return 5 + case .anz: return 6 + case .kr: return 7 + case .tw: return 8 + case .ru: return 9 + case .in: return 10 + case .nz865: return 11 + case .th: return 12 + case .UNRECOGNIZED(let i): return i + } + } + } /// - /// TODO: REPLACE - struct MQTTConfig { - // 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. - - var unknownFields = SwiftProtobuf.UnknownStorage() - - init() {} - } - - /// - /// TODO: REPLACE - struct SerialConfig { - // 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. - - var unknownFields = SwiftProtobuf.UnknownStorage() - - init() {} - } - - /// - /// TODO: REPLACE - struct ExternalNotificationConfig { - // 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. - - var unknownFields = SwiftProtobuf.UnknownStorage() - - init() {} - } - - /// - /// TODO: REPLACE - struct StoreForwardConfig { - // 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. - - var unknownFields = SwiftProtobuf.UnknownStorage() - - init() {} - } - - /// - /// TODO: REPLACE - struct RangeTestConfig { - // 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. - - var unknownFields = SwiftProtobuf.UnknownStorage() - - init() {} - } - - /// - /// Configuration for both device and environment metrics - struct TelemetryConfig { - // 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. + /// Standard predefined channel settings + /// Note: these mappings must match ModemPreset Choice in the device code. + enum ModemPreset: SwiftProtobuf.Enum { + typealias RawValue = Int /// - /// Interval in seconds of how often we should try to send our - /// device measurements to the mesh - var deviceUpdateInterval: UInt32 = 0 + /// TODO: REPLACE + case vlongSlow // = 0 /// - /// Interval in seconds of how often we should try to send our - /// environment measurements to the mesh - var environmentUpdateInterval: UInt32 = 0 + /// TODO: REPLACE + case longSlow // = 1 /// - /// Preferences for the Telemetry Module (Environment) - /// Enable/Disable the telemetry measurement module measurement collection - var environmentMeasurementEnabled: Bool = false + /// TODO: REPLACE + case longFast // = 2 /// - /// Enable/Disable the telemetry measurement module on-device display - var environmentScreenEnabled: Bool = false + /// TODO: REPLACE + case midSlow // = 3 /// - /// Sometimes sensor reads can fail. - /// If this happens, we will retry a configurable number of attempts, - /// each attempt will be delayed by the minimum required refresh rate for that sensor - var environmentReadErrorCountThreshold: UInt32 = 0 + /// TODO: REPLACE + case midFast // = 4 /// - /// Sometimes we can end up with more than read_error_count_threshold failures. - /// In this case, we will stop trying to read from the sensor for a while. - /// Wait this long until trying to read from the sensor again - var environmentRecoveryInterval: UInt32 = 0 + /// TODO: REPLACE + case shortSlow // = 5 /// - /// We'll always read the sensor in Celsius, but sometimes we might want to - /// display the results in Fahrenheit as a "user preference". - var environmentDisplayFahrenheit: Bool = false + /// TODO: REPLACE + case shortFast // = 6 + case UNRECOGNIZED(Int) - /// - /// Specify the sensor type - var environmentSensorType: TelemetrySensorType = .notSet + init() { + self = .vlongSlow + } - /// - /// Specify the peferred GPIO Pin for sensor readings - var environmentSensorPin: UInt32 = 0 + init?(rawValue: Int) { + switch rawValue { + case 0: self = .vlongSlow + case 1: self = .longSlow + case 2: self = .longFast + case 3: self = .midSlow + case 4: self = .midFast + case 5: self = .shortSlow + case 6: self = .shortFast + default: self = .UNRECOGNIZED(rawValue) + } + } - var unknownFields = SwiftProtobuf.UnknownStorage() + var rawValue: Int { + switch self { + case .vlongSlow: return 0 + case .longSlow: return 1 + case .longFast: return 2 + case .midSlow: return 3 + case .midFast: return 4 + case .shortSlow: return 5 + case .shortFast: return 6 + case .UNRECOGNIZED(let i): return i + } + } - init() {} - } - - /// - /// TODO: REPLACE - struct CannedMessageConfig { - // 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. - - var unknownFields = SwiftProtobuf.UnknownStorage() - - init() {} } init() {} @@ -534,24 +963,117 @@ struct Config { init() {} } +#if swift(>=4.2) + +extension Config.DeviceConfig.Role: CaseIterable { + // The compiler won't synthesize support with the UNRECOGNIZED case. + static var allCases: [Config.DeviceConfig.Role] = [ + .client, + .clientMute, + .router, + .routerClient, + ] +} + +extension Config.PositionConfig.PositionFlags: CaseIterable { + // The compiler won't synthesize support with the UNRECOGNIZED case. + static var allCases: [Config.PositionConfig.PositionFlags] = [ + .posUndefined, + .posAltitude, + .posAltMsl, + .posGeoSep, + .posDop, + .posHvdop, + .posSatinview, + .posSeqNos, + .posTimestamp, + ] +} + +extension Config.PowerConfig.ChargeCurrent: CaseIterable { + // The compiler won't synthesize support with the UNRECOGNIZED case. + static var allCases: [Config.PowerConfig.ChargeCurrent] = [ + .maunset, + .ma100, + .ma190, + .ma280, + .ma360, + .ma450, + .ma550, + .ma630, + .ma700, + .ma780, + .ma880, + .ma960, + .ma1000, + .ma1080, + .ma1160, + .ma1240, + .ma1320, + ] +} + +extension Config.DisplayConfig.GpsCoordinateFormat: CaseIterable { + // The compiler won't synthesize support with the UNRECOGNIZED case. + static var allCases: [Config.DisplayConfig.GpsCoordinateFormat] = [ + .gpsFormatDec, + .gpsFormatDms, + .gpsFormatUtm, + .gpsFormatMgrs, + .gpsFormatOlc, + .gpsFormatOsgr, + ] +} + +extension Config.LoRaConfig.RegionCode: CaseIterable { + // The compiler won't synthesize support with the UNRECOGNIZED case. + static var allCases: [Config.LoRaConfig.RegionCode] = [ + .unset, + .us, + .eu433, + .eu868, + .cn, + .jp, + .anz, + .kr, + .tw, + .ru, + .in, + .nz865, + .th, + ] +} + +extension Config.LoRaConfig.ModemPreset: CaseIterable { + // The compiler won't synthesize support with the UNRECOGNIZED case. + static var allCases: [Config.LoRaConfig.ModemPreset] = [ + .vlongSlow, + .longSlow, + .longFast, + .midSlow, + .midFast, + .shortSlow, + .shortFast, + ] +} + +#endif // swift(>=4.2) + #if swift(>=5.5) && canImport(_Concurrency) extension Config: @unchecked Sendable {} extension Config.OneOf_PayloadVariant: @unchecked Sendable {} extension Config.DeviceConfig: @unchecked Sendable {} -extension Config.GpsConfig: @unchecked Sendable {} +extension Config.DeviceConfig.Role: @unchecked Sendable {} +extension Config.PositionConfig: @unchecked Sendable {} +extension Config.PositionConfig.PositionFlags: @unchecked Sendable {} extension Config.PowerConfig: @unchecked Sendable {} +extension Config.PowerConfig.ChargeCurrent: @unchecked Sendable {} extension Config.WiFiConfig: @unchecked Sendable {} extension Config.DisplayConfig: @unchecked Sendable {} +extension Config.DisplayConfig.GpsCoordinateFormat: @unchecked Sendable {} extension Config.LoRaConfig: @unchecked Sendable {} -extension Config.ModuleConfig: @unchecked Sendable {} -extension Config.ModuleConfig.OneOf_PayloadVariant: @unchecked Sendable {} -extension Config.ModuleConfig.MQTTConfig: @unchecked Sendable {} -extension Config.ModuleConfig.SerialConfig: @unchecked Sendable {} -extension Config.ModuleConfig.ExternalNotificationConfig: @unchecked Sendable {} -extension Config.ModuleConfig.StoreForwardConfig: @unchecked Sendable {} -extension Config.ModuleConfig.RangeTestConfig: @unchecked Sendable {} -extension Config.ModuleConfig.TelemetryConfig: @unchecked Sendable {} -extension Config.ModuleConfig.CannedMessageConfig: @unchecked Sendable {} +extension Config.LoRaConfig.RegionCode: @unchecked Sendable {} +extension Config.LoRaConfig.ModemPreset: @unchecked Sendable {} #endif // swift(>=5.5) && canImport(_Concurrency) // MARK: - Code below here is support for the SwiftProtobuf runtime. @@ -559,13 +1081,12 @@ extension Config.ModuleConfig.CannedMessageConfig: @unchecked Sendable {} extension Config: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { static let protoMessageName: String = "Config" static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ - 1: .standard(proto: "device_config"), - 2: .standard(proto: "gps_config"), - 3: .standard(proto: "power_config"), - 4: .standard(proto: "wifi_config"), - 5: .standard(proto: "display_config"), - 6: .standard(proto: "lora_config"), - 7: .standard(proto: "module_config"), + 1: .same(proto: "device"), + 2: .same(proto: "position"), + 3: .same(proto: "power"), + 4: .same(proto: "wifi"), + 5: .same(proto: "display"), + 6: .same(proto: "lora"), ] mutating func decodeMessage(decoder: inout D) throws { @@ -579,25 +1100,25 @@ extension Config: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBas var hadOneofValue = false if let current = self.payloadVariant { hadOneofValue = true - if case .deviceConfig(let m) = current {v = m} + if case .device(let m) = current {v = m} } try decoder.decodeSingularMessageField(value: &v) if let v = v { if hadOneofValue {try decoder.handleConflictingOneOf()} - self.payloadVariant = .deviceConfig(v) + self.payloadVariant = .device(v) } }() case 2: try { - var v: Config.GpsConfig? + var v: Config.PositionConfig? var hadOneofValue = false if let current = self.payloadVariant { hadOneofValue = true - if case .gpsConfig(let m) = current {v = m} + if case .position(let m) = current {v = m} } try decoder.decodeSingularMessageField(value: &v) if let v = v { if hadOneofValue {try decoder.handleConflictingOneOf()} - self.payloadVariant = .gpsConfig(v) + self.payloadVariant = .position(v) } }() case 3: try { @@ -605,12 +1126,12 @@ extension Config: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBas var hadOneofValue = false if let current = self.payloadVariant { hadOneofValue = true - if case .powerConfig(let m) = current {v = m} + if case .power(let m) = current {v = m} } try decoder.decodeSingularMessageField(value: &v) if let v = v { if hadOneofValue {try decoder.handleConflictingOneOf()} - self.payloadVariant = .powerConfig(v) + self.payloadVariant = .power(v) } }() case 4: try { @@ -618,12 +1139,12 @@ extension Config: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBas var hadOneofValue = false if let current = self.payloadVariant { hadOneofValue = true - if case .wifiConfig(let m) = current {v = m} + if case .wifi(let m) = current {v = m} } try decoder.decodeSingularMessageField(value: &v) if let v = v { if hadOneofValue {try decoder.handleConflictingOneOf()} - self.payloadVariant = .wifiConfig(v) + self.payloadVariant = .wifi(v) } }() case 5: try { @@ -631,12 +1152,12 @@ extension Config: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBas var hadOneofValue = false if let current = self.payloadVariant { hadOneofValue = true - if case .displayConfig(let m) = current {v = m} + if case .display(let m) = current {v = m} } try decoder.decodeSingularMessageField(value: &v) if let v = v { if hadOneofValue {try decoder.handleConflictingOneOf()} - self.payloadVariant = .displayConfig(v) + self.payloadVariant = .display(v) } }() case 6: try { @@ -644,25 +1165,12 @@ extension Config: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBas var hadOneofValue = false if let current = self.payloadVariant { hadOneofValue = true - if case .loraConfig(let m) = current {v = m} + if case .lora(let m) = current {v = m} } try decoder.decodeSingularMessageField(value: &v) if let v = v { if hadOneofValue {try decoder.handleConflictingOneOf()} - self.payloadVariant = .loraConfig(v) - } - }() - case 7: try { - var v: Config.ModuleConfig? - var hadOneofValue = false - if let current = self.payloadVariant { - hadOneofValue = true - if case .moduleConfig(let m) = current {v = m} - } - try decoder.decodeSingularMessageField(value: &v) - if let v = v { - if hadOneofValue {try decoder.handleConflictingOneOf()} - self.payloadVariant = .moduleConfig(v) + self.payloadVariant = .lora(v) } }() default: break @@ -676,34 +1184,30 @@ extension Config: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBas // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and // https://github.com/apple/swift-protobuf/issues/1182 switch self.payloadVariant { - case .deviceConfig?: try { - guard case .deviceConfig(let v)? = self.payloadVariant else { preconditionFailure() } + case .device?: try { + guard case .device(let v)? = self.payloadVariant else { preconditionFailure() } try visitor.visitSingularMessageField(value: v, fieldNumber: 1) }() - case .gpsConfig?: try { - guard case .gpsConfig(let v)? = self.payloadVariant else { preconditionFailure() } + case .position?: try { + guard case .position(let v)? = self.payloadVariant else { preconditionFailure() } try visitor.visitSingularMessageField(value: v, fieldNumber: 2) }() - case .powerConfig?: try { - guard case .powerConfig(let v)? = self.payloadVariant else { preconditionFailure() } + case .power?: try { + guard case .power(let v)? = self.payloadVariant else { preconditionFailure() } try visitor.visitSingularMessageField(value: v, fieldNumber: 3) }() - case .wifiConfig?: try { - guard case .wifiConfig(let v)? = self.payloadVariant else { preconditionFailure() } + case .wifi?: try { + guard case .wifi(let v)? = self.payloadVariant else { preconditionFailure() } try visitor.visitSingularMessageField(value: v, fieldNumber: 4) }() - case .displayConfig?: try { - guard case .displayConfig(let v)? = self.payloadVariant else { preconditionFailure() } + case .display?: try { + guard case .display(let v)? = self.payloadVariant else { preconditionFailure() } try visitor.visitSingularMessageField(value: v, fieldNumber: 5) }() - case .loraConfig?: try { - guard case .loraConfig(let v)? = self.payloadVariant else { preconditionFailure() } + case .lora?: try { + guard case .lora(let v)? = self.payloadVariant else { preconditionFailure() } try visitor.visitSingularMessageField(value: v, fieldNumber: 6) }() - case .moduleConfig?: try { - guard case .moduleConfig(let v)? = self.payloadVariant else { preconditionFailure() } - try visitor.visitSingularMessageField(value: v, fieldNumber: 7) - }() case nil: break } try unknownFields.traverse(visitor: &visitor) @@ -718,67 +1222,12 @@ extension Config: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBas extension Config.DeviceConfig: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { static let protoMessageName: String = Config.protoMessageName + ".DeviceConfig" - static let _protobuf_nameMap = SwiftProtobuf._NameMap() - - mutating func decodeMessage(decoder: inout D) throws { - while let _ = try decoder.nextFieldNumber() { - } - } - - func traverse(visitor: inout V) throws { - try unknownFields.traverse(visitor: &visitor) - } - - static func ==(lhs: Config.DeviceConfig, rhs: Config.DeviceConfig) -> Bool { - if lhs.unknownFields != rhs.unknownFields {return false} - return true - } -} - -extension Config.GpsConfig: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { - static let protoMessageName: String = Config.protoMessageName + ".GpsConfig" - static let _protobuf_nameMap = SwiftProtobuf._NameMap() - - mutating func decodeMessage(decoder: inout D) throws { - while let _ = try decoder.nextFieldNumber() { - } - } - - func traverse(visitor: inout V) throws { - try unknownFields.traverse(visitor: &visitor) - } - - static func ==(lhs: Config.GpsConfig, rhs: Config.GpsConfig) -> Bool { - if lhs.unknownFields != rhs.unknownFields {return false} - return true - } -} - -extension Config.PowerConfig: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { - static let protoMessageName: String = Config.protoMessageName + ".PowerConfig" - static let _protobuf_nameMap = SwiftProtobuf._NameMap() - - mutating func decodeMessage(decoder: inout D) throws { - while let _ = try decoder.nextFieldNumber() { - } - } - - func traverse(visitor: inout V) throws { - try unknownFields.traverse(visitor: &visitor) - } - - static func ==(lhs: Config.PowerConfig, rhs: Config.PowerConfig) -> Bool { - if lhs.unknownFields != rhs.unknownFields {return false} - return true - } -} - -extension Config.WiFiConfig: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { - static let protoMessageName: String = Config.protoMessageName + ".WiFiConfig" static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ - 1: .standard(proto: "wifi_ssid"), - 2: .standard(proto: "wifi_password"), - 3: .standard(proto: "wifi_ap_mode"), + 1: .same(proto: "role"), + 2: .standard(proto: "serial_disabled"), + 3: .standard(proto: "factory_reset"), + 4: .standard(proto: "debug_log_enabled"), + 5: .standard(proto: "ntp_server"), ] mutating func decodeMessage(decoder: inout D) throws { @@ -787,31 +1236,314 @@ extension Config.WiFiConfig: SwiftProtobuf.Message, SwiftProtobuf._MessageImplem // 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.decodeSingularStringField(value: &self.wifiSsid) }() - case 2: try { try decoder.decodeSingularStringField(value: &self.wifiPassword) }() - case 3: try { try decoder.decodeSingularBoolField(value: &self.wifiApMode) }() + case 1: try { try decoder.decodeSingularEnumField(value: &self.role) }() + case 2: try { try decoder.decodeSingularBoolField(value: &self.serialDisabled) }() + case 3: try { try decoder.decodeSingularBoolField(value: &self.factoryReset) }() + case 4: try { try decoder.decodeSingularBoolField(value: &self.debugLogEnabled) }() + case 5: try { try decoder.decodeSingularStringField(value: &self.ntpServer) }() default: break } } } func traverse(visitor: inout V) throws { - if !self.wifiSsid.isEmpty { - try visitor.visitSingularStringField(value: self.wifiSsid, fieldNumber: 1) + if self.role != .client { + try visitor.visitSingularEnumField(value: self.role, fieldNumber: 1) } - if !self.wifiPassword.isEmpty { - try visitor.visitSingularStringField(value: self.wifiPassword, fieldNumber: 2) + if self.serialDisabled != false { + try visitor.visitSingularBoolField(value: self.serialDisabled, fieldNumber: 2) } - if self.wifiApMode != false { - try visitor.visitSingularBoolField(value: self.wifiApMode, fieldNumber: 3) + if self.factoryReset != false { + try visitor.visitSingularBoolField(value: self.factoryReset, fieldNumber: 3) + } + if self.debugLogEnabled != false { + try visitor.visitSingularBoolField(value: self.debugLogEnabled, fieldNumber: 4) + } + if !self.ntpServer.isEmpty { + try visitor.visitSingularStringField(value: self.ntpServer, fieldNumber: 5) + } + try unknownFields.traverse(visitor: &visitor) + } + + static func ==(lhs: Config.DeviceConfig, rhs: Config.DeviceConfig) -> Bool { + if lhs.role != rhs.role {return false} + if lhs.serialDisabled != rhs.serialDisabled {return false} + if lhs.factoryReset != rhs.factoryReset {return false} + if lhs.debugLogEnabled != rhs.debugLogEnabled {return false} + if lhs.ntpServer != rhs.ntpServer {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Config.DeviceConfig.Role: SwiftProtobuf._ProtoNameProviding { + static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 0: .same(proto: "Client"), + 1: .same(proto: "ClientMute"), + 2: .same(proto: "Router"), + 3: .same(proto: "RouterClient"), + ] +} + +extension Config.PositionConfig: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + static let protoMessageName: String = Config.protoMessageName + ".PositionConfig" + static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .standard(proto: "position_broadcast_secs"), + 2: .standard(proto: "position_broadcast_smart_disabled"), + 3: .standard(proto: "fixed_position"), + 4: .standard(proto: "location_share_disabled"), + 5: .standard(proto: "gps_disabled"), + 6: .standard(proto: "gps_update_interval"), + 7: .standard(proto: "gps_attempt_time"), + 8: .standard(proto: "gps_accept_2d"), + 9: .standard(proto: "gps_max_dop"), + 10: .standard(proto: "position_flags"), + ] + + 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.positionBroadcastSecs) }() + case 2: try { try decoder.decodeSingularBoolField(value: &self.positionBroadcastSmartDisabled) }() + case 3: try { try decoder.decodeSingularBoolField(value: &self.fixedPosition) }() + case 4: try { try decoder.decodeSingularBoolField(value: &self.locationShareDisabled) }() + case 5: try { try decoder.decodeSingularBoolField(value: &self.gpsDisabled) }() + case 6: try { try decoder.decodeSingularUInt32Field(value: &self.gpsUpdateInterval) }() + case 7: try { try decoder.decodeSingularUInt32Field(value: &self.gpsAttemptTime) }() + case 8: try { try decoder.decodeSingularBoolField(value: &self.gpsAccept2D) }() + case 9: try { try decoder.decodeSingularUInt32Field(value: &self.gpsMaxDop) }() + case 10: try { try decoder.decodeSingularUInt32Field(value: &self.positionFlags) }() + default: break + } + } + } + + func traverse(visitor: inout V) throws { + if self.positionBroadcastSecs != 0 { + try visitor.visitSingularUInt32Field(value: self.positionBroadcastSecs, fieldNumber: 1) + } + if self.positionBroadcastSmartDisabled != false { + try visitor.visitSingularBoolField(value: self.positionBroadcastSmartDisabled, fieldNumber: 2) + } + if self.fixedPosition != false { + try visitor.visitSingularBoolField(value: self.fixedPosition, fieldNumber: 3) + } + if self.locationShareDisabled != false { + try visitor.visitSingularBoolField(value: self.locationShareDisabled, fieldNumber: 4) + } + if self.gpsDisabled != false { + try visitor.visitSingularBoolField(value: self.gpsDisabled, fieldNumber: 5) + } + if self.gpsUpdateInterval != 0 { + try visitor.visitSingularUInt32Field(value: self.gpsUpdateInterval, fieldNumber: 6) + } + if self.gpsAttemptTime != 0 { + try visitor.visitSingularUInt32Field(value: self.gpsAttemptTime, fieldNumber: 7) + } + if self.gpsAccept2D != false { + try visitor.visitSingularBoolField(value: self.gpsAccept2D, fieldNumber: 8) + } + if self.gpsMaxDop != 0 { + try visitor.visitSingularUInt32Field(value: self.gpsMaxDop, fieldNumber: 9) + } + if self.positionFlags != 0 { + try visitor.visitSingularUInt32Field(value: self.positionFlags, fieldNumber: 10) + } + try unknownFields.traverse(visitor: &visitor) + } + + static func ==(lhs: Config.PositionConfig, rhs: Config.PositionConfig) -> Bool { + if lhs.positionBroadcastSecs != rhs.positionBroadcastSecs {return false} + if lhs.positionBroadcastSmartDisabled != rhs.positionBroadcastSmartDisabled {return false} + if lhs.fixedPosition != rhs.fixedPosition {return false} + if lhs.locationShareDisabled != rhs.locationShareDisabled {return false} + if lhs.gpsDisabled != rhs.gpsDisabled {return false} + if lhs.gpsUpdateInterval != rhs.gpsUpdateInterval {return false} + if lhs.gpsAttemptTime != rhs.gpsAttemptTime {return false} + if lhs.gpsAccept2D != rhs.gpsAccept2D {return false} + if lhs.gpsMaxDop != rhs.gpsMaxDop {return false} + if lhs.positionFlags != rhs.positionFlags {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Config.PositionConfig.PositionFlags: SwiftProtobuf._ProtoNameProviding { + static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 0: .same(proto: "POS_UNDEFINED"), + 1: .same(proto: "POS_ALTITUDE"), + 2: .same(proto: "POS_ALT_MSL"), + 4: .same(proto: "POS_GEO_SEP"), + 8: .same(proto: "POS_DOP"), + 16: .same(proto: "POS_HVDOP"), + 32: .same(proto: "POS_SATINVIEW"), + 64: .same(proto: "POS_SEQ_NOS"), + 128: .same(proto: "POS_TIMESTAMP"), + ] +} + +extension Config.PowerConfig: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + static let protoMessageName: String = Config.protoMessageName + ".PowerConfig" + static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .standard(proto: "charge_current"), + 2: .standard(proto: "is_low_power"), + 3: .standard(proto: "is_always_powered"), + 4: .standard(proto: "on_battery_shutdown_after_secs"), + 5: .standard(proto: "is_power_saving"), + 6: .standard(proto: "adc_multiplier_override"), + 7: .standard(proto: "wait_bluetooth_secs"), + 8: .standard(proto: "phone_timeout_secs"), + 9: .standard(proto: "mesh_sds_timeout_secs"), + 10: .standard(proto: "sds_secs"), + 11: .standard(proto: "ls_secs"), + 12: .standard(proto: "min_wake_secs"), + ] + + 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.decodeSingularEnumField(value: &self.chargeCurrent) }() + case 2: try { try decoder.decodeSingularBoolField(value: &self.isLowPower) }() + case 3: try { try decoder.decodeSingularBoolField(value: &self.isAlwaysPowered) }() + case 4: try { try decoder.decodeSingularUInt32Field(value: &self.onBatteryShutdownAfterSecs) }() + case 5: try { try decoder.decodeSingularBoolField(value: &self.isPowerSaving) }() + case 6: try { try decoder.decodeSingularFloatField(value: &self.adcMultiplierOverride) }() + case 7: try { try decoder.decodeSingularUInt32Field(value: &self.waitBluetoothSecs) }() + case 8: try { try decoder.decodeSingularUInt32Field(value: &self.phoneTimeoutSecs) }() + case 9: try { try decoder.decodeSingularUInt32Field(value: &self.meshSdsTimeoutSecs) }() + case 10: try { try decoder.decodeSingularUInt32Field(value: &self.sdsSecs) }() + case 11: try { try decoder.decodeSingularUInt32Field(value: &self.lsSecs) }() + case 12: try { try decoder.decodeSingularUInt32Field(value: &self.minWakeSecs) }() + default: break + } + } + } + + func traverse(visitor: inout V) throws { + if self.chargeCurrent != .maunset { + try visitor.visitSingularEnumField(value: self.chargeCurrent, fieldNumber: 1) + } + if self.isLowPower != false { + try visitor.visitSingularBoolField(value: self.isLowPower, fieldNumber: 2) + } + if self.isAlwaysPowered != false { + try visitor.visitSingularBoolField(value: self.isAlwaysPowered, fieldNumber: 3) + } + if self.onBatteryShutdownAfterSecs != 0 { + try visitor.visitSingularUInt32Field(value: self.onBatteryShutdownAfterSecs, fieldNumber: 4) + } + if self.isPowerSaving != false { + try visitor.visitSingularBoolField(value: self.isPowerSaving, fieldNumber: 5) + } + if self.adcMultiplierOverride != 0 { + try visitor.visitSingularFloatField(value: self.adcMultiplierOverride, fieldNumber: 6) + } + if self.waitBluetoothSecs != 0 { + try visitor.visitSingularUInt32Field(value: self.waitBluetoothSecs, fieldNumber: 7) + } + if self.phoneTimeoutSecs != 0 { + try visitor.visitSingularUInt32Field(value: self.phoneTimeoutSecs, fieldNumber: 8) + } + if self.meshSdsTimeoutSecs != 0 { + try visitor.visitSingularUInt32Field(value: self.meshSdsTimeoutSecs, fieldNumber: 9) + } + if self.sdsSecs != 0 { + try visitor.visitSingularUInt32Field(value: self.sdsSecs, fieldNumber: 10) + } + if self.lsSecs != 0 { + try visitor.visitSingularUInt32Field(value: self.lsSecs, fieldNumber: 11) + } + if self.minWakeSecs != 0 { + try visitor.visitSingularUInt32Field(value: self.minWakeSecs, fieldNumber: 12) + } + try unknownFields.traverse(visitor: &visitor) + } + + static func ==(lhs: Config.PowerConfig, rhs: Config.PowerConfig) -> Bool { + if lhs.chargeCurrent != rhs.chargeCurrent {return false} + if lhs.isLowPower != rhs.isLowPower {return false} + if lhs.isAlwaysPowered != rhs.isAlwaysPowered {return false} + if lhs.onBatteryShutdownAfterSecs != rhs.onBatteryShutdownAfterSecs {return false} + if lhs.isPowerSaving != rhs.isPowerSaving {return false} + if lhs.adcMultiplierOverride != rhs.adcMultiplierOverride {return false} + if lhs.waitBluetoothSecs != rhs.waitBluetoothSecs {return false} + if lhs.phoneTimeoutSecs != rhs.phoneTimeoutSecs {return false} + if lhs.meshSdsTimeoutSecs != rhs.meshSdsTimeoutSecs {return false} + if lhs.sdsSecs != rhs.sdsSecs {return false} + if lhs.lsSecs != rhs.lsSecs {return false} + if lhs.minWakeSecs != rhs.minWakeSecs {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Config.PowerConfig.ChargeCurrent: SwiftProtobuf._ProtoNameProviding { + static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 0: .same(proto: "MAUnset"), + 1: .same(proto: "MA100"), + 2: .same(proto: "MA190"), + 3: .same(proto: "MA280"), + 4: .same(proto: "MA360"), + 5: .same(proto: "MA450"), + 6: .same(proto: "MA550"), + 7: .same(proto: "MA630"), + 8: .same(proto: "MA700"), + 9: .same(proto: "MA780"), + 10: .same(proto: "MA880"), + 11: .same(proto: "MA960"), + 12: .same(proto: "MA1000"), + 13: .same(proto: "MA1080"), + 14: .same(proto: "MA1160"), + 15: .same(proto: "MA1240"), + 16: .same(proto: "MA1320"), + ] +} + +extension Config.WiFiConfig: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + static let protoMessageName: String = Config.protoMessageName + ".WiFiConfig" + static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "ssid"), + 2: .same(proto: "psk"), + 3: .standard(proto: "ap_mode"), + ] + + 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.decodeSingularStringField(value: &self.ssid) }() + case 2: try { try decoder.decodeSingularStringField(value: &self.psk) }() + case 3: try { try decoder.decodeSingularBoolField(value: &self.apMode) }() + default: break + } + } + } + + func traverse(visitor: inout V) throws { + if !self.ssid.isEmpty { + try visitor.visitSingularStringField(value: self.ssid, fieldNumber: 1) + } + if !self.psk.isEmpty { + try visitor.visitSingularStringField(value: self.psk, fieldNumber: 2) + } + if self.apMode != false { + try visitor.visitSingularBoolField(value: self.apMode, fieldNumber: 3) } try unknownFields.traverse(visitor: &visitor) } static func ==(lhs: Config.WiFiConfig, rhs: Config.WiFiConfig) -> Bool { - if lhs.wifiSsid != rhs.wifiSsid {return false} - if lhs.wifiPassword != rhs.wifiPassword {return false} - if lhs.wifiApMode != rhs.wifiApMode {return false} + if lhs.ssid != rhs.ssid {return false} + if lhs.psk != rhs.psk {return false} + if lhs.apMode != rhs.apMode {return false} if lhs.unknownFields != rhs.unknownFields {return false} return true } @@ -819,392 +1551,171 @@ extension Config.WiFiConfig: SwiftProtobuf.Message, SwiftProtobuf._MessageImplem extension Config.DisplayConfig: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { static let protoMessageName: String = Config.protoMessageName + ".DisplayConfig" - static let _protobuf_nameMap = SwiftProtobuf._NameMap() + static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .standard(proto: "screen_on_secs"), + 2: .standard(proto: "gps_format"), + 3: .standard(proto: "auto_screen_carousel_secs"), + ] mutating func decodeMessage(decoder: inout D) throws { - while let _ = try decoder.nextFieldNumber() { + 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.screenOnSecs) }() + case 2: try { try decoder.decodeSingularEnumField(value: &self.gpsFormat) }() + case 3: try { try decoder.decodeSingularUInt32Field(value: &self.autoScreenCarouselSecs) }() + default: break + } } } func traverse(visitor: inout V) throws { + if self.screenOnSecs != 0 { + try visitor.visitSingularUInt32Field(value: self.screenOnSecs, fieldNumber: 1) + } + if self.gpsFormat != .gpsFormatDec { + try visitor.visitSingularEnumField(value: self.gpsFormat, fieldNumber: 2) + } + if self.autoScreenCarouselSecs != 0 { + try visitor.visitSingularUInt32Field(value: self.autoScreenCarouselSecs, fieldNumber: 3) + } try unknownFields.traverse(visitor: &visitor) } static func ==(lhs: Config.DisplayConfig, rhs: Config.DisplayConfig) -> Bool { + if lhs.screenOnSecs != rhs.screenOnSecs {return false} + if lhs.gpsFormat != rhs.gpsFormat {return false} + if lhs.autoScreenCarouselSecs != rhs.autoScreenCarouselSecs {return false} if lhs.unknownFields != rhs.unknownFields {return false} return true } } +extension Config.DisplayConfig.GpsCoordinateFormat: SwiftProtobuf._ProtoNameProviding { + static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 0: .same(proto: "GpsFormatDec"), + 1: .same(proto: "GpsFormatDMS"), + 2: .same(proto: "GpsFormatUTM"), + 3: .same(proto: "GpsFormatMGRS"), + 4: .same(proto: "GpsFormatOLC"), + 5: .same(proto: "GpsFormatOSGR"), + ] +} + extension Config.LoRaConfig: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { static let protoMessageName: String = Config.protoMessageName + ".LoRaConfig" - static let _protobuf_nameMap = SwiftProtobuf._NameMap() + static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .standard(proto: "tx_power"), + 2: .standard(proto: "modem_preset"), + 3: .same(proto: "bandwidth"), + 4: .standard(proto: "spread_factor"), + 5: .standard(proto: "coding_rate"), + 6: .standard(proto: "frequency_offset"), + 7: .same(proto: "region"), + 8: .standard(proto: "hop_limit"), + 9: .standard(proto: "tx_disabled"), + 103: .standard(proto: "ignore_incoming"), + ] mutating func decodeMessage(decoder: inout D) throws { - while let _ = try decoder.nextFieldNumber() { + 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.decodeSingularInt32Field(value: &self.txPower) }() + case 2: try { try decoder.decodeSingularEnumField(value: &self.modemPreset) }() + case 3: try { try decoder.decodeSingularUInt32Field(value: &self.bandwidth) }() + case 4: try { try decoder.decodeSingularUInt32Field(value: &self.spreadFactor) }() + case 5: try { try decoder.decodeSingularUInt32Field(value: &self.codingRate) }() + case 6: try { try decoder.decodeSingularFloatField(value: &self.frequencyOffset) }() + case 7: try { try decoder.decodeSingularEnumField(value: &self.region) }() + case 8: try { try decoder.decodeSingularUInt32Field(value: &self.hopLimit) }() + case 9: try { try decoder.decodeSingularBoolField(value: &self.txDisabled) }() + case 103: try { try decoder.decodeRepeatedUInt32Field(value: &self.ignoreIncoming) }() + default: break + } } } func traverse(visitor: inout V) throws { + if self.txPower != 0 { + try visitor.visitSingularInt32Field(value: self.txPower, fieldNumber: 1) + } + if self.modemPreset != .vlongSlow { + try visitor.visitSingularEnumField(value: self.modemPreset, fieldNumber: 2) + } + if self.bandwidth != 0 { + try visitor.visitSingularUInt32Field(value: self.bandwidth, fieldNumber: 3) + } + if self.spreadFactor != 0 { + try visitor.visitSingularUInt32Field(value: self.spreadFactor, fieldNumber: 4) + } + if self.codingRate != 0 { + try visitor.visitSingularUInt32Field(value: self.codingRate, fieldNumber: 5) + } + if self.frequencyOffset != 0 { + try visitor.visitSingularFloatField(value: self.frequencyOffset, fieldNumber: 6) + } + if self.region != .unset { + try visitor.visitSingularEnumField(value: self.region, fieldNumber: 7) + } + if self.hopLimit != 0 { + try visitor.visitSingularUInt32Field(value: self.hopLimit, fieldNumber: 8) + } + if self.txDisabled != false { + try visitor.visitSingularBoolField(value: self.txDisabled, fieldNumber: 9) + } + if !self.ignoreIncoming.isEmpty { + try visitor.visitPackedUInt32Field(value: self.ignoreIncoming, fieldNumber: 103) + } try unknownFields.traverse(visitor: &visitor) } static func ==(lhs: Config.LoRaConfig, rhs: Config.LoRaConfig) -> Bool { + if lhs.txPower != rhs.txPower {return false} + if lhs.modemPreset != rhs.modemPreset {return false} + if lhs.bandwidth != rhs.bandwidth {return false} + if lhs.spreadFactor != rhs.spreadFactor {return false} + if lhs.codingRate != rhs.codingRate {return false} + if lhs.frequencyOffset != rhs.frequencyOffset {return false} + if lhs.region != rhs.region {return false} + if lhs.hopLimit != rhs.hopLimit {return false} + if lhs.txDisabled != rhs.txDisabled {return false} + if lhs.ignoreIncoming != rhs.ignoreIncoming {return false} if lhs.unknownFields != rhs.unknownFields {return false} return true } } -extension Config.ModuleConfig: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { - static let protoMessageName: String = Config.protoMessageName + ".ModuleConfig" +extension Config.LoRaConfig.RegionCode: SwiftProtobuf._ProtoNameProviding { static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ - 1: .standard(proto: "mqtt_config"), - 2: .standard(proto: "serial_config"), - 3: .standard(proto: "external_notification_config"), - 4: .standard(proto: "store_forward_config"), - 5: .standard(proto: "range_test_config"), - 6: .standard(proto: "telemetry_config"), - 7: .standard(proto: "canned_message_config"), + 0: .same(proto: "Unset"), + 1: .same(proto: "US"), + 2: .same(proto: "EU433"), + 3: .same(proto: "EU868"), + 4: .same(proto: "CN"), + 5: .same(proto: "JP"), + 6: .same(proto: "ANZ"), + 7: .same(proto: "KR"), + 8: .same(proto: "TW"), + 9: .same(proto: "RU"), + 10: .same(proto: "IN"), + 11: .same(proto: "NZ865"), + 12: .same(proto: "TH"), ] - - 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 { - var v: Config.ModuleConfig.MQTTConfig? - var hadOneofValue = false - if let current = self.payloadVariant { - hadOneofValue = true - if case .mqttConfig(let m) = current {v = m} - } - try decoder.decodeSingularMessageField(value: &v) - if let v = v { - if hadOneofValue {try decoder.handleConflictingOneOf()} - self.payloadVariant = .mqttConfig(v) - } - }() - case 2: try { - var v: Config.ModuleConfig.SerialConfig? - var hadOneofValue = false - if let current = self.payloadVariant { - hadOneofValue = true - if case .serialConfig(let m) = current {v = m} - } - try decoder.decodeSingularMessageField(value: &v) - if let v = v { - if hadOneofValue {try decoder.handleConflictingOneOf()} - self.payloadVariant = .serialConfig(v) - } - }() - case 3: try { - var v: Config.ModuleConfig.ExternalNotificationConfig? - var hadOneofValue = false - if let current = self.payloadVariant { - hadOneofValue = true - if case .externalNotificationConfig(let m) = current {v = m} - } - try decoder.decodeSingularMessageField(value: &v) - if let v = v { - if hadOneofValue {try decoder.handleConflictingOneOf()} - self.payloadVariant = .externalNotificationConfig(v) - } - }() - case 4: try { - var v: Config.ModuleConfig.StoreForwardConfig? - var hadOneofValue = false - if let current = self.payloadVariant { - hadOneofValue = true - if case .storeForwardConfig(let m) = current {v = m} - } - try decoder.decodeSingularMessageField(value: &v) - if let v = v { - if hadOneofValue {try decoder.handleConflictingOneOf()} - self.payloadVariant = .storeForwardConfig(v) - } - }() - case 5: try { - var v: Config.ModuleConfig.RangeTestConfig? - var hadOneofValue = false - if let current = self.payloadVariant { - hadOneofValue = true - if case .rangeTestConfig(let m) = current {v = m} - } - try decoder.decodeSingularMessageField(value: &v) - if let v = v { - if hadOneofValue {try decoder.handleConflictingOneOf()} - self.payloadVariant = .rangeTestConfig(v) - } - }() - case 6: try { - var v: Config.ModuleConfig.TelemetryConfig? - var hadOneofValue = false - if let current = self.payloadVariant { - hadOneofValue = true - if case .telemetryConfig(let m) = current {v = m} - } - try decoder.decodeSingularMessageField(value: &v) - if let v = v { - if hadOneofValue {try decoder.handleConflictingOneOf()} - self.payloadVariant = .telemetryConfig(v) - } - }() - case 7: try { - var v: Config.ModuleConfig.CannedMessageConfig? - var hadOneofValue = false - if let current = self.payloadVariant { - hadOneofValue = true - if case .cannedMessageConfig(let m) = current {v = m} - } - try decoder.decodeSingularMessageField(value: &v) - if let v = v { - if hadOneofValue {try decoder.handleConflictingOneOf()} - self.payloadVariant = .cannedMessageConfig(v) - } - }() - 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 - switch self.payloadVariant { - case .mqttConfig?: try { - guard case .mqttConfig(let v)? = self.payloadVariant else { preconditionFailure() } - try visitor.visitSingularMessageField(value: v, fieldNumber: 1) - }() - case .serialConfig?: try { - guard case .serialConfig(let v)? = self.payloadVariant else { preconditionFailure() } - try visitor.visitSingularMessageField(value: v, fieldNumber: 2) - }() - case .externalNotificationConfig?: try { - guard case .externalNotificationConfig(let v)? = self.payloadVariant else { preconditionFailure() } - try visitor.visitSingularMessageField(value: v, fieldNumber: 3) - }() - case .storeForwardConfig?: try { - guard case .storeForwardConfig(let v)? = self.payloadVariant else { preconditionFailure() } - try visitor.visitSingularMessageField(value: v, fieldNumber: 4) - }() - case .rangeTestConfig?: try { - guard case .rangeTestConfig(let v)? = self.payloadVariant else { preconditionFailure() } - try visitor.visitSingularMessageField(value: v, fieldNumber: 5) - }() - case .telemetryConfig?: try { - guard case .telemetryConfig(let v)? = self.payloadVariant else { preconditionFailure() } - try visitor.visitSingularMessageField(value: v, fieldNumber: 6) - }() - case .cannedMessageConfig?: try { - guard case .cannedMessageConfig(let v)? = self.payloadVariant else { preconditionFailure() } - try visitor.visitSingularMessageField(value: v, fieldNumber: 7) - }() - case nil: break - } - try unknownFields.traverse(visitor: &visitor) - } - - static func ==(lhs: Config.ModuleConfig, rhs: Config.ModuleConfig) -> Bool { - if lhs.payloadVariant != rhs.payloadVariant {return false} - if lhs.unknownFields != rhs.unknownFields {return false} - return true - } } -extension Config.ModuleConfig.MQTTConfig: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { - static let protoMessageName: String = Config.ModuleConfig.protoMessageName + ".MQTTConfig" - static let _protobuf_nameMap = SwiftProtobuf._NameMap() - - mutating func decodeMessage(decoder: inout D) throws { - while let _ = try decoder.nextFieldNumber() { - } - } - - func traverse(visitor: inout V) throws { - try unknownFields.traverse(visitor: &visitor) - } - - static func ==(lhs: Config.ModuleConfig.MQTTConfig, rhs: Config.ModuleConfig.MQTTConfig) -> Bool { - if lhs.unknownFields != rhs.unknownFields {return false} - return true - } -} - -extension Config.ModuleConfig.SerialConfig: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { - static let protoMessageName: String = Config.ModuleConfig.protoMessageName + ".SerialConfig" - static let _protobuf_nameMap = SwiftProtobuf._NameMap() - - mutating func decodeMessage(decoder: inout D) throws { - while let _ = try decoder.nextFieldNumber() { - } - } - - func traverse(visitor: inout V) throws { - try unknownFields.traverse(visitor: &visitor) - } - - static func ==(lhs: Config.ModuleConfig.SerialConfig, rhs: Config.ModuleConfig.SerialConfig) -> Bool { - if lhs.unknownFields != rhs.unknownFields {return false} - return true - } -} - -extension Config.ModuleConfig.ExternalNotificationConfig: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { - static let protoMessageName: String = Config.ModuleConfig.protoMessageName + ".ExternalNotificationConfig" - static let _protobuf_nameMap = SwiftProtobuf._NameMap() - - mutating func decodeMessage(decoder: inout D) throws { - while let _ = try decoder.nextFieldNumber() { - } - } - - func traverse(visitor: inout V) throws { - try unknownFields.traverse(visitor: &visitor) - } - - static func ==(lhs: Config.ModuleConfig.ExternalNotificationConfig, rhs: Config.ModuleConfig.ExternalNotificationConfig) -> Bool { - if lhs.unknownFields != rhs.unknownFields {return false} - return true - } -} - -extension Config.ModuleConfig.StoreForwardConfig: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { - static let protoMessageName: String = Config.ModuleConfig.protoMessageName + ".StoreForwardConfig" - static let _protobuf_nameMap = SwiftProtobuf._NameMap() - - mutating func decodeMessage(decoder: inout D) throws { - while let _ = try decoder.nextFieldNumber() { - } - } - - func traverse(visitor: inout V) throws { - try unknownFields.traverse(visitor: &visitor) - } - - static func ==(lhs: Config.ModuleConfig.StoreForwardConfig, rhs: Config.ModuleConfig.StoreForwardConfig) -> Bool { - if lhs.unknownFields != rhs.unknownFields {return false} - return true - } -} - -extension Config.ModuleConfig.RangeTestConfig: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { - static let protoMessageName: String = Config.ModuleConfig.protoMessageName + ".RangeTestConfig" - static let _protobuf_nameMap = SwiftProtobuf._NameMap() - - mutating func decodeMessage(decoder: inout D) throws { - while let _ = try decoder.nextFieldNumber() { - } - } - - func traverse(visitor: inout V) throws { - try unknownFields.traverse(visitor: &visitor) - } - - static func ==(lhs: Config.ModuleConfig.RangeTestConfig, rhs: Config.ModuleConfig.RangeTestConfig) -> Bool { - if lhs.unknownFields != rhs.unknownFields {return false} - return true - } -} - -extension Config.ModuleConfig.TelemetryConfig: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { - static let protoMessageName: String = Config.ModuleConfig.protoMessageName + ".TelemetryConfig" +extension Config.LoRaConfig.ModemPreset: SwiftProtobuf._ProtoNameProviding { static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ - 1: .standard(proto: "device_update_interval"), - 2: .standard(proto: "environment_update_interval"), - 3: .standard(proto: "environment_measurement_enabled"), - 4: .standard(proto: "environment_screen_enabled"), - 5: .standard(proto: "environment_read_error_count_threshold"), - 6: .standard(proto: "environment_recovery_interval"), - 7: .standard(proto: "environment_display_fahrenheit"), - 8: .standard(proto: "environment_sensor_type"), - 9: .standard(proto: "environment_sensor_pin"), + 0: .same(proto: "VLongSlow"), + 1: .same(proto: "LongSlow"), + 2: .same(proto: "LongFast"), + 3: .same(proto: "MidSlow"), + 4: .same(proto: "MidFast"), + 5: .same(proto: "ShortSlow"), + 6: .same(proto: "ShortFast"), ] - - 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.deviceUpdateInterval) }() - case 2: try { try decoder.decodeSingularUInt32Field(value: &self.environmentUpdateInterval) }() - case 3: try { try decoder.decodeSingularBoolField(value: &self.environmentMeasurementEnabled) }() - case 4: try { try decoder.decodeSingularBoolField(value: &self.environmentScreenEnabled) }() - case 5: try { try decoder.decodeSingularUInt32Field(value: &self.environmentReadErrorCountThreshold) }() - case 6: try { try decoder.decodeSingularUInt32Field(value: &self.environmentRecoveryInterval) }() - case 7: try { try decoder.decodeSingularBoolField(value: &self.environmentDisplayFahrenheit) }() - case 8: try { try decoder.decodeSingularEnumField(value: &self.environmentSensorType) }() - case 9: try { try decoder.decodeSingularUInt32Field(value: &self.environmentSensorPin) }() - default: break - } - } - } - - func traverse(visitor: inout V) throws { - if self.deviceUpdateInterval != 0 { - try visitor.visitSingularUInt32Field(value: self.deviceUpdateInterval, fieldNumber: 1) - } - if self.environmentUpdateInterval != 0 { - try visitor.visitSingularUInt32Field(value: self.environmentUpdateInterval, fieldNumber: 2) - } - if self.environmentMeasurementEnabled != false { - try visitor.visitSingularBoolField(value: self.environmentMeasurementEnabled, fieldNumber: 3) - } - if self.environmentScreenEnabled != false { - try visitor.visitSingularBoolField(value: self.environmentScreenEnabled, fieldNumber: 4) - } - if self.environmentReadErrorCountThreshold != 0 { - try visitor.visitSingularUInt32Field(value: self.environmentReadErrorCountThreshold, fieldNumber: 5) - } - if self.environmentRecoveryInterval != 0 { - try visitor.visitSingularUInt32Field(value: self.environmentRecoveryInterval, fieldNumber: 6) - } - if self.environmentDisplayFahrenheit != false { - try visitor.visitSingularBoolField(value: self.environmentDisplayFahrenheit, fieldNumber: 7) - } - if self.environmentSensorType != .notSet { - try visitor.visitSingularEnumField(value: self.environmentSensorType, fieldNumber: 8) - } - if self.environmentSensorPin != 0 { - try visitor.visitSingularUInt32Field(value: self.environmentSensorPin, fieldNumber: 9) - } - try unknownFields.traverse(visitor: &visitor) - } - - static func ==(lhs: Config.ModuleConfig.TelemetryConfig, rhs: Config.ModuleConfig.TelemetryConfig) -> Bool { - if lhs.deviceUpdateInterval != rhs.deviceUpdateInterval {return false} - if lhs.environmentUpdateInterval != rhs.environmentUpdateInterval {return false} - if lhs.environmentMeasurementEnabled != rhs.environmentMeasurementEnabled {return false} - if lhs.environmentScreenEnabled != rhs.environmentScreenEnabled {return false} - if lhs.environmentReadErrorCountThreshold != rhs.environmentReadErrorCountThreshold {return false} - if lhs.environmentRecoveryInterval != rhs.environmentRecoveryInterval {return false} - if lhs.environmentDisplayFahrenheit != rhs.environmentDisplayFahrenheit {return false} - if lhs.environmentSensorType != rhs.environmentSensorType {return false} - if lhs.environmentSensorPin != rhs.environmentSensorPin {return false} - if lhs.unknownFields != rhs.unknownFields {return false} - return true - } -} - -extension Config.ModuleConfig.CannedMessageConfig: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { - static let protoMessageName: String = Config.ModuleConfig.protoMessageName + ".CannedMessageConfig" - static let _protobuf_nameMap = SwiftProtobuf._NameMap() - - mutating func decodeMessage(decoder: inout D) throws { - while let _ = try decoder.nextFieldNumber() { - } - } - - func traverse(visitor: inout V) throws { - try unknownFields.traverse(visitor: &visitor) - } - - static func ==(lhs: Config.ModuleConfig.CannedMessageConfig, rhs: Config.ModuleConfig.CannedMessageConfig) -> Bool { - if lhs.unknownFields != rhs.unknownFields {return false} - return true - } } diff --git a/MeshtasticClient/Protobufs/deviceonly.pb.swift b/MeshtasticClient/Protobufs/deviceonly.pb.swift index a8e59f76..52a31d33 100644 --- a/MeshtasticClient/Protobufs/deviceonly.pb.swift +++ b/MeshtasticClient/Protobufs/deviceonly.pb.swift @@ -89,68 +89,81 @@ struct DeviceState { /// /// Read only settings/info about this node var myNode: MyNodeInfo { - get {return _myNode ?? MyNodeInfo()} - set {_myNode = newValue} + get {return _storage._myNode ?? MyNodeInfo()} + set {_uniqueStorage()._myNode = newValue} } /// Returns true if `myNode` has been explicitly set. - var hasMyNode: Bool {return self._myNode != nil} + var hasMyNode: Bool {return _storage._myNode != nil} /// Clears the value of `myNode`. Subsequent reads from it will return its default value. - mutating func clearMyNode() {self._myNode = nil} + mutating func clearMyNode() {_uniqueStorage()._myNode = nil} /// /// My owner info var owner: User { - get {return _owner ?? User()} - set {_owner = newValue} + get {return _storage._owner ?? User()} + set {_uniqueStorage()._owner = newValue} } /// Returns true if `owner` has been explicitly set. - var hasOwner: Bool {return self._owner != nil} + var hasOwner: Bool {return _storage._owner != nil} /// Clears the value of `owner`. Subsequent reads from it will return its default value. - mutating func clearOwner() {self._owner = nil} + mutating func clearOwner() {_uniqueStorage()._owner = nil} /// /// TODO: REPLACE - var nodeDb: [NodeInfo] = [] + var nodeDb: [NodeInfo] { + get {return _storage._nodeDb} + set {_uniqueStorage()._nodeDb = newValue} + } /// /// Received packets saved for delivery to the phone - var receiveQueue: [MeshPacket] = [] + var receiveQueue: [MeshPacket] { + get {return _storage._receiveQueue} + set {_uniqueStorage()._receiveQueue = newValue} + } /// /// A version integer used to invalidate old save files when we make /// incompatible changes This integer is set at build time and is private to /// NodeDB.cpp in the device code. - var version: UInt32 = 0 + var version: UInt32 { + get {return _storage._version} + set {_uniqueStorage()._version = newValue} + } /// /// We keep the last received text message (only) stored in the device flash, /// so we can show it on the screen. /// Might be null var rxTextMessage: MeshPacket { - get {return _rxTextMessage ?? MeshPacket()} - set {_rxTextMessage = newValue} + get {return _storage._rxTextMessage ?? MeshPacket()} + set {_uniqueStorage()._rxTextMessage = newValue} } /// Returns true if `rxTextMessage` has been explicitly set. - var hasRxTextMessage: Bool {return self._rxTextMessage != nil} + var hasRxTextMessage: Bool {return _storage._rxTextMessage != nil} /// Clears the value of `rxTextMessage`. Subsequent reads from it will return its default value. - mutating func clearRxTextMessage() {self._rxTextMessage = nil} + mutating func clearRxTextMessage() {_uniqueStorage()._rxTextMessage = nil} /// /// Used only during development. /// Indicates developer is testing and changes should never be saved to flash. - var noSave: Bool = false + var noSave: Bool { + get {return _storage._noSave} + set {_uniqueStorage()._noSave = newValue} + } /// /// Some GPSes seem to have bogus settings from the factory, so we always do one factory reset. - var didGpsReset: Bool = false + var didGpsReset: Bool { + get {return _storage._didGpsReset} + set {_uniqueStorage()._didGpsReset = newValue} + } var unknownFields = SwiftProtobuf.UnknownStorage() init() {} - fileprivate var _myNode: MyNodeInfo? = nil - fileprivate var _owner: User? = nil - fileprivate var _rxTextMessage: MeshPacket? = nil + fileprivate var _storage = _StorageClass.defaultInstance } /// @@ -232,66 +245,112 @@ extension DeviceState: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementati 11: .standard(proto: "did_gps_reset"), ] + fileprivate class _StorageClass { + var _myNode: MyNodeInfo? = nil + var _owner: User? = nil + var _nodeDb: [NodeInfo] = [] + var _receiveQueue: [MeshPacket] = [] + var _version: UInt32 = 0 + var _rxTextMessage: MeshPacket? = nil + var _noSave: Bool = false + var _didGpsReset: Bool = false + + static let defaultInstance = _StorageClass() + + private init() {} + + init(copying source: _StorageClass) { + _myNode = source._myNode + _owner = source._owner + _nodeDb = source._nodeDb + _receiveQueue = source._receiveQueue + _version = source._version + _rxTextMessage = source._rxTextMessage + _noSave = source._noSave + _didGpsReset = source._didGpsReset + } + } + + fileprivate mutating func _uniqueStorage() -> _StorageClass { + if !isKnownUniquelyReferenced(&_storage) { + _storage = _StorageClass(copying: _storage) + } + return _storage + } + 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 2: try { try decoder.decodeSingularMessageField(value: &self._myNode) }() - case 3: try { try decoder.decodeSingularMessageField(value: &self._owner) }() - case 4: try { try decoder.decodeRepeatedMessageField(value: &self.nodeDb) }() - case 5: try { try decoder.decodeRepeatedMessageField(value: &self.receiveQueue) }() - case 7: try { try decoder.decodeSingularMessageField(value: &self._rxTextMessage) }() - case 8: try { try decoder.decodeSingularUInt32Field(value: &self.version) }() - case 9: try { try decoder.decodeSingularBoolField(value: &self.noSave) }() - case 11: try { try decoder.decodeSingularBoolField(value: &self.didGpsReset) }() - default: break + _ = _uniqueStorage() + try withExtendedLifetime(_storage) { (_storage: _StorageClass) in + 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 2: try { try decoder.decodeSingularMessageField(value: &_storage._myNode) }() + case 3: try { try decoder.decodeSingularMessageField(value: &_storage._owner) }() + case 4: try { try decoder.decodeRepeatedMessageField(value: &_storage._nodeDb) }() + case 5: try { try decoder.decodeRepeatedMessageField(value: &_storage._receiveQueue) }() + case 7: try { try decoder.decodeSingularMessageField(value: &_storage._rxTextMessage) }() + case 8: try { try decoder.decodeSingularUInt32Field(value: &_storage._version) }() + case 9: try { try decoder.decodeSingularBoolField(value: &_storage._noSave) }() + case 11: try { try decoder.decodeSingularBoolField(value: &_storage._didGpsReset) }() + 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 - try { if let v = self._myNode { - try visitor.visitSingularMessageField(value: v, fieldNumber: 2) - } }() - try { if let v = self._owner { - try visitor.visitSingularMessageField(value: v, fieldNumber: 3) - } }() - if !self.nodeDb.isEmpty { - try visitor.visitRepeatedMessageField(value: self.nodeDb, fieldNumber: 4) - } - if !self.receiveQueue.isEmpty { - try visitor.visitRepeatedMessageField(value: self.receiveQueue, fieldNumber: 5) - } - try { if let v = self._rxTextMessage { - try visitor.visitSingularMessageField(value: v, fieldNumber: 7) - } }() - if self.version != 0 { - try visitor.visitSingularUInt32Field(value: self.version, fieldNumber: 8) - } - if self.noSave != false { - try visitor.visitSingularBoolField(value: self.noSave, fieldNumber: 9) - } - if self.didGpsReset != false { - try visitor.visitSingularBoolField(value: self.didGpsReset, fieldNumber: 11) + try withExtendedLifetime(_storage) { (_storage: _StorageClass) in + // 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 + try { if let v = _storage._myNode { + try visitor.visitSingularMessageField(value: v, fieldNumber: 2) + } }() + try { if let v = _storage._owner { + try visitor.visitSingularMessageField(value: v, fieldNumber: 3) + } }() + if !_storage._nodeDb.isEmpty { + try visitor.visitRepeatedMessageField(value: _storage._nodeDb, fieldNumber: 4) + } + if !_storage._receiveQueue.isEmpty { + try visitor.visitRepeatedMessageField(value: _storage._receiveQueue, fieldNumber: 5) + } + try { if let v = _storage._rxTextMessage { + try visitor.visitSingularMessageField(value: v, fieldNumber: 7) + } }() + if _storage._version != 0 { + try visitor.visitSingularUInt32Field(value: _storage._version, fieldNumber: 8) + } + if _storage._noSave != false { + try visitor.visitSingularBoolField(value: _storage._noSave, fieldNumber: 9) + } + if _storage._didGpsReset != false { + try visitor.visitSingularBoolField(value: _storage._didGpsReset, fieldNumber: 11) + } } try unknownFields.traverse(visitor: &visitor) } static func ==(lhs: DeviceState, rhs: DeviceState) -> Bool { - if lhs._myNode != rhs._myNode {return false} - if lhs._owner != rhs._owner {return false} - if lhs.nodeDb != rhs.nodeDb {return false} - if lhs.receiveQueue != rhs.receiveQueue {return false} - if lhs.version != rhs.version {return false} - if lhs._rxTextMessage != rhs._rxTextMessage {return false} - if lhs.noSave != rhs.noSave {return false} - if lhs.didGpsReset != rhs.didGpsReset {return false} + if lhs._storage !== rhs._storage { + let storagesAreEqual: Bool = withExtendedLifetime((lhs._storage, rhs._storage)) { (_args: (_StorageClass, _StorageClass)) in + let _storage = _args.0 + let rhs_storage = _args.1 + if _storage._myNode != rhs_storage._myNode {return false} + if _storage._owner != rhs_storage._owner {return false} + if _storage._nodeDb != rhs_storage._nodeDb {return false} + if _storage._receiveQueue != rhs_storage._receiveQueue {return false} + if _storage._version != rhs_storage._version {return false} + if _storage._rxTextMessage != rhs_storage._rxTextMessage {return false} + if _storage._noSave != rhs_storage._noSave {return false} + if _storage._didGpsReset != rhs_storage._didGpsReset {return false} + return true + } + if !storagesAreEqual {return false} + } if lhs.unknownFields != rhs.unknownFields {return false} return true } diff --git a/MeshtasticClient/Protobufs/mesh.pb.swift b/MeshtasticClient/Protobufs/mesh.pb.swift index c3f77995..c53f4a8c 100644 --- a/MeshtasticClient/Protobufs/mesh.pb.swift +++ b/MeshtasticClient/Protobufs/mesh.pb.swift @@ -122,6 +122,14 @@ enum HardwareModel: SwiftProtobuf.Enum { /// nRF52840 Dongle : https://www.nordicsemi.com/Products/Development-hardware/nrf52840-dongle/ case nrf52840Pca10059 // = 42 + /// + /// Custom Disaster Radio esp32 v3 device https://github.com/sudomesh/disaster-radio/tree/master/hardware/board_esp32_v3 + case drDev // = 43 + + /// + /// M5 esp32 based MCU modules with enclosure, TFT and LORA Shields. All Variants (Basic, Core, Fire, Core2, Paper) https://m5stack.com/ + case m5Stack // = 44 + /// /// Reserved ID For developing private Ports. These will show up in live traffic sparsely, so we can use a high number. Keep it within 8 bits. case privateHw // = 255 @@ -156,6 +164,8 @@ enum HardwareModel: SwiftProtobuf.Enum { case 40: self = .rak11200 case 41: self = .nanoG1 case 42: self = .nrf52840Pca10059 + case 43: self = .drDev + case 44: self = .m5Stack case 255: self = .privateHw default: self = .UNRECOGNIZED(rawValue) } @@ -186,6 +196,8 @@ enum HardwareModel: SwiftProtobuf.Enum { case .rak11200: return 40 case .nanoG1: return 41 case .nrf52840Pca10059: return 42 + case .drDev: return 43 + case .m5Stack: return 44 case .privateHw: return 255 case .UNRECOGNIZED(let i): return i } @@ -221,6 +233,8 @@ extension HardwareModel: CaseIterable { .rak11200, .nanoG1, .nrf52840Pca10059, + .drDev, + .m5Stack, .privateHw, ] } @@ -1590,45 +1604,20 @@ struct MyNodeInfo { /// /// Tells the phone what our node number is, default starting value is /// lowbyte of macaddr, but it will be fixed if that is already in use - var myNodeNum: UInt32 { - get {return _storage._myNodeNum} - set {_uniqueStorage()._myNodeNum = newValue} - } + var myNodeNum: UInt32 = 0 /// /// Note: This flag merely means we detected a hardware GPS in our node. /// Not the same as UserPreferences.location_sharing - var hasGps_p: Bool { - get {return _storage._hasGps_p} - set {_uniqueStorage()._hasGps_p = newValue} - } + var hasGps_p: Bool = false /// /// The maximum number of 'software' channels that can be set on this node. - var maxChannels: UInt32 { - get {return _storage._maxChannels} - set {_uniqueStorage()._maxChannels = newValue} - } - - /// - /// Deprecated! ONLY USED IN DEVICE CODE (for upgrading old 1.0 firmwares) DO NOT READ ELSEWHERE. - /// The region code for my radio (US, CN, etc...) - /// Note: This string is deprecated. - /// The 1.0 builds populate it based on the flashed firmware name. - /// But for newer builds this string will be unpopulated (missing/null). - /// For those builds you should instead look at the new read/write region enum in UserSettings - /// The format of this string was 1.0-US or 1.0-CN etc.. Or empty string if unset. - var region: String { - get {return _storage._region} - set {_uniqueStorage()._region = newValue} - } + var maxChannels: UInt32 = 0 /// /// 0.0.5 etc... - var firmwareVersion: String { - get {return _storage._firmwareVersion} - set {_uniqueStorage()._firmwareVersion = newValue} - } + var firmwareVersion: String = String() /// /// An error message we'd like to report back to the mothership through analytics. @@ -1637,99 +1626,61 @@ struct MyNodeInfo { /// This field will be cleared after the phone reads MyNodeInfo /// (i.e. it will only be reported once) /// a numeric error code to go with error message, zero means no error - var errorCode: CriticalErrorCode { - get {return _storage._errorCode} - set {_uniqueStorage()._errorCode = newValue} - } + var errorCode: CriticalErrorCode = .none /// /// A numeric error address (nonzero if available) - var errorAddress: UInt32 { - get {return _storage._errorAddress} - set {_uniqueStorage()._errorAddress = newValue} - } + var errorAddress: UInt32 = 0 /// /// The total number of errors this node has ever encountered /// (well - since the last time we discarded preferences) - var errorCount: UInt32 { - get {return _storage._errorCount} - set {_uniqueStorage()._errorCount = newValue} - } + var errorCount: UInt32 = 0 /// /// The total number of reboots this node has ever encountered /// (well - since the last time we discarded preferences) - var rebootCount: UInt32 { - get {return _storage._rebootCount} - set {_uniqueStorage()._rebootCount = newValue} - } + var rebootCount: UInt32 = 0 /// /// Calculated bitrate of the current channel (in Bytes Per Second) - var bitrate: Float { - get {return _storage._bitrate} - set {_uniqueStorage()._bitrate = newValue} - } + var bitrate: Float = 0 /// /// How long before we consider a message abandoned and we can clear our /// caches of any messages in flight Normally quite large to handle the worst case /// message delivery time, 5 minutes. /// Formerly called FLOOD_EXPIRE_TIME in the device code - var messageTimeoutMsec: UInt32 { - get {return _storage._messageTimeoutMsec} - set {_uniqueStorage()._messageTimeoutMsec = newValue} - } + var messageTimeoutMsec: UInt32 = 0 /// /// The minimum app version that can talk to this device. /// Phone/PC apps should compare this to their build number and if too low tell the user they must update their app - var minAppVersion: UInt32 { - get {return _storage._minAppVersion} - set {_uniqueStorage()._minAppVersion = newValue} - } + var minAppVersion: UInt32 = 0 /// /// 24 time windows of 1hr each with the airtime transmitted out of the device per hour. - var airPeriodTx: [UInt32] { - get {return _storage._airPeriodTx} - set {_uniqueStorage()._airPeriodTx = newValue} - } + var airPeriodTx: [UInt32] = [] /// /// 24 time windows of 1hr each with the airtime of valid packets for your mesh. - var airPeriodRx: [UInt32] { - get {return _storage._airPeriodRx} - set {_uniqueStorage()._airPeriodRx = newValue} - } + var airPeriodRx: [UInt32] = [] /// /// Is the device wifi capable? - var hasWifi_p: Bool { - get {return _storage._hasWifi_p} - set {_uniqueStorage()._hasWifi_p = newValue} - } + var hasWifi_p: Bool = false /// /// Utilization for the current channel, including well formed TX, RX and malformed RX (aka noise). - var channelUtilization: Float { - get {return _storage._channelUtilization} - set {_uniqueStorage()._channelUtilization = newValue} - } + var channelUtilization: Float = 0 /// /// Percent of airtime for transmission used within the last hour. - var airUtilTx: Float { - get {return _storage._airUtilTx} - set {_uniqueStorage()._airUtilTx = newValue} - } + var airUtilTx: Float = 0 var unknownFields = SwiftProtobuf.UnknownStorage() init() {} - - fileprivate var _storage = _StorageClass.defaultInstance } /// @@ -1860,20 +1811,26 @@ struct FromRadio { /// /// The packet id, used to allow the phone to request missing read packets from the FIFO, /// see our bluetooth docs - var id: UInt32 = 0 + var id: UInt32 { + get {return _storage._id} + set {_uniqueStorage()._id = newValue} + } /// /// Log levels, chosen to match python logging conventions. - var payloadVariant: FromRadio.OneOf_PayloadVariant? = nil + var payloadVariant: OneOf_PayloadVariant? { + get {return _storage._payloadVariant} + set {_uniqueStorage()._payloadVariant = newValue} + } /// /// Log levels, chosen to match python logging conventions. var packet: MeshPacket { get { - if case .packet(let v)? = payloadVariant {return v} + if case .packet(let v)? = _storage._payloadVariant {return v} return MeshPacket() } - set {payloadVariant = .packet(newValue)} + set {_uniqueStorage()._payloadVariant = .packet(newValue)} } /// @@ -1881,10 +1838,10 @@ struct FromRadio { /// NOTE: This ID must not change - to keep (minimal) compatibility with <1.2 version of android apps. var myInfo: MyNodeInfo { get { - if case .myInfo(let v)? = payloadVariant {return v} + if case .myInfo(let v)? = _storage._payloadVariant {return v} return MyNodeInfo() } - set {payloadVariant = .myInfo(newValue)} + set {_uniqueStorage()._payloadVariant = .myInfo(newValue)} } /// @@ -1892,20 +1849,20 @@ struct FromRadio { /// starts over with the first node in our DB var nodeInfo: NodeInfo { get { - if case .nodeInfo(let v)? = payloadVariant {return v} + if case .nodeInfo(let v)? = _storage._payloadVariant {return v} return NodeInfo() } - set {payloadVariant = .nodeInfo(newValue)} + set {_uniqueStorage()._payloadVariant = .nodeInfo(newValue)} } /// /// Set to send debug console output over our protobuf stream var logRecord: LogRecord { get { - if case .logRecord(let v)? = payloadVariant {return v} + if case .logRecord(let v)? = _storage._payloadVariant {return v} return LogRecord() } - set {payloadVariant = .logRecord(newValue)} + set {_uniqueStorage()._payloadVariant = .logRecord(newValue)} } /// @@ -1915,10 +1872,10 @@ struct FromRadio { /// NOTE: This ID must not change - to keep (minimal) compatibility with <1.2 version of android apps. var configCompleteID: UInt32 { get { - if case .configCompleteID(let v)? = payloadVariant {return v} + if case .configCompleteID(let v)? = _storage._payloadVariant {return v} return 0 } - set {payloadVariant = .configCompleteID(newValue)} + set {_uniqueStorage()._payloadVariant = .configCompleteID(newValue)} } /// @@ -1928,10 +1885,10 @@ struct FromRadio { /// NOTE: This ID must not change - to keep (minimal) compatibility with <1.2 version of android apps. var rebooted: Bool { get { - if case .rebooted(let v)? = payloadVariant {return v} + if case .rebooted(let v)? = _storage._payloadVariant {return v} return false } - set {payloadVariant = .rebooted(newValue)} + set {_uniqueStorage()._payloadVariant = .rebooted(newValue)} } var unknownFields = SwiftProtobuf.UnknownStorage() @@ -2003,6 +1960,8 @@ struct FromRadio { } init() {} + + fileprivate var _storage = _StorageClass.defaultInstance } /// @@ -2150,6 +2109,26 @@ struct ToRadio { init() {} } +/// +/// Compressed message payload +struct Compressed { + // 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. + + /// + /// PortNum to determine the how to handle the compressed payload. + var portnum: PortNum = .unknownApp + + /// + /// Compressed data. + var data: Data = Data() + + var unknownFields = SwiftProtobuf.UnknownStorage() + + init() {} +} + #if swift(>=5.5) && canImport(_Concurrency) extension HardwareModel: @unchecked Sendable {} extension Constants: @unchecked Sendable {} @@ -2178,6 +2157,7 @@ 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) // MARK: - Code below here is support for the SwiftProtobuf runtime. @@ -2207,6 +2187,8 @@ extension HardwareModel: SwiftProtobuf._ProtoNameProviding { 40: .same(proto: "RAK11200"), 41: .same(proto: "NANO_G1"), 42: .same(proto: "NRF52840_PCA10059"), + 43: .same(proto: "DR_DEV"), + 44: .same(proto: "M5STACK"), 255: .same(proto: "PRIVATE_HW"), ] } @@ -3175,7 +3157,6 @@ extension MyNodeInfo: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementatio 1: .standard(proto: "my_node_num"), 2: .standard(proto: "has_gps"), 15: .standard(proto: "max_channels"), - 4: .same(proto: "region"), 6: .standard(proto: "firmware_version"), 7: .standard(proto: "error_code"), 8: .standard(proto: "error_address"), @@ -3191,171 +3172,102 @@ extension MyNodeInfo: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementatio 20: .standard(proto: "air_util_tx"), ] - fileprivate class _StorageClass { - var _myNodeNum: UInt32 = 0 - var _hasGps_p: Bool = false - var _maxChannels: UInt32 = 0 - var _region: String = String() - var _firmwareVersion: String = String() - var _errorCode: CriticalErrorCode = .none - var _errorAddress: UInt32 = 0 - var _errorCount: UInt32 = 0 - var _rebootCount: UInt32 = 0 - var _bitrate: Float = 0 - var _messageTimeoutMsec: UInt32 = 0 - var _minAppVersion: UInt32 = 0 - var _airPeriodTx: [UInt32] = [] - var _airPeriodRx: [UInt32] = [] - var _hasWifi_p: Bool = false - var _channelUtilization: Float = 0 - var _airUtilTx: Float = 0 - - static let defaultInstance = _StorageClass() - - private init() {} - - init(copying source: _StorageClass) { - _myNodeNum = source._myNodeNum - _hasGps_p = source._hasGps_p - _maxChannels = source._maxChannels - _region = source._region - _firmwareVersion = source._firmwareVersion - _errorCode = source._errorCode - _errorAddress = source._errorAddress - _errorCount = source._errorCount - _rebootCount = source._rebootCount - _bitrate = source._bitrate - _messageTimeoutMsec = source._messageTimeoutMsec - _minAppVersion = source._minAppVersion - _airPeriodTx = source._airPeriodTx - _airPeriodRx = source._airPeriodRx - _hasWifi_p = source._hasWifi_p - _channelUtilization = source._channelUtilization - _airUtilTx = source._airUtilTx - } - } - - fileprivate mutating func _uniqueStorage() -> _StorageClass { - if !isKnownUniquelyReferenced(&_storage) { - _storage = _StorageClass(copying: _storage) - } - return _storage - } - mutating func decodeMessage(decoder: inout D) throws { - _ = _uniqueStorage() - try withExtendedLifetime(_storage) { (_storage: _StorageClass) in - 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: &_storage._myNodeNum) }() - case 2: try { try decoder.decodeSingularBoolField(value: &_storage._hasGps_p) }() - case 4: try { try decoder.decodeSingularStringField(value: &_storage._region) }() - case 6: try { try decoder.decodeSingularStringField(value: &_storage._firmwareVersion) }() - case 7: try { try decoder.decodeSingularEnumField(value: &_storage._errorCode) }() - case 8: try { try decoder.decodeSingularUInt32Field(value: &_storage._errorAddress) }() - case 9: try { try decoder.decodeSingularUInt32Field(value: &_storage._errorCount) }() - case 10: try { try decoder.decodeSingularUInt32Field(value: &_storage._rebootCount) }() - case 11: try { try decoder.decodeSingularFloatField(value: &_storage._bitrate) }() - case 13: try { try decoder.decodeSingularUInt32Field(value: &_storage._messageTimeoutMsec) }() - case 14: try { try decoder.decodeSingularUInt32Field(value: &_storage._minAppVersion) }() - case 15: try { try decoder.decodeSingularUInt32Field(value: &_storage._maxChannels) }() - case 16: try { try decoder.decodeRepeatedUInt32Field(value: &_storage._airPeriodTx) }() - case 17: try { try decoder.decodeRepeatedUInt32Field(value: &_storage._airPeriodRx) }() - case 18: try { try decoder.decodeSingularBoolField(value: &_storage._hasWifi_p) }() - case 19: try { try decoder.decodeSingularFloatField(value: &_storage._channelUtilization) }() - case 20: try { try decoder.decodeSingularFloatField(value: &_storage._airUtilTx) }() - default: break - } + 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.myNodeNum) }() + case 2: try { try decoder.decodeSingularBoolField(value: &self.hasGps_p) }() + case 6: try { try decoder.decodeSingularStringField(value: &self.firmwareVersion) }() + case 7: try { try decoder.decodeSingularEnumField(value: &self.errorCode) }() + case 8: try { try decoder.decodeSingularUInt32Field(value: &self.errorAddress) }() + case 9: try { try decoder.decodeSingularUInt32Field(value: &self.errorCount) }() + case 10: try { try decoder.decodeSingularUInt32Field(value: &self.rebootCount) }() + case 11: try { try decoder.decodeSingularFloatField(value: &self.bitrate) }() + case 13: try { try decoder.decodeSingularUInt32Field(value: &self.messageTimeoutMsec) }() + case 14: try { try decoder.decodeSingularUInt32Field(value: &self.minAppVersion) }() + case 15: try { try decoder.decodeSingularUInt32Field(value: &self.maxChannels) }() + case 16: try { try decoder.decodeRepeatedUInt32Field(value: &self.airPeriodTx) }() + case 17: try { try decoder.decodeRepeatedUInt32Field(value: &self.airPeriodRx) }() + case 18: try { try decoder.decodeSingularBoolField(value: &self.hasWifi_p) }() + case 19: try { try decoder.decodeSingularFloatField(value: &self.channelUtilization) }() + case 20: try { try decoder.decodeSingularFloatField(value: &self.airUtilTx) }() + default: break } } } func traverse(visitor: inout V) throws { - try withExtendedLifetime(_storage) { (_storage: _StorageClass) in - if _storage._myNodeNum != 0 { - try visitor.visitSingularUInt32Field(value: _storage._myNodeNum, fieldNumber: 1) - } - if _storage._hasGps_p != false { - try visitor.visitSingularBoolField(value: _storage._hasGps_p, fieldNumber: 2) - } - if !_storage._region.isEmpty { - try visitor.visitSingularStringField(value: _storage._region, fieldNumber: 4) - } - if !_storage._firmwareVersion.isEmpty { - try visitor.visitSingularStringField(value: _storage._firmwareVersion, fieldNumber: 6) - } - if _storage._errorCode != .none { - try visitor.visitSingularEnumField(value: _storage._errorCode, fieldNumber: 7) - } - if _storage._errorAddress != 0 { - try visitor.visitSingularUInt32Field(value: _storage._errorAddress, fieldNumber: 8) - } - if _storage._errorCount != 0 { - try visitor.visitSingularUInt32Field(value: _storage._errorCount, fieldNumber: 9) - } - if _storage._rebootCount != 0 { - try visitor.visitSingularUInt32Field(value: _storage._rebootCount, fieldNumber: 10) - } - if _storage._bitrate != 0 { - try visitor.visitSingularFloatField(value: _storage._bitrate, fieldNumber: 11) - } - if _storage._messageTimeoutMsec != 0 { - try visitor.visitSingularUInt32Field(value: _storage._messageTimeoutMsec, fieldNumber: 13) - } - if _storage._minAppVersion != 0 { - try visitor.visitSingularUInt32Field(value: _storage._minAppVersion, fieldNumber: 14) - } - if _storage._maxChannels != 0 { - try visitor.visitSingularUInt32Field(value: _storage._maxChannels, fieldNumber: 15) - } - if !_storage._airPeriodTx.isEmpty { - try visitor.visitPackedUInt32Field(value: _storage._airPeriodTx, fieldNumber: 16) - } - if !_storage._airPeriodRx.isEmpty { - try visitor.visitPackedUInt32Field(value: _storage._airPeriodRx, fieldNumber: 17) - } - if _storage._hasWifi_p != false { - try visitor.visitSingularBoolField(value: _storage._hasWifi_p, fieldNumber: 18) - } - if _storage._channelUtilization != 0 { - try visitor.visitSingularFloatField(value: _storage._channelUtilization, fieldNumber: 19) - } - if _storage._airUtilTx != 0 { - try visitor.visitSingularFloatField(value: _storage._airUtilTx, fieldNumber: 20) - } + if self.myNodeNum != 0 { + try visitor.visitSingularUInt32Field(value: self.myNodeNum, fieldNumber: 1) + } + if self.hasGps_p != false { + try visitor.visitSingularBoolField(value: self.hasGps_p, fieldNumber: 2) + } + if !self.firmwareVersion.isEmpty { + try visitor.visitSingularStringField(value: self.firmwareVersion, fieldNumber: 6) + } + if self.errorCode != .none { + try visitor.visitSingularEnumField(value: self.errorCode, fieldNumber: 7) + } + if self.errorAddress != 0 { + try visitor.visitSingularUInt32Field(value: self.errorAddress, fieldNumber: 8) + } + if self.errorCount != 0 { + try visitor.visitSingularUInt32Field(value: self.errorCount, fieldNumber: 9) + } + if self.rebootCount != 0 { + try visitor.visitSingularUInt32Field(value: self.rebootCount, fieldNumber: 10) + } + if self.bitrate != 0 { + try visitor.visitSingularFloatField(value: self.bitrate, fieldNumber: 11) + } + if self.messageTimeoutMsec != 0 { + try visitor.visitSingularUInt32Field(value: self.messageTimeoutMsec, fieldNumber: 13) + } + if self.minAppVersion != 0 { + try visitor.visitSingularUInt32Field(value: self.minAppVersion, fieldNumber: 14) + } + if self.maxChannels != 0 { + try visitor.visitSingularUInt32Field(value: self.maxChannels, fieldNumber: 15) + } + if !self.airPeriodTx.isEmpty { + try visitor.visitPackedUInt32Field(value: self.airPeriodTx, fieldNumber: 16) + } + if !self.airPeriodRx.isEmpty { + try visitor.visitPackedUInt32Field(value: self.airPeriodRx, fieldNumber: 17) + } + if self.hasWifi_p != false { + try visitor.visitSingularBoolField(value: self.hasWifi_p, fieldNumber: 18) + } + if self.channelUtilization != 0 { + try visitor.visitSingularFloatField(value: self.channelUtilization, fieldNumber: 19) + } + if self.airUtilTx != 0 { + try visitor.visitSingularFloatField(value: self.airUtilTx, fieldNumber: 20) } try unknownFields.traverse(visitor: &visitor) } static func ==(lhs: MyNodeInfo, rhs: MyNodeInfo) -> Bool { - if lhs._storage !== rhs._storage { - let storagesAreEqual: Bool = withExtendedLifetime((lhs._storage, rhs._storage)) { (_args: (_StorageClass, _StorageClass)) in - let _storage = _args.0 - let rhs_storage = _args.1 - if _storage._myNodeNum != rhs_storage._myNodeNum {return false} - if _storage._hasGps_p != rhs_storage._hasGps_p {return false} - if _storage._maxChannels != rhs_storage._maxChannels {return false} - if _storage._region != rhs_storage._region {return false} - if _storage._firmwareVersion != rhs_storage._firmwareVersion {return false} - if _storage._errorCode != rhs_storage._errorCode {return false} - if _storage._errorAddress != rhs_storage._errorAddress {return false} - if _storage._errorCount != rhs_storage._errorCount {return false} - if _storage._rebootCount != rhs_storage._rebootCount {return false} - if _storage._bitrate != rhs_storage._bitrate {return false} - if _storage._messageTimeoutMsec != rhs_storage._messageTimeoutMsec {return false} - if _storage._minAppVersion != rhs_storage._minAppVersion {return false} - if _storage._airPeriodTx != rhs_storage._airPeriodTx {return false} - if _storage._airPeriodRx != rhs_storage._airPeriodRx {return false} - if _storage._hasWifi_p != rhs_storage._hasWifi_p {return false} - if _storage._channelUtilization != rhs_storage._channelUtilization {return false} - if _storage._airUtilTx != rhs_storage._airUtilTx {return false} - return true - } - if !storagesAreEqual {return false} - } + if lhs.myNodeNum != rhs.myNodeNum {return false} + if lhs.hasGps_p != rhs.hasGps_p {return false} + if lhs.maxChannels != rhs.maxChannels {return false} + if lhs.firmwareVersion != rhs.firmwareVersion {return false} + if lhs.errorCode != rhs.errorCode {return false} + if lhs.errorAddress != rhs.errorAddress {return false} + if lhs.errorCount != rhs.errorCount {return false} + if lhs.rebootCount != rhs.rebootCount {return false} + if lhs.bitrate != rhs.bitrate {return false} + if lhs.messageTimeoutMsec != rhs.messageTimeoutMsec {return false} + if lhs.minAppVersion != rhs.minAppVersion {return false} + if lhs.airPeriodTx != rhs.airPeriodTx {return false} + if lhs.airPeriodRx != rhs.airPeriodRx {return false} + if lhs.hasWifi_p != rhs.hasWifi_p {return false} + if lhs.channelUtilization != rhs.channelUtilization {return false} + if lhs.airUtilTx != rhs.airUtilTx {return false} if lhs.unknownFields != rhs.unknownFields {return false} return true } @@ -3435,127 +3347,161 @@ extension FromRadio: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementation 9: .same(proto: "rebooted"), ] + fileprivate class _StorageClass { + var _id: UInt32 = 0 + var _payloadVariant: FromRadio.OneOf_PayloadVariant? + + static let defaultInstance = _StorageClass() + + private init() {} + + init(copying source: _StorageClass) { + _id = source._id + _payloadVariant = source._payloadVariant + } + } + + fileprivate mutating func _uniqueStorage() -> _StorageClass { + if !isKnownUniquelyReferenced(&_storage) { + _storage = _StorageClass(copying: _storage) + } + return _storage + } + 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.id) }() - case 3: try { - var v: MyNodeInfo? - var hadOneofValue = false - if let current = self.payloadVariant { - hadOneofValue = true - if case .myInfo(let m) = current {v = m} + _ = _uniqueStorage() + try withExtendedLifetime(_storage) { (_storage: _StorageClass) in + 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: &_storage._id) }() + case 3: try { + var v: MyNodeInfo? + var hadOneofValue = false + if let current = _storage._payloadVariant { + hadOneofValue = true + if case .myInfo(let m) = current {v = m} + } + try decoder.decodeSingularMessageField(value: &v) + if let v = v { + if hadOneofValue {try decoder.handleConflictingOneOf()} + _storage._payloadVariant = .myInfo(v) + } + }() + case 4: try { + var v: NodeInfo? + var hadOneofValue = false + if let current = _storage._payloadVariant { + hadOneofValue = true + if case .nodeInfo(let m) = current {v = m} + } + try decoder.decodeSingularMessageField(value: &v) + if let v = v { + if hadOneofValue {try decoder.handleConflictingOneOf()} + _storage._payloadVariant = .nodeInfo(v) + } + }() + case 7: try { + var v: LogRecord? + var hadOneofValue = false + if let current = _storage._payloadVariant { + hadOneofValue = true + if case .logRecord(let m) = current {v = m} + } + try decoder.decodeSingularMessageField(value: &v) + if let v = v { + if hadOneofValue {try decoder.handleConflictingOneOf()} + _storage._payloadVariant = .logRecord(v) + } + }() + case 8: try { + var v: UInt32? + try decoder.decodeSingularUInt32Field(value: &v) + if let v = v { + if _storage._payloadVariant != nil {try decoder.handleConflictingOneOf()} + _storage._payloadVariant = .configCompleteID(v) + } + }() + case 9: try { + var v: Bool? + try decoder.decodeSingularBoolField(value: &v) + if let v = v { + if _storage._payloadVariant != nil {try decoder.handleConflictingOneOf()} + _storage._payloadVariant = .rebooted(v) + } + }() + case 11: try { + var v: MeshPacket? + var hadOneofValue = false + if let current = _storage._payloadVariant { + hadOneofValue = true + if case .packet(let m) = current {v = m} + } + try decoder.decodeSingularMessageField(value: &v) + if let v = v { + if hadOneofValue {try decoder.handleConflictingOneOf()} + _storage._payloadVariant = .packet(v) + } + }() + default: break } - try decoder.decodeSingularMessageField(value: &v) - if let v = v { - if hadOneofValue {try decoder.handleConflictingOneOf()} - self.payloadVariant = .myInfo(v) - } - }() - case 4: try { - var v: NodeInfo? - var hadOneofValue = false - if let current = self.payloadVariant { - hadOneofValue = true - if case .nodeInfo(let m) = current {v = m} - } - try decoder.decodeSingularMessageField(value: &v) - if let v = v { - if hadOneofValue {try decoder.handleConflictingOneOf()} - self.payloadVariant = .nodeInfo(v) - } - }() - case 7: try { - var v: LogRecord? - var hadOneofValue = false - if let current = self.payloadVariant { - hadOneofValue = true - if case .logRecord(let m) = current {v = m} - } - try decoder.decodeSingularMessageField(value: &v) - if let v = v { - if hadOneofValue {try decoder.handleConflictingOneOf()} - self.payloadVariant = .logRecord(v) - } - }() - case 8: try { - var v: UInt32? - try decoder.decodeSingularUInt32Field(value: &v) - if let v = v { - if self.payloadVariant != nil {try decoder.handleConflictingOneOf()} - self.payloadVariant = .configCompleteID(v) - } - }() - case 9: try { - var v: Bool? - try decoder.decodeSingularBoolField(value: &v) - if let v = v { - if self.payloadVariant != nil {try decoder.handleConflictingOneOf()} - self.payloadVariant = .rebooted(v) - } - }() - case 11: try { - var v: MeshPacket? - var hadOneofValue = false - if let current = self.payloadVariant { - hadOneofValue = true - if case .packet(let m) = current {v = m} - } - try decoder.decodeSingularMessageField(value: &v) - if let v = v { - if hadOneofValue {try decoder.handleConflictingOneOf()} - self.payloadVariant = .packet(v) - } - }() - 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.id != 0 { - try visitor.visitSingularUInt32Field(value: self.id, fieldNumber: 1) - } - switch self.payloadVariant { - case .myInfo?: try { - guard case .myInfo(let v)? = self.payloadVariant else { preconditionFailure() } - try visitor.visitSingularMessageField(value: v, fieldNumber: 3) - }() - case .nodeInfo?: try { - guard case .nodeInfo(let v)? = self.payloadVariant else { preconditionFailure() } - try visitor.visitSingularMessageField(value: v, fieldNumber: 4) - }() - case .logRecord?: try { - guard case .logRecord(let v)? = self.payloadVariant else { preconditionFailure() } - try visitor.visitSingularMessageField(value: v, fieldNumber: 7) - }() - case .configCompleteID?: try { - guard case .configCompleteID(let v)? = self.payloadVariant else { preconditionFailure() } - try visitor.visitSingularUInt32Field(value: v, fieldNumber: 8) - }() - case .rebooted?: try { - guard case .rebooted(let v)? = self.payloadVariant else { preconditionFailure() } - try visitor.visitSingularBoolField(value: v, fieldNumber: 9) - }() - case .packet?: try { - guard case .packet(let v)? = self.payloadVariant else { preconditionFailure() } - try visitor.visitSingularMessageField(value: v, fieldNumber: 11) - }() - case nil: break + try withExtendedLifetime(_storage) { (_storage: _StorageClass) in + // 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 _storage._id != 0 { + try visitor.visitSingularUInt32Field(value: _storage._id, fieldNumber: 1) + } + switch _storage._payloadVariant { + case .myInfo?: try { + guard case .myInfo(let v)? = _storage._payloadVariant else { preconditionFailure() } + try visitor.visitSingularMessageField(value: v, fieldNumber: 3) + }() + case .nodeInfo?: try { + guard case .nodeInfo(let v)? = _storage._payloadVariant else { preconditionFailure() } + try visitor.visitSingularMessageField(value: v, fieldNumber: 4) + }() + case .logRecord?: try { + guard case .logRecord(let v)? = _storage._payloadVariant else { preconditionFailure() } + try visitor.visitSingularMessageField(value: v, fieldNumber: 7) + }() + case .configCompleteID?: try { + guard case .configCompleteID(let v)? = _storage._payloadVariant else { preconditionFailure() } + try visitor.visitSingularUInt32Field(value: v, fieldNumber: 8) + }() + case .rebooted?: try { + guard case .rebooted(let v)? = _storage._payloadVariant else { preconditionFailure() } + try visitor.visitSingularBoolField(value: v, fieldNumber: 9) + }() + case .packet?: try { + guard case .packet(let v)? = _storage._payloadVariant else { preconditionFailure() } + try visitor.visitSingularMessageField(value: v, fieldNumber: 11) + }() + case nil: break + } } try unknownFields.traverse(visitor: &visitor) } static func ==(lhs: FromRadio, rhs: FromRadio) -> Bool { - if lhs.id != rhs.id {return false} - if lhs.payloadVariant != rhs.payloadVariant {return false} + if lhs._storage !== rhs._storage { + let storagesAreEqual: Bool = withExtendedLifetime((lhs._storage, rhs._storage)) { (_args: (_StorageClass, _StorageClass)) in + let _storage = _args.0 + let rhs_storage = _args.1 + if _storage._id != rhs_storage._id {return false} + if _storage._payloadVariant != rhs_storage._payloadVariant {return false} + return true + } + if !storagesAreEqual {return false} + } if lhs.unknownFields != rhs.unknownFields {return false} return true } @@ -3694,3 +3640,41 @@ extension ToRadio.PeerInfo: SwiftProtobuf.Message, SwiftProtobuf._MessageImpleme return true } } + +extension Compressed: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + static let protoMessageName: String = "Compressed" + static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "portnum"), + 2: .same(proto: "data"), + ] + + 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.decodeSingularEnumField(value: &self.portnum) }() + case 2: try { try decoder.decodeSingularBytesField(value: &self.data) }() + default: break + } + } + } + + func traverse(visitor: inout V) throws { + if self.portnum != .unknownApp { + try visitor.visitSingularEnumField(value: self.portnum, fieldNumber: 1) + } + if !self.data.isEmpty { + try visitor.visitSingularBytesField(value: self.data, fieldNumber: 2) + } + try unknownFields.traverse(visitor: &visitor) + } + + static func ==(lhs: Compressed, rhs: Compressed) -> Bool { + if lhs.portnum != rhs.portnum {return false} + if lhs.data != rhs.data {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} diff --git a/MeshtasticClient/Protobufs/portnums.pb.swift b/MeshtasticClient/Protobufs/portnums.pb.swift index 57102fd2..db2d73bd 100644 --- a/MeshtasticClient/Protobufs/portnums.pb.swift +++ b/MeshtasticClient/Protobufs/portnums.pb.swift @@ -46,7 +46,6 @@ enum PortNum: SwiftProtobuf.Enum { /// A simple UTF-8 text message, which even the little micros in the mesh /// can understand and show on their screen eventually in some circumstances /// even signal might send messages in this form (see below) - /// Formerly called CLEAR_TEXT case textMessageApp // = 1 /// @@ -111,6 +110,10 @@ enum PortNum: SwiftProtobuf.Enum { /// Project files at https://github.com/a-f-G-U-C/Meshtastic-ZPS case zpsApp // = 68 + /// + /// Compressed payloads. + case compressionApp // = 69 + /// /// Private applications should use portnums >= 256. /// To simplify initial development and testing you can use "PRIVATE_APP" @@ -146,6 +149,7 @@ enum PortNum: SwiftProtobuf.Enum { case 66: self = .rangeTestApp case 67: self = .telemetryApp case 68: self = .zpsApp + case 69: self = .compressionApp case 256: self = .privateApp case 257: self = .atakForwarder case 511: self = .max @@ -169,6 +173,7 @@ enum PortNum: SwiftProtobuf.Enum { case .rangeTestApp: return 66 case .telemetryApp: return 67 case .zpsApp: return 68 + case .compressionApp: return 69 case .privateApp: return 256 case .atakForwarder: return 257 case .max: return 511 @@ -197,6 +202,7 @@ extension PortNum: CaseIterable { .rangeTestApp, .telemetryApp, .zpsApp, + .compressionApp, .privateApp, .atakForwarder, .max, @@ -227,6 +233,7 @@ extension PortNum: SwiftProtobuf._ProtoNameProviding { 66: .same(proto: "RANGE_TEST_APP"), 67: .same(proto: "TELEMETRY_APP"), 68: .same(proto: "ZPS_APP"), + 69: .same(proto: "COMPRESSION_APP"), 256: .same(proto: "PRIVATE_APP"), 257: .same(proto: "ATAK_FORWARDER"), 511: .same(proto: "MAX"),