1## Profile测试使用说明文档 2 3 本文档主要介绍了蓝牙专项测试程序的Profile测试模块的功能使用说明。 4 5 6 7### Profile测试界面 8 9 10 11 12 13#### Profile的主要接口(ohos.bluetooth.d.ts) 14 15| method名称 | API名称 | 所需参数 | 返回值 | 备注 | 16| :----------: | :------------------: | :--------------: | :----------------------------: | :--: | 17| 获取连接状态 | getConnectionDevices | () | Array<string> | Base | 18| 获取设备状态 | getDeviceState | (device: string) | ProfileConnectionState(枚举) | Base | 19| 连接 | connect | (device: string) | boolean | | 20| 取消连接 | disconnect | (device: string) | boolean | | 21| 获取播放状态 | getPlayingState | (device: string) | PlayingState(枚举) | | 22 23>enum ProfileConnectionState { 24> 25> /** the current profile is disconnected */ 26> 27> STATE_DISCONNECTED = 0, 28> 29> /** the current profile is being connected */ 30> 31> STATE_CONNECTING = 1, 32> 33> /** the current profile is connected */ 34> 35> STATE_CONNECTED = 2, 36> 37> /** the current profile is being disconnected */ 38> 39> STATE_DISCONNECTING = 3 40> 41>} 42> 43> 44> 45>enum PlayingState { 46> 47> STATE_NOT_PLAYING, 48> 49> STATE_PLAYING, 50> 51>} 52 53#### 验证工具 54 55使用蓝牙音箱或键盘,连接后可以播放声音,查看显示信息。 56 57#### 补充 58 591. A2DP(Advanced Audio Distribution Profile) 高级音频分发模式 60 - Source(源)(SRC)–当设备用作数字音频流的源时,即为SRC,该数字音频流被传送到微微网的SNK。 61 - Sink(槽)(SNK)–当设备充当同一微微网上从SRC传送的数字音频流的接收器时,它就是SNK。 62 632. AVRCP(audio vidoe remote control protocol) 协议,用于远程控制音视频设备. 底层传输基于AVCTP传输协议,在蓝牙中,主要用于蓝牙音乐的控制,比如播放/暂停/下一曲/上一曲,以及获取播放状态、音乐信息等。 AVRCP有两个角色CT(contorl devices),TG(target devices).CT通过指令控制TG播放音乐,比如蓝牙耳机是CT,而手机是TG。 64 65注:AVRCP子协议的作用是支持CT控制TG,具体来说如果手机和一个蓝牙音箱设备连接上了,那么音箱可以控制手机播放/暂停/切歌以及获得手机上播放歌曲的信息,如专辑,歌名,歌手,时长等信息。 66 673. 音频网关(AG)–这是作为音频网关的设备,用于输入和输出。作为音频网关的典型设备是手机。 68 69 免提单元(HF)–这是用作音频网关的远程音频输入和输出机制的设备。它还提供了一些远程控制手段 70 714. HFP(Hands-Free Profile),通俗点翻译就是免提协议,说白了就是蓝牙电话协议,可以让蓝牙设备通过协议定义好的AT command控制电话,如接听、挂断、拒接、语音拨号等。 72 735. HID定义了蓝牙在人机接口设备中的协议、特征和使用规程。典型的应用包括蓝牙鼠标、蓝牙键盘、蓝牙游戏手柄等。 74 756. 其他功能暂未实现 76 77#### 功能 78 79BaseProfile:基础通用协议 80 81- getConnectionDevices 82 - 使用指导:获取配置文件的已连接设备列表,返回值为已连接设备列表的地址。 83 - 限制条件:必须有已连接的设备。 84 - 验证方法:查看返回值。 85 86- getDeviceState 87 - 使用指导:获取设备的配置文件状态,device为蓝牙设备的地址,返回值为{连接配置文件的连接状态} 88 - 限制条件:有连接的配置文件 89 - 验证方法:查看返回值。 90 91#### A2dpSource配置 92 93未开启蓝牙时: 94 95 96 97开启蓝牙时: 98 99 100 101- connect 102 103 - 使用指导:使用a2dp连接到设备。device为要连接的远程设备的地址。如果连接正在进行,返回值为true;否则返回 false。 104 105 106 - 限制条件:之前未成功连接。 107 108 - 验证方法:查看连接的播放设备是否正常使用。 109 110- disconnect 111 112 - 使用指导:用a2dp断开与设备的连接。device为要断开连接的远程设备的地址。如果正在断开连接,则返回true;否则返回 false。 113 114 - 限制条件:已成功连接。 115 116 - 验证方法:查看之前连接的播放设备是否还可以使用。 117 118- getPlayingState 119 120 - 使用指导:获取设备的播放状态。device为远程设备的地址。返回值为远程设备的播放状态。 121 122 - 限制条件:已成功连接。 123 124 - 验证方法:查看之前连接的播放设备是否正常播放。 125 126#### HandsFreeAudioGateway配置 127 128未开启蓝牙时: 129 130 131 132开启蓝牙时: 133 134 135 136- connect: 137 138 - 使用指导:使用hfp连接到设备。device为要连接的远程设备的地址。如果连接正在进行,返回值为true;否则返回 false。 139 140 - 限制条件:之前未成功连接。 141 142 - 验证方法:查看连接的播放设备是否正常使用。 143 144- disconnect 145 146 - 使用指导:用hfp断开与设备的连接。device为要断开连接的远程设备的地址。如果正在断开连接,则返回true;否则返回 false。 147 148 - 限制条件:已成功连接。 149 150 - 验证方法:查看之前连接的播放设备是否还可以使用。 151 152#### HidHost配置 153 154未开启蓝牙时: 155 156 157 158开启蓝牙时: 159 160 161 162- connect 163 164 - 使用指导:使用HitHost连接到设备。device为要连接的远程设备的地址。如果连接正在进行,返回值为true;否则返回 false。 165 166 - 限制条件:之前未成功连接。 167 168 - 验证方法:查看连接的播放设备是否正常使用。 169 170- disconnect 171 172 - 使用指导:用HitHost断开与设备的连接。device为要断开连接的远程设备的地址。如果正在断开连接,则返回true;否则返回 false。 173 174 - 限制条件:已成功连接。 175 176 - 验证方法:查看之前连接的播放设备是否还可以使用。 177 178#### PanNetwork配置 179 180未开启蓝牙时: 181 182 183 184开启蓝牙时: 185 186 187 188- disconnect 189 190 - 使用指导:用PanNetwork断开与设备的连接。device为要断开连接的远程设备的地址。如果正在断开连接,则返回true;否则返回 false。 191 192 - 限制条件:已成功连接。 193 194 - 验证方法:查看之前连接的播放设备是否还可以使用。 195 196 197 198#### ProfileManager的主要接口(ohos.bluetoothManager.d.ts) 199 200| method名称 | API名称 | 所需参数 | 返回值 | 备注 | 201| :----------: | :------------------: | :--------------: | :----------------------------: | :--: | 202| 获取连接状态 | getConnectionDevices | () | Array<string> | Base | 203| 获取设备状态 | getDeviceState | (device: string) | ProfileConnectionState(枚举) | Base | 204| 连接 | connect | (device: string) | boolean | | 205| 取消连接 | disconnect | (device: string) | boolean | | 206| 获取播放状态 | getPlayingState | (device: string) | PlayingState(枚举) | | 207 208>配置: 209> 210>#### ProfileConnectionState 枚举,蓝牙设备的profile连接状态 211> 212>| 名称 | 值 | 说明 | 213>| :------------------ | :--- | :-------------------- | 214>| STATE_DISCONNECTED | 0 | 表示profile已断连。 | 215>| STATE_CONNECTING | 1 | 表示profile正在连接。 | 216>| STATE_CONNECTED | 2 | 表示profile已连接。 | 217>| STATE_DISCONNECTING | 3 | 表示profile正在断连。 | 218> 219> 220> 221>#### ProfileId 蓝牙profile枚举,API9新增PROFILE_HID_HOST,PROFILE_PAN_NETWORK。 222> 223>| 名称 | 值 | 说明 | 224>| :------------------------------- | :--- | :----------------- | 225>| PROFILE_A2DP_SOURCE | 1 | 表示A2DP profile。 | 226>| PROFILE_HANDS_FREE_AUDIO_GATEWAY | 4 | 表示HFP profile。 | 227>| PROFILE_HID_HOST | 6 | 表示HID profile。 | 228>| PROFILE_PAN_NETWORK | 7 | 表示PAN profile。 | 229 230 231 232#### 功能 233 234BaseProfile:基础通用协议 235 236- getConnectionDevices 237 238 - 使用指导:获取配置文件的已连接设备列表,返回值为已连接设备列表的地址。 239 240 - 限制条件: 241 242 - 必须有已连接的设备。 243 - @throws { BusinessError } 201 - Permission denied. 244 * @throws { BusinessError } 801 - Capability not supported. 245 * @throws { BusinessError } 2900001 - Service stopped. 246 * @throws { BusinessError } 2900003 - Bluetooth switch is off. 247 * @throws { BusinessError } 2900004 - Profile is not supported. 248 - @throws { BusinessError } 2900099 - Operation failed. 249 250 - 验证方法:查看返回值。 251 252 253 254- getDeviceState 255 256 - 使用指导:获取设备的配置文件状态,device为蓝牙设备的地址,返回值为{连接配置文件的连接状态} 257 258 - 限制条件: 259 260 - 有连接的配置文件 261 - @throws { BusinessError } 201 - Permission denied. 262 - @throws { BusinessError } 401 - Invalid parameter. 263 - @throws { BusinessError } 801 - Capability not supported. 264 - @throws { BusinessError } 2900001 - Service stopped. 265 - @throws { BusinessError } 2900003 - Bluetooth switch is off. 266 - @throws { BusinessError } 2900004 - Profile is not supported. 267 - @throws { BusinessError } 2900099 - Operation failed. 268 269 - 验证方法:查看返回值。 270 271 272 273- connect 274 275 - 使用指导:使用a2dp连接到设备。device为要连接的远程设备的地址。如果连接正在进行,返回值为true;否则返回 false。 276 277 278 - 限制条件: 279 280 - 之前未成功连接。 281 - @throws { BusinessError } 201 - Permission denied. 282 * @throws { BusinessError } 401 - Invalid parameter. 283 * @throws { BusinessError } 801 - Capability not supported. 284 * @throws { BusinessError } 2900001 - Service stopped. 285 * @throws { BusinessError } 2900003 - Bluetooth switch is off. 286 * @throws { BusinessError } 2900004 - Profile is not supported. 287 - @throws { BusinessError } 2900099 - Operation failed. 288 289 290 - 验证方法:查看连接的播放设备是否正常使用。 291 292 293 294 295- disconnect 296 297 - 使用指导:用a2dp断开与设备的连接。device为要断开连接的远程设备的地址。如果正在断开连接,则返回true;否则返回 false。 298 299 - 限制条件: 300 301 - 已成功连接。 302 - @throws { BusinessError } 201 - Permission denied. 303 * @throws { BusinessError } 401 - Invalid parameter. 304 * @throws { BusinessError } 801 - Capability not supported. 305 * @throws { BusinessError } 2900001 - Service stopped. 306 * @throws { BusinessError } 2900003 - Bluetooth switch is off. 307 * @throws { BusinessError } 2900004 - Profile is not supported. 308 * @throws { BusinessError } 2900099 - Operation failed. 309 310 - 验证方法:查看之前连接的播放设备是否还可以使用。 311 312 313 314- getPlayingState 315 316 - 使用指导:获取设备的播放状态。device为远程设备的地址。返回值为远程设备的播放状态。 317 - 限制条件: 318 - 已成功连接。 319 - @throws { BusinessError } 401 - Invalid parameter. 320 * @throws { BusinessError } 801 - Capability not supported. 321 * @throws { BusinessError } 2900001 - Service stopped. 322 * @throws { BusinessError } 2900003 - Bluetooth switch is off. 323 * @throws { BusinessError } 2900004 - Profile is not supported. 324 * @throws { BusinessError } 2900099 - Operation failed. 325 - 验证方法:查看之前连接的播放设备是否正常播放。 326