Move UART command handlers into main/cmd/ for clearer layout.
Add cmd/ to CMake include paths and update documentation paths. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
#include "client_registry.h"
|
||||
#include "cmd_client_info.h"
|
||||
#include "esp_log.h"
|
||||
#include "pb_encode.h"
|
||||
#include "uart_cmd.h"
|
||||
|
||||
static const char *TAG = "[CLIENT_INFO]";
|
||||
|
||||
static bool encode_clients_list(pb_ostream_t *stream, const pb_field_t *field,
|
||||
void *const *arg) {
|
||||
(void)arg;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
uart_cmd_bytes_t mac = {.data = client->mac, .len = CLIENT_MAC_LEN};
|
||||
|
||||
alox_ClientInfo proto = alox_ClientInfo_init_zero;
|
||||
proto.id = client->id;
|
||||
proto.available = client->available;
|
||||
proto.used = client->used;
|
||||
proto.last_ping = client_registry_ms_since(client->last_ping_at);
|
||||
proto.last_success_ping =
|
||||
client_registry_ms_since(client->last_success_ping_at);
|
||||
proto.version = client->version;
|
||||
proto.mac.funcs.encode = uart_cmd_encode_bytes;
|
||||
proto.mac.arg = &mac;
|
||||
|
||||
if (!pb_encode_tag_for_field(stream, field)) {
|
||||
return false;
|
||||
}
|
||||
if (!pb_encode_submessage(stream, alox_ClientInfo_fields, &proto)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static void handle_client_info(const uint8_t *data, size_t len) {
|
||||
(void)data;
|
||||
(void)len;
|
||||
|
||||
alox_UartMessage response;
|
||||
uart_cmd_init_response(&response, alox_MessageType_CLIENT_INFO,
|
||||
alox_UartMessage_client_info_response_tag);
|
||||
response.payload.client_info_response.clients.funcs.encode = encode_clients_list;
|
||||
response.payload.client_info_response.clients.arg = NULL;
|
||||
|
||||
ESP_LOGI(TAG, "sending %u clients", (unsigned)client_registry_count());
|
||||
uart_cmd_send(&response, TAG);
|
||||
}
|
||||
|
||||
void cmd_client_info_register(void) {
|
||||
uart_cmd_register(alox_MessageType_CLIENT_INFO, handle_client_info);
|
||||
}
|
||||
Reference in New Issue
Block a user