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