feat(Player,MQTT): add pid/speed/duration/started_at/source/ts to status/playback (F-064)
The remote phone app treats status/playback as the source of truth for what the board is doing, but the payload couldn't say what was playing, and a client receiving a stale retained message couldn't work out real elapsed time. Adds (old fields kept): - pid, speed, duration (effective stop timer after mode/legacy resolution) - started_at / ts — Unix epoch s (UTC); system clock once NTP-synced, else new Timekeeper::getUtcEpoch() (RTC local time minus configured offsets), else 0 - source — app | rf | button | schedule | unknown. Carried, not guessed: new CommandEnvelope::origin set by each transport (MQTT/WS/HTTP → APP, UART slave board → BUTTON), mapped by PlaybackHandler; RFRemote passes RF New PlaybackState.hpp has one PlaybackSnapshot::writeTo() used for both the WebSocket INFO broadcast (under "payload") and MQTT status/playback (flat), so local and remote clients match. publishPlayback() now honours the hasHeapForPublish() guard before building the document. Bumps FW_VERSION to 2.3.0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -16,12 +16,23 @@ CommandResult PlaybackHandler::execute(const CommandEnvelope& envelope) {
|
||||
return CommandResult::err("playback", "Unknown playback command");
|
||||
}
|
||||
|
||||
// Carry the command's origin through to the Player so status/playback can
|
||||
// report what triggered playback (see PlaybackState.hpp).
|
||||
static PlaybackSource sourceFromOrigin(CommandEnvelope::Origin origin) {
|
||||
switch (origin) {
|
||||
case CommandEnvelope::Origin::APP: return PlaybackSource::APP;
|
||||
case CommandEnvelope::Origin::BUTTON: return PlaybackSource::BUTTON;
|
||||
case CommandEnvelope::Origin::SCHEDULE: return PlaybackSource::SCHEDULE;
|
||||
default: return PlaybackSource::UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
CommandResult PlaybackHandler::handlePlay(const CommandEnvelope& envelope) {
|
||||
// Inject action so Player::command() takes the play branch regardless of
|
||||
// whether it was set by the V1 adapter or arrived as a bare V2 play command.
|
||||
JsonDocument& contents = const_cast<JsonDocument&>(envelope.contents);
|
||||
contents["action"] = "play";
|
||||
bool ok = _player.command(contents.as<JsonVariant>());
|
||||
bool ok = _player.command(contents.as<JsonVariant>(), sourceFromOrigin(envelope.origin));
|
||||
if (ok) return CommandResult::ok("playback", "Playback command executed");
|
||||
return CommandResult::err("playback", "Playback command failed");
|
||||
}
|
||||
@@ -29,7 +40,7 @@ CommandResult PlaybackHandler::handlePlay(const CommandEnvelope& envelope) {
|
||||
CommandResult PlaybackHandler::handleStop(const CommandEnvelope& envelope) {
|
||||
JsonDocument& contents = const_cast<JsonDocument&>(envelope.contents);
|
||||
contents["action"] = "stop";
|
||||
bool ok = _player.command(contents.as<JsonVariant>());
|
||||
bool ok = _player.command(contents.as<JsonVariant>(), sourceFromOrigin(envelope.origin));
|
||||
if (ok) return CommandResult::ok("playback", "Playback command executed");
|
||||
return CommandResult::err("playback", "Playback command failed");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user