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

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.