openharmony3.0蓝牙接口说明 和 Host管理
蓝牙接口说明
当前提供了基本的蓝牙连接和profile 功能,LTS3.0.1仅包括A2DP, BLE, GATT, SPP等基本接口。其他的功能将会在后续版本中完善和提供。
| 接口文件 | 功能 | 说明 |
|---|---|---|
| bluetooth_a2dp_src.h | interface and callback function of a2dp source | A2DP,负责传输音频的profile,手机和蓝牙耳机建立连接后传输音频就是通过A2DP |
| bluetooth_ble_advertiser.h | Defines advertiser, including avertise data and callbacks, and advertiser functions | BLE 中心设备、外围设备相关回调,功能 |
| bluetooth_ble_central_manager.h | Central manager common functions | |
| bluetooth_def.h | Defined here are various status codes | bluetooth中的业务常量定义及枚举定义 |
| bluetooth_device_class.h | Bluetooth device class | BluetoothDeviceClass的API接口类 |
| bluetooth_device.h | Bluetooth device major class | bluetooth device major class的static常量定义 |
| bluetooth_gatt_characteristic.h | Bluetooth gatt characteristic interface. | Gatt 相关的接口文件 |
| bluetooth_gatt_client.h | Bluetooth gatt client interface | |
| bluetooth_gatt_descriptor.h | Bluetooth gatt descriptor interface | |
| bluetooth_gatt_manager.h | gatt manager interface | |
| bluetooth_gatt_server.h | gatt server interface | |
| bluetooth_gatt_service.h | gatt service interface | |
| bluetooth_host.h | bluetooth host, including observer and common functions | host本机管理相关接口,如enable |
| bluetooth_remote_device.h | Bluetooth Remote Device API | 远端设备的API接口 |
| bluetooth_socket.h | spp client socket functions | socket,串口相关功能 |
| bluetooth_socket_inputstream.h | spp inputstream framework functions, including basic functions | |
| bluetooth_socket_outputstream.h | spp outputstream framework functions, including basic functions | |
| bluetooth_types.h | macro definition | bluetooth中模板相关的宏定义 |
| uuid.h | framework uuid interface. | uuid类,提供uuid相关接口功能。如字符串和uuid之间的相互转化 |
Host管理
蓝牙host管理主要是针对蓝牙本机的基本操作,包括打开和关闭蓝牙(包括传统蓝牙和BLE),设置和获取本机蓝牙名称,传统蓝牙的扫描和取消扫描周边蓝牙设备、获取本机蓝牙profile service列表,获取对其他设备的连接状态,获取、移除本机蓝牙(包括传统蓝牙和BLE)已配对的蓝牙设备或列表等。
主要接口如下表:
| 接口名 | 功能描述 |
|---|---|
| GetDefaultHost(); | 获取BluetoothHost实例,去管理本机蓝牙操作。 |
| EnableBt(); | 打开本机蓝牙。 |
| DisableBt(); | 关闭本机蓝牙。 |
| GetBtState() const; | 获取本机传统蓝牙状态: * BTStateID::STATE_TURNING_ON; * BTStateID::STATE_TURN_ON; * BTStateID::STATE_TURNING_OFF; * BTStateID::STATE_TURN_OFF. |
| SetLocalName(const std::string &name); | 设置本机蓝牙名称。 |
| GetLocalName() | 获取本机蓝牙名称。 |
| int GetBtConnectionState() const; | bluetooth connects state. * BTConnectState::CONNECTING; * BTConnectState::CONNECTED; * BTConnectState::DISCONNECTING; * BTConnectState::DISCONNECTED. |
| startBtDiscovery() | 发起蓝牙设备扫描。 |
| cancelBtDiscovery() | 取消蓝牙设备扫描。 |
| isBtDiscovering() | 检查蓝牙是否在扫描设备中。 |
| std::vector<uint32_t> GetProfileList() | 获取 profile service ID 列表 |
| GetBtProfileConnState(uint32_t profileId) | 获取本机蓝牙profile对其他设备的连接状态。BTConnectState |
| getPairedDevices(int transport) | 获取本机蓝牙已配对的蓝牙设备列。 |
| bool BluetoothFactoryReset(); | Factory reset bluetooth service |
| GetLocalDeviceClass() const; | 获取本机device class |
| SetLocalDeviceClass(const BluetoothDeviceClass &deviceClass); | 设置本机device class |
| DisableBle(); | 关闭本机BLE |
| EnableBle(); | 打开本机ble |
| IsBleEnabled() const; | 获取ble状态 |
————————————————
版权声明:本文为CSDN博主「普通网友」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/HarmonyOS_666/article/details/140926867
浙公网安备 33010602011771号