2026-01-02 13:04:19 +08:00
|
|
|
use crate::audio::config::AudioConfig;
|
2026-01-02 09:59:29 +08:00
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
|
|
2026-01-02 13:04:19 +08:00
|
|
|
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
|
|
|
|
|
pub struct DeviceInfo {
|
|
|
|
|
pub model: String,
|
|
|
|
|
pub mac: String,
|
|
|
|
|
pub version: u32,
|
2026-01-02 09:59:29 +08:00
|
|
|
}
|
|
|
|
|
|
2026-01-02 17:23:24 +08:00
|
|
|
impl DeviceInfo {
|
|
|
|
|
pub fn current() -> Self {
|
|
|
|
|
Self {
|
|
|
|
|
model: "Open-XiaoAi-V2".to_string(),
|
|
|
|
|
mac: "00:00:00:00:00:00".to_string(), // TODO: Get actual MAC
|
|
|
|
|
version: 1,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-02 09:59:29 +08:00
|
|
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
|
|
|
|
pub enum ControlPacket {
|
2026-01-02 17:23:24 +08:00
|
|
|
// Discovery
|
2026-01-02 09:59:29 +08:00
|
|
|
ServerHello {
|
2026-01-02 13:04:19 +08:00
|
|
|
tcp_port: u16,
|
2026-01-02 17:23:24 +08:00
|
|
|
udp_port: u16,
|
2026-01-02 09:59:29 +08:00
|
|
|
},
|
2026-01-02 17:23:24 +08:00
|
|
|
// Handshake
|
2026-01-02 09:59:29 +08:00
|
|
|
ClientIdentify {
|
2026-01-02 13:04:19 +08:00
|
|
|
info: DeviceInfo,
|
2026-01-02 17:23:24 +08:00
|
|
|
udp_port: u16,
|
2026-01-02 09:59:29 +08:00
|
|
|
},
|
2026-01-02 13:04:19 +08:00
|
|
|
IdentifyOk,
|
|
|
|
|
|
2026-01-02 17:23:24 +08:00
|
|
|
// Audio Control
|
2026-01-02 13:04:19 +08:00
|
|
|
StartRecording {
|
|
|
|
|
config: AudioConfig,
|
2026-01-02 09:59:29 +08:00
|
|
|
},
|
2026-01-02 13:04:19 +08:00
|
|
|
StopRecording,
|
|
|
|
|
StartPlayback {
|
|
|
|
|
config: AudioConfig,
|
2026-01-02 09:59:29 +08:00
|
|
|
},
|
2026-01-02 13:04:19 +08:00
|
|
|
StopPlayback,
|
|
|
|
|
|
|
|
|
|
// RPC
|
|
|
|
|
RpcRequest {
|
|
|
|
|
id: u32,
|
|
|
|
|
method: String,
|
|
|
|
|
args: Vec<String>,
|
|
|
|
|
},
|
|
|
|
|
RpcResponse {
|
|
|
|
|
id: u32,
|
|
|
|
|
result: RpcResult,
|
|
|
|
|
},
|
|
|
|
|
|
2026-01-02 17:23:24 +08:00
|
|
|
// Heartbeat
|
2026-01-02 13:04:19 +08:00
|
|
|
Ping,
|
|
|
|
|
Pong,
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-02 17:23:24 +08:00
|
|
|
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
|
2026-01-02 13:04:19 +08:00
|
|
|
pub struct RpcResult {
|
|
|
|
|
pub stdout: String,
|
|
|
|
|
pub stderr: String,
|
|
|
|
|
pub code: i32,
|
2026-01-02 09:59:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
|
|
|
|
pub struct AudioPacket {
|
2026-01-02 17:23:24 +08:00
|
|
|
pub data: Vec<u8>,
|
2026-01-02 09:59:29 +08:00
|
|
|
}
|