Add cmd/ to CMake include paths and update documentation paths. Co-authored-by: Cursor <cursoragent@cursor.com>
52 lines
1.6 KiB
C
52 lines
1.6 KiB
C
#include "client_registry.h"
|
|
#include "cmd_espnow_unicast_test.h"
|
|
#include "esp_log.h"
|
|
#include "esp_now_comm.h"
|
|
#include "uart_cmd.h"
|
|
|
|
static const char *TAG = "[UNICAST_TEST]";
|
|
|
|
static void reply(bool success, uint32_t seq) {
|
|
alox_UartMessage response;
|
|
uart_cmd_init_response(&response, alox_MessageType_ESPNOW_UNICAST_TEST,
|
|
alox_UartMessage_espnow_unicast_test_response_tag);
|
|
response.payload.espnow_unicast_test_response.success = success;
|
|
response.payload.espnow_unicast_test_response.seq = seq;
|
|
uart_cmd_send(&response, TAG);
|
|
}
|
|
|
|
static void handle_espnow_unicast_test(const uint8_t *data, size_t len) {
|
|
alox_UartMessage uart_msg;
|
|
|
|
if (uart_cmd_decode(data, len, &uart_msg) != ESP_OK) {
|
|
ESP_LOGW(TAG, "decode failed");
|
|
reply(false, 0);
|
|
return;
|
|
}
|
|
|
|
const alox_EspNowUnicastTestRequest *req = UART_CMD_REQ(
|
|
&uart_msg, alox_UartMessage_espnow_unicast_test_request_tag,
|
|
espnow_unicast_test_request);
|
|
if (req == NULL || req->client_id == 0) {
|
|
ESP_LOGW(TAG, "need client_id in request");
|
|
reply(false, 0);
|
|
return;
|
|
}
|
|
|
|
const client_info_t *client = client_registry_find_by_id(req->client_id);
|
|
if (client == NULL) {
|
|
ESP_LOGW(TAG, "client id %lu not in registry",
|
|
(unsigned long)req->client_id);
|
|
reply(false, req->seq);
|
|
return;
|
|
}
|
|
|
|
esp_err_t err = esp_now_comm_send_unicast_test(client->mac, req->seq);
|
|
reply(err == ESP_OK, req->seq);
|
|
}
|
|
|
|
void cmd_espnow_unicast_test_register(void) {
|
|
uart_cmd_register(alox_MessageType_ESPNOW_UNICAST_TEST,
|
|
handle_espnow_unicast_test);
|
|
}
|