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
@@ -213,6 +213,7 @@ const int cmdGetStats = 56;
|
||||
const int cmdSendAnonReq = 57;
|
||||
const int cmdSetAutoAddConfig = 58;
|
||||
const int cmdGetAutoAddConfig = 59;
|
||||
const int cmdGetAllowedRepeatFreq = 60;
|
||||
const int cmdSetPathHashMode = 61;
|
||||
|
||||
// Text message types
|
||||
@@ -262,6 +263,7 @@ const int respCodeChannelMsgRecvV3 = 17;
|
||||
const int respCodeChannelInfo = 18;
|
||||
const int respCodeCustomVars = 21;
|
||||
const int respCodeAutoAddConfig = 25;
|
||||
const int respCodeAllowedRepeatFreq = 26;
|
||||
const int respCodeStats = 24;
|
||||
|
||||
const int statsTypeCore = 0;
|
||||
@@ -282,6 +284,8 @@ const int pushCodeNewAdvert = 0x8A;
|
||||
const int pushCodeTelemetryResponse = 0x8B;
|
||||
const int pushCodeBinaryResponse = 0x8C;
|
||||
const int pushCodeControlData = 0x8E;
|
||||
const int pushCodeContactDeleted = 0x8F;
|
||||
const int pushCodeContactsFull = 0x90;
|
||||
|
||||
// Contact/advertisement types
|
||||
const int advTypeChat = 1;
|
||||
@@ -339,6 +343,10 @@ const int maxFrameSize = 172;
|
||||
const int appProtocolVersion = 4;
|
||||
// Matches firmware MAX_TEXT_LEN (10 * CIPHER_BLOCK_SIZE).
|
||||
const int maxTextPayloadBytes = 160;
|
||||
// From attempt 4 on the firmware appends [0][attempt] to the DM payload, so
|
||||
// the text must fit in MAX_TEXT_LEN - 2 (BaseChatMesh::composeMsgPacket).
|
||||
const int maxFullLengthTextAttempt = 3;
|
||||
const int maxTextPayloadBytesAfterFullLengthAttempts = maxTextPayloadBytes - 2;
|
||||
const int _sendTextMsgOverheadBytes =
|
||||
1 + 1 + 1 + 4 + 6 + 1 + 2; // +2 safety margin
|
||||
const int _sendChannelTextMsgOverheadBytes =
|
||||
@@ -589,7 +597,7 @@ Uint8List buildGetStatsFrame(int statsType) {
|
||||
|
||||
/// Path hash width on air: [61][0][mode], mode 0..3 → (mode+1) bytes per hop hash.
|
||||
Uint8List buildSetPathHashModeFrame(int mode) {
|
||||
final m = mode.clamp(0, 3).toInt();
|
||||
final m = mode.clamp(0, 2).toInt();
|
||||
return Uint8List.fromList([cmdSetPathHashMode, 0, m]);
|
||||
}
|
||||
|
||||
@@ -713,7 +721,9 @@ Uint8List buildResetPathFrame(Uint8List pubKey) {
|
||||
}
|
||||
|
||||
// Build CMD_ADD_UPDATE_CONTACT frame to set custom path
|
||||
// Format: [cmd][pub_key x32][type][flags][path_len][path x64][name x32][Lat? x4, Lon? x4][timestamp? x4]
|
||||
// Format: [cmd][pub_key x32][type][flags][path_len][path x64][name x32][last_advert x4][Lat? x4, Lon? x4][lastmod? x4]
|
||||
// The firmware stores last_advert as the contact's replay guard, so it must be
|
||||
// the contact's own advert timestamp (0 when unknown), never the phone clock.
|
||||
Uint8List buildUpdateContactPathFrame(
|
||||
Uint8List pubKey,
|
||||
Uint8List path,
|
||||
@@ -723,6 +733,7 @@ Uint8List buildUpdateContactPathFrame(
|
||||
String name = '',
|
||||
double? lat,
|
||||
double? lon,
|
||||
DateTime? lastAdvert,
|
||||
DateTime? lastModified,
|
||||
}) {
|
||||
final writer = BufferWriter();
|
||||
@@ -737,9 +748,10 @@ Uint8List buildUpdateContactPathFrame(
|
||||
// Name (32 bytes, null-padded)
|
||||
writer.writeCString(name, maxNameSize);
|
||||
|
||||
// Timestamp
|
||||
final timestamp = DateTime.now().millisecondsSinceEpoch ~/ 1000;
|
||||
writer.writeUInt32LE(timestamp);
|
||||
final lastAdvertSeconds = lastAdvert == null
|
||||
? 0
|
||||
: lastAdvert.millisecondsSinceEpoch ~/ 1000;
|
||||
writer.writeUInt32LE(lastAdvertSeconds.clamp(0, 0xFFFFFFFF).toInt());
|
||||
|
||||
// Optional [Lat x4, Lon x4][timestamp x4] tail per the doc comment above.
|
||||
// Emit 8 bytes of position (zero-filled when only lastModified is provided)
|
||||
@@ -777,28 +789,51 @@ Uint8List buildGetAutoAddFlagsFrame() {
|
||||
return Uint8List.fromList([cmdGetAutoAddConfig]);
|
||||
}
|
||||
|
||||
Uint8List buildGetAllowedRepeatFreqFrame() {
|
||||
return Uint8List.fromList([cmdGetAllowedRepeatFreq]);
|
||||
}
|
||||
|
||||
typedef RepeatFreqRange = ({int lowKHz, int highKHz});
|
||||
|
||||
// RESP_ALLOWED_REPEAT_FREQ: [code] then [lower_khz u32][upper_khz u32] pairs.
|
||||
List<RepeatFreqRange> parseAllowedRepeatFreqFrame(Uint8List frame) {
|
||||
final ranges = <RepeatFreqRange>[];
|
||||
final data = ByteData.sublistView(frame);
|
||||
for (var i = 1; i + 8 <= frame.length; i += 8) {
|
||||
ranges.add((
|
||||
lowKHz: data.getUint32(i, Endian.little),
|
||||
highKHz: data.getUint32(i + 4, Endian.little),
|
||||
));
|
||||
}
|
||||
return ranges;
|
||||
}
|
||||
|
||||
// Calculate LoRa airtime for a packet
|
||||
// Based on Semtech SX127x datasheet formula
|
||||
// Returns airtime in milliseconds
|
||||
// Preamble defaults to the firmware's per-SF length (32 up to SF8, 16 above,
|
||||
// RadioLibWrappers.h preambleLengthForSF); LDRO defaults to the RadioLib rule
|
||||
// (symbol time > 16 ms).
|
||||
int calculateLoRaAirtime({
|
||||
required int payloadBytes,
|
||||
required int spreadingFactor,
|
||||
required int bandwidthHz,
|
||||
required int codingRate,
|
||||
int preambleSymbols = 8,
|
||||
bool lowDataRateOptimize = false,
|
||||
int? preambleSymbols,
|
||||
bool? lowDataRateOptimize,
|
||||
bool explicitHeader = true,
|
||||
}) {
|
||||
// Symbol duration (Ts) in milliseconds
|
||||
final symbolDuration = (1 << spreadingFactor) / (bandwidthHz / 1000.0);
|
||||
|
||||
// Preamble time
|
||||
final preambleTime = (preambleSymbols + 4.25) * symbolDuration;
|
||||
final preamble = preambleSymbols ?? (spreadingFactor <= 8 ? 32 : 16);
|
||||
final preambleTime = (preamble + 4.25) * symbolDuration;
|
||||
|
||||
// Payload symbol count
|
||||
final headerBytes = explicitHeader ? 0 : 20;
|
||||
final crc = 1; // CRC enabled
|
||||
final de = lowDataRateOptimize ? 1 : 0;
|
||||
final de = (lowDataRateOptimize ?? symbolDuration > 16.0) ? 1 : 0;
|
||||
|
||||
final numerator =
|
||||
8 * payloadBytes - 4 * spreadingFactor + 28 + 16 * crc - headerBytes;
|
||||
@@ -831,7 +866,6 @@ int calculateMessageTimeout({
|
||||
spreadingFactor: sf,
|
||||
bandwidthHz: bwHz,
|
||||
codingRate: cr,
|
||||
lowDataRateOptimize: sf >= 11,
|
||||
);
|
||||
|
||||
if (pathLength < 0) {
|
||||
@@ -1004,6 +1038,7 @@ Uint8List buildSetAutoAddConfigFrame({
|
||||
required bool autoAddRoomServer,
|
||||
required bool autoAddSensor,
|
||||
required bool overwriteOldest,
|
||||
int? maxHops,
|
||||
}) {
|
||||
final writer = BufferWriter();
|
||||
writer.writeByte(cmdSetAutoAddConfig);
|
||||
@@ -1014,6 +1049,8 @@ Uint8List buildSetAutoAddConfigFrame({
|
||||
if (autoAddSensor) flags |= autoAddSensorFlag;
|
||||
if (overwriteOldest) flags |= autoAddOverwriteOldestFlag;
|
||||
writer.writeByte(flags);
|
||||
// Optional autoadd_max_hops (firmware keeps its value when omitted).
|
||||
if (maxHops != null) writer.writeByte(maxHops.clamp(0, 64).toInt());
|
||||
return writer.toBytes();
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user