Lancaster University's fork of the mbed BLE API. Lives on github, https://github.com/lancaster-university/BLE_API
Dependents: microbit-dal microbit-dal microbit-ble-open microbit-dal ... more
Fork of BLE_API by
GattAttribute.h
00001 /* mbed Microcontroller Library 00002 * Copyright (c) 2006-2013 ARM Limited 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #ifndef __GATT_ATTRIBUTE_H__ 00018 #define __GATT_ATTRIBUTE_H__ 00019 00020 #include "UUID.h" 00021 00022 class GattAttribute { 00023 public: 00024 typedef uint16_t Handle_t; 00025 static const Handle_t INVALID_HANDLE = 0x0000; 00026 00027 public: 00028 /** 00029 * @brief Creates a new GattAttribute using the specified 00030 * UUID, value length, and inital value. 00031 * 00032 * @param[in] uuid 00033 * The UUID to use for this attribute. 00034 * @param[in] valuePtr 00035 * The memory holding the initial value. 00036 * @param[in] len 00037 * The length in bytes of this attribute's value. 00038 * @param[in] maxLen 00039 * The max length in bytes of this attribute's value. 00040 * @param[in] hasVariableLen 00041 * Whether the attribute's value length changes overtime. 00042 * 00043 * @section EXAMPLE 00044 * 00045 * @code 00046 * 00047 * // UUID = 0x2A19, Min length 2, Max len = 2 00048 * GattAttribute attr = GattAttribute(0x2A19, &someValue, 2, 2); 00049 * 00050 * @endcode 00051 */ 00052 GattAttribute(const UUID &uuid, uint8_t *valuePtr = NULL, uint16_t len = 0, uint16_t maxLen = 0, bool hasVariableLen = true) : 00053 _uuid(uuid), _valuePtr(valuePtr), _lenMax(maxLen), _len(len), _hasVariableLen(hasVariableLen), _handle() { 00054 /* Empty */ 00055 } 00056 00057 public: 00058 Handle_t getHandle(void) const {return _handle; } 00059 const UUID &getUUID(void) const {return _uuid; } 00060 uint16_t getLength(void) const {return _len; } 00061 uint16_t getMaxLength(void) const {return _lenMax; } 00062 uint16_t *getLengthPtr(void) {return &_len; } 00063 void setHandle(Handle_t id) {_handle = id; } 00064 uint8_t *getValuePtr(void) {return _valuePtr; } 00065 bool hasVariableLength(void) const {return _hasVariableLen;} 00066 00067 private: 00068 UUID _uuid; /* Characteristic UUID. */ 00069 uint8_t *_valuePtr; 00070 uint16_t _lenMax; /* Maximum length of the value. */ 00071 uint16_t _len; /* Current length of the value. */ 00072 bool _hasVariableLen; 00073 Handle_t _handle; 00074 00075 private: 00076 /* Disallow copy and assignment. */ 00077 GattAttribute(const GattAttribute &); 00078 GattAttribute& operator=(const GattAttribute &); 00079 }; 00080 00081 #endif // ifndef __GATT_ATTRIBUTE_H__
Generated on Tue Jul 12 2022 17:17:58 by 1.7.2