my version with changed conversion between duration units

Fork of BLE_API by Bluetooth Low Energy

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers GattCharacteristic.h Source File

GattCharacteristic.h

00001 /* mbed Microcontroller Library
00002  * Copyright (c) 2006-2013 ARM Limited
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 #ifndef __GATT_CHARACTERISTIC_H__
00018 #define __GATT_CHARACTERISTIC_H__
00019 
00020 #include "Gap.h"
00021 #include "SecurityManager.h"
00022 #include "GattAttribute.h"
00023 #include "GattCallbackParamTypes.h"
00024 #include "FunctionPointerWithContext.h"
00025 
00026 class GattCharacteristic {
00027 public:
00028     enum {
00029         UUID_BATTERY_LEVEL_STATE_CHAR                     = 0x2A1B,
00030         UUID_BATTERY_POWER_STATE_CHAR                     = 0x2A1A,
00031         UUID_REMOVABLE_CHAR                               = 0x2A3A,
00032         UUID_SERVICE_REQUIRED_CHAR                        = 0x2A3B,
00033         UUID_ALERT_CATEGORY_ID_CHAR                       = 0x2A43,
00034         UUID_ALERT_CATEGORY_ID_BIT_MASK_CHAR              = 0x2A42,
00035         UUID_ALERT_LEVEL_CHAR                             = 0x2A06,
00036         UUID_ALERT_NOTIFICATION_CONTROL_POINT_CHAR        = 0x2A44,
00037         UUID_ALERT_STATUS_CHAR                            = 0x2A3F,
00038         UUID_BATTERY_LEVEL_CHAR                           = 0x2A19,
00039         UUID_BLOOD_PRESSURE_FEATURE_CHAR                  = 0x2A49,
00040         UUID_BLOOD_PRESSURE_MEASUREMENT_CHAR              = 0x2A35,
00041         UUID_BODY_SENSOR_LOCATION_CHAR                    = 0x2A38,
00042         UUID_BOOT_KEYBOARD_INPUT_REPORT_CHAR              = 0x2A22,
00043         UUID_BOOT_KEYBOARD_OUTPUT_REPORT_CHAR             = 0x2A32,
00044         UUID_BOOT_MOUSE_INPUT_REPORT_CHAR                 = 0x2A33,
00045         UUID_CURRENT_TIME_CHAR                            = 0x2A2B,
00046         UUID_DATE_TIME_CHAR                               = 0x2A08,
00047         UUID_DAY_DATE_TIME_CHAR                           = 0x2A0A,
00048         UUID_DAY_OF_WEEK_CHAR                             = 0x2A09,
00049         UUID_DST_OFFSET_CHAR                              = 0x2A0D,
00050         UUID_EXACT_TIME_256_CHAR                          = 0x2A0C,
00051         UUID_FIRMWARE_REVISION_STRING_CHAR                = 0x2A26,
00052         UUID_GLUCOSE_FEATURE_CHAR                         = 0x2A51,
00053         UUID_GLUCOSE_MEASUREMENT_CHAR                     = 0x2A18,
00054         UUID_GLUCOSE_MEASUREMENT_CONTEXT_CHAR             = 0x2A34,
00055         UUID_HARDWARE_REVISION_STRING_CHAR                = 0x2A27,
00056         UUID_HEART_RATE_CONTROL_POINT_CHAR                = 0x2A39,
00057         UUID_HEART_RATE_MEASUREMENT_CHAR                  = 0x2A37,
00058         UUID_HID_CONTROL_POINT_CHAR                       = 0x2A4C,
00059         UUID_HID_INFORMATION_CHAR                         = 0x2A4A,
00060         UUID_IEEE_REGULATORY_CERTIFICATION_DATA_LIST_CHAR = 0x2A2A,
00061         UUID_INTERMEDIATE_CUFF_PRESSURE_CHAR              = 0x2A36,
00062         UUID_INTERMEDIATE_TEMPERATURE_CHAR                = 0x2A1E,
00063         UUID_LOCAL_TIME_INFORMATION_CHAR                  = 0x2A0F,
00064         UUID_MANUFACTURER_NAME_STRING_CHAR                = 0x2A29,
00065         UUID_MEASUREMENT_INTERVAL_CHAR                    = 0x2A21,
00066         UUID_MODEL_NUMBER_STRING_CHAR                     = 0x2A24,
00067         UUID_UNREAD_ALERT_CHAR                            = 0x2A45,
00068         UUID_NEW_ALERT_CHAR                               = 0x2A46,
00069         UUID_PNP_ID_CHAR                                  = 0x2A50,
00070         UUID_PROTOCOL_MODE_CHAR                           = 0x2A4E,
00071         UUID_RECORD_ACCESS_CONTROL_POINT_CHAR             = 0x2A52,
00072         UUID_REFERENCE_TIME_INFORMATION_CHAR              = 0x2A14,
00073         UUID_REPORT_CHAR                                  = 0x2A4D,
00074         UUID_REPORT_MAP_CHAR                              = 0x2A4B,
00075         UUID_RINGER_CONTROL_POINT_CHAR                    = 0x2A40,
00076         UUID_RINGER_SETTING_CHAR                          = 0x2A41,
00077         UUID_SCAN_INTERVAL_WINDOW_CHAR                    = 0x2A4F,
00078         UUID_SCAN_REFRESH_CHAR                            = 0x2A31,
00079         UUID_SERIAL_NUMBER_STRING_CHAR                    = 0x2A25,
00080         UUID_SOFTWARE_REVISION_STRING_CHAR                = 0x2A28,
00081         UUID_SUPPORTED_NEW_ALERT_CATEGORY_CHAR            = 0x2A47,
00082         UUID_SUPPORTED_UNREAD_ALERT_CATEGORY_CHAR         = 0x2A48,
00083         UUID_SYSTEM_ID_CHAR                               = 0x2A23,
00084         UUID_TEMPERATURE_MEASUREMENT_CHAR                 = 0x2A1C,
00085         UUID_TEMPERATURE_TYPE_CHAR                        = 0x2A1D,
00086         UUID_TIME_ACCURACY_CHAR                           = 0x2A12,
00087         UUID_TIME_SOURCE_CHAR                             = 0x2A13,
00088         UUID_TIME_UPDATE_CONTROL_POINT_CHAR               = 0x2A16,
00089         UUID_TIME_UPDATE_STATE_CHAR                       = 0x2A17,
00090         UUID_TIME_WITH_DST_CHAR                           = 0x2A11,
00091         UUID_TIME_ZONE_CHAR                               = 0x2A0E,
00092         UUID_TX_POWER_LEVEL_CHAR                          = 0x2A07,
00093         UUID_CSC_FEATURE_CHAR                             = 0x2A5C,
00094         UUID_CSC_MEASUREMENT_CHAR                         = 0x2A5B,
00095         UUID_RSC_FEATURE_CHAR                             = 0x2A54,
00096         UUID_RSC_MEASUREMENT_CHAR                         = 0x2A53,
00097     };
00098 
00099     /**************************************************************************/
00100     /*!
00101         \brief  Standard GATT characteristic presentation format unit types.
00102                 These unit types are used to describe what the raw numeric
00103                 data in a characteristic actually represents.
00104 
00105         \note   See https://developer.bluetooth.org/gatt/units/Pages/default.aspx
00106     */
00107     /**************************************************************************/
00108     enum {
00109         BLE_GATT_UNIT_NONE                                                   = 0x2700,      /**< No specified unit type */
00110         BLE_GATT_UNIT_LENGTH_METRE                                           = 0x2701,      /**< Length, Metre */
00111         BLE_GATT_UNIT_MASS_KILOGRAM                                          = 0x2702,      /**< Mass, Kilogram */
00112         BLE_GATT_UNIT_TIME_SECOND                                            = 0x2703,      /**< Time, Second */
00113         BLE_GATT_UNIT_ELECTRIC_CURRENT_AMPERE                                = 0x2704,      /**< Electric Current, Ampere */
00114         BLE_GATT_UNIT_THERMODYNAMIC_TEMPERATURE_KELVIN                       = 0x2705,      /**< Thermodynamic Temperature, Kelvin */
00115         BLE_GATT_UNIT_AMOUNT_OF_SUBSTANCE_MOLE                               = 0x2706,      /**< Amount of Substance, Mole */
00116         BLE_GATT_UNIT_LUMINOUS_INTENSITY_CANDELA                             = 0x2707,      /**< Luminous Intensity, Candela */
00117         BLE_GATT_UNIT_AREA_SQUARE_METRES                                     = 0x2710,      /**< Area, Square Metres */
00118         BLE_GATT_UNIT_VOLUME_CUBIC_METRES                                    = 0x2711,      /**< Volume, Cubic Metres*/
00119         BLE_GATT_UNIT_VELOCITY_METRES_PER_SECOND                             = 0x2712,      /**< Velocity, Metres per Second*/
00120         BLE_GATT_UNIT_ACCELERATION_METRES_PER_SECOND_SQUARED                 = 0x2713,      /**< Acceleration, Metres per Second Squared */
00121         BLE_GATT_UNIT_WAVENUMBER_RECIPROCAL_METRE                            = 0x2714,      /**< Wave Number Reciprocal, Metre */
00122         BLE_GATT_UNIT_DENSITY_KILOGRAM_PER_CUBIC_METRE                       = 0x2715,      /**< Density, Kilogram per Cubic Metre */
00123         BLE_GATT_UNIT_SURFACE_DENSITY_KILOGRAM_PER_SQUARE_METRE              = 0x2716,      /**<  */
00124         BLE_GATT_UNIT_SPECIFIC_VOLUME_CUBIC_METRE_PER_KILOGRAM               = 0x2717,      /**<  */
00125         BLE_GATT_UNIT_CURRENT_DENSITY_AMPERE_PER_SQUARE_METRE                = 0x2718,      /**<  */
00126         BLE_GATT_UNIT_MAGNETIC_FIELD_STRENGTH_AMPERE_PER_METRE               = 0x2719,      /**< Magnetic Field Strength, Ampere per Metre */
00127         BLE_GATT_UNIT_AMOUNT_CONCENTRATION_MOLE_PER_CUBIC_METRE              = 0x271A,      /**<  */
00128         BLE_GATT_UNIT_MASS_CONCENTRATION_KILOGRAM_PER_CUBIC_METRE            = 0x271B,      /**<  */
00129         BLE_GATT_UNIT_LUMINANCE_CANDELA_PER_SQUARE_METRE                     = 0x271C,      /**<  */
00130         BLE_GATT_UNIT_REFRACTIVE_INDEX                                       = 0x271D,      /**<  */
00131         BLE_GATT_UNIT_RELATIVE_PERMEABILITY                                  = 0x271E,      /**<  */
00132         BLE_GATT_UNIT_PLANE_ANGLE_RADIAN                                     = 0x2720,      /**<  */
00133         BLE_GATT_UNIT_SOLID_ANGLE_STERADIAN                                  = 0x2721,      /**<  */
00134         BLE_GATT_UNIT_FREQUENCY_HERTZ                                        = 0x2722,      /**< Frequency, Hertz */
00135         BLE_GATT_UNIT_FORCE_NEWTON                                           = 0x2723,      /**< Force, Newton */
00136         BLE_GATT_UNIT_PRESSURE_PASCAL                                        = 0x2724,      /**< Pressure, Pascal */
00137         BLE_GATT_UNIT_ENERGY_JOULE                                           = 0x2725,      /**< Energy, Joule */
00138         BLE_GATT_UNIT_POWER_WATT                                             = 0x2726,      /**< Power, Watt */
00139         BLE_GATT_UNIT_ELECTRIC_CHARGE_COULOMB                                = 0x2727,      /**< Electrical Charge, Coulomb */
00140         BLE_GATT_UNIT_ELECTRIC_POTENTIAL_DIFFERENCE_VOLT                     = 0x2728,      /**< Electrical Potential Difference, Voltage */
00141         BLE_GATT_UNIT_CAPACITANCE_FARAD                                      = 0x2729,      /**<  */
00142         BLE_GATT_UNIT_ELECTRIC_RESISTANCE_OHM                                = 0x272A,      /**<  */
00143         BLE_GATT_UNIT_ELECTRIC_CONDUCTANCE_SIEMENS                           = 0x272B,      /**<  */
00144         BLE_GATT_UNIT_MAGNETIC_FLEX_WEBER                                    = 0x272C,      /**<  */
00145         BLE_GATT_UNIT_MAGNETIC_FLEX_DENSITY_TESLA                            = 0x272D,      /**<  */
00146         BLE_GATT_UNIT_INDUCTANCE_HENRY                                       = 0x272E,      /**<  */
00147         BLE_GATT_UNIT_THERMODYNAMIC_TEMPERATURE_DEGREE_CELSIUS               = 0x272F,      /**<  */
00148         BLE_GATT_UNIT_LUMINOUS_FLUX_LUMEN                                    = 0x2730,      /**<  */
00149         BLE_GATT_UNIT_ILLUMINANCE_LUX                                        = 0x2731,      /**<  */
00150         BLE_GATT_UNIT_ACTIVITY_REFERRED_TO_A_RADIONUCLIDE_BECQUEREL          = 0x2732,      /**<  */
00151         BLE_GATT_UNIT_ABSORBED_DOSE_GRAY                                     = 0x2733,      /**<  */
00152         BLE_GATT_UNIT_DOSE_EQUIVALENT_SIEVERT                                = 0x2734,      /**<  */
00153         BLE_GATT_UNIT_CATALYTIC_ACTIVITY_KATAL                               = 0x2735,      /**<  */
00154         BLE_GATT_UNIT_DYNAMIC_VISCOSITY_PASCAL_SECOND                        = 0x2740,      /**<  */
00155         BLE_GATT_UNIT_MOMENT_OF_FORCE_NEWTON_METRE                           = 0x2741,      /**<  */
00156         BLE_GATT_UNIT_SURFACE_TENSION_NEWTON_PER_METRE                       = 0x2742,      /**<  */
00157         BLE_GATT_UNIT_ANGULAR_VELOCITY_RADIAN_PER_SECOND                     = 0x2743,      /**<  */
00158         BLE_GATT_UNIT_ANGULAR_ACCELERATION_RADIAN_PER_SECOND_SQUARED         = 0x2744,      /**<  */
00159         BLE_GATT_UNIT_HEAT_FLUX_DENSITY_WATT_PER_SQUARE_METRE                = 0x2745,      /**<  */
00160         BLE_GATT_UNIT_HEAT_CAPACITY_JOULE_PER_KELVIN                         = 0x2746,      /**<  */
00161         BLE_GATT_UNIT_SPECIFIC_HEAT_CAPACITY_JOULE_PER_KILOGRAM_KELVIN       = 0x2747,      /**<  */
00162         BLE_GATT_UNIT_SPECIFIC_ENERGY_JOULE_PER_KILOGRAM                     = 0x2748,      /**<  */
00163         BLE_GATT_UNIT_THERMAL_CONDUCTIVITY_WATT_PER_METRE_KELVIN             = 0x2749,      /**<  */
00164         BLE_GATT_UNIT_ENERGY_DENSITY_JOULE_PER_CUBIC_METRE                   = 0x274A,      /**<  */
00165         BLE_GATT_UNIT_ELECTRIC_FIELD_STRENGTH_VOLT_PER_METRE                 = 0x274B,      /**<  */
00166         BLE_GATT_UNIT_ELECTRIC_CHARGE_DENSITY_COULOMB_PER_CUBIC_METRE        = 0x274C,      /**<  */
00167         BLE_GATT_UNIT_SURFACE_CHARGE_DENSITY_COULOMB_PER_SQUARE_METRE        = 0x274D,      /**<  */
00168         BLE_GATT_UNIT_ELECTRIC_FLUX_DENSITY_COULOMB_PER_SQUARE_METRE         = 0x274E,      /**<  */
00169         BLE_GATT_UNIT_PERMITTIVITY_FARAD_PER_METRE                           = 0x274F,      /**<  */
00170         BLE_GATT_UNIT_PERMEABILITY_HENRY_PER_METRE                           = 0x2750,      /**<  */
00171         BLE_GATT_UNIT_MOLAR_ENERGY_JOULE_PER_MOLE                            = 0x2751,      /**<  */
00172         BLE_GATT_UNIT_MOLAR_ENTROPY_JOULE_PER_MOLE_KELVIN                    = 0x2752,      /**<  */
00173         BLE_GATT_UNIT_EXPOSURE_COULOMB_PER_KILOGRAM                          = 0x2753,      /**<  */
00174         BLE_GATT_UNIT_ABSORBED_DOSE_RATE_GRAY_PER_SECOND                     = 0x2754,      /**<  */
00175         BLE_GATT_UNIT_RADIANT_INTENSITY_WATT_PER_STERADIAN                   = 0x2755,      /**<  */
00176         BLE_GATT_UNIT_RADIANCE_WATT_PER_SQUARE_METRE_STERADIAN               = 0x2756,      /**<  */
00177         BLE_GATT_UNIT_CATALYTIC_ACTIVITY_CONCENTRATION_KATAL_PER_CUBIC_METRE = 0x2757,      /**<  */
00178         BLE_GATT_UNIT_TIME_MINUTE                                            = 0x2760,      /**< Time, Minute */
00179         BLE_GATT_UNIT_TIME_HOUR                                              = 0x2761,      /**< Time, Hour */
00180         BLE_GATT_UNIT_TIME_DAY                                               = 0x2762,      /**< Time, Day */
00181         BLE_GATT_UNIT_PLANE_ANGLE_DEGREE                                     = 0x2763,      /**<  */
00182         BLE_GATT_UNIT_PLANE_ANGLE_MINUTE                                     = 0x2764,      /**<  */
00183         BLE_GATT_UNIT_PLANE_ANGLE_SECOND                                     = 0x2765,      /**<  */
00184         BLE_GATT_UNIT_AREA_HECTARE                                           = 0x2766,      /**<  */
00185         BLE_GATT_UNIT_VOLUME_LITRE                                           = 0x2767,      /**<  */
00186         BLE_GATT_UNIT_MASS_TONNE                                             = 0x2768,      /**<  */
00187         BLE_GATT_UNIT_PRESSURE_BAR                                           = 0x2780,      /**< Pressure, Bar */
00188         BLE_GATT_UNIT_PRESSURE_MILLIMETRE_OF_MERCURY                         = 0x2781,      /**< Pressure, Millimetre of Mercury */
00189         BLE_GATT_UNIT_LENGTH_ANGSTROM                                        = 0x2782,      /**<  */
00190         BLE_GATT_UNIT_LENGTH_NAUTICAL_MILE                                   = 0x2783,      /**<  */
00191         BLE_GATT_UNIT_AREA_BARN                                              = 0x2784,      /**<  */
00192         BLE_GATT_UNIT_VELOCITY_KNOT                                          = 0x2785,      /**<  */
00193         BLE_GATT_UNIT_LOGARITHMIC_RADIO_QUANTITY_NEPER                       = 0x2786,      /**<  */
00194         BLE_GATT_UNIT_LOGARITHMIC_RADIO_QUANTITY_BEL                         = 0x2787,      /**<  */
00195         BLE_GATT_UNIT_LENGTH_YARD                                            = 0x27A0,      /**< Length, Yard */
00196         BLE_GATT_UNIT_LENGTH_PARSEC                                          = 0x27A1,      /**< Length, Parsec */
00197         BLE_GATT_UNIT_LENGTH_INCH                                            = 0x27A2,      /**< Length, Inch */
00198         BLE_GATT_UNIT_LENGTH_FOOT                                            = 0x27A3,      /**< Length, Foot */
00199         BLE_GATT_UNIT_LENGTH_MILE                                            = 0x27A4,      /**< Length, Mile */
00200         BLE_GATT_UNIT_PRESSURE_POUND_FORCE_PER_SQUARE_INCH                   = 0x27A5,      /**<  */
00201         BLE_GATT_UNIT_VELOCITY_KILOMETRE_PER_HOUR                            = 0x27A6,      /**< Velocity, Kilometre per Hour */
00202         BLE_GATT_UNIT_VELOCITY_MILE_PER_HOUR                                 = 0x27A7,      /**< Velocity, Mile per Hour */
00203         BLE_GATT_UNIT_ANGULAR_VELOCITY_REVOLUTION_PER_MINUTE                 = 0x27A8,      /**< Angular Velocity, Revolution per Minute */
00204         BLE_GATT_UNIT_ENERGY_GRAM_CALORIE                                    = 0x27A9,      /**< Energy, Gram Calorie */
00205         BLE_GATT_UNIT_ENERGY_KILOGRAM_CALORIE                                = 0x27AA,      /**< Energy, Kilogram Calorie */
00206         BLE_GATT_UNIT_ENERGY_KILOWATT_HOUR                                   = 0x27AB,      /**< Energy, Killowatt Hour */
00207         BLE_GATT_UNIT_THERMODYNAMIC_TEMPERATURE_DEGREE_FAHRENHEIT            = 0x27AC,      /**<  */
00208         BLE_GATT_UNIT_PERCENTAGE                                             = 0x27AD,      /**< Percentage */
00209         BLE_GATT_UNIT_PER_MILLE                                              = 0x27AE,      /**<  */
00210         BLE_GATT_UNIT_PERIOD_BEATS_PER_MINUTE                                = 0x27AF,      /**<  */
00211         BLE_GATT_UNIT_ELECTRIC_CHARGE_AMPERE_HOURS                           = 0x27B0,      /**<  */
00212         BLE_GATT_UNIT_MASS_DENSITY_MILLIGRAM_PER_DECILITRE                   = 0x27B1,      /**<  */
00213         BLE_GATT_UNIT_MASS_DENSITY_MILLIMOLE_PER_LITRE                       = 0x27B2,      /**<  */
00214         BLE_GATT_UNIT_TIME_YEAR                                              = 0x27B3,      /**< Time, Year */
00215         BLE_GATT_UNIT_TIME_MONTH                                             = 0x27B4,      /**< Time, Month */
00216         BLE_GATT_UNIT_CONCENTRATION_COUNT_PER_CUBIC_METRE                    = 0x27B5,      /**<  */
00217         BLE_GATT_UNIT_IRRADIANCE_WATT_PER_SQUARE_METRE                       = 0x27B6       /**<  */
00218     };
00219 
00220     /**************************************************************************/
00221     /*!
00222         \brief  Standard GATT number types
00223 
00224         \note   See Bluetooth Specification 4.0 (Vol. 3), Part G, Section 3.3.3.5.2
00225         \note   See http://developer.bluetooth.org/gatt/descriptors/Pages/DescriptorViewer.aspx?u=org.bluetooth.descriptor.gatt.characteristic_presentation_format.xml
00226     */
00227     /**************************************************************************/
00228     enum {
00229         BLE_GATT_FORMAT_RFU     = 0x00, /**< Reserved For Future Use. */
00230         BLE_GATT_FORMAT_BOOLEAN = 0x01, /**< Boolean. */
00231         BLE_GATT_FORMAT_2BIT    = 0x02, /**< Unsigned 2-bit integer. */
00232         BLE_GATT_FORMAT_NIBBLE  = 0x03, /**< Unsigned 4-bit integer. */
00233         BLE_GATT_FORMAT_UINT8   = 0x04, /**< Unsigned 8-bit integer. */
00234         BLE_GATT_FORMAT_UINT12  = 0x05, /**< Unsigned 12-bit integer. */
00235         BLE_GATT_FORMAT_UINT16  = 0x06, /**< Unsigned 16-bit integer. */
00236         BLE_GATT_FORMAT_UINT24  = 0x07, /**< Unsigned 24-bit integer. */
00237         BLE_GATT_FORMAT_UINT32  = 0x08, /**< Unsigned 32-bit integer. */
00238         BLE_GATT_FORMAT_UINT48  = 0x09, /**< Unsigned 48-bit integer. */
00239         BLE_GATT_FORMAT_UINT64  = 0x0A, /**< Unsigned 64-bit integer. */
00240         BLE_GATT_FORMAT_UINT128 = 0x0B, /**< Unsigned 128-bit integer. */
00241         BLE_GATT_FORMAT_SINT8   = 0x0C, /**< Signed 2-bit integer. */
00242         BLE_GATT_FORMAT_SINT12  = 0x0D, /**< Signed 12-bit integer. */
00243         BLE_GATT_FORMAT_SINT16  = 0x0E, /**< Signed 16-bit integer. */
00244         BLE_GATT_FORMAT_SINT24  = 0x0F, /**< Signed 24-bit integer. */
00245         BLE_GATT_FORMAT_SINT32  = 0x10, /**< Signed 32-bit integer. */
00246         BLE_GATT_FORMAT_SINT48  = 0x11, /**< Signed 48-bit integer. */
00247         BLE_GATT_FORMAT_SINT64  = 0x12, /**< Signed 64-bit integer. */
00248         BLE_GATT_FORMAT_SINT128 = 0x13, /**< Signed 128-bit integer. */
00249         BLE_GATT_FORMAT_FLOAT32 = 0x14, /**< IEEE-754 32-bit floating point. */
00250         BLE_GATT_FORMAT_FLOAT64 = 0x15, /**< IEEE-754 64-bit floating point. */
00251         BLE_GATT_FORMAT_SFLOAT  = 0x16, /**< IEEE-11073 16-bit SFLOAT. */
00252         BLE_GATT_FORMAT_FLOAT   = 0x17, /**< IEEE-11073 32-bit FLOAT. */
00253         BLE_GATT_FORMAT_DUINT16 = 0x18, /**< IEEE-20601 format. */
00254         BLE_GATT_FORMAT_UTF8S   = 0x19, /**< UTF-8 string. */
00255         BLE_GATT_FORMAT_UTF16S  = 0x1A, /**< UTF-16 string. */
00256         BLE_GATT_FORMAT_STRUCT  = 0x1B  /**< Opaque Structure. */
00257     };
00258 
00259     /**************************************************************************/
00260     /*!
00261         \brief  Standard GATT characteristic properties
00262 
00263         \note   See Bluetooth Specification 4.0 (Vol. 3), Part G, Section 3.3.1.1
00264                 and Section 3.3.3.1 for Extended Properties
00265     */
00266     /**************************************************************************/
00267     enum Properties_t {
00268         BLE_GATT_CHAR_PROPERTIES_NONE                        = 0x00,
00269         BLE_GATT_CHAR_PROPERTIES_BROADCAST                   = 0x01, /**< Permits broadcasts of the Characteristic Value using Server Characteristic Configuration Descriptor. */
00270         BLE_GATT_CHAR_PROPERTIES_READ                        = 0x02, /**< Permits reads of the Characteristic Value. */
00271         BLE_GATT_CHAR_PROPERTIES_WRITE_WITHOUT_RESPONSE      = 0x04, /**< Permits writes of the Characteristic Value without response. */
00272         BLE_GATT_CHAR_PROPERTIES_WRITE                       = 0x08, /**< Permits writes of the Characteristic Value with response. */
00273         BLE_GATT_CHAR_PROPERTIES_NOTIFY                      = 0x10, /**< Permits notifications of a Characteristic Value without acknowledgment. */
00274         BLE_GATT_CHAR_PROPERTIES_INDICATE                    = 0x20, /**< Permits indications of a Characteristic Value with acknowledgment. */
00275         BLE_GATT_CHAR_PROPERTIES_AUTHENTICATED_SIGNED_WRITES = 0x40, /**< Permits signed writes to the Characteristic Value. */
00276         BLE_GATT_CHAR_PROPERTIES_EXTENDED_PROPERTIES         = 0x80  /**< Additional characteristic properties are defined in the Characteristic Extended Properties Descriptor */
00277     };
00278 
00279     /**************************************************************************/
00280     /*!
00281         \brief  GATT presentation format wrapper
00282 
00283         \note   See Bluetooth Specification 4.0 (Vol. 3), Part G, Section 3.3.3.5
00284         \note   See https://developer.bluetooth.org/gatt/descriptors/Pages/DescriptorViewer.aspx?u=org.bluetooth.descriptor.gatt.characteristic_presentation_format.xml
00285     */
00286     /**************************************************************************/
00287     struct PresentationFormat_t {
00288         uint8_t  gatt_format;    /**< Format of the value, see @ref ble_gatt_format_t. */
00289         int8_t   exponent;       /**< Exponent for integer data types. Ex. if Exponent = -3 and the char value is 3892, the actual value is 3.892 */
00290         uint16_t gatt_unit;      /**< UUID from Bluetooth Assigned Numbers, see @ref ble_gatt_unit_t. */
00291         uint8_t  gatt_namespace; /**< Namespace from Bluetooth Assigned Numbers, normally '1',  see @ref BLE_GATT_CPF_NAMESPACES. */
00292         uint16_t gatt_nsdesc;    /**< Namespace description from Bluetooth Assigned Numbers, normally '0', see @ref BLE_GATT_CPF_NAMESPACES. */
00293     };
00294 
00295     /**
00296      *  @brief  Creates a new GattCharacteristic using the specified 16-bit
00297      *          UUID, value length, and properties
00298      *
00299      *  @note   The UUID value must be unique in the service and is normally >1
00300      *
00301      *  @param[in]  uuid
00302      *              The UUID to use for this characteristic
00303      *  @param[in]  valuePtr
00304      *              The memory holding the initial value. The value is copied
00305      *              into the stack when the enclosing service is added; and
00306      *              thereafter maintained internally by the stack.
00307      *  @param[in]  initialLen
00308      *              The min length in bytes of this characteristic's value
00309      *  @param[in]  maxLen
00310      *              The max length in bytes of this characteristic's value
00311      *  @param[in]  props
00312      *              The 8-bit bit field containing the characteristic's properties
00313      *  @param[in]  descriptors
00314      *              A pointer to an array of descriptors to be included within
00315      *              this characteristic. The memory for the descriptor array is
00316      *              owned by the caller, and should remain valid at least until
00317      *              the enclosing service is added to the GATT table.
00318      *  @param[in]  numDescriptors
00319      *              The number of descriptors in the previous array.
00320      *
00321      * @NOTE: If valuePtr == NULL, initialLength == 0, and properties == READ
00322      *        for the value attribute of a characteristic, then that particular
00323      *        characteristic may be considered optional and dropped while
00324      *        instantiating the service with the underlying BLE stack.
00325      */
00326     GattCharacteristic(const UUID    &uuid,
00327                        uint8_t       *valuePtr       = NULL,
00328                        uint16_t       initialLen     = 0,
00329                        uint16_t       maxLen         = 0,
00330                        uint8_t        props          = BLE_GATT_CHAR_PROPERTIES_NONE,
00331                        GattAttribute *descriptors[]  = NULL,
00332                        unsigned       numDescriptors = 0) :
00333         _valueAttribute(uuid, valuePtr, initialLen, maxLen),
00334         _properties(props),
00335         _requiredSecurity(SecurityManager::SECURITY_MODE_ENCRYPTION_OPEN_LINK),
00336         _descriptors(descriptors),
00337         _descriptorCount(numDescriptors),
00338         enabledReadAuthorization(false),
00339         enabledWriteAuthorization(false),
00340         readAuthorizationCallback(),
00341         writeAuthorizationCallback() {
00342         /* empty */
00343     }
00344 
00345 public:
00346     /**
00347      * Setup the minimum security (mode and level) requirements for access to the characteristic's value attribute.
00348      *
00349      * @param securityMode Can be one of encryption or signing, with or without protection for MITM (man in the middle attacks).
00350      */
00351     void requireSecurity(SecurityManager::SecurityMode_t securityMode) {
00352         _requiredSecurity = securityMode;
00353     }
00354 
00355 public:
00356     /**
00357      * Authorization.
00358      */
00359     void setWriteAuthorizationCallback(void (*callback)(GattWriteAuthCallbackParams *)) {
00360         writeAuthorizationCallback.attach(callback);
00361         enabledWriteAuthorization = true;
00362     }
00363     template <typename T>
00364     void setWriteAuthorizationCallback(T *object, void (T::*member)(GattWriteAuthCallbackParams *)) {
00365         writeAuthorizationCallback.attach(object, member);
00366         enabledWriteAuthorization = true;
00367     }
00368     void setReadAuthorizationCallback(void (*callback)(GattReadAuthCallbackParams *)) {
00369         readAuthorizationCallback.attach(callback);
00370         enabledReadAuthorization = true;
00371     }
00372     template <typename T>
00373     void setReadAuthorizationCallback(T *object, void (T::*member)(GattReadAuthCallbackParams *)) {
00374         readAuthorizationCallback.attach(object, member);
00375         enabledReadAuthorization = true;
00376     }
00377 
00378     /**
00379      * Helper function meant to be called from the guts of the BLE stack to
00380      * determine the authorization reply for a write request.
00381      * @param  params to capture the context of the write-auth request; and also contains an out-parameter for reply.
00382      * @return        true if the write is authorized to proceed.
00383      */
00384     GattAuthCallbackReply_t authorizeWrite(GattWriteAuthCallbackParams *params) {
00385         if (!isWriteAuthorizationEnabled()) {
00386             return AUTH_CALLBACK_REPLY_SUCCESS;
00387         }
00388 
00389         params->authorizationReply = AUTH_CALLBACK_REPLY_SUCCESS; /* initialized to no-error by default */
00390         writeAuthorizationCallback.call(params);
00391         return params->authorizationReply;
00392     }
00393 
00394     /**
00395      * Helper function meant to be called from the guts of the BLE stack to
00396      * determine the authorization reply for a read request.
00397      * @param  params to capture the context of the read-auth request.
00398      *
00399      * @NOTE:  To authorize/deny the read the params->authorizationReply field
00400      *         should be set to true/false.
00401      *
00402      *         If the read is approved and params->data is unchanged (NULL),
00403      *         the current characteristic value will be used.
00404      *
00405      *         If the read is approved, a new value can be provided by setting
00406      *         the params->data pointer and params->len fields.
00407      *
00408      * @return        true if the read is authorized to proceed.
00409      */
00410     GattAuthCallbackReply_t authorizeRead(GattReadAuthCallbackParams *params) {
00411         if (!isReadAuthorizationEnabled()) {
00412             return AUTH_CALLBACK_REPLY_SUCCESS;
00413         }
00414 
00415         params->authorizationReply = AUTH_CALLBACK_REPLY_SUCCESS; /* initialized to no-error by default */
00416         readAuthorizationCallback.call(params);
00417         return params->authorizationReply;
00418     }
00419 
00420     /* accessors */
00421 public:
00422     GattAttribute&          getValueAttribute()                 {return _valueAttribute;                }
00423     const GattAttribute&    getValueAttribute()           const {return _valueAttribute;                }
00424     GattAttribute::Handle_t getValueHandle(void)          const {return getValueAttribute().getHandle();}
00425     uint8_t                 getProperties(void)           const {return _properties;                    }
00426     SecurityManager::SecurityMode_t getRequiredSecurity() const {return _requiredSecurity;              }
00427     uint8_t                 getDescriptorCount(void)      const {return _descriptorCount;               }
00428     bool                    isReadAuthorizationEnabled()  const {return enabledReadAuthorization;       }
00429     bool                    isWriteAuthorizationEnabled() const {return enabledWriteAuthorization;      }
00430 
00431     GattAttribute *getDescriptor(uint8_t index) {
00432         if (index >= _descriptorCount) {
00433             return NULL;
00434         }
00435 
00436         return _descriptors[index];
00437     }
00438 
00439 private:
00440     GattAttribute                     _valueAttribute;
00441     uint8_t                           _properties;
00442     SecurityManager::SecurityMode_t   _requiredSecurity;
00443     GattAttribute                   **_descriptors;
00444     uint8_t                           _descriptorCount;
00445 
00446     bool enabledReadAuthorization;
00447     bool enabledWriteAuthorization;
00448     FunctionPointerWithContext<GattReadAuthCallbackParams *>   readAuthorizationCallback;
00449     FunctionPointerWithContext<GattWriteAuthCallbackParams *>  writeAuthorizationCallback;
00450 
00451 private:
00452     /* disallow copy and assignment */
00453     GattCharacteristic(const GattCharacteristic &);
00454     GattCharacteristic& operator=(const GattCharacteristic &);
00455 };
00456 
00457 template <typename T>
00458 class ReadOnlyGattCharacteristic : public GattCharacteristic {
00459 public:
00460     ReadOnlyGattCharacteristic<T>(const UUID    &uuid,
00461                                   T             *valuePtr,
00462                                   uint8_t        additionalProperties = BLE_GATT_CHAR_PROPERTIES_NONE,
00463                                   GattAttribute *descriptors[]        = NULL,
00464                                   unsigned       numDescriptors       = 0) :
00465         GattCharacteristic(uuid, reinterpret_cast<uint8_t *>(valuePtr), sizeof(T), sizeof(T),
00466                            BLE_GATT_CHAR_PROPERTIES_READ | additionalProperties, descriptors, numDescriptors) {
00467         /* empty */
00468     }
00469 };
00470 
00471 template <typename T>
00472 class WriteOnlyGattCharacteristic : public GattCharacteristic {
00473 public:
00474     WriteOnlyGattCharacteristic<T>(const UUID     &uuid,
00475                                    T              *valuePtr,
00476                                    uint8_t        additionalProperties = BLE_GATT_CHAR_PROPERTIES_NONE,
00477                                    GattAttribute *descriptors[]        = NULL,
00478                                    unsigned       numDescriptors       = 0) :
00479         GattCharacteristic(uuid, reinterpret_cast<uint8_t *>(valuePtr), sizeof(T), sizeof(T),
00480                            BLE_GATT_CHAR_PROPERTIES_WRITE | additionalProperties, descriptors, numDescriptors) {
00481         /* empty */
00482     }
00483 };
00484 
00485 template <typename T>
00486 class ReadWriteGattCharacteristic : public GattCharacteristic {
00487 public:
00488     ReadWriteGattCharacteristic<T>(const UUID    &uuid,
00489                                    T             *valuePtr,
00490                                    uint8_t        additionalProperties = BLE_GATT_CHAR_PROPERTIES_NONE,
00491                                    GattAttribute *descriptors[]        = NULL,
00492                                    unsigned       numDescriptors       = 0) :
00493         GattCharacteristic(uuid, reinterpret_cast<uint8_t *>(valuePtr), sizeof(T), sizeof(T),
00494                            BLE_GATT_CHAR_PROPERTIES_READ | BLE_GATT_CHAR_PROPERTIES_WRITE | additionalProperties, descriptors, numDescriptors) {
00495         /* empty */
00496     }
00497 };
00498 
00499 template <typename T, unsigned NUM_ELEMENTS>
00500 class WriteOnlyArrayGattCharacteristic : public GattCharacteristic {
00501 public:
00502     WriteOnlyArrayGattCharacteristic<T, NUM_ELEMENTS>(const          UUID &uuid,
00503                                                       T              valuePtr[NUM_ELEMENTS],
00504                                                       uint8_t        additionalProperties = BLE_GATT_CHAR_PROPERTIES_NONE,
00505                                                       GattAttribute *descriptors[]        = NULL,
00506                                                       unsigned       numDescriptors       = 0) :
00507         GattCharacteristic(uuid, reinterpret_cast<uint8_t *>(valuePtr), sizeof(T) * NUM_ELEMENTS, sizeof(T) * NUM_ELEMENTS,
00508                            BLE_GATT_CHAR_PROPERTIES_WRITE | additionalProperties, descriptors, numDescriptors) {
00509         /* empty */
00510     }
00511 };
00512 
00513 template <typename T, unsigned NUM_ELEMENTS>
00514 class ReadOnlyArrayGattCharacteristic : public GattCharacteristic {
00515 public:
00516     ReadOnlyArrayGattCharacteristic<T, NUM_ELEMENTS>(const UUID    &uuid,
00517                                                      T              valuePtr[NUM_ELEMENTS],
00518                                                      uint8_t        additionalProperties = BLE_GATT_CHAR_PROPERTIES_NONE,
00519                                                      GattAttribute *descriptors[]        = NULL,
00520                                                      unsigned       numDescriptors       = 0) :
00521         GattCharacteristic(uuid, reinterpret_cast<uint8_t *>(valuePtr), sizeof(T) * NUM_ELEMENTS, sizeof(T) * NUM_ELEMENTS,
00522                            BLE_GATT_CHAR_PROPERTIES_READ | additionalProperties, descriptors, numDescriptors) {
00523         /* empty */
00524     }
00525 };
00526 
00527 template <typename T, unsigned NUM_ELEMENTS>
00528 class ReadWriteArrayGattCharacteristic : public GattCharacteristic {
00529 public:
00530     ReadWriteArrayGattCharacteristic<T, NUM_ELEMENTS>(const UUID    &uuid,
00531                                                       T              valuePtr[NUM_ELEMENTS],
00532                                                       uint8_t        additionalProperties = BLE_GATT_CHAR_PROPERTIES_NONE,
00533                                                       GattAttribute *descriptors[]        = NULL,
00534                                                       unsigned       numDescriptors       = 0) :
00535         GattCharacteristic(uuid, reinterpret_cast<uint8_t *>(valuePtr), sizeof(T) * NUM_ELEMENTS, sizeof(T) * NUM_ELEMENTS,
00536                            BLE_GATT_CHAR_PROPERTIES_READ | BLE_GATT_CHAR_PROPERTIES_WRITE | additionalProperties, descriptors, numDescriptors) {
00537         /* empty */
00538     }
00539 };
00540 
00541 #endif // ifndef __GATT_CHARACTERISTIC_H__