miketsai 953b7a348a feat(test): BLE test mode for validating alerts, CAN speed, and buzzer
Add TEST_ENTER/TEST_EXIT commands via BLE to enter/exit test mode.
In test mode, inference results are suppressed; testers can directly
trigger BLE JSON (TEST_BLE *), CAN+Buzzer actions (TEST_CAN *),
or run sequenced full-coverage tests (TEST_BLE_ALL, TEST_CAN_ALL,
TEST_ALL). Auto-exits after 60s idle. Routes unrecognised BLE
commands through new bt_uart_set_extra_cmd_cb() hook.
2026-06-13 18:12:05 +08:00

57 lines
2.1 KiB
C

#ifndef BT_UART_H
#define BT_UART_H
/*
* bt_uart — DX-BT24 Bluetooth module UART driver
*
* The DX-BT24 is a UART-transparent BLE module. Whatever is written to the
* serial port is forwarded verbatim over BLE to the connected iOS/Android app.
*
* TX (Notify → app):
* bt_uart_send_json(json_str) — thread-safe, non-blocking queue
*
* RX (Command ← app) — handled automatically by the reader thread:
* {"command": "status_check"} → Notify: response_type=status_check
* {"command": "get_rent_status"} → Notify: response_type=rent_status
* {"command": "rent"} → status 0→1; Notify: rent_status
* {"command": "return"} → status 1→0; Notify: rent_status
*
* Usage:
* bt_uart_init("/dev/ttyS1", 0)
* bt_uart_set_identity("1.0.0", "BT-24")
* bt_uart_set_intervention_cb(my_fn) // optional
* bt_uart_send_json(json_str)
* bt_uart_close()
*/
/* Open UART, start TX writer + RX reader threads.
* do_at_probe=1: one-time baud upgrade 9600→115200 (factory only). */
int bt_uart_init(const char *dev, int do_at_probe);
/* Set firmware version and BT peripheral name broadcast in status_check replies. */
void bt_uart_set_identity(const char *aresx_version, const char *bt_name);
/* Write JSON bytes to the BT module. Thread-safe. No-op if not init'd. */
void bt_uart_send_json(const char *json);
/* Rent status: 0=未租借, 1=租借中, 2=管理模式. Thread-safe. */
int bt_uart_get_rent_status(void);
void bt_uart_set_rent_status(int status);
/* Optional callback: return 1 if cart control is currently active, else 0.
* Called when building status_check responses. */
typedef int (*bt_intervention_fn)(void);
void bt_uart_set_intervention_cb(bt_intervention_fn fn);
/* Extra command callback — called for unrecognised BLE commands. */
typedef void (*bt_extra_cmd_fn)(const char *cmd);
void bt_uart_set_extra_cmd_cb(bt_extra_cmd_fn fn);
/* Reset handshake and notify peer; DX-BT24 is passthrough — no HW disconnect API. */
void bt_uart_disconnect(void);
/* Close the UART fd and release resources. */
void bt_uart_close(void);
#endif /* BT_UART_H */