From 30dc0874bcc076cd9a11e909932210c0d9c3a9d0 Mon Sep 17 00:00:00 2001 From: Garth Vander Houwen Date: Sun, 14 Jan 2024 21:00:54 -0800 Subject: [PATCH] Fix some store and forwared admin config bugs --- Meshtastic/Helpers/BLEManager.swift | 27 ++++++++ .../Settings/Config/Module/StoreForward.swift | 10 +-- Meshtastic/Views/Settings/Firmware.swift | 67 ++++++++++++------- 3 files changed, 73 insertions(+), 31 deletions(-) diff --git a/Meshtastic/Helpers/BLEManager.swift b/Meshtastic/Helpers/BLEManager.swift index 2f262eb4..d65053af 100644 --- a/Meshtastic/Helpers/BLEManager.swift +++ b/Meshtastic/Helpers/BLEManager.swift @@ -2277,6 +2277,33 @@ class BLEManager: NSObject, CBPeripheralDelegate, MqttClientProxyManagerDelegate return false } + public func requestStoreAndForwardModuleConfig(fromUser: UserEntity, toUser: UserEntity, adminIndex: Int32) -> Bool { + + var adminPacket = AdminMessage() + adminPacket.getModuleConfigRequest = AdminMessage.ModuleConfigType.storeforwardConfig + + var meshPacket: MeshPacket = MeshPacket() + meshPacket.to = UInt32(toUser.num) + meshPacket.from = UInt32(fromUser.num) + meshPacket.id = UInt32.random(in: UInt32(UInt8.max).. Bool { var adminPacket = AdminMessage() diff --git a/Meshtastic/Views/Settings/Config/Module/StoreForward.swift b/Meshtastic/Views/Settings/Config/Module/StoreForward.swift index 7241442f..483ff4cc 100644 --- a/Meshtastic/Views/Settings/Config/Module/StoreForward.swift +++ b/Meshtastic/Views/Settings/Config/Module/StoreForward.swift @@ -44,7 +44,7 @@ struct StoreForwardConfig: View { Text("Remote administration for: \(node?.user?.longName ?? "Unknown")") .font(.title3) .onAppear { - setDetectionSensorValues() + setStoreAndForwardValues() } } } else if node != nil && node?.num ?? 0 == bleManager.connectedPeripheral?.num ?? 0 { @@ -140,13 +140,13 @@ struct StoreForwardConfig: View { if self.bleManager.context == nil { self.bleManager.context = context } - setDetectionSensorValues() + setStoreAndForwardValues() // Need to request a Detection Sensor Module Config from the remote node before allowing changes - if bleManager.connectedPeripheral != nil && node?.detectionSensorConfig == nil { + if bleManager.connectedPeripheral != nil && node?.storeForwardConfig == nil { print("empty store and forward module config") let connectedNode = getNodeInfo(id: bleManager.connectedPeripheral.num, context: context) if node != nil && connectedNode != nil { - _ = bleManager.requestDetectionSensorModuleConfig(fromUser: connectedNode!.user!, toUser: node!.user!, adminIndex: connectedNode?.myInfo?.adminIndex ?? 0) + _ = bleManager.requestStoreAndForwardModuleConfig(fromUser: connectedNode!.user!, toUser: node!.user!, adminIndex: connectedNode?.myInfo?.adminIndex ?? 0) } } } @@ -176,7 +176,7 @@ struct StoreForwardConfig: View { } } } - func setDetectionSensorValues() { + func setStoreAndForwardValues() { self.enabled = (node?.storeForwardConfig?.enabled ?? false) self.heartbeat = (node?.storeForwardConfig?.heartbeat ?? true) self.records = Int(node?.storeForwardConfig?.records ?? 50) diff --git a/Meshtastic/Views/Settings/Firmware.swift b/Meshtastic/Views/Settings/Firmware.swift index 3e6a56ef..7395af18 100644 --- a/Meshtastic/Views/Settings/Firmware.swift +++ b/Meshtastic/Views/Settings/Firmware.swift @@ -46,9 +46,14 @@ struct Firmware: View { if supportedVersion { Text("Your Firmware is up to date") - .font(.title) - Text("Current Firmware Version: \(bleManager.connectedVersion)") + .fixedSize(horizontal: false, vertical: true) + .foregroundStyle(.green) .font(.title2) + .padding(.bottom) + Text("Current Firmware Version: \(bleManager.connectedVersion)") + .fixedSize(horizontal: false, vertical: true) + .font(.title3) + .padding(.bottom) } else { Text("Your Firmware is out of date") .fixedSize(horizontal: false, vertical: true) @@ -60,35 +65,45 @@ struct Firmware: View { .font(.title3) .padding(.bottom) } - + Divider() + Text("How to update Firmware") + .fixedSize(horizontal: false, vertical: true) + .font(.title2) + .padding(.bottom) if currentDevice?.architecture == Meshtastic.Architecture.nrf52840 { VStack(alignment: .leading) { + + Text("Drag & Drop is the reccomended way to update firmware for NRF devices.") + .fixedSize(horizontal: false, vertical: true) + .foregroundStyle(.gray) + .font(.caption) + Link("Drag & Drop Firmware Update", destination: URL(string: "https://meshtastic.org/docs/getting-started/flashing-firmware/nrf52/drag-n-drop")!) + .font(.callout) + + Button { + let connectedNode = getNodeInfo(id: bleManager.connectedPeripheral?.num ?? 0, context: context) + if connectedNode != nil { + if !bleManager.sendEnterDfuMode(fromUser: connectedNode!.user!, toUser: node!.user!) { + print("Enter DFU Failed") + } + } + } label: { + Label("Enter DFU Mode", systemImage: "square.and.arrow.down") + } + .buttonStyle(.bordered) + .buttonBorderShape(.capsule) + .controlSize(.regular) + .padding(5) + Spacer() /// RAK 4631 if currentDevice?.hwModel == 9 { - Text("You can update your Meshtastic device over bluetooth using the Nordic DFU app.") + Text("You can also update your Meshtastic device over bluetooth using the Nordic DFU app.") .fixedSize(horizontal: false, vertical: true) - .font(.callout) + .foregroundStyle(.gray) + .font(.caption) Link("Get NRF DFU from the App Store", destination: URL(string: "https://apps.apple.com/us/app/nrf-device-firmware-update/id1624454660")!) .font(.callout) .padding(.bottom) - Link("Drag & Drop Firmware Update", destination: URL(string: "https://meshtastic.org/docs/getting-started/flashing-firmware/nrf52/drag-n-drop")!) - .font(.callout) - - Button { - let connectedNode = getNodeInfo(id: bleManager.connectedPeripheral?.num ?? 0, context: context) - if connectedNode != nil { - if !bleManager.sendEnterDfuMode(fromUser: connectedNode!.user!, toUser: node!.user!) { - print("Enter DFU Failed") - } - } - } label: { - Label("Enter DFU Mode", systemImage: "square.and.arrow.down") - } - .buttonStyle(.bordered) - .buttonBorderShape(.capsule) - .controlSize(.regular) - .padding(5) - Spacer() } else { Text("OTA Updates are not supported on the this NRF Device.") .font(.title3) @@ -193,9 +208,9 @@ struct Firmware: View { } } } - //Api().loadFirmwareReleaseData { (bks) in - //sel = bks - //} + Api().loadFirmwareReleaseData { (fw) in + + } } .navigationTitle("Firmware Updates") .navigationBarTitleDisplayMode(.inline)