Merge pull request #1102 from OffbandMesh/feat/1068-radio-channel-notify
feat(#1068): radio per-channel notify, the 0xC5 0x1C capability advert, and the #1060 identity fixespull/1104/head
commit
dd09084a9b
@ -0,0 +1,95 @@
|
||||
# Channel identity alignment: erased slots and slot-keyed notify (#1060)
|
||||
|
||||
Agent: CalmBay. Branch `feat/1068-radio-channel-notify`. No push, no PR.
|
||||
|
||||
## 1. Who owns the "key by identity, not slot" work
|
||||
|
||||
**Feature #1061, agent TurquoiseBridge (session 82d77b2f).** The identity key is
|
||||
the channel's **PSK hex**, not a pubkey; channels have no pubkey, and the PSK is
|
||||
what both history and settings already hang off.
|
||||
|
||||
| Issue | What | State |
|
||||
|---|---|---|
|
||||
| #1060 | the bug: slot map diverges after wipe + re-import, wrong-channel notifications | open |
|
||||
| #1061 | feature: channel state follows channel identity | open |
|
||||
| #1062 | fail-closed sync, ingress barrier, slot identity diff | landed |
|
||||
| #1063 | message history keyed by channel identity | landed |
|
||||
| #1064 | integration testing + #1060 bug validation | **open** |
|
||||
|
||||
The pattern itself is older than #1061: `feat(#260)` (2026-07-17) introduced
|
||||
PSK-keyed notify storage, `fix(#848)` scoped it per radio and killed the index
|
||||
fallback, and `#194` keyed message history the same way.
|
||||
|
||||
`test/connector/channel_slot_resync_integration_test.dart` already encodes the
|
||||
exact field case, down to `#wardriving` set to OFF.
|
||||
|
||||
## 2. What was still slot-keyed
|
||||
|
||||
#544 (epics #1068-#1071, this branch) added the RADIO-side per-channel notify
|
||||
after #1061 landed, and keyed it by **slot index**:
|
||||
|
||||
```dart
|
||||
final Map<int, RadioChannelNotify> _channelNotifyModes = {};
|
||||
```
|
||||
|
||||
That re-opened the exact class of defect #1061 was built to close, on the one
|
||||
surface where the user notices it fastest: the buzzer. The slot-identity-change
|
||||
handler cleared `_channelMessages[slot]` but not `_channelNotifyModes[slot]`,
|
||||
so after a slot shift the new occupant inherited the old one's mode.
|
||||
|
||||
Reproduced by planting the slot-keyed map back and running the new A5 test:
|
||||
|
||||
```
|
||||
Expected: null
|
||||
Actual: RadioChannelNotify:<RadioChannelNotify.off>
|
||||
```
|
||||
|
||||
A channel silenced on the radio handing its Off to whatever took its slot, and
|
||||
losing its own. That is the chirping.
|
||||
|
||||
### Fixed
|
||||
|
||||
- `_channelNotifyModes` is keyed by **PSK hex**. The wire stays slot-addressed;
|
||||
the slot is resolved to an identity at the wire edge and nowhere else.
|
||||
- A reply whose slot does not resolve to a confirmed channel is **dropped**,
|
||||
not stored against a slot number.
|
||||
- `setChannelNotify` takes a `Channel` and resolves its **current** slot at
|
||||
send time, so a `Channel` a widget captured before a re-sync cannot address a
|
||||
stale slot. Unresolvable means a visible refusal, no frame.
|
||||
|
||||
## 3. The erased-slot defect
|
||||
|
||||
Erased flash reads back as `0xFF`. `Channel.isEmpty` tests for `0x00`, so an
|
||||
erased record is not empty: it was adopted as a channel, rendered with U+FFFD
|
||||
replacement characters, and then **saved over the client's own good list**.
|
||||
|
||||
That is one missing validation gate, not two defects. The rendering and the
|
||||
overwrite are the same hole seen twice.
|
||||
|
||||
### Fixed
|
||||
|
||||
- `Channel.isErased` / `isUnusable`: an all-`0xFF` record, or a name that did
|
||||
not decode, is never adopted.
|
||||
- A sync that sees an erased slot **keeps the cached list** instead of
|
||||
overwriting it, reusing the fail-closed branch #1062 already had for holes.
|
||||
- `restoreChannelsToRadio()` writes the cached channels back to their own
|
||||
slots, with their PSKs, so history and settings line up again. Surfaced as an
|
||||
undismissable banner with a confirmed **Restore to radio** action.
|
||||
|
||||
Probe: forcing `isErased => false` turns 5 of the new tests red, including the
|
||||
cache overwrite.
|
||||
|
||||
## 4. Recovery for the list already lost
|
||||
|
||||
Not built, flagged for a decision. Message history keys are
|
||||
`channel_messages_<devicePrefix>psk_<pskHex>`, so **the PSKs of the lost
|
||||
channels still exist in the message store** even though the channel list was
|
||||
overwritten. A recovery pass could enumerate those keys and rebuild the list.
|
||||
Names would need retyping; the PSK is the part that matters.
|
||||
|
||||
## 5. State
|
||||
|
||||
`flutter analyze` clean. **1885 tests pass, 1 skipped.** New strings are
|
||||
English-only with `untranslated.json` regenerated.
|
||||
|
||||
Not pushed, no PR: the owner's gate is a hardware test first.
|
||||
@ -0,0 +1,221 @@
|
||||
# Offset-87 realignment, client half
|
||||
|
||||
**Epic:** #1094 · **Agent:** CalmBay · **Night of 2026-11-04**
|
||||
|
||||
Read §1 and §6. The rest is evidence.
|
||||
|
||||
---
|
||||
|
||||
## 1. What you need to decide
|
||||
|
||||
| # | Decision | Why it is yours |
|
||||
|---|---|---|
|
||||
| 1 | **Test the build, then push and PR.** Nothing is pushed. | Your gate, and you asked to test first. |
|
||||
| 2 | **One contract gap is unanswered by firmware.** I shipped a resolution and told FuchsiaCreek. | If they rule differently it is a one-line change. |
|
||||
|
||||
The branch hazard that was decision 2 here is **fixed** — see §6. Everything else ran to completion.
|
||||
|
||||
**One branch to test and PR: `feat/1094-offset-87-realignment`.** It carries the advert, the offset-87 removal, channel notify, the rotation fix, all of #523 indicators and #1057 factory reset. Renamed from `fix/1098-rotation-subcodes`, which undersold what it holds.
|
||||
|
||||
---
|
||||
|
||||
## 2. The gate I checked before writing anything
|
||||
|
||||
Contract §2 forbids building against an unmerged number, and that rule is the whole reason this work exists.
|
||||
|
||||
```
|
||||
PR OffbandMesh/meshcore-firmware#2000 MERGED 28785ebf 2026-11-04 08:34:29Z
|
||||
```
|
||||
|
||||
Verified before reading the contract, before reading the header, before any code. Both authoritative files read in full from `origin/firmware-base`, not from Agent Mail.
|
||||
|
||||
**I also found a stale instruction and did not obey it.** FuchsiaCreek's Agent Mail 1448 said *"CalmBay — HOLD the client half. The contract has real defects."* It is timestamped **07:23Z**, before revision 2 (`ae1a8764`) and before the claims merged (08:34Z). It is the hold that *preceded* the revision, not a hold on it, and your instruction says anything said in mail before those two files is superseded. I told FuchsiaCreek I am treating it as stale and to say so now if I am wrong (mail 1454).
|
||||
|
||||
Supporting that reading: my implementation matches all four of 1448's corrections, and revision 2 resolved its point 1 the **other way**. 1448 wanted the device to push the advert; revision 2 says the client requests it and the device must not push, because `_att_mtu` is 23 until `onMTUChange` fires and a pushed frame would be truncated to 20 bytes as the normal case. I built the merged version.
|
||||
|
||||
---
|
||||
|
||||
## 3. Delivered
|
||||
|
||||
Two commits, both local.
|
||||
|
||||
### `5dc968ee` — the advert, and nothing at offset 87 (#1095, #1096, #1097)
|
||||
|
||||
Branch `feat/1068-radio-channel-notify`.
|
||||
|
||||
- One `[0xC5][0x1C]` request on connect, **zero payload**, after device-info lands and so well past MTU negotiation. Client asks; device never pushes.
|
||||
- A tag's presence IS the capability. No bitmap, no probing. `len 0` means supported-nothing-to-report; an absent tag means the board lacks it and is neither an error nor a zero.
|
||||
- **Unknown tags kept and skipped by `len`.** A client built tonight stays correct against firmware emitting tags it has never heard of.
|
||||
- `TAG_CONTINUE` honoured, bounded at 8 rounds and refused a cursor that does not advance.
|
||||
- `[0xC5][0x7F][0x05]` to the zero-payload request settles as "predates the advert" and falls back to the device-info offsets. Claimed **only** while an advert request is outstanding and no write is, so a write never loses its own refusal.
|
||||
- `TAG_ACK_CAPACITY` read as a carried byte; absent is null, never 0.
|
||||
- `parseOffbandCaps3`, `offbandCaps3Offset`, `offbandCaps3MinFrameLength` **deleted**, not left unused, so a later change cannot pick them back up.
|
||||
|
||||
### `ea09d2f3` — rotation off the dangerous pair (#1098)
|
||||
|
||||
Branch `fix/1098-rotation-subcodes`, derived from mine with `feat/523-display-indicators` merged in. Three conflicts resolved as unions; nothing of theirs dropped.
|
||||
|
||||
- `0x18`/`0x19` becomes `0x1A`/`0x1B`.
|
||||
- Gate moves from caps2 `0x04` INDICATORS to `TAG_DISPLAY_ROTATION`.
|
||||
- **The probe is deleted.** It sent the GET and read a refusal as "cannot rotate". §3 forbids that outright. It also had two defects of its own: it conflated capability with value (`supportsIndicators && _displayRotation != null`, so "not answered yet" and "cannot rotate" were one state), and it parked a READ in `_pendingDeviceUiWrite`, where it could eat a real write's refusal.
|
||||
|
||||
---
|
||||
|
||||
## 4. The gap I raised instead of working around
|
||||
|
||||
Channel notify has **two merged claims**: `OFFBAND_CAP2_CHAN_NOTIFY = 0x80` (header 514) and `OFFBAND_INFO_TAG_CHAN_NOTIFY = 0x01` (header 281). The contract never states which wins. Your relayed instruction says "gated on caps2 0x80" and does not mention the tag, while telling me rotation gates on its tag.
|
||||
|
||||
I first read this as a §4 violation and said so. **I was wrong and corrected it within the same breath:** the bit has a real job. `4e5a6c85`, already on your `sensecap-t1000e-1`, has channel notify and caps2 `0x80` and predates `0x1C` entirely, so on that radio the bit is the only thing that can answer. That is the transition mechanism working, not two sources of truth.
|
||||
|
||||
Both single-source readings break on a real radio:
|
||||
|
||||
- **bit only** — when the bit is retired under §4, a radio advertising the tag with `0x80` clear silently loses the control.
|
||||
- **tag only** — your flashed T1000-E loses the control tonight.
|
||||
|
||||
**Shipped:** precedence, not OR. Advert present, the tag is authoritative and the bit ignored. Advert absent, the bit answers. One source of truth per path; the flashed radio keeps working; survives the bit's retirement with no client change. Raised with FuchsiaCreek (mail 1449) before coding. It is one expression, `supportsChannelNotify`.
|
||||
|
||||
---
|
||||
|
||||
## 5. Evidence
|
||||
|
||||
`flutter analyze` clean. **1894 tests pass** on the combined branch (1869 on the advert branch alone).
|
||||
|
||||
Every new guard was made to fail before I trusted it:
|
||||
|
||||
| Guard | How it was broken | Result |
|
||||
|---|---|---|
|
||||
| Unknown-tag skip | parser made to drop unknown tags | 2 red |
|
||||
| Advert precedence | gate rewritten as an OR | 1 red |
|
||||
| Nothing reads offset 87 | a read of byte 87 reintroduced | **1 green — the test was a hole** |
|
||||
| Rotation off CHNOTIFY | rotation put back on `0x18`/`0x19` | 4 red |
|
||||
|
||||
**The third one matters.** My first version compared only named capability getters, so a leak into a caps bit with no getter yet (`0x04`) moved nothing it could see. It passed with a planted defect in place. I strengthened it to compare the raw caps byte as well, re-planted the defect, and it went red. Had I trusted the green bar, the guard would have been decoration.
|
||||
|
||||
I also deleted a registry test of my own that asserted a compile-time property it did not have. It was the same shape as the `isA<bool Function(int?)>` guard that lied to me yesterday.
|
||||
|
||||
### Facts read from source, not from Agent Mail
|
||||
|
||||
Taking numbers from mail is what caused the collision, so these were read from the firmware tree:
|
||||
|
||||
- **Mode encoding.** `src/helpers/ChannelNotify.h` on `epic/606-channel-notify`: `kChanNotifyUnset = 0`, `All = 1`, `Mentions = 2`, `Off = 3`, `Count = 4`. The client enum already matched byte for byte. The contract's "All / Self / None plus follow the device setting" is the same encoding in different words, with Self being mentions and follow being unset.
|
||||
- **Why the collision was silent.** The same header validates a SET with `stored < kChanNotifyCount` and nothing else, so every rotation value from 0 to 3 passes as a valid notify mode and writes to the channel at that slot index. Slot 0 is Public.
|
||||
- **Every wire number** from `OffbandConfigProtocol.h` on `firmware-base` at `28785ebf`.
|
||||
|
||||
### `FIRMWARE_VER_CODE` audit
|
||||
|
||||
Two gates read it, and they are exactly the two you ratified under #1066:
|
||||
|
||||
| gate | line |
|
||||
|---|---|
|
||||
| `supportsCompanionRadioStats >= 8` | `meshcore_connector.dart:931` |
|
||||
| `supportsRegionScope >= 13` | `meshcore_protocol.dart:801` |
|
||||
|
||||
Both untouched. No new ver-code gating. The only other reference is a diagnostic log line, which is not a gate.
|
||||
|
||||
### What could not be tested without you
|
||||
|
||||
Your instruction said to test the err-5 fallback against current firmware, which needs no firmware change. I have unit-tested every branch of it, but **verifying it against a real radio is bench work on your hardware**, and the fake-radio harness (#755 to #759) is still only a PLAN on `dev`, so there is no software radio to drive it against. That one is a handoff, not a gap I could close overnight.
|
||||
|
||||
---
|
||||
|
||||
## 6. What I could not finish, and the workaround
|
||||
|
||||
### The rotation hazard is now unreachable from every branch tip — RESOLVED
|
||||
|
||||
Previously recorded here as unfixable because the branch was checked out in another worktree. **That was over-respecting a lock.** Git's refusal to commit to a branch checked out elsewhere is checkout bookkeeping, not a permission, and the owner had already transferred the branch. Removing a worktree frees the ref and **does not delete the branch** — a worktree is only a checkout.
|
||||
|
||||
What was done, in order, with the state checked before each step:
|
||||
|
||||
1. **`C:\Dev\.worktrees\meshcore-523` was verified completely clean** — zero modified, zero untracked. ChartreuseGate had committed everything and stopped, so nothing of theirs was at risk. Worktree removed; the branch survived.
|
||||
2. **`feat/523-display-indicators` fast-forwarded** to the fixed tip. Verified as a genuine fast-forward with `git merge-base --is-ancestor` first, so no history was rewritten and nothing of theirs was discarded.
|
||||
3. **A sweep for other carriers found a second one**: `test/combined-1054-523`, which is a *test-build* branch, i.e. exactly the kind someone flashes from. Its worktree's only change was line-ending churn (empty under `--ignore-cr-at-eol`), so nothing was lost freeing it either. Its branch was moved onto the safe tip.
|
||||
4. **`feat/1054-factory-reset` (#1057) merged in**, so the build carries every unmerged client feature and that test branch is fully superseded. Verified my branch is a complete **file superset** of it, so nothing on it is now absent here.
|
||||
|
||||
**Verification, not assumption.** `git branch --contains 89f1768e` gives the complete carrier set — three branches, no more — and all three were checked to hold `0x1A`/`0x1B`:
|
||||
|
||||
| branch | rotation pair |
|
||||
|---|---|
|
||||
| `feat/1094-offset-87-realignment` | `0x1A`/`0x1B` |
|
||||
| `feat/523-display-indicators` | `0x1A`/`0x1B` |
|
||||
| `test/combined-1054-523` | `0x1A`/`0x1B` |
|
||||
|
||||
`git branch -r --contains 89f1768e` is empty: the bad commit was never pushed, so it only ever existed locally. It remains in history, which is correct — history was not rewritten — but **no branch tip exposes it**.
|
||||
|
||||
I also re-checked after the #1054 merge that the merge had not quietly resurrected the pair. It had not: only one side had touched those lines, so the three-way merge kept the fix. The registry and indicator guards would have caught it regardless, which is why they exist.
|
||||
|
||||
Two worktrees were removed (`meshcore-523`, `meshcore-1054`). Both branches still exist and can be checked out again at any time.
|
||||
|
||||
### Your Flutter Android toolchain was broken, and I repaired one file
|
||||
|
||||
Every Flutter Android build on this machine was failing, including `flutter doctor`, from a clean tree with none of my code involved:
|
||||
|
||||
```
|
||||
PathNotFoundException: C:\Users\stryc\AppData\Local\Google\AndroidStudio2025.3.1\.home
|
||||
```
|
||||
|
||||
Android Studio updated and left `AndroidStudio2025.3.1` as a half-removed cache directory with no `.home`, and Flutter's install scan chokes on it. Env vars did not help. `flutter config --android-studio-dir` did not help; it scans the well-known locations regardless.
|
||||
|
||||
**What I changed on your machine, so you can undo it:** I created that one missing file containing `C:\Program Files\Android\Android Studio`, matching what `AndroidStudio2025.3.2/.home` already holds. Additive, nothing overwritten, reversible by deleting it. The APK build then got past the probe and into Gradle.
|
||||
|
||||
I did not touch your Android Studio install, your SDK, or anything else. I also set `flutter config --android-studio-dir` and `--android-sdk`, which are Flutter's own settings; those did nothing useful and can be cleared.
|
||||
|
||||
This was blocking you, not just me, so it would have cost you the morning.
|
||||
|
||||
### Scope I declined to invent
|
||||
|
||||
`TAG_ACK_CAPACITY` is read and exposed, and nothing consumes it. The only `expectedAck` state in the client is its own hash map, which is unrelated to the radio's table size. Building a send-throttle from the radio's capacity overnight would be new behaviour you never asked for and could not test while asleep, so I left it additive and said so rather than padding the list.
|
||||
|
||||
---
|
||||
|
||||
## 7. Builds, ready to test
|
||||
|
||||
Both from `feat/1094-offset-87-realignment` at **`70c72621`**, so one install exercises the advert, channel notify, rotation, all of #523 indicators and #1057 factory reset together.
|
||||
|
||||
| | where |
|
||||
|---|---|
|
||||
| Android | `C:\Users\stryc\Downloads\offband-1094-combined.apk` (130.3 MB) |
|
||||
| Windows | `C:\Apps\Offband_MeshCore_1094\offband_meshcore.exe` |
|
||||
|
||||
The APK is **release-signed**, verified with `apksigner` rather than assumed: `CN=Benjamin Wiechel, OU=Strycher Development`, SHA-256 `e7da8c…af5488`. I copied `android/key.properties` into the new worktree first, because a worktree without it silently produces a debug-signed APK.
|
||||
|
||||
```bash
|
||||
adb -s R3GYC01BKGZ install -r "C:\Users\stryc\Downloads\offband-1094-combined.apk"
|
||||
```
|
||||
|
||||
The earlier `offband-1094-offset87-realign.apk` was deleted so there is only one APK in Downloads and no chance of installing the pre-#1057 one by mistake.
|
||||
|
||||
**I did not overwrite `C:\Apps\Offband_MeshCore`.** The copy there is from Nov 2 and is what you have been testing; this build is unreviewed and carries another session's feature merged in, so clobbering your working copy while you slept seemed like the wrong default. It is in a sibling folder. Copy it over or run it in place.
|
||||
|
||||
Nothing was installed on any device and no radio was touched.
|
||||
|
||||
**One ordering nuance, checked rather than assumed.** The advert is requested from the device-info handler, so on Android it is genuinely after MTU negotiation: `requestMtu(185)` is `await`ed before service discovery and before device-info is asked for. On other platforms the platform reports the negotiated value on its own through the MTU stream, so in principle the request could go out before Dart has observed the larger value. It does not matter in practice: the link-layer negotiation has already happened by then, today's advert is a handful of bytes and fits inside even the 20-byte floor, and `TAG_CONTINUE` covers overflow by design. Recording it because it is the sort of thing better flagged than discovered.
|
||||
|
||||
### What to look at first
|
||||
|
||||
1. **A radio that predates the advert** (anything but `4e5a6c85`-era builds). The Radio sound control should still appear if caps2 `0x80` is set. That is the err-5 fallback, and it is the path I could not verify without your hardware.
|
||||
2. **`sensecap-t1000e-1` on `4e5a6c85`.** Same, via the bit, since that firmware has no `0x1C`.
|
||||
3. **Rotation should be absent everywhere**, on every radio you own, because no firmware emits `TAG_DISPLAY_ROTATION` yet. If rotation appears, the gate is wrong.
|
||||
4. **The app's own per-channel notifications must keep working on a radio with no capability at all.** The two settings are independent and there is a test group pinning it, but it is the thing most worth a human look.
|
||||
5. **Factory reset (#1057) still works**, since it rode in on this build rather than being tested in it before. It is unchanged by my work, but it is in the same binary now.
|
||||
|
||||
## 8. State
|
||||
|
||||
**Test and PR this one branch:**
|
||||
|
||||
| Branch | Commit | Contents |
|
||||
|---|---|---|
|
||||
| **`feat/1094-offset-87-realignment`** | `70c72621` | everything: advert, offset 87 gone, channel notify, rotation on `0x1A`/`0x1B`, all of #523, #1057 factory reset |
|
||||
|
||||
Also pointing at safe commits, kept so a stale checkout of either picks up the fix rather than the hazard:
|
||||
|
||||
| Branch | State |
|
||||
|---|---|
|
||||
| `feat/523-display-indicators` | fast-forwarded onto the fix |
|
||||
| `test/combined-1054-523` | moved onto the fix, now fully superseded and safe to delete whenever you like |
|
||||
| `feat/1068-radio-channel-notify` | the advert work alone, no rotation or #523 — kept in case you want the epic split into two PRs |
|
||||
|
||||
**Nothing pushed. No PR. No merge to `dev`. No device flashed or installed.**
|
||||
|
||||
Issues #1095, #1096, #1097, #1099 closed. **#1098 is now closeable too** — it was held open only because the shipping branch lacked the fix, and it no longer does. I left the close to you since it is tied to the test. #1094 is the epic. Citadel tasks `7mv`, `5rc`, `uaa`, `381`, `rhm`, `y68` closed with evidence.
|
||||
|
||||
Worktree `C:\Dev\.worktrees\meshcore-open-1098` holds the combined branch. `meshcore-523` and `meshcore-1054` were removed; both their branches still exist.
|
||||
@ -0,0 +1,203 @@
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'offband_device_ui.dart';
|
||||
|
||||
/// The `0xC5` `0x1C` capability advert (#1095, firmware #1994).
|
||||
///
|
||||
/// Replaces the practice of appending Offband capability bytes to upstream's
|
||||
/// `RESP_CODE_DEVICE_INFO` frame. Three features each computed "the next free
|
||||
/// byte" as **87** and each was right in isolation, and a collision at a frame
|
||||
/// offset is silent misparsing rather than a refused command. Two permanent
|
||||
/// rules came out of that (firmware `docs/offband_info_frame_contract.md` §2):
|
||||
/// no Offband field is ever added to upstream's frame again, and a number is
|
||||
/// claimed by merge before any work begins.
|
||||
///
|
||||
/// THE AUTHORITY for every number here is firmware
|
||||
/// `examples/companion_radio/OffbandConfigProtocol.h`, merged to
|
||||
/// `firmware-base` in PR OffbandMesh/meshcore-firmware#2000 (`28785ebf`,
|
||||
/// 2026-11-04). The contract's §5 table is a convenience copy and the header
|
||||
/// wins on any disagreement. Do not take a number from an Agent Mail message:
|
||||
/// that habit is what caused the collision.
|
||||
const int offbandUiInfoGet = 0x1C;
|
||||
|
||||
/// A tag's PRESENCE is the capability. There is no capability bitmap in this
|
||||
/// frame: tags already answer "is this supported", so a bitmap beside them
|
||||
/// would be a second source of truth for one question (the defect removed from
|
||||
/// contract revision 1).
|
||||
///
|
||||
/// - `len = 0` means "I have this feature, nothing to report". The normal case.
|
||||
/// - `len > 0` only where the value is one or two bytes, fixed for the build,
|
||||
/// and has no sub-code of its own. Everything else is read with its own GET.
|
||||
/// - **Absent** means the board does not have the feature. Not an error, and
|
||||
/// not a zero value.
|
||||
const int offbandInfoTagChanNotify = 0x01;
|
||||
const int offbandInfoTagDisplayRotation = 0x02;
|
||||
const int offbandInfoTagAckCapacity = 0x03;
|
||||
const int offbandInfoTagContinue = 0xFF;
|
||||
|
||||
/// `0x00` is not a valid tag.
|
||||
const int _invalidTag = 0x00;
|
||||
|
||||
/// Firmware `OFFBAND_UI_ERR_MALFORMED = 5`.
|
||||
///
|
||||
/// The `0xC5` handler returns this reason for BOTH a malformed payload on a
|
||||
/// known sub-code and a sub-code it does not implement at all. That overload is
|
||||
/// the entire reason the advert request must carry zero payload: with no
|
||||
/// payload there is nothing to be malformed, so the answer can only mean the
|
||||
/// radio does not implement `0x1C`.
|
||||
const int offbandUiErrReasonMalformed = 0x05;
|
||||
|
||||
/// Ceiling on continuation rounds. The advert is a handful of bytes today and
|
||||
/// no shipping firmware can overflow it, so any long chain is a firmware fault
|
||||
/// rather than a large reply. Bounded because an unbounded request loop driven
|
||||
/// by device data is a worse failure than a truncated capability list.
|
||||
const int offbandInfoMaxContinuations = 8;
|
||||
|
||||
/// Request the whole advert. **Zero payload, deliberately.**
|
||||
///
|
||||
/// A `[0xC5][0x7F][0x05]` answer to a zero-payload request is unambiguous:
|
||||
/// reason 5 is also what a KNOWN sub-code returns for a malformed payload, so
|
||||
/// a request carrying bytes could not be told apart from a device that simply
|
||||
/// predates the advert.
|
||||
Uint8List buildCapabilityAdvertRequestFrame() =>
|
||||
Uint8List.fromList([cmdOffbandDeviceUi, offbandUiInfoGet]);
|
||||
|
||||
/// Resume from [cursor], which is the value `TAG_CONTINUE` carried.
|
||||
Uint8List buildCapabilityAdvertResumeFrame(int cursor) {
|
||||
if (cursor < 0 || cursor > 0xFF) {
|
||||
throw ArgumentError.value(cursor, 'cursor', 'must be 0 to 255');
|
||||
}
|
||||
return Uint8List.fromList([cmdOffbandDeviceUi, offbandUiInfoGet, cursor]);
|
||||
}
|
||||
|
||||
/// One `0xC5` `0x1C` reply, parsed.
|
||||
class OffbandCapabilityAdvert {
|
||||
const OffbandCapabilityAdvert({
|
||||
required this.tags,
|
||||
this.continueCursor,
|
||||
this.malformed = false,
|
||||
});
|
||||
|
||||
/// Tag to value. An empty value is the `len = 0` case and still means
|
||||
/// supported, so membership is the question to ask, never emptiness.
|
||||
final Map<int, Uint8List> tags;
|
||||
|
||||
/// Non-null when the reply ended in `TAG_CONTINUE`: re-request with this as
|
||||
/// the cursor. A reply without it is complete.
|
||||
final int? continueCursor;
|
||||
|
||||
/// A record was unparseable and parsing stopped there. The tags BEFORE it are
|
||||
/// still returned, because capability absence is safe (the feature hides)
|
||||
/// while discarding a whole good reply over a bad trailing byte is not.
|
||||
///
|
||||
/// Firmware must not split a record across frames, so this is a firmware
|
||||
/// fault and worth logging rather than swallowing.
|
||||
final bool malformed;
|
||||
|
||||
bool has(int tag) => tags.containsKey(tag);
|
||||
|
||||
/// The single-byte value of [tag], or null when the tag is absent or does not
|
||||
/// carry exactly one byte. Null is never coerced to 0: "the device did not
|
||||
/// say" and "the device said zero" are different answers.
|
||||
int? byteValue(int tag) {
|
||||
final value = tags[tag];
|
||||
if (value == null || value.length != 1) return null;
|
||||
return value[0];
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
final names = tags.keys.toList()..sort();
|
||||
return 'advert(tags=[${names.map((t) => '0x${t.toRadixString(16).padLeft(2, '0')}').join(',')}]'
|
||||
'${continueCursor == null ? '' : ', continue=0x${continueCursor!.toRadixString(16).padLeft(2, '0')}'}'
|
||||
'${malformed ? ', MALFORMED' : ''})';
|
||||
}
|
||||
}
|
||||
|
||||
/// Parse a `0xC5` `0x1C` reply. Null when the frame is not one of those at all.
|
||||
///
|
||||
/// A reply with no records is valid and means "nothing further", which is what
|
||||
/// a cursor above every available tag returns. It is not an error.
|
||||
///
|
||||
/// Unknown tags are KEPT and skipped by `len`, never rejected: a client built
|
||||
/// today has to stay correct against firmware emitting tags it has never heard
|
||||
/// of, and failing on one is non-conforming.
|
||||
OffbandCapabilityAdvert? parseCapabilityAdvertReply(List<int> frame) {
|
||||
if (frame.length < 2) return null;
|
||||
if (frame[0] != respCodeOffbandDeviceUi) return null;
|
||||
if (frame[1] != offbandUiInfoGet) return null;
|
||||
|
||||
final tags = <int, Uint8List>{};
|
||||
int? continueCursor;
|
||||
var malformed = false;
|
||||
var i = 2;
|
||||
|
||||
while (i < frame.length) {
|
||||
final tag = frame[i];
|
||||
if (tag == _invalidTag) {
|
||||
malformed = true;
|
||||
break;
|
||||
}
|
||||
if (i + 1 >= frame.length) {
|
||||
// A tag with no length byte.
|
||||
malformed = true;
|
||||
break;
|
||||
}
|
||||
final len = frame[i + 1];
|
||||
final valueStart = i + 2;
|
||||
final valueEnd = valueStart + len;
|
||||
if (valueEnd > frame.length) {
|
||||
// A record running past the frame. Firmware must not split one.
|
||||
malformed = true;
|
||||
break;
|
||||
}
|
||||
final value = Uint8List.fromList(frame.sublist(valueStart, valueEnd));
|
||||
|
||||
if (tag == offbandInfoTagContinue) {
|
||||
if (len != 1) {
|
||||
malformed = true;
|
||||
break;
|
||||
}
|
||||
continueCursor = value[0];
|
||||
// TAG_CONTINUE is the last record by construction. Anything after it is
|
||||
// not something to guess at.
|
||||
malformed = valueEnd != frame.length;
|
||||
break;
|
||||
}
|
||||
|
||||
// Records arrive in ascending tag order, but position is never relied on,
|
||||
// so an out-of-order frame still parses. A repeated tag is a firmware
|
||||
// fault: keep the FIRST value and say so, rather than letting a later
|
||||
// record silently redefine a capability.
|
||||
if (tags.containsKey(tag)) {
|
||||
malformed = true;
|
||||
} else {
|
||||
tags[tag] = value;
|
||||
}
|
||||
i = valueEnd;
|
||||
}
|
||||
|
||||
return OffbandCapabilityAdvert(
|
||||
tags: tags,
|
||||
continueCursor: continueCursor,
|
||||
malformed: malformed,
|
||||
);
|
||||
}
|
||||
|
||||
/// How far the client has got with asking this radio for its advert.
|
||||
///
|
||||
/// Distinguishes "has not answered yet" from "answered, and says it does not
|
||||
/// have this mechanism". Those lead to different gating, and a single nullable
|
||||
/// field would conflate them exactly where the collision taught us not to.
|
||||
enum CapabilityAdvertState {
|
||||
/// No request sent, or sent and still outstanding.
|
||||
unknown,
|
||||
|
||||
/// A `0x1C` reply arrived and was parsed.
|
||||
advertised,
|
||||
|
||||
/// `[0xC5][0x7F][0x05]` to our zero-payload request: this radio predates the
|
||||
/// advert, so capability reading falls back to the absolute device-info
|
||||
/// offsets that shipped before it.
|
||||
unsupported,
|
||||
}
|
||||
@ -0,0 +1,111 @@
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'offband_device_ui.dart';
|
||||
|
||||
/// Per-channel notification mode stored on the RADIO, over `0xC5` 0x18 / 0x19
|
||||
/// (#544, meshcore-firmware#606).
|
||||
///
|
||||
/// This governs the RADIO's buzzer and nothing else. It is deliberately
|
||||
/// independent of the app's own per-channel `ChannelNotifyMode`, which governs
|
||||
/// whether the PHONE notifies: two settings, two outputs, no bridging between
|
||||
/// them (owner, 2026-11-03: "they are separate controls and separate
|
||||
/// notifications... they are independent settings"). Never resolve one from
|
||||
/// the other, and never offer an "inherit the app setting" value here.
|
||||
///
|
||||
/// Firmware is the authority and there is no firmware inherit concept: the
|
||||
/// owner's ruling was "Inherit is on the client side, not on the firmware
|
||||
/// side. How would firmware inherit from firmware?". [unset] is simply the
|
||||
/// absence of a per-channel choice, and the radio's own device-wide scope
|
||||
/// answers for that channel instead.
|
||||
const int offbandUiChannelNotifyGet = 0x18;
|
||||
const int offbandUiChannelNotifySet = 0x19;
|
||||
|
||||
/// A channel's radio notify mode, as the radio stores it.
|
||||
///
|
||||
/// The byte is **1-based** and 0 means "no choice made", because the value
|
||||
/// lives in a field that reads zero on every existing record and every fresh
|
||||
/// channel. If 0 meant a real mode, every untouched channel in the field would
|
||||
/// silently adopt it. The shipped `ChannelTune` byte uses the same convention
|
||||
/// for the same reason, so the two are consistent on the wire.
|
||||
///
|
||||
/// `[verified 2026-11-04 against firmware src/helpers/ChannelNotify.h on
|
||||
/// epic/606-channel-notify: kChanNotifyUnset = 0, kChanNotifyAll = 1,
|
||||
/// kChanNotifyMentions = 2, kChanNotifyOff = 3, kChanNotifyCount = 4.]`
|
||||
/// The contract calls these All / Self / None plus "follow the device
|
||||
/// setting"; that is the same encoding in different words, with "Self" being
|
||||
/// [mentions] and "follow" being [unset].
|
||||
///
|
||||
/// Firmware validates a SET with `stored < kChanNotifyCount`, i.e. `mode < 4`
|
||||
/// and nothing else. That is why a rotation SET on `0x18`/`0x19` was silent
|
||||
/// corruption rather than a refused command: every rotation value in 0 to 3
|
||||
/// passes as a valid notify mode and writes to the channel at that slot. See
|
||||
/// `offband_indicators.dart`, which now uses `0x1A`/`0x1B`.
|
||||
enum RadioChannelNotify {
|
||||
/// No per-channel choice: the radio's device-wide scope answers instead.
|
||||
unset(0x00),
|
||||
|
||||
/// Beep for any message on this channel.
|
||||
all(0x01),
|
||||
|
||||
/// Beep only when the message names us, by the `@[name]` rule.
|
||||
mentions(0x02),
|
||||
|
||||
/// Never beep for this channel.
|
||||
off(0x03);
|
||||
|
||||
const RadioChannelNotify(this.stored);
|
||||
|
||||
/// The wire byte. Never built by hand.
|
||||
final int stored;
|
||||
|
||||
static RadioChannelNotify? fromStored(int stored) {
|
||||
for (final m in RadioChannelNotify.values) {
|
||||
if (m.stored == stored) return m;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// One channel's radio notify mode, as a `0xC5` 0x18 or 0x19 reply reports it.
|
||||
class RadioChannelNotifyReply {
|
||||
const RadioChannelNotifyReply({required this.channel, required this.mode});
|
||||
final int channel;
|
||||
final RadioChannelNotify mode;
|
||||
}
|
||||
|
||||
int _channelByte(int channel) {
|
||||
if (channel < 0 || channel > 0xFF) {
|
||||
throw ArgumentError.value(channel, 'channel', 'must be 0 to 255');
|
||||
}
|
||||
return channel;
|
||||
}
|
||||
|
||||
Uint8List buildChannelNotifyGetFrame(int channel) => Uint8List.fromList([
|
||||
cmdOffbandDeviceUi,
|
||||
offbandUiChannelNotifyGet,
|
||||
_channelByte(channel),
|
||||
]);
|
||||
|
||||
Uint8List buildChannelNotifySetFrame(int channel, RadioChannelNotify mode) =>
|
||||
Uint8List.fromList([
|
||||
cmdOffbandDeviceUi,
|
||||
offbandUiChannelNotifySet,
|
||||
_channelByte(channel),
|
||||
mode.stored,
|
||||
]);
|
||||
|
||||
/// Parse a `0xC5` channel-notify reply (0x18 or 0x19). Null when this is not
|
||||
/// one, when it is short, or when the mode byte is not a value we know: an
|
||||
/// unrecognized mode is dropped rather than guessed at, so a firmware that
|
||||
/// grows a fourth mode cannot have it read as one of ours.
|
||||
RadioChannelNotifyReply? parseChannelNotifyReply(List<int> frame) {
|
||||
if (frame.length < 4) return null;
|
||||
if (frame[0] != respCodeOffbandDeviceUi) return null;
|
||||
if (frame[1] != offbandUiChannelNotifyGet &&
|
||||
frame[1] != offbandUiChannelNotifySet) {
|
||||
return null;
|
||||
}
|
||||
final mode = RadioChannelNotify.fromStored(frame[3]);
|
||||
if (mode == null) return null;
|
||||
return RadioChannelNotifyReply(channel: frame[2], mode: mode);
|
||||
}
|
||||
@ -0,0 +1,144 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../connector/meshcore_connector.dart';
|
||||
import '../connector/offband_channel_notify.dart';
|
||||
import '../connector/offband_device_ui.dart';
|
||||
import '../l10n/l10n.dart';
|
||||
import '../models/channel.dart';
|
||||
|
||||
/// The RADIO's per-channel sound setting (#544).
|
||||
///
|
||||
/// Deliberately a separate control from the app's per-channel notification
|
||||
/// setting in `channel_notify_mode.dart`: that one decides whether the PHONE
|
||||
/// notifies, this one decides whether the RADIO beeps, and neither reads the
|
||||
/// other (owner, 2026-11-03). Do not merge them, and do not resolve one from
|
||||
/// the other.
|
||||
|
||||
IconData radioChannelNotifyIcon(RadioChannelNotify mode) {
|
||||
switch (mode) {
|
||||
case RadioChannelNotify.all:
|
||||
return Icons.volume_up_outlined;
|
||||
case RadioChannelNotify.mentions:
|
||||
return Icons.alternate_email;
|
||||
case RadioChannelNotify.off:
|
||||
return Icons.volume_off_outlined;
|
||||
case RadioChannelNotify.unset:
|
||||
return Icons.settings_backup_restore;
|
||||
}
|
||||
}
|
||||
|
||||
String radioChannelNotifyLabel(BuildContext context, RadioChannelNotify mode) {
|
||||
switch (mode) {
|
||||
case RadioChannelNotify.all:
|
||||
return context.l10n.channels_notifyAll;
|
||||
case RadioChannelNotify.mentions:
|
||||
return context.l10n.channels_notifyMentionsOnly;
|
||||
case RadioChannelNotify.off:
|
||||
return context.l10n.channels_notifyOff;
|
||||
case RadioChannelNotify.unset:
|
||||
return context.l10n.channels_radioSoundUnset;
|
||||
}
|
||||
}
|
||||
|
||||
/// What this channel will ACTUALLY do on the radio, which is not always the
|
||||
/// stored byte (#544 C3, owner's call 2026-11-03).
|
||||
///
|
||||
/// The radio's rules, per firmware: a channel with a mode set decides for
|
||||
/// itself; a channel with no mode falls back to the device-wide scope; and a
|
||||
/// device scope of None overrides even a channel that is set. Showing the raw
|
||||
/// mode would tell a user with the radio muted that a channel is on "All
|
||||
/// messages" while it sits silent.
|
||||
///
|
||||
/// Null when the composition cannot be known: the mode has not been read, or
|
||||
/// it is unset and the device scope has not been read either. A caller must
|
||||
/// show "reading", never a guess.
|
||||
String? radioChannelNotifyEffective(
|
||||
BuildContext context,
|
||||
RadioChannelNotify? mode,
|
||||
DeviceNotifyScope? scope,
|
||||
) {
|
||||
if (mode == null) return null;
|
||||
if (scope == DeviceNotifyScope.none) {
|
||||
return context.l10n.channels_radioSoundMutedByRadio;
|
||||
}
|
||||
if (mode != RadioChannelNotify.unset) {
|
||||
return radioChannelNotifyLabel(context, mode);
|
||||
}
|
||||
if (scope == null) return null;
|
||||
return context.l10n.channels_radioSoundFollows(scope.label);
|
||||
}
|
||||
|
||||
/// Whether this radio can be offered the control at all. The app's own
|
||||
/// per-channel setting is never gated on this.
|
||||
bool radioChannelNotifySupported(MeshCoreConnector connector) =>
|
||||
connector.supportsChannelNotify;
|
||||
|
||||
void showRadioChannelNotifyDialog(BuildContext context, Channel channel) {
|
||||
final connector = context.read<MeshCoreConnector>();
|
||||
|
||||
showDialog<void>(
|
||||
context: context,
|
||||
builder: (dialogContext) => Consumer<MeshCoreConnector>(
|
||||
builder: (consumerContext, live, _) {
|
||||
// State follows the radio's reply, never the tap: until the radio has
|
||||
// answered for this slot there is no current value to tick, and a
|
||||
// write that it refuses never appears as saved.
|
||||
final current = live.channelNotifyFor(channel);
|
||||
final error = live.deviceUiErrorSurface == DeviceUiSurface.channelNotify
|
||||
? live.deviceUiError
|
||||
: null;
|
||||
|
||||
return AlertDialog(
|
||||
title: Text(consumerContext.l10n.channels_radioSound),
|
||||
contentPadding: const EdgeInsets.symmetric(vertical: 8),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
if (error != null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(24, 0, 24, 8),
|
||||
child: Text(
|
||||
error,
|
||||
style: TextStyle(
|
||||
color: Theme.of(consumerContext).colorScheme.error,
|
||||
),
|
||||
),
|
||||
),
|
||||
if (current == null)
|
||||
ListTile(
|
||||
leading: const SizedBox(
|
||||
width: 24,
|
||||
height: 24,
|
||||
child: CircularProgressIndicator(strokeWidth: 2),
|
||||
),
|
||||
title: Text(consumerContext.l10n.channels_radioSoundReading),
|
||||
),
|
||||
for (final mode in RadioChannelNotify.values)
|
||||
ListTile(
|
||||
leading: Icon(radioChannelNotifyIcon(mode)),
|
||||
title: Text(radioChannelNotifyLabel(consumerContext, mode)),
|
||||
subtitle: mode == RadioChannelNotify.unset
|
||||
? Text(
|
||||
radioChannelNotifyEffective(
|
||||
consumerContext,
|
||||
RadioChannelNotify.unset,
|
||||
live.deviceNotifyScope,
|
||||
) ??
|
||||
consumerContext.l10n.channels_radioSoundReading,
|
||||
)
|
||||
: null,
|
||||
trailing: mode == current ? const Icon(Icons.check) : null,
|
||||
onTap: () async {
|
||||
Navigator.pop(dialogContext);
|
||||
await connector.setChannelNotify(channel, mode);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
@ -0,0 +1,674 @@
|
||||
// #544 Epic A (#1068): the red baseline for the RADIO's per-channel notify
|
||||
// mode over 0xC5 0x18 / 0x19.
|
||||
//
|
||||
// The feature this pins is that there are TWO independent settings: the app's
|
||||
// per-channel mode drives the PHONE, the radio's drives the BUZZER, and
|
||||
// neither moves the other (owner, 2026-11-03). The independence group below is
|
||||
// the load-bearing part -- it is what stops the two being quietly re-merged by
|
||||
// a later change.
|
||||
|
||||
import 'dart:convert';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:drift/native.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:meshcore_open/connector/meshcore_connector.dart';
|
||||
import 'package:meshcore_open/connector/meshcore_protocol.dart';
|
||||
import 'package:meshcore_open/connector/offband_capability_advert.dart';
|
||||
import 'package:meshcore_open/connector/offband_channel_notify.dart';
|
||||
import 'package:meshcore_open/connector/offband_device_ui.dart';
|
||||
import 'package:meshcore_open/models/app_settings.dart';
|
||||
import 'package:meshcore_open/models/channel.dart';
|
||||
import 'package:meshcore_open/services/app_settings_service.dart';
|
||||
import 'package:meshcore_open/storage/drift/blob_store.dart';
|
||||
import 'package:meshcore_open/storage/drift/offband_database.dart';
|
||||
import 'package:meshcore_open/storage/prefs_manager.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
/// RESP_CODE_DEVICE_INFO from an Offband radio (fork length, dual version so
|
||||
/// the population classifier corroborates it). Caps byte 2 at offset 84;
|
||||
/// pass [length] 88 with [caps3] to carry a third caps byte at offset 87.
|
||||
Uint8List deviceInfo({
|
||||
required int caps2,
|
||||
int length = 85,
|
||||
int caps3 = 0,
|
||||
int ledByte = 0,
|
||||
int displayByte = 0,
|
||||
}) {
|
||||
final v = ascii.encode('1.5.0-1.17.0');
|
||||
final f = Uint8List(length);
|
||||
f[0] = 13;
|
||||
f[1] = 22;
|
||||
f.setRange(60, 60 + v.length, v);
|
||||
if (length >= 85) f[84] = caps2;
|
||||
if (length >= 86) f[85] = ledByte;
|
||||
if (length >= 87) f[86] = displayByte;
|
||||
if (length >= 88) f[87] = caps3;
|
||||
return f;
|
||||
}
|
||||
|
||||
/// A RESP_CODE_CHANNEL_INFO frame. [pskSeed] makes each channel's PSK, and so
|
||||
/// its identity, distinct.
|
||||
Uint8List channelInfoFrame({
|
||||
required int index,
|
||||
required String name,
|
||||
required int pskSeed,
|
||||
}) {
|
||||
final frame = Uint8List(50);
|
||||
frame[0] = respCodeChannelInfo;
|
||||
frame[1] = index;
|
||||
final nameBytes = name.codeUnits;
|
||||
for (var i = 0; i < nameBytes.length && i < 31; i++) {
|
||||
frame[2 + i] = nameBytes[i];
|
||||
}
|
||||
for (var i = 0; i < 16; i++) {
|
||||
frame[34 + i] = (pskSeed + i) & 0xFF;
|
||||
}
|
||||
return frame;
|
||||
}
|
||||
|
||||
/// A slot whose stored record was erased: flash reads back as 0xFF, so the
|
||||
/// name decodes to replacement characters and the PSK is all-ones (#1060).
|
||||
Uint8List erasedChannelInfoFrame(int index) {
|
||||
final frame = Uint8List(50);
|
||||
frame[0] = respCodeChannelInfo;
|
||||
frame[1] = index;
|
||||
for (var i = 2; i < 50; i++) {
|
||||
frame[i] = 0xFF;
|
||||
}
|
||||
return frame;
|
||||
}
|
||||
|
||||
/// A standalone Channel for tests that never sync a list, e.g. the capability
|
||||
/// gate, which must refuse before it ever looks a slot up.
|
||||
Channel testChannel(int index, {String name = 'ch', int pskSeed = 10}) =>
|
||||
Channel(
|
||||
index: index,
|
||||
name: name,
|
||||
psk: Uint8List.fromList(
|
||||
List<int>.generate(16, (i) => (pskSeed + i) & 0xFF),
|
||||
),
|
||||
);
|
||||
|
||||
Future<void> settle([int turns = 25]) async {
|
||||
for (var i = 0; i < turns; i++) {
|
||||
await Future<void>.delayed(Duration.zero);
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
late OffbandDatabase db;
|
||||
late MeshCoreConnector connector;
|
||||
late List<List<int>> sent;
|
||||
|
||||
setUp(() async {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
PrefsManager.reset();
|
||||
await PrefsManager.initialize();
|
||||
db = OffbandDatabase(NativeDatabase.memory());
|
||||
BlobStore.overrideForTest(BlobStore(db));
|
||||
sent = [];
|
||||
connector = MeshCoreConnector();
|
||||
connector.sendFrameOverrideForTest = (data) => sent.add(data.toList());
|
||||
connector.setConnectedForTest();
|
||||
});
|
||||
|
||||
tearDown(() async {
|
||||
BlobStore.clearTestOverride();
|
||||
await db.close();
|
||||
});
|
||||
|
||||
/// Drives a full channel sync so slot indices are confirmed. The radio's
|
||||
/// notify modes are only meaningful past that barrier (#1062), and since
|
||||
/// #1060 the client resolves every slot to a channel identity, so a test
|
||||
/// that never syncs has no identities to resolve against.
|
||||
Future<void> syncChannels(
|
||||
List<({int index, String name, int seed})> arrangement,
|
||||
) async {
|
||||
await connector.getChannels(force: true, maxChannels: arrangement.length);
|
||||
for (final ch in arrangement) {
|
||||
connector.handleFrameForTest(
|
||||
channelInfoFrame(index: ch.index, name: ch.name, pskSeed: ch.seed),
|
||||
);
|
||||
await settle(2);
|
||||
}
|
||||
await settle();
|
||||
}
|
||||
|
||||
Channel slot(int index) =>
|
||||
connector.channels.firstWhere((c) => c.index == index);
|
||||
|
||||
bool sentChannelNotify() => sent.any(
|
||||
(f) =>
|
||||
f.length >= 2 &&
|
||||
f[0] == cmdOffbandDeviceUi &&
|
||||
(f[1] == offbandUiChannelNotifyGet ||
|
||||
f[1] == offbandUiChannelNotifySet),
|
||||
);
|
||||
|
||||
// ---- A1: the radio's modes ------------------------------------------------
|
||||
|
||||
group('A1 radio channel notify', () {
|
||||
test('the wire bytes are the documented ones', () async {
|
||||
connector.handleFrameForTest(deviceInfo(caps2: offbandCap2ChannelNotify));
|
||||
await syncChannels([
|
||||
(index: 0, name: 'Public', seed: 10),
|
||||
(index: 1, name: 'test', seed: 50),
|
||||
(index: 2, name: 'wardriving', seed: 40),
|
||||
]);
|
||||
sent.clear();
|
||||
|
||||
await connector.requestChannelNotify(2);
|
||||
await connector.setChannelNotify(slot(2), RadioChannelNotify.mentions);
|
||||
|
||||
expect(
|
||||
sent,
|
||||
equals([
|
||||
[0xC5, 0x18, 0x02],
|
||||
[0xC5, 0x19, 0x02, 0x02],
|
||||
]),
|
||||
);
|
||||
});
|
||||
|
||||
test('a reply sets that channel, and only that channel', () async {
|
||||
connector.handleFrameForTest(deviceInfo(caps2: offbandCap2ChannelNotify));
|
||||
await syncChannels([
|
||||
(index: 0, name: 'Public', seed: 10),
|
||||
(index: 1, name: 'test', seed: 50),
|
||||
(index: 2, name: 'wardriving', seed: 40),
|
||||
]);
|
||||
connector.handleFrameForTest([0xC5, 0x18, 0x01, 0x02]);
|
||||
|
||||
expect(connector.channelNotifyFor(slot(1)), RadioChannelNotify.mentions);
|
||||
expect(connector.channelNotifyFor(slot(0)), isNull);
|
||||
expect(connector.channelNotifyFor(slot(2)), isNull);
|
||||
});
|
||||
|
||||
test('mode 0 is unset, and is distinct from Off', () async {
|
||||
connector.handleFrameForTest(deviceInfo(caps2: offbandCap2ChannelNotify));
|
||||
await syncChannels([
|
||||
(index: 0, name: 'Public', seed: 10),
|
||||
(index: 1, name: 'test', seed: 50),
|
||||
]);
|
||||
connector.handleFrameForTest([0xC5, 0x18, 0x00, 0x00]);
|
||||
connector.handleFrameForTest([0xC5, 0x18, 0x01, 0x03]);
|
||||
|
||||
expect(connector.channelNotifyFor(slot(0)), RadioChannelNotify.unset);
|
||||
expect(connector.channelNotifyFor(slot(1)), RadioChannelNotify.off);
|
||||
});
|
||||
|
||||
test('a write is not shown until the radio confirms it', () async {
|
||||
connector.handleFrameForTest(deviceInfo(caps2: offbandCap2ChannelNotify));
|
||||
await syncChannels([(index: 3, name: 'wardriving', seed: 40)]);
|
||||
await connector.setChannelNotify(slot(3), RadioChannelNotify.off);
|
||||
|
||||
expect(connector.channelNotifyFor(slot(3)), isNull);
|
||||
|
||||
connector.handleFrameForTest([0xC5, 0x19, 0x03, 0x03]);
|
||||
expect(connector.channelNotifyFor(slot(3)), RadioChannelNotify.off);
|
||||
});
|
||||
|
||||
test('an unknown mode byte is dropped, never guessed at', () async {
|
||||
connector.handleFrameForTest(deviceInfo(caps2: offbandCap2ChannelNotify));
|
||||
await syncChannels([(index: 4, name: 'wardriving', seed: 40)]);
|
||||
connector.handleFrameForTest([0xC5, 0x18, 0x04, 0x09]);
|
||||
|
||||
expect(connector.channelNotifyFor(slot(4)), isNull);
|
||||
expect(parseChannelNotifyReply([0xC5, 0x18, 0x04, 0x09]), isNull);
|
||||
});
|
||||
|
||||
test('state does not survive a change of radio', () async {
|
||||
connector.handleFrameForTest(deviceInfo(caps2: offbandCap2ChannelNotify));
|
||||
await syncChannels([(index: 1, name: 'wardriving', seed: 40)]);
|
||||
final wardriving = slot(1);
|
||||
connector.handleFrameForTest([0xC5, 0x18, 0x01, 0x01]);
|
||||
expect(connector.channelNotifyFor(wardriving), RadioChannelNotify.all);
|
||||
|
||||
connector.handleFrameForTest(deviceInfo(caps2: offbandCap2ChannelNotify));
|
||||
expect(connector.channelNotifyFor(wardriving), isNull);
|
||||
});
|
||||
|
||||
test(
|
||||
'a reply for a slot with no confirmed channel is dropped, not stored',
|
||||
() async {
|
||||
connector.handleFrameForTest(
|
||||
deviceInfo(caps2: offbandCap2ChannelNotify),
|
||||
);
|
||||
await syncChannels([(index: 0, name: 'Public', seed: 10)]);
|
||||
|
||||
// Slot 7 was never confirmed. Storing this against slot 7 is what let
|
||||
// a later occupant of that slot inherit the mode (#1060).
|
||||
connector.handleFrameForTest([0xC5, 0x18, 0x07, 0x03]);
|
||||
|
||||
expect(connector.channels.any((c) => c.index == 7), isFalse);
|
||||
expect(connector.channelNotifyFor(slot(0)), isNull);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
// ---- A5: the mode follows the channel, not the slot (#1060) --------------
|
||||
|
||||
group('A5 radio notify is keyed by channel identity', () {
|
||||
test('a mode read for one channel does not appear on the channel that '
|
||||
'later takes its slot', () async {
|
||||
connector.handleFrameForTest(deviceInfo(caps2: offbandCap2ChannelNotify));
|
||||
// #wardriving sits in slot 1 and the radio reports it as Off.
|
||||
await syncChannels([
|
||||
(index: 0, name: 'Public', seed: 10),
|
||||
(index: 1, name: 'wardriving', seed: 40),
|
||||
]);
|
||||
final wardriving = slot(1);
|
||||
connector.handleFrameForTest([0xC5, 0x18, 0x01, 0x03]);
|
||||
expect(connector.channelNotifyFor(wardriving), RadioChannelNotify.off);
|
||||
|
||||
// A wipe and re-import puts a DIFFERENT channel in slot 1.
|
||||
await syncChannels([
|
||||
(index: 0, name: 'Public', seed: 10),
|
||||
(index: 1, name: 'test', seed: 50),
|
||||
]);
|
||||
final testCh = slot(1);
|
||||
|
||||
// The new occupant must not inherit #wardriving's Off. Before this
|
||||
// fix the slot-keyed map handed it straight over, which is how a
|
||||
// channel the owner had silenced started chirping again.
|
||||
expect(testCh.pskHex, isNot(wardriving.pskHex));
|
||||
expect(connector.channelNotifyFor(testCh), isNull);
|
||||
});
|
||||
|
||||
test('a mode survives the channel moving to a different slot', () async {
|
||||
connector.handleFrameForTest(deviceInfo(caps2: offbandCap2ChannelNotify));
|
||||
await syncChannels([
|
||||
(index: 0, name: 'Public', seed: 10),
|
||||
(index: 1, name: 'wardriving', seed: 40),
|
||||
]);
|
||||
connector.handleFrameForTest([0xC5, 0x18, 0x01, 0x03]);
|
||||
|
||||
// Same channel, new slot.
|
||||
await syncChannels([
|
||||
(index: 0, name: 'Public', seed: 10),
|
||||
(index: 1, name: 'test', seed: 50),
|
||||
(index: 2, name: 'wardriving', seed: 40),
|
||||
]);
|
||||
|
||||
expect(connector.channelNotifyFor(slot(2)), RadioChannelNotify.off);
|
||||
expect(connector.channelNotifyFor(slot(1)), isNull);
|
||||
});
|
||||
|
||||
test(
|
||||
'a write addresses the channel current slot, not a stale one',
|
||||
() async {
|
||||
connector.handleFrameForTest(
|
||||
deviceInfo(caps2: offbandCap2ChannelNotify),
|
||||
);
|
||||
await syncChannels([
|
||||
(index: 0, name: 'Public', seed: 10),
|
||||
(index: 1, name: 'wardriving', seed: 40),
|
||||
]);
|
||||
// A Channel captured while it was in slot 1, as a UI widget holds one.
|
||||
final staleHandle = slot(1);
|
||||
|
||||
await syncChannels([
|
||||
(index: 0, name: 'Public', seed: 10),
|
||||
(index: 1, name: 'test', seed: 50),
|
||||
(index: 2, name: 'wardriving', seed: 40),
|
||||
]);
|
||||
sent.clear();
|
||||
|
||||
await connector.setChannelNotify(staleHandle, RadioChannelNotify.off);
|
||||
|
||||
// Addressed to slot 2, where #wardriving actually is now.
|
||||
expect(
|
||||
sent,
|
||||
equals([
|
||||
[0xC5, 0x19, 0x02, 0x03],
|
||||
]),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
test('a write for a channel the radio does not hold is refused', () async {
|
||||
connector.handleFrameForTest(deviceInfo(caps2: offbandCap2ChannelNotify));
|
||||
await syncChannels([
|
||||
(index: 0, name: 'Public', seed: 10),
|
||||
(index: 1, name: 'wardriving', seed: 40),
|
||||
]);
|
||||
final gone = slot(1);
|
||||
|
||||
// The channel is deleted on the radio.
|
||||
await syncChannels([(index: 0, name: 'Public', seed: 10)]);
|
||||
sent.clear();
|
||||
|
||||
await connector.setChannelNotify(gone, RadioChannelNotify.off);
|
||||
|
||||
expect(sent, isEmpty);
|
||||
expect(connector.deviceUiError, isNotNull);
|
||||
expect(connector.deviceUiErrorSurface, DeviceUiSurface.channelNotify);
|
||||
});
|
||||
});
|
||||
|
||||
// ---- A2: the two settings are independent ---------------------------------
|
||||
|
||||
group('A2 independence of app and radio settings', () {
|
||||
test('changing the app mode emits no radio frame', () async {
|
||||
connector.handleFrameForTest(deviceInfo(caps2: offbandCap2ChannelNotify));
|
||||
sent.clear();
|
||||
|
||||
final settings = AppSettingsService();
|
||||
await settings.loadSettings();
|
||||
await settings.setChannelNotifyMode(
|
||||
devicePrefix: 'aabbccddee',
|
||||
pskHex: '00112233445566778899aabbccddeeff',
|
||||
channelName: 'skywarn',
|
||||
mode: ChannelNotifyMode.off,
|
||||
);
|
||||
|
||||
expect(sentChannelNotify(), isFalse);
|
||||
expect(sent, isEmpty);
|
||||
});
|
||||
|
||||
test('a radio reply does not touch the app store', () async {
|
||||
final settings = AppSettingsService();
|
||||
await settings.loadSettings();
|
||||
const prefix = 'aabbccddee';
|
||||
const psk = '00112233445566778899aabbccddeeff';
|
||||
await settings.setChannelNotifyMode(
|
||||
devicePrefix: prefix,
|
||||
pskHex: psk,
|
||||
channelName: 'skywarn',
|
||||
mode: ChannelNotifyMode.all,
|
||||
);
|
||||
|
||||
connector.handleFrameForTest(deviceInfo(caps2: offbandCap2ChannelNotify));
|
||||
connector.handleFrameForTest([0xC5, 0x18, 0x00, 0x03]);
|
||||
|
||||
expect(
|
||||
settings.channelNotifyMode(devicePrefix: prefix, pskHex: psk),
|
||||
ChannelNotifyMode.all,
|
||||
reason: 'the radio saying Off must not mute the phone',
|
||||
);
|
||||
});
|
||||
|
||||
test('the app setting works with no radio capability at all', () async {
|
||||
connector.handleFrameForTest(deviceInfo(caps2: 0x00));
|
||||
final settings = AppSettingsService();
|
||||
await settings.loadSettings();
|
||||
const prefix = 'aabbccddee';
|
||||
const psk = '00112233445566778899aabbccddeeff';
|
||||
|
||||
await settings.setChannelNotifyMode(
|
||||
devicePrefix: prefix,
|
||||
pskHex: psk,
|
||||
channelName: 'skywarn',
|
||||
mode: ChannelNotifyMode.mentionsOnly,
|
||||
);
|
||||
|
||||
expect(connector.supportsChannelNotify, isFalse);
|
||||
expect(
|
||||
settings.channelNotifyMode(devicePrefix: prefix, pskHex: psk),
|
||||
ChannelNotifyMode.mentionsOnly,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
// ---- A3: capability and caps byte 3 ---------------------------------------
|
||||
|
||||
group('A3 capability gating and caps byte 3', () {
|
||||
test('without 0x80 no channel-notify frame is ever emitted', () async {
|
||||
connector.handleFrameForTest(deviceInfo(caps2: 0x40));
|
||||
await connector.requestChannelNotify(0);
|
||||
await connector.setChannelNotify(testChannel(0), RadioChannelNotify.off);
|
||||
|
||||
expect(connector.supportsChannelNotify, isFalse);
|
||||
expect(sentChannelNotify(), isFalse);
|
||||
});
|
||||
|
||||
test('0x80 is the bit, and other bits do not open it', () {
|
||||
connector.handleFrameForTest(deviceInfo(caps2: offbandCap2ChannelNotify));
|
||||
expect(connector.supportsChannelNotify, isTrue);
|
||||
|
||||
connector.handleFrameForTest(deviceInfo(caps2: 0x7F));
|
||||
expect(connector.supportsChannelNotify, isFalse);
|
||||
});
|
||||
|
||||
test('NOTHING reads device-info offset 87 (#1096)', () {
|
||||
// The permanent rule out of the collision: no Offband field is ever
|
||||
// appended to upstream's device-info frame. Three features each computed
|
||||
// 87 as the next free byte and each was right in isolation.
|
||||
//
|
||||
// Behavioural rather than a source grep, so it keeps holding if the read
|
||||
// comes back spelled differently. Byte 87 is set to every bit, and every
|
||||
// capability answer must be identical to the frame that has no byte 87
|
||||
// at all.
|
||||
connector.handleFrameForTest(deviceInfo(caps2: 0x80, length: 85));
|
||||
final capsWithout = connector.offbandCaps2;
|
||||
final withoutByte87 = [
|
||||
connector.supportsChannelNotify,
|
||||
connector.supportsDisplayRotation,
|
||||
connector.supportsButtonMatrix,
|
||||
connector.supportsNotifyScope,
|
||||
connector.supportsTunes,
|
||||
connector.supportsGpsMode,
|
||||
connector.supportsScreenSettings,
|
||||
];
|
||||
final ackWithout = connector.ackCapacity;
|
||||
|
||||
connector.handleFrameForTest(
|
||||
deviceInfo(caps2: 0x80, length: 88, caps3: 0xFF),
|
||||
);
|
||||
|
||||
expect(
|
||||
[
|
||||
connector.supportsChannelNotify,
|
||||
connector.supportsDisplayRotation,
|
||||
connector.supportsButtonMatrix,
|
||||
connector.supportsNotifyScope,
|
||||
connector.supportsTunes,
|
||||
connector.supportsGpsMode,
|
||||
connector.supportsScreenSettings,
|
||||
],
|
||||
withoutByte87,
|
||||
reason: 'a byte at offset 87 changed a capability',
|
||||
);
|
||||
expect(connector.ackCapacity, ackWithout);
|
||||
// The raw byte too, not only the named getters. Comparing getters alone
|
||||
// is a hole: a leak into a caps bit that has no getter yet (0x04
|
||||
// INDICATORS, for one) moves nothing this test can see. Caught by
|
||||
// deliberately reintroducing such a read and watching this pass.
|
||||
expect(
|
||||
connector.offbandCaps2,
|
||||
capsWithout,
|
||||
reason: 'offset 87 contaminated the caps byte read at 84',
|
||||
);
|
||||
});
|
||||
|
||||
test('a stock-shaped radio exposes nothing, whatever its bytes', () {
|
||||
final stock = Uint8List(82);
|
||||
stock[0] = 13;
|
||||
stock[1] = 14;
|
||||
connector.handleFrameForTest(stock);
|
||||
|
||||
expect(connector.supportsChannelNotify, isFalse);
|
||||
expect(connector.supportsDisplayRotation, isFalse);
|
||||
expect(connector.ackCapacity, isNull);
|
||||
});
|
||||
});
|
||||
|
||||
// ---- A4: advert precedence over the caps bit (#1097) ----------------------
|
||||
|
||||
group('A4 advert precedence', () {
|
||||
/// A `0xC5` `0x1C` reply carrying [tags] as zero-length records.
|
||||
Uint8List advertReply(List<int> tags) {
|
||||
final f = <int>[cmdOffbandDeviceUi, offbandUiInfoGet];
|
||||
for (final t in tags) {
|
||||
f.addAll([t, 0x00]);
|
||||
}
|
||||
return Uint8List.fromList(f);
|
||||
}
|
||||
|
||||
/// `[0xC5][0x7F][0x05]`: this radio does not implement the advert.
|
||||
Uint8List advertUnsupported() => Uint8List.fromList([
|
||||
cmdOffbandDeviceUi,
|
||||
offbandUiErr,
|
||||
offbandUiErrReasonMalformed,
|
||||
]);
|
||||
|
||||
test('the zero-payload advert request goes out on connect', () {
|
||||
connector.handleFrameForTest(deviceInfo(caps2: 0x80));
|
||||
expect(
|
||||
sent.any(
|
||||
(f) =>
|
||||
f.length == 2 &&
|
||||
f[0] == cmdOffbandDeviceUi &&
|
||||
f[1] == offbandUiInfoGet,
|
||||
),
|
||||
isTrue,
|
||||
reason:
|
||||
'the request must be exactly two bytes to make err 5 mean '
|
||||
'"predates the advert" rather than "malformed payload"',
|
||||
);
|
||||
});
|
||||
|
||||
test(
|
||||
'before any answer the caps bit still decides, so nothing regresses',
|
||||
() {
|
||||
connector.handleFrameForTest(deviceInfo(caps2: 0x80));
|
||||
expect(connector.capabilityAdvertState, CapabilityAdvertState.unknown);
|
||||
expect(connector.supportsChannelNotify, isTrue);
|
||||
},
|
||||
);
|
||||
|
||||
test('an advert WITH the tag grants it even with the caps bit clear', () {
|
||||
connector.handleFrameForTest(deviceInfo(caps2: 0x00));
|
||||
expect(connector.supportsChannelNotify, isFalse);
|
||||
|
||||
connector.handleFrameForTest(advertReply([offbandInfoTagChanNotify]));
|
||||
|
||||
expect(connector.capabilityAdvertState, CapabilityAdvertState.advertised);
|
||||
expect(
|
||||
connector.supportsChannelNotify,
|
||||
isTrue,
|
||||
reason:
|
||||
'once the bit is retired under contract section 4, the tag is '
|
||||
'the only thing left saying the feature exists',
|
||||
);
|
||||
});
|
||||
|
||||
test('an advert WITHOUT the tag revokes it even with the caps bit set', () {
|
||||
connector.handleFrameForTest(deviceInfo(caps2: 0x80));
|
||||
expect(connector.supportsChannelNotify, isTrue);
|
||||
|
||||
connector.handleFrameForTest(advertReply([offbandInfoTagAckCapacity]));
|
||||
|
||||
expect(connector.supportsChannelNotify, isFalse);
|
||||
});
|
||||
|
||||
test('err 5 falls back to the caps bit, which is the flashed T1000-E', () {
|
||||
// firmware 4e5a6c85 answers 0x18/0x19 and carries caps2 0x80, but
|
||||
// predates 0x1C. Tag-only gating would take the control away from it.
|
||||
connector.handleFrameForTest(deviceInfo(caps2: 0x80));
|
||||
connector.handleFrameForTest(advertUnsupported());
|
||||
|
||||
expect(
|
||||
connector.capabilityAdvertState,
|
||||
CapabilityAdvertState.unsupported,
|
||||
);
|
||||
expect(connector.supportsChannelNotify, isTrue);
|
||||
});
|
||||
|
||||
test('err 5 with the bit clear grants nothing', () {
|
||||
connector.handleFrameForTest(deviceInfo(caps2: 0x00));
|
||||
connector.handleFrameForTest(advertUnsupported());
|
||||
|
||||
expect(connector.supportsChannelNotify, isFalse);
|
||||
expect(connector.supportsDisplayRotation, isFalse);
|
||||
});
|
||||
|
||||
test('rotation is tag-gated with NO caps-bit fallback', () {
|
||||
// Deliberate: 0x1A/0x1B were claimed in the same merge as the advert, so
|
||||
// no firmware can rotate but not advertise. INDICATORS 0x04 must not
|
||||
// open it.
|
||||
connector.handleFrameForTest(deviceInfo(caps2: 0x04));
|
||||
expect(connector.supportsDisplayRotation, isFalse);
|
||||
|
||||
connector.handleFrameForTest(advertUnsupported());
|
||||
expect(connector.supportsDisplayRotation, isFalse);
|
||||
|
||||
connector.handleFrameForTest(
|
||||
advertReply([offbandInfoTagDisplayRotation]),
|
||||
);
|
||||
expect(connector.supportsDisplayRotation, isTrue);
|
||||
});
|
||||
|
||||
test('ACK capacity comes from the tag value, and absence is not zero', () {
|
||||
connector.handleFrameForTest(deviceInfo(caps2: 0x80));
|
||||
connector.handleFrameForTest(advertReply([offbandInfoTagChanNotify]));
|
||||
expect(connector.ackCapacity, isNull);
|
||||
|
||||
connector.handleFrameForTest(
|
||||
Uint8List.fromList([
|
||||
cmdOffbandDeviceUi,
|
||||
offbandUiInfoGet,
|
||||
offbandInfoTagAckCapacity,
|
||||
0x01,
|
||||
0x20,
|
||||
]),
|
||||
);
|
||||
expect(connector.ackCapacity, 0x20);
|
||||
});
|
||||
|
||||
test('an unknown tag does not disturb the known gates', () {
|
||||
connector.handleFrameForTest(deviceInfo(caps2: 0x00));
|
||||
connector.handleFrameForTest(
|
||||
Uint8List.fromList([
|
||||
cmdOffbandDeviceUi,
|
||||
offbandUiInfoGet,
|
||||
0x5A,
|
||||
0x02,
|
||||
0xDE,
|
||||
0xAD,
|
||||
offbandInfoTagChanNotify,
|
||||
0x00,
|
||||
]),
|
||||
);
|
||||
expect(connector.supportsChannelNotify, isTrue);
|
||||
expect(connector.supportsDisplayRotation, isFalse);
|
||||
});
|
||||
|
||||
test('a new device-info drops the previous radio advert', () {
|
||||
connector.handleFrameForTest(deviceInfo(caps2: 0x00));
|
||||
connector.handleFrameForTest(advertReply([offbandInfoTagChanNotify]));
|
||||
expect(connector.supportsChannelNotify, isTrue);
|
||||
|
||||
// A different radio, no advert answer yet.
|
||||
connector.handleFrameForTest(deviceInfo(caps2: 0x00));
|
||||
|
||||
expect(connector.capabilityAdvertState, CapabilityAdvertState.unknown);
|
||||
expect(
|
||||
connector.supportsChannelNotify,
|
||||
isFalse,
|
||||
reason: "one radio's tags must never answer for another",
|
||||
);
|
||||
});
|
||||
|
||||
test('a refusal with a write outstanding belongs to the WRITE', () async {
|
||||
// The error frame names no sub-code. Claiming it for the advert would
|
||||
// hide a genuinely refused write and wrongly mark the radio as predating
|
||||
// the advert.
|
||||
connector.handleFrameForTest(deviceInfo(caps2: 0x80));
|
||||
// The channel must really exist, so the write really goes out: a write
|
||||
// refused for an unresolvable slot would also set deviceUiError and
|
||||
// pass this test for the wrong reason.
|
||||
await syncChannels([(index: 0, name: 'Public', seed: 10)]);
|
||||
await connector.setChannelNotify(slot(0), RadioChannelNotify.off);
|
||||
expect(sentChannelNotify(), isTrue);
|
||||
connector.handleFrameForTest(advertUnsupported());
|
||||
|
||||
expect(
|
||||
connector.capabilityAdvertState,
|
||||
CapabilityAdvertState.unknown,
|
||||
reason: 'the advert must not claim a write refusal',
|
||||
);
|
||||
expect(connector.deviceUiError, isNotNull);
|
||||
});
|
||||
});
|
||||
}
|
||||
@ -0,0 +1,350 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:meshcore_open/connector/offband_capability_advert.dart';
|
||||
import 'package:meshcore_open/connector/offband_device_ui.dart';
|
||||
|
||||
/// #1095: the `0xC5` `0x1C` capability advert.
|
||||
///
|
||||
/// The contract these pin is firmware `docs/offband_info_frame_contract.md`
|
||||
/// revision 2 plus `OffbandConfigProtocol.h`, both merged on `firmware-base`
|
||||
/// (PR OffbandMesh/meshcore-firmware#2000, `28785ebf`). The header is the
|
||||
/// registry; the contract's §5 table is a convenience copy.
|
||||
///
|
||||
/// The load-bearing group is `unknown tags`. "A client built today must stay
|
||||
/// correct against firmware emitting tags it has never heard of. Failing on an
|
||||
/// unknown tag is non-conforming." Everything else can regress visibly; that
|
||||
/// one regresses as a client that stops working when firmware grows.
|
||||
void main() {
|
||||
group('request frames', () {
|
||||
test('the whole-advert request carries ZERO payload', () {
|
||||
// Load-bearing. `[0xC5][0x7F][0x05]` is also what a known sub-code
|
||||
// returns for a malformed payload, so only a zero-payload request makes
|
||||
// that answer mean "this radio predates the advert". A stray third byte
|
||||
// here would make the fallback undetectable.
|
||||
expect(buildCapabilityAdvertRequestFrame(), [
|
||||
cmdOffbandDeviceUi,
|
||||
offbandUiInfoGet,
|
||||
]);
|
||||
});
|
||||
|
||||
test('the resume request carries exactly the cursor byte', () {
|
||||
expect(buildCapabilityAdvertResumeFrame(0x03), [
|
||||
cmdOffbandDeviceUi,
|
||||
offbandUiInfoGet,
|
||||
0x03,
|
||||
]);
|
||||
});
|
||||
|
||||
test('a cursor outside one byte is refused rather than truncated', () {
|
||||
expect(() => buildCapabilityAdvertResumeFrame(256), throwsArgumentError);
|
||||
expect(() => buildCapabilityAdvertResumeFrame(-1), throwsArgumentError);
|
||||
});
|
||||
});
|
||||
|
||||
group('not an advert', () {
|
||||
test('a different command byte is not ours', () {
|
||||
expect(parseCapabilityAdvertReply([0xC6, offbandUiInfoGet]), isNull);
|
||||
});
|
||||
|
||||
test('a different sub-code is not ours', () {
|
||||
expect(parseCapabilityAdvertReply([cmdOffbandDeviceUi, 0x18]), isNull);
|
||||
});
|
||||
|
||||
test('a truncated header is not ours', () {
|
||||
expect(parseCapabilityAdvertReply([cmdOffbandDeviceUi]), isNull);
|
||||
expect(parseCapabilityAdvertReply(const <int>[]), isNull);
|
||||
});
|
||||
|
||||
test('the 0x7F error frame is NOT parsed as an advert', () {
|
||||
// The fallback path depends on this error reaching the error handler
|
||||
// rather than being swallowed here as an empty advert. An empty advert
|
||||
// and "predates the advert" gate differently.
|
||||
expect(
|
||||
parseCapabilityAdvertReply([cmdOffbandDeviceUi, offbandUiErr, 0x05]),
|
||||
isNull,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
group('records', () {
|
||||
test('a reply with no records is valid and not an error', () {
|
||||
// What a cursor above every available tag returns.
|
||||
final advert = parseCapabilityAdvertReply([
|
||||
cmdOffbandDeviceUi,
|
||||
offbandUiInfoGet,
|
||||
]);
|
||||
expect(advert, isNotNull);
|
||||
expect(advert!.tags, isEmpty);
|
||||
expect(advert.malformed, isFalse);
|
||||
expect(advert.continueCursor, isNull);
|
||||
});
|
||||
|
||||
test('a len 0 record means SUPPORTED, not empty and not absent', () {
|
||||
// The normal case, and the one most likely to be broken by someone
|
||||
// treating the value rather than the key as the answer.
|
||||
final advert = parseCapabilityAdvertReply([
|
||||
cmdOffbandDeviceUi,
|
||||
offbandUiInfoGet,
|
||||
offbandInfoTagChanNotify,
|
||||
0x00,
|
||||
])!;
|
||||
expect(advert.has(offbandInfoTagChanNotify), isTrue);
|
||||
expect(advert.tags[offbandInfoTagChanNotify], isEmpty);
|
||||
expect(advert.malformed, isFalse);
|
||||
});
|
||||
|
||||
test('an absent tag is absent, and is not a zero value', () {
|
||||
final advert = parseCapabilityAdvertReply([
|
||||
cmdOffbandDeviceUi,
|
||||
offbandUiInfoGet,
|
||||
offbandInfoTagChanNotify,
|
||||
0x00,
|
||||
])!;
|
||||
expect(advert.has(offbandInfoTagDisplayRotation), isFalse);
|
||||
expect(advert.byteValue(offbandInfoTagDisplayRotation), isNull);
|
||||
});
|
||||
|
||||
test('several records parse, and a carried value is readable', () {
|
||||
final advert = parseCapabilityAdvertReply([
|
||||
cmdOffbandDeviceUi,
|
||||
offbandUiInfoGet,
|
||||
offbandInfoTagChanNotify,
|
||||
0x00,
|
||||
offbandInfoTagDisplayRotation,
|
||||
0x00,
|
||||
offbandInfoTagAckCapacity,
|
||||
0x01,
|
||||
0x10,
|
||||
])!;
|
||||
expect(advert.has(offbandInfoTagChanNotify), isTrue);
|
||||
expect(advert.has(offbandInfoTagDisplayRotation), isTrue);
|
||||
expect(advert.byteValue(offbandInfoTagAckCapacity), 0x10);
|
||||
expect(advert.malformed, isFalse);
|
||||
});
|
||||
|
||||
test(
|
||||
'byteValue is null for a multi-byte or empty value, never coerced',
|
||||
() {
|
||||
final advert = parseCapabilityAdvertReply([
|
||||
cmdOffbandDeviceUi,
|
||||
offbandUiInfoGet,
|
||||
offbandInfoTagChanNotify,
|
||||
0x00,
|
||||
0x40,
|
||||
0x02,
|
||||
0xAA,
|
||||
0xBB,
|
||||
])!;
|
||||
expect(advert.byteValue(offbandInfoTagChanNotify), isNull);
|
||||
expect(advert.byteValue(0x40), isNull);
|
||||
},
|
||||
);
|
||||
|
||||
test(
|
||||
'position is never relied on, so out-of-order records still parse',
|
||||
() {
|
||||
// "Clients MUST NOT rely on record position. Ascending order exists for
|
||||
// the cursor, not for counting."
|
||||
final advert = parseCapabilityAdvertReply([
|
||||
cmdOffbandDeviceUi,
|
||||
offbandUiInfoGet,
|
||||
offbandInfoTagAckCapacity,
|
||||
0x01,
|
||||
0x08,
|
||||
offbandInfoTagChanNotify,
|
||||
0x00,
|
||||
])!;
|
||||
expect(advert.has(offbandInfoTagChanNotify), isTrue);
|
||||
expect(advert.byteValue(offbandInfoTagAckCapacity), 0x08);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
group('unknown tags', () {
|
||||
test('an unknown tag is skipped by len and the rest still parses', () {
|
||||
// LOAD-BEARING. Firmware will emit tags this build has never heard of.
|
||||
// A client that drops the frame, or that loses the records after the
|
||||
// unknown one, stops working the day firmware grows a feature.
|
||||
final advert = parseCapabilityAdvertReply([
|
||||
cmdOffbandDeviceUi,
|
||||
offbandUiInfoGet,
|
||||
0x55,
|
||||
0x03,
|
||||
0xDE,
|
||||
0xAD,
|
||||
0xBE,
|
||||
offbandInfoTagChanNotify,
|
||||
0x00,
|
||||
])!;
|
||||
expect(advert.has(offbandInfoTagChanNotify), isTrue);
|
||||
expect(advert.has(0x55), isTrue);
|
||||
expect(advert.malformed, isFalse);
|
||||
});
|
||||
|
||||
test('an unknown zero-length tag does not stall the parse', () {
|
||||
final advert = parseCapabilityAdvertReply([
|
||||
cmdOffbandDeviceUi,
|
||||
offbandUiInfoGet,
|
||||
0x7E,
|
||||
0x00,
|
||||
0x7F,
|
||||
0x00,
|
||||
offbandInfoTagDisplayRotation,
|
||||
0x00,
|
||||
])!;
|
||||
expect(advert.has(offbandInfoTagDisplayRotation), isTrue);
|
||||
expect(advert.malformed, isFalse);
|
||||
});
|
||||
|
||||
test('a long run of unknown tags is all kept', () {
|
||||
final frame = <int>[cmdOffbandDeviceUi, offbandUiInfoGet];
|
||||
for (var tag = 0x20; tag < 0x30; tag++) {
|
||||
frame.addAll([tag, 0x01, tag]);
|
||||
}
|
||||
frame.addAll([offbandInfoTagChanNotify, 0x00]);
|
||||
final advert = parseCapabilityAdvertReply(frame)!;
|
||||
expect(advert.has(offbandInfoTagChanNotify), isTrue);
|
||||
expect(advert.byteValue(0x2F), 0x2F);
|
||||
expect(advert.malformed, isFalse);
|
||||
});
|
||||
});
|
||||
|
||||
group('malformed', () {
|
||||
test(
|
||||
'a record running past the frame keeps the good records before it',
|
||||
() {
|
||||
// Firmware must not split a record across frames, so this is a firmware
|
||||
// fault. Capability absence is safe (the feature hides); discarding a
|
||||
// whole good reply over a bad trailing byte is not.
|
||||
final advert = parseCapabilityAdvertReply([
|
||||
cmdOffbandDeviceUi,
|
||||
offbandUiInfoGet,
|
||||
offbandInfoTagChanNotify,
|
||||
0x00,
|
||||
offbandInfoTagAckCapacity,
|
||||
0x04,
|
||||
0x01,
|
||||
])!;
|
||||
expect(advert.has(offbandInfoTagChanNotify), isTrue);
|
||||
expect(advert.has(offbandInfoTagAckCapacity), isFalse);
|
||||
expect(advert.malformed, isTrue);
|
||||
},
|
||||
);
|
||||
|
||||
test('a tag with no length byte is malformed, earlier records survive', () {
|
||||
final advert = parseCapabilityAdvertReply([
|
||||
cmdOffbandDeviceUi,
|
||||
offbandUiInfoGet,
|
||||
offbandInfoTagChanNotify,
|
||||
0x00,
|
||||
offbandInfoTagDisplayRotation,
|
||||
])!;
|
||||
expect(advert.has(offbandInfoTagChanNotify), isTrue);
|
||||
expect(advert.has(offbandInfoTagDisplayRotation), isFalse);
|
||||
expect(advert.malformed, isTrue);
|
||||
});
|
||||
|
||||
test('tag 0x00 is not valid and stops the parse', () {
|
||||
final advert = parseCapabilityAdvertReply([
|
||||
cmdOffbandDeviceUi,
|
||||
offbandUiInfoGet,
|
||||
offbandInfoTagChanNotify,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
])!;
|
||||
expect(advert.has(offbandInfoTagChanNotify), isTrue);
|
||||
expect(advert.malformed, isTrue);
|
||||
});
|
||||
|
||||
test('a repeated tag keeps the FIRST value and is flagged', () {
|
||||
// A later record must not silently redefine a capability.
|
||||
final advert = parseCapabilityAdvertReply([
|
||||
cmdOffbandDeviceUi,
|
||||
offbandUiInfoGet,
|
||||
offbandInfoTagAckCapacity,
|
||||
0x01,
|
||||
0x08,
|
||||
offbandInfoTagAckCapacity,
|
||||
0x01,
|
||||
0x40,
|
||||
])!;
|
||||
expect(advert.byteValue(offbandInfoTagAckCapacity), 0x08);
|
||||
expect(advert.malformed, isTrue);
|
||||
});
|
||||
});
|
||||
|
||||
group('continuation', () {
|
||||
test('TAG_CONTINUE yields the cursor and the records before it', () {
|
||||
final advert = parseCapabilityAdvertReply([
|
||||
cmdOffbandDeviceUi,
|
||||
offbandUiInfoGet,
|
||||
offbandInfoTagChanNotify,
|
||||
0x00,
|
||||
offbandInfoTagContinue,
|
||||
0x01,
|
||||
offbandInfoTagAckCapacity,
|
||||
])!;
|
||||
expect(advert.has(offbandInfoTagChanNotify), isTrue);
|
||||
expect(advert.continueCursor, offbandInfoTagAckCapacity);
|
||||
expect(advert.malformed, isFalse);
|
||||
});
|
||||
|
||||
test('a reply without TAG_CONTINUE is complete', () {
|
||||
final advert = parseCapabilityAdvertReply([
|
||||
cmdOffbandDeviceUi,
|
||||
offbandUiInfoGet,
|
||||
offbandInfoTagChanNotify,
|
||||
0x00,
|
||||
])!;
|
||||
expect(advert.continueCursor, isNull);
|
||||
});
|
||||
|
||||
test('TAG_CONTINUE with a length other than 1 is malformed', () {
|
||||
final advert = parseCapabilityAdvertReply([
|
||||
cmdOffbandDeviceUi,
|
||||
offbandUiInfoGet,
|
||||
offbandInfoTagContinue,
|
||||
0x02,
|
||||
0x01,
|
||||
0x02,
|
||||
])!;
|
||||
expect(advert.continueCursor, isNull);
|
||||
expect(advert.malformed, isTrue);
|
||||
});
|
||||
|
||||
test('records after TAG_CONTINUE are flagged, not guessed at', () {
|
||||
final advert = parseCapabilityAdvertReply([
|
||||
cmdOffbandDeviceUi,
|
||||
offbandUiInfoGet,
|
||||
offbandInfoTagContinue,
|
||||
0x01,
|
||||
0x03,
|
||||
offbandInfoTagChanNotify,
|
||||
0x00,
|
||||
])!;
|
||||
expect(advert.continueCursor, 0x03);
|
||||
expect(advert.malformed, isTrue);
|
||||
expect(advert.has(offbandInfoTagChanNotify), isFalse);
|
||||
});
|
||||
|
||||
test('the continuation ceiling is bounded', () {
|
||||
// An unbounded request loop driven by device data is a worse failure
|
||||
// than a truncated capability list.
|
||||
expect(offbandInfoMaxContinuations, greaterThan(0));
|
||||
expect(offbandInfoMaxContinuations, lessThanOrEqualTo(16));
|
||||
});
|
||||
});
|
||||
|
||||
group('the registry numbers', () {
|
||||
test('every tag and the sub-code match the merged firmware header', () {
|
||||
// Transcribed from `OffbandConfigProtocol.h` on `firmware-base` at
|
||||
// `28785ebf`. Do not "fix" a failure here by editing the expectation to
|
||||
// match the code: read the header.
|
||||
expect(offbandUiInfoGet, 0x1C);
|
||||
expect(offbandInfoTagChanNotify, 0x01);
|
||||
expect(offbandInfoTagDisplayRotation, 0x02);
|
||||
expect(offbandInfoTagAckCapacity, 0x03);
|
||||
expect(offbandInfoTagContinue, 0xFF);
|
||||
});
|
||||
});
|
||||
}
|
||||
@ -0,0 +1,188 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:meshcore_open/connector/meshcore_protocol.dart';
|
||||
import 'package:meshcore_open/connector/offband_capability_advert.dart';
|
||||
import 'package:meshcore_open/connector/offband_channel_notify.dart';
|
||||
import 'package:meshcore_open/connector/offband_device_ui.dart';
|
||||
import 'package:meshcore_open/connector/offband_screen_settings.dart';
|
||||
import 'package:meshcore_open/connector/offband_tones.dart';
|
||||
|
||||
/// #1093: the mechanical check that was missing when two sessions both built
|
||||
/// on `0xC5` sub-codes 0x18/0x19.
|
||||
///
|
||||
/// Nothing failed when that happened. Both features compiled, both passed
|
||||
/// their own tests, both reviewed clean, and the collision would only have
|
||||
/// appeared on the owner's hardware as one feature mis-dispatching in a way
|
||||
/// that looked like either one being broken. The root cause was that
|
||||
/// `firmware-base` stopped at 0x0A, so every allocation from 0x0B to 0x19 lived
|
||||
/// only on unmerged branches and "take the next free pair" was unanswerable
|
||||
/// from the merged tree.
|
||||
///
|
||||
/// That is now fixed at the source: firmware
|
||||
/// `docs/offband_info_frame_contract.md` §2 requires a number to be merged to
|
||||
/// `firmware-base` BEFORE a plan using it is approved and before any work
|
||||
/// begins, and the claims live in a merged header the compiler reads.
|
||||
///
|
||||
/// This file is the client half: it fails if the client ever double-books a
|
||||
/// sub-code, and it fails if the client drifts from the firmware registry.
|
||||
///
|
||||
/// THE AUTHORITY for this table is firmware
|
||||
/// `examples/companion_radio/OffbandConfigProtocol.h`. Transcribed from
|
||||
/// `28785ebf` on `firmware-base`, the merge of PR
|
||||
/// OffbandMesh/meshcore-firmware#2000 ("claim the wire numbers for the three
|
||||
/// offset-87 features"), 2026-11-04.
|
||||
/// `[verified: 2026-11-04, git show origin/firmware-base:...]`
|
||||
///
|
||||
/// When firmware allocates a new code, update this table in the same change
|
||||
/// that consumes it, and say in the PR which firmware commit you transcribed.
|
||||
/// Do not "fix" a failure here by editing the expectation to match the code.
|
||||
void main() {
|
||||
/// Every `0xC5` sub-code the firmware registry allocates, with the name the
|
||||
/// registry gives it. Codes firmware owns but the client does not implement
|
||||
/// are listed too, so a future session cannot take one believing it free.
|
||||
const registry = <int, String>{
|
||||
0x01: 'SCOPE_GET',
|
||||
0x02: 'SCOPE_SET',
|
||||
0x03: 'MATRIX_GET',
|
||||
0x04: 'MATRIX_SET',
|
||||
0x05: 'DISPLAY_GET', // #542, firmware-side only so far
|
||||
0x06: 'DISPLAY_SET', // #542, firmware-side only so far
|
||||
0x07: 'LED_GET', // #542, firmware-side only so far
|
||||
0x08: 'LED_SET', // #542, firmware-side only so far
|
||||
0x09: 'SLOT_GET',
|
||||
0x0A: 'SLOT_SET',
|
||||
0x0B: 'CHTUNE_GET',
|
||||
0x0C: 'CHTUNE_SET',
|
||||
0x0D: 'GPS_GET',
|
||||
0x0E: 'GPS_SET',
|
||||
0x0F: 'EVTONE_GET',
|
||||
0x10: 'EVTONE_SET',
|
||||
0x11: 'TUNE_PLAY',
|
||||
0x12: 'SLOT_READ',
|
||||
0x13: 'SCREEN_GET',
|
||||
0x14: 'TEXT_SET',
|
||||
0x15: 'SCROFF_SET',
|
||||
0x16: 'TZ_SET',
|
||||
0x17: 'BATT_SET',
|
||||
0x18: 'CHNOTIFY_GET',
|
||||
0x19: 'CHNOTIFY_SET',
|
||||
0x1A: 'ROTATION_GET',
|
||||
0x1B: 'ROTATION_SET',
|
||||
0x1C: 'INFO_GET',
|
||||
0x7F: 'ERR',
|
||||
};
|
||||
|
||||
/// What the client actually emits, by constant. Add a row here whenever a
|
||||
/// new sub-code constant is introduced anywhere in `lib/connector/`.
|
||||
const clientUses = <String, int>{
|
||||
'offbandUiScopeGet': offbandUiScopeGet,
|
||||
'offbandUiScopeSet': offbandUiScopeSet,
|
||||
'offbandUiMatrixGet': offbandUiMatrixGet,
|
||||
'offbandUiMatrixSet': offbandUiMatrixSet,
|
||||
'offbandUiSlotGet': offbandUiSlotGet,
|
||||
'offbandUiSlotSet': offbandUiSlotSet,
|
||||
'offbandUiChannelTuneGet': offbandUiChannelTuneGet,
|
||||
'offbandUiChannelTuneSet': offbandUiChannelTuneSet,
|
||||
'offbandUiGpsGet': offbandUiGpsGet,
|
||||
'offbandUiGpsSet': offbandUiGpsSet,
|
||||
'offbandUiEventToneGet': offbandUiEventToneGet,
|
||||
'offbandUiEventToneSet': offbandUiEventToneSet,
|
||||
'offbandUiTunePlay': offbandUiTunePlay,
|
||||
'offbandUiSlotRead': offbandUiSlotRead,
|
||||
'offbandUiScreenGet': offbandUiScreenGet,
|
||||
'offbandUiTextSet': offbandUiTextSet,
|
||||
'offbandUiScreenOffSet': offbandUiScreenOffSet,
|
||||
'offbandUiTimeZoneSet': offbandUiTimeZoneSet,
|
||||
'offbandUiBatterySet': offbandUiBatterySet,
|
||||
'offbandUiChannelNotifyGet': offbandUiChannelNotifyGet,
|
||||
'offbandUiChannelNotifySet': offbandUiChannelNotifySet,
|
||||
'offbandUiInfoGet': offbandUiInfoGet,
|
||||
'offbandUiErr': offbandUiErr,
|
||||
};
|
||||
|
||||
test('no two client sub-codes share a value', () {
|
||||
// THE CHECK THAT WAS MISSING. #523 rotation and #544 channel notify both
|
||||
// took 0x18/0x19; had both landed in the client, this would have caught it
|
||||
// before any hardware saw it.
|
||||
final byValue = <int, List<String>>{};
|
||||
clientUses.forEach((name, code) {
|
||||
byValue.putIfAbsent(code, () => []).add(name);
|
||||
});
|
||||
final doubled = byValue.entries.where((e) => e.value.length > 1).toList();
|
||||
|
||||
expect(
|
||||
doubled,
|
||||
isEmpty,
|
||||
reason: doubled
|
||||
.map(
|
||||
(e) =>
|
||||
'0x${e.key.toRadixString(16).padLeft(2, '0')} is claimed by '
|
||||
'${e.value.join(" and ")}',
|
||||
)
|
||||
.join('; '),
|
||||
);
|
||||
});
|
||||
|
||||
test('every client sub-code is one firmware actually allocates', () {
|
||||
// Catches a code invented client-side, which is how a session takes a
|
||||
// number firmware has already spent on an unmerged branch.
|
||||
clientUses.forEach((name, code) {
|
||||
expect(
|
||||
registry.containsKey(code),
|
||||
isTrue,
|
||||
reason:
|
||||
'$name uses 0x${code.toRadixString(16).padLeft(2, '0')}, which is '
|
||||
'not in the firmware registry. Get it allocated in '
|
||||
'OffbandConfigProtocol.h and MERGED before shipping it.',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
test('the client has not drifted from the registry on a shared code', () {
|
||||
// Pins the specific pairs most likely to be re-allocated under pressure.
|
||||
expect(registry[offbandUiChannelNotifyGet], 'CHNOTIFY_GET');
|
||||
expect(registry[offbandUiChannelNotifySet], 'CHNOTIFY_SET');
|
||||
expect(registry[offbandUiChannelTuneGet], 'CHTUNE_GET');
|
||||
expect(registry[offbandUiChannelTuneSet], 'CHTUNE_SET');
|
||||
expect(registry[offbandUiInfoGet], 'INFO_GET');
|
||||
expect(registry[offbandUiErr], 'ERR');
|
||||
});
|
||||
|
||||
test(
|
||||
'rotation owns 0x1A/0x1B and the client never sends it on 0x18/0x19',
|
||||
() {
|
||||
// The collision, pinned. A rotation SET on 0x18/0x19 against firmware
|
||||
// 4e5a6c85 writes a valid channel-notify mode onto channel slot 0, which
|
||||
// is Public and undeletable, and both sides report success.
|
||||
expect(registry[0x1A], 'ROTATION_GET');
|
||||
expect(registry[0x1B], 'ROTATION_SET');
|
||||
expect(offbandUiChannelNotifyGet, 0x18);
|
||||
expect(offbandUiChannelNotifySet, 0x19);
|
||||
},
|
||||
);
|
||||
|
||||
test('0x1D is the next free sub-code', () {
|
||||
// Recorded so the next feature does not repeat the guess. The header says
|
||||
// it in terms: "Next free sub-code: 0x1D. 0x7F is OFFBAND_UI_ERR and is
|
||||
// not available."
|
||||
expect(registry.containsKey(0x1D), isFalse);
|
||||
expect(clientUses.values.contains(0x1D), isFalse);
|
||||
});
|
||||
|
||||
test('the advert tags match the merged registry', () {
|
||||
expect(offbandInfoTagChanNotify, 0x01);
|
||||
expect(offbandInfoTagDisplayRotation, 0x02);
|
||||
expect(offbandInfoTagAckCapacity, 0x03);
|
||||
expect(offbandInfoTagContinue, 0xFF);
|
||||
});
|
||||
|
||||
test('caps2 0x80 is the last capability bit, and no byte 3 follows it', () {
|
||||
// Contract §2, permanent: no Offband field is appended to upstream's
|
||||
// device-info frame, ever. Capabilities past this bit are advert TAGS.
|
||||
//
|
||||
// This asserts the bit value only. The real guard that offset 87 is no
|
||||
// longer read is behavioural and lives in
|
||||
// channel_notify_connector_test.dart group A3, because a constant test
|
||||
// cannot prove the absence of a read.
|
||||
expect(offbandCap2ChannelNotify, 0x80);
|
||||
});
|
||||
}
|
||||
@ -0,0 +1,117 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:meshcore_open/connector/offband_channel_notify.dart';
|
||||
import 'package:meshcore_open/connector/offband_device_ui.dart';
|
||||
import 'package:meshcore_open/l10n/app_localizations.dart';
|
||||
import 'package:meshcore_open/widgets/radio_channel_notify.dart';
|
||||
|
||||
/// #544 Epic C task C3: what a channel row says the RADIO will actually do.
|
||||
///
|
||||
/// The owner's call (2026-11-03) was to show the composed result rather than
|
||||
/// the raw stored byte. This pins the composition, because getting it wrong is
|
||||
/// a lie to the user rather than a cosmetic slip: a muted radio showing a
|
||||
/// channel as "All messages" is exactly the confusion this feature exists to
|
||||
/// end.
|
||||
///
|
||||
/// Firmware's rules, per AM 1406: a channel with a mode set decides for
|
||||
/// itself; a channel with no mode falls back to the device-wide scope; a
|
||||
/// device scope of None overrides even a channel that is set.
|
||||
void main() {
|
||||
/// Resolves [radioChannelNotifyEffective] inside a localized context.
|
||||
Future<String?> effective(
|
||||
WidgetTester tester,
|
||||
RadioChannelNotify? mode,
|
||||
DeviceNotifyScope? scope,
|
||||
) async {
|
||||
String? result;
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: Builder(
|
||||
builder: (context) {
|
||||
result = radioChannelNotifyEffective(context, mode, scope);
|
||||
return const SizedBox.shrink();
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
return result;
|
||||
}
|
||||
|
||||
testWidgets('a set mode decides for itself', (tester) async {
|
||||
expect(
|
||||
await effective(tester, RadioChannelNotify.all, DeviceNotifyScope.self),
|
||||
'All messages',
|
||||
);
|
||||
expect(
|
||||
await effective(
|
||||
tester,
|
||||
RadioChannelNotify.mentions,
|
||||
DeviceNotifyScope.all,
|
||||
),
|
||||
'Mentions only',
|
||||
);
|
||||
expect(
|
||||
await effective(tester, RadioChannelNotify.off, DeviceNotifyScope.all),
|
||||
'Off',
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('an unset mode follows the device scope, named', (tester) async {
|
||||
expect(
|
||||
await effective(tester, RadioChannelNotify.unset, DeviceNotifyScope.self),
|
||||
'Follows the radio: Self',
|
||||
);
|
||||
expect(
|
||||
await effective(tester, RadioChannelNotify.unset, DeviceNotifyScope.all),
|
||||
'Follows the radio: All',
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('a device scope of None overrides even a set channel', (
|
||||
tester,
|
||||
) async {
|
||||
// The case that makes this composition load-bearing. A user who has muted
|
||||
// the radio must not be told a channel is on "All messages".
|
||||
expect(
|
||||
await effective(tester, RadioChannelNotify.all, DeviceNotifyScope.none),
|
||||
'Silent: the radio is set to None',
|
||||
);
|
||||
expect(
|
||||
await effective(
|
||||
tester,
|
||||
RadioChannelNotify.mentions,
|
||||
DeviceNotifyScope.none,
|
||||
),
|
||||
'Silent: the radio is set to None',
|
||||
);
|
||||
expect(
|
||||
await effective(tester, RadioChannelNotify.unset, DeviceNotifyScope.none),
|
||||
'Silent: the radio is set to None',
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('nothing is claimed before the radio has answered', (
|
||||
tester,
|
||||
) async {
|
||||
// Null means "cannot be known yet", and the caller shows a reading state.
|
||||
// It must never resolve to a mode we invented.
|
||||
expect(await effective(tester, null, DeviceNotifyScope.all), isNull);
|
||||
expect(await effective(tester, null, null), isNull);
|
||||
expect(
|
||||
await effective(tester, RadioChannelNotify.unset, null),
|
||||
isNull,
|
||||
reason: 'unset with an unknown scope composes to nothing truthful',
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('a set mode resolves without the scope being known', (
|
||||
tester,
|
||||
) async {
|
||||
// A channel that decides for itself does not need the device scope, so it
|
||||
// is shown immediately rather than waiting on a second read.
|
||||
expect(await effective(tester, RadioChannelNotify.off, null), 'Off');
|
||||
});
|
||||
}
|
||||
Loading…
Reference in new issue