Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CoreScopeViewer/Features/FieldTools/FieldToolsScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,9 @@ struct FieldToolsScreen: View {
NodeVisionScreen(name: target.name, target: coordinate, repeaterKey: {
if case .node(let node) = target { return node.publicKey }
return nil
}(), role: {
if case .node(let node) = target { return node.role }
return nil
}())
}
}
Expand Down
2 changes: 1 addition & 1 deletion CoreScopeViewer/Features/NodeDetail/NodeDetailScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ struct NodeDetailScreen: View {
let item = FieldCatalogItem.node(displayedNode)
if let coordinate = item.coordinate {
NodeVisionScreen(name: item.name, target: coordinate,
repeaterKey: displayedNode.publicKey)
repeaterKey: displayedNode.publicKey, role: displayedNode.role)
}
}

Expand Down
363 changes: 285 additions & 78 deletions CoreScopeViewer/Features/NodeVision/NodeVisionScreen.swift

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions CoreScopeViewer/Models/FieldGeometry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,15 @@ enum FieldGeometry {
/// Project a height estimate only when combined vertical uncertainty is small enough to be useful.
static func cameraVerticalOffset(
distance: Double, antennaElevation: Double, phoneElevation: Double,
phoneAccuracy: Double, pitch: Double, halfHeightTangent: Double
phoneAccuracy: Double, pitch: Double, halfHeightTangent: Double, clampAngle: Bool = false
) -> Double? {
guard [distance, antennaElevation, phoneElevation, phoneAccuracy, pitch, halfHeightTangent].allSatisfy(\.isFinite),
distance > 0, phoneAccuracy > 0, halfHeightTangent > 0,
cameraElevationUncertainty(distance: distance, phoneAccuracy: phoneAccuracy) <= 30 else { return nil }
let curvature = distance * distance / (2 * earthRadiusMeters)
let angle = atan2(antennaElevation - phoneElevation - curvature, distance).degrees - pitch
guard abs(angle) < 89 else { return nil }
return tan(angle.radians) / halfHeightTangent
guard clampAngle || abs(angle) < 89 else { return nil }
return tan(min(max(angle, -89), 89).radians) / halfHeightTangent
}

/// Core Motion true-north coordinates are X north, Y west, Z up.
Expand Down
54 changes: 51 additions & 3 deletions CoreScopeViewer/Resources/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -13620,6 +13620,22 @@
}
}
},
"Higher-confidence elevation" : {
"localizations" : {
"es" : {
"stringUnit" : {
"state" : "translated",
"value" : "Elevación de mayor confianza"
}
},
"pt-BR" : {
"stringUnit" : {
"state" : "translated",
"value" : "Elevação mais confiável"
}
}
}
},
"Highlights in version %@" : {
"localizations" : {
"es" : {
Expand Down Expand Up @@ -21575,6 +21591,22 @@
}
}
},
"Phone altitude uncertain" : {
"localizations" : {
"es" : {
"stringUnit" : {
"state" : "translated",
"value" : "Altitud del teléfono incierta"
}
},
"pt-BR" : {
"stringUnit" : {
"state" : "translated",
"value" : "Altitude do celular incerta"
}
}
}
},
"Place a transmitter to find nearby known nodes." : {
"localizations" : {
"es" : {
Expand Down Expand Up @@ -33013,18 +33045,34 @@
}
}
},
"When enough elevation data is available, NodeVision uses it to place the focused marker vertically. “Elevation Uncertain” means its height on screen is a rough guide." : {
"When the phone’s altitude is accurate enough, NodeVision places markers by estimated antenna elevation. Without a reported height, it assumes a typical rooftop or handheld height. A dashed outline marks an approximate placement based on a default height or a less precise phone altitude." : {
"localizations" : {
"es" : {
"stringUnit" : {
"state" : "translated",
"value" : "Cuando la altitud del teléfono es lo bastante precisa, NodeVision coloca los marcadores según la elevación estimada de la antena. Si no se ha indicado la altura, usa una altura típica de azotea o de dispositivo de mano. Un contorno discontinuo indica una posición aproximada basada en una altura predeterminada o en una altitud del teléfono menos precisa."
}
},
"pt-BR" : {
"stringUnit" : {
"state" : "translated",
"value" : "Quando a altitude do celular é precisa o suficiente, o NodeVision posiciona os marcadores pela elevação estimada da antena. Sem uma altura informada, usa uma altura típica de telhado ou de dispositivo portátil. Um contorno tracejado indica uma posição aproximada baseada em uma altura padrão ou em uma altitude do celular menos precisa."
}
}
}
},
"When your phone’s altitude is missing or too uncertain, markers show which way to turn. Their height on screen doesn’t indicate whether a node is above or below you." : {
"localizations" : {
"es" : {
"stringUnit" : {
"state" : "translated",
"value" : "Cuando hay suficientes datos de elevación, NodeVision los usa para colocar el marcador destacado en el eje vertical. «Elevación incierta» significa que su altura en pantalla es orientativa."
"value" : "Cuando no se dispone de la altitud del teléfono o es demasiado imprecisa, los marcadores indican hacia dónde girar. Su altura en pantalla no indica si un nodo está por encima o por debajo de ti."
}
},
"pt-BR" : {
"stringUnit" : {
"state" : "translated",
"value" : "Quando há dados de elevação suficientes, o NodeVision os usa para posicionar o marcador destacado na vertical. “Elevação incerta” indica que a altura na tela é apenas uma referência."
"value" : "Quando a altitude do celular está indisponível ou é imprecisa demais, os marcadores mostram para onde virar. A altura deles na tela não indica se um nó está acima ou abaixo de você."
}
}
}
Expand Down
77 changes: 77 additions & 0 deletions CoreScopeViewerTests/FieldGeometryTests.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Foundation
import simd
import Testing
@testable import CoreScopeViewer
Expand Down Expand Up @@ -160,3 +161,79 @@ struct FieldGeometryTests {
#expect(FieldGeometry.deviceAxesUseMatrixRows(rows: turned, gravity: SIMD3(0, 0, -1)) == nil)
}
}


struct NodeVisionElevationTests {
@Test func discoveryMarkersLeaveTheEdgesWhenTiltedFartherAway() {
#expect(discoveryMarkerY(projectedY: -24, paneHeight: 800, minimumY: 166, maximumY: 700) == 166)
#expect(discoveryMarkerY(projectedY: 824, paneHeight: 800, minimumY: 166, maximumY: 700) == 700)
#expect(discoveryMarkerY(projectedY: -25, paneHeight: 800, minimumY: 166, maximumY: 700) == nil)
#expect(discoveryMarkerY(projectedY: 825, paneHeight: 800, minimumY: 166, maximumY: 700) == nil)
}

@Test func reportedAndDefaultHeights() {
#expect(VisionAntennaHeight(role: "repeater", reported: 12).meters == 12)
#expect(!VisionAntennaHeight(role: "repeater", reported: 12).approximate)
for role in ["repeater", "room", "room-server"] {
#expect(VisionAntennaHeight(role: role, reported: nil).meters == CoverageHeightPreset.rooftop.meters)
#expect(VisionAntennaHeight(role: role, reported: nil).approximate)
}
#expect(VisionAntennaHeight(role: "companion", reported: 12).meters == CoverageHeightPreset.handheld.meters)
}

@Test func placementModeAppliesToEveryMarker() {
let distances = [30.0, 500]
for mode in [
VisionElevationMode(altitude: nil, accuracy: 2, distances: distances, nearDistance: 5),
VisionElevationMode(altitude: 100, accuracy: 10, distances: distances, nearDistance: 5)
] {
#expect(mode == .guide)
#expect(mode.offset(distance: 30, antenna: nil, pitch: 2, tangent: 0.5) ==
mode.offset(distance: 500, antenna: 150, pitch: 2, tangent: 0.5))
}
let mode = VisionElevationMode(altitude: 100, accuracy: 2, distances: [500], nearDistance: 5)
#expect(mode == .elevation(altitude: 100, accuracy: 2))
#expect(mode.offset(distance: 500, antenna: nil, pitch: 2, tangent: 0.5) == nil)
#expect(mode.offset(distance: 500, antenna: 150, pitch: 2, tangent: 0.5) != nil)
}

@Test func altitudeDeadbandAccumulatesChanges() {
let stable = stableVisionAltitude(previous: 100, current: 100.2, distance: 100)
#expect(stable == 100)
#expect(stableVisionAltitude(previous: stable, current: 100.3, distance: 100) == 100.3)
#expect(stableVisionAltitude(previous: stable, current: nil, distance: 100) == nil)
}

@Test func terrainBatchesCacheByNodeAndCoordinateAndKeepSuccessfulBatches() async throws {
let provider = VisionTestTerrainProvider()
let cache = VisionTerrainCache(provider: provider)
let points = try Set((0..<101).map { index in
let coordinate = try #require(FieldCoordinate(latitude: Double(index) / 100, longitude: 0))
return try #require(VisionTerrainPoint(key: String(format: "%03d", index), coordinate: coordinate))
})
let first = await cache.resolve(points)
#expect(first.count == 100)
#expect(await provider.requests.map(\.count) == [100, 2])
let cachedPoints = Set(first.keys)
_ = await cache.resolve(points)
#expect(await provider.requests.count == 2)
let coordinate = try #require(FieldCoordinate(latitude: 2, longitude: 0))
let moved = try #require(VisionTerrainPoint(key: "000", coordinate: coordinate))
let updated = await cache.resolve(cachedPoints.union([moved]))
#expect(updated[moved] == 42)
#expect(await provider.requests.last == [moved.coordinate, moved.coordinate])
}
}

