Includes library modifications to allow access to AIN_4 (AIN_0 / 5)

Committer:
bryantaylor
Date:
Tue Sep 20 21:26:12 2016 +0000
Revision:
0:eafc3fd41f75
hackathon

Who changed what in which revision?

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