prova invio BLE

Dependents:   BLE_HeartRate_IDB04A1

Fork of BLE_API by Bluetooth Low Energy

Committer:
vcoubard
Date:
Wed Apr 06 19:14:51 2016 +0100
Revision:
1163:7a1cfb9ae86e
Parent:
1132:6362b7c2fdff
Child:
1179:4ab722f8dca0
Synchronized with git rev 0fd17e96
Author: Andres Amaya Garcia
Add missing docs and fix doxy warnings in GattCharacteristic.h

Who changed what in which revision?

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