Skip to content

feat: Accurately display outgoing diagnostic packets#4569

Merged
jamesarich merged 7 commits into
mainfrom
fix/positions
Feb 16, 2026
Merged

feat: Accurately display outgoing diagnostic packets#4569
jamesarich merged 7 commits into
mainfrom
fix/positions

Conversation

@jamesarich

@jamesarich jamesarich commented Feb 16, 2026

Copy link
Copy Markdown
Collaborator

resolves #4568
resolves #4567 (hopefully)

This pull request introduces a consistent approach for handling local node numbers in logs and queries, ensuring that logs from the local node are always mapped to a stable identifier (MeshLog.NODE_NUM_LOCAL). This change improves data continuity across hardware swaps and simplifies log retrieval and management. The update also adds comprehensive documentation and new tests to verify correct log behavior for local and remote nodes.

Local Node Number Mapping and Logging

  • Updated MeshMessageProcessor and PacketHandler to log packets from the local node using MeshLog.NODE_NUM_LOCAL, ensuring consistency and stability in log records. [1] [2]
  • Added new tests in MeshMessageProcessorTest.kt and PacketHandlerTest.kt to verify that logs from the local node use NODE_NUM_LOCAL and logs from remote nodes use their actual node numbers. [1] [2]

Repository and Query Improvements

  • Refactored MeshLogRepository to centralize the mapping of local node numbers to NODE_NUM_LOCAL in all relevant queries, including telemetry and general log retrieval, as well as log deletion. Introduced the effectiveLogId helper and improved documentation throughout. [1] [2] [3]
  • Added the PORT_ANY constant for generalized port queries and improved method documentation to clarify log retrieval and deletion behaviors.

Node Repository Enhancements

  • Added effectiveLogNodeId helper to NodeRepository for consistent log queries, and improved documentation for repository methods and properties. [1] [2] [3] [4] [5] [6]

@github-actions github-actions Bot added the bugfix PR tag label Feb 16, 2026
@codecov

codecov Bot commented Feb 16, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 10.83744% with 181 lines in your changes missing coverage. Please review.
✅ Project coverage is 14.80%. Comparing base (6a24431) to head (e09a0d0).
⚠️ Report is 1 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...htastic/feature/node/detail/NodeDetailViewModel.kt 0.00% 94 Missing ⚠️
...eshtastic/feature/node/metrics/MetricsViewModel.kt 0.00% 49 Missing ⚠️
...shtastic/core/data/repository/MeshLogRepository.kt 31.57% 20 Missing and 6 partials ⚠️
...rg/meshtastic/feature/map/node/NodeMapViewModel.kt 0.00% 7 Missing ⚠️
...otlin/org/meshtastic/core/model/util/Extensions.kt 33.33% 0 Missing and 2 partials ⚠️
...om/geeksville/mesh/service/MeshMessageProcessor.kt 0.00% 0 Missing and 1 partial ⚠️
.../meshtastic/core/data/repository/NodeRepository.kt 66.66% 0 Missing and 1 partial ⚠️
...shtastic/feature/node/component/PositionSection.kt 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4569      +/-   ##
==========================================
+ Coverage   14.39%   14.80%   +0.40%     
==========================================
  Files         427      427              
  Lines       14818    14841      +23     
  Branches     2452     2455       +3     
==========================================
+ Hits         2133     2197      +64     
+ Misses      12380    12326      -54     
- Partials      305      318      +13     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

…logging

This commit introduces several refinements to standardize how local node interactions are logged and how data requests are queried, improving code clarity and maintainability.

-   **Standardized Local Node Logging**:
    -   Introduced `MeshLog.NODE_NUM_LOCAL` (set to 0) to consistently represent the local node in the database.
    -   Updated `MeshMessageProcessor` and `PacketHandler` to log all outgoing packets and packets originating from the local device with `NODE_NUM_LOCAL` as the `fromNum`.

-   **Refactored Request Logging**:
    -   Added a new `MeshLogRepository.getRequestLogs` function to simplify querying for request packets (e.g., Traceroute, Neighbor Info) sent from the local node to a specific destination.
    -   Removed redundant filtering logic from `MetricsViewModel` and `NodeDetailViewModel`, which now use the new repository method.

-   **Centralized Fallback Node Creation**:
    -   Moved the logic for creating temporary "fallback" nodes (for nodes not yet in the database) into a static `Node.createFallback` function.
    -   This removes duplicate code from the ViewModels and ensures consistent fallback node generation.

-   **Added Unit Tests**:
    -   New tests were added to verify the behavior of `Node.createFallback`, `MeshLogRepository.getRequestLogs`, and the correct logging of local vs. remote packets.

Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
This commit refactors how data for the local node is queried from the `MeshLogRepository`. Previously, the device's own `nodeNum` was used to fetch logs, which could be incorrect or unavailable on startup.

