BLE_API_Tiny_BLE
Fork of BLE_API by
public/GattAttribute.h@300:d9a39f759a6a, 2015-03-02 (annotated)
- Committer:
- rgrover1
- Date:
- Mon Mar 02 11:50:48 2015 +0000
- Revision:
- 300:d9a39f759a6a
- Parent:
- 299:c1e4400af825
- Child:
- 304:30618b2c9808
Synchronized with git rev 91b4b8f8
Author: Rohit Grover
initialize the min/max length values correctly in the constructor for URIDataChar.
Previously, the minLength value was always set to URI_DATA_MAX, whereas maxLen got initialized by the values stored persistently. Except for the case of default initialization, the value of maxLength would always be less than then minLength; causing improper behaviour from the underlying stack while setting up characterisitics.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rgrover1 | 260:ea7f9f14cc15 | 1 | /* mbed Microcontroller Library |
rgrover1 | 260:ea7f9f14cc15 | 2 | * Copyright (c) 2006-2013 ARM Limited |
rgrover1 | 260:ea7f9f14cc15 | 3 | * |
rgrover1 | 260:ea7f9f14cc15 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
rgrover1 | 260:ea7f9f14cc15 | 5 | * you may not use this file except in compliance with the License. |
rgrover1 | 260:ea7f9f14cc15 | 6 | * You may obtain a copy of the License at |
rgrover1 | 260:ea7f9f14cc15 | 7 | * |
rgrover1 | 260:ea7f9f14cc15 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
rgrover1 | 260:ea7f9f14cc15 | 9 | * |
rgrover1 | 260:ea7f9f14cc15 | 10 | * Unless required by applicable law or agreed to in writing, software |
rgrover1 | 260:ea7f9f14cc15 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
rgrover1 | 260:ea7f9f14cc15 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
rgrover1 | 260:ea7f9f14cc15 | 13 | * See the License for the specific language governing permissions and |
rgrover1 | 260:ea7f9f14cc15 | 14 | * limitations under the License. |
rgrover1 | 260:ea7f9f14cc15 | 15 | */ |
rgrover1 | 260:ea7f9f14cc15 | 16 | |
rgrover1 | 260:ea7f9f14cc15 | 17 | #ifndef __GATT_ATTRIBUTE_H__ |
rgrover1 | 260:ea7f9f14cc15 | 18 | #define __GATT_ATTRIBUTE_H__ |
rgrover1 | 260:ea7f9f14cc15 | 19 | |
rgrover1 | 260:ea7f9f14cc15 | 20 | class GattAttribute { |
rgrover1 | 260:ea7f9f14cc15 | 21 | public: |
rgrover1 | 260:ea7f9f14cc15 | 22 | typedef uint16_t Handle_t; |
rgrover1 | 260:ea7f9f14cc15 | 23 | |
rgrover1 | 260:ea7f9f14cc15 | 24 | public: |
rgrover1 | 260:ea7f9f14cc15 | 25 | /** |
rgrover1 | 260:ea7f9f14cc15 | 26 | * @brief Creates a new GattAttribute using the specified |
rgrover1 | 260:ea7f9f14cc15 | 27 | * UUID, value length, and inital value |
rgrover1 | 260:ea7f9f14cc15 | 28 | * |
rgrover1 | 260:ea7f9f14cc15 | 29 | * @param[in] uuid |
rgrover1 | 260:ea7f9f14cc15 | 30 | * The UUID to use for this attribute |
rgrover1 | 260:ea7f9f14cc15 | 31 | * @param[in] valuePtr |
rgrover1 | 260:ea7f9f14cc15 | 32 | * The memory holding the initial value. |
rgrover1 | 260:ea7f9f14cc15 | 33 | * @param[in] initialLen |
rgrover1 | 260:ea7f9f14cc15 | 34 | * The min length in bytes of this characteristic's value |
rgrover1 | 260:ea7f9f14cc15 | 35 | * @param[in] maxLen |
rgrover1 | 260:ea7f9f14cc15 | 36 | * The max length in bytes of this characteristic's value |
rgrover1 | 260:ea7f9f14cc15 | 37 | * |
rgrover1 | 260:ea7f9f14cc15 | 38 | * @section EXAMPLE |
rgrover1 | 260:ea7f9f14cc15 | 39 | * |
rgrover1 | 260:ea7f9f14cc15 | 40 | * @code |
rgrover1 | 260:ea7f9f14cc15 | 41 | * |
rgrover1 | 260:ea7f9f14cc15 | 42 | * // UUID = 0x2A19, Min length 2, Max len = 2, Properties = write |
rgrover1 | 260:ea7f9f14cc15 | 43 | * GattCharacteristic c = GattCharacteristic( 0x2A19, 2, 2, BLE_GATT_CHAR_PROPERTIES_WRITE ); |
rgrover1 | 260:ea7f9f14cc15 | 44 | * |
rgrover1 | 260:ea7f9f14cc15 | 45 | * @endcode |
rgrover1 | 260:ea7f9f14cc15 | 46 | */ |
rgrover1 | 260:ea7f9f14cc15 | 47 | /**************************************************************************/ |
rgrover1 | 260:ea7f9f14cc15 | 48 | GattAttribute(const UUID &uuid, uint8_t *valuePtr = NULL, uint16_t initialLen = 0, uint16_t maxLen = 0) : |
rgrover1 | 300:d9a39f759a6a | 49 | _uuid(uuid), _valuePtr(valuePtr), _initialLen(initialLen), _lenMax(maxLen), _handle() { |
rgrover1 | 260:ea7f9f14cc15 | 50 | /* empty */ |
rgrover1 | 260:ea7f9f14cc15 | 51 | } |
rgrover1 | 260:ea7f9f14cc15 | 52 | |
rgrover1 | 260:ea7f9f14cc15 | 53 | public: |
rgrover1 | 260:ea7f9f14cc15 | 54 | Handle_t getHandle(void) const {return _handle; } |
rgrover1 | 260:ea7f9f14cc15 | 55 | const UUID &getUUID(void) const {return _uuid; } |
rgrover1 | 260:ea7f9f14cc15 | 56 | uint16_t getInitialLength(void) const {return _initialLen;} |
rgrover1 | 260:ea7f9f14cc15 | 57 | uint16_t getMaxLength(void) const {return _lenMax; } |
rgrover1 | 260:ea7f9f14cc15 | 58 | void setHandle(Handle_t id) {_handle = id; } |
rgrover1 | 260:ea7f9f14cc15 | 59 | uint8_t *getValuePtr(void) {return _valuePtr; } |
rgrover1 | 260:ea7f9f14cc15 | 60 | |
rgrover1 | 260:ea7f9f14cc15 | 61 | private: |
rgrover1 | 260:ea7f9f14cc15 | 62 | UUID _uuid; /* Characteristic UUID */ |
rgrover1 | 260:ea7f9f14cc15 | 63 | uint8_t *_valuePtr; |
rgrover1 | 260:ea7f9f14cc15 | 64 | uint16_t _initialLen; /* Initial length of the value */ |
rgrover1 | 260:ea7f9f14cc15 | 65 | uint16_t _lenMax; /* Maximum length of the value */ |
rgrover1 | 260:ea7f9f14cc15 | 66 | Handle_t _handle; |
rgrover1 | 260:ea7f9f14cc15 | 67 | |
rgrover1 | 260:ea7f9f14cc15 | 68 | private: |
rgrover1 | 260:ea7f9f14cc15 | 69 | /* disallow copy and assignment */ |
rgrover1 | 260:ea7f9f14cc15 | 70 | GattAttribute(const GattAttribute &); |
rgrover1 | 260:ea7f9f14cc15 | 71 | GattAttribute& operator=(const GattAttribute &); |
rgrover1 | 260:ea7f9f14cc15 | 72 | }; |
rgrover1 | 260:ea7f9f14cc15 | 73 | |
rgrover1 | 260:ea7f9f14cc15 | 74 | #endif // ifndef __GATT_ATTRIBUTE_H__ |