1
0
mirror of https://github.com/bluekitchen/btstack.git synced 2025-03-31 10:20:58 +00:00

docu: extract GATT clients and services documentation from source code

This commit is contained in:
Milanka Ringwald 2021-05-19 09:55:26 +02:00 committed by Matthias Ringwald
parent fcd07a80fc
commit 1ea30d1b44
31 changed files with 273 additions and 213 deletions

@ -4,3 +4,5 @@ docs_final
docs_tmp
latex
mkdocs.yml
api_index.md
tmp

@ -36,13 +36,16 @@ update_content:
./update_listings.py
# create docs/ports/existing_ports.md
./ports2markdown.py
# create docs/gatt_clients.md and docs/gatt_services.md
./update_gatt_services.py
# re-create docs_final
rm -rf docs_final
cp -r docs docs_final
clean:
rm -rf docs_final tmp btstack *.pdf latex/btstack_generated.* latex/btstack_final.tex mkdocs.yml
rm -rf docs/appendix/apis.md docs/appendix/index.md docs/examples/examples.md docs/chipsets.md
rm -rf docs/appendix/apis.md api_index.md docs/examples/examples.md docs/chipsets.md
rm -rf docs/gatt_clients.md docs/gatt_services.md
rm -rf latex btstack help

2
doc/manual/docs/.gitignore vendored Normal file

@ -0,0 +1,2 @@
gatt_clients.md
gatt_services.md