Now, when fetching logs (Telemetry, MeshPackets, Position, etc.) for the user's own device, `MeshLog.NODE_NUM_LOCAL` is used as the node identifier. This ensures that queries for the local node are correctly directed, regardless of whether its `nodeNum` has been established.

This change is applied across multiple ViewModels to standardize local data fetching:
- `MetricsViewModel`
- `NodeDetailViewModel`
- `NodeMapViewModel`

Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
This commit centralizes common logic into the `core` module and refactors the `NodeDetailViewModel` and `MetricsViewModel` for clarity and efficiency.

Helper functions for validating metrics and signals have been moved to `core/model/util/Extensions.kt` for reuse. The logic for determining the effective node ID for log queries (mapping the local node number to 0) has been extracted into `NodeRepository`.

The `NodeDetailViewModel` is significantly refactored to simplify its complex data flow. The previous large `combine` operation with many arguments has been broken down into smaller, more manageable data groups for logs, identity, and metadata. This improves readability and maintainability.

Specific changes include:
- **`core/model`**:
    - Moved `hasValidEnvironmentMetrics` and a refined `isDirectSignal` (previously `hasValidSignal`) to `Extensions.kt`.
- **`core/data`**:
    - Added `effectiveLogNodeId` to `NodeRepository` to abstract the logic for determining which node ID to use for log lookups.
- **`feature/node`**:
    - **`MetricsViewModel`**: Updated to use the new centralized helper functions and the `effectiveLogNodeId` method from `NodeRepository`.
    - **`NodeDetailViewModel`**:
        - Refactored the `uiState` flow to use smaller, grouped `combine` calls for better organization.
        - Introduced internal data classes (`LogsGroup`, `IdentityGroup`, `MetadataGroup`) to structure the data fetching process.
        - Removed the large, monolithic `NodeDetailUiStateData` data class.
        - Adopted the new centralized helper and repository methods.

Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
This commit refactors the `PositionSection` to conditionally display action buttons based on whether the node is local and has a valid position.

- The "Exchange Position" button is now only shown for remote nodes.
- For local nodes, the "Compass" button will now span the full width of the screen, but only if the node has a valid position.
- If the node is local and has no valid position, no action buttons are displayed.

Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
This commit refactors data-fetching logic to centralize the mapping of the local node's number to a stable identifier (`MeshLog.NODE_NUM_LOCAL`), ensuring log continuity even if the local node ID changes.

The `MeshLogRepository` now transparently handles this redirection for all queries (`getTelemetryFrom`, `getLogsFrom`, `getMeshPacketsFrom`), removing this responsibility from the ViewModels. This simplifies the presentation layer by eliminating the need to resolve the `effectiveLogNodeId` before making a data request.

**Specific Changes:**
- **`MeshLogRepository`**:
    - Introduced a private `effectiveLogId` flow that maps the current node number to `MeshLog.NODE_NUM_LOCAL` if it's the local node.
    - All public data-fetching methods for a specific `nodeNum` now use this `effectiveLogId` flow internally.
    - Added documentation for public methods.
- **`NodeRepository`**:
    - Removed `effectiveLogNodeId` as its logic is now encapsulated within `MeshLogRepository`.
- **`MetricsViewModel` & `NodeDetailViewModel`**:
    - Removed all usage of `flatMapLatest` with `effectiveLogNodeId`.
    - Data flows are now fetched directly using the target `nodeNum`, relying on the repository to handle local node mapping.
- **`MeshLogDao`**:
    - Updated the query for `getLogsFrom` to use `-1` as a wildcard for `portNum`, improving clarity over the previous use of `0`.
- **Documentation**:
    - Added KDoc to `MeshLog`, `Node`, `MetricsViewModel`, `NodeDetailViewModel`, `NodeRepository`, and `MeshLogRepository` for better code clarity.

Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR standardizes how the app logs and queries “local node” traffic by mapping it to a stable log identifier (MeshLog.NODE_NUM_LOCAL), improving continuity across radio/hardware swaps and fixing missing/mis-attributed diagnostic logs (e.g., traceroute).

Changes:

  • Log outgoing and locally-originated packets using MeshLog.NODE_NUM_LOCAL rather than the transient hardware node number.
  • Centralize local-node ID remapping in MeshLogRepository (and add getRequestLogs) so UI queries consistently retrieve local request/response history.
  • Add utility extensions (isDirectSignal, hasValidEnvironmentMetrics), fallback node creation helper, and new unit tests validating the new log behavior.

