diff --git a/lib/connector/meshcore_connector.dart b/lib/connector/meshcore_connector.dart index 79d4ed4a..9f4e53b9 100644 --- a/lib/connector/meshcore_connector.dart +++ b/lib/connector/meshcore_connector.dart @@ -5920,21 +5920,27 @@ class MeshCoreConnector extends ChangeNotifier { } // Companion radio layout: - // [code][snr?][res?][res?][prefix x6][path_len][txt_type][timestamp x4][extra?][text...] - // double snr = 0; + // [code][snr][res1][res2][prefix x6][path_len][txt_type][timestamp x4][extra?][text...] + // Firmware writes snr as (int8)(snr_dB * 4), so dB = byte / 4.0 + // (MyMesh.cpp:512). res1 bit0 = device-composed outgoing flag (#429); + // res2 will carry RSSI once firmware ships it (#439/#456) — not read yet. + double? snr; bool isOutgoing = false; if (code == respCodeContactMsgRecvV3) { - // Older firmware layout with SNR as a signed byte after the code - // snr = reader.readInt8().toDouble() * 4; // SNR in dB, scaled by 4 - reader.skipBytes(1); // Skip SNR byte + snr = reader.readInt8() / 4.0; // reserved1 bit0 = outgoing flag: set for a message composed on the // device itself, so it renders as sent-by-me (#429 part B). isOutgoing = (reader.readByte() & 0x01) != 0; - reader.skipBytes(1); // Skip reserved2 + reader.skipBytes(1); // reserved2 (RSSI pending — #439/#456) } final senderPrefix = reader.readBytes(6); - final pathLength = reader.readByte(); + // path_len is the flood hop count, or 0xFF when the frame arrived + // direct/point-to-point (MyMesh.cpp:545). Preserve that distinction for + // the Path screen before the 0xFF->0 normalization below. (#438) + final rawPathLen = reader.readByte(); + final isFloodRoute = rawPathLen != 0xFF; + final pathLength = rawPathLen; final txtType = reader.readByte(); final timestampRaw = reader.readUInt32LE(); final timestamp = DateTime.fromMillisecondsSinceEpoch( @@ -5996,7 +6002,11 @@ class MeshCoreConnector extends ChangeNotifier { pathLength: pathLength == 0xFF ? 0 : pathLength, pathBytes: Uint8List(0), fourByteRoomContactKey: roomAuthorPrefix, + // A device-composed outgoing message has no real RX frame, so its SNR / + // path-type / rxTime are meaningless — null them like rxTime (#429/#438). rxTime: isOutgoing ? null : DateTime.now(), + snr: isOutgoing ? null : snr, + isFloodRoute: isOutgoing ? null : isFloodRoute, ); } catch (e) { appLogger.warn('Error parsing contact direct message: $e'); diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index d174e039..a319bf25 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -1956,6 +1956,33 @@ } }, "channelPath_pathLabelTitle": "Path", + "channelPath_routeDirect": "direct (routed)", + "channelPath_routeFlood": "flood, {hops} hops", + "@channelPath_routeFlood": { + "placeholders": { + "hops": { + "type": "int" + } + } + }, + "channelPath_snrLabel": "SNR", + "channelPath_snrValue": "{db} dB", + "@channelPath_snrValue": { + "placeholders": { + "db": { + "type": "String" + } + } + }, + "channelPath_rssiLabel": "RSSI", + "channelPath_rssiValue": "{dbm} dBm", + "@channelPath_rssiValue": { + "placeholders": { + "dbm": { + "type": "int" + } + } + }, "channelPath_observedPathHeader": "Observed Path", "channelPath_selectedPathLabel": "{label} • {prefixes}", "@channelPath_selectedPathLabel": { diff --git a/lib/l10n/app_localizations.dart b/lib/l10n/app_localizations.dart index 4206a7c5..3e2c821d 100644 --- a/lib/l10n/app_localizations.dart +++ b/lib/l10n/app_localizations.dart @@ -6368,6 +6368,42 @@ abstract class AppLocalizations { /// **'Path'** String get channelPath_pathLabelTitle; + /// No description provided for @channelPath_routeDirect. + /// + /// In en, this message translates to: + /// **'direct (routed)'** + String get channelPath_routeDirect; + + /// No description provided for @channelPath_routeFlood. + /// + /// In en, this message translates to: + /// **'flood, {hops} hops'** + String channelPath_routeFlood(int hops); + + /// No description provided for @channelPath_snrLabel. + /// + /// In en, this message translates to: + /// **'SNR'** + String get channelPath_snrLabel; + + /// No description provided for @channelPath_snrValue. + /// + /// In en, this message translates to: + /// **'{db} dB'** + String channelPath_snrValue(String db); + + /// No description provided for @channelPath_rssiLabel. + /// + /// In en, this message translates to: + /// **'RSSI'** + String get channelPath_rssiLabel; + + /// No description provided for @channelPath_rssiValue. + /// + /// In en, this message translates to: + /// **'{dbm} dBm'** + String channelPath_rssiValue(int dbm); + /// No description provided for @channelPath_observedPathHeader. /// /// In en, this message translates to: diff --git a/lib/l10n/app_localizations_bg.dart b/lib/l10n/app_localizations_bg.dart index fa5afe31..391b15a8 100644 --- a/lib/l10n/app_localizations_bg.dart +++ b/lib/l10n/app_localizations_bg.dart @@ -3675,6 +3675,30 @@ class AppLocalizationsBg extends AppLocalizations { @override String get channelPath_pathLabelTitle => 'Пътекино'; + @override + String get channelPath_routeDirect => 'direct (routed)'; + + @override + String channelPath_routeFlood(int hops) { + return 'flood, $hops hops'; + } + + @override + String get channelPath_snrLabel => 'SNR'; + + @override + String channelPath_snrValue(String db) { + return '$db dB'; + } + + @override + String get channelPath_rssiLabel => 'RSSI'; + + @override + String channelPath_rssiValue(int dbm) { + return '$dbm dBm'; + } + @override String get channelPath_observedPathHeader => 'Наблюдаван път'; diff --git a/lib/l10n/app_localizations_de.dart b/lib/l10n/app_localizations_de.dart index 12814e06..d25a0d3f 100644 --- a/lib/l10n/app_localizations_de.dart +++ b/lib/l10n/app_localizations_de.dart @@ -3681,6 +3681,30 @@ class AppLocalizationsDe extends AppLocalizations { @override String get channelPath_pathLabelTitle => 'Pfad'; + @override + String get channelPath_routeDirect => 'direct (routed)'; + + @override + String channelPath_routeFlood(int hops) { + return 'flood, $hops hops'; + } + + @override + String get channelPath_snrLabel => 'SNR'; + + @override + String channelPath_snrValue(String db) { + return '$db dB'; + } + + @override + String get channelPath_rssiLabel => 'RSSI'; + + @override + String channelPath_rssiValue(int dbm) { + return '$dbm dBm'; + } + @override String get channelPath_observedPathHeader => 'Beobachteter Pfad'; diff --git a/lib/l10n/app_localizations_en.dart b/lib/l10n/app_localizations_en.dart index 8e459630..e6674964 100644 --- a/lib/l10n/app_localizations_en.dart +++ b/lib/l10n/app_localizations_en.dart @@ -3610,6 +3610,30 @@ class AppLocalizationsEn extends AppLocalizations { @override String get channelPath_pathLabelTitle => 'Path'; + @override + String get channelPath_routeDirect => 'direct (routed)'; + + @override + String channelPath_routeFlood(int hops) { + return 'flood, $hops hops'; + } + + @override + String get channelPath_snrLabel => 'SNR'; + + @override + String channelPath_snrValue(String db) { + return '$db dB'; + } + + @override + String get channelPath_rssiLabel => 'RSSI'; + + @override + String channelPath_rssiValue(int dbm) { + return '$dbm dBm'; + } + @override String get channelPath_observedPathHeader => 'Observed Path'; diff --git a/lib/l10n/app_localizations_es.dart b/lib/l10n/app_localizations_es.dart index 6cd42a4e..d8e3b546 100644 --- a/lib/l10n/app_localizations_es.dart +++ b/lib/l10n/app_localizations_es.dart @@ -3669,6 +3669,30 @@ class AppLocalizationsEs extends AppLocalizations { @override String get channelPath_pathLabelTitle => 'Ruta'; + @override + String get channelPath_routeDirect => 'direct (routed)'; + + @override + String channelPath_routeFlood(int hops) { + return 'flood, $hops hops'; + } + + @override + String get channelPath_snrLabel => 'SNR'; + + @override + String channelPath_snrValue(String db) { + return '$db dB'; + } + + @override + String get channelPath_rssiLabel => 'RSSI'; + + @override + String channelPath_rssiValue(int dbm) { + return '$dbm dBm'; + } + @override String get channelPath_observedPathHeader => 'Ruta Observada'; diff --git a/lib/l10n/app_localizations_fr.dart b/lib/l10n/app_localizations_fr.dart index a6c40f0e..b5118139 100644 --- a/lib/l10n/app_localizations_fr.dart +++ b/lib/l10n/app_localizations_fr.dart @@ -3692,6 +3692,30 @@ class AppLocalizationsFr extends AppLocalizations { @override String get channelPath_pathLabelTitle => 'Chemin'; + @override + String get channelPath_routeDirect => 'direct (routed)'; + + @override + String channelPath_routeFlood(int hops) { + return 'flood, $hops hops'; + } + + @override + String get channelPath_snrLabel => 'SNR'; + + @override + String channelPath_snrValue(String db) { + return '$db dB'; + } + + @override + String get channelPath_rssiLabel => 'RSSI'; + + @override + String channelPath_rssiValue(int dbm) { + return '$dbm dBm'; + } + @override String get channelPath_observedPathHeader => 'Chemin observé'; diff --git a/lib/l10n/app_localizations_hu.dart b/lib/l10n/app_localizations_hu.dart index bb15161c..db701b40 100644 --- a/lib/l10n/app_localizations_hu.dart +++ b/lib/l10n/app_localizations_hu.dart @@ -3686,6 +3686,30 @@ class AppLocalizationsHu extends AppLocalizations { @override String get channelPath_pathLabelTitle => 'Út'; + @override + String get channelPath_routeDirect => 'direct (routed)'; + + @override + String channelPath_routeFlood(int hops) { + return 'flood, $hops hops'; + } + + @override + String get channelPath_snrLabel => 'SNR'; + + @override + String channelPath_snrValue(String db) { + return '$db dB'; + } + + @override + String get channelPath_rssiLabel => 'RSSI'; + + @override + String channelPath_rssiValue(int dbm) { + return '$dbm dBm'; + } + @override String get channelPath_observedPathHeader => 'Megfigyelt útvonal'; diff --git a/lib/l10n/app_localizations_it.dart b/lib/l10n/app_localizations_it.dart index e941e8d5..71fad96f 100644 --- a/lib/l10n/app_localizations_it.dart +++ b/lib/l10n/app_localizations_it.dart @@ -3674,6 +3674,30 @@ class AppLocalizationsIt extends AppLocalizations { @override String get channelPath_pathLabelTitle => 'Percorso'; + @override + String get channelPath_routeDirect => 'direct (routed)'; + + @override + String channelPath_routeFlood(int hops) { + return 'flood, $hops hops'; + } + + @override + String get channelPath_snrLabel => 'SNR'; + + @override + String channelPath_snrValue(String db) { + return '$db dB'; + } + + @override + String get channelPath_rssiLabel => 'RSSI'; + + @override + String channelPath_rssiValue(int dbm) { + return '$dbm dBm'; + } + @override String get channelPath_observedPathHeader => 'Percorso Osservato'; diff --git a/lib/l10n/app_localizations_ja.dart b/lib/l10n/app_localizations_ja.dart index cefdbe3a..cabb6aae 100644 --- a/lib/l10n/app_localizations_ja.dart +++ b/lib/l10n/app_localizations_ja.dart @@ -3491,6 +3491,30 @@ class AppLocalizationsJa extends AppLocalizations { @override String get channelPath_pathLabelTitle => '道'; + @override + String get channelPath_routeDirect => 'direct (routed)'; + + @override + String channelPath_routeFlood(int hops) { + return 'flood, $hops hops'; + } + + @override + String get channelPath_snrLabel => 'SNR'; + + @override + String channelPath_snrValue(String db) { + return '$db dB'; + } + + @override + String get channelPath_rssiLabel => 'RSSI'; + + @override + String channelPath_rssiValue(int dbm) { + return '$dbm dBm'; + } + @override String get channelPath_observedPathHeader => '観察された経路'; diff --git a/lib/l10n/app_localizations_ko.dart b/lib/l10n/app_localizations_ko.dart index 8e7f8d4c..36c1335d 100644 --- a/lib/l10n/app_localizations_ko.dart +++ b/lib/l10n/app_localizations_ko.dart @@ -3493,6 +3493,30 @@ class AppLocalizationsKo extends AppLocalizations { @override String get channelPath_pathLabelTitle => '경로'; + @override + String get channelPath_routeDirect => 'direct (routed)'; + + @override + String channelPath_routeFlood(int hops) { + return 'flood, $hops hops'; + } + + @override + String get channelPath_snrLabel => 'SNR'; + + @override + String channelPath_snrValue(String db) { + return '$db dB'; + } + + @override + String get channelPath_rssiLabel => 'RSSI'; + + @override + String channelPath_rssiValue(int dbm) { + return '$dbm dBm'; + } + @override String get channelPath_observedPathHeader => '관찰된 경로'; diff --git a/lib/l10n/app_localizations_nl.dart b/lib/l10n/app_localizations_nl.dart index 122044dc..5e0cb3cc 100644 --- a/lib/l10n/app_localizations_nl.dart +++ b/lib/l10n/app_localizations_nl.dart @@ -3656,6 +3656,30 @@ class AppLocalizationsNl extends AppLocalizations { @override String get channelPath_pathLabelTitle => 'Pad'; + @override + String get channelPath_routeDirect => 'direct (routed)'; + + @override + String channelPath_routeFlood(int hops) { + return 'flood, $hops hops'; + } + + @override + String get channelPath_snrLabel => 'SNR'; + + @override + String channelPath_snrValue(String db) { + return '$db dB'; + } + + @override + String get channelPath_rssiLabel => 'RSSI'; + + @override + String channelPath_rssiValue(int dbm) { + return '$dbm dBm'; + } + @override String get channelPath_observedPathHeader => 'Waargenomen Pad'; diff --git a/lib/l10n/app_localizations_pl.dart b/lib/l10n/app_localizations_pl.dart index 56fa7ed3..261f538b 100644 --- a/lib/l10n/app_localizations_pl.dart +++ b/lib/l10n/app_localizations_pl.dart @@ -3687,6 +3687,30 @@ class AppLocalizationsPl extends AppLocalizations { @override String get channelPath_pathLabelTitle => 'Ścieżka'; + @override + String get channelPath_routeDirect => 'direct (routed)'; + + @override + String channelPath_routeFlood(int hops) { + return 'flood, $hops hops'; + } + + @override + String get channelPath_snrLabel => 'SNR'; + + @override + String channelPath_snrValue(String db) { + return '$db dB'; + } + + @override + String get channelPath_rssiLabel => 'RSSI'; + + @override + String channelPath_rssiValue(int dbm) { + return '$dbm dBm'; + } + @override String get channelPath_observedPathHeader => 'Obserwowana ścieżka'; diff --git a/lib/l10n/app_localizations_pt.dart b/lib/l10n/app_localizations_pt.dart index 4437000a..c131e8b2 100644 --- a/lib/l10n/app_localizations_pt.dart +++ b/lib/l10n/app_localizations_pt.dart @@ -3668,6 +3668,30 @@ class AppLocalizationsPt extends AppLocalizations { @override String get channelPath_pathLabelTitle => 'Caminho'; + @override + String get channelPath_routeDirect => 'direct (routed)'; + + @override + String channelPath_routeFlood(int hops) { + return 'flood, $hops hops'; + } + + @override + String get channelPath_snrLabel => 'SNR'; + + @override + String channelPath_snrValue(String db) { + return '$db dB'; + } + + @override + String get channelPath_rssiLabel => 'RSSI'; + + @override + String channelPath_rssiValue(int dbm) { + return '$dbm dBm'; + } + @override String get channelPath_observedPathHeader => 'Rastreamento Observado'; diff --git a/lib/l10n/app_localizations_ru.dart b/lib/l10n/app_localizations_ru.dart index 24ac3d3c..9abac0b4 100644 --- a/lib/l10n/app_localizations_ru.dart +++ b/lib/l10n/app_localizations_ru.dart @@ -3676,6 +3676,30 @@ class AppLocalizationsRu extends AppLocalizations { @override String get channelPath_pathLabelTitle => 'Путь'; + @override + String get channelPath_routeDirect => 'direct (routed)'; + + @override + String channelPath_routeFlood(int hops) { + return 'flood, $hops hops'; + } + + @override + String get channelPath_snrLabel => 'SNR'; + + @override + String channelPath_snrValue(String db) { + return '$db dB'; + } + + @override + String get channelPath_rssiLabel => 'RSSI'; + + @override + String channelPath_rssiValue(int dbm) { + return '$dbm dBm'; + } + @override String get channelPath_observedPathHeader => 'Наблюдаемый путь'; diff --git a/lib/l10n/app_localizations_sk.dart b/lib/l10n/app_localizations_sk.dart index 8e0b1794..771f2522 100644 --- a/lib/l10n/app_localizations_sk.dart +++ b/lib/l10n/app_localizations_sk.dart @@ -3655,6 +3655,30 @@ class AppLocalizationsSk extends AppLocalizations { @override String get channelPath_pathLabelTitle => 'Cesta'; + @override + String get channelPath_routeDirect => 'direct (routed)'; + + @override + String channelPath_routeFlood(int hops) { + return 'flood, $hops hops'; + } + + @override + String get channelPath_snrLabel => 'SNR'; + + @override + String channelPath_snrValue(String db) { + return '$db dB'; + } + + @override + String get channelPath_rssiLabel => 'RSSI'; + + @override + String channelPath_rssiValue(int dbm) { + return '$dbm dBm'; + } + @override String get channelPath_observedPathHeader => 'Sledovaná cesta'; diff --git a/lib/l10n/app_localizations_sl.dart b/lib/l10n/app_localizations_sl.dart index ed6cefb8..4a6ab6f2 100644 --- a/lib/l10n/app_localizations_sl.dart +++ b/lib/l10n/app_localizations_sl.dart @@ -3650,6 +3650,30 @@ class AppLocalizationsSl extends AppLocalizations { @override String get channelPath_pathLabelTitle => 'Pot'; + @override + String get channelPath_routeDirect => 'direct (routed)'; + + @override + String channelPath_routeFlood(int hops) { + return 'flood, $hops hops'; + } + + @override + String get channelPath_snrLabel => 'SNR'; + + @override + String channelPath_snrValue(String db) { + return '$db dB'; + } + + @override + String get channelPath_rssiLabel => 'RSSI'; + + @override + String channelPath_rssiValue(int dbm) { + return '$dbm dBm'; + } + @override String get channelPath_observedPathHeader => 'Opazovana pot'; diff --git a/lib/l10n/app_localizations_sv.dart b/lib/l10n/app_localizations_sv.dart index b25e4c82..df159d4d 100644 --- a/lib/l10n/app_localizations_sv.dart +++ b/lib/l10n/app_localizations_sv.dart @@ -3630,6 +3630,30 @@ class AppLocalizationsSv extends AppLocalizations { @override String get channelPath_pathLabelTitle => 'Sökväg'; + @override + String get channelPath_routeDirect => 'direct (routed)'; + + @override + String channelPath_routeFlood(int hops) { + return 'flood, $hops hops'; + } + + @override + String get channelPath_snrLabel => 'SNR'; + + @override + String channelPath_snrValue(String db) { + return '$db dB'; + } + + @override + String get channelPath_rssiLabel => 'RSSI'; + + @override + String channelPath_rssiValue(int dbm) { + return '$dbm dBm'; + } + @override String get channelPath_observedPathHeader => 'Observerad Sökväg'; diff --git a/lib/l10n/app_localizations_uk.dart b/lib/l10n/app_localizations_uk.dart index 5f09a207..8d72e0dd 100644 --- a/lib/l10n/app_localizations_uk.dart +++ b/lib/l10n/app_localizations_uk.dart @@ -3672,6 +3672,30 @@ class AppLocalizationsUk extends AppLocalizations { @override String get channelPath_pathLabelTitle => 'Шлях'; + @override + String get channelPath_routeDirect => 'direct (routed)'; + + @override + String channelPath_routeFlood(int hops) { + return 'flood, $hops hops'; + } + + @override + String get channelPath_snrLabel => 'SNR'; + + @override + String channelPath_snrValue(String db) { + return '$db dB'; + } + + @override + String get channelPath_rssiLabel => 'RSSI'; + + @override + String channelPath_rssiValue(int dbm) { + return '$dbm dBm'; + } + @override String get channelPath_observedPathHeader => 'Спостережуваний шлях'; diff --git a/lib/l10n/app_localizations_zh.dart b/lib/l10n/app_localizations_zh.dart index 99e472cf..6e75415f 100644 --- a/lib/l10n/app_localizations_zh.dart +++ b/lib/l10n/app_localizations_zh.dart @@ -3396,6 +3396,30 @@ class AppLocalizationsZh extends AppLocalizations { @override String get channelPath_pathLabelTitle => '路径'; + @override + String get channelPath_routeDirect => 'direct (routed)'; + + @override + String channelPath_routeFlood(int hops) { + return 'flood, $hops hops'; + } + + @override + String get channelPath_snrLabel => 'SNR'; + + @override + String channelPath_snrValue(String db) { + return '$db dB'; + } + + @override + String get channelPath_rssiLabel => 'RSSI'; + + @override + String channelPath_rssiValue(int dbm) { + return '$dbm dBm'; + } + @override String get channelPath_observedPathHeader => '观察到的路径'; diff --git a/lib/models/message.dart b/lib/models/message.dart index 37e0964d..2535962b 100644 --- a/lib/models/message.dart +++ b/lib/models/message.dart @@ -47,6 +47,21 @@ class Message { /// fabricated. [timestamp] is the SENDER's claimed time; this is ours. final DateTime? rxTime; + /// RX signal-to-noise in dB for the received frame, captured from the v3 + /// contact-msg-recv frame. Null for outgoing messages, pre-v3 firmware, and + /// records stored before #438 — never fabricated. (#438) + final double? snr; + + /// RX signal strength in dBm. Null until firmware populates it — the wire + /// currently sends a reserved 0 byte here, so we do NOT read it yet (#439). + final int? rssi; + + /// True if this frame arrived flood-routed (path_len = hop count); false if + /// it came direct/point-to-point (firmware sends path_len 0xFF for that, + /// MyMesh.cpp:545). Null for outgoing/pre-#438 records. Drives the Path + /// screen's "direct (routed)" vs "flood, N hops" label. (#438) + final bool? isFloodRoute; + Message({ required this.senderKey, required this.text, @@ -73,6 +88,9 @@ class Message { Map>? reactionSenders, Map? reactionStatuses, this.rxTime, + this.snr, + this.rssi, + this.isFloodRoute, }) : messageId = messageId ?? '${timestamp.millisecondsSinceEpoch}_${pubKeyToHex(senderKey)}_${text.hashCode}', @@ -105,6 +123,9 @@ class Message { Map? reactionStatuses, Uint8List? fourByteRoomContactKey, DateTime? rxTime, + double? snr, + int? rssi, + bool? isFloodRoute, }) { return Message( senderKey: senderKey, @@ -141,6 +162,9 @@ class Message { fourByteRoomContactKey: fourByteRoomContactKey ?? this.fourByteRoomContactKey, rxTime: rxTime ?? this.rxTime, + snr: snr ?? this.snr, + rssi: rssi ?? this.rssi, + isFloodRoute: isFloodRoute ?? this.isFloodRoute, ); } diff --git a/lib/screens/channel_message_path_screen.dart b/lib/screens/channel_message_path_screen.dart index 274e004b..7014c342 100644 --- a/lib/screens/channel_message_path_screen.dart +++ b/lib/screens/channel_message_path_screen.dart @@ -21,10 +21,21 @@ import '../widgets/adaptive_app_bar_title.dart'; class ChannelMessagePathScreen extends StatelessWidget { final ChannelMessage message; final bool channelMessage; + + /// RF details for a direct message, sourced from the [Message] (#438). Null + /// for channel messages and outgoing/legacy records; each row is hidden when + /// its value is null. [rssi] stays null until firmware ships it (#439). + final double? snr; + final int? rssi; + final bool? isFloodRoute; + const ChannelMessagePathScreen({ super.key, required this.message, this.channelMessage = false, + this.snr, + this.rssi, + this.isFloodRoute, }); @override @@ -146,10 +157,24 @@ class ChannelMessagePathScreen extends StatelessWidget { ), _buildDetailRow( l10n.channelPath_pathLabelTitle, - _formatPathLabel(message.hopCount, l10n), + isFloodRoute == null + ? _formatPathLabel(message.hopCount, l10n) + : (isFloodRoute! + ? l10n.channelPath_routeFlood(message.hopCount ?? 0) + : l10n.channelPath_routeDirect), ), if (observedLabel != null) _buildDetailRow(l10n.channelPath_observedLabel, observedLabel), + if (snr != null) + _buildDetailRow( + l10n.channelPath_snrLabel, + l10n.channelPath_snrValue(snr!.toStringAsFixed(2)), + ), + if (rssi != null) + _buildDetailRow( + l10n.channelPath_rssiLabel, + l10n.channelPath_rssiValue(rssi!), + ), ], ), ), diff --git a/lib/screens/chat_screen.dart b/lib/screens/chat_screen.dart index dfe0be79..8710592b 100644 --- a/lib/screens/chat_screen.dart +++ b/lib/screens/chat_screen.dart @@ -1501,7 +1501,12 @@ class _ChatScreenState extends State { Navigator.push( context, MaterialPageRoute( - builder: (context) => ChannelMessagePathScreen(message: pathMessage), + builder: (context) => ChannelMessagePathScreen( + message: pathMessage, + snr: message.snr, + rssi: message.rssi, + isFloodRoute: message.isFloodRoute, + ), ), ); } diff --git a/lib/storage/message_store.dart b/lib/storage/message_store.dart index 4ad4c2bf..d7951531 100644 --- a/lib/storage/message_store.dart +++ b/lib/storage/message_store.dart @@ -175,6 +175,9 @@ class MessageStore { ), 'fourByteRoomContactKey': base64Encode(msg.fourByteRoomContactKey), 'rxTime': msg.rxTime?.millisecondsSinceEpoch, + 'snr': msg.snr, + 'rssi': msg.rssi, + 'isFloodRoute': msg.isFloodRoute, }; } @@ -234,6 +237,9 @@ class MessageStore { rxTime: json['rxTime'] != null ? DateTime.fromMillisecondsSinceEpoch(json['rxTime'] as int) : null, + snr: (json['snr'] as num?)?.toDouble(), + rssi: json['rssi'] as int?, + isFloodRoute: json['isFloodRoute'] as bool?, ); } } diff --git a/test/models/message_snr_test.dart b/test/models/message_snr_test.dart new file mode 100644 index 00000000..e909ce19 --- /dev/null +++ b/test/models/message_snr_test.dart @@ -0,0 +1,75 @@ +import 'dart:typed_data'; + +import 'package:flutter_test/flutter_test.dart'; +import 'package:meshcore_open/models/message.dart'; + +void main() { + Uint8List key(int b) => Uint8List.fromList(List.filled(32, b)); + + group('Message SNR/RSSI/route fields (#438)', () { + test('defaults are null (legacy/outgoing records)', () { + final m = Message( + senderKey: key(1), + text: 'hi', + timestamp: DateTime(2026), + isOutgoing: true, + ); + expect(m.snr, isNull); + expect(m.rssi, isNull); + expect(m.isFloodRoute, isNull); + }); + + test('copyWith preserves fields when not overridden', () { + final m = Message( + senderKey: key(2), + text: 'hi', + timestamp: DateTime(2026), + isOutgoing: false, + snr: -3.25, + isFloodRoute: true, + ); + final c = m.copyWith(retryCount: 1); + expect(c.snr, -3.25); + expect(c.isFloodRoute, isTrue); + expect(c.rssi, isNull); + }); + + test('copyWith overrides when provided', () { + final m = Message( + senderKey: key(3), + text: 'hi', + timestamp: DateTime(2026), + isOutgoing: false, + snr: 5.0, + isFloodRoute: false, + ); + final c = m.copyWith(snr: 9.5, isFloodRoute: true, rssi: -80); + expect(c.snr, 9.5); + expect(c.isFloodRoute, isTrue); + expect(c.rssi, -80); + }); + }); + + group('SNR wire scaling (#438)', () { + // Firmware sends (int8)(snr_dB * 4); the app recovers dB as byte / 4.0 + // (MyMesh.cpp:512). A naive *4 would be 16x off and out of int8 range. + double snrFromByte(int b) => b.toSigned(8) / 4.0; + + test('positive SNR', () => expect(snrFromByte(50), 12.5)); + test('zero', () => expect(snrFromByte(0), 0.0)); + test('negative SNR', () => expect(snrFromByte(-13), closeTo(-3.25, 1e-9))); + test('int8 extremes stay in a sane dB range', () { + expect(snrFromByte(127), closeTo(31.75, 1e-9)); + expect(snrFromByte(-128), closeTo(-32.0, 1e-9)); + }); + }); + + group('flood vs direct discriminator (#438)', () { + // path_len == 0xFF => direct (routed); anything else => flood N hops. + bool isFlood(int rawPathLen) => rawPathLen != 0xFF; + + test('0xFF is direct', () => expect(isFlood(0xFF), isFalse)); + test('0 hops is flood, not direct', () => expect(isFlood(0), isTrue)); + test('3 hops is flood', () => expect(isFlood(3), isTrue)); + }); +}