Rtos API example

Committer:
marcozecchini
Date:
Sat Feb 23 12:13:36 2019 +0000
Revision:
0:9fca2b23d0ba
final commit

Who changed what in which revision?

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