1 Star 0 Fork 338

chenqiao2008 / communication_bluetooth

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
README.md 4.22 KB
一键复制 编辑 原始数据 按行查看 历史
Annie_wang 提交于 2021-09-30 15:15 . update docs

Bluetooth

Introduction

The Bluetooth module provides APIs for accessing and using Bluetooth services, such as APIs for Generic Attribute Profile (GATT) operations, Bluetooth Low Energy (BLE) advertising, and scan.

Directory Structure

/foundation/communication/bluetooth
├── interfaces                              # API code
│   └── innerkits                           # System service APIs
│       ├── native_c                        # C APIs
│       │   └── include                     # Header files for C APIs
│       └── native_cpp                      # C++ APIs
├── sa_profile                              # Service ability profile
└── services                                # Bluetooth service code
└── LICENSE                                  # License declaration file

Constraints

The Bluetooth module must be compiled in C language.

Usage

Only BLE-related APIs and basic Bluetooth Generic Access Profile (GAP) APIs are provided.

Standard System

The C API definition as well as the service and protocol stack code are provided for the standard system. Currently, only the BLE-related APIs, including the APIs for GATT operations on BLE devices, BLE advertising, and scan, are provided. Other APIs, such as APIs related to A2DP, AVRCP, and HFP, will be gradually provided later.

The directories for the standard system are as follows:

interface/

sa_profile/

services/

Mini or Small System

Only C APIs for BLE, such as APIs for GATT operations, BLE advertising, and scan, are provided for the mini and small systems. Other APIs, such as APIs related to A2DP, AVRCP, and HFP, will be gradually provided later.

The directory for the mini or standard system is as follows:

interfaces/innerkits/native_c/include

C APIs

  • Enable or disable Bluetooth.
/* Enable classic Bluetooth.*/
bool EnableBt(void);
/* Disable classic Bluetooth. */
bool DisableBt(void);
/* Enable BLE. */
bool EnableBle(void);
/* Disable BLE. */
bool DisableBle(void);
  • Obtain Bluetooth status.
/* Obtain the classic Bluetooth status. */
int GetBtState();
/* Check whether BLE is enabled. */
bool IsBleEnabled();
  • Obtain the local MAC address.
/* Obtain the MAC address. */
bool GetLocalAddr(unsigned char *mac, unsigned int len);
  • Set the name of the local device.
/* Set the name of the local device.*/
bool SetLocalName(unsigned char *localName, unsigned char length);
  • Enable the GATT server feature and start the GATT service.
/* Initialize the Bluetooth protocol stack. */
int InitBtStack(void);
int EnableBtStack(void);
/* Register an application with a specified appUuid. */
int BleGattsRegister(BtUuid appUuid);
/* Add a service. */
int BleGattsAddService(int serverId, BtUuid srvcUuid, bool isPrimary, int number);
/* Add a characteristic. */
int BleGattsAddCharacteristic(int serverId, int srvcHandle, BtUuid characUuid, int properties, int permissions);
/* Add a descriptor. */
int BleGattsAddDescriptor(int serverId, int srvcHandle, BtUuid descUuid, int permissions);
/* Start the GATT service. */
int BleGattsStartService(int serverId, int srvcHandle);
  • Enable BLE advertising.
/* Set the data to advertise. */
int BleSetAdvData(int advId, const BleConfigAdvData *data);
/* Start advertising. */
int BleStartAdv(int advId, const BleAdvParams *param);
  • Enable BLE scan.
/* Set scan parameters. */
int BleSetScanParameters(int clientId, BleScanParams *param);
/* Start a scan. */
int BleStartScan(void);

Repositories Involved

communication_bluetooth

1
https://gitee.com/chenqiao2008/communication_bluetooth.git
git@gitee.com:chenqiao2008/communication_bluetooth.git
chenqiao2008
communication_bluetooth
communication_bluetooth
master

搜索帮助