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_CHARACTERISTIC_H__
|
switches |
0:0e018d759a2a
|
18
|
#define __GATT_CHARACTERISTIC_H__
|
switches |
0:0e018d759a2a
|
19
|
|
switches |
0:0e018d759a2a
|
20
|
#include "Gap.h"
|
switches |
0:0e018d759a2a
|
21
|
#include "SecurityManager.h"
|
switches |
0:0e018d759a2a
|
22
|
#include "GattAttribute.h"
|
switches |
0:0e018d759a2a
|
23
|
#include "GattCallbackParamTypes.h"
|
switches |
0:0e018d759a2a
|
24
|
#include "FunctionPointerWithContext.h"
|
switches |
0:0e018d759a2a
|
25
|
|
switches |
0:0e018d759a2a
|
26
|
class GattCharacteristic {
|
switches |
0:0e018d759a2a
|
27
|
public:
|
switches |
0:0e018d759a2a
|
28
|
enum {
|
switches |
0:0e018d759a2a
|
29
|
UUID_BATTERY_LEVEL_STATE_CHAR = 0x2A1B,
|
switches |
0:0e018d759a2a
|
30
|
UUID_BATTERY_POWER_STATE_CHAR = 0x2A1A,
|
switches |
0:0e018d759a2a
|
31
|
UUID_REMOVABLE_CHAR = 0x2A3A,
|
switches |
0:0e018d759a2a
|
32
|
UUID_SERVICE_REQUIRED_CHAR = 0x2A3B,
|
switches |
0:0e018d759a2a
|
33
|
UUID_ALERT_CATEGORY_ID_CHAR = 0x2A43,
|
switches |
0:0e018d759a2a
|
34
|
UUID_ALERT_CATEGORY_ID_BIT_MASK_CHAR = 0x2A42,
|
switches |
0:0e018d759a2a
|
35
|
UUID_ALERT_LEVEL_CHAR = 0x2A06,
|
switches |
0:0e018d759a2a
|
36
|
UUID_ALERT_NOTIFICATION_CONTROL_POINT_CHAR = 0x2A44,
|
switches |
0:0e018d759a2a
|
37
|
UUID_ALERT_STATUS_CHAR = 0x2A3F,
|
switches |
0:0e018d759a2a
|
38
|
UUID_BATTERY_LEVEL_CHAR = 0x2A19,
|
switches |
0:0e018d759a2a
|
39
|
UUID_BLOOD_PRESSURE_FEATURE_CHAR = 0x2A49,
|
switches |
0:0e018d759a2a
|
40
|
UUID_BLOOD_PRESSURE_MEASUREMENT_CHAR = 0x2A35,
|
switches |
0:0e018d759a2a
|
41
|
UUID_BODY_SENSOR_LOCATION_CHAR = 0x2A38,
|
switches |
0:0e018d759a2a
|
42
|
UUID_BOOT_KEYBOARD_INPUT_REPORT_CHAR = 0x2A22,
|
switches |
0:0e018d759a2a
|
43
|
UUID_BOOT_KEYBOARD_OUTPUT_REPORT_CHAR = 0x2A32,
|
switches |
0:0e018d759a2a
|
44
|
UUID_BOOT_MOUSE_INPUT_REPORT_CHAR = 0x2A33,
|
switches |
0:0e018d759a2a
|
45
|
UUID_CURRENT_TIME_CHAR = 0x2A2B,
|
switches |
0:0e018d759a2a
|
46
|
UUID_DATE_TIME_CHAR = 0x2A08,
|
switches |
0:0e018d759a2a
|
47
|
UUID_DAY_DATE_TIME_CHAR = 0x2A0A,
|
switches |
0:0e018d759a2a
|
48
|
UUID_DAY_OF_WEEK_CHAR = 0x2A09,
|
switches |
0:0e018d759a2a
|
49
|
UUID_DST_OFFSET_CHAR = 0x2A0D,
|
switches |
0:0e018d759a2a
|
50
|
UUID_EXACT_TIME_256_CHAR = 0x2A0C,
|
switches |
0:0e018d759a2a
|
51
|
UUID_FIRMWARE_REVISION_STRING_CHAR = 0x2A26,
|
switches |
0:0e018d759a2a
|
52
|
UUID_GLUCOSE_FEATURE_CHAR = 0x2A51,
|
switches |
0:0e018d759a2a
|
53
|
UUID_GLUCOSE_MEASUREMENT_CHAR = 0x2A18,
|
switches |
0:0e018d759a2a
|
54
|
UUID_GLUCOSE_MEASUREMENT_CONTEXT_CHAR = 0x2A34,
|
switches |
0:0e018d759a2a
|
55
|
UUID_HARDWARE_REVISION_STRING_CHAR = 0x2A27,
|
switches |
0:0e018d759a2a
|
56
|
UUID_HEART_RATE_CONTROL_POINT_CHAR = 0x2A39,
|
switches |
0:0e018d759a2a
|
57
|
UUID_HEART_RATE_MEASUREMENT_CHAR = 0x2A37,
|
switches |
0:0e018d759a2a
|
58
|
UUID_HID_CONTROL_POINT_CHAR = 0x2A4C,
|
switches |
0:0e018d759a2a
|
59
|
UUID_HID_INFORMATION_CHAR = 0x2A4A,
|
switches |
0:0e018d759a2a
|
60
|
UUID_HUMIDITY_CHAR = 0x2A6F,
|
switches |
0:0e018d759a2a
|
61
|
UUID_IEEE_REGULATORY_CERTIFICATION_DATA_LIST_CHAR = 0x2A2A,
|
switches |
0:0e018d759a2a
|
62
|
UUID_INTERMEDIATE_CUFF_PRESSURE_CHAR = 0x2A36,
|
switches |
0:0e018d759a2a
|
63
|
UUID_INTERMEDIATE_TEMPERATURE_CHAR = 0x2A1E,
|
switches |
0:0e018d759a2a
|
64
|
UUID_LOCAL_TIME_INFORMATION_CHAR = 0x2A0F,
|
switches |
0:0e018d759a2a
|
65
|
UUID_MANUFACTURER_NAME_STRING_CHAR = 0x2A29,
|
switches |
0:0e018d759a2a
|
66
|
UUID_MEASUREMENT_INTERVAL_CHAR = 0x2A21,
|
switches |
0:0e018d759a2a
|
67
|
UUID_MODEL_NUMBER_STRING_CHAR = 0x2A24,
|
switches |
0:0e018d759a2a
|
68
|
UUID_UNREAD_ALERT_CHAR = 0x2A45,
|
switches |
0:0e018d759a2a
|
69
|
UUID_NEW_ALERT_CHAR = 0x2A46,
|
switches |
0:0e018d759a2a
|
70
|
UUID_PNP_ID_CHAR = 0x2A50,
|
switches |
0:0e018d759a2a
|
71
|
UUID_PRESSURE_CHAR = 0x2A6D,
|
switches |
0:0e018d759a2a
|
72
|
UUID_PROTOCOL_MODE_CHAR = 0x2A4E,
|
switches |
0:0e018d759a2a
|
73
|
UUID_RECORD_ACCESS_CONTROL_POINT_CHAR = 0x2A52,
|
switches |
0:0e018d759a2a
|
74
|
UUID_REFERENCE_TIME_INFORMATION_CHAR = 0x2A14,
|
switches |
0:0e018d759a2a
|
75
|
UUID_REPORT_CHAR = 0x2A4D,
|
switches |
0:0e018d759a2a
|
76
|
UUID_REPORT_MAP_CHAR = 0x2A4B,
|
switches |
0:0e018d759a2a
|
77
|
UUID_RINGER_CONTROL_POINT_CHAR = 0x2A40,
|
switches |
0:0e018d759a2a
|
78
|
UUID_RINGER_SETTING_CHAR = 0x2A41,
|
switches |
0:0e018d759a2a
|
79
|
UUID_SCAN_INTERVAL_WINDOW_CHAR = 0x2A4F,
|
switches |
0:0e018d759a2a
|
80
|
UUID_SCAN_REFRESH_CHAR = 0x2A31,
|
switches |
0:0e018d759a2a
|
81
|
UUID_SERIAL_NUMBER_STRING_CHAR = 0x2A25,
|
switches |
0:0e018d759a2a
|
82
|
UUID_SOFTWARE_REVISION_STRING_CHAR = 0x2A28,
|
switches |
0:0e018d759a2a
|
83
|
UUID_SUPPORTED_NEW_ALERT_CATEGORY_CHAR = 0x2A47,
|
switches |
0:0e018d759a2a
|
84
|
UUID_SUPPORTED_UNREAD_ALERT_CATEGORY_CHAR = 0x2A48,
|
switches |
0:0e018d759a2a
|
85
|
UUID_SYSTEM_ID_CHAR = 0x2A23,
|
switches |
0:0e018d759a2a
|
86
|
UUID_TEMPERATURE_CHAR = 0x2A6E,
|
switches |
0:0e018d759a2a
|
87
|
UUID_TEMPERATURE_MEASUREMENT_CHAR = 0x2A1C,
|
switches |
0:0e018d759a2a
|
88
|
UUID_TEMPERATURE_TYPE_CHAR = 0x2A1D,
|
switches |
0:0e018d759a2a
|
89
|
UUID_TIME_ACCURACY_CHAR = 0x2A12,
|
switches |
0:0e018d759a2a
|
90
|
UUID_TIME_SOURCE_CHAR = 0x2A13,
|
switches |
0:0e018d759a2a
|
91
|
UUID_TIME_UPDATE_CONTROL_POINT_CHAR = 0x2A16,
|
switches |
0:0e018d759a2a
|
92
|
UUID_TIME_UPDATE_STATE_CHAR = 0x2A17,
|
switches |
0:0e018d759a2a
|
93
|
UUID_TIME_WITH_DST_CHAR = 0x2A11,
|
switches |
0:0e018d759a2a
|
94
|
UUID_TIME_ZONE_CHAR = 0x2A0E,
|
switches |
0:0e018d759a2a
|
95
|
UUID_TX_POWER_LEVEL_CHAR = 0x2A07,
|
switches |
0:0e018d759a2a
|
96
|
UUID_CSC_FEATURE_CHAR = 0x2A5C,
|
switches |
0:0e018d759a2a
|
97
|
UUID_CSC_MEASUREMENT_CHAR = 0x2A5B,
|
switches |
0:0e018d759a2a
|
98
|
UUID_RSC_FEATURE_CHAR = 0x2A54,
|
switches |
0:0e018d759a2a
|
99
|
UUID_RSC_MEASUREMENT_CHAR = 0x2A53
|
switches |
0:0e018d759a2a
|
100
|
};
|
switches |
0:0e018d759a2a
|
101
|
|
switches |
0:0e018d759a2a
|
102
|
/**
|
switches |
0:0e018d759a2a
|
103
|
* @brief Standard GATT characteristic presentation format unit types.
|
switches |
0:0e018d759a2a
|
104
|
* These unit types are used to describe what the raw numeric
|
switches |
0:0e018d759a2a
|
105
|
* data in a characteristic actually represents.
|
switches |
0:0e018d759a2a
|
106
|
*
|
switches |
0:0e018d759a2a
|
107
|
* @note See https://developer.bluetooth.org/gatt/units/Pages/default.aspx
|
switches |
0:0e018d759a2a
|
108
|
*/
|
switches |
0:0e018d759a2a
|
109
|
enum {
|
switches |
0:0e018d759a2a
|
110
|
BLE_GATT_UNIT_NONE = 0x2700, /**< No specified unit type. */
|
switches |
0:0e018d759a2a
|
111
|
BLE_GATT_UNIT_LENGTH_METRE = 0x2701, /**< Length, metre. */
|
switches |
0:0e018d759a2a
|
112
|
BLE_GATT_UNIT_MASS_KILOGRAM = 0x2702, /**< Mass, kilogram. */
|
switches |
0:0e018d759a2a
|
113
|
BLE_GATT_UNIT_TIME_SECOND = 0x2703, /**< Time, second. */
|
switches |
0:0e018d759a2a
|
114
|
BLE_GATT_UNIT_ELECTRIC_CURRENT_AMPERE = 0x2704, /**< Electric current, ampere. */
|
switches |
0:0e018d759a2a
|
115
|
BLE_GATT_UNIT_THERMODYNAMIC_TEMPERATURE_KELVIN = 0x2705, /**< Thermodynamic temperature, kelvin. */
|
switches |
0:0e018d759a2a
|
116
|
BLE_GATT_UNIT_AMOUNT_OF_SUBSTANCE_MOLE = 0x2706, /**< Amount of substance, mole. */
|
switches |
0:0e018d759a2a
|
117
|
BLE_GATT_UNIT_LUMINOUS_INTENSITY_CANDELA = 0x2707, /**< Luminous intensity, candela. */
|
switches |
0:0e018d759a2a
|
118
|
BLE_GATT_UNIT_AREA_SQUARE_METRES = 0x2710, /**< Area, square metres. */
|
switches |
0:0e018d759a2a
|
119
|
BLE_GATT_UNIT_VOLUME_CUBIC_METRES = 0x2711, /**< Volume, cubic metres. */
|
switches |
0:0e018d759a2a
|
120
|
BLE_GATT_UNIT_VELOCITY_METRES_PER_SECOND = 0x2712, /**< Velocity, metres per second. */
|
switches |
0:0e018d759a2a
|
121
|
BLE_GATT_UNIT_ACCELERATION_METRES_PER_SECOND_SQUARED = 0x2713, /**< Acceleration, metres per second squared. */
|
switches |
0:0e018d759a2a
|
122
|
BLE_GATT_UNIT_WAVENUMBER_RECIPROCAL_METRE = 0x2714, /**< Wave number reciprocal, metre. */
|
switches |
0:0e018d759a2a
|
123
|
BLE_GATT_UNIT_DENSITY_KILOGRAM_PER_CUBIC_METRE = 0x2715, /**< Density, kilogram per cubic metre. */
|
switches |
0:0e018d759a2a
|
124
|
BLE_GATT_UNIT_SURFACE_DENSITY_KILOGRAM_PER_SQUARE_METRE = 0x2716, /**< */
|
switches |
0:0e018d759a2a
|
125
|
BLE_GATT_UNIT_SPECIFIC_VOLUME_CUBIC_METRE_PER_KILOGRAM = 0x2717, /**< */
|
switches |
0:0e018d759a2a
|
126
|
BLE_GATT_UNIT_CURRENT_DENSITY_AMPERE_PER_SQUARE_METRE = 0x2718, /**< */
|
switches |
0:0e018d759a2a
|
127
|
BLE_GATT_UNIT_MAGNETIC_FIELD_STRENGTH_AMPERE_PER_METRE = 0x2719, /**< Magnetic field strength, ampere per metre. */
|
switches |
0:0e018d759a2a
|
128
|
BLE_GATT_UNIT_AMOUNT_CONCENTRATION_MOLE_PER_CUBIC_METRE = 0x271A, /**< */
|
switches |
0:0e018d759a2a
|
129
|
BLE_GATT_UNIT_MASS_CONCENTRATION_KILOGRAM_PER_CUBIC_METRE = 0x271B, /**< */
|
switches |
0:0e018d759a2a
|
130
|
BLE_GATT_UNIT_LUMINANCE_CANDELA_PER_SQUARE_METRE = 0x271C, /**< */
|
switches |
0:0e018d759a2a
|
131
|
BLE_GATT_UNIT_REFRACTIVE_INDEX = 0x271D, /**< */
|
switches |
0:0e018d759a2a
|
132
|
BLE_GATT_UNIT_RELATIVE_PERMEABILITY = 0x271E, /**< */
|
switches |
0:0e018d759a2a
|
133
|
BLE_GATT_UNIT_PLANE_ANGLE_RADIAN = 0x2720, /**< */
|
switches |
0:0e018d759a2a
|
134
|
BLE_GATT_UNIT_SOLID_ANGLE_STERADIAN = 0x2721, /**< */
|
switches |
0:0e018d759a2a
|
135
|
BLE_GATT_UNIT_FREQUENCY_HERTZ = 0x2722, /**< Frequency, hertz. */
|
switches |
0:0e018d759a2a
|
136
|
BLE_GATT_UNIT_FORCE_NEWTON = 0x2723, /**< Force, newton. */
|
switches |
0:0e018d759a2a
|
137
|
BLE_GATT_UNIT_PRESSURE_PASCAL = 0x2724, /**< Pressure, pascal. */
|
switches |
0:0e018d759a2a
|
138
|
BLE_GATT_UNIT_ENERGY_JOULE = 0x2725, /**< Energy, joule. */
|
switches |
0:0e018d759a2a
|
139
|
BLE_GATT_UNIT_POWER_WATT = 0x2726, /**< Power, watt. */
|
switches |
0:0e018d759a2a
|
140
|
BLE_GATT_UNIT_ELECTRIC_CHARGE_COULOMB = 0x2727, /**< Electrical charge, coulomb. */
|
switches |
0:0e018d759a2a
|
141
|
BLE_GATT_UNIT_ELECTRIC_POTENTIAL_DIFFERENCE_VOLT = 0x2728, /**< Electrical potential difference, voltage. */
|
switches |
0:0e018d759a2a
|
142
|
BLE_GATT_UNIT_CAPACITANCE_FARAD = 0x2729, /**< */
|
switches |
0:0e018d759a2a
|
143
|
BLE_GATT_UNIT_ELECTRIC_RESISTANCE_OHM = 0x272A, /**< */
|
switches |
0:0e018d759a2a
|
144
|
BLE_GATT_UNIT_ELECTRIC_CONDUCTANCE_SIEMENS = 0x272B, /**< */
|
switches |
0:0e018d759a2a
|
145
|
BLE_GATT_UNIT_MAGNETIC_FLEX_WEBER = 0x272C, /**< */
|
switches |
0:0e018d759a2a
|
146
|
BLE_GATT_UNIT_MAGNETIC_FLEX_DENSITY_TESLA = 0x272D, /**< */
|
switches |
0:0e018d759a2a
|
147
|
BLE_GATT_UNIT_INDUCTANCE_HENRY = 0x272E, /**< */
|
switches |
0:0e018d759a2a
|
148
|
BLE_GATT_UNIT_THERMODYNAMIC_TEMPERATURE_DEGREE_CELSIUS = 0x272F, /**< */
|
switches |
0:0e018d759a2a
|
149
|
BLE_GATT_UNIT_LUMINOUS_FLUX_LUMEN = 0x2730, /**< */
|
switches |
0:0e018d759a2a
|
150
|
BLE_GATT_UNIT_ILLUMINANCE_LUX = 0x2731, /**< */
|
switches |
0:0e018d759a2a
|
151
|
BLE_GATT_UNIT_ACTIVITY_REFERRED_TO_A_RADIONUCLIDE_BECQUEREL = 0x2732, /**< */
|
switches |
0:0e018d759a2a
|
152
|
BLE_GATT_UNIT_ABSORBED_DOSE_GRAY = 0x2733, /**< */
|
switches |
0:0e018d759a2a
|
153
|
BLE_GATT_UNIT_DOSE_EQUIVALENT_SIEVERT = 0x2734, /**< */
|
switches |
0:0e018d759a2a
|
154
|
BLE_GATT_UNIT_CATALYTIC_ACTIVITY_KATAL = 0x2735, /**< */
|
switches |
0:0e018d759a2a
|
155
|
BLE_GATT_UNIT_DYNAMIC_VISCOSITY_PASCAL_SECOND = 0x2740, /**< */
|
switches |
0:0e018d759a2a
|
156
|
BLE_GATT_UNIT_MOMENT_OF_FORCE_NEWTON_METRE = 0x2741, /**< */
|
switches |
0:0e018d759a2a
|
157
|
BLE_GATT_UNIT_SURFACE_TENSION_NEWTON_PER_METRE = 0x2742, /**< */
|
switches |
0:0e018d759a2a
|
158
|
BLE_GATT_UNIT_ANGULAR_VELOCITY_RADIAN_PER_SECOND = 0x2743, /**< */
|
switches |
0:0e018d759a2a
|
159
|
BLE_GATT_UNIT_ANGULAR_ACCELERATION_RADIAN_PER_SECOND_SQUARED = 0x2744, /**< */
|
switches |
0:0e018d759a2a
|
160
|
BLE_GATT_UNIT_HEAT_FLUX_DENSITY_WATT_PER_SQUARE_METRE = 0x2745, /**< */
|
switches |
0:0e018d759a2a
|
161
|
BLE_GATT_UNIT_HEAT_CAPACITY_JOULE_PER_KELVIN = 0x2746, /**< */
|
switches |
0:0e018d759a2a
|
162
|
BLE_GATT_UNIT_SPECIFIC_HEAT_CAPACITY_JOULE_PER_KILOGRAM_KELVIN = 0x2747, /**< */
|
switches |
0:0e018d759a2a
|
163
|
BLE_GATT_UNIT_SPECIFIC_ENERGY_JOULE_PER_KILOGRAM = 0x2748, /**< */
|
switches |
0:0e018d759a2a
|
164
|
BLE_GATT_UNIT_THERMAL_CONDUCTIVITY_WATT_PER_METRE_KELVIN = 0x2749, /**< */
|
switches |
0:0e018d759a2a
|
165
|
BLE_GATT_UNIT_ENERGY_DENSITY_JOULE_PER_CUBIC_METRE = 0x274A, /**< */
|
switches |
0:0e018d759a2a
|
166
|
BLE_GATT_UNIT_ELECTRIC_FIELD_STRENGTH_VOLT_PER_METRE = 0x274B, /**< */
|
switches |
0:0e018d759a2a
|
167
|
BLE_GATT_UNIT_ELECTRIC_CHARGE_DENSITY_COULOMB_PER_CUBIC_METRE = 0x274C, /**< */
|
switches |
0:0e018d759a2a
|
168
|
BLE_GATT_UNIT_SURFACE_CHARGE_DENSITY_COULOMB_PER_SQUARE_METRE = 0x274D, /**< */
|
switches |
0:0e018d759a2a
|
169
|
BLE_GATT_UNIT_ELECTRIC_FLUX_DENSITY_COULOMB_PER_SQUARE_METRE = 0x274E, /**< */
|
switches |
0:0e018d759a2a
|
170
|
BLE_GATT_UNIT_PERMITTIVITY_FARAD_PER_METRE = 0x274F, /**< */
|
switches |
0:0e018d759a2a
|
171
|
BLE_GATT_UNIT_PERMEABILITY_HENRY_PER_METRE = 0x2750, /**< */
|
switches |
0:0e018d759a2a
|
172
|
BLE_GATT_UNIT_MOLAR_ENERGY_JOULE_PER_MOLE = 0x2751, /**< */
|
switches |
0:0e018d759a2a
|
173
|
BLE_GATT_UNIT_MOLAR_ENTROPY_JOULE_PER_MOLE_KELVIN = 0x2752, /**< */
|
switches |
0:0e018d759a2a
|
174
|
BLE_GATT_UNIT_EXPOSURE_COULOMB_PER_KILOGRAM = 0x2753, /**< */
|
switches |
0:0e018d759a2a
|
175
|
BLE_GATT_UNIT_ABSORBED_DOSE_RATE_GRAY_PER_SECOND = 0x2754, /**< */
|
switches |
0:0e018d759a2a
|
176
|
BLE_GATT_UNIT_RADIANT_INTENSITY_WATT_PER_STERADIAN = 0x2755, /**< */
|
switches |
0:0e018d759a2a
|
177
|
BLE_GATT_UNIT_RADIANCE_WATT_PER_SQUARE_METRE_STERADIAN = 0x2756, /**< */
|
switches |
0:0e018d759a2a
|
178
|
BLE_GATT_UNIT_CATALYTIC_ACTIVITY_CONCENTRATION_KATAL_PER_CUBIC_METRE = 0x2757, /**< */
|
switches |
0:0e018d759a2a
|
179
|
BLE_GATT_UNIT_TIME_MINUTE = 0x2760, /**< Time, minute. */
|
switches |
0:0e018d759a2a
|
180
|
BLE_GATT_UNIT_TIME_HOUR = 0x2761, /**< Time, hour. */
|
switches |
0:0e018d759a2a
|
181
|
BLE_GATT_UNIT_TIME_DAY = 0x2762, /**< Time, day. */
|
switches |
0:0e018d759a2a
|
182
|
BLE_GATT_UNIT_PLANE_ANGLE_DEGREE = 0x2763, /**< */
|
switches |
0:0e018d759a2a
|
183
|
BLE_GATT_UNIT_PLANE_ANGLE_MINUTE = 0x2764, /**< */
|
switches |
0:0e018d759a2a
|
184
|
BLE_GATT_UNIT_PLANE_ANGLE_SECOND = 0x2765, /**< */
|
switches |
0:0e018d759a2a
|
185
|
BLE_GATT_UNIT_AREA_HECTARE = 0x2766, /**< */
|
switches |
0:0e018d759a2a
|
186
|
BLE_GATT_UNIT_VOLUME_LITRE = 0x2767, /**< */
|
switches |
0:0e018d759a2a
|
187
|
BLE_GATT_UNIT_MASS_TONNE = 0x2768, /**< */
|
switches |
0:0e018d759a2a
|
188
|
BLE_GATT_UNIT_PRESSURE_BAR = 0x2780, /**< Pressure, bar. */
|
switches |
0:0e018d759a2a
|
189
|
BLE_GATT_UNIT_PRESSURE_MILLIMETRE_OF_MERCURY = 0x2781, /**< Pressure, millimetre of mercury. */
|
switches |
0:0e018d759a2a
|
190
|
BLE_GATT_UNIT_LENGTH_ANGSTROM = 0x2782, /**< */
|
switches |
0:0e018d759a2a
|
191
|
BLE_GATT_UNIT_LENGTH_NAUTICAL_MILE = 0x2783, /**< */
|
switches |
0:0e018d759a2a
|
192
|
BLE_GATT_UNIT_AREA_BARN = 0x2784, /**< */
|
switches |
0:0e018d759a2a
|
193
|
BLE_GATT_UNIT_VELOCITY_KNOT = 0x2785, /**< */
|
switches |
0:0e018d759a2a
|
194
|
BLE_GATT_UNIT_LOGARITHMIC_RADIO_QUANTITY_NEPER = 0x2786, /**< */
|
switches |
0:0e018d759a2a
|
195
|
BLE_GATT_UNIT_LOGARITHMIC_RADIO_QUANTITY_BEL = 0x2787, /**< */
|
switches |
0:0e018d759a2a
|
196
|
BLE_GATT_UNIT_LENGTH_YARD = 0x27A0, /**< Length, yard. */
|
switches |
0:0e018d759a2a
|
197
|
BLE_GATT_UNIT_LENGTH_PARSEC = 0x27A1, /**< Length, parsec. */
|
switches |
0:0e018d759a2a
|
198
|
BLE_GATT_UNIT_LENGTH_INCH = 0x27A2, /**< Length, inch. */
|
switches |
0:0e018d759a2a
|
199
|
BLE_GATT_UNIT_LENGTH_FOOT = 0x27A3, /**< Length, foot. */
|
switches |
0:0e018d759a2a
|
200
|
BLE_GATT_UNIT_LENGTH_MILE = 0x27A4, /**< Length, mile. */
|
switches |
0:0e018d759a2a
|
201
|
BLE_GATT_UNIT_PRESSURE_POUND_FORCE_PER_SQUARE_INCH = 0x27A5, /**< */
|
switches |
0:0e018d759a2a
|
202
|
BLE_GATT_UNIT_VELOCITY_KILOMETRE_PER_HOUR = 0x27A6, /**< Velocity, kilometre per hour. */
|
switches |
0:0e018d759a2a
|
203
|
BLE_GATT_UNIT_VELOCITY_MILE_PER_HOUR = 0x27A7, /**< Velocity, mile per hour. */
|
switches |
0:0e018d759a2a
|
204
|
BLE_GATT_UNIT_ANGULAR_VELOCITY_REVOLUTION_PER_MINUTE = 0x27A8, /**< Angular Velocity, revolution per minute. */
|
switches |
0:0e018d759a2a
|
205
|
BLE_GATT_UNIT_ENERGY_GRAM_CALORIE = 0x27A9, /**< Energy, gram calorie. */
|
switches |
0:0e018d759a2a
|
206
|
BLE_GATT_UNIT_ENERGY_KILOGRAM_CALORIE = 0x27AA, /**< Energy, kilogram calorie. */
|
switches |
0:0e018d759a2a
|
207
|
BLE_GATT_UNIT_ENERGY_KILOWATT_HOUR = 0x27AB, /**< Energy, killowatt hour. */
|
switches |
0:0e018d759a2a
|
208
|
BLE_GATT_UNIT_THERMODYNAMIC_TEMPERATURE_DEGREE_FAHRENHEIT = 0x27AC, /**< */
|
switches |
0:0e018d759a2a
|
209
|
BLE_GATT_UNIT_PERCENTAGE = 0x27AD, /**< Percentage. */
|
switches |
0:0e018d759a2a
|
210
|
BLE_GATT_UNIT_PER_MILLE = 0x27AE, /**< */
|
switches |
0:0e018d759a2a
|
211
|
BLE_GATT_UNIT_PERIOD_BEATS_PER_MINUTE = 0x27AF, /**< */
|
switches |
0:0e018d759a2a
|
212
|
BLE_GATT_UNIT_ELECTRIC_CHARGE_AMPERE_HOURS = 0x27B0, /**< */
|
switches |
0:0e018d759a2a
|
213
|
BLE_GATT_UNIT_MASS_DENSITY_MILLIGRAM_PER_DECILITRE = 0x27B1, /**< */
|
switches |
0:0e018d759a2a
|
214
|
BLE_GATT_UNIT_MASS_DENSITY_MILLIMOLE_PER_LITRE = 0x27B2, /**< */
|
switches |
0:0e018d759a2a
|
215
|
BLE_GATT_UNIT_TIME_YEAR = 0x27B3, /**< Time, year. */
|
switches |
0:0e018d759a2a
|
216
|
BLE_GATT_UNIT_TIME_MONTH = 0x27B4, /**< Time, month. */
|
switches |
0:0e018d759a2a
|
217
|
BLE_GATT_UNIT_CONCENTRATION_COUNT_PER_CUBIC_METRE = 0x27B5, /**< */
|
switches |
0:0e018d759a2a
|
218
|
BLE_GATT_UNIT_IRRADIANCE_WATT_PER_SQUARE_METRE = 0x27B6 /**< */
|
switches |
0:0e018d759a2a
|
219
|
};
|
switches |
0:0e018d759a2a
|
220
|
|
switches |
0:0e018d759a2a
|
221
|
/**
|
switches |
0:0e018d759a2a
|
222
|
* @brief Standard GATT number types.
|
switches |
0:0e018d759a2a
|
223
|
*
|
switches |
0:0e018d759a2a
|
224
|
* @note See Bluetooth Specification 4.0 (Vol. 3), Part G, Section 3.3.3.5.2.
|
switches |
0:0e018d759a2a
|
225
|
*
|
switches |
0:0e018d759a2a
|
226
|
* @note See http://developer.bluetooth.org/gatt/descriptors/Pages/DescriptorViewer.aspx?u=org.bluetooth.descriptor.gatt.characteristic_presentation_format.xml
|
switches |
0:0e018d759a2a
|
227
|
*/
|
switches |
0:0e018d759a2a
|
228
|
enum {
|
switches |
0:0e018d759a2a
|
229
|
BLE_GATT_FORMAT_RFU = 0x00, /**< Reserved for future use. */
|
switches |
0:0e018d759a2a
|
230
|
BLE_GATT_FORMAT_BOOLEAN = 0x01, /**< Boolean. */
|
switches |
0:0e018d759a2a
|
231
|
BLE_GATT_FORMAT_2BIT = 0x02, /**< Unsigned 2-bit integer. */
|
switches |
0:0e018d759a2a
|
232
|
BLE_GATT_FORMAT_NIBBLE = 0x03, /**< Unsigned 4-bit integer. */
|
switches |
0:0e018d759a2a
|
233
|
BLE_GATT_FORMAT_UINT8 = 0x04, /**< Unsigned 8-bit integer. */
|
switches |
0:0e018d759a2a
|
234
|
BLE_GATT_FORMAT_UINT12 = 0x05, /**< Unsigned 12-bit integer. */
|
switches |
0:0e018d759a2a
|
235
|
BLE_GATT_FORMAT_UINT16 = 0x06, /**< Unsigned 16-bit integer. */
|
switches |
0:0e018d759a2a
|
236
|
BLE_GATT_FORMAT_UINT24 = 0x07, /**< Unsigned 24-bit integer. */
|
switches |
0:0e018d759a2a
|
237
|
BLE_GATT_FORMAT_UINT32 = 0x08, /**< Unsigned 32-bit integer. */
|
switches |
0:0e018d759a2a
|
238
|
BLE_GATT_FORMAT_UINT48 = 0x09, /**< Unsigned 48-bit integer. */
|
switches |
0:0e018d759a2a
|
239
|
BLE_GATT_FORMAT_UINT64 = 0x0A, /**< Unsigned 64-bit integer. */
|
switches |
0:0e018d759a2a
|
240
|
BLE_GATT_FORMAT_UINT128 = 0x0B, /**< Unsigned 128-bit integer. */
|
switches |
0:0e018d759a2a
|
241
|
BLE_GATT_FORMAT_SINT8 = 0x0C, /**< Signed 2-bit integer. */
|
switches |
0:0e018d759a2a
|
242
|
BLE_GATT_FORMAT_SINT12 = 0x0D, /**< Signed 12-bit integer. */
|
switches |
0:0e018d759a2a
|
243
|
BLE_GATT_FORMAT_SINT16 = 0x0E, /**< Signed 16-bit integer. */
|
switches |
0:0e018d759a2a
|
244
|
BLE_GATT_FORMAT_SINT24 = 0x0F, /**< Signed 24-bit integer. */
|
switches |
0:0e018d759a2a
|
245
|
BLE_GATT_FORMAT_SINT32 = 0x10, /**< Signed 32-bit integer. */
|
switches |
0:0e018d759a2a
|
246
|
BLE_GATT_FORMAT_SINT48 = 0x11, /**< Signed 48-bit integer. */
|
switches |
0:0e018d759a2a
|
247
|
BLE_GATT_FORMAT_SINT64 = 0x12, /**< Signed 64-bit integer. */
|
switches |
0:0e018d759a2a
|
248
|
BLE_GATT_FORMAT_SINT128 = 0x13, /**< Signed 128-bit integer. */
|
switches |
0:0e018d759a2a
|
249
|
BLE_GATT_FORMAT_FLOAT32 = 0x14, /**< IEEE-754 32-bit floating point. */
|
switches |
0:0e018d759a2a
|
250
|
BLE_GATT_FORMAT_FLOAT64 = 0x15, /**< IEEE-754 64-bit floating point. */
|
switches |
0:0e018d759a2a
|
251
|
BLE_GATT_FORMAT_SFLOAT = 0x16, /**< IEEE-11073 16-bit SFLOAT. */
|
switches |
0:0e018d759a2a
|
252
|
BLE_GATT_FORMAT_FLOAT = 0x17, /**< IEEE-11073 32-bit FLOAT. */
|
switches |
0:0e018d759a2a
|
253
|
BLE_GATT_FORMAT_DUINT16 = 0x18, /**< IEEE-20601 format. */
|
switches |
0:0e018d759a2a
|
254
|
BLE_GATT_FORMAT_UTF8S = 0x19, /**< UTF-8 string. */
|
switches |
0:0e018d759a2a
|
255
|
BLE_GATT_FORMAT_UTF16S = 0x1A, /**< UTF-16 string. */
|
switches |
0:0e018d759a2a
|
256
|
BLE_GATT_FORMAT_STRUCT = 0x1B /**< Opaque Structure. */
|
switches |
0:0e018d759a2a
|
257
|
};
|
switches |
0:0e018d759a2a
|
258
|
|
switches |
0:0e018d759a2a
|
259
|
/*!
|
switches |
0:0e018d759a2a
|
260
|
* @brief Standard GATT characteristic properties.
|
switches |
0:0e018d759a2a
|
261
|
*
|
switches |
0:0e018d759a2a
|
262
|
* @note See Bluetooth Specification 4.0 (Vol. 3), Part G, Section 3.3.1.1
|
switches |
0:0e018d759a2a
|
263
|
* and Section 3.3.3.1 for Extended Properties.
|
switches |
0:0e018d759a2a
|
264
|
*/
|
switches |
0:0e018d759a2a
|
265
|
enum Properties_t {
|
switches |
0:0e018d759a2a
|
266
|
BLE_GATT_CHAR_PROPERTIES_NONE = 0x00,
|
switches |
0:0e018d759a2a
|
267
|
BLE_GATT_CHAR_PROPERTIES_BROADCAST = 0x01, /**< Permits broadcasts of the characteristic value using the Server Characteristic Configuration descriptor. */
|
switches |
0:0e018d759a2a
|
268
|
BLE_GATT_CHAR_PROPERTIES_READ = 0x02, /**< Permits reads of the characteristic value. */
|
switches |
0:0e018d759a2a
|
269
|
BLE_GATT_CHAR_PROPERTIES_WRITE_WITHOUT_RESPONSE = 0x04, /**< Permits writes of the characteristic value without response. */
|
switches |
0:0e018d759a2a
|
270
|
BLE_GATT_CHAR_PROPERTIES_WRITE = 0x08, /**< Permits writes of the characteristic value with response. */
|
switches |
0:0e018d759a2a
|
271
|
BLE_GATT_CHAR_PROPERTIES_NOTIFY = 0x10, /**< Permits notifications of a characteristic value without acknowledgment. */
|
switches |
0:0e018d759a2a
|
272
|
BLE_GATT_CHAR_PROPERTIES_INDICATE = 0x20, /**< Permits indications of a characteristic value with acknowledgment. */
|
switches |
0:0e018d759a2a
|
273
|
BLE_GATT_CHAR_PROPERTIES_AUTHENTICATED_SIGNED_WRITES = 0x40, /**< Permits signed writes to the characteristic value. */
|
switches |
0:0e018d759a2a
|
274
|
BLE_GATT_CHAR_PROPERTIES_EXTENDED_PROPERTIES = 0x80 /**< Additional characteristic properties are defined in the Characteristic Extended Properties descriptor */
|
switches |
0:0e018d759a2a
|
275
|
};
|
switches |
0:0e018d759a2a
|
276
|
|
switches |
0:0e018d759a2a
|
277
|
/**
|
switches |
0:0e018d759a2a
|
278
|
* @brief GATT presentation format wrapper.
|
switches |
0:0e018d759a2a
|
279
|
*
|
switches |
0:0e018d759a2a
|
280
|
* @note See Bluetooth Specification 4.0 (Vol. 3), Part G, Section 3.3.3.5.
|
switches |
0:0e018d759a2a
|
281
|
*
|
switches |
0:0e018d759a2a
|
282
|
* @note See https://developer.bluetooth.org/gatt/descriptors/Pages/DescriptorViewer.aspx?u=org.bluetooth.descriptor.gatt.characteristic_presentation_format.xml
|
switches |
0:0e018d759a2a
|
283
|
*/
|
switches |
0:0e018d759a2a
|
284
|
struct PresentationFormat_t {
|
switches |
0:0e018d759a2a
|
285
|
uint8_t gatt_format; /**< Format of the value. */
|
switches |
0:0e018d759a2a
|
286
|
int8_t exponent; /**< Exponent for integer data types. Example: if Exponent = -3 and the char value is 3892, the actual value is 3.892 */
|
switches |
0:0e018d759a2a
|
287
|
uint16_t gatt_unit; /**< UUID from Bluetooth Assigned Numbers. */
|
switches |
0:0e018d759a2a
|
288
|
uint8_t gatt_namespace; /**< Namespace from Bluetooth Assigned Numbers, normally '1'. */
|
switches |
0:0e018d759a2a
|
289
|
uint16_t gatt_nsdesc; /**< Namespace description from Bluetooth Assigned Numbers, normally '0'. */
|
switches |
0:0e018d759a2a
|
290
|
};
|
switches |
0:0e018d759a2a
|
291
|
|
switches |
0:0e018d759a2a
|
292
|
/**
|
switches |
0:0e018d759a2a
|
293
|
* @brief Creates a new GattCharacteristic using the specified 16-bit
|
switches |
0:0e018d759a2a
|
294
|
* UUID, value length, and properties.
|
switches |
0:0e018d759a2a
|
295
|
*
|
switches |
0:0e018d759a2a
|
296
|
* @param[in] uuid
|
switches |
0:0e018d759a2a
|
297
|
* The UUID to use for this characteristic.
|
switches |
0:0e018d759a2a
|
298
|
* @param[in] valuePtr
|
switches |
0:0e018d759a2a
|
299
|
* The memory holding the initial value. The value is copied
|
switches |
0:0e018d759a2a
|
300
|
* into the stack when the enclosing service is added, and
|
switches |
0:0e018d759a2a
|
301
|
* is thereafter maintained internally by the stack.
|
switches |
0:0e018d759a2a
|
302
|
* @param[in] len
|
switches |
0:0e018d759a2a
|
303
|
* The length in bytes of this characteristic's value.
|
switches |
0:0e018d759a2a
|
304
|
* @param[in] maxLen
|
switches |
0:0e018d759a2a
|
305
|
* The max length in bytes of this characteristic's value.
|
switches |
0:0e018d759a2a
|
306
|
* @param[in] props
|
switches |
0:0e018d759a2a
|
307
|
* The 8-bit field containing the characteristic's properties.
|
switches |
0:0e018d759a2a
|
308
|
* @param[in] descriptors
|
switches |
0:0e018d759a2a
|
309
|
* A pointer to an array of descriptors to be included within
|
switches |
0:0e018d759a2a
|
310
|
* this characteristic. The memory for the descriptor array is
|
switches |
0:0e018d759a2a
|
311
|
* owned by the caller, and should remain valid at least until
|
switches |
0:0e018d759a2a
|
312
|
* the enclosing service is added to the GATT table.
|
switches |
0:0e018d759a2a
|
313
|
* @param[in] numDescriptors
|
switches |
0:0e018d759a2a
|
314
|
* The number of descriptors in the previous array.
|
switches |
0:0e018d759a2a
|
315
|
* @param[in] hasVariableLen
|
switches |
0:0e018d759a2a
|
316
|
* Whether the attribute's value length changes over time.
|
switches |
0:0e018d759a2a
|
317
|
*
|
switches |
0:0e018d759a2a
|
318
|
* @note The UUID value must be unique in the service and is normally >1.
|
switches |
0:0e018d759a2a
|
319
|
*
|
switches |
0:0e018d759a2a
|
320
|
* @note If valuePtr == NULL, length == 0, and properties == READ
|
switches |
0:0e018d759a2a
|
321
|
* for the value attribute of a characteristic, then that particular
|
switches |
0:0e018d759a2a
|
322
|
* characteristic may be considered optional and dropped while
|
switches |
0:0e018d759a2a
|
323
|
* instantiating the service with the underlying BLE stack.
|
switches |
0:0e018d759a2a
|
324
|
*/
|
switches |
0:0e018d759a2a
|
325
|
GattCharacteristic(const UUID &uuid,
|
switches |
0:0e018d759a2a
|
326
|
uint8_t *valuePtr = NULL,
|
switches |
0:0e018d759a2a
|
327
|
uint16_t len = 0,
|
switches |
0:0e018d759a2a
|
328
|
uint16_t maxLen = 0,
|
switches |
0:0e018d759a2a
|
329
|
uint8_t props = BLE_GATT_CHAR_PROPERTIES_NONE,
|
switches |
0:0e018d759a2a
|
330
|
GattAttribute *descriptors[] = NULL,
|
switches |
0:0e018d759a2a
|
331
|
unsigned numDescriptors = 0,
|
switches |
0:0e018d759a2a
|
332
|
bool hasVariableLen = true) :
|
switches |
0:0e018d759a2a
|
333
|
_valueAttribute(uuid, valuePtr, len, maxLen, hasVariableLen),
|
switches |
0:0e018d759a2a
|
334
|
_properties(props),
|
switches |
0:0e018d759a2a
|
335
|
_requiredSecurity(SecurityManager::SECURITY_MODE_ENCRYPTION_OPEN_LINK),
|
switches |
0:0e018d759a2a
|
336
|
_descriptors(descriptors),
|
switches |
0:0e018d759a2a
|
337
|
_descriptorCount(numDescriptors),
|
switches |
0:0e018d759a2a
|
338
|
enabledReadAuthorization(false),
|
switches |
0:0e018d759a2a
|
339
|
enabledWriteAuthorization(false),
|
switches |
0:0e018d759a2a
|
340
|
readAuthorizationCallback(),
|
switches |
0:0e018d759a2a
|
341
|
writeAuthorizationCallback() {
|
switches |
0:0e018d759a2a
|
342
|
/* empty */
|
switches |
0:0e018d759a2a
|
343
|
}
|
switches |
0:0e018d759a2a
|
344
|
|
switches |
0:0e018d759a2a
|
345
|
public:
|
switches |
0:0e018d759a2a
|
346
|
/**
|
switches |
0:0e018d759a2a
|
347
|
* Set up the minimum security (mode and level) requirements for access to
|
switches |
0:0e018d759a2a
|
348
|
* the characteristic's value attribute.
|
switches |
0:0e018d759a2a
|
349
|
*
|
switches |
0:0e018d759a2a
|
350
|
* @param[in] securityMode
|
switches |
0:0e018d759a2a
|
351
|
* Can be one of encryption or signing, with or without
|
switches |
0:0e018d759a2a
|
352
|
* protection for man in the middle attacks (MITM).
|
switches |
0:0e018d759a2a
|
353
|
*/
|
switches |
0:0e018d759a2a
|
354
|
void requireSecurity(SecurityManager::SecurityMode_t securityMode) {
|
switches |
0:0e018d759a2a
|
355
|
_requiredSecurity = securityMode;
|
switches |
0:0e018d759a2a
|
356
|
}
|
switches |
0:0e018d759a2a
|
357
|
|
switches |
0:0e018d759a2a
|
358
|
public:
|
switches |
0:0e018d759a2a
|
359
|
/**
|
switches |
0:0e018d759a2a
|
360
|
* Set up callback that will be triggered before the GATT Client is allowed
|
switches |
0:0e018d759a2a
|
361
|
* to write this characteristic. The handler will determine the
|
switches |
0:0e018d759a2a
|
362
|
* authorization reply for the write.
|
switches |
0:0e018d759a2a
|
363
|
*
|
switches |
0:0e018d759a2a
|
364
|
* @param[in] callback
|
switches |
0:0e018d759a2a
|
365
|
* Event handler being registered.
|
switches |
0:0e018d759a2a
|
366
|
*/
|
switches |
0:0e018d759a2a
|
367
|
void setWriteAuthorizationCallback(void (*callback)(GattWriteAuthCallbackParams *)) {
|
switches |
0:0e018d759a2a
|
368
|
writeAuthorizationCallback.attach(callback);
|
switches |
0:0e018d759a2a
|
369
|
enabledWriteAuthorization = true;
|
switches |
0:0e018d759a2a
|
370
|
}
|
switches |
0:0e018d759a2a
|
371
|
|
switches |
0:0e018d759a2a
|
372
|
/**
|
switches |
0:0e018d759a2a
|
373
|
* Same as GattCharacrteristic::setWriteAuthorizationCallback(), but allows
|
switches |
0:0e018d759a2a
|
374
|
* the possibility to add an object reference and member function as
|
switches |
0:0e018d759a2a
|
375
|
* handler for connection event callbacks.
|
switches |
0:0e018d759a2a
|
376
|
*
|
switches |
0:0e018d759a2a
|
377
|
* @param[in] object
|
switches |
0:0e018d759a2a
|
378
|
* Pointer to the object of a class defining the member callback
|
switches |
0:0e018d759a2a
|
379
|
* function (@p member).
|
switches |
0:0e018d759a2a
|
380
|
* @param[in] member
|
switches |
0:0e018d759a2a
|
381
|
* The member callback (within the context of an object) to be
|
switches |
0:0e018d759a2a
|
382
|
* invoked.
|
switches |
0:0e018d759a2a
|
383
|
*/
|
switches |
0:0e018d759a2a
|
384
|
template <typename T>
|
switches |
0:0e018d759a2a
|
385
|
void setWriteAuthorizationCallback(T *object, void (T::*member)(GattWriteAuthCallbackParams *)) {
|
switches |
0:0e018d759a2a
|
386
|
writeAuthorizationCallback.attach(object, member);
|
switches |
0:0e018d759a2a
|
387
|
enabledWriteAuthorization = true;
|
switches |
0:0e018d759a2a
|
388
|
}
|
switches |
0:0e018d759a2a
|
389
|
|
switches |
0:0e018d759a2a
|
390
|
/**
|
switches |
0:0e018d759a2a
|
391
|
* Set up callback that will be triggered before the GATT Client is allowed
|
switches |
0:0e018d759a2a
|
392
|
* to read this characteristic. The handler will determine the
|
switches |
0:0e018d759a2a
|
393
|
* authorizaion reply for the read.
|
switches |
0:0e018d759a2a
|
394
|
*
|
switches |
0:0e018d759a2a
|
395
|
* @param[in] callback
|
switches |
0:0e018d759a2a
|
396
|
* Event handler being registered.
|
switches |
0:0e018d759a2a
|
397
|
*/
|
switches |
0:0e018d759a2a
|
398
|
void setReadAuthorizationCallback(void (*callback)(GattReadAuthCallbackParams *)) {
|
switches |
0:0e018d759a2a
|
399
|
readAuthorizationCallback.attach(callback);
|
switches |
0:0e018d759a2a
|
400
|
enabledReadAuthorization = true;
|
switches |
0:0e018d759a2a
|
401
|
}
|
switches |
0:0e018d759a2a
|
402
|
|
switches |
0:0e018d759a2a
|
403
|
/**
|
switches |
0:0e018d759a2a
|
404
|
* Same as GattCharacrteristic::setReadAuthorizationCallback(), but allows
|
switches |
0:0e018d759a2a
|
405
|
* the possibility to add an object reference and member function as
|
switches |
0:0e018d759a2a
|
406
|
* handler for connection event callbacks.
|
switches |
0:0e018d759a2a
|
407
|
*
|
switches |
0:0e018d759a2a
|
408
|
* @param[in] object
|
switches |
0:0e018d759a2a
|
409
|
* Pointer to the object of a class defining the member callback
|
switches |
0:0e018d759a2a
|
410
|
* function (@p member).
|
switches |
0:0e018d759a2a
|
411
|
* @param[in] member
|
switches |
0:0e018d759a2a
|
412
|
* The member callback (within the context of an object) to be
|
switches |
0:0e018d759a2a
|
413
|
* invoked.
|
switches |
0:0e018d759a2a
|
414
|
*/
|
switches |
0:0e018d759a2a
|
415
|
template <typename T>
|
switches |
0:0e018d759a2a
|
416
|
void setReadAuthorizationCallback(T *object, void (T::*member)(GattReadAuthCallbackParams *)) {
|
switches |
0:0e018d759a2a
|
417
|
readAuthorizationCallback.attach(object, member);
|
switches |
0:0e018d759a2a
|
418
|
enabledReadAuthorization = true;
|
switches |
0:0e018d759a2a
|
419
|
}
|
switches |
0:0e018d759a2a
|
420
|
|
switches |
0:0e018d759a2a
|
421
|
/**
|
switches |
0:0e018d759a2a
|
422
|
* Helper that calls the registered handler to determine the authorization
|
switches |
0:0e018d759a2a
|
423
|
* reply for a write request. This function is meant to be called from the
|
switches |
0:0e018d759a2a
|
424
|
* BLE stack specific implementation.
|
switches |
0:0e018d759a2a
|
425
|
*
|
switches |
0:0e018d759a2a
|
426
|
* @param[in] params
|
switches |
0:0e018d759a2a
|
427
|
* To capture the context of the write-auth request. Also
|
switches |
0:0e018d759a2a
|
428
|
* contains an out-parameter for reply.
|
switches |
0:0e018d759a2a
|
429
|
*
|
switches |
0:0e018d759a2a
|
430
|
* @return A GattAuthCallbackReply_t value indicating whether authorization
|
switches |
0:0e018d759a2a
|
431
|
* is granted.
|
switches |
0:0e018d759a2a
|
432
|
*/
|
switches |
0:0e018d759a2a
|
433
|
GattAuthCallbackReply_t authorizeWrite(GattWriteAuthCallbackParams *params) {
|
switches |
0:0e018d759a2a
|
434
|
if (!isWriteAuthorizationEnabled()) {
|
switches |
0:0e018d759a2a
|
435
|
return AUTH_CALLBACK_REPLY_SUCCESS;
|
switches |
0:0e018d759a2a
|
436
|
}
|
switches |
0:0e018d759a2a
|
437
|
|
switches |
0:0e018d759a2a
|
438
|
params->authorizationReply = AUTH_CALLBACK_REPLY_SUCCESS; /* Initialized to no-error by default. */
|
switches |
0:0e018d759a2a
|
439
|
writeAuthorizationCallback.call(params);
|
switches |
0:0e018d759a2a
|
440
|
return params->authorizationReply;
|
switches |
0:0e018d759a2a
|
441
|
}
|
switches |
0:0e018d759a2a
|
442
|
|
switches |
0:0e018d759a2a
|
443
|
/**
|
switches |
0:0e018d759a2a
|
444
|
* Helper that calls the registered handler to determine the authorization
|
switches |
0:0e018d759a2a
|
445
|
* reply for a read request. This function is meant to be called from the
|
switches |
0:0e018d759a2a
|
446
|
* BLE stack specific implementation.
|
switches |
0:0e018d759a2a
|
447
|
*
|
switches |
0:0e018d759a2a
|
448
|
* @param[in] params
|
switches |
0:0e018d759a2a
|
449
|
* To capture the context of the read-auth request.
|
switches |
0:0e018d759a2a
|
450
|
*
|
switches |
0:0e018d759a2a
|
451
|
* @return A GattAuthCallbackReply_t value indicating whether authorization
|
switches |
0:0e018d759a2a
|
452
|
* is granted.
|
switches |
0:0e018d759a2a
|
453
|
*
|
switches |
0:0e018d759a2a
|
454
|
* @note To authorize or deny the read the params->authorizationReply field
|
switches |
0:0e018d759a2a
|
455
|
* should be set to true (authorize) or false (deny).
|
switches |
0:0e018d759a2a
|
456
|
*
|
switches |
0:0e018d759a2a
|
457
|
* @note If the read is approved and params->data is unchanged (NULL),
|
switches |
0:0e018d759a2a
|
458
|
* the current characteristic value will be used.
|
switches |
0:0e018d759a2a
|
459
|
*
|
switches |
0:0e018d759a2a
|
460
|
* @note If the read is approved, a new value can be provided by setting
|
switches |
0:0e018d759a2a
|
461
|
* the params->data pointer and params->len fields.
|
switches |
0:0e018d759a2a
|
462
|
*/
|
switches |
0:0e018d759a2a
|
463
|
GattAuthCallbackReply_t authorizeRead(GattReadAuthCallbackParams *params) {
|
switches |
0:0e018d759a2a
|
464
|
if (!isReadAuthorizationEnabled()) {
|
switches |
0:0e018d759a2a
|
465
|
return AUTH_CALLBACK_REPLY_SUCCESS;
|
switches |
0:0e018d759a2a
|
466
|
}
|
switches |
0:0e018d759a2a
|
467
|
|
switches |
0:0e018d759a2a
|
468
|
params->authorizationReply = AUTH_CALLBACK_REPLY_SUCCESS; /* Initialized to no-error by default. */
|
switches |
0:0e018d759a2a
|
469
|
readAuthorizationCallback.call(params);
|
switches |
0:0e018d759a2a
|
470
|
return params->authorizationReply;
|
switches |
0:0e018d759a2a
|
471
|
}
|
switches |
0:0e018d759a2a
|
472
|
|
switches |
0:0e018d759a2a
|
473
|
public:
|
switches |
0:0e018d759a2a
|
474
|
/**
|
switches |
0:0e018d759a2a
|
475
|
* Get the characteristic's value attribute.
|
switches |
0:0e018d759a2a
|
476
|
*
|
switches |
0:0e018d759a2a
|
477
|
* @return A reference to the characteristic's value attribute.
|
switches |
0:0e018d759a2a
|
478
|
*/
|
switches |
0:0e018d759a2a
|
479
|
GattAttribute& getValueAttribute() {
|
switches |
0:0e018d759a2a
|
480
|
return _valueAttribute;
|
switches |
0:0e018d759a2a
|
481
|
}
|
switches |
0:0e018d759a2a
|
482
|
|
switches |
0:0e018d759a2a
|
483
|
/**
|
switches |
0:0e018d759a2a
|
484
|
* A const alternative to GattCharacteristic::getValueAttribute().
|
switches |
0:0e018d759a2a
|
485
|
*
|
switches |
0:0e018d759a2a
|
486
|
* @return A const reference to the characteristic's value attribute.
|
switches |
0:0e018d759a2a
|
487
|
*/
|
switches |
0:0e018d759a2a
|
488
|
const GattAttribute& getValueAttribute() const {
|
switches |
0:0e018d759a2a
|
489
|
return _valueAttribute;
|
switches |
0:0e018d759a2a
|
490
|
}
|
switches |
0:0e018d759a2a
|
491
|
|
switches |
0:0e018d759a2a
|
492
|
/**
|
switches |
0:0e018d759a2a
|
493
|
* Get the characteristic's value attribute handle in the ATT table.
|
switches |
0:0e018d759a2a
|
494
|
*
|
switches |
0:0e018d759a2a
|
495
|
* @return The value attribute handle.
|
switches |
0:0e018d759a2a
|
496
|
*
|
switches |
0:0e018d759a2a
|
497
|
* @note The attribute handle is typically assigned by the underlying BLE
|
switches |
0:0e018d759a2a
|
498
|
* stack.
|
switches |
0:0e018d759a2a
|
499
|
*/
|
switches |
0:0e018d759a2a
|
500
|
GattAttribute::Handle_t getValueHandle(void) const {
|
switches |
0:0e018d759a2a
|
501
|
return getValueAttribute().getHandle();
|
switches |
0:0e018d759a2a
|
502
|
}
|
switches |
0:0e018d759a2a
|
503
|
|
switches |
0:0e018d759a2a
|
504
|
/**
|
switches |
0:0e018d759a2a
|
505
|
* Get the characteristic's propertied. Refer to
|
switches |
0:0e018d759a2a
|
506
|
* GattCharacteristic::Properties_t.
|
switches |
0:0e018d759a2a
|
507
|
*
|
switches |
0:0e018d759a2a
|
508
|
* @return The characteristic's properties.
|
switches |
0:0e018d759a2a
|
509
|
*/
|
switches |
0:0e018d759a2a
|
510
|
uint8_t getProperties(void) const {
|
switches |
0:0e018d759a2a
|
511
|
return _properties;
|
switches |
0:0e018d759a2a
|
512
|
}
|
switches |
0:0e018d759a2a
|
513
|
|
switches |
0:0e018d759a2a
|
514
|
/**
|
switches |
0:0e018d759a2a
|
515
|
* Get the characteristic's required security.
|
switches |
0:0e018d759a2a
|
516
|
*
|
switches |
0:0e018d759a2a
|
517
|
* @return The characteristic's required security.
|
switches |
0:0e018d759a2a
|
518
|
*/
|
switches |
0:0e018d759a2a
|
519
|
SecurityManager::SecurityMode_t getRequiredSecurity() const {
|
switches |
0:0e018d759a2a
|
520
|
return _requiredSecurity;
|
switches |
0:0e018d759a2a
|
521
|
}
|
switches |
0:0e018d759a2a
|
522
|
|
switches |
0:0e018d759a2a
|
523
|
/**
|
switches |
0:0e018d759a2a
|
524
|
* Get the total number of descriptors within this characteristic.
|
switches |
0:0e018d759a2a
|
525
|
*
|
switches |
0:0e018d759a2a
|
526
|
* @return The total number of descriptors.
|
switches |
0:0e018d759a2a
|
527
|
*/
|
switches |
0:0e018d759a2a
|
528
|
uint8_t getDescriptorCount(void) const {
|
switches |
0:0e018d759a2a
|
529
|
return _descriptorCount;
|
switches |
0:0e018d759a2a
|
530
|
}
|
switches |
0:0e018d759a2a
|
531
|
|
switches |
0:0e018d759a2a
|
532
|
/**
|
switches |
0:0e018d759a2a
|
533
|
* Check whether read authorization is enabled i.e. check whether a
|
switches |
0:0e018d759a2a
|
534
|
* read authorization callback was previously registered. Refer to
|
switches |
0:0e018d759a2a
|
535
|
* GattCharacteristic::setReadAuthorizationCallback().
|
switches |
0:0e018d759a2a
|
536
|
*
|
switches |
0:0e018d759a2a
|
537
|
* @return true if read authorization is enabled, false otherwise.
|
switches |
0:0e018d759a2a
|
538
|
*/
|
switches |
0:0e018d759a2a
|
539
|
bool isReadAuthorizationEnabled() const {
|
switches |
0:0e018d759a2a
|
540
|
return enabledReadAuthorization;
|
switches |
0:0e018d759a2a
|
541
|
}
|
switches |
0:0e018d759a2a
|
542
|
|
switches |
0:0e018d759a2a
|
543
|
/**
|
switches |
0:0e018d759a2a
|
544
|
* Check whether write authorization is enabled i.e. check whether a
|
switches |
0:0e018d759a2a
|
545
|
* write authorization callback was previously registered. Refer to
|
switches |
0:0e018d759a2a
|
546
|
* GattCharacteristic::setReadAuthorizationCallback().
|
switches |
0:0e018d759a2a
|
547
|
*
|
switches |
0:0e018d759a2a
|
548
|
* @return true if write authorization is enabled, false otherwise.
|
switches |
0:0e018d759a2a
|
549
|
*/
|
switches |
0:0e018d759a2a
|
550
|
bool isWriteAuthorizationEnabled() const {
|
switches |
0:0e018d759a2a
|
551
|
return enabledWriteAuthorization;
|
switches |
0:0e018d759a2a
|
552
|
}
|
switches |
0:0e018d759a2a
|
553
|
|
switches |
0:0e018d759a2a
|
554
|
/**
|
switches |
0:0e018d759a2a
|
555
|
* Get this characteristic's descriptor at a specific index.
|
switches |
0:0e018d759a2a
|
556
|
*
|
switches |
0:0e018d759a2a
|
557
|
* @param[in] index
|
switches |
0:0e018d759a2a
|
558
|
* The descriptor's index.
|
switches |
0:0e018d759a2a
|
559
|
*
|
switches |
0:0e018d759a2a
|
560
|
* @return A pointer the requested descriptor if @p index contains a valid
|
switches |
0:0e018d759a2a
|
561
|
* descriptor, or NULL otherwise.
|
switches |
0:0e018d759a2a
|
562
|
*/
|
switches |
0:0e018d759a2a
|
563
|
GattAttribute *getDescriptor(uint8_t index) {
|
switches |
0:0e018d759a2a
|
564
|
if (index >= _descriptorCount) {
|
switches |
0:0e018d759a2a
|
565
|
return NULL;
|
switches |
0:0e018d759a2a
|
566
|
}
|
switches |
0:0e018d759a2a
|
567
|
|
switches |
0:0e018d759a2a
|
568
|
return _descriptors[index];
|
switches |
0:0e018d759a2a
|
569
|
}
|
switches |
0:0e018d759a2a
|
570
|
|
switches |
0:0e018d759a2a
|
571
|
private:
|
switches |
0:0e018d759a2a
|
572
|
/**
|
switches |
0:0e018d759a2a
|
573
|
* Attribute that contains the actual value of this characteristic.
|
switches |
0:0e018d759a2a
|
574
|
*/
|
switches |
0:0e018d759a2a
|
575
|
GattAttribute _valueAttribute;
|
switches |
0:0e018d759a2a
|
576
|
/**
|
switches |
0:0e018d759a2a
|
577
|
* The characteristic's properties. Refer to
|
switches |
0:0e018d759a2a
|
578
|
* GattCharacteristic::Properties_t.
|
switches |
0:0e018d759a2a
|
579
|
*/
|
switches |
0:0e018d759a2a
|
580
|
uint8_t _properties;
|
switches |
0:0e018d759a2a
|
581
|
/**
|
switches |
0:0e018d759a2a
|
582
|
* The characteristic's required security.
|
switches |
0:0e018d759a2a
|
583
|
*/
|
switches |
0:0e018d759a2a
|
584
|
SecurityManager::SecurityMode_t _requiredSecurity;
|
switches |
0:0e018d759a2a
|
585
|
/**
|
switches |
0:0e018d759a2a
|
586
|
* The characteristic's descriptor attributes.
|
switches |
0:0e018d759a2a
|
587
|
*/
|
switches |
0:0e018d759a2a
|
588
|
GattAttribute **_descriptors;
|
switches |
0:0e018d759a2a
|
589
|
/**
|
switches |
0:0e018d759a2a
|
590
|
* The number of descriptors in this characteristic.
|
switches |
0:0e018d759a2a
|
591
|
*/
|
switches |
0:0e018d759a2a
|
592
|
uint8_t _descriptorCount;
|
switches |
0:0e018d759a2a
|
593
|
|
switches |
0:0e018d759a2a
|
594
|
/**
|
switches |
0:0e018d759a2a
|
595
|
* Whether read authorization is enabled i.e. whether there is a registered
|
switches |
0:0e018d759a2a
|
596
|
* callback to determine read authorization reply.
|
switches |
0:0e018d759a2a
|
597
|
*/
|
switches |
0:0e018d759a2a
|
598
|
bool enabledReadAuthorization;
|
switches |
0:0e018d759a2a
|
599
|
/**
|
switches |
0:0e018d759a2a
|
600
|
* Whether write authorization is enabled i.e. whether there is a registered
|
switches |
0:0e018d759a2a
|
601
|
* callback to determine write authorization reply.
|
switches |
0:0e018d759a2a
|
602
|
*/
|
switches |
0:0e018d759a2a
|
603
|
bool enabledWriteAuthorization;
|
switches |
0:0e018d759a2a
|
604
|
/**
|
switches |
0:0e018d759a2a
|
605
|
* The registered callback handler for read authorization reply.
|
switches |
0:0e018d759a2a
|
606
|
*/
|
switches |
0:0e018d759a2a
|
607
|
FunctionPointerWithContext<GattReadAuthCallbackParams *> readAuthorizationCallback;
|
switches |
0:0e018d759a2a
|
608
|
/**
|
switches |
0:0e018d759a2a
|
609
|
* The registered callback handler for write authorization reply.
|
switches |
0:0e018d759a2a
|
610
|
*/
|
switches |
0:0e018d759a2a
|
611
|
FunctionPointerWithContext<GattWriteAuthCallbackParams *> writeAuthorizationCallback;
|
switches |
0:0e018d759a2a
|
612
|
|
switches |
0:0e018d759a2a
|
613
|
private:
|
switches |
0:0e018d759a2a
|
614
|
/* Disallow copy and assignment. */
|
switches |
0:0e018d759a2a
|
615
|
GattCharacteristic(const GattCharacteristic &);
|
switches |
0:0e018d759a2a
|
616
|
GattCharacteristic& operator=(const GattCharacteristic &);
|
switches |
0:0e018d759a2a
|
617
|
};
|
switches |
0:0e018d759a2a
|
618
|
|
switches |
0:0e018d759a2a
|
619
|
/**
|
switches |
0:0e018d759a2a
|
620
|
* Helper class to construct a read-only GattCharacteristic.
|
switches |
0:0e018d759a2a
|
621
|
*/
|
switches |
0:0e018d759a2a
|
622
|
template <typename T>
|
switches |
0:0e018d759a2a
|
623
|
class ReadOnlyGattCharacteristic : public GattCharacteristic {
|
switches |
0:0e018d759a2a
|
624
|
public:
|
switches |
0:0e018d759a2a
|
625
|
/**
|
switches |
0:0e018d759a2a
|
626
|
* Construct a ReadOnlyGattCharacteristic.
|
switches |
0:0e018d759a2a
|
627
|
*
|
switches |
0:0e018d759a2a
|
628
|
* @param[in] uuid
|
switches |
0:0e018d759a2a
|
629
|
* The characteristic's UUID.
|
switches |
0:0e018d759a2a
|
630
|
* @param[in] valuePtr
|
switches |
0:0e018d759a2a
|
631
|
* Pointer to the characterisitic's initial value.
|
switches |
0:0e018d759a2a
|
632
|
* @param[in] additionalProperties
|
switches |
0:0e018d759a2a
|
633
|
* Additional characterisitic properties. By default, the
|
switches |
0:0e018d759a2a
|
634
|
* properties are set to
|
switches |
0:0e018d759a2a
|
635
|
* Properties_t::BLE_GATT_CHAR_PROPERTIES_READ.
|
switches |
0:0e018d759a2a
|
636
|
* @param[in] descriptors
|
switches |
0:0e018d759a2a
|
637
|
* An array of pointers to descriptors to be added to the new
|
switches |
0:0e018d759a2a
|
638
|
* characteristic.
|
switches |
0:0e018d759a2a
|
639
|
* @param[in] numDescriptors
|
switches |
0:0e018d759a2a
|
640
|
* The total number of descriptors in @p descriptors.
|
switches |
0:0e018d759a2a
|
641
|
*
|
switches |
0:0e018d759a2a
|
642
|
* @note Instances of ReadOnlyGattCharacteristic have a fixed length
|
switches |
0:0e018d759a2a
|
643
|
* attribute value that equals sizeof(T). For a variable length
|
switches |
0:0e018d759a2a
|
644
|
* alternative use GattCharacteristic directly.
|
switches |
0:0e018d759a2a
|
645
|
*/
|
switches |
0:0e018d759a2a
|
646
|
ReadOnlyGattCharacteristic<T>(const UUID &uuid,
|
switches |
0:0e018d759a2a
|
647
|
T *valuePtr,
|
switches |
0:0e018d759a2a
|
648
|
uint8_t additionalProperties = BLE_GATT_CHAR_PROPERTIES_NONE,
|
switches |
0:0e018d759a2a
|
649
|
GattAttribute *descriptors[] = NULL,
|
switches |
0:0e018d759a2a
|
650
|
unsigned numDescriptors = 0) :
|
switches |
0:0e018d759a2a
|
651
|
GattCharacteristic(uuid, reinterpret_cast<uint8_t *>(valuePtr), sizeof(T), sizeof(T),
|
switches |
0:0e018d759a2a
|
652
|
BLE_GATT_CHAR_PROPERTIES_READ | additionalProperties, descriptors, numDescriptors, false) {
|
switches |
0:0e018d759a2a
|
653
|
/* empty */
|
switches |
0:0e018d759a2a
|
654
|
}
|
switches |
0:0e018d759a2a
|
655
|
};
|
switches |
0:0e018d759a2a
|
656
|
|
switches |
0:0e018d759a2a
|
657
|
/**
|
switches |
0:0e018d759a2a
|
658
|
* Helper class to construct a write-only GattCharacteristic.
|
switches |
0:0e018d759a2a
|
659
|
*/
|
switches |
0:0e018d759a2a
|
660
|
template <typename T>
|
switches |
0:0e018d759a2a
|
661
|
class WriteOnlyGattCharacteristic : public GattCharacteristic {
|
switches |
0:0e018d759a2a
|
662
|
public:
|
switches |
0:0e018d759a2a
|
663
|
/**
|
switches |
0:0e018d759a2a
|
664
|
* Construct a WriteOnlyGattCharacteristic.
|
switches |
0:0e018d759a2a
|
665
|
*
|
switches |
0:0e018d759a2a
|
666
|
* @param[in] uuid
|
switches |
0:0e018d759a2a
|
667
|
* The characteristic's UUID.
|
switches |
0:0e018d759a2a
|
668
|
* @param[in] valuePtr
|
switches |
0:0e018d759a2a
|
669
|
* Pointer to the characterisitic's initial value.
|
switches |
0:0e018d759a2a
|
670
|
* @param[in] additionalProperties
|
switches |
0:0e018d759a2a
|
671
|
* Additional characterisitic properties. By default, the
|
switches |
0:0e018d759a2a
|
672
|
* properties are set to
|
switches |
0:0e018d759a2a
|
673
|
* Properties_t::BLE_GATT_CHAR_PROPERTIES_WRITE.
|
switches |
0:0e018d759a2a
|
674
|
* @param[in] descriptors
|
switches |
0:0e018d759a2a
|
675
|
* An array of pointers to descriptors to be added to the new
|
switches |
0:0e018d759a2a
|
676
|
* characteristic.
|
switches |
0:0e018d759a2a
|
677
|
* @param[in] numDescriptors
|
switches |
0:0e018d759a2a
|
678
|
* The total number of descriptors in @p descriptors.
|
switches |
0:0e018d759a2a
|
679
|
*
|
switches |
0:0e018d759a2a
|
680
|
* @note Instances of WriteOnlyGattCharacteristic have variable length
|
switches |
0:0e018d759a2a
|
681
|
* attribute value with maximum size equal to sizeof(T). For a fixed length
|
switches |
0:0e018d759a2a
|
682
|
* alternative use GattCharacteristic directly.
|
switches |
0:0e018d759a2a
|
683
|
*/
|
switches |
0:0e018d759a2a
|
684
|
WriteOnlyGattCharacteristic<T>(const UUID &uuid,
|
switches |
0:0e018d759a2a
|
685
|
T *valuePtr,
|
switches |
0:0e018d759a2a
|
686
|
uint8_t additionalProperties = BLE_GATT_CHAR_PROPERTIES_NONE,
|
switches |
0:0e018d759a2a
|
687
|
GattAttribute *descriptors[] = NULL,
|
switches |
0:0e018d759a2a
|
688
|
unsigned numDescriptors = 0) :
|
switches |
0:0e018d759a2a
|
689
|
GattCharacteristic(uuid, reinterpret_cast<uint8_t *>(valuePtr), sizeof(T), sizeof(T),
|
switches |
0:0e018d759a2a
|
690
|
BLE_GATT_CHAR_PROPERTIES_WRITE | additionalProperties, descriptors, numDescriptors) {
|
switches |
0:0e018d759a2a
|
691
|
/* empty */
|
switches |
0:0e018d759a2a
|
692
|
}
|
switches |
0:0e018d759a2a
|
693
|
};
|
switches |
0:0e018d759a2a
|
694
|
|
switches |
0:0e018d759a2a
|
695
|
/**
|
switches |
0:0e018d759a2a
|
696
|
* Helper class to construct a readable and writable GattCharacteristic.
|
switches |
0:0e018d759a2a
|
697
|
*/
|
switches |
0:0e018d759a2a
|
698
|
template <typename T>
|
switches |
0:0e018d759a2a
|
699
|
class ReadWriteGattCharacteristic : public GattCharacteristic {
|
switches |
0:0e018d759a2a
|
700
|
public:
|
switches |
0:0e018d759a2a
|
701
|
/**
|
switches |
0:0e018d759a2a
|
702
|
* Construct a ReadWriteGattCharacteristic.
|
switches |
0:0e018d759a2a
|
703
|
*
|
switches |
0:0e018d759a2a
|
704
|
* @param[in] uuid
|
switches |
0:0e018d759a2a
|
705
|
* The characteristic's UUID.
|
switches |
0:0e018d759a2a
|
706
|
* @param[in] valuePtr
|
switches |
0:0e018d759a2a
|
707
|
* Pointer to the characterisitic's initial value.
|
switches |
0:0e018d759a2a
|
708
|
* @param[in] additionalProperties
|
switches |
0:0e018d759a2a
|
709
|
* Additional characterisitic properties. By default, the
|
switches |
0:0e018d759a2a
|
710
|
* properties are set to
|
switches |
0:0e018d759a2a
|
711
|
* Properties_t::BLE_GATT_CHAR_PROPERTIES_WRITE |
|
switches |
0:0e018d759a2a
|
712
|
* Properties_t::BLE_GATT_CHAR_PROPERTIES_READ.
|
switches |
0:0e018d759a2a
|
713
|
* @param[in] descriptors
|
switches |
0:0e018d759a2a
|
714
|
* An array of pointers to descriptors to be added to the new
|
switches |
0:0e018d759a2a
|
715
|
* characteristic.
|
switches |
0:0e018d759a2a
|
716
|
* @param[in] numDescriptors
|
switches |
0:0e018d759a2a
|
717
|
* The total number of descriptors in @p descriptors.
|
switches |
0:0e018d759a2a
|
718
|
*
|
switches |
0:0e018d759a2a
|
719
|
* @note Instances of ReadWriteGattCharacteristic have variable length
|
switches |
0:0e018d759a2a
|
720
|
* attribute value with maximum size equal to sizeof(T). For a fixed length
|
switches |
0:0e018d759a2a
|
721
|
* alternative use GattCharacteristic directly.
|
switches |
0:0e018d759a2a
|
722
|
*/
|
switches |
0:0e018d759a2a
|
723
|
ReadWriteGattCharacteristic<T>(const UUID &uuid,
|
switches |
0:0e018d759a2a
|
724
|
T *valuePtr,
|
switches |
0:0e018d759a2a
|
725
|
uint8_t additionalProperties = BLE_GATT_CHAR_PROPERTIES_NONE,
|
switches |
0:0e018d759a2a
|
726
|
GattAttribute *descriptors[] = NULL,
|
switches |
0:0e018d759a2a
|
727
|
unsigned numDescriptors = 0) :
|
switches |
0:0e018d759a2a
|
728
|
GattCharacteristic(uuid, reinterpret_cast<uint8_t *>(valuePtr), sizeof(T), sizeof(T),
|
switches |
0:0e018d759a2a
|
729
|
BLE_GATT_CHAR_PROPERTIES_READ | BLE_GATT_CHAR_PROPERTIES_WRITE | additionalProperties, descriptors, numDescriptors) {
|
switches |
0:0e018d759a2a
|
730
|
/* empty */
|
switches |
0:0e018d759a2a
|
731
|
}
|
switches |
0:0e018d759a2a
|
732
|
};
|
switches |
0:0e018d759a2a
|
733
|
|
switches |
0:0e018d759a2a
|
734
|
/**
|
switches |
0:0e018d759a2a
|
735
|
* Helper class to construct a write-only GattCharacteristic with an array
|
switches |
0:0e018d759a2a
|
736
|
* value.
|
switches |
0:0e018d759a2a
|
737
|
*/
|
switches |
0:0e018d759a2a
|
738
|
template <typename T, unsigned NUM_ELEMENTS>
|
switches |
0:0e018d759a2a
|
739
|
class WriteOnlyArrayGattCharacteristic : public GattCharacteristic {
|
switches |
0:0e018d759a2a
|
740
|
public:
|
switches |
0:0e018d759a2a
|
741
|
/**
|
switches |
0:0e018d759a2a
|
742
|
* Construct a WriteOnlyGattCharacteristic.
|
switches |
0:0e018d759a2a
|
743
|
*
|
switches |
0:0e018d759a2a
|
744
|
* @param[in] uuid
|
switches |
0:0e018d759a2a
|
745
|
* The characteristic's UUID.
|
switches |
0:0e018d759a2a
|
746
|
* @param[in] valuePtr
|
switches |
0:0e018d759a2a
|
747
|
* Pointer to an array of length NUM_ELEMENTS containing the
|
switches |
0:0e018d759a2a
|
748
|
* characteristic's intitial value.
|
switches |
0:0e018d759a2a
|
749
|
* @param[in] additionalProperties
|
switches |
0:0e018d759a2a
|
750
|
* Additional characterisitic properties. By default, the
|
switches |
0:0e018d759a2a
|
751
|
* properties are set to
|
switches |
0:0e018d759a2a
|
752
|
* Properties_t::BLE_GATT_CHAR_PROPERTIES_WRITE.
|
switches |
0:0e018d759a2a
|
753
|
* @param[in] descriptors
|
switches |
0:0e018d759a2a
|
754
|
* An array of pointers to descriptors to be added to the new
|
switches |
0:0e018d759a2a
|
755
|
* characteristic.
|
switches |
0:0e018d759a2a
|
756
|
* @param[in] numDescriptors
|
switches |
0:0e018d759a2a
|
757
|
* The total number of descriptors in @p descriptors.
|
switches |
0:0e018d759a2a
|
758
|
*
|
switches |
0:0e018d759a2a
|
759
|
* @note Instances of WriteOnlyGattCharacteristic have variable length
|
switches |
0:0e018d759a2a
|
760
|
* attribute value with maximum size equal to sizeof(T) * NUM_ELEMENTS.
|
switches |
0:0e018d759a2a
|
761
|
* For a fixed length alternative use GattCharacteristic directly.
|
switches |
0:0e018d759a2a
|
762
|
*/
|
switches |
0:0e018d759a2a
|
763
|
WriteOnlyArrayGattCharacteristic<T, NUM_ELEMENTS>(const UUID &uuid,
|
switches |
0:0e018d759a2a
|
764
|
T valuePtr[NUM_ELEMENTS],
|
switches |
0:0e018d759a2a
|
765
|
uint8_t additionalProperties = BLE_GATT_CHAR_PROPERTIES_NONE,
|
switches |
0:0e018d759a2a
|
766
|
GattAttribute *descriptors[] = NULL,
|
switches |
0:0e018d759a2a
|
767
|
unsigned numDescriptors = 0) :
|
switches |
0:0e018d759a2a
|
768
|
GattCharacteristic(uuid, reinterpret_cast<uint8_t *>(valuePtr), sizeof(T) * NUM_ELEMENTS, sizeof(T) * NUM_ELEMENTS,
|
switches |
0:0e018d759a2a
|
769
|
BLE_GATT_CHAR_PROPERTIES_WRITE | additionalProperties, descriptors, numDescriptors) {
|
switches |
0:0e018d759a2a
|
770
|
/* empty */
|
switches |
0:0e018d759a2a
|
771
|
}
|
switches |
0:0e018d759a2a
|
772
|
};
|
switches |
0:0e018d759a2a
|
773
|
|
switches |
0:0e018d759a2a
|
774
|
/**
|
switches |
0:0e018d759a2a
|
775
|
* Helper class to construct a read-only GattCharacteristic with an array
|
switches |
0:0e018d759a2a
|
776
|
* value.
|
switches |
0:0e018d759a2a
|
777
|
*/
|
switches |
0:0e018d759a2a
|
778
|
template <typename T, unsigned NUM_ELEMENTS>
|
switches |
0:0e018d759a2a
|
779
|
class ReadOnlyArrayGattCharacteristic : public GattCharacteristic {
|
switches |
0:0e018d759a2a
|
780
|
public:
|
switches |
0:0e018d759a2a
|
781
|
/**
|
switches |
0:0e018d759a2a
|
782
|
* Construct a ReadOnlyGattCharacteristic.
|
switches |
0:0e018d759a2a
|
783
|
*
|
switches |
0:0e018d759a2a
|
784
|
* @param[in] uuid
|
switches |
0:0e018d759a2a
|
785
|
* The characteristic's UUID.
|
switches |
0:0e018d759a2a
|
786
|
* @param[in] valuePtr
|
switches |
0:0e018d759a2a
|
787
|
* Pointer to an array of length NUM_ELEMENTS containing the
|
switches |
0:0e018d759a2a
|
788
|
* characteristic's intitial value.
|
switches |
0:0e018d759a2a
|
789
|
* @param[in] additionalProperties
|
switches |
0:0e018d759a2a
|
790
|
* Additional characterisitic properties. By default, the
|
switches |
0:0e018d759a2a
|
791
|
* properties are set to
|
switches |
0:0e018d759a2a
|
792
|
* Properties_t::BLE_GATT_CHAR_PROPERTIES_READ.
|
switches |
0:0e018d759a2a
|
793
|
* @param[in] descriptors
|
switches |
0:0e018d759a2a
|
794
|
* An array of pointers to descriptors to be added to the new
|
switches |
0:0e018d759a2a
|
795
|
* characteristic.
|
switches |
0:0e018d759a2a
|
796
|
* @param[in] numDescriptors
|
switches |
0:0e018d759a2a
|
797
|
* The total number of descriptors in @p descriptors.
|
switches |
0:0e018d759a2a
|
798
|
*
|
switches |
0:0e018d759a2a
|
799
|
* @note Instances of ReadOnlyGattCharacteristic have fixed length
|
switches |
0:0e018d759a2a
|
800
|
* attribute value that equals sizeof(T) * NUM_ELEMENTS.
|
switches |
0:0e018d759a2a
|
801
|
* For a variable length alternative use GattCharacteristic directly.
|
switches |
0:0e018d759a2a
|
802
|
*/
|
switches |
0:0e018d759a2a
|
803
|
ReadOnlyArrayGattCharacteristic<T, NUM_ELEMENTS>(const UUID &uuid,
|
switches |
0:0e018d759a2a
|
804
|
T valuePtr[NUM_ELEMENTS],
|
switches |
0:0e018d759a2a
|
805
|
uint8_t additionalProperties = BLE_GATT_CHAR_PROPERTIES_NONE,
|
switches |
0:0e018d759a2a
|
806
|
GattAttribute *descriptors[] = NULL,
|
switches |
0:0e018d759a2a
|
807
|
unsigned numDescriptors = 0) :
|
switches |
0:0e018d759a2a
|
808
|
GattCharacteristic(uuid, reinterpret_cast<uint8_t *>(valuePtr), sizeof(T) * NUM_ELEMENTS, sizeof(T) * NUM_ELEMENTS,
|
switches |
0:0e018d759a2a
|
809
|
BLE_GATT_CHAR_PROPERTIES_READ | additionalProperties, descriptors, numDescriptors, false) {
|
switches |
0:0e018d759a2a
|
810
|
/* empty */
|
switches |
0:0e018d759a2a
|
811
|
}
|
switches |
0:0e018d759a2a
|
812
|
};
|
switches |
0:0e018d759a2a
|
813
|
|
switches |
0:0e018d759a2a
|
814
|
/**
|
switches |
0:0e018d759a2a
|
815
|
* Helper class to construct a readable and writable GattCharacteristic with an array
|
switches |
0:0e018d759a2a
|
816
|
* value.
|
switches |
0:0e018d759a2a
|
817
|
*/
|
switches |
0:0e018d759a2a
|
818
|
template <typename T, unsigned NUM_ELEMENTS>
|
switches |
0:0e018d759a2a
|
819
|
class ReadWriteArrayGattCharacteristic : public GattCharacteristic {
|
switches |
0:0e018d759a2a
|
820
|
public:
|
switches |
0:0e018d759a2a
|
821
|
/**
|
switches |
0:0e018d759a2a
|
822
|
* Construct a ReadWriteGattCharacteristic.
|
switches |
0:0e018d759a2a
|
823
|
*
|
switches |
0:0e018d759a2a
|
824
|
* @param[in] uuid
|
switches |
0:0e018d759a2a
|
825
|
* The characteristic's UUID.
|
switches |
0:0e018d759a2a
|
826
|
* @param[in] valuePtr
|
switches |
0:0e018d759a2a
|
827
|
* Pointer to an array of length NUM_ELEMENTS containing the
|
switches |
0:0e018d759a2a
|
828
|
* characteristic's intitial value.
|
switches |
0:0e018d759a2a
|
829
|
* @param[in] additionalProperties
|
switches |
0:0e018d759a2a
|
830
|
* Additional characterisitic properties. By default, the
|
switches |
0:0e018d759a2a
|
831
|
* properties are set to
|
switches |
0:0e018d759a2a
|
832
|
* Properties_t::BLE_GATT_CHAR_PROPERTIES_WRITE |
|
switches |
0:0e018d759a2a
|
833
|
* Properties_t::BLE_GATT_CHAR_PROPERTIES_READ.
|
switches |
0:0e018d759a2a
|
834
|
* @param[in] descriptors
|
switches |
0:0e018d759a2a
|
835
|
* An array of pointers to descriptors to be added to the new
|
switches |
0:0e018d759a2a
|
836
|
* characteristic.
|
switches |
0:0e018d759a2a
|
837
|
* @param[in] numDescriptors
|
switches |
0:0e018d759a2a
|
838
|
* The total number of descriptors in @p descriptors.
|
switches |
0:0e018d759a2a
|
839
|
*
|
switches |
0:0e018d759a2a
|
840
|
* @note Instances of ReadWriteGattCharacteristic have variable length
|
switches |
0:0e018d759a2a
|
841
|
* attribute value with maximum size equal to sizeof(T) * NUM_ELEMENTS.
|
switches |
0:0e018d759a2a
|
842
|
* For a fixed length alternative use GattCharacteristic directly.
|
switches |
0:0e018d759a2a
|
843
|
*/
|
switches |
0:0e018d759a2a
|
844
|
ReadWriteArrayGattCharacteristic<T, NUM_ELEMENTS>(const UUID &uuid,
|
switches |
0:0e018d759a2a
|
845
|
T valuePtr[NUM_ELEMENTS],
|
switches |
0:0e018d759a2a
|
846
|
uint8_t additionalProperties = BLE_GATT_CHAR_PROPERTIES_NONE,
|
switches |
0:0e018d759a2a
|
847
|
GattAttribute *descriptors[] = NULL,
|
switches |
0:0e018d759a2a
|
848
|
unsigned numDescriptors = 0) :
|
switches |
0:0e018d759a2a
|
849
|
GattCharacteristic(uuid, reinterpret_cast<uint8_t *>(valuePtr), sizeof(T) * NUM_ELEMENTS, sizeof(T) * NUM_ELEMENTS,
|
switches |
0:0e018d759a2a
|
850
|
BLE_GATT_CHAR_PROPERTIES_READ | BLE_GATT_CHAR_PROPERTIES_WRITE | additionalProperties, descriptors, numDescriptors) {
|
switches |
0:0e018d759a2a
|
851
|
/* empty */
|
switches |
0:0e018d759a2a
|
852
|
}
|
switches |
0:0e018d759a2a
|
853
|
};
|
switches |
0:0e018d759a2a
|
854
|
|
switches |
0:0e018d759a2a
|
855
|
#endif /* ifndef __GATT_CHARACTERISTIC_H__ */
|