fix tracepath

This commit is contained in:
PacoX
2026-05-26 20:12:27 +02:00
parent e88281b7b6
commit 5d03f99040
11 changed files with 566 additions and 185 deletions
+9 -5
View File
@@ -2821,7 +2821,7 @@ class MeshCoreConnector extends ChangeNotifier {
);
if (idx != -1) {
_contacts[idx] = _contacts[idx].copyWith(
pathLength: customPath.length,
pathLength: pathLen,
path: customPath,
);
notifyListeners();
@@ -4578,7 +4578,7 @@ class MeshCoreConnector extends ChangeNotifier {
isOutgoing: false,
isCli: isCli,
status: MessageStatus.delivered,
pathLength: pathLength == 0xFF ? 0 : pathLength,
pathLength: pathLength == 0xFF ? -1 : (pathLength & 0x3F),
pathBytes: Uint8List(0),
fourByteRoomContactKey: msgText.length >= 4
? Uint8List.fromList(msgText.substring(0, 4).codeUnits)
@@ -6025,6 +6025,7 @@ class MeshCoreConnector extends ChangeNotifier {
final packet = BufferReader(frame);
int payloadType = 0;
Uint8List pathBytes = Uint8List(0);
int pathHashWidth = 1;
try {
packet.skipBytes(1); // Skip frame type byte
packet.skipBytes(1); // Skip SNR byte
@@ -6039,6 +6040,7 @@ class MeshCoreConnector extends ChangeNotifier {
//final payloadVer = (header >> 6) & 0x03;
final pathLenRaw = packet.readByte();
final pathByteLen = _decodePathByteLen(pathLenRaw);
pathHashWidth = _decodePathHashWidth(pathLenRaw);
pathBytes = packet.readBytes(pathByteLen);
} catch (e) {
appLogger.warn('Malformed RX frame: $e', tag: 'Connector');
@@ -6086,7 +6088,7 @@ class MeshCoreConnector extends ChangeNotifier {
publicKey: publicKey,
name: name,
type: type,
pathLength: pathBytes.isEmpty ? -1 : pathBytes.length,
pathLength: pathBytes.isEmpty ? -1 : (pathBytes.length ~/ pathHashWidth),
path: Uint8List.fromList(
pathBytes.reversed.toList(),
), // Store path in reverse for easier use in outgoing messages
@@ -6171,7 +6173,7 @@ class MeshCoreConnector extends ChangeNotifier {
publicKey: publicKey,
name: name,
type: type,
pathLength: path.length,
pathLength: path.isEmpty ? -1 : (path.length ~/ pathHashWidth),
path: Uint8List.fromList(
path.reversed.toList(),
), // Store path in reverse for easier use in outgoing messages
@@ -6223,7 +6225,7 @@ class MeshCoreConnector extends ChangeNotifier {
longitude: hasLocation ? longitude : existing.longitude,
name: hasName ? name : existing.name,
path: Uint8List.fromList(path.reversed.toList()),
pathLength: path.length,
pathLength: path.isEmpty ? -1 : (path.length ~/ pathHashWidth),
lastMessageAt: mergedLastMessageAt,
lastSeen: DateTime.fromMillisecondsSinceEpoch(timestamp * 1000),
pathOverride: existing.pathOverride, // Preserve user's path choice
@@ -6517,12 +6519,14 @@ const int _cipherMacSize = 2;
/// Decodes the firmware's encoded path_len byte into actual byte length.
/// Bits 0-5: hash count (0-63), Bits 6-7: hash size code (0=1byte, 1=2bytes, 2=3bytes).
int _decodePathByteLen(int pathLenRaw) {
if (pathLenRaw == 0xFF || pathLenRaw == 0) return 0;
final hashCount = pathLenRaw & 63;
final hashSize = _decodePathHashWidth(pathLenRaw);
return hashCount * hashSize;
}
int _decodePathHashWidth(int pathLenRaw) {
if (pathLenRaw == 0xFF) return 1;
return ((pathLenRaw >> 6) & 0x03) + 1;
}