diff --git a/documentation/ota-updates.md b/documentation/ota-updates.md index efc928b3..e1d6335c 100644 --- a/documentation/ota-updates.md +++ b/documentation/ota-updates.md @@ -23,7 +23,10 @@ update stops with "not an -ota build". (`fw ver`, `fw status`) and takes the matching delta from the **latest release** on git.rfa.cz, checked against the release's `SHA256SUMS`. *Choose .mcfw files* is for your own builds (signed with your own key). -4. **Update**. Keep the app open until the log ends with `applied`; about +4. **Check** (optional) only finds out: it shows the node's `ver` and either + "up to date … no update needed" or "update available" with the delta + size. A login and three or four CLI replies on air, no chunks. +5. **Update**. Keep the app open until the log ends with `applied`; about 2–3 minutes on a direct link, a minute of it waiting for the reboot. A second run against an updated node ends with "the node already runs …". diff --git a/lib/screens/repeater_ota_screen.dart b/lib/screens/repeater_ota_screen.dart index 6fb2b4b3..49c5869c 100644 --- a/lib/screens/repeater_ota_screen.dart +++ b/lib/screens/repeater_ota_screen.dart @@ -96,7 +96,7 @@ class _RepeaterOtaScreenState extends State { if (skipped.isNotEmpty) _addLog('not OTA packages: ${skipped.join(', ')}'); } - Future _start() async { + Future _start({bool checkOnly = false}) async { if (!ensureRadioConnected(context)) return; final duty = double.tryParse(_duty.text.replaceAll(',', '.')); final gap = double.tryParse(_gap.text.replaceAll(',', '.')); @@ -130,6 +130,7 @@ class _RepeaterOtaScreenState extends State { side: side, window: window ?? 15, apply: _apply, + checkOnly: checkOnly, ); setState(() { _transfer = transfer; @@ -139,12 +140,19 @@ class _RepeaterOtaScreenState extends State { String outcome; try { final r = await transfer.run(); + final release = r.tag ?? 'this release'; outcome = switch (r.state) { OtaState.applied => 'applied: ${r.versionAfter ?? r.package?.version}', OtaState.staged => 'staged ${r.package?.name} (not applied)', - OtaState.current => 'the node already runs this release', + OtaState.current => + 'up to date: the node already runs $release, no update needed', + OtaState.available => + 'update available: $release, delta ${r.package?.data.length} B', OtaState.noPackage => 'no delta fits the node\'s image', }; + if (r.versionBefore != null) { + outcome = 'node: ${r.versionBefore}\n$outcome'; + } outcome += ', airtime ${r.airtime.toStringAsFixed(1)} s'; } on OtaCancelled { outcome = 'cancelled (the node keeps what it got until the next begin)'; @@ -320,6 +328,14 @@ class _RepeaterOtaScreenState extends State { padding: const EdgeInsets.fromLTRB(16, 12, 16, 0), child: Row( children: [ + OutlinedButton.icon( + onPressed: _running + ? null + : () => _start(checkOnly: true), + icon: const Icon(Icons.manage_search), + label: const Text('Check'), + ), + const SizedBox(width: 12), Expanded( child: FilledButton.icon( onPressed: _running ? null : _start, diff --git a/lib/services/ota/ota_transfer.dart b/lib/services/ota/ota_transfer.dart index 0571b23d..8ec1bd9d 100644 --- a/lib/services/ota/ota_transfer.dart +++ b/lib/services/ota/ota_transfer.dart @@ -40,12 +40,23 @@ class OtaCancelled extends OtaError { OtaCancelled() : super('cancelled'); } -enum OtaState { current, noPackage, staged, applied } +/// [available]: only with [OtaTransfer.checkOnly] -- a delta for the node's +/// image exists, nothing was sent. +enum OtaState { current, available, noPackage, staged, applied } class OtaResult { - OtaResult(this.state, {this.package, this.versionAfter, this.airtime = 0}); + OtaResult( + this.state, { + this.package, + this.tag, + this.versionBefore, + this.versionAfter, + this.airtime = 0, + }); final OtaState state; final OtaPackage? package; + final String? tag; // the release, when the package came from one + final String? versionBefore; // `ver`, with checkOnly final String? versionAfter; final double airtime; } @@ -68,6 +79,7 @@ class OtaTransfer { this.apply = true, this.applyWait = const Duration(seconds: 60), this.release, + this.checkOnly = false, }) : _bucket = OtaBucket(duty); final MeshCoreConnector connector; @@ -87,6 +99,10 @@ class OtaTransfer { /// latest public release). final OtaRelease? release; + /// Only find out whether an update exists: login, `ver`, `fw status`, the + /// release lookup -- and stop before `fw begin`. + final bool checkOnly; + final OtaBucket _bucket; late final RepeaterCommandService _cli = RepeaterCommandService(connector); StreamSubscription? _frames; @@ -540,6 +556,7 @@ class OtaTransfer { }); try { await _login(); + final before = checkOnly ? await _ask('ver') : null; final status = await _ask('fw status'); var base = otaParseStatus(status)?.$2; if (base == null && status.startsWith('>')) { @@ -548,14 +565,23 @@ class OtaTransfer { } if (base == null) { log('no base image: not an -ota build'); - return OtaResult(OtaState.noPackage, airtime: airtime); + return OtaResult( + OtaState.noPackage, + versionBefore: before, + airtime: airtime, + ); } var pkgs = packages; + String? tag; if (pkgs.isEmpty) { final target = otaParseTarget(await _ask('fw ver')); if (target == null) { log('`fw ver` names no target: not an -ota build'); - return OtaResult(OtaState.noPackage, airtime: airtime); + return OtaResult( + OtaState.noPackage, + versionBefore: before, + airtime: airtime, + ); } log('looking for $target from $base in the latest release'); final OtaReleaseMatch m; @@ -566,15 +592,26 @@ class OtaTransfer { } catch (e) { throw OtaError('release: cannot download ($e)'); } + tag = m.tag; if (m.current) { log('the node already runs ${m.tag}'); - return OtaResult(OtaState.current, airtime: airtime); + return OtaResult( + OtaState.current, + tag: tag, + versionBefore: before, + airtime: airtime, + ); } if (m.package == null) { log( '${m.tag} has no delta from $base (too old: a full image over USB/BLE)', ); - return OtaResult(OtaState.noPackage, airtime: airtime); + return OtaResult( + OtaState.noPackage, + tag: tag, + versionBefore: before, + airtime: airtime, + ); } log('${m.tag}: ${m.package!.name}, sha256 ok'); pkgs = [m.package!]; @@ -585,6 +622,8 @@ class OtaTransfer { return OtaResult( OtaState.current, package: pick.package, + tag: tag, + versionBefore: before, airtime: airtime, ); } @@ -592,11 +631,25 @@ class OtaTransfer { log( 'no delta starts from $base (a full image does not go over the mesh)', ); - return OtaResult(OtaState.noPackage, airtime: airtime); + return OtaResult( + OtaState.noPackage, + tag: tag, + versionBefore: before, + airtime: airtime, + ); } final pkg = pick.package!; final data = pkg.data; log('package ${pkg.name} (delta, ${data.length} B)'); + if (checkOnly) { + return OtaResult( + OtaState.available, + package: pkg, + tag: tag, + versionBefore: before, + airtime: airtime, + ); + } if (side != null) await _enterSide(); final sid = 1 + math.Random().nextInt(0xFFFF);