feat(#438): show path type + SNR on the message Path screen

Tapping a DM opens the Path screen; it now shows the RF details the app
was already receiving but discarding:

- SNR: captured from the v3 contact-msg-recv frame (was skipBytes(1)).
  Firmware sends (int8)(snr_dB*4), so dB = byte/4.0 (MyMesh.cpp:512) —
  the old commented-out code multiplied by 4, which was 16x wrong.
- Path type: firmware sends path_len 0xFF for a direct/routed frame and
  the hop count for a flood (MyMesh.cpp:545). The app collapsed 0xFF->0,
  colliding "direct" with "flood, 0 hops". Capture the distinction into
  Message.isFloodRoute so the Path row reads "direct (routed)" vs
  "flood, N hops".
- RSSI: row wired to Message.rssi but left null — the wire byte is a
  hardcoded reserved 0 today; populated once firmware ships it (#439).

Message gains snr/rssi/isFloodRoute (nullable, additive, persisted like
rxTime). 10 tests cover scaling, the 0xFF discriminator, and copyWith.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
pull/454/head
Strycher 4 months ago
parent 7933567abf
commit f935a48ef0

@ -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');

@ -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": {

@ -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:

@ -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 => 'Наблюдаван път';

@ -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';

@ -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';

@ -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';

@ -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é';

@ -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';

@ -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';

@ -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 => '観察された経路';

@ -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 => '관찰된 경로';

@ -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';

@ -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';

@ -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';

@ -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 => 'Наблюдаемый путь';

@ -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';

@ -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';

@ -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';

@ -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 => 'Спостережуваний шлях';

@ -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 => '观察到的路径';

@ -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<String, List<String>>? reactionSenders,
Map<String, MessageStatus>? reactionStatuses,
this.rxTime,
this.snr,
this.rssi,
this.isFloodRoute,
}) : messageId =
messageId ??
'${timestamp.millisecondsSinceEpoch}_${pubKeyToHex(senderKey)}_${text.hashCode}',
@ -105,6 +123,9 @@ class Message {
Map<String, MessageStatus>? 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,
);
}

@ -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!),
),
],
),
),

@ -1501,7 +1501,12 @@ class _ChatScreenState extends State<ChatScreen> {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => ChannelMessagePathScreen(message: pathMessage),
builder: (context) => ChannelMessagePathScreen(
message: pathMessage,
snr: message.snr,
rssi: message.rssi,
isFloodRoute: message.isFloodRoute,
),
),
);
}

@ -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?,
);
}
}

@ -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<int>.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));
});
}
Loading…
Cancel
Save

Powered by TurnKey Linux.