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