High level Bluetooth Low Energy API and radio abstraction layer
Fork of BLE_API by
ble/GattService.h@1209:dd7707bda534, 2017-03-28 (annotated)
- Committer:
- cordonn2
- Date:
- Tue Mar 28 19:09:54 2017 +0000
- Revision:
- 1209:dd7707bda534
- Parent:
- 1183:1589830dbdb7
Added ability to filter advertising channel programmatically
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
vcoubard | 1167:91c37c858f48 | 1 | /* mbed Microcontroller Library |
vcoubard | 1167:91c37c858f48 | 2 | * Copyright (c) 2006-2013 ARM Limited |
vcoubard | 1167:91c37c858f48 | 3 | * |
vcoubard | 1167:91c37c858f48 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
vcoubard | 1167:91c37c858f48 | 5 | * you may not use this file except in compliance with the License. |
vcoubard | 1167:91c37c858f48 | 6 | * You may obtain a copy of the License at |
vcoubard | 1167:91c37c858f48 | 7 | * |
vcoubard | 1167:91c37c858f48 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
vcoubard | 1167:91c37c858f48 | 9 | * |
vcoubard | 1167:91c37c858f48 | 10 | * Unless required by applicable law or agreed to in writing, software |
vcoubard | 1167:91c37c858f48 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
vcoubard | 1167:91c37c858f48 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
vcoubard | 1167:91c37c858f48 | 13 | * See the License for the specific language governing permissions and |
vcoubard | 1167:91c37c858f48 | 14 | * limitations under the License. |
vcoubard | 1167:91c37c858f48 | 15 | */ |
vcoubard | 1167:91c37c858f48 | 16 | |
vcoubard | 1167:91c37c858f48 | 17 | #ifndef __GATT_SERVICE_H__ |
vcoubard | 1167:91c37c858f48 | 18 | #define __GATT_SERVICE_H__ |
vcoubard | 1167:91c37c858f48 | 19 | |
vcoubard | 1167:91c37c858f48 | 20 | #include "UUID.h" |
vcoubard | 1167:91c37c858f48 | 21 | #include "GattCharacteristic.h" |
vcoubard | 1167:91c37c858f48 | 22 | |
vcoubard | 1167:91c37c858f48 | 23 | class GattService { |
vcoubard | 1167:91c37c858f48 | 24 | public: |
vcoubard | 1167:91c37c858f48 | 25 | enum { |
vcoubard | 1167:91c37c858f48 | 26 | UUID_ALERT_NOTIFICATION_SERVICE = 0x1811, |
vcoubard | 1167:91c37c858f48 | 27 | UUID_BATTERY_SERVICE = 0x180F, |
vcoubard | 1167:91c37c858f48 | 28 | UUID_BLOOD_PRESSURE_SERVICE = 0x1810, |
vcoubard | 1167:91c37c858f48 | 29 | UUID_CURRENT_TIME_SERVICE = 0x1805, |
vcoubard | 1167:91c37c858f48 | 30 | UUID_CYCLING_SPEED_AND_CADENCE = 0x1816, |
vcoubard | 1167:91c37c858f48 | 31 | UUID_DEVICE_INFORMATION_SERVICE = 0x180A, |
vcoubard | 1167:91c37c858f48 | 32 | UUID_ENVIRONMENTAL_SERVICE = 0x181A, |
vcoubard | 1167:91c37c858f48 | 33 | UUID_GLUCOSE_SERVICE = 0x1808, |
vcoubard | 1167:91c37c858f48 | 34 | UUID_HEALTH_THERMOMETER_SERVICE = 0x1809, |
vcoubard | 1167:91c37c858f48 | 35 | UUID_HEART_RATE_SERVICE = 0x180D, |
vcoubard | 1167:91c37c858f48 | 36 | UUID_HUMAN_INTERFACE_DEVICE_SERVICE = 0x1812, |
vcoubard | 1167:91c37c858f48 | 37 | UUID_IMMEDIATE_ALERT_SERVICE = 0x1802, |
vcoubard | 1167:91c37c858f48 | 38 | UUID_LINK_LOSS_SERVICE = 0x1803, |
vcoubard | 1167:91c37c858f48 | 39 | UUID_NEXT_DST_CHANGE_SERVICE = 0x1807, |
vcoubard | 1167:91c37c858f48 | 40 | UUID_PHONE_ALERT_STATUS_SERVICE = 0x180E, |
vcoubard | 1167:91c37c858f48 | 41 | UUID_REFERENCE_TIME_UPDATE_SERVICE = 0x1806, |
vcoubard | 1167:91c37c858f48 | 42 | UUID_RUNNING_SPEED_AND_CADENCE = 0x1814, |
vcoubard | 1167:91c37c858f48 | 43 | UUID_SCAN_PARAMETERS_SERVICE = 0x1813, |
vcoubard | 1167:91c37c858f48 | 44 | UUID_TX_POWER_SERVICE = 0x1804 |
vcoubard | 1167:91c37c858f48 | 45 | }; |
vcoubard | 1167:91c37c858f48 | 46 | |
vcoubard | 1167:91c37c858f48 | 47 | public: |
vcoubard | 1167:91c37c858f48 | 48 | /** |
vcoubard | 1167:91c37c858f48 | 49 | * @brief Creates a new GattService using the specified 16-bit |
vcoubard | 1167:91c37c858f48 | 50 | * UUID, value length, and properties. |
vcoubard | 1167:91c37c858f48 | 51 | * |
vcoubard | 1167:91c37c858f48 | 52 | * @note The UUID value must be unique and is normally >1. |
vcoubard | 1167:91c37c858f48 | 53 | * |
vcoubard | 1167:91c37c858f48 | 54 | * @param[in] uuid |
vcoubard | 1167:91c37c858f48 | 55 | * The UUID to use for this service. |
vcoubard | 1167:91c37c858f48 | 56 | * @param[in] characteristics |
vcoubard | 1167:91c37c858f48 | 57 | * A pointer to an array of characteristics to be included within this service. |
vcoubard | 1167:91c37c858f48 | 58 | * @param[in] numCharacteristics |
vcoubard | 1167:91c37c858f48 | 59 | * The number of characteristics. |
vcoubard | 1167:91c37c858f48 | 60 | */ |
vcoubard | 1167:91c37c858f48 | 61 | GattService(const UUID &uuid, GattCharacteristic *characteristics[], unsigned numCharacteristics) : |
vcoubard | 1183:1589830dbdb7 | 62 | _primaryServiceID(uuid), |
vcoubard | 1183:1589830dbdb7 | 63 | _characteristicCount(numCharacteristics), |
vcoubard | 1183:1589830dbdb7 | 64 | _characteristics(characteristics), |
vcoubard | 1183:1589830dbdb7 | 65 | _handle(0) { |
vcoubard | 1167:91c37c858f48 | 66 | /* empty */ |
vcoubard | 1167:91c37c858f48 | 67 | } |
vcoubard | 1167:91c37c858f48 | 68 | |
vcoubard | 1183:1589830dbdb7 | 69 | /** |
vcoubard | 1183:1589830dbdb7 | 70 | * Get this service's UUID. |
vcoubard | 1183:1589830dbdb7 | 71 | * |
vcoubard | 1183:1589830dbdb7 | 72 | * @return A reference to the service's UUID. |
vcoubard | 1183:1589830dbdb7 | 73 | */ |
vcoubard | 1183:1589830dbdb7 | 74 | const UUID &getUUID(void) const { |
vcoubard | 1183:1589830dbdb7 | 75 | return _primaryServiceID; |
vcoubard | 1183:1589830dbdb7 | 76 | } |
vcoubard | 1183:1589830dbdb7 | 77 | |
vcoubard | 1183:1589830dbdb7 | 78 | /** |
vcoubard | 1183:1589830dbdb7 | 79 | * Get handle of the service declaration attribute in the ATT table. |
vcoubard | 1183:1589830dbdb7 | 80 | * |
vcoubard | 1183:1589830dbdb7 | 81 | * @return The service's handle. |
vcoubard | 1183:1589830dbdb7 | 82 | */ |
vcoubard | 1183:1589830dbdb7 | 83 | uint16_t getHandle(void) const { |
vcoubard | 1183:1589830dbdb7 | 84 | return _handle; |
vcoubard | 1183:1589830dbdb7 | 85 | } |
vcoubard | 1167:91c37c858f48 | 86 | |
vcoubard | 1183:1589830dbdb7 | 87 | /** |
vcoubard | 1183:1589830dbdb7 | 88 | * Get the total number of characteristics within this service. |
vcoubard | 1183:1589830dbdb7 | 89 | * |
vcoubard | 1183:1589830dbdb7 | 90 | * @return The total number of characteristics within this service. |
vcoubard | 1183:1589830dbdb7 | 91 | */ |
vcoubard | 1183:1589830dbdb7 | 92 | uint8_t getCharacteristicCount(void) const { |
vcoubard | 1183:1589830dbdb7 | 93 | return _characteristicCount; |
vcoubard | 1183:1589830dbdb7 | 94 | } |
vcoubard | 1183:1589830dbdb7 | 95 | |
vcoubard | 1183:1589830dbdb7 | 96 | /** |
vcoubard | 1183:1589830dbdb7 | 97 | * Set the handle of the service declaration attribute in the ATT table. |
vcoubard | 1183:1589830dbdb7 | 98 | * |
vcoubard | 1183:1589830dbdb7 | 99 | * @param[in] handle |
vcoubard | 1183:1589830dbdb7 | 100 | * The service's handle. |
vcoubard | 1183:1589830dbdb7 | 101 | */ |
vcoubard | 1183:1589830dbdb7 | 102 | void setHandle(uint16_t handle) { |
vcoubard | 1183:1589830dbdb7 | 103 | _handle = handle; |
vcoubard | 1183:1589830dbdb7 | 104 | } |
vcoubard | 1183:1589830dbdb7 | 105 | |
vcoubard | 1183:1589830dbdb7 | 106 | /** |
vcoubard | 1183:1589830dbdb7 | 107 | * Get this service's characteristic at a specific index. |
vcoubard | 1183:1589830dbdb7 | 108 | * |
vcoubard | 1183:1589830dbdb7 | 109 | * @param[in] index |
vcoubard | 1183:1589830dbdb7 | 110 | * The index of the characteristic. |
vcoubard | 1183:1589830dbdb7 | 111 | * |
vcoubard | 1183:1589830dbdb7 | 112 | * @return A pointer to the characterisitic at index @p index. |
vcoubard | 1183:1589830dbdb7 | 113 | */ |
vcoubard | 1167:91c37c858f48 | 114 | GattCharacteristic *getCharacteristic(uint8_t index) { |
vcoubard | 1167:91c37c858f48 | 115 | if (index >= _characteristicCount) { |
vcoubard | 1167:91c37c858f48 | 116 | return NULL; |
vcoubard | 1167:91c37c858f48 | 117 | } |
vcoubard | 1167:91c37c858f48 | 118 | |
vcoubard | 1167:91c37c858f48 | 119 | return _characteristics[index]; |
vcoubard | 1167:91c37c858f48 | 120 | } |
vcoubard | 1167:91c37c858f48 | 121 | |
vcoubard | 1167:91c37c858f48 | 122 | private: |
vcoubard | 1183:1589830dbdb7 | 123 | /** |
vcoubard | 1183:1589830dbdb7 | 124 | * This service's UUID. |
vcoubard | 1183:1589830dbdb7 | 125 | */ |
vcoubard | 1167:91c37c858f48 | 126 | UUID _primaryServiceID; |
vcoubard | 1183:1589830dbdb7 | 127 | /** |
vcoubard | 1183:1589830dbdb7 | 128 | * Total number of characteristics within this service. |
vcoubard | 1183:1589830dbdb7 | 129 | */ |
vcoubard | 1167:91c37c858f48 | 130 | uint8_t _characteristicCount; |
vcoubard | 1183:1589830dbdb7 | 131 | /** |
vcoubard | 1183:1589830dbdb7 | 132 | * An array with pointers to the characteristics added to this service. |
vcoubard | 1183:1589830dbdb7 | 133 | */ |
vcoubard | 1167:91c37c858f48 | 134 | GattCharacteristic **_characteristics; |
vcoubard | 1183:1589830dbdb7 | 135 | /** |
vcoubard | 1183:1589830dbdb7 | 136 | * Handle of the service declaration attribute in the ATT table. |
vcoubard | 1183:1589830dbdb7 | 137 | * |
vcoubard | 1183:1589830dbdb7 | 138 | * @note This handle is generally assigned by the underlying BLE stack when the |
vcoubard | 1183:1589830dbdb7 | 139 | * service is added to the ATT table. |
vcoubard | 1183:1589830dbdb7 | 140 | */ |
vcoubard | 1167:91c37c858f48 | 141 | uint16_t _handle; |
vcoubard | 1167:91c37c858f48 | 142 | }; |
vcoubard | 1167:91c37c858f48 | 143 | |
vcoubard | 1183:1589830dbdb7 | 144 | #endif /* ifndef __GATT_SERVICE_H__ */ |