From ed96ffa3e883c2637f6eabd201974608aae60dd7 Mon Sep 17 00:00:00 2001 From: diffwireauto <330573775+diffwireauto@users.noreply.github.com> Date: Sun, 25 Oct 2026 17:14:09 -0400 Subject: [PATCH] fix(#970): act on the adversarial review, cite the merged firmware No preview is sent while a slot transfer runs, so neither can take the other's refusal. A final SLOT_SET reply that is not 0 is no longer read as a commit. Back during a read or save now says why it is held. Comments now cite meshcore-firmware f3d30a88 on firmware-base, which merged 3e788e2a with the contract files unchanged. The wider attribution fix is #991. Co-Authored-By: Claude Opus 5.5 --- lib/connector/meshcore_connector.dart | 11 +++++++++ lib/connector/meshcore_protocol.dart | 2 +- lib/connector/offband_screen_settings.dart | 2 +- lib/connector/offband_tones.dart | 4 ++-- lib/models/badge_time_zones.dart | 2 +- .../settings/tune_slot_editor_screen.dart | 10 +++++++- test/connector/offband_device_ui_test.dart | 2 +- .../offband_screen_settings_test.dart | 2 +- test/connector/offband_tones_test.dart | 2 +- test/connector/tunes_connector_test.dart | 23 +++++++++++++++++++ 10 files changed, 51 insertions(+), 9 deletions(-) diff --git a/lib/connector/meshcore_connector.dart b/lib/connector/meshcore_connector.dart index 04b4d6fe..e8315818 100644 --- a/lib/connector/meshcore_connector.dart +++ b/lib/connector/meshcore_connector.dart @@ -1225,6 +1225,9 @@ class MeshCoreConnector extends ChangeNotifier { /// refused the id (the refusal is then shown like any other). Future playTune(int tuneId) async { if (!_deviceUiGateOpen('play', advertised: supportsTunes)) return null; + // A refusal names no sub-code, so a preview sent mid-transfer could take + // the transfer's refusal, or hand it one. + if (_tuneSlotTransferActive) return null; _appDebugLogService?.info('play -> $tuneId [0xC5][0x11]', tag: 'DeviceUI'); final reply = await _sendDeviceUiAndAwait( buildTunePlayFrame(tuneId), @@ -1388,6 +1391,14 @@ class MeshCoreConnector extends ChangeNotifier { if (more && reply.slotAccepted!.accepted != end) { return _SlotPush.displaced; } + // A commit answers 0. Anything else is not a commit, whatever it is. + if (!more && reply.slotAccepted!.accepted != 0) { + _setDeviceUiError( + DeviceUiSurface.tuneSlot, + 'The radio did not confirm saving this tune. Nothing was changed.', + ); + return _SlotPush.failed; + } offset = end; onProgress?.call(offset, bytes.length); } while (offset < bytes.length); diff --git a/lib/connector/meshcore_protocol.dart b/lib/connector/meshcore_protocol.dart index c8526bf2..40074fd7 100644 --- a/lib/connector/meshcore_protocol.dart +++ b/lib/connector/meshcore_protocol.dart @@ -606,7 +606,7 @@ bool firmwareSupportsNotifyScope(int? offbandCaps2) => /// 0x12), channel tune (0x0B, 0x0C), event tones (0x0F, 0x10) and preview /// (0x11). Firmware sets it where the UI plays every sound through its tune /// engine, which needs a buzzer but is not implied by one, so a radio can -/// advertise the scope bit without this (meshcore-firmware `3e788e2a`). +/// advertise the scope bit without this (meshcore-firmware `f3d30a88`). const int offbandCap2Tunes = 0x10; /// GPS mode and Power-save interval over `0xC5` sub-codes 0x0D / 0x0E (#969). diff --git a/lib/connector/offband_screen_settings.dart b/lib/connector/offband_screen_settings.dart index d0e7de8e..059f964b 100644 --- a/lib/connector/offband_screen_settings.dart +++ b/lib/connector/offband_screen_settings.dart @@ -4,7 +4,7 @@ import 'offband_device_ui.dart'; /// The badge's own display and battery settings over `0xC5` (#987): both /// text sizes, Screen off, time zone and the battery full point. Gated on caps -/// byte 2 `0x40` SCREEN_SETTINGS (meshcore-firmware `3e788e2a`). +/// byte 2 `0x40` SCREEN_SETTINGS (meshcore-firmware `f3d30a88`). /// /// Every reply, GET or SET, is the whole set re-read after the write: /// `[0xC5][sub][nav][msg][scr_stored:2][scr_secs:2][tz][batt_stored:2] diff --git a/lib/connector/offband_tones.dart b/lib/connector/offband_tones.dart index 901ba69a..de5b6c6c 100644 --- a/lib/connector/offband_tones.dart +++ b/lib/connector/offband_tones.dart @@ -5,7 +5,7 @@ import 'offband_device_ui.dart'; /// The radio's tune system over `0xC5` (#970, #971, #986): the built-in tune /// table, the eight custom RTTTL slots, the six event tones and preview. /// -/// Gated on caps byte 2 `0x10` TUNES (meshcore-firmware `3e788e2a`). The +/// Gated on caps byte 2 `0x10` TUNES (meshcore-firmware `f3d30a88`). The /// contract lives in firmware's `OffbandConfigProtocol.h`; the tables and the /// validator below are ports of `Tunes.h` and `TuneSlots.h` at that commit. @@ -336,7 +336,7 @@ bool _isDefaultsSep(int c) => c == 0x2C || c == 0x3A; const int _colon = 0x3A; -/// Port of firmware `rtttlProblem()` (`Tunes.h`, `3e788e2a`), step for step. +/// Port of firmware `rtttlProblem()` (`Tunes.h`, `f3d30a88`), step for step. RtttlProblem rtttlProblem(String rtttl) { final s = rtttl.codeUnits; if (s.isEmpty) return RtttlProblem.empty; diff --git a/lib/models/badge_time_zones.dart b/lib/models/badge_time_zones.dart index 320f6d14..ee494e14 100644 --- a/lib/models/badge_time_zones.dart +++ b/lib/models/badge_time_zones.dart @@ -1,5 +1,5 @@ /// The badge's time zone table, a copy of firmware `src/helpers/TimeZones.h` -/// at meshcore-firmware `3e788e2a` (#987). +/// on meshcore-firmware `firmware-base` at `f3d30a88` (#987). /// /// The radio stores a zone as an index into this list, so the order is the /// contract. Firmware keeps it append-only ("Append only; never reorder"), so diff --git a/lib/screens/settings/tune_slot_editor_screen.dart b/lib/screens/settings/tune_slot_editor_screen.dart index aa3bfe6e..fcc6dd97 100644 --- a/lib/screens/settings/tune_slot_editor_screen.dart +++ b/lib/screens/settings/tune_slot_editor_screen.dart @@ -202,7 +202,15 @@ class _TuneSlotEditorScreenState extends State { // halfway, and the radio would keep the old tune. canPop: !_dirty && !_busy, onPopInvokedWithResult: (didPop, _) async { - if (didPop || _busy) return; + if (didPop) return; + if (_busy) { + ScaffoldMessenger.of(context).showSnackBar( + const SnackBar( + content: Text('Wait for the radio to finish, then go back.'), + ), + ); + return; + } final navigator = Navigator.of(context); if (await _confirmDiscard()) navigator.pop(); }, diff --git a/test/connector/offband_device_ui_test.dart b/test/connector/offband_device_ui_test.dart index 81d91d01..61c0443f 100644 --- a/test/connector/offband_device_ui_test.dart +++ b/test/connector/offband_device_ui_test.dart @@ -212,7 +212,7 @@ void main() { test('the new bits collide with no allocated caps-byte-2 bit', () { // Firmware allocates 0x01 scope, 0x02 matrix, 0x04 indicators, 0x08 // packet hash (OffbandConfigProtocol.h on firmware-base), and - // 3e788e2a adds 0x10 TUNES, 0x20 GPS mode, 0x40 SCREEN_SETTINGS. + // f3d30a88 adds 0x10 TUNES, 0x20 GPS mode, 0x40 SCREEN_SETTINGS. const allocated = 0x01 | 0x02 | 0x04 | 0x08; const added = [ offbandCap2Tunes, diff --git a/test/connector/offband_screen_settings_test.dart b/test/connector/offband_screen_settings_test.dart index 9074967f..fd1f97b6 100644 --- a/test/connector/offband_screen_settings_test.dart +++ b/test/connector/offband_screen_settings_test.dart @@ -1,5 +1,5 @@ // #987: the badge's screen and battery settings over 0xC5 0x13 to 0x17, and -// the time zone table, against meshcore-firmware 3e788e2a. +// the time zone table, against meshcore-firmware f3d30a88. import 'dart:typed_data'; diff --git a/test/connector/offband_tones_test.dart b/test/connector/offband_tones_test.dart index 535c5510..91946a39 100644 --- a/test/connector/offband_tones_test.dart +++ b/test/connector/offband_tones_test.dart @@ -1,5 +1,5 @@ // #970, #986: the tune codec over 0xC5, against the contract in -// meshcore-firmware 3e788e2a OffbandConfigProtocol.h, and the ports of its +// meshcore-firmware f3d30a88 OffbandConfigProtocol.h, and the ports of its // RTTTL validator and slot-name rule. import 'dart:typed_data'; diff --git a/test/connector/tunes_connector_test.dart b/test/connector/tunes_connector_test.dart index 354eaf29..25e94578 100644 --- a/test/connector/tunes_connector_test.dart +++ b/test/connector/tunes_connector_test.dart @@ -277,6 +277,29 @@ void main() { expect(sent.first, equals([0xC5, 0x0A, 3, 0, 0])); }); + test('a final reply that is not 0 is not a commit', () async { + connector.handleFrameForTest(deviceInfo(caps2: 0x10)); + radio = (f) => f[1] == 0x0A + ? [ + [0xC5, 0x0A, f[2], 5], + ] + : const []; + expect(await connector.saveTuneSlot(0, 'x:d=4:c'), isFalse); + expect(connector.deviceUiErrorSurface, DeviceUiSurface.tuneSlot); + }); + + test('no preview is sent while a slot transfer is running', () async { + connector.handleFrameForTest(deviceInfo(caps2: 0x10)); + sent.clear(); + final read = connector.readTuneSlot(0); + await Future.delayed(Duration.zero); + expect(connector.tuneSlotTransferActive, isTrue); + expect(await connector.playTune(3), isNull); + expect(sentSub({0x11}), isFalse); + connector.handleFrameForTest([0xC5, 0x12, 0, 0, 0]); + expect(await read, ''); + }); + test('a tune over 240 characters is never sent', () async { connector.handleFrameForTest(deviceInfo(caps2: 0x10)); sent.clear();