Added better radio abstraction layer, moved Gatt enums from blecommon.h to GattCharacteristic.h
This commit is contained in:
parent
552de461fb
commit
88fc64ded8
12 changed files with 770 additions and 494 deletions
|
@ -21,19 +21,225 @@
|
|||
#include "blecommon.h"
|
||||
#include "UUID.h"
|
||||
|
||||
/* ToDo: Update to use 16-bit or 128-bit UUIDs! */
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
\brief GATT characteristic
|
||||
*/
|
||||
/**************************************************************************/
|
||||
class GattCharacteristic
|
||||
{
|
||||
private:
|
||||
|
||||
public:
|
||||
GattCharacteristic(uint16_t uuid=0, uint16_t minLen=1, uint16_t maxLen=1, uint8_t properties=0);
|
||||
virtual ~GattCharacteristic(void);
|
||||
|
||||
uint16_t uuid; /* Characteristic UUID */
|
||||
uint16_t lenMin; /* Minimum length of the value */
|
||||
uint16_t lenMax; /* Maximum length of the value */
|
||||
uint8_t handle;
|
||||
uint8_t properties;
|
||||
public:
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
\brief Standard GATT characteristic presentation format unit types.
|
||||
These unit types are used to decribe what the raw numeric
|
||||
data in a characteristic actually represents.
|
||||
|
||||
\note See https://developer.bluetooth.org/gatt/units/Pages/default.aspx
|
||||
*/
|
||||
/**************************************************************************/
|
||||
typedef enum ble_gatt_unit_e
|
||||
{
|
||||
BLE_GATT_UNIT_NONE = 0x2700, /**< No specified unit type */
|
||||
BLE_GATT_UNIT_LENGTH_METRE = 0x2701, /**< Length, Metre */
|
||||
BLE_GATT_UNIT_MASS_KILOGRAM = 0x2702, /**< Mass, Kilogram */
|
||||
BLE_GATT_UNIT_TIME_SECOND = 0x2703, /**< Time, Second */
|
||||
BLE_GATT_UNIT_ELECTRIC_CURRENT_AMPERE = 0x2704, /**< Electric Current, Ampere */
|
||||
BLE_GATT_UNIT_THERMODYNAMIC_TEMPERATURE_KELVIN = 0x2705, /**< Thermodynamic Temperature, Kelvin */
|
||||
BLE_GATT_UNIT_AMOUNT_OF_SUBSTANCE_MOLE = 0x2706, /**< Amount of Substance, Mole */
|
||||
BLE_GATT_UNIT_LUMINOUS_INTENSITY_CANDELA = 0x2707, /**< Luminous Intensity, Candela */
|
||||
BLE_GATT_UNIT_AREA_SQUARE_METRES = 0x2710, /**< Area, Square Metres */
|
||||
BLE_GATT_UNIT_VOLUME_CUBIC_METRES = 0x2711, /**< Volume, Cubic Metres*/
|
||||
BLE_GATT_UNIT_VELOCITY_METRES_PER_SECOND = 0x2712, /**< Velocity, Metres per Second*/
|
||||
BLE_GATT_UNIT_ACCELERATION_METRES_PER_SECOND_SQUARED = 0x2713, /**< Acceleration, Metres per Second Squared */
|
||||
BLE_GATT_UNIT_WAVENUMBER_RECIPROCAL_METRE = 0x2714, /**< Wave Number Reciprocal, Metre */
|
||||
BLE_GATT_UNIT_DENSITY_KILOGRAM_PER_CUBIC_METRE = 0x2715, /**< Density, Kilogram per Cubic Metre */
|
||||
BLE_GATT_UNIT_SURFACE_DENSITY_KILOGRAM_PER_SQUARE_METRE = 0x2716, /**< */
|
||||
BLE_GATT_UNIT_SPECIFIC_VOLUME_CUBIC_METRE_PER_KILOGRAM = 0x2717, /**< */
|
||||
BLE_GATT_UNIT_CURRENT_DENSITY_AMPERE_PER_SQUARE_METRE = 0x2718, /**< */
|
||||
BLE_GATT_UNIT_MAGNETIC_FIELD_STRENGTH_AMPERE_PER_METRE = 0x2719, /**< Magnetic Field Strength, Ampere per Metre */
|
||||
BLE_GATT_UNIT_AMOUNT_CONCENTRATION_MOLE_PER_CUBIC_METRE = 0x271A, /**< */
|
||||
BLE_GATT_UNIT_MASS_CONCENTRATION_KILOGRAM_PER_CUBIC_METRE = 0x271B, /**< */
|
||||
BLE_GATT_UNIT_LUMINANCE_CANDELA_PER_SQUARE_METRE = 0x271C, /**< */
|
||||
BLE_GATT_UNIT_REFRACTIVE_INDEX = 0x271D, /**< */
|
||||
BLE_GATT_UNIT_RELATIVE_PERMEABILITY = 0x271E, /**< */
|
||||
BLE_GATT_UNIT_PLANE_ANGLE_RADIAN = 0x2720, /**< */
|
||||
BLE_GATT_UNIT_SOLID_ANGLE_STERADIAN = 0x2721, /**< */
|
||||
BLE_GATT_UNIT_FREQUENCY_HERTZ = 0x2722, /**< Frequency, Hertz */
|
||||
BLE_GATT_UNIT_FORCE_NEWTON = 0x2723, /**< Force, Newton */
|
||||
BLE_GATT_UNIT_PRESSURE_PASCAL = 0x2724, /**< Pressure, Pascal */
|
||||
BLE_GATT_UNIT_ENERGY_JOULE = 0x2725, /**< Energy, Joule */
|
||||
BLE_GATT_UNIT_POWER_WATT = 0x2726, /**< Power, Watt */
|
||||
BLE_GATT_UNIT_ELECTRIC_CHARGE_COULOMB = 0x2727, /**< Electrical Charge, Coulomb */
|
||||
BLE_GATT_UNIT_ELECTRIC_POTENTIAL_DIFFERENCE_VOLT = 0x2728, /**< Electrical Potential Difference, Voltage */
|
||||
BLE_GATT_UNIT_CAPACITANCE_FARAD = 0x2729, /**< */
|
||||
BLE_GATT_UNIT_ELECTRIC_RESISTANCE_OHM = 0x272A, /**< */
|
||||
BLE_GATT_UNIT_ELECTRIC_CONDUCTANCE_SIEMENS = 0x272B, /**< */
|
||||
BLE_GATT_UNIT_MAGNETIC_FLEX_WEBER = 0x272C, /**< */
|
||||
BLE_GATT_UNIT_MAGNETIC_FLEX_DENSITY_TESLA = 0x272D, /**< */
|
||||
BLE_GATT_UNIT_INDUCTANCE_HENRY = 0x272E, /**< */
|
||||
BLE_GATT_UNIT_THERMODYNAMIC_TEMPERATURE_DEGREE_CELSIUS = 0x272F, /**< */
|
||||
BLE_GATT_UNIT_LUMINOUS_FLUX_LUMEN = 0x2730, /**< */
|
||||
BLE_GATT_UNIT_ILLUMINANCE_LUX = 0x2731, /**< */
|
||||
BLE_GATT_UNIT_ACTIVITY_REFERRED_TO_A_RADIONUCLIDE_BECQUEREL = 0x2732, /**< */
|
||||
BLE_GATT_UNIT_ABSORBED_DOSE_GRAY = 0x2733, /**< */
|
||||
BLE_GATT_UNIT_DOSE_EQUIVALENT_SIEVERT = 0x2734, /**< */
|
||||
BLE_GATT_UNIT_CATALYTIC_ACTIVITY_KATAL = 0x2735, /**< */
|
||||
BLE_GATT_UNIT_DYNAMIC_VISCOSITY_PASCAL_SECOND = 0x2740, /**< */
|
||||
BLE_GATT_UNIT_MOMENT_OF_FORCE_NEWTON_METRE = 0x2741, /**< */
|
||||
BLE_GATT_UNIT_SURFACE_TENSION_NEWTON_PER_METRE = 0x2742, /**< */
|
||||
BLE_GATT_UNIT_ANGULAR_VELOCITY_RADIAN_PER_SECOND = 0x2743, /**< */
|
||||
BLE_GATT_UNIT_ANGULAR_ACCELERATION_RADIAN_PER_SECOND_SQUARED = 0x2744, /**< */
|
||||
BLE_GATT_UNIT_HEAT_FLUX_DENSITY_WATT_PER_SQUARE_METRE = 0x2745, /**< */
|
||||
BLE_GATT_UNIT_HEAT_CAPACITY_JOULE_PER_KELVIN = 0x2746, /**< */
|
||||
BLE_GATT_UNIT_SPECIFIC_HEAT_CAPACITY_JOULE_PER_KILOGRAM_KELVIN = 0x2747, /**< */
|
||||
BLE_GATT_UNIT_SPECIFIC_ENERGY_JOULE_PER_KILOGRAM = 0x2748, /**< */
|
||||
BLE_GATT_UNIT_THERMAL_CONDUCTIVITY_WATT_PER_METRE_KELVIN = 0x2749, /**< */
|
||||
BLE_GATT_UNIT_ENERGY_DENSITY_JOULE_PER_CUBIC_METRE = 0x274A, /**< */
|
||||
BLE_GATT_UNIT_ELECTRIC_FIELD_STRENGTH_VOLT_PER_METRE = 0x274B, /**< */
|
||||
BLE_GATT_UNIT_ELECTRIC_CHARGE_DENSITY_COULOMB_PER_CUBIC_METRE = 0x274C, /**< */
|
||||
BLE_GATT_UNIT_SURFACE_CHARGE_DENSITY_COULOMB_PER_SQUARE_METRE = 0x274D, /**< */
|
||||
BLE_GATT_UNIT_ELECTRIC_FLUX_DENSITY_COULOMB_PER_SQUARE_METRE = 0x274E, /**< */
|
||||
BLE_GATT_UNIT_PERMITTIVITY_FARAD_PER_METRE = 0x274F, /**< */
|
||||
BLE_GATT_UNIT_PERMEABILITY_HENRY_PER_METRE = 0x2750, /**< */
|
||||
BLE_GATT_UNIT_MOLAR_ENERGY_JOULE_PER_MOLE = 0x2751, /**< */
|
||||
BLE_GATT_UNIT_MOLAR_ENTROPY_JOULE_PER_MOLE_KELVIN = 0x2752, /**< */
|
||||
BLE_GATT_UNIT_EXPOSURE_COULOMB_PER_KILOGRAM = 0x2753, /**< */
|
||||
BLE_GATT_UNIT_ABSORBED_DOSE_RATE_GRAY_PER_SECOND = 0x2754, /**< */
|
||||
BLE_GATT_UNIT_RADIANT_INTENSITY_WATT_PER_STERADIAN = 0x2755, /**< */
|
||||
BLE_GATT_UNIT_RADIANCE_WATT_PER_SQUARE_METRE_STERADIAN = 0x2756, /**< */
|
||||
BLE_GATT_UNIT_CATALYTIC_ACTIVITY_CONCENTRATION_KATAL_PER_CUBIC_METRE = 0x2757, /**< */
|
||||
BLE_GATT_UNIT_TIME_MINUTE = 0x2760, /**< Time, Minute */
|
||||
BLE_GATT_UNIT_TIME_HOUR = 0x2761, /**< Time, Hour */
|
||||
BLE_GATT_UNIT_TIME_DAY = 0x2762, /**< Time, Day */
|
||||
BLE_GATT_UNIT_PLANE_ANGLE_DEGREE = 0x2763, /**< */
|
||||
BLE_GATT_UNIT_PLANE_ANGLE_MINUTE = 0x2764, /**< */
|
||||
BLE_GATT_UNIT_PLANE_ANGLE_SECOND = 0x2765, /**< */
|
||||
BLE_GATT_UNIT_AREA_HECTARE = 0x2766, /**< */
|
||||
BLE_GATT_UNIT_VOLUME_LITRE = 0x2767, /**< */
|
||||
BLE_GATT_UNIT_MASS_TONNE = 0x2768, /**< */
|
||||
BLE_GATT_UNIT_PRESSURE_BAR = 0x2780, /**< Pressure, Bar */
|
||||
BLE_GATT_UNIT_PRESSURE_MILLIMETRE_OF_MERCURY = 0x2781, /**< Pressure, Millimetre of Mercury */
|
||||
BLE_GATT_UNIT_LENGTH_ANGSTROM = 0x2782, /**< */
|
||||
BLE_GATT_UNIT_LENGTH_NAUTICAL_MILE = 0x2783, /**< */
|
||||
BLE_GATT_UNIT_AREA_BARN = 0x2784, /**< */
|
||||
BLE_GATT_UNIT_VELOCITY_KNOT = 0x2785, /**< */
|
||||
BLE_GATT_UNIT_LOGARITHMIC_RADIO_QUANTITY_NEPER = 0x2786, /**< */
|
||||
BLE_GATT_UNIT_LOGARITHMIC_RADIO_QUANTITY_BEL = 0x2787, /**< */
|
||||
BLE_GATT_UNIT_LENGTH_YARD = 0x27A0, /**< Length, Yard */
|
||||
BLE_GATT_UNIT_LENGTH_PARSEC = 0x27A1, /**< Length, Parsec */
|
||||
BLE_GATT_UNIT_LENGTH_INCH = 0x27A2, /**< Length, Inch */
|
||||
BLE_GATT_UNIT_LENGTH_FOOT = 0x27A3, /**< Length, Foot */
|
||||
BLE_GATT_UNIT_LENGTH_MILE = 0x27A4, /**< Length, Mile */
|
||||
BLE_GATT_UNIT_PRESSURE_POUND_FORCE_PER_SQUARE_INCH = 0x27A5, /**< */
|
||||
BLE_GATT_UNIT_VELOCITY_KILOMETRE_PER_HOUR = 0x27A6, /**< Velocity, Kilometre per Hour */
|
||||
BLE_GATT_UNIT_VELOCITY_MILE_PER_HOUR = 0x27A7, /**< Velocity, Mile per Hour */
|
||||
BLE_GATT_UNIT_ANGULAR_VELOCITY_REVOLUTION_PER_MINUTE = 0x27A8, /**< Angular Velocity, Revolution per Minute */
|
||||
BLE_GATT_UNIT_ENERGY_GRAM_CALORIE = 0x27A9, /**< Energy, Gram Calorie */
|
||||
BLE_GATT_UNIT_ENERGY_KILOGRAM_CALORIE = 0x27AA, /**< Energy, Kilogram Calorie */
|
||||
BLE_GATT_UNIT_ENERGY_KILOWATT_HOUR = 0x27AB, /**< Energy, Killowatt Hour */
|
||||
BLE_GATT_UNIT_THERMODYNAMIC_TEMPERATURE_DEGREE_FAHRENHEIT = 0x27AC, /**< */
|
||||
BLE_GATT_UNIT_PERCENTAGE = 0x27AD, /**< Percentage */
|
||||
BLE_GATT_UNIT_PER_MILLE = 0x27AE, /**< */
|
||||
BLE_GATT_UNIT_PERIOD_BEATS_PER_MINUTE = 0x27AF, /**< */
|
||||
BLE_GATT_UNIT_ELECTRIC_CHARGE_AMPERE_HOURS = 0x27B0, /**< */
|
||||
BLE_GATT_UNIT_MASS_DENSITY_MILLIGRAM_PER_DECILITRE = 0x27B1, /**< */
|
||||
BLE_GATT_UNIT_MASS_DENSITY_MILLIMOLE_PER_LITRE = 0x27B2, /**< */
|
||||
BLE_GATT_UNIT_TIME_YEAR = 0x27B3, /**< Time, Year */
|
||||
BLE_GATT_UNIT_TIME_MONTH = 0x27B4, /**< Time, Month */
|
||||
BLE_GATT_UNIT_CONCENTRATION_COUNT_PER_CUBIC_METRE = 0x27B5, /**< */
|
||||
BLE_GATT_UNIT_IRRADIANCE_WATT_PER_SQUARE_METRE = 0x27B6 /**< */
|
||||
} ble_gatt_unit_t;
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
\brief Standard GATT number types
|
||||
|
||||
\note See Bluetooth Specification 4.0 (Vol. 3), Part G, Section 3.3.3.5.2
|
||||
\note See http://developer.bluetooth.org/gatt/descriptors/Pages/DescriptorViewer.aspx?u=org.bluetooth.descriptor.gatt.characteristic_presentation_format.xml
|
||||
*/
|
||||
/**************************************************************************/
|
||||
typedef enum ble_gatt_format_e
|
||||
{
|
||||
BLE_GATT_FORMAT_RFU = 0x00, /**< Reserved For Future Use. */
|
||||
BLE_GATT_FORMAT_BOOLEAN = 0x01, /**< Boolean. */
|
||||
BLE_GATT_FORMAT_2BIT = 0x02, /**< Unsigned 2-bit integer. */
|
||||
BLE_GATT_FORMAT_NIBBLE = 0x03, /**< Unsigned 4-bit integer. */
|
||||
BLE_GATT_FORMAT_UINT8 = 0x04, /**< Unsigned 8-bit integer. */
|
||||
BLE_GATT_FORMAT_UINT12 = 0x05, /**< Unsigned 12-bit integer. */
|
||||
BLE_GATT_FORMAT_UINT16 = 0x06, /**< Unsigned 16-bit integer. */
|
||||
BLE_GATT_FORMAT_UINT24 = 0x07, /**< Unsigned 24-bit integer. */
|
||||
BLE_GATT_FORMAT_UINT32 = 0x08, /**< Unsigned 32-bit integer. */
|
||||
BLE_GATT_FORMAT_UINT48 = 0x09, /**< Unsigned 48-bit integer. */
|
||||
BLE_GATT_FORMAT_UINT64 = 0x0A, /**< Unsigned 64-bit integer. */
|
||||
BLE_GATT_FORMAT_UINT128 = 0x0B, /**< Unsigned 128-bit integer. */
|
||||
BLE_GATT_FORMAT_SINT8 = 0x0C, /**< Signed 2-bit integer. */
|
||||
BLE_GATT_FORMAT_SINT12 = 0x0D, /**< Signed 12-bit integer. */
|
||||
BLE_GATT_FORMAT_SINT16 = 0x0E, /**< Signed 16-bit integer. */
|
||||
BLE_GATT_FORMAT_SINT24 = 0x0F, /**< Signed 24-bit integer. */
|
||||
BLE_GATT_FORMAT_SINT32 = 0x10, /**< Signed 32-bit integer. */
|
||||
BLE_GATT_FORMAT_SINT48 = 0x11, /**< Signed 48-bit integer. */
|
||||
BLE_GATT_FORMAT_SINT64 = 0x12, /**< Signed 64-bit integer. */
|
||||
BLE_GATT_FORMAT_SINT128 = 0x13, /**< Signed 128-bit integer. */
|
||||
BLE_GATT_FORMAT_FLOAT32 = 0x14, /**< IEEE-754 32-bit floating point. */
|
||||
BLE_GATT_FORMAT_FLOAT64 = 0x15, /**< IEEE-754 64-bit floating point. */
|
||||
BLE_GATT_FORMAT_SFLOAT = 0x16, /**< IEEE-11073 16-bit SFLOAT. */
|
||||
BLE_GATT_FORMAT_FLOAT = 0x17, /**< IEEE-11073 32-bit FLOAT. */
|
||||
BLE_GATT_FORMAT_DUINT16 = 0x18, /**< IEEE-20601 format. */
|
||||
BLE_GATT_FORMAT_UTF8S = 0x19, /**< UTF-8 string. */
|
||||
BLE_GATT_FORMAT_UTF16S = 0x1A, /**< UTF-16 string. */
|
||||
BLE_GATT_FORMAT_STRUCT = 0x1B /**< Opaque Structure. */
|
||||
} ble_gatt_format_t;
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
\brief Standard GATT characteritic properties
|
||||
|
||||
\note See Bluetooth Specification 4.0 (Vol. 3), Part G, Section 3.3.1.1
|
||||
and Section 3.3.3.1 for Extended Properties
|
||||
*/
|
||||
/**************************************************************************/
|
||||
typedef enum ble_gatt_char_properties_e
|
||||
{
|
||||
BLE_GATT_CHAR_PROPERTIES_BROADCAST = 0x01, /**< Permits broadcasts of the Characteristic Value using Server Characteristic Configuration Descriptor. */
|
||||
BLE_GATT_CHAR_PROPERTIES_READ = 0x02, /**< Permits reads of the Characteristic Value. */
|
||||
BLE_GATT_CHAR_PROPERTIES_WRITE_WITHOUT_RESPONSE = 0x04, /**< Permits writes of the Characteristic Value without response. */
|
||||
BLE_GATT_CHAR_PROPERTIES_WRITE = 0x08, /**< Permits writes of the Characteristic Value with response. */
|
||||
BLE_GATT_CHAR_PROPERTIES_NOTIFY = 0x10, /**< Permits notifications of a Characteristic Value without acknowledgement. */
|
||||
BLE_GATT_CHAR_PROPERTIES_INDICATE = 0x20, /**< Permits indications of a Characteristic Value with acknowledgement. */
|
||||
BLE_GATT_CHAR_PROPERTIES_AUTHENTICATED_SIGNED_WRITES = 0x40, /**< Permits signed writes to the Characteristic Value. */
|
||||
BLE_GATT_CHAR_PROPERTIES_EXTENDED_PROPERTIES = 0x80 /**< Additional characteristic properties are defined in the Characteristic Extended Properties Descriptor */
|
||||
} ble_gatt_char_properties_t;
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
\brief GATT presentation format wrapper
|
||||
|
||||
\note See Bluetooth Specification 4.0 (Vol. 3), Part G, Section 3.3.3.5
|
||||
\note See https://developer.bluetooth.org/gatt/descriptors/Pages/DescriptorViewer.aspx?u=org.bluetooth.descriptor.gatt.characteristic_presentation_format.xml
|
||||
*/
|
||||
/**************************************************************************/
|
||||
typedef struct PresentationFormat
|
||||
{
|
||||
uint8_t gatt_format; /**< Format of the value, see @ref ble_gatt_format_t. */
|
||||
int8_t exponent; /**< Exponent for integer data types. Ex. if Exponent = -3 and the char value is 3892, the actual value is 3.892 */
|
||||
uint16_t gatt_unit; /**< UUID from Bluetooth Assigned Numbers, see @ref ble_gatt_unit_t. */
|
||||
uint8_t gatt_namespace; /**< Namespace from Bluetooth Assigned Numbers, normally '1', see @ref BLE_GATT_CPF_NAMESPACES. */
|
||||
uint16_t gatt_nsdesc; /**< Namespace description from Bluetooth Assigned Numbers, normally '0', see @ref BLE_GATT_CPF_NAMESPACES. */
|
||||
} presentation_format_t;
|
||||
|
||||
GattCharacteristic(uint16_t uuid=0, uint16_t minLen=1, uint16_t maxLen=1, uint8_t properties=0);
|
||||
virtual ~GattCharacteristic(void);
|
||||
|
||||
uint16_t uuid; /* Characteristic UUID */
|
||||
uint16_t lenMin; /* Minimum length of the value */
|
||||
uint16_t lenMax; /* Maximum length of the value */
|
||||
uint8_t handle;
|
||||
uint8_t properties;
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -24,21 +24,26 @@
|
|||
|
||||
#define BLE_SERVICE_MAX_CHARACTERISTICS (5)
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
\brief GATT service
|
||||
*/
|
||||
/**************************************************************************/
|
||||
class GattService
|
||||
{
|
||||
private:
|
||||
|
||||
public:
|
||||
GattService(uint8_t[16]); /* 128-bit Base UUID */
|
||||
GattService(uint16_t); /* 16-bit BLE UUID */
|
||||
virtual ~GattService(void);
|
||||
|
||||
UUID primaryServiceID;
|
||||
uint8_t characteristicCount;
|
||||
GattCharacteristic characteristics[BLE_SERVICE_MAX_CHARACTERISTICS];
|
||||
uint8_t handle;
|
||||
|
||||
ble_error_t addCharacteristic(GattCharacteristic &);
|
||||
private:
|
||||
|
||||
public:
|
||||
GattService(uint8_t[16]); /* 128-bit Base UUID */
|
||||
GattService(uint16_t); /* 16-bit BLE UUID */
|
||||
virtual ~GattService(void);
|
||||
|
||||
UUID primaryServiceID;
|
||||
uint8_t characteristicCount;
|
||||
GattCharacteristic characteristics[BLE_SERVICE_MAX_CHARACTERISTICS];
|
||||
uint8_t handle;
|
||||
|
||||
ble_error_t addCharacteristic(GattCharacteristic &);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
205
blecommon.h
205
blecommon.h
|
@ -36,211 +36,6 @@ typedef enum ble_error_e
|
|||
BLE_ERROR_PARAM_OUT_OF_RANGE = 3 /**< One of the supplied parameters is outside the valid range */
|
||||
} ble_error_t;
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
\brief Standard GATT characteristic presentation format unit types.
|
||||
These unit types are used to decribe what the raw numeric
|
||||
data in a characteristic actually represents.
|
||||
|
||||
\note See https://developer.bluetooth.org/gatt/units/Pages/default.aspx
|
||||
*/
|
||||
/**************************************************************************/
|
||||
typedef enum ble_gatt_unit_e
|
||||
{
|
||||
BLE_GATT_UNIT_NONE = 0x2700, /**< No specified unit type */
|
||||
BLE_GATT_UNIT_LENGTH_METRE = 0x2701, /**< Length, Metre */
|
||||
BLE_GATT_UNIT_MASS_KILOGRAM = 0x2702, /**< Mass, Kilogram */
|
||||
BLE_GATT_UNIT_TIME_SECOND = 0x2703, /**< Time, Second */
|
||||
BLE_GATT_UNIT_ELECTRIC_CURRENT_AMPERE = 0x2704, /**< Electric Current, Ampere */
|
||||
BLE_GATT_UNIT_THERMODYNAMIC_TEMPERATURE_KELVIN = 0x2705, /**< Thermodynamic Temperature, Kelvin */
|
||||
BLE_GATT_UNIT_AMOUNT_OF_SUBSTANCE_MOLE = 0x2706, /**< Amount of Substance, Mole */
|
||||
BLE_GATT_UNIT_LUMINOUS_INTENSITY_CANDELA = 0x2707, /**< Luminous Intensity, Candela */
|
||||
BLE_GATT_UNIT_AREA_SQUARE_METRES = 0x2710, /**< Area, Square Metres */
|
||||
BLE_GATT_UNIT_VOLUME_CUBIC_METRES = 0x2711, /**< Volume, Cubic Metres*/
|
||||
BLE_GATT_UNIT_VELOCITY_METRES_PER_SECOND = 0x2712, /**< Velocity, Metres per Second*/
|
||||
BLE_GATT_UNIT_ACCELERATION_METRES_PER_SECOND_SQUARED = 0x2713, /**< Acceleration, Metres per Second Squared */
|
||||
BLE_GATT_UNIT_WAVENUMBER_RECIPROCAL_METRE = 0x2714, /**< Wave Number Reciprocal, Metre */
|
||||
BLE_GATT_UNIT_DENSITY_KILOGRAM_PER_CUBIC_METRE = 0x2715, /**< Density, Kilogram per Cubic Metre */
|
||||
BLE_GATT_UNIT_SURFACE_DENSITY_KILOGRAM_PER_SQUARE_METRE = 0x2716, /**< */
|
||||
BLE_GATT_UNIT_SPECIFIC_VOLUME_CUBIC_METRE_PER_KILOGRAM = 0x2717, /**< */
|
||||
BLE_GATT_UNIT_CURRENT_DENSITY_AMPERE_PER_SQUARE_METRE = 0x2718, /**< */
|
||||
BLE_GATT_UNIT_MAGNETIC_FIELD_STRENGTH_AMPERE_PER_METRE = 0x2719, /**< Magnetic Field Strength, Ampere per Metre */
|
||||
BLE_GATT_UNIT_AMOUNT_CONCENTRATION_MOLE_PER_CUBIC_METRE = 0x271A, /**< */
|
||||
BLE_GATT_UNIT_MASS_CONCENTRATION_KILOGRAM_PER_CUBIC_METRE = 0x271B, /**< */
|
||||
BLE_GATT_UNIT_LUMINANCE_CANDELA_PER_SQUARE_METRE = 0x271C, /**< */
|
||||
BLE_GATT_UNIT_REFRACTIVE_INDEX = 0x271D, /**< */
|
||||
BLE_GATT_UNIT_RELATIVE_PERMEABILITY = 0x271E, /**< */
|
||||
BLE_GATT_UNIT_PLANE_ANGLE_RADIAN = 0x2720, /**< */
|
||||
BLE_GATT_UNIT_SOLID_ANGLE_STERADIAN = 0x2721, /**< */
|
||||
BLE_GATT_UNIT_FREQUENCY_HERTZ = 0x2722, /**< Frequency, Hertz */
|
||||
BLE_GATT_UNIT_FORCE_NEWTON = 0x2723, /**< Force, Newton */
|
||||
BLE_GATT_UNIT_PRESSURE_PASCAL = 0x2724, /**< Pressure, Pascal */
|
||||
BLE_GATT_UNIT_ENERGY_JOULE = 0x2725, /**< Energy, Joule */
|
||||
BLE_GATT_UNIT_POWER_WATT = 0x2726, /**< Power, Watt */
|
||||
BLE_GATT_UNIT_ELECTRIC_CHARGE_COULOMB = 0x2727, /**< Electrical Charge, Coulomb */
|
||||
BLE_GATT_UNIT_ELECTRIC_POTENTIAL_DIFFERENCE_VOLT = 0x2728, /**< Electrical Potential Difference, Voltage */
|
||||
BLE_GATT_UNIT_CAPACITANCE_FARAD = 0x2729, /**< */
|
||||
BLE_GATT_UNIT_ELECTRIC_RESISTANCE_OHM = 0x272A, /**< */
|
||||
BLE_GATT_UNIT_ELECTRIC_CONDUCTANCE_SIEMENS = 0x272B, /**< */
|
||||
BLE_GATT_UNIT_MAGNETIC_FLEX_WEBER = 0x272C, /**< */
|
||||
BLE_GATT_UNIT_MAGNETIC_FLEX_DENSITY_TESLA = 0x272D, /**< */
|
||||
BLE_GATT_UNIT_INDUCTANCE_HENRY = 0x272E, /**< */
|
||||
BLE_GATT_UNIT_THERMODYNAMIC_TEMPERATURE_DEGREE_CELSIUS = 0x272F, /**< */
|
||||
BLE_GATT_UNIT_LUMINOUS_FLUX_LUMEN = 0x2730, /**< */
|
||||
BLE_GATT_UNIT_ILLUMINANCE_LUX = 0x2731, /**< */
|
||||
BLE_GATT_UNIT_ACTIVITY_REFERRED_TO_A_RADIONUCLIDE_BECQUEREL = 0x2732, /**< */
|
||||
BLE_GATT_UNIT_ABSORBED_DOSE_GRAY = 0x2733, /**< */
|
||||
BLE_GATT_UNIT_DOSE_EQUIVALENT_SIEVERT = 0x2734, /**< */
|
||||
BLE_GATT_UNIT_CATALYTIC_ACTIVITY_KATAL = 0x2735, /**< */
|
||||
BLE_GATT_UNIT_DYNAMIC_VISCOSITY_PASCAL_SECOND = 0x2740, /**< */
|
||||
BLE_GATT_UNIT_MOMENT_OF_FORCE_NEWTON_METRE = 0x2741, /**< */
|
||||
BLE_GATT_UNIT_SURFACE_TENSION_NEWTON_PER_METRE = 0x2742, /**< */
|
||||
BLE_GATT_UNIT_ANGULAR_VELOCITY_RADIAN_PER_SECOND = 0x2743, /**< */
|
||||
BLE_GATT_UNIT_ANGULAR_ACCELERATION_RADIAN_PER_SECOND_SQUARED = 0x2744, /**< */
|
||||
BLE_GATT_UNIT_HEAT_FLUX_DENSITY_WATT_PER_SQUARE_METRE = 0x2745, /**< */
|
||||
BLE_GATT_UNIT_HEAT_CAPACITY_JOULE_PER_KELVIN = 0x2746, /**< */
|
||||
BLE_GATT_UNIT_SPECIFIC_HEAT_CAPACITY_JOULE_PER_KILOGRAM_KELVIN = 0x2747, /**< */
|
||||
BLE_GATT_UNIT_SPECIFIC_ENERGY_JOULE_PER_KILOGRAM = 0x2748, /**< */
|
||||
BLE_GATT_UNIT_THERMAL_CONDUCTIVITY_WATT_PER_METRE_KELVIN = 0x2749, /**< */
|
||||
BLE_GATT_UNIT_ENERGY_DENSITY_JOULE_PER_CUBIC_METRE = 0x274A, /**< */
|
||||
BLE_GATT_UNIT_ELECTRIC_FIELD_STRENGTH_VOLT_PER_METRE = 0x274B, /**< */
|
||||
BLE_GATT_UNIT_ELECTRIC_CHARGE_DENSITY_COULOMB_PER_CUBIC_METRE = 0x274C, /**< */
|
||||
BLE_GATT_UNIT_SURFACE_CHARGE_DENSITY_COULOMB_PER_SQUARE_METRE = 0x274D, /**< */
|
||||
BLE_GATT_UNIT_ELECTRIC_FLUX_DENSITY_COULOMB_PER_SQUARE_METRE = 0x274E, /**< */
|
||||
BLE_GATT_UNIT_PERMITTIVITY_FARAD_PER_METRE = 0x274F, /**< */
|
||||
BLE_GATT_UNIT_PERMEABILITY_HENRY_PER_METRE = 0x2750, /**< */
|
||||
BLE_GATT_UNIT_MOLAR_ENERGY_JOULE_PER_MOLE = 0x2751, /**< */
|
||||
BLE_GATT_UNIT_MOLAR_ENTROPY_JOULE_PER_MOLE_KELVIN = 0x2752, /**< */
|
||||
BLE_GATT_UNIT_EXPOSURE_COULOMB_PER_KILOGRAM = 0x2753, /**< */
|
||||
BLE_GATT_UNIT_ABSORBED_DOSE_RATE_GRAY_PER_SECOND = 0x2754, /**< */
|
||||
BLE_GATT_UNIT_RADIANT_INTENSITY_WATT_PER_STERADIAN = 0x2755, /**< */
|
||||
BLE_GATT_UNIT_RADIANCE_WATT_PER_SQUARE_METRE_STERADIAN = 0x2756, /**< */
|
||||
BLE_GATT_UNIT_CATALYTIC_ACTIVITY_CONCENTRATION_KATAL_PER_CUBIC_METRE = 0x2757, /**< */
|
||||
BLE_GATT_UNIT_TIME_MINUTE = 0x2760, /**< Time, Minute */
|
||||
BLE_GATT_UNIT_TIME_HOUR = 0x2761, /**< Time, Hour */
|
||||
BLE_GATT_UNIT_TIME_DAY = 0x2762, /**< Time, Day */
|
||||
BLE_GATT_UNIT_PLANE_ANGLE_DEGREE = 0x2763, /**< */
|
||||
BLE_GATT_UNIT_PLANE_ANGLE_MINUTE = 0x2764, /**< */
|
||||
BLE_GATT_UNIT_PLANE_ANGLE_SECOND = 0x2765, /**< */
|
||||
BLE_GATT_UNIT_AREA_HECTARE = 0x2766, /**< */
|
||||
BLE_GATT_UNIT_VOLUME_LITRE = 0x2767, /**< */
|
||||
BLE_GATT_UNIT_MASS_TONNE = 0x2768, /**< */
|
||||
BLE_GATT_UNIT_PRESSURE_BAR = 0x2780, /**< Pressure, Bar */
|
||||
BLE_GATT_UNIT_PRESSURE_MILLIMETRE_OF_MERCURY = 0x2781, /**< Pressure, Millimetre of Mercury */
|
||||
BLE_GATT_UNIT_LENGTH_ANGSTROM = 0x2782, /**< */
|
||||
BLE_GATT_UNIT_LENGTH_NAUTICAL_MILE = 0x2783, /**< */
|
||||
BLE_GATT_UNIT_AREA_BARN = 0x2784, /**< */
|
||||
BLE_GATT_UNIT_VELOCITY_KNOT = 0x2785, /**< */
|
||||
BLE_GATT_UNIT_LOGARITHMIC_RADIO_QUANTITY_NEPER = 0x2786, /**< */
|
||||
BLE_GATT_UNIT_LOGARITHMIC_RADIO_QUANTITY_BEL = 0x2787, /**< */
|
||||
BLE_GATT_UNIT_LENGTH_YARD = 0x27A0, /**< Length, Yard */
|
||||
BLE_GATT_UNIT_LENGTH_PARSEC = 0x27A1, /**< Length, Parsec */
|
||||
BLE_GATT_UNIT_LENGTH_INCH = 0x27A2, /**< Length, Inch */
|
||||
BLE_GATT_UNIT_LENGTH_FOOT = 0x27A3, /**< Length, Foot */
|
||||
BLE_GATT_UNIT_LENGTH_MILE = 0x27A4, /**< Length, Mile */
|
||||
BLE_GATT_UNIT_PRESSURE_POUND_FORCE_PER_SQUARE_INCH = 0x27A5, /**< */
|
||||
BLE_GATT_UNIT_VELOCITY_KILOMETRE_PER_HOUR = 0x27A6, /**< Velocity, Kilometre per Hour */
|
||||
BLE_GATT_UNIT_VELOCITY_MILE_PER_HOUR = 0x27A7, /**< Velocity, Mile per Hour */
|
||||
BLE_GATT_UNIT_ANGULAR_VELOCITY_REVOLUTION_PER_MINUTE = 0x27A8, /**< Angular Velocity, Revolution per Minute */
|
||||
BLE_GATT_UNIT_ENERGY_GRAM_CALORIE = 0x27A9, /**< Energy, Gram Calorie */
|
||||
BLE_GATT_UNIT_ENERGY_KILOGRAM_CALORIE = 0x27AA, /**< Energy, Kilogram Calorie */
|
||||
BLE_GATT_UNIT_ENERGY_KILOWATT_HOUR = 0x27AB, /**< Energy, Killowatt Hour */
|
||||
BLE_GATT_UNIT_THERMODYNAMIC_TEMPERATURE_DEGREE_FAHRENHEIT = 0x27AC, /**< */
|
||||
BLE_GATT_UNIT_PERCENTAGE = 0x27AD, /**< Percentage */
|
||||
BLE_GATT_UNIT_PER_MILLE = 0x27AE, /**< */
|
||||
BLE_GATT_UNIT_PERIOD_BEATS_PER_MINUTE = 0x27AF, /**< */
|
||||
BLE_GATT_UNIT_ELECTRIC_CHARGE_AMPERE_HOURS = 0x27B0, /**< */
|
||||
BLE_GATT_UNIT_MASS_DENSITY_MILLIGRAM_PER_DECILITRE = 0x27B1, /**< */
|
||||
BLE_GATT_UNIT_MASS_DENSITY_MILLIMOLE_PER_LITRE = 0x27B2, /**< */
|
||||
BLE_GATT_UNIT_TIME_YEAR = 0x27B3, /**< Time, Year */
|
||||
BLE_GATT_UNIT_TIME_MONTH = 0x27B4, /**< Time, Month */
|
||||
BLE_GATT_UNIT_CONCENTRATION_COUNT_PER_CUBIC_METRE = 0x27B5, /**< */
|
||||
BLE_GATT_UNIT_IRRADIANCE_WATT_PER_SQUARE_METRE = 0x27B6 /**< */
|
||||
} ble_gatt_unit_t;
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
\brief Standard GATT number types
|
||||
|
||||
\note See Bluetooth Specification 4.0 (Vol. 3), Part G, Section 3.3.3.5.2
|
||||
\note See http://developer.bluetooth.org/gatt/descriptors/Pages/DescriptorViewer.aspx?u=org.bluetooth.descriptor.gatt.characteristic_presentation_format.xml
|
||||
*/
|
||||
/**************************************************************************/
|
||||
typedef enum ble_gatt_format_e
|
||||
{
|
||||
BLE_GATT_FORMAT_RFU = 0x00, /**< Reserved For Future Use. */
|
||||
BLE_GATT_FORMAT_BOOLEAN = 0x01, /**< Boolean. */
|
||||
BLE_GATT_FORMAT_2BIT = 0x02, /**< Unsigned 2-bit integer. */
|
||||
BLE_GATT_FORMAT_NIBBLE = 0x03, /**< Unsigned 4-bit integer. */
|
||||
BLE_GATT_FORMAT_UINT8 = 0x04, /**< Unsigned 8-bit integer. */
|
||||
BLE_GATT_FORMAT_UINT12 = 0x05, /**< Unsigned 12-bit integer. */
|
||||
BLE_GATT_FORMAT_UINT16 = 0x06, /**< Unsigned 16-bit integer. */
|
||||
BLE_GATT_FORMAT_UINT24 = 0x07, /**< Unsigned 24-bit integer. */
|
||||
BLE_GATT_FORMAT_UINT32 = 0x08, /**< Unsigned 32-bit integer. */
|
||||
BLE_GATT_FORMAT_UINT48 = 0x09, /**< Unsigned 48-bit integer. */
|
||||
BLE_GATT_FORMAT_UINT64 = 0x0A, /**< Unsigned 64-bit integer. */
|
||||
BLE_GATT_FORMAT_UINT128 = 0x0B, /**< Unsigned 128-bit integer. */
|
||||
BLE_GATT_FORMAT_SINT8 = 0x0C, /**< Signed 2-bit integer. */
|
||||
BLE_GATT_FORMAT_SINT12 = 0x0D, /**< Signed 12-bit integer. */
|
||||
BLE_GATT_FORMAT_SINT16 = 0x0E, /**< Signed 16-bit integer. */
|
||||
BLE_GATT_FORMAT_SINT24 = 0x0F, /**< Signed 24-bit integer. */
|
||||
BLE_GATT_FORMAT_SINT32 = 0x10, /**< Signed 32-bit integer. */
|
||||
BLE_GATT_FORMAT_SINT48 = 0x11, /**< Signed 48-bit integer. */
|
||||
BLE_GATT_FORMAT_SINT64 = 0x12, /**< Signed 64-bit integer. */
|
||||
BLE_GATT_FORMAT_SINT128 = 0x13, /**< Signed 128-bit integer. */
|
||||
BLE_GATT_FORMAT_FLOAT32 = 0x14, /**< IEEE-754 32-bit floating point. */
|
||||
BLE_GATT_FORMAT_FLOAT64 = 0x15, /**< IEEE-754 64-bit floating point. */
|
||||
BLE_GATT_FORMAT_SFLOAT = 0x16, /**< IEEE-11073 16-bit SFLOAT. */
|
||||
BLE_GATT_FORMAT_FLOAT = 0x17, /**< IEEE-11073 32-bit FLOAT. */
|
||||
BLE_GATT_FORMAT_DUINT16 = 0x18, /**< IEEE-20601 format. */
|
||||
BLE_GATT_FORMAT_UTF8S = 0x19, /**< UTF-8 string. */
|
||||
BLE_GATT_FORMAT_UTF16S = 0x1A, /**< UTF-16 string. */
|
||||
BLE_GATT_FORMAT_STRUCT = 0x1B /**< Opaque Structure. */
|
||||
} ble_gatt_format_t;
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
\brief Standard GATT characteritic properties
|
||||
|
||||
\note See Bluetooth Specification 4.0 (Vol. 3), Part G, Section 3.3.1.1
|
||||
and Section 3.3.3.1 for Extended Properties
|
||||
*/
|
||||
/**************************************************************************/
|
||||
typedef enum ble_gatt_char_properties_e
|
||||
{
|
||||
BLE_GATT_CHAR_PROPERTIES_BROADCAST = 0x01, /**< Permits broadcasts of the Characteristic Value using Server Characteristic Configuration Descriptor. */
|
||||
BLE_GATT_CHAR_PROPERTIES_READ = 0x02, /**< Permits reads of the Characteristic Value. */
|
||||
BLE_GATT_CHAR_PROPERTIES_WRITE_WITHOUT_RESPONSE = 0x04, /**< Permits writes of the Characteristic Value without response. */
|
||||
BLE_GATT_CHAR_PROPERTIES_WRITE = 0x08, /**< Permits writes of the Characteristic Value with response. */
|
||||
BLE_GATT_CHAR_PROPERTIES_NOTIFY = 0x10, /**< Permits notifications of a Characteristic Value without acknowledgement. */
|
||||
BLE_GATT_CHAR_PROPERTIES_INDICATE = 0x20, /**< Permits indications of a Characteristic Value with acknowledgement. */
|
||||
BLE_GATT_CHAR_PROPERTIES_AUTHENTICATED_SIGNED_WRITES = 0x40, /**< Permits signed writes to the Characteristic Value. */
|
||||
BLE_GATT_CHAR_PROPERTIES_EXTENDED_PROPERTIES = 0x80 /**< Additional characteristic properties are defined in the Characteristic Extended Properties Descriptor */
|
||||
} ble_gatt_char_properties_t;
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
\brief GATT presentation format wrapper
|
||||
|
||||
\note See Bluetooth Specification 4.0 (Vol. 3), Part G, Section 3.3.3.5
|
||||
\note See https://developer.bluetooth.org/gatt/descriptors/Pages/DescriptorViewer.aspx?u=org.bluetooth.descriptor.gatt.characteristic_presentation_format.xml
|
||||
*/
|
||||
/**************************************************************************/
|
||||
typedef struct PresentationFormat
|
||||
{
|
||||
uint8_t gatt_format; /**< Format of the value, see @ref ble_gatt_format_t. */
|
||||
int8_t exponent; /**< Exponent for integer data types. Ex. if Exponent = -3 and the char value is 3892, the actual value is 3.892 */
|
||||
uint16_t gatt_unit; /**< UUID from Bluetooth Assigned Numbers, see @ref ble_gatt_unit_t. */
|
||||
uint8_t gatt_namespace; /**< Namespace from Bluetooth Assigned Numbers, normally '1', see @ref BLE_GATT_CPF_NAMESPACES. */
|
||||
uint16_t gatt_nsdesc; /**< Namespace description from Bluetooth Assigned Numbers, normally '0', see @ref BLE_GATT_CPF_NAMESPACES. */
|
||||
} presentation_format_t;
|
||||
|
||||
struct SecurityMode
|
||||
{
|
||||
uint8_t mode; /**< Security Mode (1 or 2), 0 for no permissions at all. */
|
||||
uint8_t level; /**< Level (1, 2 or 3), 0 for no permissions at all. */
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
40
hw/BLEDevice.h
Normal file
40
hw/BLEDevice.h
Normal file
|
@ -0,0 +1,40 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef __BLE_DEVICE_H__
|
||||
#define __BLE_DEVICE_H__
|
||||
|
||||
#include "mbed.h"
|
||||
#include "blecommon.h"
|
||||
#include "hw/Gap.h"
|
||||
#include "hw/GattServer.h"
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
\brief
|
||||
The base class used to abstract away BLE capable radio transceivers
|
||||
or SOCs, to enable this BLE API to work with any radio transparently.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
class BLEDevice
|
||||
{
|
||||
public:
|
||||
virtual Gap& getGap() = 0;
|
||||
virtual GattServer& getGattServer() = 0;
|
||||
virtual ble_error_t reset(void) = 0;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -14,64 +14,55 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef __BLE_RADIO_H__
|
||||
#define __BLE_RADIO_H__
|
||||
#ifndef __GAP_H__
|
||||
#define __GAP_H__
|
||||
|
||||
#include "mbed.h"
|
||||
#include "blecommon.h"
|
||||
#include "GattService.h"
|
||||
#include "GapAdvertisingData.h"
|
||||
#include "GapAdvertisingParams.h"
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
\brief
|
||||
The base class used to abstract away BLE capable radio transceivers
|
||||
or SOCs, to enable this BLE API to work with any radio transparently.
|
||||
The base class used to abstract GAP functionality to a specific radio
|
||||
transceiver, SOC or BLE Stack.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
class BLERadio
|
||||
class Gap
|
||||
{
|
||||
protected:
|
||||
FunctionPointer _callback_event;
|
||||
FunctionPointer m_callback_event;
|
||||
|
||||
public:
|
||||
/******************************************************************/
|
||||
/*!
|
||||
\brief
|
||||
Identifies events generated by the radio HW when an event
|
||||
Identifies GAP events generated by the radio HW when an event
|
||||
callback occurs
|
||||
*/
|
||||
/******************************************************************/
|
||||
typedef enum radio_event_e
|
||||
typedef enum gap_event_e
|
||||
{
|
||||
RADIO_EVENT_CONNECT = 0x01, /**< A BLE connection was established by the radio */
|
||||
RADIO_EVENT_DISCONNECT = 0x02, /**< The BLE device was disconnected */
|
||||
RADIO_EVENT_WRITE = 0x03, /**< A BLE write request occured */
|
||||
RADIO_EVENT_RADIOERROR = 0x80 /**< A low level error occured on the radio */
|
||||
} radioEvent_t;
|
||||
|
||||
uint8_t serviceCount;
|
||||
uint8_t characteristicCount;
|
||||
|
||||
/* ToDo: Force constructor with event handler callback */
|
||||
GAP_EVENT_TODO = 0x01 /**< ... */
|
||||
} gapEvent_t;
|
||||
|
||||
/* These functions must be defined in the sub-class */
|
||||
virtual ble_error_t setAdvertising(GapAdvertisingParams &, GapAdvertisingData &, GapAdvertisingData &) = 0;
|
||||
virtual ble_error_t addService(GattService &) = 0;
|
||||
virtual ble_error_t readCharacteristic(uint8_t, uint8_t[], uint16_t) = 0;
|
||||
virtual ble_error_t writeCharacteristic(uint8_t, uint8_t[], uint16_t) = 0;
|
||||
virtual ble_error_t start(void) = 0;
|
||||
virtual ble_error_t stop(void) = 0;
|
||||
virtual ble_error_t reset(void) = 0;
|
||||
virtual ble_error_t startAdvertising(void) = 0;
|
||||
virtual ble_error_t stopAdvertising(void) = 0;
|
||||
|
||||
/* BLE event callback (connect, disconnect, etc.) */
|
||||
uint8_t advertising;
|
||||
uint8_t connected;
|
||||
|
||||
/* Event callback */
|
||||
void attach(void (*function)(void)) {
|
||||
_callback_event.attach( function );
|
||||
m_callback_event.attach( function );
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void attach(T *object, void (T::*member)(void)) {
|
||||
_callback_event.attach( object, member );
|
||||
m_callback_event.attach( object, member );
|
||||
}
|
||||
};
|
||||
|
69
hw/GattServer.h
Normal file
69
hw/GattServer.h
Normal file
|
@ -0,0 +1,69 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef __GATT_SERVER_H__
|
||||
#define __GATT_SERVER_H__
|
||||
|
||||
#include "blecommon.h"
|
||||
#include "UUID.h"
|
||||
#include "GattService.h"
|
||||
#include "mbed.h"
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
\brief
|
||||
The base class used to abstract GATT Server functionality to a specific
|
||||
radio transceiver, SOC or BLE Stack.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
class GattServer
|
||||
{
|
||||
protected:
|
||||
FunctionPointer m_callback_event;
|
||||
|
||||
public:
|
||||
/******************************************************************/
|
||||
/*!
|
||||
\brief
|
||||
Identifies GATT events generated by the radio HW when an event
|
||||
callback occurs
|
||||
*/
|
||||
/******************************************************************/
|
||||
typedef enum gatt_event_e
|
||||
{
|
||||
GATT_EVENT_TODO = 0x01 /**< ... */
|
||||
} gattEvent_t;
|
||||
|
||||
/* These functions must be defined in the sub-class */
|
||||
virtual ble_error_t addService(GattService &) = 0;
|
||||
virtual ble_error_t readValue(uint8_t, uint8_t[], uint16_t) = 0;
|
||||
virtual ble_error_t updateValue(uint8_t, uint8_t[], uint16_t) = 0;
|
||||
|
||||
uint8_t serviceCount;
|
||||
uint8_t characteristicCount;
|
||||
|
||||
/* Event callback */
|
||||
void attach(void (*function)(void)) {
|
||||
m_callback_event.attach( function );
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void attach(T *object, void (T::*member)(void)) {
|
||||
m_callback_event.attach( object, member );
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
91
hw/nRF51822s/nRF51822s.cpp
Normal file
91
hw/nRF51822s/nRF51822s.cpp
Normal file
|
@ -0,0 +1,91 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "mbed.h"
|
||||
#include "nRF51822s.h"
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief UART callback function
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void nRF51822s::uartCallback(void)
|
||||
{
|
||||
/* ToDo: Check responses and set a flag for success/error/etc. */
|
||||
|
||||
/* Read serial to clear the RX interrupt */
|
||||
uart.getc();
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Constructor
|
||||
*/
|
||||
/**************************************************************************/
|
||||
nRF51822s::nRF51822s(PinName tx, PinName rx, PinName rts, PinName cts) : uart(tx, rx), gap(uart), gattServer(uart)
|
||||
{
|
||||
/* Setup the nRF UART interface */
|
||||
uart.baud(9600);
|
||||
|
||||
/* Echo data on the debug CDC port */
|
||||
uart.attach(this, &nRF51822s::uartCallback);
|
||||
|
||||
/* Add flow control for UART (required by the nRF51822) */
|
||||
uart.set_flow_control(RawSerial::RTSCTS, rts, cts);
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Destructor
|
||||
*/
|
||||
/**************************************************************************/
|
||||
nRF51822s::~nRF51822s(void)
|
||||
{
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Resets the BLE HW, removing any existing services and
|
||||
characteristics
|
||||
|
||||
@returns ble_error_t
|
||||
|
||||
@retval BLE_ERROR_NONE
|
||||
Everything executed properly
|
||||
|
||||
@section EXAMPLE
|
||||
|
||||
@code
|
||||
|
||||
@endcode
|
||||
*/
|
||||
/**************************************************************************/
|
||||
ble_error_t nRF51822s::reset(void)
|
||||
{
|
||||
wait(0.5);
|
||||
|
||||
/* Command ID = 0x0005, No payload */
|
||||
uart.printf("10 05 00 00\r\n");
|
||||
|
||||
/* Reset the service and characteristic counters */
|
||||
//serviceCount = 0;
|
||||
//characteristicCount = 0;
|
||||
|
||||
/* Wait for the radio to come back up */
|
||||
wait(1);
|
||||
|
||||
return BLE_ERROR_NONE;
|
||||
}
|
51
hw/nRF51822s/nRF51822s.h
Normal file
51
hw/nRF51822s/nRF51822s.h
Normal file
|
@ -0,0 +1,51 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef __NRF51822_H__
|
||||
#define __NRF51822_H__
|
||||
|
||||
#include "mbed.h"
|
||||
#include "blecommon.h"
|
||||
#include "hw/BLEDevice.h"
|
||||
#include "hw/nRF51822s/nRF51Gap.h"
|
||||
#include "hw/nRF51822s/nRF51GattServer.h"
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
\brief
|
||||
|
||||
*/
|
||||
/**************************************************************************/
|
||||
class nRF51822s : public BLEDevice
|
||||
{
|
||||
protected:
|
||||
RawSerial uart;
|
||||
nRF51Gap gap;
|
||||
nRF51GattServer gattServer;
|
||||
|
||||
public:
|
||||
nRF51822s(PinName, PinName, PinName, PinName);
|
||||
virtual ~nRF51822s(void);
|
||||
|
||||
virtual Gap& getGap() { return gap; };
|
||||
virtual GattServer& getGattServer() { return gattServer; };
|
||||
virtual ble_error_t reset(void);
|
||||
|
||||
private:
|
||||
void uartCallback(void);
|
||||
};
|
||||
|
||||
#endif
|
|
@ -14,41 +14,18 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "nRF51822.h"
|
||||
#include "nRF51Gap.h"
|
||||
#include "mbed.h"
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief UART callback function
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void nRF51822::uartCallback(void)
|
||||
{
|
||||
/* ToDo: Check responses and set a flag for success/error/etc. */
|
||||
|
||||
/* Read serial to clear the RX interrupt */
|
||||
uart.getc();
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Constructor
|
||||
*/
|
||||
/**************************************************************************/
|
||||
nRF51822::nRF51822(PinName tx, PinName rx, PinName rts, PinName cts) : uart(tx, rx)
|
||||
nRF51Gap::nRF51Gap(RawSerial &serial) : Gap(), uart(serial)
|
||||
{
|
||||
/* Setup the nRF UART interface */
|
||||
uart.baud(9600);
|
||||
|
||||
/* Echo data on the debug CDC port */
|
||||
uart.attach(this, &nRF51822::uartCallback);
|
||||
|
||||
/* Add flow control for UART (required by the nRF51822) */
|
||||
uart.set_flow_control(RawSerial::RTSCTS, rts, cts);
|
||||
|
||||
/* Reset the service and characteristic counters */
|
||||
serviceCount = 0;
|
||||
characteristicCount = 0;
|
||||
connected = 0;
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
|
@ -56,7 +33,7 @@ nRF51822::nRF51822(PinName tx, PinName rx, PinName rts, PinName cts) : uart(tx,
|
|||
@brief Destructor
|
||||
*/
|
||||
/**************************************************************************/
|
||||
nRF51822::~nRF51822(void)
|
||||
nRF51Gap::~nRF51Gap(void)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -97,7 +74,7 @@ nRF51822::~nRF51822(void)
|
|||
@endcode
|
||||
*/
|
||||
/**************************************************************************/
|
||||
ble_error_t nRF51822::setAdvertising(GapAdvertisingParams & params, GapAdvertisingData & advData, GapAdvertisingData & scanResponse)
|
||||
ble_error_t nRF51Gap::setAdvertising(GapAdvertisingParams & params, GapAdvertisingData & advData, GapAdvertisingData & scanResponse)
|
||||
{
|
||||
uint8_t len = 0;
|
||||
uint8_t *buffer;
|
||||
|
@ -220,162 +197,6 @@ ble_error_t nRF51822::setAdvertising(GapAdvertisingParams & params, GapAdvertisi
|
|||
return BLE_ERROR_NONE;
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Adds a new service to the GATT table on the peripheral
|
||||
|
||||
@returns ble_error_t
|
||||
|
||||
@retval BLE_ERROR_NONE
|
||||
Everything executed properly
|
||||
|
||||
@section EXAMPLE
|
||||
|
||||
@code
|
||||
|
||||
@endcode
|
||||
*/
|
||||
/**************************************************************************/
|
||||
ble_error_t nRF51822::addService(GattService & service)
|
||||
{
|
||||
/* ToDo: Make sure we don't overflow the array, etc. */
|
||||
/* ToDo: Make sure this service UUID doesn't already exist (?) */
|
||||
/* ToDo: Basic validation */
|
||||
|
||||
/* Add the service to the nRF51 */
|
||||
if (service.primaryServiceID.type == UUID::UUID_TYPE_SHORT)
|
||||
{
|
||||
/* 16-bit BLE UUID */
|
||||
uart.printf("10 01 00 04 01 02 %02X %02X\r\n",
|
||||
service.primaryServiceID.value & 0xFF,
|
||||
service.primaryServiceID.value >> 8);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* 128-bit Custom UUID */
|
||||
uart.printf("10 01 00 12 01 10 %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X\r\n",
|
||||
service.primaryServiceID.base[0],
|
||||
service.primaryServiceID.base[1],
|
||||
service.primaryServiceID.base[2],
|
||||
service.primaryServiceID.base[3],
|
||||
service.primaryServiceID.base[4],
|
||||
service.primaryServiceID.base[5],
|
||||
service.primaryServiceID.base[6],
|
||||
service.primaryServiceID.base[7],
|
||||
service.primaryServiceID.base[8],
|
||||
service.primaryServiceID.base[9],
|
||||
service.primaryServiceID.base[10],
|
||||
service.primaryServiceID.base[11],
|
||||
service.primaryServiceID.base[12],
|
||||
service.primaryServiceID.base[13],
|
||||
service.primaryServiceID.base[14],
|
||||
service.primaryServiceID.base[15]);
|
||||
}
|
||||
|
||||
/* ToDo: Check response */
|
||||
wait(0.1);
|
||||
|
||||
/* Add characteristics to the service */
|
||||
for (uint8_t i = 0; i < service.characteristicCount; i++)
|
||||
{
|
||||
/* Command ID = 0x0002 */
|
||||
uart.printf("10 02 00 0F 01 02 %02X %02X 04 02 %02X %02X 05 02 %02X %02X 03 01 %02X\r\n",
|
||||
service.characteristics[i].uuid & 0xFF,
|
||||
service.characteristics[i].uuid >> 8,
|
||||
service.characteristics[i].lenMin & 0xFF,
|
||||
service.characteristics[i].lenMin >> 8,
|
||||
service.characteristics[i].lenMax & 0xFF,
|
||||
service.characteristics[i].lenMax >> 8,
|
||||
service.characteristics[i].properties);
|
||||
|
||||
/* ToDo: Check response */
|
||||
wait(0.1);
|
||||
|
||||
/* Update the characteristic handle */
|
||||
service.characteristics[i].handle = characteristicCount;
|
||||
characteristicCount++;
|
||||
}
|
||||
|
||||
/* Update the service handle */
|
||||
service.handle = serviceCount;
|
||||
serviceCount++;
|
||||
|
||||
return BLE_ERROR_NONE;
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Reads the value of a characteristic, based on the service
|
||||
and characteristic index fields
|
||||
|
||||
@param[in] charHandle
|
||||
The handle of the GattCharacteristic to read from
|
||||
@param[in] buffer
|
||||
Buffer to hold the the characteristic's value
|
||||
(raw byte array in LSB format)
|
||||
@param[in] len
|
||||
The number of bytes read into the buffer
|
||||
|
||||
@returns ble_error_t
|
||||
|
||||
@retval BLE_ERROR_NONE
|
||||
Everything executed properly
|
||||
|
||||
@section EXAMPLE
|
||||
|
||||
@code
|
||||
|
||||
@endcode
|
||||
*/
|
||||
/**************************************************************************/
|
||||
ble_error_t nRF51822::readCharacteristic(uint8_t charHandle, uint8_t buffer[], uint16_t len)
|
||||
{
|
||||
/* ToDo */
|
||||
|
||||
return BLE_ERROR_NONE;
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Updates the value of a characteristic, based on the service
|
||||
and characteristic index fields
|
||||
|
||||
@param[in] charHandle
|
||||
The handle of the GattCharacteristic to write to
|
||||
@param[in] buffer
|
||||
Data to use when updating the characteristic's value
|
||||
(raw byte array in LSB format)
|
||||
@param[in] len
|
||||
The number of bytes in buffer
|
||||
|
||||
@returns ble_error_t
|
||||
|
||||
@retval BLE_ERROR_NONE
|
||||
Everything executed properly
|
||||
|
||||
@section EXAMPLE
|
||||
|
||||
@code
|
||||
|
||||
@endcode
|
||||
*/
|
||||
/**************************************************************************/
|
||||
ble_error_t nRF51822::writeCharacteristic(uint8_t charHandle, uint8_t buffer[], uint16_t len)
|
||||
{
|
||||
/* Command ID = 0x0006, Payload = Characteristic ID, Value */
|
||||
uart.printf("10 06 00 %02X %02X", len + 1, charHandle);
|
||||
for (uint16_t i = 0; i<len; i++)
|
||||
{
|
||||
uart.printf(" %02X", buffer[i]);
|
||||
}
|
||||
uart.printf("\r\n");
|
||||
|
||||
/* ToDo: Check response */
|
||||
wait(0.1);
|
||||
|
||||
return BLE_ERROR_NONE;
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Starts the BLE HW, initialising any services that were
|
||||
|
@ -395,7 +216,7 @@ ble_error_t nRF51822::writeCharacteristic(uint8_t charHandle, uint8_t buffer[],
|
|||
@endcode
|
||||
*/
|
||||
/**************************************************************************/
|
||||
ble_error_t nRF51822::start(void)
|
||||
ble_error_t nRF51Gap::startAdvertising(void)
|
||||
{
|
||||
/* Command ID = 0x0003, No payload */
|
||||
uart.printf("10 03 00 00\r\n");
|
||||
|
@ -422,7 +243,7 @@ ble_error_t nRF51822::start(void)
|
|||
@endcode
|
||||
*/
|
||||
/**************************************************************************/
|
||||
ble_error_t nRF51822::stop(void)
|
||||
ble_error_t nRF51Gap::stopAdvertising(void)
|
||||
{
|
||||
/* Command ID = 0x0004, No payload */
|
||||
uart.printf("10 04 00 00\r\n");
|
||||
|
@ -432,35 +253,3 @@ ble_error_t nRF51822::stop(void)
|
|||
|
||||
return BLE_ERROR_NONE;
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Resets the BLE HW, removing any existing services and
|
||||
characteristics
|
||||
|
||||
@returns ble_error_t
|
||||
|
||||
@retval BLE_ERROR_NONE
|
||||
Everything executed properly
|
||||
|
||||
@section EXAMPLE
|
||||
|
||||
@code
|
||||
|
||||
@endcode
|
||||
*/
|
||||
/**************************************************************************/
|
||||
ble_error_t nRF51822::reset(void)
|
||||
{
|
||||
/* Command ID = 0x0005, No payload */
|
||||
uart.printf("10 05 00 00\r\n");
|
||||
|
||||
/* Reset the service and characteristic counters */
|
||||
serviceCount = 0;
|
||||
characteristicCount = 0;
|
||||
|
||||
/* Wait for the radio to come back up */
|
||||
wait(1);
|
||||
|
||||
return BLE_ERROR_NONE;
|
||||
}
|
47
hw/nRF51822s/nRF51Gap.h
Normal file
47
hw/nRF51822s/nRF51Gap.h
Normal file
|
@ -0,0 +1,47 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef __NRF51822_GAP_H__
|
||||
#define __NRF51822_GAP_H__
|
||||
|
||||
#include "mbed.h"
|
||||
#include "blecommon.h"
|
||||
#include "GapAdvertisingParams.h"
|
||||
#include "GapAdvertisingData.h"
|
||||
#include "hw/Gap.h"
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
\brief
|
||||
|
||||
*/
|
||||
/**************************************************************************/
|
||||
class nRF51Gap : public Gap
|
||||
{
|
||||
public:
|
||||
nRF51Gap(RawSerial &);
|
||||
virtual ~nRF51Gap(void);
|
||||
|
||||
/* Functions that must be implemented from Gap */
|
||||
virtual ble_error_t setAdvertising(GapAdvertisingParams &, GapAdvertisingData &, GapAdvertisingData &);
|
||||
virtual ble_error_t startAdvertising(void);
|
||||
virtual ble_error_t stopAdvertising(void);
|
||||
|
||||
private:
|
||||
RawSerial& uart;
|
||||
};
|
||||
|
||||
#endif
|
197
hw/nRF51822s/nRF51GattServer.cpp
Normal file
197
hw/nRF51822s/nRF51GattServer.cpp
Normal file
|
@ -0,0 +1,197 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "nRF51GattServer.h"
|
||||
#include "mbed.h"
|
||||
|
||||
/* ToDo: Convert to Singleton! */
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Constructor
|
||||
*/
|
||||
/**************************************************************************/
|
||||
nRF51GattServer::nRF51GattServer(RawSerial &serial): GattServer(), uart(serial)
|
||||
{
|
||||
/* Reset the service and characteristic counters */
|
||||
serviceCount = 0;
|
||||
characteristicCount = 0;
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Destructor
|
||||
*/
|
||||
/**************************************************************************/
|
||||
nRF51GattServer::~nRF51GattServer(void)
|
||||
{
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Adds a new service to the GATT table on the peripheral
|
||||
|
||||
@returns ble_error_t
|
||||
|
||||
@retval BLE_ERROR_NONE
|
||||
Everything executed properly
|
||||
|
||||
@section EXAMPLE
|
||||
|
||||
@code
|
||||
|
||||
@endcode
|
||||
*/
|
||||
/**************************************************************************/
|
||||
ble_error_t nRF51GattServer::addService(GattService & service)
|
||||
{
|
||||
/* ToDo: Make sure we don't overflow the array, etc. */
|
||||
/* ToDo: Make sure this service UUID doesn't already exist (?) */
|
||||
/* ToDo: Basic validation */
|
||||
|
||||
/* Add the service to the nRF51 */
|
||||
if (service.primaryServiceID.type == UUID::UUID_TYPE_SHORT)
|
||||
{
|
||||
/* 16-bit BLE UUID */
|
||||
uart.printf("10 01 00 04 01 02 %02X %02X\r\n",
|
||||
service.primaryServiceID.value & 0xFF,
|
||||
service.primaryServiceID.value >> 8);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* 128-bit Custom UUID */
|
||||
uart.printf("10 01 00 12 01 10 %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X\r\n",
|
||||
service.primaryServiceID.base[0],
|
||||
service.primaryServiceID.base[1],
|
||||
service.primaryServiceID.base[2],
|
||||
service.primaryServiceID.base[3],
|
||||
service.primaryServiceID.base[4],
|
||||
service.primaryServiceID.base[5],
|
||||
service.primaryServiceID.base[6],
|
||||
service.primaryServiceID.base[7],
|
||||
service.primaryServiceID.base[8],
|
||||
service.primaryServiceID.base[9],
|
||||
service.primaryServiceID.base[10],
|
||||
service.primaryServiceID.base[11],
|
||||
service.primaryServiceID.base[12],
|
||||
service.primaryServiceID.base[13],
|
||||
service.primaryServiceID.base[14],
|
||||
service.primaryServiceID.base[15]);
|
||||
}
|
||||
|
||||
/* ToDo: Check response */
|
||||
wait(0.1);
|
||||
|
||||
/* Add characteristics to the service */
|
||||
for (uint8_t i = 0; i < service.characteristicCount; i++)
|
||||
{
|
||||
/* Command ID = 0x0002 */
|
||||
uart.printf("10 02 00 0F 01 02 %02X %02X 04 02 %02X %02X 05 02 %02X %02X 03 01 %02X\r\n",
|
||||
service.characteristics[i].uuid & 0xFF,
|
||||
service.characteristics[i].uuid >> 8,
|
||||
service.characteristics[i].lenMin & 0xFF,
|
||||
service.characteristics[i].lenMin >> 8,
|
||||
service.characteristics[i].lenMax & 0xFF,
|
||||
service.characteristics[i].lenMax >> 8,
|
||||
service.characteristics[i].properties);
|
||||
|
||||
/* ToDo: Check response */
|
||||
wait(0.1);
|
||||
|
||||
/* Update the characteristic handle */
|
||||
service.characteristics[i].handle = characteristicCount;
|
||||
characteristicCount++;
|
||||
}
|
||||
|
||||
/* Update the service handle */
|
||||
service.handle = serviceCount;
|
||||
serviceCount++;
|
||||
|
||||
return BLE_ERROR_NONE;
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Reads the value of a characteristic, based on the service
|
||||
and characteristic index fields
|
||||
|
||||
@param[in] charHandle
|
||||
The handle of the GattCharacteristic to read from
|
||||
@param[in] buffer
|
||||
Buffer to hold the the characteristic's value
|
||||
(raw byte array in LSB format)
|
||||
@param[in] len
|
||||
The number of bytes read into the buffer
|
||||
|
||||
@returns ble_error_t
|
||||
|
||||
@retval BLE_ERROR_NONE
|
||||
Everything executed properly
|
||||
|
||||
@section EXAMPLE
|
||||
|
||||
@code
|
||||
|
||||
@endcode
|
||||
*/
|
||||
/**************************************************************************/
|
||||
ble_error_t nRF51GattServer::readValue(uint8_t charHandle, uint8_t buffer[], uint16_t len)
|
||||
{
|
||||
/* ToDo */
|
||||
|
||||
return BLE_ERROR_NONE;
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Updates the value of a characteristic, based on the service
|
||||
and characteristic index fields
|
||||
|
||||
@param[in] charHandle
|
||||
The handle of the GattCharacteristic to write to
|
||||
@param[in] buffer
|
||||
Data to use when updating the characteristic's value
|
||||
(raw byte array in LSB format)
|
||||
@param[in] len
|
||||
The number of bytes in buffer
|
||||
|
||||
@returns ble_error_t
|
||||
|
||||
@retval BLE_ERROR_NONE
|
||||
Everything executed properly
|
||||
|
||||
@section EXAMPLE
|
||||
|
||||
@code
|
||||
|
||||
@endcode
|
||||
*/
|
||||
/**************************************************************************/
|
||||
ble_error_t nRF51GattServer::updateValue(uint8_t charHandle, uint8_t buffer[], uint16_t len)
|
||||
{
|
||||
/* Command ID = 0x0006, Payload = Characteristic ID, Value */
|
||||
uart.printf("10 06 00 %02X %02X", len + 1, charHandle);
|
||||
for (uint16_t i = 0; i<len; i++)
|
||||
{
|
||||
uart.printf(" %02X", buffer[i]);
|
||||
}
|
||||
uart.printf("\r\n");
|
||||
|
||||
/* ToDo: Check response */
|
||||
wait(0.1);
|
||||
|
||||
return BLE_ERROR_NONE;
|
||||
}
|
|
@ -14,41 +14,36 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef __NRF51822_H__
|
||||
#define __NRF51822_H__
|
||||
#ifndef __NRF51822_GATT_SERVER_H__
|
||||
#define __NRF51822_GATT_SERVER_H__
|
||||
|
||||
#include "mbed.h"
|
||||
#include "blecommon.h"
|
||||
#include "BLERadio.h"
|
||||
#include "GattService.h"
|
||||
#include "hw/GattServer.h"
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
\brief
|
||||
Driver for the nRF51822 in connectivity mode using custom serialization
|
||||
firmware.
|
||||
|
||||
*/
|
||||
/**************************************************************************/
|
||||
class nRF51822 : public BLERadio
|
||||
{
|
||||
class nRF51GattServer : public GattServer
|
||||
{
|
||||
public:
|
||||
nRF51822(PinName tx, PinName rx, PinName rts, PinName cts);
|
||||
virtual ~nRF51822(void);
|
||||
nRF51GattServer(RawSerial &);
|
||||
virtual ~nRF51GattServer(void);
|
||||
|
||||
/* Functions that mus be implemented from BLERadio */
|
||||
virtual ble_error_t setAdvertising(GapAdvertisingParams &, GapAdvertisingData &, GapAdvertisingData &);
|
||||
/* Functions that must be implemented from GattServer */
|
||||
virtual ble_error_t addService(GattService &);
|
||||
virtual ble_error_t readCharacteristic(uint8_t, uint8_t[], uint16_t);
|
||||
virtual ble_error_t writeCharacteristic(uint8_t, uint8_t[], uint16_t);
|
||||
virtual ble_error_t start(void);
|
||||
virtual ble_error_t stop(void);
|
||||
virtual ble_error_t reset(void);
|
||||
virtual ble_error_t readValue(uint8_t, uint8_t[], uint16_t);
|
||||
virtual ble_error_t updateValue(uint8_t, uint8_t[], uint16_t);
|
||||
|
||||
private:
|
||||
RawSerial uart;
|
||||
|
||||
/* nRF51 Functions */
|
||||
void uartCallback(void);
|
||||
|
||||
private:
|
||||
RawSerial& uart;
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Reference in a new issue