Skip to content

Commit

Permalink
Use snr from routing message for single hop results rather than node
Browse files Browse the repository at this point in the history
Clean up snr float handling in traceroute paths
  • Loading branch information
bjpetit committed Oct 23, 2024
1 parent 6ee3a4e commit dfa4b89
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
12 changes: 6 additions & 6 deletions Meshtastic/Helpers/BLEManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -835,8 +835,8 @@ class BLEManager: NSObject, CBPeripheralDelegate, MqttClientProxyManagerDelegate
let traceRoute = getTraceRoute(id: Int64(decodedInfo.packet.decoded.requestID), context: context)
traceRoute?.response = true
if routingMessage.route.count == 0 {
let snr = routingMessage.snrBack.count > 0 ? routingMessage.snrBack[0] / 4 : 0
traceRoute?.snr = Float(snr)
let snr = routingMessage.snrBack.count > 0 ? Float(routingMessage.snrBack[0]) / 4 : 0.0
traceRoute?.snr = snr
let logString = String.localizedStringWithFormat("mesh.log.traceroute.received.direct %@".localized, String(snr))
MeshLogger.log("🪧 \(logString)")
} else {
Expand All @@ -848,7 +848,7 @@ class BLEManager: NSObject, CBPeripheralDelegate, MqttClientProxyManagerDelegate
connectedHop.time = Date()
connectedHop.num = connectedPeripheral.num
connectedHop.name = connectedNode.user?.longName ?? "???"
connectedHop.snr = Float(routingMessage.snrBack.last ?? 0 / 4)
connectedHop.snr = Float(routingMessage.snrBack.last ?? 0) / 4
if let mostRecent = traceRoute?.node?.positions?.lastObject as? PositionEntity, mostRecent.time! >= Calendar.current.date(byAdding: .hour, value: -24, to: Date())! {
connectedHop.altitude = mostRecent.altitude
connectedHop.latitudeI = mostRecent.latitudeI
Expand All @@ -866,7 +866,7 @@ class BLEManager: NSObject, CBPeripheralDelegate, MqttClientProxyManagerDelegate
let traceRouteHop = TraceRouteHopEntity(context: context)
traceRouteHop.time = Date()
if routingMessage.snrTowards.count >= index + 1 {
traceRouteHop.snr = Float(routingMessage.snrTowards[index] / 4)
traceRouteHop.snr = Float(routingMessage.snrTowards[index]) / 4
}
if let hn = hopNode, hn.hasPositions {
if let mostRecent = hn.positions?.lastObject as? PositionEntity, mostRecent.time! >= Calendar.current.date(byAdding: .hour, value: -24, to: Date())! {
Expand All @@ -888,7 +888,7 @@ class BLEManager: NSObject, CBPeripheralDelegate, MqttClientProxyManagerDelegate
let destinationHop = TraceRouteHopEntity(context: context)
destinationHop.name = traceRoute?.node?.user?.longName ?? "unknown".localized
destinationHop.time = Date()
destinationHop.snr = Float(routingMessage.snrTowards.last ?? 0 / 4)
destinationHop.snr = Float(routingMessage.snrTowards.last ?? 0) / 4
destinationHop.num = traceRoute?.node?.num ?? 0
if let mostRecent = traceRoute?.node?.positions?.lastObject as? PositionEntity, mostRecent.time! >= Calendar.current.date(byAdding: .hour, value: -24, to: Date())! {
destinationHop.altitude = mostRecent.altitude
Expand All @@ -910,7 +910,7 @@ class BLEManager: NSObject, CBPeripheralDelegate, MqttClientProxyManagerDelegate
traceRouteHop.time = Date()
traceRouteHop.back = true
if routingMessage.snrBack.count >= index + 1 {
traceRouteHop.snr = Float(routingMessage.snrBack[index] / 4)
traceRouteHop.snr = Float(routingMessage.snrBack[index]) / 4
}
if let hn = hopNode, hn.hasPositions {
if let mostRecent = hn.positions?.lastObject as? PositionEntity, mostRecent.time! >= Calendar.current.date(byAdding: .hour, value: -24, to: Date())! {
Expand Down
7 changes: 3 additions & 4 deletions Meshtastic/Views/Nodes/TraceRouteLog.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,13 @@ struct TraceRouteLog: View {
}
.listStyle(.plain)
}
.frame(minHeight: CGFloat(node.traceRoutes?.count ?? 0 * 40), maxHeight: 250)
.frame(minHeight: CGFloat((node.traceRoutes?.count ?? 0) * 40), maxHeight: 250)
Divider()
ScrollView {
if selectedRoute != nil {

if selectedRoute?.response ?? false && selectedRoute?.hopsTowards ?? 0 == 0 {
Label {
Text("Trace route received directly by \(selectedRoute?.node?.user?.longName ?? "unknown".localized) with a SNR of \(String(format: "%.2f", selectedRoute?.node?.snr ?? 0.0)) dB")
Text("Trace route received directly by \(selectedRoute?.node?.user?.longName ?? "unknown".localized) with a SNR of \(String(format: "%.2f", selectedRoute?.snr ?? 0.0)) dB")
} icon: {
Image(systemName: "signpost.right.and.left")
.symbolRenderingMode(.hierarchical)
Expand Down Expand Up @@ -131,7 +130,7 @@ struct TraceRouteLog: View {
.symbolRenderingMode(.hierarchical)
}
}
if false {//selectedRoute?.hops?.count ?? 0 >= 3 {
if false {// selectedRoute?.hops?.count ?? 0 >= 3 {
HStack(alignment: .center) {
GeometryReader { geometry in
let size = ((geometry.size.width >= geometry.size.height ? geometry.size.height : geometry.size.width) / 2) - (idiom == .phone ? 45 : 85)
Expand Down

0 comments on commit dfa4b89

Please sign in to comment.