37 Star 34 Fork 200

OpenHarmony / communication_bluetooth

Create your Gitee Account
Explore and code with more than 8 million developers,Free private repositories !:)
Sign up
Clone or Download
contribute
Sync branch
Cancel
Notice: Creating folder will generate an empty file .keep, because not support in Git
Loading...
README.md

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:

interfaces/

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

About

蓝牙服务组件为设备提供接入与使用Bluetooth的相关接口,包括BLE设备gatt相关的操作,以及BLE广播、扫描等功能。 expand collapse
C++ and 4 more languages
Apache-2.0
Cancel

Releases

No release

OpenHarmony

Contributors

All

Activities

Load More
can not load any more
1
https://gitee.com/openharmony/communication_bluetooth.git
git@gitee.com:openharmony/communication_bluetooth.git
openharmony
communication_bluetooth
communication_bluetooth
master

Search

10d9f8b4 4838521 8bde8327 4838521