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