prova

Fork of BLE_API by Bluetooth Low Energy

Committer:
andreasortino
Date:
Thu Sep 28 13:22:57 2017 +0000
Revision:
1209:b8e423d6b91b
Parent:
1183:1589830dbdb7
ertrfgnbc

Who changed what in which revision?

UserRevisionLine numberNew 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 {
andreasortino 1209:b8e423d6b91b 26
vcoubard 1167:91c37c858f48 27 UUID_ALERT_NOTIFICATION_SERVICE = 0x1811,
vcoubard 1167:91c37c858f48 28 UUID_BATTERY_SERVICE = 0x180F,
vcoubard 1167:91c37c858f48 29 UUID_BLOOD_PRESSURE_SERVICE = 0x1810,
vcoubard 1167:91c37c858f48 30 UUID_CURRENT_TIME_SERVICE = 0x1805,
vcoubard 1167:91c37c858f48 31 UUID_CYCLING_SPEED_AND_CADENCE = 0x1816,
vcoubard 1167:91c37c858f48 32 UUID_DEVICE_INFORMATION_SERVICE = 0x180A,
vcoubard 1167:91c37c858f48 33 UUID_ENVIRONMENTAL_SERVICE = 0x181A,
vcoubard 1167:91c37c858f48 34 UUID_GLUCOSE_SERVICE = 0x1808,
vcoubard 1167:91c37c858f48 35 UUID_HEALTH_THERMOMETER_SERVICE = 0x1809,
andreasortino 1209:b8e423d6b91b 36 UUID_HEART_RATE_SERVICE = 0x180D, //Originale
andreasortino 1209:b8e423d6b91b 37
vcoubard 1167:91c37c858f48 38 UUID_HUMAN_INTERFACE_DEVICE_SERVICE = 0x1812,
vcoubard 1167:91c37c858f48 39 UUID_IMMEDIATE_ALERT_SERVICE = 0x1802,
vcoubard 1167:91c37c858f48 40 UUID_LINK_LOSS_SERVICE = 0x1803,
vcoubard 1167:91c37c858f48 41 UUID_NEXT_DST_CHANGE_SERVICE = 0x1807,
vcoubard 1167:91c37c858f48 42 UUID_PHONE_ALERT_STATUS_SERVICE = 0x180E,
vcoubard 1167:91c37c858f48 43 UUID_REFERENCE_TIME_UPDATE_SERVICE = 0x1806,
vcoubard 1167:91c37c858f48 44 UUID_RUNNING_SPEED_AND_CADENCE = 0x1814,
vcoubard 1167:91c37c858f48 45 UUID_SCAN_PARAMETERS_SERVICE = 0x1813,
vcoubard 1167:91c37c858f48 46 UUID_TX_POWER_SERVICE = 0x1804
vcoubard 1167:91c37c858f48 47 };
vcoubard 1167:91c37c858f48 48
vcoubard 1167:91c37c858f48 49 public:
vcoubard 1167:91c37c858f48 50 /**
vcoubard 1167:91c37c858f48 51 * @brief Creates a new GattService using the specified 16-bit
vcoubard 1167:91c37c858f48 52 * UUID, value length, and properties.
vcoubard 1167:91c37c858f48 53 *
vcoubard 1167:91c37c858f48 54 * @note The UUID value must be unique and is normally >1.
vcoubard 1167:91c37c858f48 55 *
vcoubard 1167:91c37c858f48 56 * @param[in] uuid
vcoubard 1167:91c37c858f48 57 * The UUID to use for this service.
vcoubard 1167:91c37c858f48 58 * @param[in] characteristics
vcoubard 1167:91c37c858f48 59 * A pointer to an array of characteristics to be included within this service.
vcoubard 1167:91c37c858f48 60 * @param[in] numCharacteristics
vcoubard 1167:91c37c858f48 61 * The number of characteristics.
vcoubard 1167:91c37c858f48 62 */
vcoubard 1167:91c37c858f48 63 GattService(const UUID &uuid, GattCharacteristic *characteristics[], unsigned numCharacteristics) :
vcoubard 1183:1589830dbdb7 64 _primaryServiceID(uuid),
vcoubard 1183:1589830dbdb7 65 _characteristicCount(numCharacteristics),
vcoubard 1183:1589830dbdb7 66 _characteristics(characteristics),
vcoubard 1183:1589830dbdb7 67 _handle(0) {
vcoubard 1167:91c37c858f48 68 /* empty */
vcoubard 1167:91c37c858f48 69 }
vcoubard 1167:91c37c858f48 70
vcoubard 1183:1589830dbdb7 71 /**
vcoubard 1183:1589830dbdb7 72 * Get this service's UUID.
vcoubard 1183:1589830dbdb7 73 *
vcoubard 1183:1589830dbdb7 74 * @return A reference to the service's UUID.
vcoubard 1183:1589830dbdb7 75 */
vcoubard 1183:1589830dbdb7 76 const UUID &getUUID(void) const {
vcoubard 1183:1589830dbdb7 77 return _primaryServiceID;
vcoubard 1183:1589830dbdb7 78 }
vcoubard 1183:1589830dbdb7 79
vcoubard 1183:1589830dbdb7 80 /**
vcoubard 1183:1589830dbdb7 81 * Get handle of the service declaration attribute in the ATT table.
vcoubard 1183:1589830dbdb7 82 *
vcoubard 1183:1589830dbdb7 83 * @return The service's handle.
vcoubard 1183:1589830dbdb7 84 */
vcoubard 1183:1589830dbdb7 85 uint16_t getHandle(void) const {
vcoubard 1183:1589830dbdb7 86 return _handle;
vcoubard 1183:1589830dbdb7 87 }
vcoubard 1167:91c37c858f48 88
vcoubard 1183:1589830dbdb7 89 /**
vcoubard 1183:1589830dbdb7 90 * Get the total number of characteristics within this service.
vcoubard 1183:1589830dbdb7 91 *
vcoubard 1183:1589830dbdb7 92 * @return The total number of characteristics within this service.
vcoubard 1183:1589830dbdb7 93 */
vcoubard 1183:1589830dbdb7 94 uint8_t getCharacteristicCount(void) const {
vcoubard 1183:1589830dbdb7 95 return _characteristicCount;
vcoubard 1183:1589830dbdb7 96 }
vcoubard 1183:1589830dbdb7 97
vcoubard 1183:1589830dbdb7 98 /**
vcoubard 1183:1589830dbdb7 99 * Set the handle of the service declaration attribute in the ATT table.
vcoubard 1183:1589830dbdb7 100 *
vcoubard 1183:1589830dbdb7 101 * @param[in] handle
vcoubard 1183:1589830dbdb7 102 * The service's handle.
vcoubard 1183:1589830dbdb7 103 */
vcoubard 1183:1589830dbdb7 104 void setHandle(uint16_t handle) {
vcoubard 1183:1589830dbdb7 105 _handle = handle;
vcoubard 1183:1589830dbdb7 106 }
vcoubard 1183:1589830dbdb7 107
vcoubard 1183:1589830dbdb7 108 /**
vcoubard 1183:1589830dbdb7 109 * Get this service's characteristic at a specific index.
vcoubard 1183:1589830dbdb7 110 *
vcoubard 1183:1589830dbdb7 111 * @param[in] index
vcoubard 1183:1589830dbdb7 112 * The index of the characteristic.
vcoubard 1183:1589830dbdb7 113 *
vcoubard 1183:1589830dbdb7 114 * @return A pointer to the characterisitic at index @p index.
vcoubard 1183:1589830dbdb7 115 */
vcoubard 1167:91c37c858f48 116 GattCharacteristic *getCharacteristic(uint8_t index) {
vcoubard 1167:91c37c858f48 117 if (index >= _characteristicCount) {
vcoubard 1167:91c37c858f48 118 return NULL;
vcoubard 1167:91c37c858f48 119 }
vcoubard 1167:91c37c858f48 120
vcoubard 1167:91c37c858f48 121 return _characteristics[index];
vcoubard 1167:91c37c858f48 122 }
vcoubard 1167:91c37c858f48 123
vcoubard 1167:91c37c858f48 124 private:
vcoubard 1183:1589830dbdb7 125 /**
vcoubard 1183:1589830dbdb7 126 * This service's UUID.
vcoubard 1183:1589830dbdb7 127 */
vcoubard 1167:91c37c858f48 128 UUID _primaryServiceID;
vcoubard 1183:1589830dbdb7 129 /**
vcoubard 1183:1589830dbdb7 130 * Total number of characteristics within this service.
vcoubard 1183:1589830dbdb7 131 */
vcoubard 1167:91c37c858f48 132 uint8_t _characteristicCount;
vcoubard 1183:1589830dbdb7 133 /**
vcoubard 1183:1589830dbdb7 134 * An array with pointers to the characteristics added to this service.
vcoubard 1183:1589830dbdb7 135 */
vcoubard 1167:91c37c858f48 136 GattCharacteristic **_characteristics;
vcoubard 1183:1589830dbdb7 137 /**
vcoubard 1183:1589830dbdb7 138 * Handle of the service declaration attribute in the ATT table.
vcoubard 1183:1589830dbdb7 139 *
vcoubard 1183:1589830dbdb7 140 * @note This handle is generally assigned by the underlying BLE stack when the
vcoubard 1183:1589830dbdb7 141 * service is added to the ATT table.
vcoubard 1183:1589830dbdb7 142 */
vcoubard 1167:91c37c858f48 143 uint16_t _handle;
vcoubard 1167:91c37c858f48 144 };
vcoubard 1167:91c37c858f48 145
vcoubard 1183:1589830dbdb7 146 #endif /* ifndef __GATT_SERVICE_H__ */