# YX_Voice 架构设计 ## 整体架构图 ``` ┌─────────────────────────────────────────────────────────────────────┐ │ YX_Voice 架构图 │ ├─────────────────────────────────────────────────────────────────────┤ │ │ │ ┌──────────────┐ TXZ协议 ┌──────────────────────────────┐ │ │ │ TXZ语音 │◄────────────►│ VoiceService │ │ │ │ 助手模块 │ │ (服务入口 & TXZ连接管理) │ │ │ └──────────────┘ └──────────────┬───────────────┘ │ │ │ │ │ ┌──────────────────────────┼────────────────┐ │ │ │ │ │ │ │ ▼ ▼ ▼ │ │ ┌──────────────────────┐ ┌──────────────────────┐ ┌──────────┐│ │ │ ProtocolManager │ │ VoiceManager │ │ Helpers ││ │ │ (协议分发管理) │ │ (核心状态管理) │ │ (辅助类) ││ │ └──────────┬───────────┘ └──────────┬───────────┘ └──────────┘│ │ │ │ │ │ ▼ ▼ │ │ ┌──────────────────────────────────────────────────────────────┐ │ │ │ Protocol Implementations │ │ │ │ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌────────┐ │ │ │ │ │ Voice │ │ Air │ │ Setting │ │ Media │ │ Car │ │ │ │ │ │Protocol │ │Protocol │ │Protocol │ │Protocol │ │Control │ │ │ │ │ └─────────┘ └─────────┘ └─────────┘ └─────────┘ └────────┘ │ │ │ └──────────────────────────────────────────────────────────────┘ │ │ │ │ ┌──────────────────────────────────────────────────────────────┐ │ │ │ IPC Communication Layer │ │ │ │ YxIPC (跨进程通信框架) │ │ │ └──────────────────────────┬───────────────────────────────────┘ │ │ │ │ │ ┌───────────────────────┼───────────────────────┐ │ │ ▼ ▼ ▼ │ │ ┌─────────┐ ┌─────────┐ ┌─────────┐ │ │ │ 音乐 │ │ 设置 │ │ 空调 │ │ │ │ 模块 │ │ 模块 │ │ 模块 │ │ │ └─────────┘ └─────────┘ └─────────┘ │ │ │ └─────────────────────────────────────────────────────────────────────┘ ``` ## 模块分层 | 层级 | 模块 | 职责 | |------|------|------| | 应用层 | VoiceService | 服务入口、生命周期管理 | | 核心层 | ProtocolManager, VoiceManager | 协议分发、状态管理 | | 协议层 | BaseProtocol及子类 | 具体协议解析与执行 | | 辅助层 | Helpers, Receivers, Observers | 状态监听、辅助功能 | | 通信层 | YxIPC, TxzProtocolManager | 跨进程通信 | --- ## 协议处理流程 ``` TXZ语音指令 │ ▼ TxzProtocolManager.setDefaultHandler() │ ├── 解析 commandType (协议名称) ├── 解析 Bundle 参数 ├── 转换为JSON格式 │ ▼ ProtocolManager.onResponse() │ ▼ YxProtocolHandler.onHandleProtocol() │ ▼ 具体Protocol实现类.onProtocolLogic() ``` --- ## IPC通信架构 ``` ┌─────────────────┐ YxIPC ┌─────────────────┐ │ YX_Voice │◄──────────────►│ YX_Music │ │ (Server) │ │ (Client) │ └────────┬────────┘ └─────────────────┘ │ │ YxIPC ▼ ┌─────────────────┐ │ YX_Setting │ └─────────────────┘ ``` **IPC配置**: ```java YxIpcConfig yxIpcConfig = new YxIpcConfig(); yxIpcConfig.addRemoteStartService(PackageConst.MUSIC_PKG); yxIpcConfig.addRemoteStartService(PackageConst.SETTING_PKG); yxIpcConfig.setRemoteListener(ProtocolManager.getInstance()); YxIPC.getInstance().bind(this, yxIpcConfig); ``` --- ## TXZ协议通信 ``` ┌─────────────────┐ TxzProtocolManager ┌─────────────────┐ │ YX_Voice │◄─────────────────────►│ TXZ语音助手 │ │ (ConnectionService) │ (AIDL Service) │ └─────────────────┘ └─────────────────┘ ``` **连接流程**: ```java TxzProtocolManager.initialize(this); TxzProtocolManager.connect(PackageConst.TXZ_PKG_NEW); TxzProtocolManager.getConnection(PackageConst.TXZ_PKG_NEW).addConnectionListener(this); ``` --- ## 模块依赖关系 ``` YX_Voice ├── YX_IPC_SDK (IPC通信) ├── YX_Lib_CommonBase (公共基础库) ├── YX_AutoMotiveSDK (车载SDK) ├── library-release-0127.aar (TXZ协议库) ├── tools.jar (工具库) ├── framework_classes.jar (系统框架) └── serial-0.1.6_classes.jar (串口库) ``` --- ## 包名依赖 | 包名 | 说明 | |------|------| | com.txzing.voiceassistant | TXZ语音助手 | | com.yaxon.music | 音乐模块 | | com.yaxon.radio | 收音机模块 | | com.yaxon.hvac | 空调模块 | | com.yaxon.bluetooth | 蓝牙模块 | | com.yaxon.setting | 设置模块 | | com.yaxon.carcontrol | 车辆控制模块 | | com.yaxon.avm | 360环视模块 | | com.yaxon.dvr | 行车记录仪模块 | | com.android.systemui | 系统UI | --- ## 核心模块 ### VoiceService - **继承关系**: `VoiceService extends BaseVoiceService implements ConnectionListener` - **职责**: 与TXZ语音助手建立连接、接收并分发语音指令 ### ProtocolManager - **设计模式**: 单例模式 - **职责**: 实现IPC消息监听接口、将消息分发给协议处理器 ### YxProtocolHandler - **职责**: 维护包名到协议逻辑类的映射、在后台线程处理协议分发 ### VoiceManager - **设计模式**: 单例模式 - **职责**: 管理TXZ绑定状态、AVM/DVR前台状态、注册车辆状态回调 ### VoiceEventHelper - **职责**: 封装所有语音控制操作、与各模块进行IPC通信 --- *文档生成日期: 2026-03-19*