Lee Shen / FTHR_USB_serial_qSPI
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers GattService.h Source File

GattService.h

00001 /* mbed Microcontroller Library
00002  * Copyright (c) 2006-2013 ARM Limited
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015 */
00016 
00017 #ifndef __GATT_SERVICE_H__
00018 #define __GATT_SERVICE_H__
00019 
00020 #include "UUID.h"
00021 #include "GattCharacteristic.h"
00022 
00023 class GattService {
00024 public:
00025     enum {
00026         UUID_ALERT_NOTIFICATION_SERVICE     = 0x1811,
00027         UUID_BATTERY_SERVICE                = 0x180F,
00028         UUID_BLOOD_PRESSURE_SERVICE         = 0x1810,
00029         UUID_CURRENT_TIME_SERVICE           = 0x1805,
00030         UUID_CYCLING_SPEED_AND_CADENCE      = 0x1816,
00031         UUID_DEVICE_INFORMATION_SERVICE     = 0x180A,
00032         UUID_ENVIRONMENTAL_SERVICE          = 0x181A,
00033         UUID_GLUCOSE_SERVICE                = 0x1808,
00034         UUID_HEALTH_THERMOMETER_SERVICE     = 0x1809,
00035         UUID_HEART_RATE_SERVICE             = 0x180D,
00036         UUID_HUMAN_INTERFACE_DEVICE_SERVICE = 0x1812,
00037         UUID_IMMEDIATE_ALERT_SERVICE        = 0x1802,
00038         UUID_LINK_LOSS_SERVICE              = 0x1803,
00039         UUID_NEXT_DST_CHANGE_SERVICE        = 0x1807,
00040         UUID_PHONE_ALERT_STATUS_SERVICE     = 0x180E,
00041         UUID_REFERENCE_TIME_UPDATE_SERVICE  = 0x1806,
00042         UUID_RUNNING_SPEED_AND_CADENCE      = 0x1814,
00043         UUID_SCAN_PARAMETERS_SERVICE        = 0x1813,
00044         UUID_TX_POWER_SERVICE               = 0x1804
00045     };
00046 
00047 public:
00048     /**
00049      *  @brief  Creates a new GattService using the specified UUID and characteristics.
00050      *
00051      *  @note   The UUID value must be unique and is normally >1.
00052      *
00053      *  @param[in]  uuid
00054      *              The UUID to use for this service.
00055      *  @param[in]  characteristics
00056      *              A pointer to an array of characteristics to be included within this service.
00057      *  @param[in]  numCharacteristics
00058      *              The number of characteristics.
00059      */
00060     GattService(const UUID &uuid, GattCharacteristic *characteristics[], unsigned numCharacteristics) :
00061         _primaryServiceID(uuid),
00062         _characteristicCount(numCharacteristics),
00063         _characteristics(characteristics),
00064         _handle(0) {
00065         /* empty */
00066     }
00067 
00068     /**
00069      * Get this service's UUID.
00070      *
00071      * @return A reference to the service's UUID.
00072      */
00073     const UUID &getUUID(void) const {
00074         return _primaryServiceID;
00075     }
00076 
00077     /**
00078      * Get handle of the service declaration attribute in the ATT table.
00079      *
00080      * @return The service's handle.
00081      */
00082     uint16_t getHandle(void) const {
00083         return _handle;
00084     }
00085 
00086     /**
00087      * Get the total number of characteristics within this service.
00088      *
00089      * @return The total number of characteristics within this service.
00090      */
00091     uint8_t getCharacteristicCount(void) const {
00092         return _characteristicCount;
00093     }
00094 
00095     /**
00096      * Set the handle of the service declaration attribute in the ATT table.
00097      *
00098      * @param[in] handle
00099      *              The service's handle.
00100      */
00101     void setHandle(uint16_t handle) {
00102         _handle = handle;
00103     }
00104 
00105     /**
00106      * Get this service's characteristic at a specific index.
00107      *
00108      * @param[in] index
00109      *              The index of the characteristic.
00110      *
00111      * @return A pointer to the characteristic at index @p index.
00112      */
00113     GattCharacteristic *getCharacteristic(uint8_t index) {
00114         if (index >= _characteristicCount) {
00115             return NULL;
00116         }
00117 
00118         return _characteristics[index];
00119     }
00120 
00121 private:
00122     /**
00123      * This service's UUID.
00124      */
00125     UUID                 _primaryServiceID;
00126     /**
00127      * Total number of characteristics within this service.
00128      */
00129     uint8_t              _characteristicCount;
00130     /**
00131      * An array with pointers to the characteristics added to this service.
00132      */
00133     GattCharacteristic **_characteristics;
00134     /**
00135      * Handle of the service declaration attribute in the ATT table.
00136      *
00137      * @note This handle is generally assigned by the underlying BLE stack when the
00138      *       service is added to the ATT table.
00139      */
00140     uint16_t             _handle;
00141 };
00142 
00143 #endif /* ifndef __GATT_SERVICE_H__ */