Shutdown and Reboot buttons for nodes

This commit is contained in:
Garth Vander Houwen 2022-05-29 22:02:25 -07:00
parent 4847731402
commit 12da2fd628
4 changed files with 103 additions and 7 deletions

View file

@ -755,7 +755,7 @@
CODE_SIGN_ENTITLEMENTS = MeshtasticClient/MeshtasticClient.entitlements;
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 9;
CURRENT_PROJECT_VERSION = 10;
DEVELOPMENT_ASSET_PATHS = "\"MeshtasticClient/Preview Content\"";
DEVELOPMENT_TEAM = GCH7VS5Y9R;
ENABLE_PREVIEWS = YES;
@ -787,7 +787,7 @@
CODE_SIGN_ENTITLEMENTS = MeshtasticClient/MeshtasticClient.entitlements;
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 9;
CURRENT_PROJECT_VERSION = 10;
DEVELOPMENT_ASSET_PATHS = "\"MeshtasticClient/Preview Content\"";
DEVELOPMENT_TEAM = GCH7VS5Y9R;
ENABLE_PREVIEWS = YES;

View file

@ -968,15 +968,50 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph
return false
}
// Send Position
public func sendShutdown(destNum: Int64, wantResponse: Bool) -> Bool {
var adminPacket = AdminMessage()
adminPacket.rebootSeconds = 30
adminPacket.shutdownSeconds = 10
var meshPacket: MeshPacket = MeshPacket()
meshPacket.to = UInt32(connectedPeripheral.num)
meshPacket.from = UInt32(connectedPeripheral.num)
meshPacket.from = 0 //UInt32(connectedPeripheral.num)
meshPacket.id = UInt32.random(in: UInt32(UInt8.max)..<UInt32.max)
meshPacket.priority = MeshPacket.Priority.reliable
meshPacket.wantAck = false
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 sendReboot(destNum: Int64, wantResponse: Bool) -> Bool {
var adminPacket = AdminMessage()
adminPacket.rebootSeconds = 10
var meshPacket: MeshPacket = MeshPacket()
meshPacket.to = UInt32(connectedPeripheral.num)
meshPacket.from = 0 //UInt32(connectedPeripheral.num)
meshPacket.id = UInt32.random(in: UInt32(UInt8.max)..<UInt32.max)
meshPacket.priority = MeshPacket.Priority.reliable
meshPacket.wantAck = false

View file

@ -24,7 +24,7 @@ struct Connect: View {
var body: some View {
let firmwareVersion = bleManager.lastConnnectionVersion
let minimumVersion = "1.3.0"
let minimumVersion = "1.3.12"
let supportedVersion = firmwareVersion == "0.0.0" || minimumVersion.compare(firmwareVersion, options: .numeric) == .orderedAscending || minimumVersion.compare(firmwareVersion, options: .numeric) == .orderedSame
NavigationView {

View file

@ -12,6 +12,9 @@ struct NodeDetail: View {
@Environment(\.managedObjectContext) var context
@EnvironmentObject var bleManager: BLEManager
@EnvironmentObject var userSettings: UserSettings
@State private var isPresentingShutdownConfirm: Bool = false
@State private var isPresentingRebootConfirm: Bool = false
var node: NodeInfoEntity
@ -80,8 +83,66 @@ struct NodeDetail: View {
}
ScrollView {
HStack {
if self.bleManager.connectedPeripheral != nil && self.bleManager.connectedPeripheral.num == node.num {
Button(action: {
isPresentingShutdownConfirm = true
}) {
Image(systemName: "power")
.symbolRenderingMode(.hierarchical)
.imageScale(.small)
.foregroundColor(Color.accentColor)
Text("Power Off")
.font(.caption)
}
.padding()
.background(Color(.systemGray6))
.clipShape(Capsule())
.confirmationDialog(
"Are you sure?",
isPresented: $isPresentingShutdownConfirm
) {
Button("Shutdown Node?", role: .destructive) {
let success = bleManager.sendShutdown(destNum: node.num, wantResponse: false)
}
}
Button(action: {
isPresentingRebootConfirm = true
}) {
Image(systemName: "arrow.triangle.2.circlepath")
.symbolRenderingMode(.hierarchical)
.imageScale(.small)
.foregroundColor(Color.accentColor)
Text("Reboot")
.font(.caption)
}
.padding()
.background(Color(.systemGray6))
.clipShape(Capsule())
.confirmationDialog(
"Are you sure?",
isPresented: $isPresentingRebootConfirm
) {
Button("Reboot Node?", role: .destructive) {
let success = bleManager.sendReboot(destNum: node.num, wantResponse: false)
}
}
}
}
.padding(5)
Divider()
HStack {
Image(systemName: "clock.badge.checkmark.fill")