@ -1,29 +0,0 @@
BTstack allows to implement and use GATT Clients in a modular way.
### Battery Service Client {#sec:BatteryServiceClient}}
The Battery Service Client connects to the Battery Services of a remote device and queries its battery level values. Level updates are either received via notifications (if supported by the remote Battery Service), or by manual polling.
See [Battery Service Client API](appendix/apis/#battery-service-client-api).
### Device Information Service Client {#sec:DeviceInformationServiceClient}}
The Device Information Service Client retrieves the following information from a remote device:
- manufacturer name
- model number
- serial number
- hardware revision
- firmware revision
- software revision
- system ID
- IEEE regulatory certification
- PNP ID
See [Device Information Service Client API](appendix/apis/#device-information-service-client-api).
### Scan Parameters Service Client {#sec:ScanParametersServiceClient}}
The Scan Parameters Service Client allows to store its LE scan parameters on a remote device such that the remote device can utilize this information to optimize power consumption and/or reconnection latency.
See [Scan Parameters Service Client API](appendix/apis/#scan-parameters-service-client-api).

@ -1,119 +0,0 @@
BTstack allows to implement and use GATT Services in a modular way.
To use an already implemented GATT Service Server, you only have to add it to your application's
GATT file with:
- `#import <service_name.gatt>` for .gatt files located in *src/ble/gatt-service*
- `#import "service_name.gatt"` for .gatt files located in the same folder as your application's .gatt file.
Each service will have an API at *src/ble/gatt-service/service_name_server.h. To activate it, you need
to call *service_name_init(..)*. Please see the .h file for details.
### Battery Service Server {#sec:BatteryServiceServer}}
The Battery Service allows to query your device's battery level in a standardized way.
To use with your application, add `#import <batery_service.gatt>` to your .gatt file.
After adding it to your .gatt file, you call *battery_service_server_init(value)* with the
current value of your battery. The valid range for the battery level is 0-100.
If the battery level changes, you can call *battery_service_server_set_battery_value(value)*. The service supports sending Notifications if the client enables them.
See [Battery Service Server API](appendix/apis/#battery-service-server-api).
### Cycling Power Service Server {#sec:CyclingPowerServiceServer}
The Cycling Power Service allows to query device's power- and force-related data and optionally speed- and cadence-related data for use in sports and fitness applications.
To use with your application, add `#import <cycling_power_service.gatt>` to your .gatt file.
See [Cycling Power Service Server API](appendix/apis/#cycling-power-service-server-api).
### Cycling Speed and Cadence Service Server {#sec:CyclingSpeedAndCadenceServiceServer}
The Cycling Speed and Cadence Service allows to query device's speed- and cadence-related data for use in sports and fitness applications.
To use with your application, add `#import <cycling_speed_and_cadence_service.gatt>` to your .gatt file.
See [Cycling Speed and Cadence Service Server API](appendix/apis/#cycling-speed-and-cadence-service-server-api).
### Device Information Service Server {#sec:DeviceInformationServiceServer}
TheDevice Information Service allows to query manufacturer and/or vendor information about a device.
To use with your application, add `#import <device_information_service.gatt>` to your .gatt file.
See [Device Information Service Server API](appendix/apis/#device-information-service-server-api).
### Heart Rate Service Server {#sec:HeartRateServiceServer}}
The heart rate service server provides heart rate measurements via notifications.
Each notification reports the heart rate measurement in beats per minute, and if enabled,
the total energy expended in kilo Joules, as well as RR-intervals in 1/1024 seconds resolution.
The Energy Expended field represents the accumulated energy expended
in kilo Joules since the last time it was reset. If the maximum value of 65535
kilo Joules is reached, it will remain at this value, until a reset command
from the client is received.
The RR-Interval represents the time between two consecutive R waves in
an Electrocardiogram (ECG) waveform. If needed, the RR-Intervals are sent in
multiple notifications.
To use with your application, add `#import <heart_rate_service.gatt>` to your .gatt file.
After adding it to your .gatt file, you call *heart_rate_server_init(body_sensor_location, energy_expended_supported)*
with the intended sensor location, and a flag indicating if energy expanded is supported.
If heart rate measurement changes, you can call
*heart_rate_service_server_update_heart_rate_values(heart_rate_bpm, service_sensor_contact_status, rr_interval_count, rr_intervals)*.
This function will trigger sending Notifications if the client enables them.
If energy expanded is supported, you can call *heart_rate_service_add_energy_expended(energy_expended_kJ)*
with the newly expanded energy. The accumulated energy expended value
will be emitted with the next heart rate measurement.
See [Heart Rate Service Server API](appendix/apis/#heart-rate-service-server-api).
### Mesh Provisioning Service Server {#sec:MeshProvisioningServiceServer}
The Mesh Provisioning Service allows a Provisioning Client to provision a device to participate in the mesh network.
To use with your application, add `#import <mesh_provisioning_service.gatt>` to your .gatt file.
See [Mesh Provisioning Service Server API](appendix/apis/#mesh-provisioning-service-server-api).
### Mesh Proxy Service Server {#sec:MeshProxyServiceServer}
The Mesh Proxy Service is used to enable a server to send and receive Proxy PDUs with a client.
To use with your application, add `#import <mesh_proxy_service.gatt>` to your .gatt file.
See [Mesh Proxy Service Server API](appendix/apis/#mesh-proxy-service-server-api).
### Nordic SPP Service Server {#sec:NordicSPPServiceServer}
The Nordic SPP Service is implementation of the Nordic SPP-like profile.
To use with your application, add `#import <nordic_spp_service.gatt>` to your .gatt file.
See [Nordic SPP Service Server API](appendix/apis/#nordic-spp-service-server-api).
### Scan Parameters Service Server {#sec:ScanParametersServiceServer}
The Scan Parameters Service enables a remote GATT Client to store the LE scan parameters it is using locally. These parameters can be utilized by the application to optimize power consumption and/or reconnection latency.
To use with your application, add `#import <scan_parameters_service.gatt>` to your .gatt file.
See [Scan Parameters Service Server API](appendix/apis/#scan-parameters-server-api).
### u-blox SPP Service Server {#sec:ubloxSPPServiceServer}
The u-blox SPP Service is implementation of the u-Blox SPP-like profile.
To use with your application, add `#import <ublox_spp_service.gatt>` to your .gatt file.
See [u-blox SPP Service Server API](appendix/apis/#ublox-spp-service-server-api).

@ -22,3 +22,4 @@ stm32-f103rb-nucleo
stm32-f4discovery-cc256x
stm32-l053r8-em9304
windows-winusb
*.jpg

@ -11,6 +11,7 @@ nav:
- 'Protocols': protocols.md
- 'Profiles': profiles.md
- 'Implemented GATT Services': gatt_services.md
- 'Implemented GATT Clients': gatt_clients.md
- 'Examples': examples/examples.md
- 'Chipsets': chipsets.md
- 'Porting to Other Platforms': porting.md

@ -73,11 +73,12 @@ def process_readmes(intro_file, port_folder, ports_file, ports_folder):
def main(argv):
btstackfolder = "../../"
docsfolder = "docs/"
template_folder = "template/"
inputfolder = btstackfolder + "port/"
portsfolder = docsfolder + "ports/"
introfile = portsfolder + "intro.md"
outputfile = portsfolder + "existing_ports.md"
inputfolder = btstackfolder + "port/"
portsfolder = docsfolder + "ports/"
introfile = template_folder + "ports_intro.md"
outputfile = portsfolder + "existing_ports.md"
process_readmes(introfile, inputfolder, outputfile, portsfolder)
if __name__ == "__main__":

@ -0,0 +1,3 @@
BTstack allows to implement and use GATT Clients in a modular way.

@ -0,0 +1,10 @@
BTstack allows to implement and use GATT Services in a modular way.
To use an already implemented GATT Service Server, you only have to add it to your application's GATT file with:
- `#import <service_name.gatt>` for .gatt files located in *src/ble/gatt-service*
- `#import "service_name.gatt"` for .gatt files located in the same folder as your application's .gatt file.
Each service will have an API at *src/ble/gatt-service/service_name_server.h*. To activate it, you need to call *service_name_init(..)*.
Please see the .h file for details.

@ -221,7 +221,7 @@ def main(argv):
docsfolder = "docs/"
apifile = docsfolder + "appendix/apis.md"
indexfile = docsfolder + "appendix/index.md"
indexfile = "api_index.md"
cmd = 'update_apis.py [-b <btstackfolder>] [-a <apifile>] [-g <githubfolder>] [-i <indexfile>]'
try:

@ -0,0 +1,155 @@
#!/usr/bin/env python3
import os, sys, getopt, re
import subprocess
class State:
SearchIntro = 0
IntroFound = 1
SearchAPI = 2
btstack_root = os.path.abspath(os.path.dirname(sys.argv[0]) + '/../../')
inputfolder = btstack_root + "/src/ble/gatt-service/"
manual_folder = btstack_root + "/doc/manual/"
docsfolder = manual_folder + "docs/"
template_folder = manual_folder + "template/"
mdfiles = {
# source file sufix : docu file, [white list od source files]
"_server.h" : ["gatt_services.md", ["hids_device.h"]],
"_client.h" : ["gatt_clients.md", []]
}
abrevations = {
"Ancs" : "ANCS",
"Hids" : "HIDS",
"Ublox": "u-blox",
"Spp" : "SPP",
"And" : "and"
}
description_template = """
### NAME {#sec:REFERENCE}
"""
description_api = """
See [NAME API](appendix/apis/#REFERENCE).
"""
def isEmptyCommentLine(line):
return re.match('(\s*\*\s*)\n',line)
def isCommentLine(line):
return re.match('(\s*\*\s*).*',line)
def isEndOfComment(line):
return re.match('\s*\*/.*', line)
def isNewItem(line):
return re.match('(\s*\*\s*\-\s*)(.*)',line)
def isTextTag(line):
return re.match('.*(@text).*', line)
def isItemizeTag(line):
return re.match("(\s+\*\s+)(-\s)(.*)", line)
def processTextLine(line):
if isEmptyCommentLine(line):
return "\n\n"
line.rstrip()
if isTextTag(line):
text_line_parts = re.match(".*(@text\s*)(.*)", line)
return text_line_parts.group(2).lstrip() + " "
if isItemizeTag(line):
text_line_parts = re.match("(\s*\*\s*\-\s*)(.*)", line)
return "- " + text_line_parts.group(2)
if isEmptyCommentLine(line):
return "\n"
text_line_parts = re.match("(\s+\*\s+)(.*)", line)
if text_line_parts:
return text_line_parts.group(2) + " "
return ""
def handle_abrevations(basename):
name_parts = [item.capitalize() for item in basename.split("_")]
for i in range(len(name_parts)):
try:
name_parts[i] = abrevations[name_parts[i]]
except KeyError:
continue
return " ".join(name_parts)
def process_file(basename, inputfile_path, outputfile_path):
reference = basename.replace("_", "-")
name = handle_abrevations(basename)
title = description_template.replace("NAME", name).replace("REFERENCE", reference)
api = description_api.replace("NAME", name).replace("REFERENCE", reference)
text_block = ""
with open(inputfile_path, 'r') as fin:
state = State.SearchIntro
for line in fin:
if state == State.SearchIntro:
if isTextTag(line):
state = State.IntroFound
text_block = text_block + processTextLine(line)
continue
if state == State.IntroFound:
text_block = text_block + processTextLine(line)
if isEndOfComment(line):
state = State.SearchIntro
fin.close()
with open(outputfile_path, 'a+') as fout:
fout.write(title)
fout.write(text_block)
fout.write(api)
fout.close()
def main(argv):
for source_filename_sufix, [outputfile, white_list] in mdfiles.items():
outputfile_path = docsfolder + outputfile
introfile_path = template_folder + outputfile[:-3] + "_intro.md"
print('Code folder: ', inputfolder)
print('Intro file: ', introfile_path)
print('Output file: ', outputfile_path)
with open(outputfile_path, 'w') as fout:
with open(introfile_path, 'r') as fin:
for line in fin:
fout.write(line)
fin.close()
fout.close()
files_to_process = []
for root, dirs, files in os.walk(inputfolder, topdown=True):
for f in files:
if not f.endswith(source_filename_sufix):
if f not in white_list:
continue
files_to_process.append(root + "/"+ f)
files_to_process.sort()
for inputfile_path in files_to_process:
basename = os.path.basename(inputfile_path)[:-2]
process_file(basename, inputfile_path, outputfile_path)
if __name__ == "__main__":
main(sys.argv[1:])

@ -341,10 +341,11 @@ def processExamples(intro_file, examples_folder, examples_ofile, git_branch_name
def main(argv):
btstackfolder = "../../"
docsfolder = "docs/"
template_folder = "template/"
git_branch_name = "master"
inputfolder = btstackfolder + "example/"
introfile = docsfolder + "examples/intro.md"
introfile = template_folder + "examples_intro.md"
outputfile = docsfolder + "examples/examples.md"
cmd = 'update_listings.py [-f <inputfolder>] [-i <introfile>] [-o <outputfile>]'
@ -363,9 +364,9 @@ def main(argv):
introfile = arg
elif opt in ("-o", "--ofile"):
outputfile = arg
print ('Input folder is : ', inputfolder)
print ('Intro file is : ', introfile)
print ('Output file is : ', outputfile)
print ('Input folder: ', inputfolder)
print ('Intro file: ', introfile)
print ('Output file: ', outputfile)
try:
output = subprocess.check_output("git symbolic-ref --short HEAD", stderr=subprocess.STDOUT, timeout=3, shell=True)

@ -38,13 +38,18 @@
#ifndef ANCS_CLIENT_H
#define ANCS_CLIENT_H
#include <stdint.h>
#include "btstack_defines.h"
#if defined __cplusplus
extern "C" {
#endif
#include <stdint.h>
#include "btstack_defines.h"
/**
* @text The ANCS Client implements Notification Consumer (NC) of the [Apple Notification Center Service (ANCS)](https://developer.apple.com/library/archive/documentation/CoreBluetooth/Reference/AppleNotificationCenterServiceSpecification/Introduction/Introduction.html).
*/
/* API_START */
void ancs_client_init(void);

@ -44,11 +44,16 @@
#include "btstack_linked_list.h"
#include "ble/gatt_client.h"
#if defined __cplusplus
extern "C" {
#endif
/**
* @text The Battery Service Client connects to the Battery Services of a remote device
* and queries its battery level values. Level updates are either received via notifications
* (if supported by the remote Battery Service), or by manual polling.
*/
#ifndef MAX_NUM_BATTERY_SERVICES
#define MAX_NUM_BATTERY_SERVICES 3
#endif

@ -44,8 +44,14 @@ extern "C" {
#endif
/**
* Implementation of the GATT Battery Service Server
* To use with your application, add '#import <battery_service.gatt' to your .gatt file
* @text The Battery Service allows to query your device's battery level in a standardized way.
*
* To use with your application, add `#import <batery_service.gatt>` to your .gatt file.
* After adding it to your .gatt file, you call *battery_service_server_init(value)* with the
* current value of your battery. The valid range for the battery level is 0-100.
*
* If the battery level changes, you can call *battery_service_server_set_battery_value(value)*.
* The service supports sending Notifications if the client enables them.
*/
/* API_START */

@ -44,15 +44,13 @@ extern "C" {
#endif
/**
* Implementation of the GATT Cycling Power Service Server
*/
// *****************************************************************************
/* GATT_SERVICE_SERVER_START(cycling_power_service_server){Cycling PowerService}
* @text The Cycling Power Service allows to query device's power- and
* force-related data and optionally speed- and cadence-related data for
* use in sports and fitness applications.
*
* To use with your application, add `#import <cycling_power_service.gatt>`
* to your .gatt file.
*/
// *****************************************************************************
/* GATT_SERVICE_SERVER_END */
/* API_START */
#define CYCLING_POWER_MANUFACTURER_SPECIFIC_DATA_MAX_SIZE 16

@ -44,15 +44,13 @@ extern "C" {
#endif
/**
* Implementation of the GATT Cycling Speed and Cadence Service Server
*/
// *****************************************************************************
/* GATT_SERVICE_SERVER_START(cycling_speed_and_cadence_service_server){Cycling Speed and Cadence Service}
* @text The Cycling Speed and Cadence Service allows to query
* device's speed- and cadence-related data for use in sports and
* fitness applications.
*
* To use with your application, add `#import <cycling_speed_and_cadence_service.gatt>`
* to your .gatt file.
*/
// *****************************************************************************
/* GATT_SERVICE_SERVER_END */
/* API_START */

@ -43,11 +43,23 @@
#include "bluetooth.h"
#include "ble/gatt_client.h"
#if defined __cplusplus
extern "C" {
#endif
/**
* @text The Device Information Service Client retrieves the following information from a remote device:
* - manufacturer name
* - model number
* - serial number
* - hardware revision
* - firmware revision
* - software revision
* - system ID
* - IEEE regulatory certification
* - PNP ID
*/
/* API_START */
/**

@ -46,13 +46,13 @@ extern "C" {
/* API_START */
/**
* Implementation of the Device Information Service Server
* @text Th eDevice Information Service allows to query manufacturer and/or
* vendor information about a device.
*
* To use with your application, add `#import <device_information_service.gatt>` to your .gatt file.
*
* To use with your application, add '#import <device_information_sevice.gatt' to your .gatt file
* and call all functions below. All strings and blobs need to stay valid after calling the functions.
*
* @note: instead of calling all setters, you can create a local copy of the .gatt file and remove
* all Characteristics that are not relevant for your application and define all fixed values in the .gatt file
* *Note*: instead of calling all setters, you can create a local copy of the .gatt file and remove
* all Characteristics that are not relevant for your application and define all fixed values in the .gatt file.
*/
/**

@ -44,15 +44,8 @@ extern "C" {
#endif
/**
* Implementation of the GATT Heart Rate Service Server
*/
// *****************************************************************************
/* GATT_SERVICE_SERVER_START(heart_rate_service_server){Heart Rate Service}
*
* The heart rate service server provides heart rate measurements via
* notifications.
*
* @text The heart rate service server provides heart rate measurements via notifications.
*
* Each notification reports the heart rate measurement in beats per minute, and if enabled,
* the total energy expended in kilo Joules, as well as RR-intervals in 1/1024 seconds resolution.
*
@ -60,15 +53,15 @@ extern "C" {
* in kilo Joules since the last time it was reset. If the maximum value of 65535
* kilo Joules is reached, it will remain at this value, until a reset command
* from the client is received.
*
*
* The RR-Interval represents the time between two consecutive R waves in
* an Electrocardiogram (ECG) waveform. If needed, the RR-Intervals are sent in
* multiple notifications.
*
*
* To use with your application, add `#import <heart_rate_service.gatt>` to your .gatt file.
* After adding it to your .gatt file, you call *heart_rate_server_init(body_sensor_location, energy_expended_supported)*
* with the intended sensor location, and a flag indicating if energy expanded is supported.
*
*
* If heart rate measurement changes, you can call
* *heart_rate_service_server_update_heart_rate_values(heart_rate_bpm, service_sensor_contact_status, rr_interval_count, rr_intervals)*.
* This function will trigger sending Notifications if the client enables them.
@ -76,10 +69,7 @@ extern "C" {
* If energy expanded is supported, you can call *heart_rate_service_add_energy_expended(energy_expended_kJ)*
* with the newly expanded energy. The accumulated energy expended value
* will be emitted with the next heart rate measurement.
*
*/
// *****************************************************************************
/* GATT_SERVICE_SERVER_END */
/* API_START */

@ -38,10 +38,6 @@
#ifndef HIDS_CLIENT_H
#define HIDS_CLIENT_H
#if defined __cplusplus
extern "C" {
#endif
#include <stdint.h>
#include "btstack_defines.h"
#include "btstack_hid.h"
@ -49,6 +45,14 @@ extern "C" {
#include "btstack_linked_list.h"
#include "ble/gatt_client.h"
#if defined __cplusplus
extern "C" {
#endif
/**
* @text The HID Service Client is used on the HID Host to receive reports and other HID data.
*/
#ifndef MAX_NUM_HID_SERVICES
#define MAX_NUM_HID_SERVICES 3
#endif

@ -46,7 +46,7 @@ extern "C" {
#endif
/**
* Implementation of the GATT HIDS Device
* @text Implementation of the GATT HIDS Device
* To use with your application, add '#import <hids.gatt>' to your .gatt file
*/

@ -46,7 +46,9 @@ extern "C" {
#endif
/**
* Implementation of the Mesh Provisioning Service Server
* @text The Mesh Provisioning Service allows a Provisioning Client to provision a device to participate in the mesh network.
*
* To use with your application, add `#import <mesh_provisioning_service.gatt>` to your .gatt file.
*/
/* API_START */

@ -46,7 +46,9 @@ extern "C" {
#endif
/**
* Implementation of the Mesh Proxy Service Server
* @text The Mesh Proxy Service is used to enable a server to send and receive Proxy PDUs with a client.
*
* To use with your application, add `#import <mesh_proxy_service.gatt>` to your .gatt file.
*/
/* API_START */

@ -48,9 +48,9 @@ extern "C" {
/* API_START */
/**
* Implementation of the Nordic SPP-like profile
* @text The Nordic SPP Service is implementation of the Nordic SPP-like profile.
*
* To use with your application, add '#import <nordic_spp_service.gatt' to your .gatt file
* To use with your application, add `#import <nordic_spp_service.gatt` to your .gatt file
* and call all functions below. All strings and blobs need to stay valid after calling the functions.
*/

@ -35,6 +35,13 @@
*
*/
/**
* @text The Scan Parameters Service Client allows to store its
* LE scan parameters on a remote device such that the remote device
* can utilize this information to optimize power consumption and/or
* reconnection latency.
*/
#ifndef SCAN_PARAMAETERS_SERVICE_CLIENT_H
#define SCAN_PARAMAETERS_SERVICE_CLIENT_H

@ -48,9 +48,9 @@ extern "C" {
/* API_START */
/**
* Implementation of the Scan Parameters service
* @text The Scan Parameters Service enables a remote GATT Client to store the LE scan parameters it is using locally. These parameters can be utilized by the application to optimize power consumption and/or reconnection latency.
*
* To use with your application, add '#import <scan_parameters_service.gatt' to your .gatt file
* To use with your application, add `#import <scan_parameters_service.gatt` to your .gatt file
* and call all functions below. All strings and blobs need to stay valid after calling the functions.
*/

@ -48,9 +48,9 @@ extern "C" {
/* API_START */
/**
* Implementation of the ublox SPP-like profile
* @text The u-blox SPP Service is implementation of the u-Blox SPP-like profile.
*
* To use with your application, add '#import <ublox_spp_service.gatt' to your .gatt file
* To use with your application, add `#import <ublox_spp_service.gatt` to your .gatt file
* and call all functions below. All strings and blobs need to stay valid after calling the functions.
*/