UART-controlled ESP32 peripheral for automated E2E Bluetooth testing. Dual-mode (Classic BT + BLE) via Bluedroid on original ESP32. Firmware (ESP-IDF v5.x, 2511 lines C): - NDJSON protocol over UART1 (115200 baud) - System commands: ping, reset, get_info, get_status - Classic BT: GAP, SPP, all 4 SSP pairing modes - BLE: GATTS, advertising, GATT service/characteristic management - 6 device personas: headset, speaker, keyboard, sensor, phone, bare - Event reporter: thread-safe async event queue to host Python MCP server (FastMCP, 1626 lines): - Async serial client with command/response correlation - Event queue with wait_for pattern matching - Tools: connection, configure, classic, ble, persona, events - MCP resources: esp32://status, esp32://events, esp32://personas Tests: 74 unit tests passing, 5 integration test stubs (skip without hardware)
36 lines
1.4 KiB
C
36 lines
1.4 KiB
C
/*
|
|
* event_reporter.h -- Thread-safe event queue for BT callback -> UART NDJSON.
|
|
*
|
|
* BT callbacks run on the Bluedroid task; touching UART from there is
|
|
* asking for trouble. Instead, callbacks push lightweight event structs
|
|
* onto a FreeRTOS queue. A dedicated reporter task drains the queue
|
|
* and serialises each event as a single NDJSON line over UART.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <stdbool.h>
|
|
#include <stdint.h>
|
|
#include "cJSON.h"
|
|
|
|
/* Lifecycle */
|
|
void event_reporter_init(void);
|
|
|
|
/*
|
|
* Generic event push. Takes ownership of `data` (will be freed by the
|
|
* reporter task after serialisation). Safe to call from any task/ISR
|
|
* context that can tolerate a brief queue-send timeout.
|
|
*/
|
|
void event_report(const char *event_name, cJSON *data);
|
|
|
|
/* Convenience helpers -- build the cJSON internally. */
|
|
void event_report_pair_request(const char *address, const char *type,
|
|
int passkey);
|
|
void event_report_pair_complete(const char *address, bool success);
|
|
void event_report_connect(const char *address, const char *transport);
|
|
void event_report_disconnect(const char *address, const char *transport);
|
|
void event_report_gatt_read(uint16_t char_handle, const char *address);
|
|
void event_report_gatt_write(uint16_t char_handle, const char *address,
|
|
const uint8_t *value, uint16_t len);
|
|
void event_report_gatt_subscribe(uint16_t char_handle, bool subscribed);
|