Skip to content

Commit fdfd14c

Browse files
author
carlescufi
committed
Add an Attribute class and derive GattCharacteristic from it, to prepare for descriptors
1 parent d498467 commit fdfd14c

File tree

2 files changed

+93
-25
lines changed

2 files changed

+93
-25
lines changed

public/GattAttribute.h

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
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__

public/GattCharacteristic.h

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,14 @@
2020

2121
#include "blecommon.h"
2222
#include "UUID.h"
23+
#include "GattAttribute.h"
2324

2425
/**************************************************************************/
2526
/*!
2627
\brief GATT characteristic
2728
*/
2829
/**************************************************************************/
29-
class GattCharacteristic
30+
class GattCharacteristic : public GattAttribute
3031
{
3132
public:
3233
enum {
@@ -325,39 +326,17 @@ class GattCharacteristic
325326
/**************************************************************************/
326327
GattCharacteristic(const UUID &uuid, uint8_t *valuePtr = NULL, uint16_t initialLen = 0, uint16_t maxLen = 0,
327328
uint8_t props = BLE_GATT_CHAR_PROPERTIES_NONE) :
328-
_uuid(uuid), _valuePtr(valuePtr), _initialLen(initialLen), _lenMax(maxLen), _handle(), _properties(props) {
329+
GattAttribute(uuid, valuePtr, initialLen, maxLen), _properties(props) {
329330
/* empty */
330331
}
331332

332333
public:
333-
uint16_t getHandle(void) const {
334-
return _handle;
335-
}
336-
void setHandle(uint16_t id) {
337-
_handle = id;
338-
}
339-
const UUID &getUUID(void) const {
340-
return _uuid;
341-
}
342334
uint8_t getProperties(void) const {
343335
return _properties;
344336
}
345-
uint16_t getInitialLength(void) const {
346-
return _initialLen;
347-
}
348-
uint16_t getMaxLength(void) const {
349-
return _lenMax;
350-
}
351-
uint8_t *getValuePtr(void) {
352-
return _valuePtr;
353-
}
337+
354338

355339
private:
356-
UUID _uuid; /* Characteristic UUID */
357-
uint8_t *_valuePtr;
358-
uint16_t _initialLen; /* Initial length of the value */
359-
uint16_t _lenMax; /* Maximum length of the value */
360-
uint16_t _handle;
361340
uint8_t _properties;
362341
};
363342

0 commit comments

Comments
 (0)