prova

Fork of BLE_API by Bluetooth Low Energy

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         
00027         UUID_ALERT_NOTIFICATION_SERVICE     = 0x1811,
00028         UUID_BATTERY_SERVICE                = 0x180F,
00029         UUID_BLOOD_PRESSURE_SERVICE         = 0x1810,
00030         UUID_CURRENT_TIME_SERVICE           = 0x1805,
00031         UUID_CYCLING_SPEED_AND_CADENCE      = 0x1816,
00032         UUID_DEVICE_INFORMATION_SERVICE     = 0x180A,
00033         UUID_ENVIRONMENTAL_SERVICE          = 0x181A,
00034         UUID_GLUCOSE_SERVICE                = 0x1808,
00035         UUID_HEALTH_THERMOMETER_SERVICE     = 0x1809,
00036         UUID_HEART_RATE_SERVICE             = 0x180D,         //Originale
00037         
00038         UUID_HUMAN_INTERFACE_DEVICE_SERVICE = 0x1812,
00039         UUID_IMMEDIATE_ALERT_SERVICE        = 0x1802,
00040         UUID_LINK_LOSS_SERVICE              = 0x1803,
00041         UUID_NEXT_DST_CHANGE_SERVICE        = 0x1807,
00042         UUID_PHONE_ALERT_STATUS_SERVICE     = 0x180E,
00043         UUID_REFERENCE_TIME_UPDATE_SERVICE  = 0x1806,
00044         UUID_RUNNING_SPEED_AND_CADENCE      = 0x1814,
00045         UUID_SCAN_PARAMETERS_SERVICE        = 0x1813,
00046         UUID_TX_POWER_SERVICE               = 0x1804
00047     };
00048 
00049 public:
00050     /**
00051      *  @brief  Creates a new GattService using the specified 16-bit
00052      *          UUID, value length, and properties.
00053      *
00054      *  @note   The UUID value must be unique and is normally >1.
00055      *
00056      *  @param[in]  uuid
00057      *              The UUID to use for this service.
00058      *  @param[in]  characteristics
00059      *              A pointer to an array of characteristics to be included within this service.
00060      *  @param[in]  numCharacteristics
00061      *              The number of characteristics.
00062      */
00063     GattService(const UUID &uuid, GattCharacteristic *characteristics[], unsigned numCharacteristics) :
00064         _primaryServiceID(uuid),
00065         _characteristicCount(numCharacteristics),
00066         _characteristics(characteristics),
00067         _handle(0) {
00068         /* empty */
00069     }
00070 
00071     /**
00072      * Get this service's UUID.
00073      *
00074      * @return A reference to the service's UUID.
00075      */
00076     const UUID &getUUID(void) const {
00077         return _primaryServiceID;
00078     }
00079 
00080     /**
00081      * Get handle of the service declaration attribute in the ATT table.
00082      *
00083      * @return The service's handle.
00084      */
00085     uint16_t getHandle(void) const {
00086         return _handle;
00087     }
00088 
00089     /**
00090      * Get the total number of characteristics within this service.
00091      *
00092      * @return The total number of characteristics within this service.
00093      */
00094     uint8_t getCharacteristicCount(void) const {
00095         return _characteristicCount;
00096     }
00097 
00098     /**
00099      * Set the handle of the service declaration attribute in the ATT table.
00100      *
00101      * @param[in] handle
00102      *              The service's handle.
00103      */
00104     void setHandle(uint16_t handle) {
00105         _handle = handle;
00106     }
00107 
00108     /**
00109      * Get this service's characteristic at a specific index.
00110      *
00111      * @param[in] index
00112      *              The index of the characteristic.
00113      *
00114      * @return A pointer to the characterisitic at index @p index.
00115      */
00116     GattCharacteristic *getCharacteristic(uint8_t index) {
00117         if (index >= _characteristicCount) {
00118             return NULL;
00119         }
00120 
00121         return _characteristics[index];
00122     }
00123 
00124 private:
00125     /**
00126      * This service's UUID.
00127      */
00128     UUID                 _primaryServiceID;
00129     /**
00130      * Total number of characteristics within this service.
00131      */
00132     uint8_t              _characteristicCount;
00133     /**
00134      * An array with pointers to the characteristics added to this service.
00135      */
00136     GattCharacteristic **_characteristics;
00137     /**
00138      * Handle of the service declaration attribute in the ATT table.
00139      *
00140      * @note This handle is generally assigned by the underlying BLE stack when the
00141      *       service is added to the ATT table.
00142      */
00143     uint16_t             _handle;
00144 };
00145 
00146 #endif /* ifndef __GATT_SERVICE_H__ */