From 089e13db0817fb8a73d0ac0206a1904d94a5b882 Mon Sep 17 00:00:00 2001 From: Garth Vander Houwen Date: Thu, 21 Dec 2023 19:33:45 -0800 Subject: [PATCH] Add user role to node list --- Meshtastic/Helpers/LocationsHandler.swift | 6 +++-- Meshtastic/Helpers/MeshPackets.swift | 2 ++ .../Views/Nodes/Helpers/NodeListItem.swift | 9 +++++++- Meshtastic/Views/Nodes/TraceRouteLog.swift | 22 ++++++++----------- 4 files changed, 23 insertions(+), 16 deletions(-) diff --git a/Meshtastic/Helpers/LocationsHandler.swift b/Meshtastic/Helpers/LocationsHandler.swift index cd9707af..ebe05903 100644 --- a/Meshtastic/Helpers/LocationsHandler.swift +++ b/Meshtastic/Helpers/LocationsHandler.swift @@ -40,7 +40,6 @@ import CoreLocation self.manager = CLLocationManager() // Creating a location manager instance is safe to call here in `MainActor`. locationsArray = [CLLocation]() enableSmartPosition = true - self.manager.distanceFilter = 5 } func startLocationUpdates() { @@ -66,7 +65,7 @@ import CoreLocation locationAdded = true } if !locationAdded { - print("Bad Location \(self.count): \(loc)") + //print("Bad Location \(self.count): \(loc)") } } } @@ -85,12 +84,15 @@ import CoreLocation func addLocation(_ location: CLLocation) -> Bool { let age = -location.timestamp.timeIntervalSinceNow if age > 10 { + print("Bad Location \(self.count): Too Old \(location)") return false } if location.horizontalAccuracy < 0 { + print("Bad Location \(self.count): Horizontal Accuracy: \(location.horizontalAccuracy) \(location)") return false } if location.horizontalAccuracy > 100 { + print("Bad Location \(self.count): Horizontal Accuracy: \(location.horizontalAccuracy) \(location)") return false } locationsArray.append(location) diff --git a/Meshtastic/Helpers/MeshPackets.swift b/Meshtastic/Helpers/MeshPackets.swift index b8f48d7e..92139355 100644 --- a/Meshtastic/Helpers/MeshPackets.swift +++ b/Meshtastic/Helpers/MeshPackets.swift @@ -268,6 +268,7 @@ func nodeInfoPacket (nodeInfo: NodeInfo, channel: UInt32, context: NSManagedObje newUser.shortName = nodeInfo.user.shortName newUser.hwModel = String(describing: nodeInfo.user.hwModel).uppercased() newUser.isLicensed = nodeInfo.user.isLicensed + newUser.role = Int32(nodeInfo.user.role.rawValue) newNode.user = newUser } else { let newUser = UserEntity(context: context) @@ -337,6 +338,7 @@ func nodeInfoPacket (nodeInfo: NodeInfo, channel: UInt32, context: NSManagedObje fetchedNode[0].user!.longName = nodeInfo.user.longName fetchedNode[0].user!.shortName = nodeInfo.user.shortName fetchedNode[0].user!.isLicensed = nodeInfo.user.isLicensed + fetchedNode[0].user!.role = Int32(nodeInfo.user.role.rawValue) fetchedNode[0].user!.hwModel = String(describing: nodeInfo.user.hwModel).uppercased() } else { if (fetchedNode[0].user == nil) { diff --git a/Meshtastic/Views/Nodes/Helpers/NodeListItem.swift b/Meshtastic/Views/Nodes/Helpers/NodeListItem.swift index 2fb63b53..fec2e026 100644 --- a/Meshtastic/Views/Nodes/Helpers/NodeListItem.swift +++ b/Meshtastic/Views/Nodes/Helpers/NodeListItem.swift @@ -52,6 +52,14 @@ struct NodeListItem: View { LastHeardText(lastHeard: node.lastHeard) .font(.callout) } + HStack { + let role = DeviceRoles(rawValue: Int(node.user?.role ?? 0)) + Image(systemName: role?.systemName ?? "figure") + .font(.callout) + .symbolRenderingMode(.hierarchical) + Text("Role: \(role?.name ?? "unknown".localized)") + .font(.callout) + } if node.positions?.count ?? 0 > 0 && connectedNode != node.num { HStack { let lastPostion = node.positions!.reversed()[0] as! PositionEntity @@ -89,7 +97,6 @@ struct NodeListItem: View { .font(.callout) } } - if !connected { HStack { let preset = ModemPresets(rawValue: Int(modemPreset)) diff --git a/Meshtastic/Views/Nodes/TraceRouteLog.swift b/Meshtastic/Views/Nodes/TraceRouteLog.swift index a5e00a8b..dde3db46 100644 --- a/Meshtastic/Views/Nodes/TraceRouteLog.swift +++ b/Meshtastic/Views/Nodes/TraceRouteLog.swift @@ -46,9 +46,14 @@ struct TraceRouteLog: View { VStack { if selectedRoute != nil { if selectedRoute?.response ?? false && selectedRoute?.hops?.count ?? 0 > 0 { - Text("Received by \(selectedRoute?.node?.user?.longName ?? "unknown".localized)") - Text("Route: \(selectedRoute?.routeText ?? "unknown".localized)") - .font(.title3) + + Label { + Text("Route: \(selectedRoute?.routeText ?? "unknown".localized)") + } icon: { + Image(systemName: "signpost.right.and.left") + .symbolRenderingMode(.hierarchical) + } + .font(.title2) } else if selectedRoute?.response ?? false { Label { Text("Trace route received directly by \(selectedRoute?.node?.user?.longName ?? "unknown".localized)") @@ -56,7 +61,7 @@ struct TraceRouteLog: View { Image(systemName: "signpost.right.and.left") .symbolRenderingMode(.hierarchical) } - .font(.title3) + .font(.title2) } let hopsArray = selectedRoute?.hops?.array as? [TraceRouteHopEntity] ?? [] @@ -128,15 +133,6 @@ struct TraceRouteLog: View { .symbolRenderingMode(.hierarchical) } .font(.title3) - Divider() - Label { - Text("\(selectedRoute?.time?.formatted() ?? "") - No response") - - } icon: { - Image(systemName: "person.slash") - .symbolRenderingMode(.hierarchical) - } - .font(.callout) Spacer() } }