Pinned to some recent date

Committer:
Simon Cooksey
Date:
Thu Nov 17 16:43:53 2016 +0000
Revision:
0:fb7af294d5d9
Initial commit

Who changed what in which revision?

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