Slaves forward configured tap kinds to the master; goTool exposes CLI, dashboard, REST, and WebSocket with separate notify vs receive and 2s display cache. Co-authored-by: Cursor <cursoragent@cursor.com>
89 lines
2.3 KiB
C
89 lines
2.3 KiB
C
#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);
|
|
}
|