From 82d7f5555261c53b213e7e256d8b2c99485c3018 Mon Sep 17 00:00:00 2001 From: Garth Vander Houwen Date: Fri, 30 Dec 2022 22:30:15 -0800 Subject: [PATCH] Use iPhone 24 hour setting for date formatting Clean up several inconsistent admin message methods --- Meshtastic/Export/WriteCsvFile.swift | 6 +- Meshtastic/Helpers/BLEManager.swift | 97 +++++++------------ Meshtastic/Helpers/MeshPackets.swift | 14 +-- Meshtastic/Views/Nodes/DeviceMetricsLog.swift | 4 +- .../Views/Nodes/EnvironmentMetricsLog.swift | 4 +- Meshtastic/Views/Nodes/NodeDetail.swift | 48 +++------ Meshtastic/Views/Nodes/PositionLog.swift | 6 +- .../Views/Settings/Config/DeviceConfig.swift | 8 +- .../Config/Module/CannedMessagesConfig.swift | 2 +- de.lproj/Localizable.strings | 2 + en.lproj/Localizable.strings | 2 + 11 files changed, 66 insertions(+), 127 deletions(-) diff --git a/Meshtastic/Export/WriteCsvFile.swift b/Meshtastic/Export/WriteCsvFile.swift index b0de58cc..c7003bae 100644 --- a/Meshtastic/Export/WriteCsvFile.swift +++ b/Meshtastic/Export/WriteCsvFile.swift @@ -23,7 +23,7 @@ func TelemetryToCsvFile(telemetry: [TelemetryEntity], metricsType: Int) -> Strin csvString += ", " csvString += String(dm.airUtilTx) csvString += ", " - csvString += dm.time?.formattedDate(format: "yyyy-MM-dd HH:mm:ss") ?? NSLocalizedString("unknown.age", comment: "") + csvString += dm.time?.formattedDate(format: "yyyy-MM-dd j:mm:ss") ?? NSLocalizedString("unknown.age", comment: "") } } } else if metricsType == 1 { @@ -44,7 +44,7 @@ func TelemetryToCsvFile(telemetry: [TelemetryEntity], metricsType: Int) -> Strin csvString += ", " csvString += String(dm.current) csvString += ", " - csvString += dm.time?.formattedDate(format: "yyyy-MM-dd HH:mm:ss") ?? NSLocalizedString("unknown.age", comment: "") + csvString += dm.time?.formattedDate(format: "yyyy-MM-dd j:mm:ss") ?? NSLocalizedString("unknown.age", comment: "") } } } @@ -73,7 +73,7 @@ func PositionToCsvFile(positions: [PositionEntity]) -> String { csvString += ", " csvString += String(pos.snr) csvString += ", " - csvString += pos.time?.formattedDate(format: "yyyy-MM-dd HH:mm:ss") ?? NSLocalizedString("unknown.age", comment: "") + csvString += pos.time?.formattedDate(format: "yyyy-MM-dd j:mm:ss") ?? NSLocalizedString("unknown.age", comment: "") } return csvString } diff --git a/Meshtastic/Helpers/BLEManager.swift b/Meshtastic/Helpers/BLEManager.swift index 99f3e0b6..cbe4fbd5 100644 --- a/Meshtastic/Helpers/BLEManager.swift +++ b/Meshtastic/Helpers/BLEManager.swift @@ -831,14 +831,14 @@ class BLEManager: NSObject, CBPeripheralDelegate, ObservableObject { return false } - public func sendReboot(destNum: Int64) -> Bool { + public func sendReboot(fromUser: UserEntity, toUser: UserEntity) -> Bool { var adminPacket = AdminMessage() adminPacket.rebootSeconds = 10 var meshPacket: MeshPacket = MeshPacket() meshPacket.to = UInt32(connectedPeripheral.num) - meshPacket.from = 0 //UInt32(connectedPeripheral.num) + meshPacket.from = UInt32(fromUser.num) meshPacket.id = UInt32.random(in: UInt32(UInt8.max).. Bool { - - var adminPacket = AdminMessage() - adminPacket.factoryReset = 1 - - var meshPacket: MeshPacket = MeshPacket() - meshPacket.to = UInt32(destNum) - meshPacket.from = 0 //UInt32(connectedPeripheral.num) - meshPacket.id = UInt32.random(in: UInt32(UInt8.max).. Bool { + public func sendFactoryReset(fromUser: UserEntity, toUser: UserEntity) -> Bool { + + var adminPacket = AdminMessage() + adminPacket.factoryReset = 1 + + 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() adminPacket.nodedbReset = 1 var meshPacket: MeshPacket = MeshPacket() - meshPacket.to = UInt32(destNum) - meshPacket.from = 0 //UInt32(connectedPeripheral.num) + meshPacket.to = UInt32(toUser.num) + meshPacket.from = UInt32(fromUser.num) meshPacket.id = UInt32.random(in: UInt32(UInt8.max).. NodeInfoEntity? { - if nodeInfo.hasUser { - MeshLogger.log("📟 Node info received for: \(nodeInfo.user.longName)") - } else { - MeshLogger.log("📟 Node info received for: \(nodeInfo.num)") - } + MeshLogger.log("📟 Node info received for: \(nodeInfo.num)") let fetchNodeInfoRequest: NSFetchRequest = NSFetchRequest.init(entityName: "NodeInfoEntity") fetchNodeInfoRequest.predicate = NSPredicate(format: "num == %lld", Int64(nodeInfo.num)) @@ -897,12 +893,8 @@ func nodeInfoPacket (nodeInfo: NodeInfo, channel: UInt32, context: NSManagedObje } do { try context.save() - - if nodeInfo.hasUser { - MeshLogger.log("📟 Node info received for: \(nodeInfo.user.longName)") - } else { - MeshLogger.log("📟 Node info received for: \(nodeInfo.num)") - } + print("💾 NodeInfo saved for \(nodeInfo.num)") + return fetchedNode[0] } catch { context.rollback() diff --git a/Meshtastic/Views/Nodes/DeviceMetricsLog.swift b/Meshtastic/Views/Nodes/DeviceMetricsLog.swift index 903d94b3..59b9dcc6 100644 --- a/Meshtastic/Views/Nodes/DeviceMetricsLog.swift +++ b/Meshtastic/Views/Nodes/DeviceMetricsLog.swift @@ -68,7 +68,7 @@ struct DeviceMetricsLog: View { } TableColumn("Time Stamp") { dm in if dm.metricsType == 0 { - Text(dm.time?.formattedDate(format: "MM/dd/yy hh:mm") ?? "Unknown time") + Text(dm.time?.formattedDate(format: "MM/dd/yy j:mm") ?? "Unknown time") } } } @@ -117,7 +117,7 @@ struct DeviceMetricsLog: View { .font(.caption) Text("\(String(format: "%.2f", dm.airUtilTx))%") .font(.caption) - Text(dm.time?.formattedDate(format: "MM/dd/yy hh:mm") ?? "Unknown time") + Text(dm.time?.formattedDate(format: "MM/dd/yy j:mm") ?? "Unknown time") .font(.caption) } } diff --git a/Meshtastic/Views/Nodes/EnvironmentMetricsLog.swift b/Meshtastic/Views/Nodes/EnvironmentMetricsLog.swift index 18f72249..1f4a3b24 100644 --- a/Meshtastic/Views/Nodes/EnvironmentMetricsLog.swift +++ b/Meshtastic/Views/Nodes/EnvironmentMetricsLog.swift @@ -57,7 +57,7 @@ struct EnvironmentMetricsLog: View { } TableColumn("Time Stamp") { em in if em.metricsType == 1 { - Text(em.time?.formattedDate(format: "MM/dd/yy hh:mm") ?? "Unknown time") + Text(em.time?.formattedDate(format: "MM/dd/yy j:mm") ?? "Unknown time") } } } @@ -104,7 +104,7 @@ struct EnvironmentMetricsLog: View { .font(.caption) Text("\(String(format: "%.2f", em.gasResistance))") .font(.caption) - Text(em.time?.formattedDate(format: "MM/dd/yy hh:mm") ?? "Unknown time") + Text(em.time?.formattedDate(format: "MM/dd/yy j:mm") ?? "Unknown time") .font(.caption) } } diff --git a/Meshtastic/Views/Nodes/NodeDetail.swift b/Meshtastic/Views/Nodes/NodeDetail.swift index 20bf8532..e41cae3e 100644 --- a/Meshtastic/Views/Nodes/NodeDetail.swift +++ b/Meshtastic/Views/Nodes/NodeDetail.swift @@ -192,28 +192,21 @@ struct NodeDetail: View { HStack { VStack(alignment: .center) { - CircleText(text: node.user?.shortName ?? "???", color: .accentColor) } - Divider() - VStack { - if node.user != nil { - Image(node.user!.hwModel ?? "UNSET") .resizable() .frame(width: 75, height: 75) .cornerRadius(5) - Text(String(node.user!.hwModel ?? "UNSET")) .font(.callout).fixedSize() } } .padding(5) - if node.snr > 0 { Divider() VStack(alignment: .center) { @@ -375,26 +368,23 @@ struct NodeDetail: View { }) { - Label("Reboot", systemImage: "arrow.triangle.2.circlepath") + Label("reboot", systemImage: "arrow.triangle.2.circlepath") } .buttonStyle(.bordered) .buttonBorderShape(.capsule) .controlSize(.large) .padding() - .confirmationDialog( - - "are.you.sure", - isPresented: $showingRebootConfirm - ) { - - Button("Reboot Node?", role: .destructive) { - - if !bleManager.sendReboot(destNum: node.num) { - - print("Reboot Failed") + .confirmationDialog("are.you.sure", + + isPresented: $showingRebootConfirm + ) { + Button("reboot.node", role: .destructive) { + + if !bleManager.sendReboot(fromUser: node.user!, toUser: node.user!) { + print("Reboot Failed") + } + } } - } - } } .padding(5) } @@ -402,12 +392,10 @@ struct NodeDetail: View { .offset( y:-40) } .edgesIgnoringSafeArea([.leading, .trailing]) - .navigationBarTitle(String(node.user?.longName ?? NSLocalizedString("unknown", comment: "Unknown")), displayMode: .inline) + .navigationBarTitle(String(node.user?.longName ?? NSLocalizedString("unknown", comment: "")), displayMode: .inline) .padding(.bottom, 10) .navigationBarItems(trailing: - ZStack { - ConnectedDevice( bluetoothOn: bleManager.isSwitchedOn, deviceConnected: bleManager.connectedPeripheral != nil, @@ -421,15 +409,3 @@ struct NodeDetail: View { } } } - -struct NodeInfoEntityDetail_Previews: PreviewProvider { - - static let bleManager = BLEManager() - - static var previews: some View { - Group { - - // NodeDetail(node: node) - } - } -} diff --git a/Meshtastic/Views/Nodes/PositionLog.swift b/Meshtastic/Views/Nodes/PositionLog.swift index 4554c7b9..8fe6e582 100644 --- a/Meshtastic/Views/Nodes/PositionLog.swift +++ b/Meshtastic/Views/Nodes/PositionLog.swift @@ -50,7 +50,7 @@ struct PositionLog: View { Text("\(String(format: "%.2f", position.snr)) dB") } TableColumn("Time Stamp") { position in - Text(position.time?.formattedDate(format: "MM/dd/yy hh:mm") ?? "Unknown time") + Text(position.time?.formattedDate(format: "MM/dd/yy j:mm") ?? "Unknown time") } } @@ -95,7 +95,7 @@ struct PositionLog: View { .font(.caption2) Text(String(mappin.altitude)) .font(.caption2) - Text(mappin.time?.formattedDate(format: "MM/dd/yy hh:mm") ?? "Unknown time") + Text(mappin.time?.formattedDate(format: "MM/dd/yy j:mm") ?? "Unknown time") .font(.caption2) } } @@ -125,9 +125,7 @@ struct PositionLog: View { titleVisibility: .visible ) { Button("Delete all positions?", role: .destructive) { - if clearPositions(destNum: node.num, context: context) { - print("Successfully Cleared Position Log") } else { diff --git a/Meshtastic/Views/Settings/Config/DeviceConfig.swift b/Meshtastic/Views/Settings/Config/DeviceConfig.swift index 34ae0231..0fb1e14c 100644 --- a/Meshtastic/Views/Settings/Config/DeviceConfig.swift +++ b/Meshtastic/Views/Settings/Config/DeviceConfig.swift @@ -90,7 +90,7 @@ struct DeviceConfig: View { Button("Reset NodeDB", role: .destructive) { isPresentingNodeDBResetConfirm = true } - .disabled(bleManager.connectedPeripheral == nil) + .disabled(node?.user == nil) .buttonStyle(.bordered) .buttonBorderShape(.capsule) .controlSize(.large) @@ -101,7 +101,7 @@ struct DeviceConfig: View { titleVisibility: .visible ) { Button("Erase all device and app data?", role: .destructive) { - if bleManager.sendNodeDBReset(destNum: bleManager.connectedPeripheral.num) { + if bleManager.sendNodeDBReset(fromUser: node!.user!, toUser: node!.user!) { bleManager.disconnectPeripheral() clearCoreDataDatabase(context: context) } else { @@ -112,7 +112,7 @@ struct DeviceConfig: View { Button("Factory Reset", role: .destructive) { isPresentingFactoryResetConfirm = true } - .disabled(bleManager.connectedPeripheral == nil) + .disabled(node?.user == nil) .buttonStyle(.bordered) .buttonBorderShape(.capsule) .controlSize(.large) @@ -124,7 +124,7 @@ struct DeviceConfig: View { ) { Button("Factory reset your device and app? ", role: .destructive) { - if bleManager.sendFactoryReset(destNum: bleManager.connectedPeripheral.num) { + if bleManager.sendFactoryReset(fromUser: node!.user!, toUser: node!.user!) { bleManager.disconnectPeripheral() clearCoreDataDatabase(context: context) } else { diff --git a/Meshtastic/Views/Settings/Config/Module/CannedMessagesConfig.swift b/Meshtastic/Views/Settings/Config/Module/CannedMessagesConfig.swift index 5996f3ff..01d51a62 100644 --- a/Meshtastic/Views/Settings/Config/Module/CannedMessagesConfig.swift +++ b/Meshtastic/Views/Settings/Config/Module/CannedMessagesConfig.swift @@ -256,7 +256,7 @@ struct CannedMessagesConfig: View { // for now just disable the button after a successful save hasMessagesChanges = false if !hasChanges { - bleManager.sendReboot(destNum: node!.num) + bleManager.sendReboot(fromUser: node!.user!, toUser: node!.user!) goBack() } } diff --git a/de.lproj/Localizable.strings b/de.lproj/Localizable.strings index cfd71cce..ddd6abbf 100644 --- a/de.lproj/Localizable.strings +++ b/de.lproj/Localizable.strings @@ -150,6 +150,8 @@ "radio.configuration"="Geräteeinstellungen"; "range.test"="Entfernungstest"; "range.test.config"="Entfernungstest Konfiguration"; +"reboot"="Reboot"; +"reboot.node"="Reboot node?"; "reply"="Antworten"; "received.ack"="Empfangsbestätigung"; "received.ack.real"="Recipient Ack"; diff --git a/en.lproj/Localizable.strings b/en.lproj/Localizable.strings index a9b6a05a..fa2ca147 100644 --- a/en.lproj/Localizable.strings +++ b/en.lproj/Localizable.strings @@ -151,6 +151,8 @@ "range.test"="Range Test"; "range.test.config"="Range Test Config"; "reply"="Reply"; +"reboot"="Reboot"; +"reboot.node"="Reboot node?"; "received.ack"="Received Ack"; "received.ack.real"="Recipient Ack"; "routing.acknowledged"="Acknowledged";