fix: use explicit time <epoch> for repeater clock sync
Companion firmware (MeshCore commit 4a869163, 2025-12-30) replaces the CLI frame timestamp with the companion node's RTC for TXT_TYPE_CLI_DATA, so "clock sync" sets the repeater clock to the node RTC. Nodes with a wrong RTC push repeater clocks years into the future; firmware cannot set the clock backwards without clkreboot. - RepeaterCommandService: translate "clock sync" to "time <phone epoch>" before sending, matching official meshcore-cli behavior - repeater login dialog: send "time <epoch>" for auto clock sync after login (this path bypasses RepeaterCommandService) - add unit tests for the command translation Ref: https://github.com/zjs81/meshcore-open/issues/464
This commit is contained in:
3 files changed
+61
-1
No files matched your search
@@ -4,6 +4,18 @@ import '../models/path_selection.dart';
|
|||||||
import '../connector/meshcore_connector.dart';
|
import '../connector/meshcore_connector.dart';
|
||||||
import '../connector/meshcore_protocol.dart';
|
import '../connector/meshcore_protocol.dart';
|
||||||
|
|
||||||
|
/// Companion firmware (MeshCore commit 4a869163, 2025-12-30) replaces the CLI
|
||||||
|
/// frame timestamp with the companion node's RTC for TXT_TYPE_CLI_DATA, so a
|
||||||
|
/// plain "clock sync" sets the repeater clock to the node clock. The official
|
||||||
|
/// meshcore-cli translates it to an explicit `time <epoch>` command instead;
|
||||||
|
/// 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;
|
||||||
|
}
|
||||||
|
|
||||||
class RepeaterCommandService {
|
class RepeaterCommandService {
|
||||||
final MeshCoreConnector _connector;
|
final MeshCoreConnector _connector;
|
||||||
final Map<String, Completer<String>> _pendingCommands = {};
|
final Map<String, Completer<String>> _pendingCommands = {};
|
||||||
@@ -25,6 +37,7 @@ class RepeaterCommandService {
|
|||||||
Function(int)? onAttempt,
|
Function(int)? onAttempt,
|
||||||
int retries = maxRetries,
|
int retries = maxRetries,
|
||||||
}) async {
|
}) async {
|
||||||
|
command = normalizeRepeaterClockSyncCommand(command);
|
||||||
final attemptCount = retries < 1 ? 1 : retries;
|
final attemptCount = retries < 1 ? 1 : retries;
|
||||||
final selection = await _connector.preparePathForContactSend(repeater);
|
final selection = await _connector.preparePathForContactSend(repeater);
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import '../l10n/l10n.dart';
|
|||||||
import '../models/contact.dart';
|
import '../models/contact.dart';
|
||||||
import '../l10n/contact_localization.dart';
|
import '../l10n/contact_localization.dart';
|
||||||
import '../services/storage_service.dart';
|
import '../services/storage_service.dart';
|
||||||
|
import '../services/repeater_command_service.dart';
|
||||||
import '../connector/meshcore_connector.dart';
|
import '../connector/meshcore_connector.dart';
|
||||||
import '../connector/meshcore_protocol.dart';
|
import '../connector/meshcore_protocol.dart';
|
||||||
import '../theme/mesh_theme.dart';
|
import '../theme/mesh_theme.dart';
|
||||||
@@ -201,7 +202,10 @@ class _RepeaterLoginDialogState extends State<RepeaterLoginDialog> {
|
|||||||
await _connector.sendFrame(
|
await _connector.sendFrame(
|
||||||
buildSendCliCommandFrame(
|
buildSendCliCommandFrame(
|
||||||
repeater.publicKey,
|
repeater.publicKey,
|
||||||
'clock sync',
|
normalizeRepeaterClockSyncCommand(
|
||||||
|
'clock sync',
|
||||||
|
nowSeconds: timestampSeconds,
|
||||||
|
),
|
||||||
timestampSeconds: timestampSeconds,
|
timestampSeconds: timestampSeconds,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -0,0 +1,43 @@
|
|||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:meshcore_open/services/repeater_command_service.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
group('normalizeRepeaterClockSyncCommand', () {
|
||||||
|
test('translates "clock sync" to explicit time command', () {
|
||||||
|
final result = normalizeRepeaterClockSyncCommand(
|
||||||
|
'clock sync',
|
||||||
|
nowSeconds: 1787900000,
|
||||||
|
);
|
||||||
|
expect(result, 'time 1787900000');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('is case-insensitive and tolerates surrounding whitespace', () {
|
||||||
|
expect(
|
||||||
|
normalizeRepeaterClockSyncCommand(' Clock Sync ', nowSeconds: 1),
|
||||||
|
'time 1',
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('passes other commands through unchanged', () {
|
||||||
|
expect(normalizeRepeaterClockSyncCommand('clock', nowSeconds: 1), 'clock');
|
||||||
|
expect(
|
||||||
|
normalizeRepeaterClockSyncCommand('get radio', nowSeconds: 1),
|
||||||
|
'get radio',
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
normalizeRepeaterClockSyncCommand('time 123', nowSeconds: 1),
|
||||||
|
'time 123',
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('uses current time when nowSeconds is omitted', () {
|
||||||
|
final before = DateTime.now().millisecondsSinceEpoch ~/ 1000;
|
||||||
|
final result = normalizeRepeaterClockSyncCommand('clock sync');
|
||||||
|
final after = DateTime.now().millisecondsSinceEpoch ~/ 1000;
|
||||||
|
|
||||||
|
expect(result, startsWith('time '));
|
||||||
|
final epoch = int.parse(result.substring('time '.length));
|
||||||
|
expect(epoch, inInclusiveRange(before, after));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
Reference in new issue
Block a user