Unify cache polling on CACHE_STATUS and split API docs.
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>
This commit is contained in:
@@ -1,68 +0,0 @@
|
||||
#include "client_registry.h"
|
||||
#include "cmd_accel_snapshot.h"
|
||||
#include "uart_cmd.h"
|
||||
|
||||
static const char *TAG = "[ACCEL_SNAP]";
|
||||
|
||||
static void fill_accel_snapshot(alox_AccelSnapshotResponse *out,
|
||||
uint32_t filter_client_id) {
|
||||
if (out == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
out->samples_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;
|
||||
}
|
||||
if (filter_client_id != 0 && client->id != filter_client_id) {
|
||||
continue;
|
||||
}
|
||||
if (!client->accel_stream_enabled) {
|
||||
continue;
|
||||
}
|
||||
if (out->samples_count >=
|
||||
sizeof(out->samples) / sizeof(out->samples[0])) {
|
||||
break;
|
||||
}
|
||||
|
||||
alox_AccelSample *sample = &out->samples[out->samples_count++];
|
||||
sample->client_id = client->id;
|
||||
sample->valid = client->accel_valid;
|
||||
sample->x = client->accel_x;
|
||||
sample->y = client->accel_y;
|
||||
sample->z = client->accel_z;
|
||||
if (client->accel_valid) {
|
||||
sample->age_ms = client_registry_ms_since(client->accel_updated_at);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void handle_accel_snapshot(const uint8_t *data, size_t len) {
|
||||
uint32_t filter_client_id = 0;
|
||||
|
||||
if (len > 0) {
|
||||
alox_UartMessage req;
|
||||
if (uart_cmd_decode(data, len, &req) == ESP_OK) {
|
||||
alox_AccelSnapshotRequest *snap_req = UART_CMD_REQ(
|
||||
&req, alox_UartMessage_accel_snapshot_request_tag, accel_snapshot_request);
|
||||
if (snap_req != NULL) {
|
||||
filter_client_id = snap_req->client_id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
alox_UartMessage response;
|
||||
uart_cmd_init_response(&response, alox_MessageType_ACCEL_SNAPSHOT,
|
||||
alox_UartMessage_accel_snapshot_response_tag);
|
||||
fill_accel_snapshot(&response.payload.accel_snapshot_response, filter_client_id);
|
||||
|
||||
uart_cmd_send(&response, TAG);
|
||||
}
|
||||
|
||||
void cmd_accel_snapshot_register(void) {
|
||||
uart_cmd_register(alox_MessageType_ACCEL_SNAPSHOT, handle_accel_snapshot);
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
#ifndef CMD_ACCEL_SNAPSHOT_H
|
||||
#define CMD_ACCEL_SNAPSHOT_H
|
||||
|
||||
void cmd_accel_snapshot_register(void);
|
||||
|
||||
#endif
|
||||
+29
-20
@@ -28,8 +28,7 @@ static void fill_cache_status(alox_CacheStatusResponse *out) {
|
||||
return;
|
||||
}
|
||||
|
||||
out->accel_count = 0;
|
||||
out->taps_count = 0;
|
||||
out->clients_count = 0;
|
||||
|
||||
size_t count = client_registry_count();
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
@@ -38,31 +37,41 @@ static void fill_cache_status(alox_CacheStatusResponse *out) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (client->accel_stream_enabled &&
|
||||
out->accel_count < sizeof(out->accel) / sizeof(out->accel[0])) {
|
||||
alox_AccelSample *sample = &out->accel[out->accel_count++];
|
||||
sample->client_id = client->id;
|
||||
sample->valid = client->accel_valid;
|
||||
sample->x = client->accel_x;
|
||||
sample->y = client->accel_y;
|
||||
sample->z = client->accel_z;
|
||||
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) {
|
||||
sample->age_ms = client_registry_ms_since(client->accel_updated_at);
|
||||
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 (tap_notify_any(client) &&
|
||||
out->taps_count < sizeof(out->taps) / sizeof(out->taps[0])) {
|
||||
if (want_tap) {
|
||||
uint32_t kind = 0;
|
||||
uint32_t age_ms = 0;
|
||||
if (!client_registry_take_tap(client->id, &kind, &age_ms)) {
|
||||
continue;
|
||||
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;
|
||||
}
|
||||
alox_TapEvent *event = &out->taps[out->taps_count++];
|
||||
event->client_id = client->id;
|
||||
event->valid = true;
|
||||
event->kind = tap_kind_from_registry(kind);
|
||||
event->age_ms = age_ms;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,16 +48,12 @@ static const char *message_type_name(uint16_t id) {
|
||||
return "FIND_ME";
|
||||
case alox_MessageType_RESTART:
|
||||
return "RESTART";
|
||||
case alox_MessageType_ACCEL_SNAPSHOT:
|
||||
return "ACCEL_SNAPSHOT";
|
||||
case alox_MessageType_ACCEL_STREAM:
|
||||
return "ACCEL_STREAM";
|
||||
case alox_MessageType_BATTERY_STATUS:
|
||||
return "BATTERY_STATUS";
|
||||
case alox_MessageType_TAP_NOTIFY:
|
||||
return "TAP_NOTIFY";
|
||||
case alox_MessageType_TAP_SNAPSHOT:
|
||||
return "TAP_SNAPSHOT";
|
||||
case alox_MessageType_CACHE_STATUS:
|
||||
return "CACHE_STATUS";
|
||||
default:
|
||||
|
||||
@@ -1,88 +0,0 @@
|
||||
#include "client_registry.h"
|
||||
#include "cmd_tap_snapshot.h"
|
||||
#include "uart_cmd.h"
|
||||
|
||||
static const char *TAG = "[TAP_SNAP]";
|
||||
|
||||
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 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 void fill_tap_snapshot(alox_TapSnapshotResponse *out,
|
||||
uint32_t filter_client_id) {
|
||||
if (out == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
out->events_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;
|
||||
}
|
||||
if (filter_client_id != 0 && client->id != filter_client_id) {
|
||||
continue;
|
||||
}
|
||||
if (!tap_notify_any(client)) {
|
||||
continue;
|
||||
}
|
||||
if (out->events_count >= sizeof(out->events) / sizeof(out->events[0])) {
|
||||
break;
|
||||
}
|
||||
|
||||
uint32_t kind = 0;
|
||||
uint32_t age_ms = 0;
|
||||
if (!client_registry_take_tap(client->id, &kind, &age_ms)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
alox_TapEvent *event = &out->events[out->events_count++];
|
||||
event->client_id = client->id;
|
||||
event->valid = true;
|
||||
event->kind = tap_kind_from_registry(kind);
|
||||
event->age_ms = age_ms;
|
||||
}
|
||||
}
|
||||
|
||||
static void handle_tap_snapshot(const uint8_t *data, size_t len) {
|
||||
uint32_t filter_client_id = 0;
|
||||
|
||||
if (len > 0) {
|
||||
alox_UartMessage req;
|
||||
if (uart_cmd_decode(data, len, &req) == ESP_OK) {
|
||||
alox_TapSnapshotRequest *snap_req = UART_CMD_REQ(
|
||||
&req, alox_UartMessage_tap_snapshot_request_tag, tap_snapshot_request);
|
||||
if (snap_req != NULL) {
|
||||
filter_client_id = snap_req->client_id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
alox_UartMessage response;
|
||||
uart_cmd_init_response(&response, alox_MessageType_TAP_SNAPSHOT,
|
||||
alox_UartMessage_tap_snapshot_response_tag);
|
||||
fill_tap_snapshot(&response.payload.tap_snapshot_response, filter_client_id);
|
||||
|
||||
uart_cmd_send(&response, TAG);
|
||||
}
|
||||
|
||||
void cmd_tap_snapshot_register(void) {
|
||||
uart_cmd_register(alox_MessageType_TAP_SNAPSHOT, handle_tap_snapshot);
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
#ifndef CMD_TAP_SNAPSHOT_H
|
||||
#define CMD_TAP_SNAPSHOT_H
|
||||
|
||||
void cmd_tap_snapshot_register(void);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user