Restrict shutdown and reboot to connected node, update position to show unknown age for nodes older than six months

This commit is contained in:
Garth Vander Houwen 2022-05-30 21:48:46 -07:00
parent 12da2fd628
commit bca583e530
6 changed files with 60 additions and 65 deletions

View file

@ -884,7 +884,7 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph
var meshPacket = MeshPacket()
meshPacket.to = UInt32(destNum)
meshPacket.from = 0 //UInt32(connectedPeripheral.num)
meshPacket.from = 0 // Send 0 as from from phone to device to avoid warning about client trying to set node num
meshPacket.wantAck = wantResponse
var dataMessage = DataMessage()
@ -933,41 +933,6 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph
}
}
// MARK: Device Settings
public func getSettings() -> Bool {
var adminPacket = AdminMessage()
var meshPacket: MeshPacket = MeshPacket()
meshPacket.to = UInt32(connectedPeripheral.num)
meshPacket.from = UInt32(connectedPeripheral.num)
meshPacket.id = UInt32.random(in: UInt32(UInt8.max)..<UInt32.max)
meshPacket.priority = MeshPacket.Priority.reliable
meshPacket.wantAck = true
meshPacket.hopLimit = 0
var dataMessage = DataMessage()
dataMessage.payload = try! adminPacket.serializedData()
dataMessage.portnum = PortNum.adminApp
meshPacket.decoded = dataMessage
var toRadio: ToRadio!
toRadio = ToRadio()
toRadio.packet = meshPacket
let binaryData: Data = try! toRadio.serializedData()
if connectedPeripheral!.peripheral.state == CBPeripheralState.connected {
connectedPeripheral.peripheral.writeValue(binaryData, for: TORADIO_characteristic, type: .withResponse)
return true
}
return false
}
public func sendShutdown(destNum: Int64, wantResponse: Bool) -> Bool {
var adminPacket = AdminMessage()
@ -1001,7 +966,6 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph
}
return false
}
public func sendReboot(destNum: Int64, wantResponse: Bool) -> Bool {
@ -1037,6 +1001,5 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph
}
return false
}
}

View file

@ -0,0 +1,30 @@
//
// DateTimeText.swift
// MeshtasticClient
//
// Created by Garth Vander Houwen on 5/30/22.
//
import SwiftUI
//
// LastHeardText.swift
// Meshtastic Apple
//
// Created by Garth Vander Houwen on 5/25/22.
//
struct DateTimeText: View {
var dateTime: Date?
let sixMonthsAgo = Calendar.current.date(byAdding: .month, value: -6, to: Date())
var body: some View {
if (dateTime != nil && dateTime! >= sixMonthsAgo!){
Text("\(dateTime!, style: .date) \(dateTime!, style: .time)")
} else {
Text("Unknown Age")
}
}
}

View file

@ -14,12 +14,12 @@ struct NodeAnnotation: View {
.cornerRadius(10)
Image(systemName: "mappin.circle.fill")
.font(.title)
.foregroundColor(.red)
.font(.largeTitle)
.foregroundColor(.accentColor)
Image(systemName: "arrowtriangle.down.fill")
.font(.caption)
.foregroundColor(.red)
.foregroundColor(.accentColor)
.offset(x: 0, y: -5)
}
}

View file

@ -85,7 +85,7 @@ struct NodeDetail: View {
ScrollView {
HStack {
if self.bleManager.connectedPeripheral != nil && self.bleManager.connectedPeripheral.num == node.num {
if self.bleManager.connectedPeripheral != nil && self.bleManager.connectedPeripheral.num == node.num && self.bleManager.connectedPeripheral.num == node.num {
Button(action: {
@ -315,7 +315,7 @@ struct NodeDetail: View {
.symbolRenderingMode(.hierarchical)
Text("Time:")
.font(.caption)
Text("\(mappin.time!, style: .date) \(mappin.time!, style: .time)")
DateTimeText(dateTime: mappin.time)
.foregroundColor(.gray)
.font(.caption)
Divider()