Fix some store and forwared admin config bugs

This commit is contained in:
Garth Vander Houwen 2024-01-14 21:00:54 -08:00
parent ca423e614e
commit 30dc0874bc
3 changed files with 73 additions and 31 deletions

View file

@ -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)..<UInt32.max)
meshPacket.priority = MeshPacket.Priority.reliable
meshPacket.channel = UInt32(adminIndex)
meshPacket.wantAck = true
var dataMessage = DataMessage()
dataMessage.payload = try! adminPacket.serializedData()
dataMessage.portnum = PortNum.adminApp
dataMessage.wantResponse = true
meshPacket.decoded = dataMessage
let messageDescription = "🛎️ Requested Store and Forward Module Config on admin channel \(adminIndex) for node: \(toUser.longName ?? "unknown".localized)"
if sendAdminMessageToRadio(meshPacket: meshPacket, adminDescription: messageDescription, fromUser: fromUser, toUser: toUser) {
return true
}
return false
}
public func requestTelemetryModuleConfig(fromUser: UserEntity, toUser: UserEntity, adminIndex: Int32) -> Bool {
var adminPacket = AdminMessage()

View file

@ -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)

View file

@ -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)