mbed os with nrf51 internal bandgap enabled to read battery level

Dependents:   BLE_file_test BLE_Blink ExternalEncoder

Committer:
elessair
Date:
Sun Oct 23 15:10:02 2016 +0000
Revision:
0:f269e3021894
Initial commit

Who changed what in which revision?

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