feat: Accurately display outgoing diagnostic packets#4569
Merged
Conversation
Codecov Report❌ Patch coverage is 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. |
58e8bd8 to
9f0c01a
Compare
…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>
9f0c01a to
279c5da
Compare
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>
Contributor
There was a problem hiding this comment.
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_LOCALrather than the transient hardware node number. - Centralize local-node ID remapping in
MeshLogRepository(and addgetRequestLogs) 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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
MeshMessageProcessorandPacketHandlerto log packets from the local node usingMeshLog.NODE_NUM_LOCAL, ensuring consistency and stability in log records. [1] [2]MeshMessageProcessorTest.ktandPacketHandlerTest.ktto verify that logs from the local node useNODE_NUM_LOCALand logs from remote nodes use their actual node numbers. [1] [2]Repository and Query Improvements
MeshLogRepositoryto centralize the mapping of local node numbers toNODE_NUM_LOCALin all relevant queries, including telemetry and general log retrieval, as well as log deletion. Introduced theeffectiveLogIdhelper and improved documentation throughout. [1] [2] [3]PORT_ANYconstant for generalized port queries and improved method documentation to clarify log retrieval and deletion behaviors.Node Repository Enhancements
effectiveLogNodeIdhelper toNodeRepositoryfor consistent log queries, and improved documentation for repository methods and properties. [1] [2] [3] [4] [5] [6]