1. 设备连接、状态与硬件自检
本节说明如何通过 BLE NUS 发现 ReAI 录音卡、建立订阅并完成时间同步握手,以及读取设备固件版本、运行状态、电量、存储空间和 11 项硬件模块自检。
ReAI Recording Card SDK Documentation › Connection & Device Telemetry
SDK v0.0.9 (MIT)BLE 5 NUSMain ≥ 0.3.0 (BASE_INFO wifiVersion 需 ≥ 0.3.18 或已开过 Wi-Fi)
概述与连接握手顺序
- 扫描广播包含 NUS 服务
6e400001-b5a3-f393-e0a9-e50e24dcca9e或名称以DYJ开头的设备。 - 连接 GATT 后校验 Write(
6e400002)与 Notify(6e400003)特征,开启 Notify 通知订阅。 - 立即发送
SYNC_TIME:新开机设备的 RTC 默认未同步,连接后第一时间校准时钟,后续录音的.txt元数据才会生成synced_<Unix秒>文件名。
协议语法与参数
SYNC_TIME / BASE_INFO / STATE_INFO / BATTERY / STORAGE / TEST_CHECK
| 命令 | 请求载荷 | 核心返回字段 | 说明 |
|---|---|---|---|
SYNC_TIME | {"timestamp": 1794000000} | code, message, timestamp | Unix 秒级时间戳 |
BASE_INFO | 无 | version, versionCode, deviceId, deviceName, wifiVersion, wifiVersionCode | 主控 ≥ 0.3.18 内置配对 Wi-Fi 版本常量(如 0.1.4/104),无需开 Wi-Fi 即可读取 |
STATE_INFO | 无 | authState, recordRealtimeEnabled, wifiOpen, bootType, lowPowerMode | wifiOpen 决定 SD 卡归属 |
BATTERY | 无 | level, levelText, isCharging, voltage, adc_raw | voltage 单位为 mV |
STORAGE | 无 | total, used | 单位为 MB;要求 wifiOpen == false |
TEST_CHECK | 无 | 连续返回 11 帧 {"key":"...","result":true} | 无 index:-1 结束帧,收满 11 帧即完成 |
代码示例
javascript
const NUS_SERVICE = "6e400001-b5a3-f393-e0a9-e50e24dcca9e";
const NUS_WRITE = "6e400002-b5a3-f393-e0a9-e50e24dcca9e";
const NUS_NOTIFY = "6e400003-b5a3-f393-e0a9-e50e24dcca9e";
const device = await navigator.bluetooth.requestDevice({
filters: [{ services: [NUS_SERVICE] }, { namePrefix: "DYJ" }],
optionalServices: [NUS_SERVICE],
});
const server = await device.gatt.connect();
const service = await server.getPrimaryService(NUS_SERVICE);
const writeChar = await service.getCharacteristic(NUS_WRITE);
const notifyChar = await service.getCharacteristic(NUS_NOTIFY);
await notifyChar.startNotifications();
// 分片(<= 20 字节)写入 SYNC_TIME 与 BASE_INFO
const syncFrame = `SYNC_TIME:${JSON.stringify({ timestamp: Math.floor(Date.now() / 1000) })}\r\n`;
await writeChar.writeValueWithResponse(new TextEncoder().encode(syncFrame));
await writeChar.writeValueWithResponse(new TextEncoder().encode("BASE_INFO\r\n"));rust
use std::time::Duration;
use reai_card_sdk::DeviceManager;
let manager = DeviceManager::new().await?;
let devices = manager.scan(Duration::from_secs(5)).await?;
let device = manager.connect(devices.first().expect("no card found")).await?;
let info = device.device_info().await?;
let state = device.state().await?;
let battery = device.battery().await?;
let storage = device.storage().await?;
let checks = device.test_modules().await?;
println!("{info:?} | {state:?} | {battery:?} | {storage:?} | {} modules", checks.len());bash
make cli ARGS=scan
make cli ARGS=check网页实时演示
当前浏览器环境未启用 Web Bluetooth(需 Chrome / Edge + HTTPS 或 localhost)。你仍可立即点击「启用虚拟录音卡模拟器」在线体验全部接口。
DEVICE_ID / NAME
-
MAIN / WIFI FIRMWARE
-
BATTERY
-
STORAGE (MB)
-
协议通信实时日志 (BLE NUS / HTTP)
连接真实设备或虚拟模拟器后,此处实时显示每条 TX / RX 帧。