feat(Player,PlaybackHandler): specific ACK messages for playback.play/stop (F-067)
Every rejection used to reach the caller as "Playback command failed".
Player::command() now returns PlayerCommandResult { ok, message } and
PlaybackHandler forwards the message verbatim:
- busy, missing pid, invalid speed / note_assignments / durations / mode,
timed|interval without duration, bells disabled, bell overload lockout,
melody failed to load (incl. 0-byte file), not found without url,
needs download but no SD card
- success: "Playback started", "Melody download started — …",
"Playback stopped", and "Already stopped" (stop while idle stays SUCCESS —
idempotent, goal state reached)
Validation runs before setMelodyAttributes(), so a rejected play no longer
half-applies its fields. Also fixes: url was sticky (a later play of another
pid could download the old URL under the new name); bells.disable let a play
"succeed" and report playing with silent bells; a non-string name/pid
assigned nullptr to std::string.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -79,6 +79,7 @@ Check `git log -- src/Version.hpp` for the real bump history before tagging a ne
|
||||
| F-064 | Richer `status/playback` — `pid`, `speed`, `duration`, `started_at`, `source`, `ts` (same fields on the WebSocket playback INFO event); command origin carried on `CommandEnvelope` | v2.3.0 | Stable |
|
||||
| F-065 | `stopping` playback state formally documented (duration reached, bells finishing the current loop) — kept on `status/playback`, not suppressed | v2.3.0 | Stable |
|
||||
| F-066 | Fix: stale retained `status/playback` — republished with the Player's real state on every MQTT (re)connect | v2.3.0 | Stable |
|
||||
| F-067 | Specific `playback.play` / `playback.stop` ACK messages (busy, invalid params, not found, load failed, bells disabled, overload…) instead of a generic "Playback command failed"; `url` no longer sticky | v2.3.0 | Stable |
|
||||
|
||||
---
|
||||
|
||||
@@ -1239,3 +1240,55 @@ switch, heap guard.
|
||||
Verified: `pio run -e vesper-std-v1` builds clean.
|
||||
|
||||
Subsystem: `src/Communication/CommunicationRouter/CommunicationRouter.cpp`
|
||||
|
||||
---
|
||||
|
||||
### F-067 — Specific playback ACK messages
|
||||
|
||||
`Player::command()` returned a bare `bool`, so every rejection reached the caller as
|
||||
`"Playback command failed"` and every success as `"Playback command executed"` — the phone app couldn't
|
||||
tell "already playing" from "melody missing" from "bells switched off".
|
||||
|
||||
**Now** `Player::command()` returns `PlayerCommandResult { ok, message }` and `PlaybackHandler` sends
|
||||
`message` verbatim. All strings are constants at the top of `Player.cpp` (plus the per-field
|
||||
`Invalid <field>: …` validation messages) and are listed exhaustively, in check order, in
|
||||
api-reference.md → `playback.play` and the console page. Reply `type` stays `"playback"`.
|
||||
|
||||
Success: `Playback started`, `Melody download started — playback begins when it completes`,
|
||||
`Playback stopped`, `Already stopped`.
|
||||
|
||||
**Decision — stop when already idle is SUCCESS** (`"Already stopped"`), not an error: stop is idempotent,
|
||||
the caller's goal state is reached, and an app's stop button shouldn't have to special-case an error.
|
||||
The distinct message still lets a client tell the two apart.
|
||||
|
||||
**Behaviour changes that come with it:**
|
||||
- Up-front validation (`Player::validatePlayParams()`) runs **before** `setMelodyAttributes()`, so a
|
||||
rejected play no longer half-applies its fields to the sticky state. New rejections that used to be
|
||||
silently accepted: `speed` outside 0–65535 (used to wrap), `note_assignments` that isn't an array of
|
||||
≤16 ints in 0–16 (extras used to be ignored), negative/non-integer durations (used to wrap to huge
|
||||
unsigned values), unknown `mode` (used to fall back to `single`), `timed`/`interval` with
|
||||
`duration` 0 (`interval` with 0 re-paused on every timer tick).
|
||||
- **Blocked gates** (`Player::playbackBlockedReason()`): `bells.disable` in effect (previously the
|
||||
command succeeded and status said `playing` while `BellEngine::start()` silently refused — new
|
||||
`BellEngine::areBellsEnabled()`), and any bell over its max load while the guard is on (the same
|
||||
condition `Telemetry::checkBellLoads()` force-stops on, so a start would be cut off within a second).
|
||||
- `loadMelodyInRAM()` returns the error string instead of `bool`, and now treats a **0-byte** SD file as
|
||||
`Melody failed to load` (previously it "loaded" zero steps, `play()` bailed silently and the command
|
||||
still returned success).
|
||||
- Needs-a-download on a build with no FileManager (agnus) is now rejected up front instead of
|
||||
queueing a download that could only fail.
|
||||
- **`url` is no longer sticky.** A URL left over from an earlier play was reused for a later play of a
|
||||
*different* `pid` that wasn't on SD, downloading the old melody's file and saving it under the new
|
||||
pid's name. Omitted `url` now means "no download for this play".
|
||||
- `name`/`pid`/`uid` are read with `| ""` — a non-string value used to assign `nullptr` to a
|
||||
`std::string` (undefined behaviour / crash).
|
||||
|
||||
Download failures still can't be ACK errors (the download runs after the reply, on `MelodyDL`) — see
|
||||
F-068 for how they are reported. RF-triggered plays log the rejection reason (`RF slot N play
|
||||
rejected: …`).
|
||||
|
||||
Verified: `pio run -e vesper-std-v1` and `pio run -e agnus-v1` build clean; ArduinoJson 7 type-check
|
||||
semantics used by the validator (`is<uint32_t>` on negatives/floats/2^32, `is<int>`, `| ""` on
|
||||
non-strings/null) confirmed with a host-side test.
|
||||
|
||||
Subsystem: `src/Player/Player.hpp`, `src/Player/Player.cpp`, `src/BellEngine/BellEngine.hpp`, `src/BellEngine/BellEngine.cpp`, `src/Communication/Handlers/PlaybackHandler/PlaybackHandler.hpp`, `src/Communication/Handlers/PlaybackHandler/PlaybackHandler.cpp`, `src/RFRemote/RFRemote.cpp`
|
||||
|
||||
Reference in New Issue
Block a user