Includes library modifications to allow access to AIN_4 (AIN_0 / 5)

Committer:
bryantaylor
Date:
Tue Sep 20 21:26:12 2016 +0000
Revision:
0:eafc3fd41f75
hackathon

Who changed what in which revision?

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