Official Sheffield ARMBand micro:bit program

Committer:
MrBedfordVan
Date:
Mon Oct 17 12:41:20 2016 +0000
Revision:
0:b9164b348919
Official Sheffield ARMBand Micro:bit program

Who changed what in which revision?

UserRevisionLine numberNew contents of line
MrBedfordVan 0:b9164b348919 1 /* mbed Microcontroller Library
MrBedfordVan 0:b9164b348919 2 * Copyright (c) 2006-2013 ARM Limited
MrBedfordVan 0:b9164b348919 3 *
MrBedfordVan 0:b9164b348919 4 * Licensed under the Apache License, Version 2.0 (the "License");
MrBedfordVan 0:b9164b348919 5 * you may not use this file except in compliance with the License.
MrBedfordVan 0:b9164b348919 6 * You may obtain a copy of the License at
MrBedfordVan 0:b9164b348919 7 *
MrBedfordVan 0:b9164b348919 8 * http://www.apache.org/licenses/LICENSE-2.0
MrBedfordVan 0:b9164b348919 9 *
MrBedfordVan 0:b9164b348919 10 * Unless required by applicable law or agreed to in writing, software
MrBedfordVan 0:b9164b348919 11 * distributed under the License is distributed on an "AS IS" BASIS,
MrBedfordVan 0:b9164b348919 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
MrBedfordVan 0:b9164b348919 13 * See the License for the specific language governing permissions and
MrBedfordVan 0:b9164b348919 14 * limitations under the License.
MrBedfordVan 0:b9164b348919 15 */
MrBedfordVan 0:b9164b348919 16
MrBedfordVan 0:b9164b348919 17 #ifndef __GATT_ATTRIBUTE_H__
MrBedfordVan 0:b9164b348919 18 #define __GATT_ATTRIBUTE_H__
MrBedfordVan 0:b9164b348919 19
MrBedfordVan 0:b9164b348919 20 #include "UUID.h"
MrBedfordVan 0:b9164b348919 21
MrBedfordVan 0:b9164b348919 22 class GattAttribute {
MrBedfordVan 0:b9164b348919 23 public:
MrBedfordVan 0:b9164b348919 24 typedef uint16_t Handle_t;
MrBedfordVan 0:b9164b348919 25 static const Handle_t INVALID_HANDLE = 0x0000;
MrBedfordVan 0:b9164b348919 26
MrBedfordVan 0:b9164b348919 27 public:
MrBedfordVan 0:b9164b348919 28 /**
MrBedfordVan 0:b9164b348919 29 * @brief Creates a new GattAttribute using the specified
MrBedfordVan 0:b9164b348919 30 * UUID, value length, and inital value.
MrBedfordVan 0:b9164b348919 31 *
MrBedfordVan 0:b9164b348919 32 * @param[in] uuid
MrBedfordVan 0:b9164b348919 33 * The UUID to use for this attribute.
MrBedfordVan 0:b9164b348919 34 * @param[in] valuePtr
MrBedfordVan 0:b9164b348919 35 * The memory holding the initial value.
MrBedfordVan 0:b9164b348919 36 * @param[in] len
MrBedfordVan 0:b9164b348919 37 * The length in bytes of this attribute's value.
MrBedfordVan 0:b9164b348919 38 * @param[in] maxLen
MrBedfordVan 0:b9164b348919 39 * The max length in bytes of this attribute's value.
MrBedfordVan 0:b9164b348919 40 * @param[in] hasVariableLen
MrBedfordVan 0:b9164b348919 41 * Whether the attribute's value length changes overtime.
MrBedfordVan 0:b9164b348919 42 *
MrBedfordVan 0:b9164b348919 43 * @section EXAMPLE
MrBedfordVan 0:b9164b348919 44 *
MrBedfordVan 0:b9164b348919 45 * @code
MrBedfordVan 0:b9164b348919 46 *
MrBedfordVan 0:b9164b348919 47 * // UUID = 0x2A19, Min length 2, Max len = 2
MrBedfordVan 0:b9164b348919 48 * GattAttribute attr = GattAttribute(0x2A19, &someValue, 2, 2);
MrBedfordVan 0:b9164b348919 49 *
MrBedfordVan 0:b9164b348919 50 * @endcode
MrBedfordVan 0:b9164b348919 51 */
MrBedfordVan 0:b9164b348919 52 GattAttribute(const UUID &uuid, uint8_t *valuePtr = NULL, uint16_t len = 0, uint16_t maxLen = 0, bool hasVariableLen = true) :
MrBedfordVan 0:b9164b348919 53 _uuid(uuid), _valuePtr(valuePtr), _lenMax(maxLen), _len(len), _hasVariableLen(hasVariableLen), _handle() {
MrBedfordVan 0:b9164b348919 54 /* Empty */
MrBedfordVan 0:b9164b348919 55 }
MrBedfordVan 0:b9164b348919 56
MrBedfordVan 0:b9164b348919 57 public:
MrBedfordVan 0:b9164b348919 58 Handle_t getHandle(void) const {return _handle; }
MrBedfordVan 0:b9164b348919 59 const UUID &getUUID(void) const {return _uuid; }
MrBedfordVan 0:b9164b348919 60 uint16_t getLength(void) const {return _len; }
MrBedfordVan 0:b9164b348919 61 uint16_t getMaxLength(void) const {return _lenMax; }
MrBedfordVan 0:b9164b348919 62 uint16_t *getLengthPtr(void) {return &_len; }
MrBedfordVan 0:b9164b348919 63 void setHandle(Handle_t id) {_handle = id; }
MrBedfordVan 0:b9164b348919 64 uint8_t *getValuePtr(void) {return _valuePtr; }
MrBedfordVan 0:b9164b348919 65 bool hasVariableLength(void) const {return _hasVariableLen;}
MrBedfordVan 0:b9164b348919 66
MrBedfordVan 0:b9164b348919 67 private:
MrBedfordVan 0:b9164b348919 68 UUID _uuid; /* Characteristic UUID. */
MrBedfordVan 0:b9164b348919 69 uint8_t *_valuePtr;
MrBedfordVan 0:b9164b348919 70 uint16_t _lenMax; /* Maximum length of the value. */
MrBedfordVan 0:b9164b348919 71 uint16_t _len; /* Current length of the value. */
MrBedfordVan 0:b9164b348919 72 bool _hasVariableLen;
MrBedfordVan 0:b9164b348919 73 Handle_t _handle;
MrBedfordVan 0:b9164b348919 74
MrBedfordVan 0:b9164b348919 75 private:
MrBedfordVan 0:b9164b348919 76 /* Disallow copy and assignment. */
MrBedfordVan 0:b9164b348919 77 GattAttribute(const GattAttribute &);
MrBedfordVan 0:b9164b348919 78 GattAttribute& operator=(const GattAttribute &);
MrBedfordVan 0:b9164b348919 79 };
MrBedfordVan 0:b9164b348919 80
MrBedfordVan 0:b9164b348919 81 #endif // ifndef __GATT_ATTRIBUTE_H__