diff --git a/Meshtastic/Helpers/BLEManager.swift b/Meshtastic/Helpers/BLEManager.swift index bdc28320..6b5058df 100644 --- a/Meshtastic/Helpers/BLEManager.swift +++ b/Meshtastic/Helpers/BLEManager.swift @@ -29,7 +29,7 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph @Published var connectedPeripheral: Peripheral! @Published var lastConnectionError: String - @Published var minimumVersion = "1.3.41" + @Published var minimumVersion = "1.3.42" @Published var connectedVersion: String @Published var invalidVersion = false @Published var preferredPeripheral = false diff --git a/Meshtastic/Helpers/MeshPackets.swift b/Meshtastic/Helpers/MeshPackets.swift index 9ad70170..2792317e 100644 --- a/Meshtastic/Helpers/MeshPackets.swift +++ b/Meshtastic/Helpers/MeshPackets.swift @@ -194,32 +194,31 @@ func localConfig (config: Config, meshlogging: Bool, context:NSManagedObjectCont let newLoRaConfig = LoRaConfigEntity(context: context) newLoRaConfig.regionCode = Int32(config.lora.region.rawValue) - newLoRaConfig.modemPreset = Int32(config.lora.modemPreset.rawValue) - newLoRaConfig.hopLimit = Int32(config.lora.hopLimit) - newLoRaConfig.txPower = Int32(config.lora.txPower) - newLoRaConfig.txEnabled = config.lora.txEnabled newLoRaConfig.usePreset = config.lora.usePreset + newLoRaConfig.modemPreset = Int32(config.lora.modemPreset.rawValue) newLoRaConfig.bandwidth = Int32(config.lora.bandwidth) newLoRaConfig.spreadFactor = Int32(config.lora.spreadFactor) newLoRaConfig.codingRate = Int32(config.lora.codingRate) - newLoRaConfig.spreadFactor = Int32(config.lora.spreadFactor) - newLoRaConfig.frequencyOffset = Int32(config.lora.frequencyOffset) - + newLoRaConfig.frequencyOffset = config.lora.frequencyOffset + newLoRaConfig.hopLimit = Int32(config.lora.hopLimit) + newLoRaConfig.txPower = Int32(config.lora.txPower) + newLoRaConfig.txEnabled = config.lora.txEnabled + newLoRaConfig.channelNum = Int32(config.lora.channelNum) fetchedNode[0].loRaConfig = newLoRaConfig } else { fetchedNode[0].loRaConfig?.regionCode = Int32(config.lora.region.rawValue) - fetchedNode[0].loRaConfig?.modemPreset = Int32(config.lora.modemPreset.rawValue) - fetchedNode[0].loRaConfig?.hopLimit = Int32(config.lora.hopLimit) - fetchedNode[0].loRaConfig?.txPower = Int32(config.lora.txPower) - fetchedNode[0].loRaConfig?.txEnabled = config.lora.txEnabled fetchedNode[0].loRaConfig?.usePreset = config.lora.usePreset + fetchedNode[0].loRaConfig?.modemPreset = Int32(config.lora.modemPreset.rawValue) fetchedNode[0].loRaConfig?.bandwidth = Int32(config.lora.bandwidth) fetchedNode[0].loRaConfig?.spreadFactor = Int32(config.lora.spreadFactor) fetchedNode[0].loRaConfig?.codingRate = Int32(config.lora.codingRate) - fetchedNode[0].loRaConfig?.spreadFactor = Int32(config.lora.spreadFactor) - fetchedNode[0].loRaConfig?.frequencyOffset = Int32(config.lora.frequencyOffset) + fetchedNode[0].loRaConfig?.frequencyOffset = config.lora.frequencyOffset + fetchedNode[0].loRaConfig?.hopLimit = Int32(config.lora.hopLimit) + fetchedNode[0].loRaConfig?.txPower = Int32(config.lora.txPower) + fetchedNode[0].loRaConfig?.txEnabled = config.lora.txEnabled + fetchedNode[0].loRaConfig?.channelNum = Int32(config.lora.channelNum) } do { @@ -239,7 +238,6 @@ func localConfig (config: Config, meshlogging: Bool, context:NSManagedObjectCont print("💥 No Nodes found in local database matching node number \(nodeNum) unable to save Lora Config") } - } catch { let nsError = error as NSError diff --git a/Meshtastic/Meshtastic.xcdatamodeld/MeshtasticDataModel.xcdatamodel/contents b/Meshtastic/Meshtastic.xcdatamodeld/MeshtasticDataModel.xcdatamodel/contents index a34a3211..c79ca23e 100644 --- a/Meshtastic/Meshtastic.xcdatamodeld/MeshtasticDataModel.xcdatamodel/contents +++ b/Meshtastic/Meshtastic.xcdatamodeld/MeshtasticDataModel.xcdatamodel/contents @@ -24,7 +24,7 @@ - + @@ -60,7 +60,7 @@ - + diff --git a/Meshtastic/Views/Settings/ShareChannels.swift b/Meshtastic/Views/Settings/ShareChannels.swift index e9907486..d5ac1ae1 100644 --- a/Meshtastic/Views/Settings/ShareChannels.swift +++ b/Meshtastic/Views/Settings/ShareChannels.swift @@ -29,6 +29,8 @@ struct QrCodeImage { return qrImage } } + + struct ShareChannels: View { @Environment(\.managedObjectContext) var context @@ -50,7 +52,7 @@ struct ShareChannels: View { var node: NodeInfoEntity? - @State private var channelsUrl = "https://meshtastic.org/e/#test" + @State private var channelsUrl = "https://meshtastic.org/e/#" var qrCodeImage = QrCodeImage() var body: some View { @@ -93,7 +95,7 @@ struct ShareChannels: View { Toggle("Channel 0 Included", isOn: $includeChannel0) .toggleStyle(.switch) .labelsHidden() - .disabled(true) + .disabled(channel.role == 1) Text((channel.name!.isEmpty ? "Primary" : channel.name) ?? "Primary") } else if channel.index == 1 { @@ -142,10 +144,9 @@ struct ShareChannels: View { if channel.role > 0 { Image(systemName: "lock.fill") .foregroundColor(.green) - } else { + } else { Image(systemName: "lock.slash") .foregroundColor(.gray) - } Spacer() } @@ -166,8 +167,7 @@ struct ShareChannels: View { ) .buttonStyle(.bordered) .buttonBorderShape(.capsule) - .controlSize(.small) - .padding(.bottom) + .controlSize(.large) Image(uiImage: qrImage) .resizable() @@ -192,7 +192,6 @@ struct ShareChannels: View { .buttonBorderShape(.capsule) .controlSize(.small) .padding(.top) - } } .sheet(isPresented: $isPresentingHelp) { @@ -238,11 +237,43 @@ struct ShareChannels: View { self.bleManager.context = context self.initialLoad = false - channelSet = ChannelSet() + GenerateChannelSet() } } } .navigationViewStyle(StackNavigationViewStyle()) } } + func GenerateChannelSet() { + + var loRaConfig = Config.LoRaConfig() + loRaConfig.region = RegionCodes(rawValue: Int(node!.loRaConfig!.regionCode))!.protoEnumValue() + loRaConfig.modemPreset = ModemPresets(rawValue: Int(node!.loRaConfig!.modemPreset))!.protoEnumValue() + loRaConfig.bandwidth = UInt32(node!.loRaConfig!.bandwidth) + loRaConfig.spreadFactor = UInt32(node!.loRaConfig!.spreadFactor) + loRaConfig.codingRate = UInt32(node!.loRaConfig!.codingRate) + loRaConfig.frequencyOffset = node!.loRaConfig!.frequencyOffset + loRaConfig.hopLimit = UInt32(node!.loRaConfig!.hopLimit) + loRaConfig.txEnabled = node!.loRaConfig!.txEnabled + loRaConfig.txPower = node!.loRaConfig!.txPower + loRaConfig.channelNum = UInt32(node!.loRaConfig!.channelNum) + + channelSet.loraConfig = loRaConfig + + for ch in node!.myInfo!.channels!.array as! [ChannelEntity] { + print(ch) + if ch.role > 0 { + var channelSettings = ChannelSettings() + channelSettings.name = ch.name! + channelSettings.psk = ch.psk ?? Data() + channelSettings.id = UInt32(ch.id) + channelSettings.uplinkEnabled = ch.uplinkEnabled + channelSettings.downlinkEnabled = ch.downlinkEnabled + channelSet.settings.append(channelSettings) + } + } + + let settingsString = try! channelSet.serializedData().base64EncodedString(options: [.endLineWithLineFeed]) + channelsUrl = "https://www.meshtastic.org/e/#" + settingsString.dropLast(2) + } }