Pinned to some recent date

Committer:
Simon Cooksey
Date:
Thu Nov 17 16:43:53 2016 +0000
Revision:
0:fb7af294d5d9
Initial commit

Who changed what in which revision?

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