BLE_API_Tiny_BLE

Dependents:   CSSE4011_BLE_IMU

Fork of BLE_API by Bluetooth Low Energy

Committer:
rgrover1
Date:
Fri Nov 21 09:23:24 2014 +0000
Revision:
139:baaf1c5f0db2
Parent:
137:4b648181ea6b
Child:
140:407d134c179d
Synchronized with git rev d93ad344
Author: Rohit Grover
Merge pull request #5 from xiongyihui/master

make the library less dependent on the mbed.h header

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:
Rohit Grover 118:620d28e7a1ba 32 typedef uint16_t Handle_t;
carlescufi 112:64c88ad45610 33
Rohit Grover 118:620d28e7a1ba 34 public:
carlescufi 112:64c88ad45610 35 /**
carlescufi 112:64c88ad45610 36 * @brief Creates a new GattAttribute using the specified
carlescufi 112:64c88ad45610 37 * UUID, value length, and inital value
carlescufi 112:64c88ad45610 38 *
carlescufi 112:64c88ad45610 39 * @param[in] uuid
carlescufi 112:64c88ad45610 40 * The UUID to use for this attribute
carlescufi 112:64c88ad45610 41 * @param[in] valuePtr
carlescufi 112:64c88ad45610 42 * The memory holding the initial value.
carlescufi 112:64c88ad45610 43 * @param[in] initialLen
carlescufi 112:64c88ad45610 44 * The min length in bytes of this characteristic's value
carlescufi 112:64c88ad45610 45 * @param[in] maxLen
carlescufi 112:64c88ad45610 46 * The max length in bytes of this characteristic's value
carlescufi 112:64c88ad45610 47 *
carlescufi 112:64c88ad45610 48 * @section EXAMPLE
carlescufi 112:64c88ad45610 49 *
carlescufi 112:64c88ad45610 50 * @code
carlescufi 112:64c88ad45610 51 *
carlescufi 112:64c88ad45610 52 * // UUID = 0x2A19, Min length 2, Max len = 2, Properties = write
carlescufi 112:64c88ad45610 53 * GattCharacteristic c = GattCharacteristic( 0x2A19, 2, 2, BLE_GATT_CHAR_PROPERTIES_WRITE );
carlescufi 112:64c88ad45610 54 *
carlescufi 112:64c88ad45610 55 * @endcode
carlescufi 112:64c88ad45610 56 */
carlescufi 112:64c88ad45610 57 /**************************************************************************/
carlescufi 112:64c88ad45610 58 GattAttribute(const UUID &uuid, uint8_t *valuePtr = NULL, uint16_t initialLen = 0, uint16_t maxLen = 0) :
carlescufi 112:64c88ad45610 59 _uuid(uuid), _valuePtr(valuePtr), _initialLen(initialLen), _lenMax(maxLen), _handle(){
carlescufi 112:64c88ad45610 60 /* empty */
carlescufi 112:64c88ad45610 61 }
carlescufi 112:64c88ad45610 62
carlescufi 112:64c88ad45610 63 public:
Rohit Grover 118:620d28e7a1ba 64 Handle_t getHandle(void) const {
carlescufi 112:64c88ad45610 65 return _handle;
carlescufi 112:64c88ad45610 66 }
Rohit Grover 118:620d28e7a1ba 67
Rohit Grover 118:620d28e7a1ba 68 void setHandle(Handle_t id) {
carlescufi 112:64c88ad45610 69 _handle = id;
carlescufi 112:64c88ad45610 70 }
Rohit Grover 118:620d28e7a1ba 71
carlescufi 112:64c88ad45610 72 const UUID &getUUID(void) const {
carlescufi 112:64c88ad45610 73 return _uuid;
carlescufi 112:64c88ad45610 74 }
Rohit Grover 118:620d28e7a1ba 75
carlescufi 112:64c88ad45610 76 uint16_t getInitialLength(void) const {
carlescufi 112:64c88ad45610 77 return _initialLen;
carlescufi 112:64c88ad45610 78 }
Rohit Grover 118:620d28e7a1ba 79
carlescufi 112:64c88ad45610 80 uint16_t getMaxLength(void) const {
carlescufi 112:64c88ad45610 81 return _lenMax;
carlescufi 112:64c88ad45610 82 }
Rohit Grover 118:620d28e7a1ba 83
carlescufi 112:64c88ad45610 84 uint8_t *getValuePtr(void) {
carlescufi 112:64c88ad45610 85 return _valuePtr;
carlescufi 112:64c88ad45610 86 }
carlescufi 112:64c88ad45610 87
carlescufi 112:64c88ad45610 88 protected:
carlescufi 112:64c88ad45610 89 UUID _uuid; /* Characteristic UUID */
carlescufi 112:64c88ad45610 90 uint8_t *_valuePtr;
carlescufi 112:64c88ad45610 91 uint16_t _initialLen; /* Initial length of the value */
carlescufi 112:64c88ad45610 92 uint16_t _lenMax; /* Maximum length of the value */
Rohit Grover 118:620d28e7a1ba 93 Handle_t _handle;
carlescufi 112:64c88ad45610 94 };
carlescufi 112:64c88ad45610 95
rgrover1 137:4b648181ea6b 96 #endif // ifndef __GATT_ATTRIBUTE_H__