PM5: add CMD_CEP_STATUS, a compact hardware-status snapshot

For the Flipper Zero FAP's status page: hw status/CMD_STATUS replies
entirely via free-text Dbprintf packets the FAP's frame layer discards,
with nothing structured on the terminating ack. CMD_CEP_STATUS follows
the CMD_CAPABILITIES precedent instead - one binary cep_status_t reply
covering CEP handshake state, BWM battery telemetry, and a firmware
version string.

Always replies PM3_SUCCESS; fields for a feature this build lacks
(no WITH_CEP, no WITH_BWM_STATUS) read as zero rather than failing the
command, so any client can call it unconditionally. cep_attached isn't
included yet - its getter (cep_is_attached()) only exists on the
not-yet-merged WFI-skip responsiveness branch (#3687); can be appended
later following capabilities_t's own append-only convention.

Stacked on the pm5-bwm-battery-telemetry branch (CMD_PM5_BWM_GET_BATTERY),
which this command's battery field reuses via bwm_read_battery_info().

Co-Authored-By: Claude Sonnet 5 <[email protected]>
This commit is contained in:
Tom Harkness
2026-10-04 14:42:29 +02:00
committed by Philippe Teuwen
co-authored by Claude Sonnet 5
parent 7bd39effbd
commit ac9c402e13
2 changed files with 31 additions and 0 deletions
+14
View File
@@ -4098,6 +4098,20 @@ static void PacketReceived(PacketCommandNG *packet) {
SendCapabilities();
break;
}
case CMD_CEP_STATUS: {
cep_status_t status = {0};
#ifdef WITH_CEP
status.cep_active = cep_is_active();
#endif
#ifdef WITH_BWM_STATUS
bwm_read_battery_info(&status.battery);
#endif
if (CheckValidInformationMagic(&g_version_information)) {
strncpy(status.fw_version, g_version_information.gitversion, sizeof(status.fw_version) - 1);
}
reply_ng(CMD_CEP_STATUS, PM3_SUCCESS, (uint8_t *)&status, sizeof(status));
break;
}
case CMD_PING: {
reply_ng(CMD_PING, PM3_SUCCESS, packet->data.asBytes, packet->length);
break;
+17
View File
@@ -1008,6 +1008,23 @@ typedef struct {
// underlying data source and by clients (e.g. the Flipper Zero FAP) that want the raw
// numbers instead of hw status's free-text Dbprintf lines.
#define CMD_PM5_BWM_GET_BATTERY 0x0184
// PM5, live hardware-status snapshot (CEP handshake state, battery telemetry,
// firmware version) for the Flipper Zero FAP's status page and any future
// client. Always answers PM3_SUCCESS with every field it can - fields for a
// feature this build doesn't have (no WITH_CEP, no WITH_BWM_STATUS) read as
// zero/false rather than the command failing. A client that also wants to
// distinguish "zero" from "not built" should check CMD_CAPABILITIES'
// compiled_with_cep/compiled_with_bwm first.
// req: none. resp: cep_status_t.
#define CMD_CEP_STATUS 0x0185
typedef struct {
uint8_t cep_active; // cep_is_active(): handshake complete, SPI transport live
bwm_battery_info_t battery; // bwm_read_battery_info(); all-zero if WITH_BWM_STATUS not built
char fw_version[24]; // g_version_information.gitversion, NUL-terminated, may truncate
// Appended in a future version once cep_is_attached() lands (PR #3687,
// not yet merged): a cep_attached byte distinguishing "physically
// present, handshake not yet complete" from "active".
} PACKED cep_status_t;
#define BWM_OTA_ACTION_BEGIN 0x00
#define BWM_OTA_ACTION_WRITE 0x01
#define BWM_OTA_ACTION_END 0x02