Reviewed changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
feature/node/src/main/kotlin/org/meshtastic/feature/node/metrics/MetricsViewModel.kt Switches traceroute/neighbor request sourcing to repository helper and reuses shared metric validation extensions.
feature/node/src/main/kotlin/org/meshtastic/feature/node/detail/NodeDetailViewModel.kt Refactors UI-state assembly and uses new request-log query + shared extensions for signal/environment metrics.
feature/node/src/main/kotlin/org/meshtastic/feature/node/component/PositionSection.kt Adjusts action button visibility/behavior for local vs remote nodes.
feature/map/src/main/kotlin/org/meshtastic/feature/map/node/NodeMapViewModel.kt Attempts to remap local node position log queries to NODE_NUM_LOCAL for continuity.
core/model/src/main/kotlin/org/meshtastic/core/model/util/Extensions.kt Adds reusable MeshPacket/Telemetry extensions for filtering signal/environment metrics.
core/model/src/test/kotlin/org/meshtastic/core/model/util/ExtensionsTest.kt Adds unit tests for the new extensions.
core/database/src/main/kotlin/org/meshtastic/core/database/model/Node.kt Introduces Node.createFallback(...) helper for unknown/hidden nodes.
core/database/src/test/kotlin/org/meshtastic/core/database/model/NodeTest.kt Tests fallback-node generation behavior.
core/database/src/main/kotlin/org/meshtastic/core/database/entity/MeshLog.kt Documents log entity and defines NODE_NUM_LOCAL constant.
core/database/src/main/kotlin/org/meshtastic/core/database/dao/MeshLogDao.kt Updates port filtering semantics to support a true “any port” sentinel.
core/data/src/main/kotlin/org/meshtastic/core/data/repository/MeshLogRepository.kt Centralizes local-node remapping, adds request-log helper, and updates deletion/query behavior.
core/data/src/test/kotlin/org/meshtastic/core/data/repository/MeshLogRepositoryTest.kt Extends repository tests to cover request-log filtering and updated construction.
core/data/src/main/kotlin/org/meshtastic/core/data/repository/NodeRepository.kt Adds effectiveLogNodeId(...) flow helper for consistent local-log querying.
core/data/src/test/kotlin/org/meshtastic/core/data/repository/NodeRepositoryTest.kt Tests local-node ID remapping behavior under node-number changes.
app/src/main/java/com/geeksville/mesh/service/PacketHandler.kt Logs outgoing packets with NODE_NUM_LOCAL.
app/src/main/java/com/geeksville/mesh/service/MeshMessageProcessor.kt Logs packets from the local node using NODE_NUM_LOCAL and remote packets with their real node number.
app/src/test/java/com/geeksville/mesh/service/PacketHandlerTest.kt Adds test verifying outgoing packets are logged as local (NODE_NUM_LOCAL).
app/src/test/java/com/geeksville/mesh/service/MeshMessageProcessorTest.kt Adds tests verifying local vs remote packet logging behavior.

This commit enables the Metrics screen to display data logged from the local node itself, identified by `NODE_NUM_LOCAL`. Previously, the screen would only show data for remote nodes.

This is achieved by using the `effectiveLogNodeId` to determine whether to query for the specific node's ID or the generic local node ID. This change affects how telemetry, mesh packets (signal, position), and other logs (traceroute, neighbor info, paxcounter) are fetched and displayed.

Specific changes include:
- Refactored `MetricsViewModel` to use `nodeRepository.effectiveLogNodeId` which resolves to `NODE_NUM_LOCAL` when the metrics for the local device are being viewed.
- Data flows for telemetry, signal metrics, traceroute, neighbor info, position, and paxcounter are now switched based on this effective node ID.
- The signal metric filter was updated from `isDirectSignal()` to the more inclusive `hasValidSignal()` to correctly display metrics for the local node.
- Added a test case in `MeshLogRepositoryTest` to verify that `deleteLogs` correctly targets `NODE_NUM_LOCAL` when the local node's number is provided.

Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
This commit prevents telemetry and paxcount packets that are requests for data (`want_response = true`) from being logged as data points in the metrics screen. This ensures that only actual measurement data is used for graphing and analysis.

Additionally, this change includes a minor bug fix in the position CSV export and general code reformatting.

Specific changes:
- Updated `MeshLogRepository` to filter out telemetry packets where `want_response` is true.
- Modified `MetricsViewModel` to ignore paxcounter packets where `want_response` is true.
- Corrected a variable name from `satsIn_view` to `satsInView` in the `savePositionCSV` function.
- Applied general code cleanup and reformatting across `MetricsViewModel.kt` and `MeshLogRepository.kt`.

Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
@jamesarich jamesarich added this pull request to the merge queue Feb 16, 2026
Merged via the queue into main with commit c690ddc Feb 16, 2026
8 checks passed
@jamesarich jamesarich deleted the fix/positions branch February 16, 2026 22:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix PR tag

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: traceroute log missing since 2.7.13 [Bug]: Position log of 3rd party node fails to update after arbitrary amount of time

2 participants