Improve readability with getHandle inline
Fork of BLE_API by
public/GattCharacteristic.h@255:097be53aea02, 2014-12-12 (annotated)
- Committer:
- rgrover1
- Date:
- Fri Dec 12 13:32:24 2014 +0000
- Revision:
- 255:097be53aea02
- Parent:
- 254:69d049317cae
Synchronized with git rev 2552bf25
Author: Rohit Grover
Release 0.2.9
=============
API enhancements to support read/write authorization for GATT accesses.
Enhancements
~~~~~~~~~~~~
* Add support for authorization, whereby the user application can receive a
callback to authorize a read or a write on a characteristic's value
attribute before GATT commits the transaction. We now have an API for
GattCharacterisitc called setWriteAuthorizationCallback() which can filter
incoming access requests before they get applied to the GATT database.
Bugfixes
~~~~~~~~
Compatibility
~~~~~~~~~~~~~
This release is backward compatible with 0.2.4.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Rohit Grover |
106:a20be740075d | 1 | /* mbed Microcontroller Library |
Rohit Grover |
106:a20be740075d | 2 | * Copyright (c) 2006-2013 ARM Limited |
Rohit Grover |
106:a20be740075d | 3 | * |
Rohit Grover |
106:a20be740075d | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
Rohit Grover |
106:a20be740075d | 5 | * you may not use this file except in compliance with the License. |
Rohit Grover |
106:a20be740075d | 6 | * You may obtain a copy of the License at |
Rohit Grover |
106:a20be740075d | 7 | * |
Rohit Grover |
106:a20be740075d | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
Rohit Grover |
106:a20be740075d | 9 | * |
Rohit Grover |
106:a20be740075d | 10 | * Unless required by applicable law or agreed to in writing, software |
Rohit Grover |
106:a20be740075d | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
Rohit Grover |
106:a20be740075d | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
Rohit Grover |
106:a20be740075d | 13 | * See the License for the specific language governing permissions and |
Rohit Grover |
106:a20be740075d | 14 | * limitations under the License. |
Rohit Grover |
106:a20be740075d | 15 | */ |
Rohit Grover |
106:a20be740075d | 16 | |
Rohit Grover |
106:a20be740075d | 17 | #ifndef __GATT_CHARACTERISTIC_H__ |
Rohit Grover |
106:a20be740075d | 18 | #define __GATT_CHARACTERISTIC_H__ |
Rohit Grover |
106:a20be740075d | 19 | |
carlescufi | 112:64c88ad45610 | 20 | #include "GattAttribute.h" |
rgrover1 | 251:5d9118449482 | 21 | #include "GattCharacteristicWriteCBParams.h" |
rgrover1 | 251:5d9118449482 | 22 | #include "FunctionPointerWithContext.h" |
Rohit Grover |
106:a20be740075d | 23 | |
rgrover1 | 144:c025c8839682 | 24 | class GattCharacteristic { |
Rohit Grover |
106:a20be740075d | 25 | public: |
Rohit Grover |
106:a20be740075d | 26 | enum { |
Rohit Grover |
106:a20be740075d | 27 | UUID_BATTERY_LEVEL_STATE_CHAR = 0x2A1B, |
Rohit Grover |
106:a20be740075d | 28 | UUID_BATTERY_POWER_STATE_CHAR = 0x2A1A, |
Rohit Grover |
106:a20be740075d | 29 | UUID_REMOVABLE_CHAR = 0x2A3A, |
Rohit Grover |
106:a20be740075d | 30 | UUID_SERVICE_REQUIRED_CHAR = 0x2A3B, |
Rohit Grover |
106:a20be740075d | 31 | UUID_ALERT_CATEGORY_ID_CHAR = 0x2A43, |
Rohit Grover |
106:a20be740075d | 32 | UUID_ALERT_CATEGORY_ID_BIT_MASK_CHAR = 0x2A42, |
Rohit Grover |
106:a20be740075d | 33 | UUID_ALERT_LEVEL_CHAR = 0x2A06, |
Rohit Grover |
106:a20be740075d | 34 | UUID_ALERT_NOTIFICATION_CONTROL_POINT_CHAR = 0x2A44, |
Rohit Grover |
106:a20be740075d | 35 | UUID_ALERT_STATUS_CHAR = 0x2A3F, |
Rohit Grover |
106:a20be740075d | 36 | UUID_BATTERY_LEVEL_CHAR = 0x2A19, |
Rohit Grover |
106:a20be740075d | 37 | UUID_BLOOD_PRESSURE_FEATURE_CHAR = 0x2A49, |
Rohit Grover |
106:a20be740075d | 38 | UUID_BLOOD_PRESSURE_MEASUREMENT_CHAR = 0x2A35, |
Rohit Grover |
106:a20be740075d | 39 | UUID_BODY_SENSOR_LOCATION_CHAR = 0x2A38, |
Rohit Grover |
106:a20be740075d | 40 | UUID_BOOT_KEYBOARD_INPUT_REPORT_CHAR = 0x2A22, |
Rohit Grover |
106:a20be740075d | 41 | UUID_BOOT_KEYBOARD_OUTPUT_REPORT_CHAR = 0x2A32, |
Rohit Grover |
106:a20be740075d | 42 | UUID_BOOT_MOUSE_INPUT_REPORT_CHAR = 0x2A33, |
Rohit Grover |
106:a20be740075d | 43 | UUID_CURRENT_TIME_CHAR = 0x2A2B, |
Rohit Grover |
106:a20be740075d | 44 | UUID_DATE_TIME_CHAR = 0x2A08, |
Rohit Grover |
106:a20be740075d | 45 | UUID_DAY_DATE_TIME_CHAR = 0x2A0A, |
Rohit Grover |
106:a20be740075d | 46 | UUID_DAY_OF_WEEK_CHAR = 0x2A09, |
Rohit Grover |
106:a20be740075d | 47 | UUID_DST_OFFSET_CHAR = 0x2A0D, |
Rohit Grover |
106:a20be740075d | 48 | UUID_EXACT_TIME_256_CHAR = 0x2A0C, |
Rohit Grover |
106:a20be740075d | 49 | UUID_FIRMWARE_REVISION_STRING_CHAR = 0x2A26, |
Rohit Grover |
106:a20be740075d | 50 | UUID_GLUCOSE_FEATURE_CHAR = 0x2A51, |
Rohit Grover |
106:a20be740075d | 51 | UUID_GLUCOSE_MEASUREMENT_CHAR = 0x2A18, |
Rohit Grover |
106:a20be740075d | 52 | UUID_GLUCOSE_MEASUREMENT_CONTEXT_CHAR = 0x2A34, |
Rohit Grover |
106:a20be740075d | 53 | UUID_HARDWARE_REVISION_STRING_CHAR = 0x2A27, |
Rohit Grover |
106:a20be740075d | 54 | UUID_HEART_RATE_CONTROL_POINT_CHAR = 0x2A39, |
Rohit Grover |
106:a20be740075d | 55 | UUID_HEART_RATE_MEASUREMENT_CHAR = 0x2A37, |
Rohit Grover |
106:a20be740075d | 56 | UUID_HID_CONTROL_POINT_CHAR = 0x2A4C, |
Rohit Grover |
106:a20be740075d | 57 | UUID_HID_INFORMATION_CHAR = 0x2A4A, |
Rohit Grover |
106:a20be740075d | 58 | UUID_IEEE_REGULATORY_CERTIFICATION_DATA_LIST_CHAR = 0x2A2A, |
Rohit Grover |
106:a20be740075d | 59 | UUID_INTERMEDIATE_CUFF_PRESSURE_CHAR = 0x2A36, |
Rohit Grover |
106:a20be740075d | 60 | UUID_INTERMEDIATE_TEMPERATURE_CHAR = 0x2A1E, |
Rohit Grover |
106:a20be740075d | 61 | UUID_LOCAL_TIME_INFORMATION_CHAR = 0x2A0F, |
Rohit Grover |
106:a20be740075d | 62 | UUID_MANUFACTURER_NAME_STRING_CHAR = 0x2A29, |
Rohit Grover |
106:a20be740075d | 63 | UUID_MEASUREMENT_INTERVAL_CHAR = 0x2A21, |
Rohit Grover |
106:a20be740075d | 64 | UUID_MODEL_NUMBER_STRING_CHAR = 0x2A24, |
Rohit Grover |
106:a20be740075d | 65 | UUID_UNREAD_ALERT_CHAR = 0x2A45, |
Rohit Grover |
106:a20be740075d | 66 | UUID_NEW_ALERT_CHAR = 0x2A46, |
Rohit Grover |
106:a20be740075d | 67 | UUID_PNP_ID_CHAR = 0x2A50, |
Rohit Grover |
106:a20be740075d | 68 | UUID_PROTOCOL_MODE_CHAR = 0x2A4E, |
Rohit Grover |
106:a20be740075d | 69 | UUID_RECORD_ACCESS_CONTROL_POINT_CHAR = 0x2A52, |
Rohit Grover |
106:a20be740075d | 70 | UUID_REFERENCE_TIME_INFORMATION_CHAR = 0x2A14, |
Rohit Grover |
106:a20be740075d | 71 | UUID_REPORT_CHAR = 0x2A4D, |
Rohit Grover |
106:a20be740075d | 72 | UUID_REPORT_MAP_CHAR = 0x2A4B, |
Rohit Grover |
106:a20be740075d | 73 | UUID_RINGER_CONTROL_POINT_CHAR = 0x2A40, |
Rohit Grover |
106:a20be740075d | 74 | UUID_RINGER_SETTING_CHAR = 0x2A41, |
Rohit Grover |
106:a20be740075d | 75 | UUID_SCAN_INTERVAL_WINDOW_CHAR = 0x2A4F, |
Rohit Grover |
106:a20be740075d | 76 | UUID_SCAN_REFRESH_CHAR = 0x2A31, |
Rohit Grover |
106:a20be740075d | 77 | UUID_SERIAL_NUMBER_STRING_CHAR = 0x2A25, |
Rohit Grover |
106:a20be740075d | 78 | UUID_SOFTWARE_REVISION_STRING_CHAR = 0x2A28, |
Rohit Grover |
106:a20be740075d | 79 | UUID_SUPPORTED_NEW_ALERT_CATEGORY_CHAR = 0x2A47, |
Rohit Grover |
106:a20be740075d | 80 | UUID_SUPPORTED_UNREAD_ALERT_CATEGORY_CHAR = 0x2A48, |
Rohit Grover |
106:a20be740075d | 81 | UUID_SYSTEM_ID_CHAR = 0x2A23, |
Rohit Grover |
106:a20be740075d | 82 | UUID_TEMPERATURE_MEASUREMENT_CHAR = 0x2A1C, |
Rohit Grover |
106:a20be740075d | 83 | UUID_TEMPERATURE_TYPE_CHAR = 0x2A1D, |
Rohit Grover |
106:a20be740075d | 84 | UUID_TIME_ACCURACY_CHAR = 0x2A12, |
Rohit Grover |
106:a20be740075d | 85 | UUID_TIME_SOURCE_CHAR = 0x2A13, |
Rohit Grover |
106:a20be740075d | 86 | UUID_TIME_UPDATE_CONTROL_POINT_CHAR = 0x2A16, |
Rohit Grover |
106:a20be740075d | 87 | UUID_TIME_UPDATE_STATE_CHAR = 0x2A17, |
Rohit Grover |
106:a20be740075d | 88 | UUID_TIME_WITH_DST_CHAR = 0x2A11, |
Rohit Grover |
106:a20be740075d | 89 | UUID_TIME_ZONE_CHAR = 0x2A0E, |
Rohit Grover |
106:a20be740075d | 90 | UUID_TX_POWER_LEVEL_CHAR = 0x2A07, |
Rohit Grover |
106:a20be740075d | 91 | UUID_CSC_FEATURE_CHAR = 0x2A5C, |
Rohit Grover |
106:a20be740075d | 92 | UUID_CSC_MEASUREMENT_CHAR = 0x2A5B, |
Rohit Grover |
106:a20be740075d | 93 | UUID_RSC_FEATURE_CHAR = 0x2A54, |
Rohit Grover |
106:a20be740075d | 94 | UUID_RSC_MEASUREMENT_CHAR = 0x2A53, |
Rohit Grover |
106:a20be740075d | 95 | }; |
Rohit Grover |
106:a20be740075d | 96 | |
Rohit Grover |
106:a20be740075d | 97 | /**************************************************************************/ |
Rohit Grover |
106:a20be740075d | 98 | /*! |
Rohit Grover |
106:a20be740075d | 99 | \brief Standard GATT characteristic presentation format unit types. |
rgrover1 | 144:c025c8839682 | 100 | These unit types are used to describe what the raw numeric |
Rohit Grover |
106:a20be740075d | 101 | data in a characteristic actually represents. |
Rohit Grover |
106:a20be740075d | 102 | |
Rohit Grover |
106:a20be740075d | 103 | \note See https://developer.bluetooth.org/gatt/units/Pages/default.aspx |
Rohit Grover |
106:a20be740075d | 104 | */ |
Rohit Grover |
106:a20be740075d | 105 | /**************************************************************************/ |
Rohit Grover |
106:a20be740075d | 106 | typedef enum ble_gatt_unit_e { |
rgrover1 | 144:c025c8839682 | 107 | BLE_GATT_UNIT_NONE = 0x2700, /**< No specified unit type */ |
rgrover1 | 144:c025c8839682 | 108 | BLE_GATT_UNIT_LENGTH_METRE = 0x2701, /**< Length, Metre */ |
rgrover1 | 144:c025c8839682 | 109 | BLE_GATT_UNIT_MASS_KILOGRAM = 0x2702, /**< Mass, Kilogram */ |
rgrover1 | 144:c025c8839682 | 110 | BLE_GATT_UNIT_TIME_SECOND = 0x2703, /**< Time, Second */ |
rgrover1 | 144:c025c8839682 | 111 | BLE_GATT_UNIT_ELECTRIC_CURRENT_AMPERE = 0x2704, /**< Electric Current, Ampere */ |
rgrover1 | 144:c025c8839682 | 112 | BLE_GATT_UNIT_THERMODYNAMIC_TEMPERATURE_KELVIN = 0x2705, /**< Thermodynamic Temperature, Kelvin */ |
rgrover1 | 144:c025c8839682 | 113 | BLE_GATT_UNIT_AMOUNT_OF_SUBSTANCE_MOLE = 0x2706, /**< Amount of Substance, Mole */ |
rgrover1 | 144:c025c8839682 | 114 | BLE_GATT_UNIT_LUMINOUS_INTENSITY_CANDELA = 0x2707, /**< Luminous Intensity, Candela */ |
rgrover1 | 144:c025c8839682 | 115 | BLE_GATT_UNIT_AREA_SQUARE_METRES = 0x2710, /**< Area, Square Metres */ |
rgrover1 | 144:c025c8839682 | 116 | BLE_GATT_UNIT_VOLUME_CUBIC_METRES = 0x2711, /**< Volume, Cubic Metres*/ |
rgrover1 | 144:c025c8839682 | 117 | BLE_GATT_UNIT_VELOCITY_METRES_PER_SECOND = 0x2712, /**< Velocity, Metres per Second*/ |
rgrover1 | 144:c025c8839682 | 118 | BLE_GATT_UNIT_ACCELERATION_METRES_PER_SECOND_SQUARED = 0x2713, /**< Acceleration, Metres per Second Squared */ |
rgrover1 | 144:c025c8839682 | 119 | BLE_GATT_UNIT_WAVENUMBER_RECIPROCAL_METRE = 0x2714, /**< Wave Number Reciprocal, Metre */ |
rgrover1 | 144:c025c8839682 | 120 | BLE_GATT_UNIT_DENSITY_KILOGRAM_PER_CUBIC_METRE = 0x2715, /**< Density, Kilogram per Cubic Metre */ |
rgrover1 | 144:c025c8839682 | 121 | BLE_GATT_UNIT_SURFACE_DENSITY_KILOGRAM_PER_SQUARE_METRE = 0x2716, /**< */ |
rgrover1 | 144:c025c8839682 | 122 | BLE_GATT_UNIT_SPECIFIC_VOLUME_CUBIC_METRE_PER_KILOGRAM = 0x2717, /**< */ |
rgrover1 | 144:c025c8839682 | 123 | BLE_GATT_UNIT_CURRENT_DENSITY_AMPERE_PER_SQUARE_METRE = 0x2718, /**< */ |
rgrover1 | 144:c025c8839682 | 124 | BLE_GATT_UNIT_MAGNETIC_FIELD_STRENGTH_AMPERE_PER_METRE = 0x2719, /**< Magnetic Field Strength, Ampere per Metre */ |
rgrover1 | 144:c025c8839682 | 125 | BLE_GATT_UNIT_AMOUNT_CONCENTRATION_MOLE_PER_CUBIC_METRE = 0x271A, /**< */ |
rgrover1 | 144:c025c8839682 | 126 | BLE_GATT_UNIT_MASS_CONCENTRATION_KILOGRAM_PER_CUBIC_METRE = 0x271B, /**< */ |
rgrover1 | 144:c025c8839682 | 127 | BLE_GATT_UNIT_LUMINANCE_CANDELA_PER_SQUARE_METRE = 0x271C, /**< */ |
rgrover1 | 144:c025c8839682 | 128 | BLE_GATT_UNIT_REFRACTIVE_INDEX = 0x271D, /**< */ |
rgrover1 | 144:c025c8839682 | 129 | BLE_GATT_UNIT_RELATIVE_PERMEABILITY = 0x271E, /**< */ |
rgrover1 | 144:c025c8839682 | 130 | BLE_GATT_UNIT_PLANE_ANGLE_RADIAN = 0x2720, /**< */ |
rgrover1 | 144:c025c8839682 | 131 | BLE_GATT_UNIT_SOLID_ANGLE_STERADIAN = 0x2721, /**< */ |
rgrover1 | 144:c025c8839682 | 132 | BLE_GATT_UNIT_FREQUENCY_HERTZ = 0x2722, /**< Frequency, Hertz */ |
rgrover1 | 144:c025c8839682 | 133 | BLE_GATT_UNIT_FORCE_NEWTON = 0x2723, /**< Force, Newton */ |
rgrover1 | 144:c025c8839682 | 134 | BLE_GATT_UNIT_PRESSURE_PASCAL = 0x2724, /**< Pressure, Pascal */ |
rgrover1 | 144:c025c8839682 | 135 | BLE_GATT_UNIT_ENERGY_JOULE = 0x2725, /**< Energy, Joule */ |
rgrover1 | 144:c025c8839682 | 136 | BLE_GATT_UNIT_POWER_WATT = 0x2726, /**< Power, Watt */ |
rgrover1 | 144:c025c8839682 | 137 | BLE_GATT_UNIT_ELECTRIC_CHARGE_COULOMB = 0x2727, /**< Electrical Charge, Coulomb */ |
rgrover1 | 144:c025c8839682 | 138 | BLE_GATT_UNIT_ELECTRIC_POTENTIAL_DIFFERENCE_VOLT = 0x2728, /**< Electrical Potential Difference, Voltage */ |
rgrover1 | 144:c025c8839682 | 139 | BLE_GATT_UNIT_CAPACITANCE_FARAD = 0x2729, /**< */ |
rgrover1 | 144:c025c8839682 | 140 | BLE_GATT_UNIT_ELECTRIC_RESISTANCE_OHM = 0x272A, /**< */ |
rgrover1 | 144:c025c8839682 | 141 | BLE_GATT_UNIT_ELECTRIC_CONDUCTANCE_SIEMENS = 0x272B, /**< */ |
rgrover1 | 144:c025c8839682 | 142 | BLE_GATT_UNIT_MAGNETIC_FLEX_WEBER = 0x272C, /**< */ |
rgrover1 | 144:c025c8839682 | 143 | BLE_GATT_UNIT_MAGNETIC_FLEX_DENSITY_TESLA = 0x272D, /**< */ |
rgrover1 | 144:c025c8839682 | 144 | BLE_GATT_UNIT_INDUCTANCE_HENRY = 0x272E, /**< */ |
rgrover1 | 144:c025c8839682 | 145 | BLE_GATT_UNIT_THERMODYNAMIC_TEMPERATURE_DEGREE_CELSIUS = 0x272F, /**< */ |
rgrover1 | 144:c025c8839682 | 146 | BLE_GATT_UNIT_LUMINOUS_FLUX_LUMEN = 0x2730, /**< */ |
rgrover1 | 144:c025c8839682 | 147 | BLE_GATT_UNIT_ILLUMINANCE_LUX = 0x2731, /**< */ |
rgrover1 | 144:c025c8839682 | 148 | BLE_GATT_UNIT_ACTIVITY_REFERRED_TO_A_RADIONUCLIDE_BECQUEREL = 0x2732, /**< */ |
rgrover1 | 144:c025c8839682 | 149 | BLE_GATT_UNIT_ABSORBED_DOSE_GRAY = 0x2733, /**< */ |
rgrover1 | 144:c025c8839682 | 150 | BLE_GATT_UNIT_DOSE_EQUIVALENT_SIEVERT = 0x2734, /**< */ |
rgrover1 | 144:c025c8839682 | 151 | BLE_GATT_UNIT_CATALYTIC_ACTIVITY_KATAL = 0x2735, /**< */ |
rgrover1 | 144:c025c8839682 | 152 | BLE_GATT_UNIT_DYNAMIC_VISCOSITY_PASCAL_SECOND = 0x2740, /**< */ |
rgrover1 | 144:c025c8839682 | 153 | BLE_GATT_UNIT_MOMENT_OF_FORCE_NEWTON_METRE = 0x2741, /**< */ |
rgrover1 | 144:c025c8839682 | 154 | BLE_GATT_UNIT_SURFACE_TENSION_NEWTON_PER_METRE = 0x2742, /**< */ |
rgrover1 | 144:c025c8839682 | 155 | BLE_GATT_UNIT_ANGULAR_VELOCITY_RADIAN_PER_SECOND = 0x2743, /**< */ |
rgrover1 | 144:c025c8839682 | 156 | BLE_GATT_UNIT_ANGULAR_ACCELERATION_RADIAN_PER_SECOND_SQUARED = 0x2744, /**< */ |
rgrover1 | 144:c025c8839682 | 157 | BLE_GATT_UNIT_HEAT_FLUX_DENSITY_WATT_PER_SQUARE_METRE = 0x2745, /**< */ |
rgrover1 | 144:c025c8839682 | 158 | BLE_GATT_UNIT_HEAT_CAPACITY_JOULE_PER_KELVIN = 0x2746, /**< */ |
rgrover1 | 144:c025c8839682 | 159 | BLE_GATT_UNIT_SPECIFIC_HEAT_CAPACITY_JOULE_PER_KILOGRAM_KELVIN = 0x2747, /**< */ |
rgrover1 | 144:c025c8839682 | 160 | BLE_GATT_UNIT_SPECIFIC_ENERGY_JOULE_PER_KILOGRAM = 0x2748, /**< */ |
rgrover1 | 144:c025c8839682 | 161 | BLE_GATT_UNIT_THERMAL_CONDUCTIVITY_WATT_PER_METRE_KELVIN = 0x2749, /**< */ |
rgrover1 | 144:c025c8839682 | 162 | BLE_GATT_UNIT_ENERGY_DENSITY_JOULE_PER_CUBIC_METRE = 0x274A, /**< */ |
rgrover1 | 144:c025c8839682 | 163 | BLE_GATT_UNIT_ELECTRIC_FIELD_STRENGTH_VOLT_PER_METRE = 0x274B, /**< */ |
rgrover1 | 144:c025c8839682 | 164 | BLE_GATT_UNIT_ELECTRIC_CHARGE_DENSITY_COULOMB_PER_CUBIC_METRE = 0x274C, /**< */ |
rgrover1 | 144:c025c8839682 | 165 | BLE_GATT_UNIT_SURFACE_CHARGE_DENSITY_COULOMB_PER_SQUARE_METRE = 0x274D, /**< */ |
rgrover1 | 144:c025c8839682 | 166 | BLE_GATT_UNIT_ELECTRIC_FLUX_DENSITY_COULOMB_PER_SQUARE_METRE = 0x274E, /**< */ |
rgrover1 | 144:c025c8839682 | 167 | BLE_GATT_UNIT_PERMITTIVITY_FARAD_PER_METRE = 0x274F, /**< */ |
rgrover1 | 144:c025c8839682 | 168 | BLE_GATT_UNIT_PERMEABILITY_HENRY_PER_METRE = 0x2750, /**< */ |
rgrover1 | 144:c025c8839682 | 169 | BLE_GATT_UNIT_MOLAR_ENERGY_JOULE_PER_MOLE = 0x2751, /**< */ |
rgrover1 | 144:c025c8839682 | 170 | BLE_GATT_UNIT_MOLAR_ENTROPY_JOULE_PER_MOLE_KELVIN = 0x2752, /**< */ |
rgrover1 | 144:c025c8839682 | 171 | BLE_GATT_UNIT_EXPOSURE_COULOMB_PER_KILOGRAM = 0x2753, /**< */ |
rgrover1 | 144:c025c8839682 | 172 | BLE_GATT_UNIT_ABSORBED_DOSE_RATE_GRAY_PER_SECOND = 0x2754, /**< */ |
rgrover1 | 144:c025c8839682 | 173 | BLE_GATT_UNIT_RADIANT_INTENSITY_WATT_PER_STERADIAN = 0x2755, /**< */ |
rgrover1 | 144:c025c8839682 | 174 | BLE_GATT_UNIT_RADIANCE_WATT_PER_SQUARE_METRE_STERADIAN = 0x2756, /**< */ |
rgrover1 | 144:c025c8839682 | 175 | BLE_GATT_UNIT_CATALYTIC_ACTIVITY_CONCENTRATION_KATAL_PER_CUBIC_METRE = 0x2757, /**< */ |
rgrover1 | 144:c025c8839682 | 176 | BLE_GATT_UNIT_TIME_MINUTE = 0x2760, /**< Time, Minute */ |
rgrover1 | 144:c025c8839682 | 177 | BLE_GATT_UNIT_TIME_HOUR = 0x2761, /**< Time, Hour */ |
rgrover1 | 144:c025c8839682 | 178 | BLE_GATT_UNIT_TIME_DAY = 0x2762, /**< Time, Day */ |
rgrover1 | 144:c025c8839682 | 179 | BLE_GATT_UNIT_PLANE_ANGLE_DEGREE = 0x2763, /**< */ |
rgrover1 | 144:c025c8839682 | 180 | BLE_GATT_UNIT_PLANE_ANGLE_MINUTE = 0x2764, /**< */ |
rgrover1 | 144:c025c8839682 | 181 | BLE_GATT_UNIT_PLANE_ANGLE_SECOND = 0x2765, /**< */ |
rgrover1 | 144:c025c8839682 | 182 | BLE_GATT_UNIT_AREA_HECTARE = 0x2766, /**< */ |
rgrover1 | 144:c025c8839682 | 183 | BLE_GATT_UNIT_VOLUME_LITRE = 0x2767, /**< */ |
rgrover1 | 144:c025c8839682 | 184 | BLE_GATT_UNIT_MASS_TONNE = 0x2768, /**< */ |
rgrover1 | 144:c025c8839682 | 185 | BLE_GATT_UNIT_PRESSURE_BAR = 0x2780, /**< Pressure, Bar */ |
rgrover1 | 144:c025c8839682 | 186 | BLE_GATT_UNIT_PRESSURE_MILLIMETRE_OF_MERCURY = 0x2781, /**< Pressure, Millimetre of Mercury */ |
rgrover1 | 144:c025c8839682 | 187 | BLE_GATT_UNIT_LENGTH_ANGSTROM = 0x2782, /**< */ |
rgrover1 | 144:c025c8839682 | 188 | BLE_GATT_UNIT_LENGTH_NAUTICAL_MILE = 0x2783, /**< */ |
rgrover1 | 144:c025c8839682 | 189 | BLE_GATT_UNIT_AREA_BARN = 0x2784, /**< */ |
rgrover1 | 144:c025c8839682 | 190 | BLE_GATT_UNIT_VELOCITY_KNOT = 0x2785, /**< */ |
rgrover1 | 144:c025c8839682 | 191 | BLE_GATT_UNIT_LOGARITHMIC_RADIO_QUANTITY_NEPER = 0x2786, /**< */ |
rgrover1 | 144:c025c8839682 | 192 | BLE_GATT_UNIT_LOGARITHMIC_RADIO_QUANTITY_BEL = 0x2787, /**< */ |
rgrover1 | 144:c025c8839682 | 193 | BLE_GATT_UNIT_LENGTH_YARD = 0x27A0, /**< Length, Yard */ |
rgrover1 | 144:c025c8839682 | 194 | BLE_GATT_UNIT_LENGTH_PARSEC = 0x27A1, /**< Length, Parsec */ |
rgrover1 | 144:c025c8839682 | 195 | BLE_GATT_UNIT_LENGTH_INCH = 0x27A2, /**< Length, Inch */ |
rgrover1 | 144:c025c8839682 | 196 | BLE_GATT_UNIT_LENGTH_FOOT = 0x27A3, /**< Length, Foot */ |
rgrover1 | 144:c025c8839682 | 197 | BLE_GATT_UNIT_LENGTH_MILE = 0x27A4, /**< Length, Mile */ |
rgrover1 | 144:c025c8839682 | 198 | BLE_GATT_UNIT_PRESSURE_POUND_FORCE_PER_SQUARE_INCH = 0x27A5, /**< */ |
rgrover1 | 144:c025c8839682 | 199 | BLE_GATT_UNIT_VELOCITY_KILOMETRE_PER_HOUR = 0x27A6, /**< Velocity, Kilometre per Hour */ |
rgrover1 | 144:c025c8839682 | 200 | BLE_GATT_UNIT_VELOCITY_MILE_PER_HOUR = 0x27A7, /**< Velocity, Mile per Hour */ |
rgrover1 | 144:c025c8839682 | 201 | BLE_GATT_UNIT_ANGULAR_VELOCITY_REVOLUTION_PER_MINUTE = 0x27A8, /**< Angular Velocity, Revolution per Minute */ |
rgrover1 | 144:c025c8839682 | 202 | BLE_GATT_UNIT_ENERGY_GRAM_CALORIE = 0x27A9, /**< Energy, Gram Calorie */ |
rgrover1 | 144:c025c8839682 | 203 | BLE_GATT_UNIT_ENERGY_KILOGRAM_CALORIE = 0x27AA, /**< Energy, Kilogram Calorie */ |
rgrover1 | 144:c025c8839682 | 204 | BLE_GATT_UNIT_ENERGY_KILOWATT_HOUR = 0x27AB, /**< Energy, Killowatt Hour */ |
rgrover1 | 144:c025c8839682 | 205 | BLE_GATT_UNIT_THERMODYNAMIC_TEMPERATURE_DEGREE_FAHRENHEIT = 0x27AC, /**< */ |
rgrover1 | 144:c025c8839682 | 206 | BLE_GATT_UNIT_PERCENTAGE = 0x27AD, /**< Percentage */ |
rgrover1 | 144:c025c8839682 | 207 | BLE_GATT_UNIT_PER_MILLE = 0x27AE, /**< */ |
rgrover1 | 144:c025c8839682 | 208 | BLE_GATT_UNIT_PERIOD_BEATS_PER_MINUTE = 0x27AF, /**< */ |
rgrover1 | 144:c025c8839682 | 209 | BLE_GATT_UNIT_ELECTRIC_CHARGE_AMPERE_HOURS = 0x27B0, /**< */ |
rgrover1 | 144:c025c8839682 | 210 | BLE_GATT_UNIT_MASS_DENSITY_MILLIGRAM_PER_DECILITRE = 0x27B1, /**< */ |
rgrover1 | 144:c025c8839682 | 211 | BLE_GATT_UNIT_MASS_DENSITY_MILLIMOLE_PER_LITRE = 0x27B2, /**< */ |
rgrover1 | 144:c025c8839682 | 212 | BLE_GATT_UNIT_TIME_YEAR = 0x27B3, /**< Time, Year */ |
rgrover1 | 144:c025c8839682 | 213 | BLE_GATT_UNIT_TIME_MONTH = 0x27B4, /**< Time, Month */ |
rgrover1 | 144:c025c8839682 | 214 | BLE_GATT_UNIT_CONCENTRATION_COUNT_PER_CUBIC_METRE = 0x27B5, /**< */ |
rgrover1 | 144:c025c8839682 | 215 | BLE_GATT_UNIT_IRRADIANCE_WATT_PER_SQUARE_METRE = 0x27B6 /**< */ |
Rohit Grover |
106:a20be740075d | 216 | } ble_gatt_unit_t; |
Rohit Grover |
106:a20be740075d | 217 | |
Rohit Grover |
106:a20be740075d | 218 | /**************************************************************************/ |
Rohit Grover |
106:a20be740075d | 219 | /*! |
Rohit Grover |
106:a20be740075d | 220 | \brief Standard GATT number types |
Rohit Grover |
106:a20be740075d | 221 | |
Rohit Grover |
106:a20be740075d | 222 | \note See Bluetooth Specification 4.0 (Vol. 3), Part G, Section 3.3.3.5.2 |
Rohit Grover |
106:a20be740075d | 223 | \note See http://developer.bluetooth.org/gatt/descriptors/Pages/DescriptorViewer.aspx?u=org.bluetooth.descriptor.gatt.characteristic_presentation_format.xml |
Rohit Grover |
106:a20be740075d | 224 | */ |
Rohit Grover |
106:a20be740075d | 225 | /**************************************************************************/ |
Rohit Grover |
106:a20be740075d | 226 | typedef enum ble_gatt_format_e { |
Rohit Grover |
106:a20be740075d | 227 | BLE_GATT_FORMAT_RFU = 0x00, /**< Reserved For Future Use. */ |
Rohit Grover |
106:a20be740075d | 228 | BLE_GATT_FORMAT_BOOLEAN = 0x01, /**< Boolean. */ |
Rohit Grover |
106:a20be740075d | 229 | BLE_GATT_FORMAT_2BIT = 0x02, /**< Unsigned 2-bit integer. */ |
Rohit Grover |
106:a20be740075d | 230 | BLE_GATT_FORMAT_NIBBLE = 0x03, /**< Unsigned 4-bit integer. */ |
Rohit Grover |
106:a20be740075d | 231 | BLE_GATT_FORMAT_UINT8 = 0x04, /**< Unsigned 8-bit integer. */ |
Rohit Grover |
106:a20be740075d | 232 | BLE_GATT_FORMAT_UINT12 = 0x05, /**< Unsigned 12-bit integer. */ |
Rohit Grover |
106:a20be740075d | 233 | BLE_GATT_FORMAT_UINT16 = 0x06, /**< Unsigned 16-bit integer. */ |
Rohit Grover |
106:a20be740075d | 234 | BLE_GATT_FORMAT_UINT24 = 0x07, /**< Unsigned 24-bit integer. */ |
Rohit Grover |
106:a20be740075d | 235 | BLE_GATT_FORMAT_UINT32 = 0x08, /**< Unsigned 32-bit integer. */ |
Rohit Grover |
106:a20be740075d | 236 | BLE_GATT_FORMAT_UINT48 = 0x09, /**< Unsigned 48-bit integer. */ |
Rohit Grover |
106:a20be740075d | 237 | BLE_GATT_FORMAT_UINT64 = 0x0A, /**< Unsigned 64-bit integer. */ |
Rohit Grover |
106:a20be740075d | 238 | BLE_GATT_FORMAT_UINT128 = 0x0B, /**< Unsigned 128-bit integer. */ |
Rohit Grover |
106:a20be740075d | 239 | BLE_GATT_FORMAT_SINT8 = 0x0C, /**< Signed 2-bit integer. */ |
Rohit Grover |
106:a20be740075d | 240 | BLE_GATT_FORMAT_SINT12 = 0x0D, /**< Signed 12-bit integer. */ |
Rohit Grover |
106:a20be740075d | 241 | BLE_GATT_FORMAT_SINT16 = 0x0E, /**< Signed 16-bit integer. */ |
Rohit Grover |
106:a20be740075d | 242 | BLE_GATT_FORMAT_SINT24 = 0x0F, /**< Signed 24-bit integer. */ |
Rohit Grover |
106:a20be740075d | 243 | BLE_GATT_FORMAT_SINT32 = 0x10, /**< Signed 32-bit integer. */ |
Rohit Grover |
106:a20be740075d | 244 | BLE_GATT_FORMAT_SINT48 = 0x11, /**< Signed 48-bit integer. */ |
Rohit Grover |
106:a20be740075d | 245 | BLE_GATT_FORMAT_SINT64 = 0x12, /**< Signed 64-bit integer. */ |
Rohit Grover |
106:a20be740075d | 246 | BLE_GATT_FORMAT_SINT128 = 0x13, /**< Signed 128-bit integer. */ |
Rohit Grover |
106:a20be740075d | 247 | BLE_GATT_FORMAT_FLOAT32 = 0x14, /**< IEEE-754 32-bit floating point. */ |
Rohit Grover |
106:a20be740075d | 248 | BLE_GATT_FORMAT_FLOAT64 = 0x15, /**< IEEE-754 64-bit floating point. */ |
Rohit Grover |
106:a20be740075d | 249 | BLE_GATT_FORMAT_SFLOAT = 0x16, /**< IEEE-11073 16-bit SFLOAT. */ |
Rohit Grover |
106:a20be740075d | 250 | BLE_GATT_FORMAT_FLOAT = 0x17, /**< IEEE-11073 32-bit FLOAT. */ |
Rohit Grover |
106:a20be740075d | 251 | BLE_GATT_FORMAT_DUINT16 = 0x18, /**< IEEE-20601 format. */ |
Rohit Grover |
106:a20be740075d | 252 | BLE_GATT_FORMAT_UTF8S = 0x19, /**< UTF-8 string. */ |
Rohit Grover |
106:a20be740075d | 253 | BLE_GATT_FORMAT_UTF16S = 0x1A, /**< UTF-16 string. */ |
Rohit Grover |
106:a20be740075d | 254 | BLE_GATT_FORMAT_STRUCT = 0x1B /**< Opaque Structure. */ |
Rohit Grover |
106:a20be740075d | 255 | } ble_gatt_format_t; |
Rohit Grover |
106:a20be740075d | 256 | |
Rohit Grover |
106:a20be740075d | 257 | /**************************************************************************/ |
Rohit Grover |
106:a20be740075d | 258 | /*! |
rgrover1 | 144:c025c8839682 | 259 | \brief Standard GATT characteristic properties |
Rohit Grover |
106:a20be740075d | 260 | |
Rohit Grover |
106:a20be740075d | 261 | \note See Bluetooth Specification 4.0 (Vol. 3), Part G, Section 3.3.1.1 |
Rohit Grover |
106:a20be740075d | 262 | and Section 3.3.3.1 for Extended Properties |
Rohit Grover |
106:a20be740075d | 263 | */ |
Rohit Grover |
106:a20be740075d | 264 | /**************************************************************************/ |
Rohit Grover |
106:a20be740075d | 265 | typedef enum ble_gatt_char_properties_e { |
Rohit Grover |
106:a20be740075d | 266 | BLE_GATT_CHAR_PROPERTIES_NONE = 0x00, |
Rohit Grover |
106:a20be740075d | 267 | BLE_GATT_CHAR_PROPERTIES_BROADCAST = 0x01, /**< Permits broadcasts of the Characteristic Value using Server Characteristic Configuration Descriptor. */ |
Rohit Grover |
106:a20be740075d | 268 | BLE_GATT_CHAR_PROPERTIES_READ = 0x02, /**< Permits reads of the Characteristic Value. */ |
Rohit Grover |
106:a20be740075d | 269 | BLE_GATT_CHAR_PROPERTIES_WRITE_WITHOUT_RESPONSE = 0x04, /**< Permits writes of the Characteristic Value without response. */ |
Rohit Grover |
106:a20be740075d | 270 | BLE_GATT_CHAR_PROPERTIES_WRITE = 0x08, /**< Permits writes of the Characteristic Value with response. */ |
rgrover1 | 144:c025c8839682 | 271 | BLE_GATT_CHAR_PROPERTIES_NOTIFY = 0x10, /**< Permits notifications of a Characteristic Value without acknowledgment. */ |
rgrover1 | 144:c025c8839682 | 272 | BLE_GATT_CHAR_PROPERTIES_INDICATE = 0x20, /**< Permits indications of a Characteristic Value with acknowledgment. */ |
Rohit Grover |
106:a20be740075d | 273 | BLE_GATT_CHAR_PROPERTIES_AUTHENTICATED_SIGNED_WRITES = 0x40, /**< Permits signed writes to the Characteristic Value. */ |
Rohit Grover |
106:a20be740075d | 274 | BLE_GATT_CHAR_PROPERTIES_EXTENDED_PROPERTIES = 0x80 /**< Additional characteristic properties are defined in the Characteristic Extended Properties Descriptor */ |
Rohit Grover |
106:a20be740075d | 275 | } ble_gatt_char_properties_t; |
Rohit Grover |
106:a20be740075d | 276 | |
Rohit Grover |
106:a20be740075d | 277 | /**************************************************************************/ |
Rohit Grover |
106:a20be740075d | 278 | /*! |
Rohit Grover |
106:a20be740075d | 279 | \brief GATT presentation format wrapper |
Rohit Grover |
106:a20be740075d | 280 | |
Rohit Grover |
106:a20be740075d | 281 | \note See Bluetooth Specification 4.0 (Vol. 3), Part G, Section 3.3.3.5 |
Rohit Grover |
106:a20be740075d | 282 | \note See https://developer.bluetooth.org/gatt/descriptors/Pages/DescriptorViewer.aspx?u=org.bluetooth.descriptor.gatt.characteristic_presentation_format.xml |
Rohit Grover |
106:a20be740075d | 283 | */ |
Rohit Grover |
106:a20be740075d | 284 | /**************************************************************************/ |
Rohit Grover |
106:a20be740075d | 285 | typedef struct PresentationFormat { |
Rohit Grover |
106:a20be740075d | 286 | uint8_t gatt_format; /**< Format of the value, see @ref ble_gatt_format_t. */ |
Rohit Grover |
106:a20be740075d | 287 | int8_t exponent; /**< Exponent for integer data types. Ex. if Exponent = -3 and the char value is 3892, the actual value is 3.892 */ |
Rohit Grover |
106:a20be740075d | 288 | uint16_t gatt_unit; /**< UUID from Bluetooth Assigned Numbers, see @ref ble_gatt_unit_t. */ |
Rohit Grover |
106:a20be740075d | 289 | uint8_t gatt_namespace; /**< Namespace from Bluetooth Assigned Numbers, normally '1', see @ref BLE_GATT_CPF_NAMESPACES. */ |
Rohit Grover |
106:a20be740075d | 290 | uint16_t gatt_nsdesc; /**< Namespace description from Bluetooth Assigned Numbers, normally '0', see @ref BLE_GATT_CPF_NAMESPACES. */ |
Rohit Grover |
106:a20be740075d | 291 | } presentation_format_t; |
Rohit Grover |
106:a20be740075d | 292 | |
rgrover1 | 144:c025c8839682 | 293 | /** |
rgrover1 | 249:0aa24096bec1 | 294 | * @brief Creates a new GattCharacteristic using the specified 16-bit |
rgrover1 | 249:0aa24096bec1 | 295 | * UUID, value length, and properties |
rgrover1 | 249:0aa24096bec1 | 296 | * |
rgrover1 | 249:0aa24096bec1 | 297 | * @note The UUID value must be unique in the service and is normally >1 |
rgrover1 | 249:0aa24096bec1 | 298 | * |
rgrover1 | 249:0aa24096bec1 | 299 | * @param[in] uuid |
rgrover1 | 249:0aa24096bec1 | 300 | * The UUID to use for this characteristic |
rgrover1 | 249:0aa24096bec1 | 301 | * @param[in] valuePtr |
rgrover1 | 249:0aa24096bec1 | 302 | * The memory holding the initial value. The value is copied |
rgrover1 | 249:0aa24096bec1 | 303 | * into the stack when the enclosing service is added; and |
rgrover1 | 249:0aa24096bec1 | 304 | * thereafter maintained internally by the stack. |
rgrover1 | 249:0aa24096bec1 | 305 | * @param[in] initialLen |
rgrover1 | 249:0aa24096bec1 | 306 | * The min length in bytes of this characteristic's value |
rgrover1 | 249:0aa24096bec1 | 307 | * @param[in] maxLen |
rgrover1 | 249:0aa24096bec1 | 308 | * The max length in bytes of this characteristic's value |
rgrover1 | 249:0aa24096bec1 | 309 | * @param[in] props |
rgrover1 | 249:0aa24096bec1 | 310 | * The 8-bit bit field containing the characteristic's properties |
rgrover1 | 249:0aa24096bec1 | 311 | * @param[in] descriptors |
rgrover1 | 249:0aa24096bec1 | 312 | * A pointer to an array of descriptors to be included within this characteristic |
rgrover1 | 249:0aa24096bec1 | 313 | * @param[in] numDescriptors |
rgrover1 | 249:0aa24096bec1 | 314 | * The number of descriptors |
rgrover1 | 251:5d9118449482 | 315 | * @param[in] writeAuthorizationIn |
rgrover1 | 251:5d9118449482 | 316 | * Do the attribute(s) of this characteristic have write |
rgrover1 | 251:5d9118449482 | 317 | * authorization enabled? if so, Write Authorization will be |
rgrover1 | 251:5d9118449482 | 318 | * requested from the application on every write request |
rgrover1 | 251:5d9118449482 | 319 | * operation (but not write command). |
rgrover1 | 249:0aa24096bec1 | 320 | * |
rgrover1 | 249:0aa24096bec1 | 321 | * @NOTE: If valuePtr == NULL, initialLength == 0, and properties == READ |
rgrover1 | 249:0aa24096bec1 | 322 | * for the value attribute of a characteristic, then that particular |
rgrover1 | 249:0aa24096bec1 | 323 | * characteristic may be considered optional and dropped while |
rgrover1 | 249:0aa24096bec1 | 324 | * instantiating the service with the underlying BLE stack. |
rgrover1 | 249:0aa24096bec1 | 325 | */ |
rgrover1 | 251:5d9118449482 | 326 | GattCharacteristic(const UUID &uuid, |
rgrover1 | 251:5d9118449482 | 327 | uint8_t *valuePtr = NULL, |
rgrover1 | 251:5d9118449482 | 328 | uint16_t initialLen = 0, |
rgrover1 | 251:5d9118449482 | 329 | uint16_t maxLen = 0, |
rgrover1 | 251:5d9118449482 | 330 | uint8_t props = BLE_GATT_CHAR_PROPERTIES_NONE, |
rgrover1 | 251:5d9118449482 | 331 | GattAttribute *descriptors[] = NULL, |
rgrover1 | 251:5d9118449482 | 332 | unsigned numDescriptors = 0) : |
rgrover1 | 251:5d9118449482 | 333 | _valueAttribute(uuid, valuePtr, initialLen, maxLen), |
rgrover1 | 251:5d9118449482 | 334 | _properties(props), |
rgrover1 | 251:5d9118449482 | 335 | _descriptors(descriptors), |
rgrover1 | 251:5d9118449482 | 336 | _descriptorCount(numDescriptors), |
rgrover1 | 255:097be53aea02 | 337 | enabledReadAuthorization(false), |
rgrover1 | 254:69d049317cae | 338 | enabledWriteAuthorization(false), |
rgrover1 | 255:097be53aea02 | 339 | readAuthorizationCallback(), |
rgrover1 | 251:5d9118449482 | 340 | writeAuthorizationCallback() { |
rgrover1 | 251:5d9118449482 | 341 | /* empty */ |
Rohit Grover |
106:a20be740075d | 342 | } |
Rohit Grover |
106:a20be740075d | 343 | |
rgrover1 | 255:097be53aea02 | 344 | /** |
rgrover1 | 255:097be53aea02 | 345 | * Authorization. |
rgrover1 | 255:097be53aea02 | 346 | */ |
Rohit Grover |
106:a20be740075d | 347 | public: |
rgrover1 | 251:5d9118449482 | 348 | void setWriteAuthorizationCallback(void (*callback)(GattCharacteristicWriteAuthCBParams *)) { |
rgrover1 | 251:5d9118449482 | 349 | writeAuthorizationCallback.attach(callback); |
rgrover1 | 254:69d049317cae | 350 | enabledWriteAuthorization = true; |
rgrover1 | 251:5d9118449482 | 351 | } |
rgrover1 | 251:5d9118449482 | 352 | template <typename T> |
rgrover1 | 251:5d9118449482 | 353 | void setWriteAuthorizationCallback(T *object, void (T::*member)(GattCharacteristicWriteAuthCBParams *)) { |
rgrover1 | 251:5d9118449482 | 354 | writeAuthorizationCallback.attach(object, member); |
rgrover1 | 254:69d049317cae | 355 | enabledWriteAuthorization = true; |
rgrover1 | 251:5d9118449482 | 356 | } |
rgrover1 | 255:097be53aea02 | 357 | void setReadAuthorizationCallback(void (*callback)(GattCharacteristicReadAuthCBParams *)) { |
rgrover1 | 255:097be53aea02 | 358 | readAuthorizationCallback.attach(callback); |
rgrover1 | 255:097be53aea02 | 359 | enabledReadAuthorization = true; |
rgrover1 | 255:097be53aea02 | 360 | } |
rgrover1 | 255:097be53aea02 | 361 | template <typename T> |
rgrover1 | 255:097be53aea02 | 362 | void setReadAuthorizationCallback(T *object, void (T::*member)(GattCharacteristicReadAuthCBParams *)) { |
rgrover1 | 255:097be53aea02 | 363 | readAuthorizationCallback.attach(object, member); |
rgrover1 | 255:097be53aea02 | 364 | enabledReadAuthorization = true; |
rgrover1 | 255:097be53aea02 | 365 | } |
rgrover1 | 251:5d9118449482 | 366 | |
rgrover1 | 251:5d9118449482 | 367 | /** |
rgrover1 | 251:5d9118449482 | 368 | * Helper function meant to be called from the guts of the BLE stack to |
rgrover1 | 251:5d9118449482 | 369 | * determine the authorization reply for a write request. |
rgrover1 | 251:5d9118449482 | 370 | * @param params to capture the context of the write-auth request; and also contains an out-parameter for reply. |
rgrover1 | 251:5d9118449482 | 371 | * @return true if the write is authorized to proceed. |
rgrover1 | 251:5d9118449482 | 372 | */ |
rgrover1 | 251:5d9118449482 | 373 | bool authorizeWrite(GattCharacteristicWriteAuthCBParams *params) { |
rgrover1 | 254:69d049317cae | 374 | if (!isWriteAuthorizationEnabled()) { |
rgrover1 | 254:69d049317cae | 375 | return true; |
rgrover1 | 254:69d049317cae | 376 | } |
rgrover1 | 254:69d049317cae | 377 | |
rgrover1 | 251:5d9118449482 | 378 | params->authorizationReply = true; /* initialized to true by default */ |
rgrover1 | 251:5d9118449482 | 379 | writeAuthorizationCallback.call(params); |
rgrover1 | 251:5d9118449482 | 380 | return params->authorizationReply; |
rgrover1 | 251:5d9118449482 | 381 | } |
rgrover1 | 251:5d9118449482 | 382 | |
rgrover1 | 255:097be53aea02 | 383 | /** |
rgrover1 | 255:097be53aea02 | 384 | * Helper function meant to be called from the guts of the BLE stack to |
rgrover1 | 255:097be53aea02 | 385 | * determine the authorization reply for a read request. |
rgrover1 | 255:097be53aea02 | 386 | * @param params to capture the context of the read-auth request; and also contains an out-parameter for reply. |
rgrover1 | 255:097be53aea02 | 387 | * @return true if the read is authorized to proceed. |
rgrover1 | 255:097be53aea02 | 388 | */ |
rgrover1 | 255:097be53aea02 | 389 | bool authorizeRead(GattCharacteristicReadAuthCBParams *params) { |
rgrover1 | 255:097be53aea02 | 390 | if (!isReadAuthorizationEnabled()) { |
rgrover1 | 255:097be53aea02 | 391 | return true; |
rgrover1 | 255:097be53aea02 | 392 | } |
rgrover1 | 255:097be53aea02 | 393 | |
rgrover1 | 255:097be53aea02 | 394 | params->authorizationReply = true; /* initialized to true by default */ |
rgrover1 | 255:097be53aea02 | 395 | readAuthorizationCallback.call(params); |
rgrover1 | 255:097be53aea02 | 396 | return params->authorizationReply; |
rgrover1 | 255:097be53aea02 | 397 | } |
rgrover1 | 255:097be53aea02 | 398 | |
rgrover1 | 255:097be53aea02 | 399 | /* accessors */ |
rgrover1 | 255:097be53aea02 | 400 | public: |
rgrover1 | 255:097be53aea02 | 401 | GattAttribute& getValueAttribute() {return _valueAttribute; } |
rgrover1 | 255:097be53aea02 | 402 | const GattAttribute& getValueAttribute() const {return _valueAttribute; } |
rgrover1 | 251:5d9118449482 | 403 | GattAttribute::Handle_t getValueHandle(void) const {return getValueAttribute().getHandle();} |
rgrover1 | 255:097be53aea02 | 404 | uint8_t getProperties(void) const {return _properties; } |
rgrover1 | 255:097be53aea02 | 405 | uint8_t getDescriptorCount(void) const {return _descriptorCount; } |
rgrover1 | 255:097be53aea02 | 406 | bool isReadAuthorizationEnabled() const {return enabledReadAuthorization; } |
rgrover1 | 254:69d049317cae | 407 | bool isWriteAuthorizationEnabled() const {return enabledWriteAuthorization; } |
rgrover1 | 144:c025c8839682 | 408 | |
carlescufi | 114:f1ede142a78f | 409 | GattAttribute *getDescriptor(uint8_t index) { |
carlescufi | 114:f1ede142a78f | 410 | if (index >= _descriptorCount) { |
carlescufi | 114:f1ede142a78f | 411 | return NULL; |
carlescufi | 114:f1ede142a78f | 412 | } |
carlescufi | 114:f1ede142a78f | 413 | |
carlescufi | 114:f1ede142a78f | 414 | return _descriptors[index]; |
carlescufi | 114:f1ede142a78f | 415 | } |
carlescufi | 112:64c88ad45610 | 416 | |
Rohit Grover |
106:a20be740075d | 417 | private: |
rgrover1 | 144:c025c8839682 | 418 | GattAttribute _valueAttribute; |
rgrover1 | 144:c025c8839682 | 419 | uint8_t _properties; |
rgrover1 | 144:c025c8839682 | 420 | GattAttribute **_descriptors; |
rgrover1 | 144:c025c8839682 | 421 | uint8_t _descriptorCount; |
rgrover1 | 255:097be53aea02 | 422 | |
rgrover1 | 255:097be53aea02 | 423 | bool enabledReadAuthorization; |
rgrover1 | 254:69d049317cae | 424 | bool enabledWriteAuthorization; |
rgrover1 | 255:097be53aea02 | 425 | FunctionPointerWithContext<GattCharacteristicReadAuthCBParams *> readAuthorizationCallback; |
rgrover1 | 251:5d9118449482 | 426 | FunctionPointerWithContext<GattCharacteristicWriteAuthCBParams *> writeAuthorizationCallback; |
rgrover1 | 144:c025c8839682 | 427 | |
rgrover1 | 144:c025c8839682 | 428 | private: |
rgrover1 | 144:c025c8839682 | 429 | /* disallow copy and assignment */ |
rgrover1 | 144:c025c8839682 | 430 | GattCharacteristic(const GattCharacteristic &); |
rgrover1 | 144:c025c8839682 | 431 | GattCharacteristic& operator=(const GattCharacteristic &); |
Rohit Grover |
106:a20be740075d | 432 | }; |
Rohit Grover |
106:a20be740075d | 433 | |
rgrover1 | 144:c025c8839682 | 434 | #endif // ifndef __GATT_CHARACTERISTIC_H__ |