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
@@ -11,9 +11,7 @@ import '../connector/meshcore_protocol.dart';
|
||||
/// do the same so the repeater always gets the phone's time.
|
||||
String normalizeRepeaterClockSyncCommand(String command, {int? nowSeconds}) {
|
||||
final epoch = nowSeconds ?? DateTime.now().millisecondsSinceEpoch ~/ 1000;
|
||||
return command.trim().toLowerCase() == 'clock sync'
|
||||
? 'time $epoch'
|
||||
: command;
|
||||
return command.trim().toLowerCase() == 'clock sync' ? 'time $epoch' : command;
|
||||
}
|
||||
|
||||
class RepeaterCommandService {
|
||||
@@ -25,19 +23,22 @@ class RepeaterCommandService {
|
||||
int _prefixCounter = 0;
|
||||
|
||||
static const int maxRetries = 5;
|
||||
static final RegExp _prefixPattern = RegExp(r'^[0-9A-Fa-f]{2}\|');
|
||||
|
||||
RepeaterCommandService(this._connector);
|
||||
|
||||
/// Send a CLI command to a repeater with automatic retries
|
||||
/// Returns a future that completes when a response is received or after max retries
|
||||
/// Returns a future that completes when a response is received or after max retries.
|
||||
/// With [raw], the command is sent verbatim without the `XX|` reply prefix.
|
||||
Future<String> sendCommand(
|
||||
Contact repeater,
|
||||
String command, {
|
||||
Function(String)? onResponse,
|
||||
Function(int)? onAttempt,
|
||||
int retries = maxRetries,
|
||||
bool raw = false,
|
||||
}) async {
|
||||
command = normalizeRepeaterClockSyncCommand(command);
|
||||
if (!raw) command = normalizeRepeaterClockSyncCommand(command);
|
||||
final attemptCount = retries < 1 ? 1 : retries;
|
||||
final selection = await _connector.preparePathForContactSend(repeater);
|
||||
|
||||
@@ -49,6 +50,7 @@ class RepeaterCommandService {
|
||||
command,
|
||||
selection,
|
||||
attempt,
|
||||
raw,
|
||||
);
|
||||
onResponse?.call(response);
|
||||
return response;
|
||||
@@ -65,6 +67,7 @@ class RepeaterCommandService {
|
||||
String command,
|
||||
PathSelection selection,
|
||||
int attempt,
|
||||
bool raw,
|
||||
) async {
|
||||
final repeaterKey = repeater.publicKeyHex;
|
||||
final prefix = _nextPrefixToken();
|
||||
@@ -75,7 +78,7 @@ class RepeaterCommandService {
|
||||
_pendingByPrefix[prefix] = commandId;
|
||||
|
||||
try {
|
||||
final framedCommand = '$prefix$command';
|
||||
final framedCommand = raw ? command : '$prefix$command';
|
||||
final pathLengthValue = selection.useFlood ? -1 : selection.hopCount;
|
||||
final timestampSeconds = DateTime.now().millisecondsSinceEpoch ~/ 1000;
|
||||
_connector.trackRepeaterAck(
|
||||
@@ -125,6 +128,15 @@ class RepeaterCommandService {
|
||||
}
|
||||
}
|
||||
|
||||
/// Send [line] verbatim and don't wait for a reply. While `region load` is
|
||||
/// active the firmware consumes each line before prefix stripping and
|
||||
/// sends nothing back (simple_repeater/MyMesh.cpp handleCommand).
|
||||
Future<void> sendUnansweredLine(Contact repeater, String line) {
|
||||
return _connector.sendFrame(
|
||||
buildSendCliCommandFrame(repeater.publicKey, line),
|
||||
);
|
||||
}
|
||||
|
||||
/// Call this when a text message response is received from a repeater
|
||||
void handleResponse(Contact repeater, String responseText) {
|
||||
// Find pending command for this repeater and complete it
|
||||
@@ -132,14 +144,17 @@ class RepeaterCommandService {
|
||||
|
||||
String? commandId;
|
||||
String responsePayload = responseText;
|
||||
if (responseText.length >= 3 && responseText[2] == '|') {
|
||||
final prefix = responseText.substring(0, 3);
|
||||
if (_prefixPattern.hasMatch(responseText)) {
|
||||
final prefix = responseText.substring(0, 3).toUpperCase();
|
||||
commandId = _pendingByPrefix[prefix];
|
||||
if (commandId == null || !commandId.startsWith('${repeaterKey}_')) {
|
||||
return;
|
||||
}
|
||||
responsePayload = responseText.substring(3).trimLeft();
|
||||
}
|
||||
|
||||
commandId ??= _pendingCommands.keys.firstWhere(
|
||||
(id) => id.startsWith(repeaterKey),
|
||||
(id) => id.startsWith('${repeaterKey}_'),
|
||||
orElse: () => '',
|
||||
);
|
||||
|
||||
|
||||
Reference in new issue
Block a user