Holla back

Fork of BLE_API by Bluetooth Low Energy

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers GattAttribute.h Source File

GattAttribute.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 
00018 #ifndef __GATT_ATTRIBUTE_H__
00019 #define __GATT_ATTRIBUTE_H__
00020 
00021 #include "blecommon.h"
00022 #include "UUID.h"
00023 
00024 /**************************************************************************/
00025 /*!
00026     \brief  GATT attribute
00027 */
00028 /**************************************************************************/
00029 class GattAttribute
00030 {
00031 public:
00032     typedef uint16_t Handle_t;
00033 
00034 public:
00035     /**
00036      *  @brief  Creates a new GattAttribute using the specified
00037      *          UUID, value length, and inital value
00038      *
00039      *  @param[in]  uuid
00040      *              The UUID to use for this attribute
00041      *  @param[in]  valuePtr
00042      *              The memory holding the initial value.
00043      *  @param[in]  initialLen
00044      *              The min length in bytes of this characteristic's value
00045      *  @param[in]  maxLen
00046      *              The max length in bytes of this characteristic's value
00047      *
00048      *  @section EXAMPLE
00049      *
00050      *  @code
00051      *
00052      *  // UUID = 0x2A19, Min length 2, Max len = 2, Properties = write
00053      *  GattCharacteristic c = GattCharacteristic( 0x2A19, 2, 2, BLE_GATT_CHAR_PROPERTIES_WRITE );
00054      *
00055      *  @endcode
00056      */
00057     /**************************************************************************/
00058     GattAttribute(const UUID &uuid, uint8_t *valuePtr = NULL, uint16_t initialLen = 0, uint16_t maxLen = 0) :
00059         _uuid(uuid), _valuePtr(valuePtr), _initialLen(initialLen), _lenMax(maxLen), _handle(){
00060         /* empty */
00061     }
00062 
00063 public:
00064     Handle_t getHandle(void) const {
00065         return _handle;
00066     }
00067 
00068     void setHandle(Handle_t id) {
00069         _handle = id;
00070     }
00071 
00072     const UUID &getUUID(void) const {
00073         return _uuid;
00074     }
00075 
00076     uint16_t getInitialLength(void) const {
00077         return _initialLen;
00078     }
00079 
00080     uint16_t getMaxLength(void) const {
00081         return _lenMax;
00082     }
00083 
00084     uint8_t *getValuePtr(void) {
00085         return _valuePtr;
00086     }
00087 
00088 protected:
00089     UUID      _uuid;        /* Characteristic UUID */
00090     uint8_t  *_valuePtr;
00091     uint16_t  _initialLen;  /* Initial length of the value */
00092     uint16_t  _lenMax;      /* Maximum length of the value */
00093     Handle_t  _handle;
00094 };
00095 
00096 #endif // ifndef __GATT_ATTRIBUTE_H__