• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1.. _module-pw_bluetooth_profiles:
2
3=====================
4pw_bluetooth_profiles
5=====================
6
7.. attention::
8
9   :bdg-ref-primary-line:`module-pw_bluetooth_profiles` is under construction,
10   depends on the experimental :bdg-ref-primary-line:`module-pw_bluetooth`
11   module and may see significant breaking API changes.
12
13The ``pw_bluetooth_profiles`` module provides a collection of implementations
14for basic Bluetooth profiles built on top of the ``pw_bluetooth`` module API.
15These profiles are independent from each other
16
17--------------------------
18Device Information Service
19--------------------------
20The ``device_info_service`` target implements the Device Information Service
21(DIS) as defined in the specification version 1.1. It exposes up to nine
22different basic properties of the device such as the model, manufacturer or
23serial number, all of which are optional. This module implements the GATT
24server-side service (``bluetooth::gatt::LocalServiceDelegate``) with the
25following limitations:
26
27- The subset of properties exposed and their values are constant throughout the
28  life of the service.
29- The subset of properties is defined at compile time, but the values may be
30  defined at runtime before service initialization. For example, the serial
31  number property might be different for different devices running the same
32  code.
33- All property values must be available in memory while the service is
34  published. Rather than using a callback mechanism to let the user produce the
35  property value at run-time, this module expects those values to be readily
36  available when initialized, but they can be stored in read-only memory.
37
38Usage
39-----
40The main intended usage of the service consists on creating and publishing the
41service, leaving it published forever referencing the values passed on
42initialization.
43
44The subset of properties exposed is a template parameter bit field
45(``DeviceInfo::Field``) and can't be changed at run-time. The ``pw::span``
46values referenced in the ``DeviceInfo`` struct must remain available after
47initialization to avoid copying them to RAM in the service, but the
48``DeviceInfo`` struct itself can be destroyed after initialization.
49
50Example code:
51
52.. code-block:: cpp
53
54   using pw::bluetooth_profiles::DeviceInfo;
55   using pw::bluetooth_profiles::DeviceInfoService;
56
57   // Global serial number for the device, initialized elsewhere.
58   pw::InlineString serial_number(...);
59
60   // Select which fields to expose at compile-time with a constexpr template
61   // parameter.
62   constexpr auto kUsedFields = DeviceInfo::Field::kModelNumber |
63                                DeviceInfo::Field::kSerialNumber |
64                                DeviceInfo::Field::kSoftwareRevision;
65
66   // Create a DeviceInfo with the values. Values are referenced from the
67   // service, not copied, so they must remain available while the service is
68   // published.
69   DeviceInfo device_info = {};
70   device_info.model_number = pw::as_bytes(pw::span{"My Model"sv});
71   device_info.software_revision = pw::as_bytes(pw::span{REVISION_MACRO});
72   device_info.serial_number = pw::as_bytes(
73       pw::span(serial_number.data(), serial_number.size()));
74
75   DeviceInfoService<kUsedFields, pw::bluetooth::gatt::Handle{123}>
76       device_info_service{device_info};
77   device_info_service.PublishService(...);
78