private actor VisionTestTerrainProvider: NodePlannerElevationProviding {
private(set) var requests: [[NodePlannerCoordinate]] = []

func elevations(for coordinates: [NodePlannerCoordinate]) async throws -> NodePlannerTerrainProfile {
requests.append(coordinates)
if requests.count == 2 { throw NodePlannerElevationError.unavailable }
return NodePlannerTerrainProfile(
samples: coordinates.map { NodePlannerTerrainSample(coordinate: $0, elevationMeters: 42) },
provenance: NodePlannerElevationProvenance(fetchedAt: .now, origin: .network)
)
}
}
7 changes: 7 additions & 0 deletions ROADMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,13 @@ Estimated Coverage shipped through 0.11.0. It includes:

## After 1.0

- Evaluate Core Motion absolute altitude in NodeVision on supported iPhones.
First, log `CMAbsoluteAltitudeData` altitude and uncertainty alongside Core
Location readings in DEBUG. Compare stationary jitter, the response to a
known stair climb, and time spent in direction-only mode. Verify the altitude
reference matches the terrain data before using the Core Motion reading for
placement. Keep Core Location and the existing direction-only fallback for
unavailable, stale, or uncertain readings.
- Expand packet details with raw hex, decoded fields, propagation timing, and a
clearer per-observer observation timeline.
- Add grouped and observation-level packet views where they improve diagnosis.
Expand Down
4 changes: 2 additions & 2 deletions android/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ val localProperties = Properties().apply {
}
val cartoKey = providers.environmentVariable("CARTO_API_KEY")
.orElse(localProperties.getProperty("CARTO_API_KEY", "")).get()
/** Optional Google Maps (beta) provider; without a key only CARTO is offered. */
/** Optional Google Maps provider; without a key only CARTO is offered. */
val googleMapsKey = providers.environmentVariable("GOOGLE_MAPS_API_KEY")
.orElse(localProperties.getProperty("GOOGLE_MAPS_API_KEY", "")).get()
/** Release signing comes only from the git-ignored local.properties; without it, release builds are unsigned. */
Expand Down Expand Up @@ -160,7 +160,7 @@ dependencies {
implementation("com.squareup.okhttp3:okhttp:4.12.0")
// OpenGL supports the full API 26+ device range, including non-Vulkan GPUs.
implementation("org.maplibre.gl:android-sdk-opengl:13.6.1")
// Google Maps (beta): the native SDK with ordinary markers and no map ID (the free Maps SDK SKU).
// Google Maps: the native SDK with ordinary markers and no map ID (the free Maps SDK SKU).
implementation("com.google.android.gms:play-services-maps:20.0.0")
implementation("com.google.maps.android:android-maps-utils:4.0.0")
// QR encoding for MeshCore contact codes (iOS uses Core Image's built-in generator).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class ConsistencyUiTest {
@Test fun pausedSettingsUsesAccurateStatusAndConsistentHeadings() {
compose.setContent { NodeScopeTheme(Appearance.DARK) {
Surface(Modifier.fillMaxSize().systemBarsPadding()) {
SettingsScreen(AppPreferences(), LiveConnection.PAUSED, null, null, {}, {}, {}, {}, {}, {})
SettingsScreen(AppPreferences(), LiveConnection.PAUSED, null, null, {}, {}, {}, {}, {}, {}, onMapLab = {})
}
} }
compose.onNodeWithText("Appearance").assertIsDisplayed()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ class FoundationUiTest {
var preferences by remember { mutableStateOf(AppPreferences()) }
NodeScopeTheme(preferences.appearance) {
SettingsScreen(preferences, LiveConnection.LIVE, null, null, { selected = it; preferences = preferences.copy(appearance = it) },
{}, {}, {}, {}, {})
{}, {}, {}, {}, {}, onMapLab = {})
}
}
compose.onNodeWithText("Dark").performClick().assertIsSelected()
Expand All @@ -234,7 +234,7 @@ class FoundationUiTest {
MeshNode("one", "North", "repeater", lastSeen = "2026-01-01T00:00:00Z"),
MeshNode("two", "South", "sensor", lastSeen = "2026-01-01T00:00:00Z"),
)
compose.setContent { NodeScopeTheme(Appearance.SYSTEM) { NodeBrowser(nodes, 2, { selected = it }) } }
compose.setContent { NodeScopeTheme(Appearance.SYSTEM) { NodeBrowser(nodes, 2, onNode = { selected = it }) } }
compose.onNodeWithText("Search name, public key, or role").performTextInput("SENSOR")
compose.onNodeWithText("North").assertDoesNotExist()
compose.onNodeWithText("South").performClick()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,18 +101,21 @@ class LinkProfileUiTest {

@Test fun settingsUnitIsUsedWhenOpeningPlanner() {
val preferences = mutableStateOf(org.nodescope.android.core.storage.AppPreferences(
onboarded = true, destination = "SETTINGS", distanceUnit = DistanceUnit.METRIC))
onboarded = true, destination = "SETTINGS", storedDistanceUnit = DistanceUnit.METRIC))
compose.setContent {
CompositionLocalProvider(LocalDensity provides Density(3f, 1f)) {
CompositionLocalProvider(
LocalDensity provides Density(3f, 1f),
LocalDistanceUnit provides preferences.value.distanceUnit,
) {
NodeScopeTheme(Appearance.LIGHT) {
org.nodescope.android.app.AppShell(preferences.value,
org.nodescope.android.core.network.SessionState(), {}, {}, {}, {}, {},
nodeLibrary = org.nodescope.android.core.storage.NodeLibrary(),
onDistanceUnit = { preferences.value = preferences.value.copy(distanceUnit = it) })
onDistanceUnit = { preferences.value = preferences.value.copy(storedDistanceUnit = it) })
}
}
}
compose.onNodeWithText("Imperial (mi)").performScrollTo().performClick()
compose.onNodeWithText("US (mi, ft)").performScrollTo().performClick()
compose.runOnIdle { assertEquals(DistanceUnit.IMPERIAL, preferences.value.distanceUnit) }
compose.onNodeWithText("Explore").performClick()
compose.onNodeWithText("Node Planner").performScrollTo().performClick()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import org.junit.Test
import org.nodescope.android.core.design.NodeScopeTheme
import org.nodescope.android.core.model.MeshNode
import org.nodescope.android.core.storage.Appearance
import org.nodescope.android.feature.map.MapNodeSelectionSheet
import org.nodescope.android.feature.map.MapNodePreview
import org.nodescope.android.feature.map.ReplayControls
import org.nodescope.android.feature.map.ReplayRoute
import java.io.File
Expand All @@ -28,7 +28,7 @@ class MapControlsUiTest {
var opened = false
var visible by mutableStateOf(true)
compose.setContent { NodeScopeTheme(Appearance.LIGHT) {
if (visible) MapNodeSelectionSheet(
if (visible) MapNodePreview(
MeshNode("test-node", "A long repeater name in the neighborhood", "repeater", lastSeen = "2026-09-26T12:00:00Z"),
onDetails = { opened = true; visible = false }, onDismiss = { visible = false })
} }
Expand Down
2 changes: 1 addition & 1 deletion android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:localeConfig="@xml/locales_config" android:name=".app.NodeScopeApplication" android:icon="@mipmap/ic_launcher" android:roundIcon="@mipmap/ic_launcher" android:dataExtractionRules="@xml/data_extraction_rules" android:label="@string/app_name" android:theme="@style/Theme.NodeScope" android:allowBackup="true" android:fullBackupContent="@xml/backup_rules" android:usesCleartextTraffic="false" android:supportsRtl="true">
<!-- Google Maps (beta); the key is restricted to this app's package and signing certificates. -->
<!-- Google Maps; the key is restricted to this app's package and signing certificates. -->
<meta-data android:name="com.google.android.geo.API_KEY" android:value="${googleMapsApiKey}" />
<!-- singleTop: a link opened while the app is running reaches onNewIntent instead of a second copy. -->
<activity android:name=".MainActivity" android:exported="true" android:launchMode="singleTop">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ sealed interface FieldQrCode {
}

private fun decode(value: String): String? = runCatching {
URLDecoder.decode(value, Charsets.UTF_8)
URLDecoder.decode(value, Charsets.UTF_8.name())
}.getOrNull()

private fun publicKey(value: String): String? = value.lowercase().takeIf { key ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,14 @@ object FieldGeometry {
/** Project a height estimate only when combined vertical uncertainty is small enough to be useful. */
fun cameraVerticalOffset(
distance: Double, antennaElevation: Double, phoneElevation: Double,
phoneAccuracy: Double, pitch: Double, halfHeightTangent: Double,
phoneAccuracy: Double, pitch: Double, halfHeightTangent: Double, clampAngle: Boolean = false,
): Double? {
if (!listOf(distance, antennaElevation, phoneElevation, phoneAccuracy, pitch, halfHeightTangent).all(Double::isFinite) ||
distance <= 0 || phoneAccuracy <= 0 || halfHeightTangent <= 0 ||
cameraElevationUncertainty(distance, phoneAccuracy) > 30) return null
val curvature = distance * distance / (2 * EARTH_RADIUS_METERS)
val angle = Math.toDegrees(atan2(antennaElevation - phoneElevation - curvature, distance)) - pitch
if (kotlin.math.abs(angle) >= 89) return null
return kotlin.math.tan(Math.toRadians(angle)) / halfHeightTangent
if (!clampAngle && kotlin.math.abs(angle) >= 89) return null
return kotlin.math.tan(Math.toRadians(angle.coerceIn(-89.0, 89.0))) / halfHeightTangent
}
}
Loading
Loading