Refactor LoRa airtime tests and add new functionality
- Updated LoRa airtime calculations in `lora_airtime_test.dart` to reflect new reference values. - Introduced new tests for LDRO behavior and preamble symbol calculations. - Added `contact_path_width_test.dart` to validate path hash width handling in contacts. - Enhanced `model_changes_test.dart` to ensure legacy data migration works correctly. - Created `remote_node_stats_test.dart` to decode and validate remote node statistics. - Implemented `map_marker_parse_test.dart` for parsing marker text with coordinate validation. - Developed `map_tile_cache_key_test.dart` to ensure API keys are excluded from cache keys. - Added `message_retry_failure_test.dart` to test message retry service behavior on failures. - Extended `path_history_service_test.dart` to preserve learned state across path attempts. - Enhanced `received_image_store_test.dart` to handle concurrent writes and review fixes. - Implemented `repeater_command_service_test.dart` to validate command response handling. - Created `store_tolerant_parsing_test.dart` to ensure stores skip malformed records gracefully. - Cleared untranslated JSON file for localization updates.
This commit is contained in:
1 parent
d5f54dfa11
commit
d74587c167
105 files changed
+6419
-2072
No files matched your search
@@ -107,7 +107,7 @@ class Channel {
|
||||
/// Normalize a hashtag name for consistent community PSK derivation.
|
||||
/// Strips leading #, converts to lowercase, trims whitespace.
|
||||
static String _normalizeCommunityHashtag(String hashtag) {
|
||||
return hashtag.replaceFirst(RegExp(r'^#'), '').toLowerCase().trim();
|
||||
return hashtag.trim().replaceFirst(RegExp(r'^#'), '').toLowerCase().trim();
|
||||
}
|
||||
|
||||
static String formatPskHex(Uint8List psk) {
|
||||
|
||||
@@ -157,7 +157,7 @@ class ChannelMessage {
|
||||
return null;
|
||||
}
|
||||
|
||||
int pathLen;
|
||||
int? pathLen;
|
||||
int txtType;
|
||||
int? packetPathHashWidth;
|
||||
Uint8List pathBytes = Uint8List(0);
|
||||
@@ -169,20 +169,24 @@ class ChannelMessage {
|
||||
reader.skipBytes(1); // Skip reserved byte
|
||||
channelIdx = reader.readByte();
|
||||
final pathByte = reader.readUInt8();
|
||||
// pathByte packs: top 2 bits = hash width mode, low 6 bits = hop count
|
||||
packetPathHashWidth = ((pathByte & 0xC0) >> 6) + 1;
|
||||
final hopCount = pathByte & 0x3F;
|
||||
pathLen = hopCount;
|
||||
// If a path is present, read hopCount * width bytes
|
||||
if (hasPath && hopCount > 0) {
|
||||
final totalPathBytes = hopCount * packetPathHashWidth;
|
||||
pathBytes = reader.readBytes(totalPathBytes);
|
||||
// 0xFF = direct-routed; hop count is not reported.
|
||||
if (pathByte != 0xFF) {
|
||||
// pathByte packs: top 2 bits = hash width mode, low 6 bits = hop count
|
||||
packetPathHashWidth = ((pathByte & 0xC0) >> 6) + 1;
|
||||
final hopCount = pathByte & 0x3F;
|
||||
pathLen = hopCount;
|
||||
// If a path is present, read hopCount * width bytes
|
||||
if (hasPath && hopCount > 0) {
|
||||
final totalPathBytes = hopCount * packetPathHashWidth;
|
||||
pathBytes = reader.readBytes(totalPathBytes);
|
||||
}
|
||||
}
|
||||
// After consuming optional path bytes, read the text type byte.
|
||||
txtType = reader.readByte();
|
||||
} else {
|
||||
channelIdx = reader.readByte();
|
||||
pathLen = reader.readInt8();
|
||||
final pathByte = reader.readUInt8();
|
||||
pathLen = pathByte == 0xFF ? null : pathByte & 0x3F;
|
||||
txtType = reader.readByte();
|
||||
}
|
||||
final timestampRaw = reader.readUInt32LE();
|
||||
|
||||
@@ -76,12 +76,14 @@ class Community {
|
||||
factory Community.fromJson(Map<String, dynamic> json) {
|
||||
return Community(
|
||||
id: json['id'] as String,
|
||||
name: json['name'] as String,
|
||||
name: json['name'] as String? ?? '',
|
||||
secret: base64Decode(json['secret'] as String),
|
||||
createdAt: DateTime.fromMillisecondsSinceEpoch(json['created_at'] as int),
|
||||
createdAt: DateTime.fromMillisecondsSinceEpoch(
|
||||
json['created_at'] as int? ?? 0,
|
||||
),
|
||||
hashtagChannels:
|
||||
(json['hashtag_channels'] as List<dynamic>?)
|
||||
?.map((e) => e as String)
|
||||
?.whereType<String>()
|
||||
.toList() ??
|
||||
[],
|
||||
);
|
||||
@@ -157,7 +159,7 @@ class Community {
|
||||
/// Normalize a hashtag name for consistent PSK derivation.
|
||||
/// Strips leading #, converts to lowercase, trims whitespace.
|
||||
static String _normalizeCommunityHashtag(String hashtag) {
|
||||
return hashtag.replaceFirst(RegExp(r'^#'), '').toLowerCase().trim();
|
||||
return hashtag.trim().replaceFirst(RegExp(r'^#'), '').toLowerCase().trim();
|
||||
}
|
||||
|
||||
/// Returns true if this is the community's public channel
|
||||
|
||||
+14
-2
@@ -10,6 +10,7 @@ class Contact {
|
||||
final int flags;
|
||||
final int pathLength; // -1 = flood, 0+ = direct hops (from device)
|
||||
final Uint8List path; // Path bytes from device
|
||||
final int pathHashWidth; // Bytes per hop in [path], as learned by the device
|
||||
final int?
|
||||
pathOverride; // User's path override: -1 = force flood, null = auto
|
||||
final Uint8List? pathOverrideBytes; // User's path override bytes
|
||||
@@ -29,6 +30,7 @@ class Contact {
|
||||
this.flags = 0,
|
||||
required this.pathLength,
|
||||
required this.path,
|
||||
this.pathHashWidth = 1,
|
||||
this.pathOverride,
|
||||
this.pathOverrideBytes,
|
||||
this.latitude,
|
||||
@@ -81,6 +83,7 @@ class Contact {
|
||||
int? flags,
|
||||
int? pathLength,
|
||||
Uint8List? path,
|
||||
int? pathHashWidth,
|
||||
int? pathOverride,
|
||||
Uint8List? pathOverrideBytes,
|
||||
bool clearPathOverride = false,
|
||||
@@ -99,6 +102,7 @@ class Contact {
|
||||
flags: flags ?? this.flags,
|
||||
pathLength: pathLength ?? this.pathLength,
|
||||
path: path ?? this.path,
|
||||
pathHashWidth: pathHashWidth ?? this.pathHashWidth,
|
||||
pathOverride: clearPathOverride
|
||||
? null
|
||||
: (pathOverride ?? this.pathOverride),
|
||||
@@ -140,6 +144,13 @@ class Contact {
|
||||
return "<${publicKeyHex.substring(0, 8)}...${publicKeyHex.substring(publicKeyHex.length - 8)}>";
|
||||
}
|
||||
|
||||
/// Infers bytes per hop for stored paths that predate [pathHashWidth].
|
||||
static int inferPathHashWidth(int hopCount, int byteLen) {
|
||||
if (hopCount <= 0 || byteLen % hopCount != 0) return 1;
|
||||
final width = byteLen ~/ hopCount;
|
||||
return width >= 1 && width <= 3 ? width : 1;
|
||||
}
|
||||
|
||||
Uint8List get pathBytesForDisplay {
|
||||
if (pathOverride != null) {
|
||||
if (pathOverride! < 0) return Uint8List(0);
|
||||
@@ -168,12 +179,12 @@ class Contact {
|
||||
final pathLen = reader.readByte();
|
||||
int hopCount = 0;
|
||||
int byteLen = 0;
|
||||
int width = 1;
|
||||
if (pathLen == 0xFF) {
|
||||
hopCount = -1;
|
||||
} else {
|
||||
final mode = (pathLen & 0xC0) >> 6;
|
||||
width = ((pathLen & 0xC0) >> 6) + 1;
|
||||
hopCount = pathLen & 0x3F;
|
||||
final width = mode + 1;
|
||||
byteLen = hopCount * width;
|
||||
}
|
||||
final safePathLen = byteLen > 0
|
||||
@@ -225,6 +236,7 @@ class Contact {
|
||||
flags: flags,
|
||||
pathLength: hopCount,
|
||||
path: pathBytes,
|
||||
pathHashWidth: width,
|
||||
latitude: lat,
|
||||
longitude: lon,
|
||||
lastSeen: DateTime.fromMillisecondsSinceEpoch(
|
||||
|
||||
@@ -35,7 +35,7 @@ class DeliveryObservation {
|
||||
pathLength: json['path_length'] as int,
|
||||
messageBytes: json['message_bytes'] as int,
|
||||
secondsSinceLastRx: json['seconds_since_last_rx'] as int? ?? 0,
|
||||
isFlood: json['is_flood'] as bool,
|
||||
isFlood: json['is_flood'] as bool? ?? false,
|
||||
deliveryMs: json['delivery_ms'] as int,
|
||||
timestamp: DateTime.parse(json['timestamp'] as String),
|
||||
);
|
||||
|
||||
@@ -525,7 +525,7 @@ class RadioSettings {
|
||||
(
|
||||
'Off-Grid 869',
|
||||
RadioSettings(
|
||||
frequencyMHz: 869.0,
|
||||
frequencyMHz: 869.495,
|
||||
bandwidth: LoRaBandwidth.bw250,
|
||||
spreadingFactor: LoRaSpreadingFactor.sf11,
|
||||
codingRate: LoRaCodingRate.cr4_8,
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
import 'dart:typed_data';
|
||||
|
||||
/// Binary status reply pushed as PUSH_CODE_STATUS_RESPONSE.
|
||||
///
|
||||
/// The first 48 bytes are shared by repeater `RepeaterStats` and room
|
||||
/// `ServerStats`. After that, repeaters send `total_rx_air_time_secs` and
|
||||
/// `n_recv_errors` (uint32 each), rooms send `n_posted` and `n_post_push`
|
||||
/// (uint16 each).
|
||||
class RemoteNodeStats {
|
||||
static const int payloadOffset = 8;
|
||||
static const int commonSize = 48;
|
||||
|
||||
final int batteryMv;
|
||||
final int queueLen;
|
||||
final int noiseFloor;
|
||||
final int lastRssi;
|
||||
final int packetsRecv;
|
||||
final int packetsSent;
|
||||
final int txAirSecs;
|
||||
final int uptimeSecs;
|
||||
final int floodTx;
|
||||
final int directTx;
|
||||
final int floodRx;
|
||||
final int directRx;
|
||||
final int errEvents;
|
||||
final double lastSnr;
|
||||
final int directDups;
|
||||
final int floodDups;
|
||||
final int? rxAirSecs;
|
||||
final int? recvErrors;
|
||||
final int? posted;
|
||||
final int? postPushes;
|
||||
|
||||
const RemoteNodeStats({
|
||||
required this.batteryMv,
|
||||
required this.queueLen,
|
||||
required this.noiseFloor,
|
||||
required this.lastRssi,
|
||||
required this.packetsRecv,
|
||||
required this.packetsSent,
|
||||
required this.txAirSecs,
|
||||
required this.uptimeSecs,
|
||||
required this.floodTx,
|
||||
required this.directTx,
|
||||
required this.floodRx,
|
||||
required this.directRx,
|
||||
required this.errEvents,
|
||||
required this.lastSnr,
|
||||
required this.directDups,
|
||||
required this.floodDups,
|
||||
this.rxAirSecs,
|
||||
this.recvErrors,
|
||||
this.posted,
|
||||
this.postPushes,
|
||||
});
|
||||
|
||||
static RemoteNodeStats? tryParse(Uint8List frame, {required bool isRoom}) {
|
||||
if (frame.length < payloadOffset + commonSize) return null;
|
||||
final data = ByteData.sublistView(frame, payloadOffset);
|
||||
int u16(int o) => data.getUint16(o, Endian.little);
|
||||
int i16(int o) => data.getInt16(o, Endian.little);
|
||||
int u32(int o) => data.getUint32(o, Endian.little);
|
||||
bool has(int o, int size) => data.lengthInBytes >= o + size;
|
||||
|
||||
return RemoteNodeStats(
|
||||
batteryMv: u16(0),
|
||||
queueLen: u16(2),
|
||||
noiseFloor: i16(4),
|
||||
lastRssi: i16(6),
|
||||
packetsRecv: u32(8),
|
||||
packetsSent: u32(12),
|
||||
txAirSecs: u32(16),
|
||||
uptimeSecs: u32(20),
|
||||
floodTx: u32(24),
|
||||
directTx: u32(28),
|
||||
floodRx: u32(32),
|
||||
directRx: u32(36),
|
||||
errEvents: u16(40),
|
||||
lastSnr: i16(42) / 4.0,
|
||||
directDups: u16(44),
|
||||
floodDups: u16(46),
|
||||
rxAirSecs: !isRoom && has(48, 4) ? u32(48) : null,
|
||||
recvErrors: !isRoom && has(52, 4) ? u32(52) : null,
|
||||
posted: isRoom && has(48, 2) ? u16(48) : null,
|
||||
postPushes: isRoom && has(50, 2) ? u16(50) : null,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user