Mbed OS Reference
Loading...
Searching...
No Matches
gatt/GattService.h
1/* mbed Microcontroller Library
2 * Copyright (c) 2006-2020 ARM Limited
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19#ifndef MBED_GATT_SERVICE_H__
20#define MBED_GATT_SERVICE_H__
21
22#include "ble/common/UUID.h"
23#include "ble/gatt/GattCharacteristic.h"
24
25/**
26 * @addtogroup ble
27 * @{
28 * @addtogroup gatt
29 * @{
30 * @addtogroup server
31 * @{
32 */
33
34/**
35 * Representation of a GattServer service.
36 *
37 * A service is a cohesive collection of characteristics. It is identified by a
38 * UUID and starts at a specific handle of its GattServer.
39 */
41public:
42 enum {
43 /**
44 * UUID of the Alert Notification service.
45 */
47
48 /**
49 * UUID of the Battery service.
50 */
52
53 /**
54 * UUID of the Blood Pressure service.
55 */
57
58 /**
59 * UUID of the Current Time service.
60 */
62
63 /**
64 * UUID of the Cycling Speed and Cadence (CSC) service.
65 */
67
68 /**
69 * UUID of the Device Information Service (DIS).
70 */
72
73 /**
74 * UUID of the environmental service.
75 */
77
78 /**
79 * UUID of the Glucose service.
80 */
82
83 /**
84 * UUID of the health thermometer.
85 */
87
88 /**
89 * UUID of the Heart Rate service.
90 */
92
93 /**
94 * UUID of the Human Interface Device (HID) service.
95 */
97
98 /**
99 * UUID of the Immediate Alert service.
100 */
102
103 /**
104 * UUID of the Link Loss service.
105 */
107
108 /**
109 * UUID of the Next DST change service.
110 */
112
113 /**
114 * UUID of the Phone Alert Status service.
115 */
117
118 /**
119 * UUID of the Reference Time Update service.
120 */
122
123 /**
124 * UUID of the Running Speed and Cadence (RSC) service.
125 */
127
128 /**
129 * UUID of the Scan Parameter service.
130 */
132
133 /**
134 * UUID of the TX power service.
135 */
136 UUID_TX_POWER_SERVICE = 0x1804
137 };
138
139public:
140 /**
141 * Construct a GattService.
142 *
143 * @param[in] uuid The UUID assigned to this service.
144 * @param[in] characteristics A pointer to the array of characteristics that
145 * belongs to the service.
146 * @param[in] numCharacteristics The number of characteristics.
147 *
148 * @attention The characteristics of the service must remain valid while the
149 * GattServer uses the service.
150 */
152 const UUID &uuid,
153 GattCharacteristic *characteristics[],
154 unsigned numCharacteristics
155 ) :
156 _primaryServiceID(uuid),
157 _characteristicCount(numCharacteristics),
158 _characteristics(characteristics),
159 _handle(0) {
160 }
161
162 /**
163 * Get this service's UUID.
164 *
165 * @return A reference to the service's UUID.
166 */
167 const UUID &getUUID() const
168 {
169 return _primaryServiceID;
170 }
171
172 /**
173 * Get the handle of the service declaration attribute in the ATT table.
174 *
175 * @return The service's handle.
176 */
177 uint16_t getHandle() const
178 {
179 return _handle;
180 }
181
182 /**
183 * Get the total number of characteristics within this service.
184 *
185 * @return The total number of characteristics within this service.
186 */
188 {
189 return _characteristicCount;
190 }
191
192 /**
193 * Set the handle of the service declaration attribute in the ATT table.
194 *
195 * @attention Application code must not use this API.
196 *
197 * @param[in] handle The service's handle.
198 */
199 void setHandle(uint16_t handle)
200 {
201 _handle = handle;
202 }
203
204 /**
205 * Get this service's characteristic at a specific index.
206 *
207 * @param[in] index The index of the characteristic.
208 *
209 * @return A pointer to the characteristic at index @p index.
210 */
212 {
213 if (index >= _characteristicCount) {
214 return nullptr;
215 }
216
217 return _characteristics[index];
218 }
219
220private:
221 /**
222 * This service's UUID.
223 */
224 UUID _primaryServiceID;
225
226 /**
227 * Total number of characteristics within this service.
228 */
229 uint8_t _characteristicCount;
230
231 /**
232 * An array with pointers to the characteristics added to this service.
233 */
234 GattCharacteristic **_characteristics;
235
236 /**
237 * Handle of the service declaration attribute in the ATT table.
238 *
239 * @note The underlying BLE stack generally assigns this handle when the
240 * service is added to the ATT table.
241 */
242 uint16_t _handle;
243};
244
245/**
246 * @}
247 * @}
248 * @}
249 */
250
251#endif /* ifndef MBED_GATT_SERVICE_H__ */
Representation of a GattServer characteristic.
Representation of a GattServer service.
void setHandle(uint16_t handle)
Set the handle of the service declaration attribute in the ATT table.
uint16_t getHandle() const
Get the handle of the service declaration attribute in the ATT table.
@ UUID_CURRENT_TIME_SERVICE
UUID of the Current Time service.
@ UUID_LINK_LOSS_SERVICE
UUID of the Link Loss service.
@ UUID_BLOOD_PRESSURE_SERVICE
UUID of the Blood Pressure service.
@ UUID_HEART_RATE_SERVICE
UUID of the Heart Rate service.
@ UUID_NEXT_DST_CHANGE_SERVICE
UUID of the Next DST change service.
@ UUID_HUMAN_INTERFACE_DEVICE_SERVICE
UUID of the Human Interface Device (HID) service.
@ UUID_BATTERY_SERVICE
UUID of the Battery service.
@ UUID_PHONE_ALERT_STATUS_SERVICE
UUID of the Phone Alert Status service.
@ UUID_ENVIRONMENTAL_SERVICE
UUID of the environmental service.
@ UUID_IMMEDIATE_ALERT_SERVICE
UUID of the Immediate Alert service.
@ UUID_CYCLING_SPEED_AND_CADENCE
UUID of the Cycling Speed and Cadence (CSC) service.
@ UUID_GLUCOSE_SERVICE
UUID of the Glucose service.
@ UUID_DEVICE_INFORMATION_SERVICE
UUID of the Device Information Service (DIS).
@ UUID_ALERT_NOTIFICATION_SERVICE
UUID of the Alert Notification service.
@ UUID_HEALTH_THERMOMETER_SERVICE
UUID of the health thermometer.
@ UUID_REFERENCE_TIME_UPDATE_SERVICE
UUID of the Reference Time Update service.
@ UUID_RUNNING_SPEED_AND_CADENCE
UUID of the Running Speed and Cadence (RSC) service.
@ UUID_TX_POWER_SERVICE
UUID of the TX power service.
@ UUID_SCAN_PARAMETERS_SERVICE
UUID of the Scan Parameter service.
GattCharacteristic * getCharacteristic(uint8_t index)
Get this service's characteristic at a specific index.
GattService(const UUID &uuid, GattCharacteristic *characteristics[], unsigned numCharacteristics)
Construct a GattService.
uint8_t getCharacteristicCount() const
Get the total number of characteristics within this service.
const UUID & getUUID() const
Get this service's UUID.
Representation of a Universally Unique Identifier (UUID).
Definition: common/UUID.h:76