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