User | Revision | Line number | New contents of line |
switches |
0:0e018d759a2a
|
1
|
/* mbed Microcontroller Library
|
switches |
0:0e018d759a2a
|
2
|
* Copyright (c) 2006-2013 ARM Limited
|
switches |
0:0e018d759a2a
|
3
|
*
|
switches |
0:0e018d759a2a
|
4
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
switches |
0:0e018d759a2a
|
5
|
* you may not use this file except in compliance with the License.
|
switches |
0:0e018d759a2a
|
6
|
* You may obtain a copy of the License at
|
switches |
0:0e018d759a2a
|
7
|
*
|
switches |
0:0e018d759a2a
|
8
|
* http://www.apache.org/licenses/LICENSE-2.0
|
switches |
0:0e018d759a2a
|
9
|
*
|
switches |
0:0e018d759a2a
|
10
|
* Unless required by applicable law or agreed to in writing, software
|
switches |
0:0e018d759a2a
|
11
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
switches |
0:0e018d759a2a
|
12
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
switches |
0:0e018d759a2a
|
13
|
* See the License for the specific language governing permissions and
|
switches |
0:0e018d759a2a
|
14
|
* limitations under the License.
|
switches |
0:0e018d759a2a
|
15
|
*/
|
switches |
0:0e018d759a2a
|
16
|
|
switches |
0:0e018d759a2a
|
17
|
#ifndef __GATT_SERVICE_H__
|
switches |
0:0e018d759a2a
|
18
|
#define __GATT_SERVICE_H__
|
switches |
0:0e018d759a2a
|
19
|
|
switches |
0:0e018d759a2a
|
20
|
#include "UUID.h"
|
switches |
0:0e018d759a2a
|
21
|
#include "GattCharacteristic.h"
|
switches |
0:0e018d759a2a
|
22
|
|
switches |
0:0e018d759a2a
|
23
|
class GattService {
|
switches |
0:0e018d759a2a
|
24
|
public:
|
switches |
0:0e018d759a2a
|
25
|
enum {
|
switches |
0:0e018d759a2a
|
26
|
UUID_ALERT_NOTIFICATION_SERVICE = 0x1811,
|
switches |
0:0e018d759a2a
|
27
|
UUID_BATTERY_SERVICE = 0x180F,
|
switches |
0:0e018d759a2a
|
28
|
UUID_BLOOD_PRESSURE_SERVICE = 0x1810,
|
switches |
0:0e018d759a2a
|
29
|
UUID_CURRENT_TIME_SERVICE = 0x1805,
|
switches |
0:0e018d759a2a
|
30
|
UUID_CYCLING_SPEED_AND_CADENCE = 0x1816,
|
switches |
0:0e018d759a2a
|
31
|
UUID_DEVICE_INFORMATION_SERVICE = 0x180A,
|
switches |
0:0e018d759a2a
|
32
|
UUID_ENVIRONMENTAL_SERVICE = 0x181A,
|
switches |
0:0e018d759a2a
|
33
|
UUID_GLUCOSE_SERVICE = 0x1808,
|
switches |
0:0e018d759a2a
|
34
|
UUID_HEALTH_THERMOMETER_SERVICE = 0x1809,
|
switches |
0:0e018d759a2a
|
35
|
UUID_HEART_RATE_SERVICE = 0x180D,
|
switches |
0:0e018d759a2a
|
36
|
UUID_HUMAN_INTERFACE_DEVICE_SERVICE = 0x1812,
|
switches |
0:0e018d759a2a
|
37
|
UUID_IMMEDIATE_ALERT_SERVICE = 0x1802,
|
switches |
0:0e018d759a2a
|
38
|
UUID_LINK_LOSS_SERVICE = 0x1803,
|
switches |
0:0e018d759a2a
|
39
|
UUID_NEXT_DST_CHANGE_SERVICE = 0x1807,
|
switches |
0:0e018d759a2a
|
40
|
UUID_PHONE_ALERT_STATUS_SERVICE = 0x180E,
|
switches |
0:0e018d759a2a
|
41
|
UUID_REFERENCE_TIME_UPDATE_SERVICE = 0x1806,
|
switches |
0:0e018d759a2a
|
42
|
UUID_RUNNING_SPEED_AND_CADENCE = 0x1814,
|
switches |
0:0e018d759a2a
|
43
|
UUID_SCAN_PARAMETERS_SERVICE = 0x1813,
|
switches |
0:0e018d759a2a
|
44
|
UUID_TX_POWER_SERVICE = 0x1804
|
switches |
0:0e018d759a2a
|
45
|
};
|
switches |
0:0e018d759a2a
|
46
|
|
switches |
0:0e018d759a2a
|
47
|
public:
|
switches |
0:0e018d759a2a
|
48
|
/**
|
switches |
0:0e018d759a2a
|
49
|
* @brief Creates a new GattService using the specified 16-bit
|
switches |
0:0e018d759a2a
|
50
|
* UUID, value length, and properties.
|
switches |
0:0e018d759a2a
|
51
|
*
|
switches |
0:0e018d759a2a
|
52
|
* @note The UUID value must be unique and is normally >1.
|
switches |
0:0e018d759a2a
|
53
|
*
|
switches |
0:0e018d759a2a
|
54
|
* @param[in] uuid
|
switches |
0:0e018d759a2a
|
55
|
* The UUID to use for this service.
|
switches |
0:0e018d759a2a
|
56
|
* @param[in] characteristics
|
switches |
0:0e018d759a2a
|
57
|
* A pointer to an array of characteristics to be included within this service.
|
switches |
0:0e018d759a2a
|
58
|
* @param[in] numCharacteristics
|
switches |
0:0e018d759a2a
|
59
|
* The number of characteristics.
|
switches |
0:0e018d759a2a
|
60
|
*/
|
switches |
0:0e018d759a2a
|
61
|
GattService(const UUID &uuid, GattCharacteristic *characteristics[], unsigned numCharacteristics) :
|
switches |
0:0e018d759a2a
|
62
|
_primaryServiceID(uuid),
|
switches |
0:0e018d759a2a
|
63
|
_characteristicCount(numCharacteristics),
|
switches |
0:0e018d759a2a
|
64
|
_characteristics(characteristics),
|
switches |
0:0e018d759a2a
|
65
|
_handle(0) {
|
switches |
0:0e018d759a2a
|
66
|
/* empty */
|
switches |
0:0e018d759a2a
|
67
|
}
|
switches |
0:0e018d759a2a
|
68
|
|
switches |
0:0e018d759a2a
|
69
|
/**
|
switches |
0:0e018d759a2a
|
70
|
* Get this service's UUID.
|
switches |
0:0e018d759a2a
|
71
|
*
|
switches |
0:0e018d759a2a
|
72
|
* @return A reference to the service's UUID.
|
switches |
0:0e018d759a2a
|
73
|
*/
|
switches |
0:0e018d759a2a
|
74
|
const UUID &getUUID(void) const {
|
switches |
0:0e018d759a2a
|
75
|
return _primaryServiceID;
|
switches |
0:0e018d759a2a
|
76
|
}
|
switches |
0:0e018d759a2a
|
77
|
|
switches |
0:0e018d759a2a
|
78
|
/**
|
switches |
0:0e018d759a2a
|
79
|
* Get handle of the service declaration attribute in the ATT table.
|
switches |
0:0e018d759a2a
|
80
|
*
|
switches |
0:0e018d759a2a
|
81
|
* @return The service's handle.
|
switches |
0:0e018d759a2a
|
82
|
*/
|
switches |
0:0e018d759a2a
|
83
|
uint16_t getHandle(void) const {
|
switches |
0:0e018d759a2a
|
84
|
return _handle;
|
switches |
0:0e018d759a2a
|
85
|
}
|
switches |
0:0e018d759a2a
|
86
|
|
switches |
0:0e018d759a2a
|
87
|
/**
|
switches |
0:0e018d759a2a
|
88
|
* Get the total number of characteristics within this service.
|
switches |
0:0e018d759a2a
|
89
|
*
|
switches |
0:0e018d759a2a
|
90
|
* @return The total number of characteristics within this service.
|
switches |
0:0e018d759a2a
|
91
|
*/
|
switches |
0:0e018d759a2a
|
92
|
uint8_t getCharacteristicCount(void) const {
|
switches |
0:0e018d759a2a
|
93
|
return _characteristicCount;
|
switches |
0:0e018d759a2a
|
94
|
}
|
switches |
0:0e018d759a2a
|
95
|
|
switches |
0:0e018d759a2a
|
96
|
/**
|
switches |
0:0e018d759a2a
|
97
|
* Set the handle of the service declaration attribute in the ATT table.
|
switches |
0:0e018d759a2a
|
98
|
*
|
switches |
0:0e018d759a2a
|
99
|
* @param[in] handle
|
switches |
0:0e018d759a2a
|
100
|
* The service's handle.
|
switches |
0:0e018d759a2a
|
101
|
*/
|
switches |
0:0e018d759a2a
|
102
|
void setHandle(uint16_t handle) {
|
switches |
0:0e018d759a2a
|
103
|
_handle = handle;
|
switches |
0:0e018d759a2a
|
104
|
}
|
switches |
0:0e018d759a2a
|
105
|
|
switches |
0:0e018d759a2a
|
106
|
/**
|
switches |
0:0e018d759a2a
|
107
|
* Get this service's characteristic at a specific index.
|
switches |
0:0e018d759a2a
|
108
|
*
|
switches |
0:0e018d759a2a
|
109
|
* @param[in] index
|
switches |
0:0e018d759a2a
|
110
|
* The index of the characteristic.
|
switches |
0:0e018d759a2a
|
111
|
*
|
switches |
0:0e018d759a2a
|
112
|
* @return A pointer to the characterisitic at index @p index.
|
switches |
0:0e018d759a2a
|
113
|
*/
|
switches |
0:0e018d759a2a
|
114
|
GattCharacteristic *getCharacteristic(uint8_t index) {
|
switches |
0:0e018d759a2a
|
115
|
if (index >= _characteristicCount) {
|
switches |
0:0e018d759a2a
|
116
|
return NULL;
|
switches |
0:0e018d759a2a
|
117
|
}
|
switches |
0:0e018d759a2a
|
118
|
|
switches |
0:0e018d759a2a
|
119
|
return _characteristics[index];
|
switches |
0:0e018d759a2a
|
120
|
}
|
switches |
0:0e018d759a2a
|
121
|
|
switches |
0:0e018d759a2a
|
122
|
private:
|
switches |
0:0e018d759a2a
|
123
|
/**
|
switches |
0:0e018d759a2a
|
124
|
* This service's UUID.
|
switches |
0:0e018d759a2a
|
125
|
*/
|
switches |
0:0e018d759a2a
|
126
|
UUID _primaryServiceID;
|
switches |
0:0e018d759a2a
|
127
|
/**
|
switches |
0:0e018d759a2a
|
128
|
* Total number of characteristics within this service.
|
switches |
0:0e018d759a2a
|
129
|
*/
|
switches |
0:0e018d759a2a
|
130
|
uint8_t _characteristicCount;
|
switches |
0:0e018d759a2a
|
131
|
/**
|
switches |
0:0e018d759a2a
|
132
|
* An array with pointers to the characteristics added to this service.
|
switches |
0:0e018d759a2a
|
133
|
*/
|
switches |
0:0e018d759a2a
|
134
|
GattCharacteristic **_characteristics;
|
switches |
0:0e018d759a2a
|
135
|
/**
|
switches |
0:0e018d759a2a
|
136
|
* Handle of the service declaration attribute in the ATT table.
|
switches |
0:0e018d759a2a
|
137
|
*
|
switches |
0:0e018d759a2a
|
138
|
* @note This handle is generally assigned by the underlying BLE stack when the
|
switches |
0:0e018d759a2a
|
139
|
* service is added to the ATT table.
|
switches |
0:0e018d759a2a
|
140
|
*/
|
switches |
0:0e018d759a2a
|
141
|
uint16_t _handle;
|
switches |
0:0e018d759a2a
|
142
|
};
|
switches |
0:0e018d759a2a
|
143
|
|
switches |
0:0e018d759a2a
|
144
|
#endif /* ifndef __GATT_SERVICE_H__ */
|