abc

Fork of BLE_API by Bluetooth Low Energy

Committer:
carlescufi
Date:
Wed Aug 27 15:22:22 2014 +0200
Revision:
112:64c88ad45610
Child:
118:620d28e7a1ba
Add an Attribute class and derive GattCharacteristic from it, to prepare for descriptors

Who changed what in which revision?

UserRevisionLine numberNew contents of line
carlescufi 112:64c88ad45610 1 /* mbed Microcontroller Library
carlescufi 112:64c88ad45610 2 * Copyright (c) 2006-2013 ARM Limited
carlescufi 112:64c88ad45610 3 *
carlescufi 112:64c88ad45610 4 * Licensed under the Apache License, Version 2.0 (the "License");
carlescufi 112:64c88ad45610 5 * you may not use this file except in compliance with the License.
carlescufi 112:64c88ad45610 6 * You may obtain a copy of the License at
carlescufi 112:64c88ad45610 7 *
carlescufi 112:64c88ad45610 8 * http://www.apache.org/licenses/LICENSE-2.0
carlescufi 112:64c88ad45610 9 *
carlescufi 112:64c88ad45610 10 * Unless required by applicable law or agreed to in writing, software
carlescufi 112:64c88ad45610 11 * distributed under the License is distributed on an "AS IS" BASIS,
carlescufi 112:64c88ad45610 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
carlescufi 112:64c88ad45610 13 * See the License for the specific language governing permissions and
carlescufi 112:64c88ad45610 14 * limitations under the License.
carlescufi 112:64c88ad45610 15 */
carlescufi 112:64c88ad45610 16
carlescufi 112:64c88ad45610 17
carlescufi 112:64c88ad45610 18 #ifndef __GATT_ATTRIBUTE_H__
carlescufi 112:64c88ad45610 19 #define __GATT_ATTRIBUTE_H__
carlescufi 112:64c88ad45610 20
carlescufi 112:64c88ad45610 21 #include "blecommon.h"
carlescufi 112:64c88ad45610 22 #include "UUID.h"
carlescufi 112:64c88ad45610 23
carlescufi 112:64c88ad45610 24 /**************************************************************************/
carlescufi 112:64c88ad45610 25 /*!
carlescufi 112:64c88ad45610 26 \brief GATT attribute
carlescufi 112:64c88ad45610 27 */
carlescufi 112:64c88ad45610 28 /**************************************************************************/
carlescufi 112:64c88ad45610 29 class GattAttribute
carlescufi 112:64c88ad45610 30 {
carlescufi 112:64c88ad45610 31 public:
carlescufi 112:64c88ad45610 32
carlescufi 112:64c88ad45610 33 /**
carlescufi 112:64c88ad45610 34 * @brief Creates a new GattAttribute using the specified
carlescufi 112:64c88ad45610 35 * UUID, value length, and inital value
carlescufi 112:64c88ad45610 36 *
carlescufi 112:64c88ad45610 37 * @param[in] uuid
carlescufi 112:64c88ad45610 38 * The UUID to use for this attribute
carlescufi 112:64c88ad45610 39 * @param[in] valuePtr
carlescufi 112:64c88ad45610 40 * The memory holding the initial value.
carlescufi 112:64c88ad45610 41 * @param[in] initialLen
carlescufi 112:64c88ad45610 42 * The min length in bytes of this characteristic's value
carlescufi 112:64c88ad45610 43 * @param[in] maxLen
carlescufi 112:64c88ad45610 44 * The max length in bytes of this characteristic's value
carlescufi 112:64c88ad45610 45 *
carlescufi 112:64c88ad45610 46 * @section EXAMPLE
carlescufi 112:64c88ad45610 47 *
carlescufi 112:64c88ad45610 48 * @code
carlescufi 112:64c88ad45610 49 *
carlescufi 112:64c88ad45610 50 * // UUID = 0x2A19, Min length 2, Max len = 2, Properties = write
carlescufi 112:64c88ad45610 51 * GattCharacteristic c = GattCharacteristic( 0x2A19, 2, 2, BLE_GATT_CHAR_PROPERTIES_WRITE );
carlescufi 112:64c88ad45610 52 *
carlescufi 112:64c88ad45610 53 * @endcode
carlescufi 112:64c88ad45610 54 */
carlescufi 112:64c88ad45610 55 /**************************************************************************/
carlescufi 112:64c88ad45610 56 GattAttribute(const UUID &uuid, uint8_t *valuePtr = NULL, uint16_t initialLen = 0, uint16_t maxLen = 0) :
carlescufi 112:64c88ad45610 57 _uuid(uuid), _valuePtr(valuePtr), _initialLen(initialLen), _lenMax(maxLen), _handle(){
carlescufi 112:64c88ad45610 58 /* empty */
carlescufi 112:64c88ad45610 59 }
carlescufi 112:64c88ad45610 60
carlescufi 112:64c88ad45610 61 public:
carlescufi 112:64c88ad45610 62 uint16_t getHandle(void) const {
carlescufi 112:64c88ad45610 63 return _handle;
carlescufi 112:64c88ad45610 64 }
carlescufi 112:64c88ad45610 65 void setHandle(uint16_t id) {
carlescufi 112:64c88ad45610 66 _handle = id;
carlescufi 112:64c88ad45610 67 }
carlescufi 112:64c88ad45610 68 const UUID &getUUID(void) const {
carlescufi 112:64c88ad45610 69 return _uuid;
carlescufi 112:64c88ad45610 70 }
carlescufi 112:64c88ad45610 71 uint16_t getInitialLength(void) const {
carlescufi 112:64c88ad45610 72 return _initialLen;
carlescufi 112:64c88ad45610 73 }
carlescufi 112:64c88ad45610 74 uint16_t getMaxLength(void) const {
carlescufi 112:64c88ad45610 75 return _lenMax;
carlescufi 112:64c88ad45610 76 }
carlescufi 112:64c88ad45610 77 uint8_t *getValuePtr(void) {
carlescufi 112:64c88ad45610 78 return _valuePtr;
carlescufi 112:64c88ad45610 79 }
carlescufi 112:64c88ad45610 80
carlescufi 112:64c88ad45610 81 protected:
carlescufi 112:64c88ad45610 82 UUID _uuid; /* Characteristic UUID */
carlescufi 112:64c88ad45610 83 uint8_t *_valuePtr;
carlescufi 112:64c88ad45610 84 uint16_t _initialLen; /* Initial length of the value */
carlescufi 112:64c88ad45610 85 uint16_t _lenMax; /* Maximum length of the value */
carlescufi 112:64c88ad45610 86 uint16_t _handle;
carlescufi 112:64c88ad45610 87 };
carlescufi 112:64c88ad45610 88
carlescufi 112:64c88ad45610 89 #endif // ifndef __GATT_ATTRIBUTE_H__