Replace separate accel/tap snapshot UART commands with one clients[] response that omits unsubscribed fields; remove snapshot handlers and CLI commands. Add goTool/docs for WebSocket streams and REST; tap-snapshot REST uses CACHE_STATUS. Co-authored-by: Cursor <cursoragent@cursor.com>
93 lines
2.4 KiB
C
93 lines
2.4 KiB
C
#include "client_registry.h"
|
|
#include "cmd_cache_status.h"
|
|
#include "uart_cmd.h"
|
|
|
|
static const char *TAG = "[CACHE_STAT]";
|
|
|
|
static bool tap_notify_any(const client_info_t *client) {
|
|
return client != NULL &&
|
|
(client->tap_notify_single || client->tap_notify_double ||
|
|
client->tap_notify_triple);
|
|
}
|
|
|
|
static alox_TapKind tap_kind_from_registry(uint32_t kind) {
|
|
switch (kind) {
|
|
case 1:
|
|
return alox_TapKind_TAP_SINGLE;
|
|
case 2:
|
|
return alox_TapKind_TAP_DOUBLE;
|
|
case 3:
|
|
return alox_TapKind_TAP_TRIPLE;
|
|
default:
|
|
return alox_TapKind_TAP_NONE;
|
|
}
|
|
}
|
|
|
|
static void fill_cache_status(alox_CacheStatusResponse *out) {
|
|
if (out == NULL) {
|
|
return;
|
|
}
|
|
|
|
out->clients_count = 0;
|
|
|
|
size_t count = client_registry_count();
|
|
for (size_t i = 0; i < count; i++) {
|
|
const client_info_t *client = client_registry_at(i);
|
|
if (client == NULL) {
|
|
continue;
|
|
}
|
|
|
|
const bool want_accel = client->accel_stream_enabled;
|
|
const bool want_tap = tap_notify_any(client);
|
|
if (!want_accel && !want_tap) {
|
|
continue;
|
|
}
|
|
if (out->clients_count >=
|
|
sizeof(out->clients) / sizeof(out->clients[0])) {
|
|
break;
|
|
}
|
|
|
|
alox_CacheClientStatus *entry = &out->clients[out->clients_count++];
|
|
entry->client_id = client->id;
|
|
entry->has_accel = false;
|
|
entry->has_tap = false;
|
|
|
|
if (want_accel) {
|
|
entry->has_accel = true;
|
|
entry->accel.valid = client->accel_valid;
|
|
if (client->accel_valid) {
|
|
entry->accel.x = client->accel_x;
|
|
entry->accel.y = client->accel_y;
|
|
entry->accel.z = client->accel_z;
|
|
entry->accel.age_ms =
|
|
client_registry_ms_since(client->accel_updated_at);
|
|
}
|
|
}
|
|
|
|
if (want_tap) {
|
|
uint32_t kind = 0;
|
|
uint32_t age_ms = 0;
|
|
if (client_registry_take_tap(client->id, &kind, &age_ms)) {
|
|
entry->has_tap = true;
|
|
entry->tap.kind = tap_kind_from_registry(kind);
|
|
entry->tap.age_ms = age_ms;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
static void handle_cache_status(const uint8_t *data, size_t len) {
|
|
(void)data;
|
|
(void)len;
|
|
|
|
alox_UartMessage response;
|
|
uart_cmd_init_response(&response, alox_MessageType_CACHE_STATUS,
|
|
alox_UartMessage_cache_status_response_tag);
|
|
fill_cache_status(&response.payload.cache_status_response);
|
|
uart_cmd_send(&response, TAG);
|
|
}
|
|
|
|
void cmd_cache_status_register(void) {
|
|
uart_cmd_register(alox_MessageType_CACHE_STATUS, handle_cache_status);
|
|
}
|