white space diffs; generated using uncrustify

master
Rohit Grover 2014-05-21 15:01:14 +01:00
parent 887047c58f
commit a9cf898a4b
16 changed files with 945 additions and 636 deletions

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <stdio.h>
#include <string.h>
@ -54,16 +54,16 @@ GapAdvertisingData::~GapAdvertisingData(void)
\args[in] advDataType The Advertising 'DataType' to add
\args[in] payload Pointer to the payload contents
\args[in] len Size of the payload in bytes
\returns ble_error_t
\retval BLE_ERROR_NONE
Everything executed properly
\retval BLE_ERROR_BUFFER_OVERFLOW
The specified data would cause the advertising buffer
to overflow
\par EXAMPLE
\code
@ -71,27 +71,30 @@ GapAdvertisingData::~GapAdvertisingData(void)
\endcode
*/
/**************************************************************************/
ble_error_t GapAdvertisingData::addData(DataType advDataType, uint8_t * payload, uint8_t len)
ble_error_t GapAdvertisingData::addData(DataType advDataType,
uint8_t *payload,
uint8_t len)
{
/* ToDo: Check if an AD type already exists and if the existing */
/* value is exclusive or not (flags, etc.) */
/* Make sure we don't exceed the 31 byte payload limit */
if (_payloadLen + len + 2 >= GAP_ADVERTISING_DATA_MAX_PAYLOAD)
if (_payloadLen + len + 2 >= GAP_ADVERTISING_DATA_MAX_PAYLOAD) {
return BLE_ERROR_BUFFER_OVERFLOW;
}
/* Field length */
memset(&_payload[_payloadLen], len+1, 1);
memset(&_payload[_payloadLen], len + 1, 1);
_payloadLen++;
/* Field ID */
memset(&_payload[_payloadLen], (uint8_t)advDataType, 1);
memset(&_payload[_payloadLen], (uint8_t)advDataType, 1);
_payloadLen++;
/* Payload */
memcpy(&_payload[_payloadLen], payload, len);
_payloadLen += len;
return BLE_ERROR_NONE;
}
@ -101,16 +104,16 @@ ble_error_t GapAdvertisingData::addData(DataType advDataType, uint8_t * payload,
payload
\args[in] appearance The APPEARANCE value to add
\returns ble_error_t
\retval BLE_ERROR_NONE
Everything executed properly
\retval BLE_ERROR_BUFFER_OVERFLOW
The specified data would cause the advertising buffer
to overflow
\par EXAMPLE
\code
@ -121,7 +124,7 @@ ble_error_t GapAdvertisingData::addData(DataType advDataType, uint8_t * payload,
ble_error_t GapAdvertisingData::addAppearance(Appearance appearance)
{
_appearance = appearance;
return addData(GapAdvertisingData::APPEARANCE, (uint8_t*)&appearance, 2);
return addData(GapAdvertisingData::APPEARANCE, (uint8_t *)&appearance, 2);
}
/**************************************************************************/
@ -137,20 +140,20 @@ ble_error_t GapAdvertisingData::addAppearance(Appearance appearance)
\par LE_GENERAL_DISCOVERABLE
The peripheral is permanently discoverable
\par BREDR_NOT_SUPPORTED
This peripheral is a Bluetooth Low Energy only device
(no EDR support)
\returns ble_error_t
\retval BLE_ERROR_NONE
Everything executed properly
\retval BLE_ERROR_BUFFER_OVERFLOW
The specified data would cause the advertising buffer
to overflow
\par EXAMPLE
\code
@ -160,7 +163,7 @@ ble_error_t GapAdvertisingData::addAppearance(Appearance appearance)
/**************************************************************************/
ble_error_t GapAdvertisingData::addFlags(Flags flag)
{
return addData(GapAdvertisingData::FLAGS, (uint8_t*)&flag, 1);
return addData(GapAdvertisingData::FLAGS, (uint8_t *)&flag, 1);
}
/**************************************************************************/
@ -169,16 +172,16 @@ ble_error_t GapAdvertisingData::addFlags(Flags flag)
advertising payload
\args[in] flag The TX_POWER_LEVEL value to add
\returns ble_error_t
\retval BLE_ERROR_NONE
Everything executed properly
\retval BLE_ERROR_BUFFER_OVERFLOW
The specified data would cause the advertising buffer
to overflow
\par EXAMPLE
\code
@ -189,7 +192,7 @@ ble_error_t GapAdvertisingData::addFlags(Flags flag)
ble_error_t GapAdvertisingData::addTxPower(int8_t txPower)
{
/* ToDo: Basic error checking to make sure txPower is in range */
return addData(GapAdvertisingData::TX_POWER_LEVEL, (uint8_t*)&txPower, 1);
return addData(GapAdvertisingData::TX_POWER_LEVEL, (uint8_t *)&txPower, 1);
}
/**************************************************************************/
@ -206,11 +209,11 @@ void GapAdvertisingData::clear(void)
/**************************************************************************/
/*!
\brief Returns a pointer to the the current payload
\returns A pointer to the payload
*/
/**************************************************************************/
uint8_t * GapAdvertisingData::getPayload(void)
uint8_t *GapAdvertisingData::getPayload(void)
{
return (_payloadLen > 0) ? _payload : NULL;
}
@ -218,7 +221,7 @@ uint8_t * GapAdvertisingData::getPayload(void)
/**************************************************************************/
/*!
\brief Returns the current payload length (0..31 bytes)
\returns The payload length in bytes
*/
/**************************************************************************/
@ -230,7 +233,7 @@ uint8_t GapAdvertisingData::getPayloadLen(void)
/**************************************************************************/
/*!
\brief Returns the 16-bit appearance value for this device
\returns The 16-bit appearance value
*/
/**************************************************************************/

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __GAP_ADVERTISING_DATA_H__
#define __GAP_ADVERTISING_DATA_H__
@ -27,10 +27,10 @@
This class provides several helper functions to generate properly
formatted GAP Advertising and Scan Response data payloads
\note
\note
See Bluetooth Specification 4.0 (Vol. 3), Part C, Section 11 and 18
for further information on Advertising and Scan Response data.
\par Advertising and Scan Response Payloads
Advertising data and Scan Response data are organized around a set of
data types called 'AD types' in Bluetooth 4.0 (see the Bluetooth Core
@ -40,38 +40,38 @@
Each AD type has it's own standardized 'assigned number', as defined
by the Bluetooth SIG:
https://www.bluetooth.org/en-us/specification/assigned-numbers/generic-access-profile
\par
For convenience sake, all appropriate AD types have been encapsulated
into GapAdvertisingData::DataType.
\par
Before the AD Types and their payload (if any) can be inserted into
the Advertising or Scan Response frames, they need to be formatted as
follows:
\li \c Record length (1 byte)
\li \c AD Type (1 byte)
\li \c AD payload (optional, only present if record length > 1)
\par
This class takes care of properly formatting the payload, performs
some basic checks on the payload length, and tries to avoid common
errors like adding an exclusive AD field twice in the Advertising
or Scan Response payload.
\par EXAMPLE
\code
// ToDo
\endcode
*/
/**************************************************************************/
class GapAdvertisingData
{
public:
public:
/**********************************************************************/
/*!
\brief
@ -79,7 +79,7 @@ class GapAdvertisingData
These AD types are used to describe the capabilities of the
peripheral, and get inserted inside the advertising or scan
response payloads.
\par Source
\li \c Bluetooth Core Specification 4.0 (Vol. 3), Part C, Section 11, 18
\li \c https://www.bluetooth.org/en-us/specification/assigned-numbers/generic-access-profile
@ -87,44 +87,117 @@ class GapAdvertisingData
/**********************************************************************/
enum DataType
{
FLAGS = 0x01, /**< \ref Flags */
INCOMPLETE_LIST_16BIT_SERVICE_IDS = 0x02, /**< Incomplete list of 16-bit Service IDs */
COMPLETE_LIST_16BIT_SERVICE_IDS = 0x03, /**< Complete list of 16-bit Service IDs */
INCOMPLETE_LIST_32BIT_SERVICE_IDS = 0x04, /**< Incomplete list of 32-bit Service IDs (not relevant for Bluetooth 4.0) */
COMPLETE_LIST_32BIT_SERVICE_IDS = 0x05, /**< Complete list of 32-bit Service IDs (not relevant for Bluetooth 4.0) */
INCOMPLETE_LIST_128BIT_SERVICE_IDS = 0x06, /**< Incomplete list of 128-bit Service IDs */
COMPLETE_LIST_128BIT_SERVICE_IDS = 0x07, /**< Complete list of 128-bit Service IDs */
SHORTENED_LOCAL_NAME = 0x08, /**< Shortened Local Name */
COMPLETE_LOCAL_NAME = 0x09, /**< Complete Local Name */
TX_POWER_LEVEL = 0x0A, /**< TX Power Level (in dBm) */
DEVICE_ID = 0x10, /**< Device ID */
SLAVE_CONNECTION_INTERVAL_RANGE = 0x12, /**< Slave Connection Interval Range */
SERVICE_DATA = 0x16, /**< Service Data */
APPEARANCE = 0x19, /**< \ref Appearance */
ADVERTISING_INTERVAL = 0x1A, /**< Advertising Interval */
MANUFACTURER_SPECIFIC_DATA = 0xFF /**< Manufacturer Specific Data */
FLAGS = 0x01, /**< \ref
*Flags */
INCOMPLETE_LIST_16BIT_SERVICE_IDS = 0x02, /**<
*Incomplete
*list of
*16-bit
*Service IDs
**/
COMPLETE_LIST_16BIT_SERVICE_IDS = 0x03, /**< Complete
*list of
*16-bit
*Service IDs
**/
INCOMPLETE_LIST_32BIT_SERVICE_IDS = 0x04, /**<
*Incomplete
*list of
*32-bit
*Service IDs
*(not
*relevant for
*Bluetooth
*4.0) */
COMPLETE_LIST_32BIT_SERVICE_IDS = 0x05, /**< Complete
*list of
*32-bit
*Service IDs
*(not
*relevant for
*Bluetooth
*4.0) */
INCOMPLETE_LIST_128BIT_SERVICE_IDS = 0x06, /**<
*Incomplete
*list of
*128-bit
*Service IDs
**/
COMPLETE_LIST_128BIT_SERVICE_IDS = 0x07, /**< Complete
*list of
*128-bit
*Service IDs
**/
SHORTENED_LOCAL_NAME = 0x08, /**< Shortened
*Local Name
**/
COMPLETE_LOCAL_NAME = 0x09, /**< Complete
*Local Name
**/
TX_POWER_LEVEL = 0x0A, /**< TX Power
*Level (in
*dBm) */
DEVICE_ID = 0x10, /**< Device ID
**/
SLAVE_CONNECTION_INTERVAL_RANGE = 0x12, /**< Slave
*Connection
*Interval
*Range */
SERVICE_DATA = 0x16, /**< Service
*Data */
APPEARANCE = 0x19, /**< \ref
*Appearance
**/
ADVERTISING_INTERVAL = 0x1A, /**<
*Advertising
*Interval */
MANUFACTURER_SPECIFIC_DATA = 0xFF /**<
*Manufacturer
*Specific
*Data */
};
/**********************************************************************/
/*!
\brief
A list of values for the FLAGS AD Type
\note
You can use more than one value in the FLAGS AD Type (ex.
LE_GENERAL_DISCOVERABLE and BREDR_NOT_SUPPORTED).
\par Source
\li \c Bluetooth Core Specification 4.0 (Vol. 3), Part C, Section 18.1
*/
/**********************************************************************/
enum Flags
{
LE_LIMITED_DISCOVERABLE = 0x01, /**< Peripheral device is discoverable for a limited period of time */
LE_GENERAL_DISCOVERABLE = 0x02, /**< Peripheral device is discoverable at any moment */
BREDR_NOT_SUPPORTED = 0x04, /**< Peripheral device is LE only */
SIMULTANEOUS_LE_BREDR_C = 0x08, /**< Not relevant - central mode only */
SIMULTANEOUS_LE_BREDR_H = 0x10 /**< Not relevant - central mode only */
LE_LIMITED_DISCOVERABLE = 0x01, /**<
*Peripheral
*device is
*discoverable
*for a
*limited
*period of
*time */
LE_GENERAL_DISCOVERABLE = 0x02, /**<
*Peripheral
*device is
*discoverable
*at any
*moment */
BREDR_NOT_SUPPORTED = 0x04, /**<
*Peripheral
*device is LE
*only */
SIMULTANEOUS_LE_BREDR_C = 0x08, /**< Not
*relevant -
*central mode
*only */
SIMULTANEOUS_LE_BREDR_H = 0x10 /**< Not
*relevant -
*central mode
*only */
};
/**********************************************************************/
@ -132,7 +205,7 @@ class GapAdvertisingData
\brief
A list of values for the APPEARANCE AD Type, which describes the
physical shape or appearance of the device
\par Source
\li \c Bluetooth Core Specification Supplement, Part A, Section 1.12
\li \c Bluetooth Core Specification 4.0 (Vol. 3), Part C, Section 12.2
@ -141,54 +214,137 @@ class GapAdvertisingData
/**********************************************************************/
enum Appearance
{
UNKNOWN = 0, /**< Unknown of unspecified appearance type */
GENERIC_PHONE = 64, /**< Generic Phone */
GENERIC_COMPUTER = 128, /**< Generic Computer */
GENERIC_WATCH = 192, /**< Generic Watch */
WATCH_SPORTS_WATCH = 193, /**< Sports Watch */
GENERIC_CLOCK = 256, /**< Generic Clock */
GENERIC_DISPLAY = 320, /**< Generic Display */
GENERIC_REMOTE_CONTROL = 384, /**< Generic Remote Control */
GENERIC_EYE_GLASSES = 448, /**< Generic Eye Glasses */
GENERIC_TAG = 512, /**< Generic Tag */
GENERIC_KEYRING = 576, /**< Generic Keyring */
GENERIC_MEDIA_PLAYER = 640, /**< Generic Media Player */
GENERIC_BARCODE_SCANNER = 704, /**< Generic Barcode Scanner */
GENERIC_THERMOMETER = 768, /**< Generic Thermometer */
THERMOMETER_EAR = 769, /**< Ear Thermometer */
GENERIC_HEART_RATE_SENSOR = 832, /**< Generic Heart Rate Sensor */
HEART_RATE_SENSOR_HEART_RATE_BELT = 833, /**< Belt Heart Rate Sensor */
GENERIC_BLOOD_PRESSURE = 896, /**< Generic Blood Pressure */
BLOOD_PRESSURE_ARM = 897, /**< Arm Blood Pressure */
BLOOD_PRESSURE_WRIST = 898, /**< Wrist Blood Pressure */
HUMAN_INTERFACE_DEVICE_HID = 960, /**< Human Interface Device (HID) */
KEYBOARD = 961, /**< Keyboard */
MOUSE = 962, /**< Mouse */
JOYSTICK = 963, /**< Joystick */
GAMEPAD = 964, /**< Gamepad */
DIGITIZER_TABLET = 965, /**< Digitizer Tablet */
CARD_READER = 966, /**< Card Read */
DIGITAL_PEN = 967, /**< Digital Pen */
BARCODE_SCANNER = 968, /**< Barcode Scanner */
GENERIC_GLUCOSE_METER = 1024, /**< Generic Glucose Meter */
GENERIC_RUNNING_WALKING_SENSOR = 1088, /**< Generic Running/Walking Sensor */
RUNNING_WALKING_SENSOR_IN_SHOE = 1089, /**< In Shoe Running/Walking Sensor */
RUNNING_WALKING_SENSOR_ON_SHOE = 1090, /**< On Shoe Running/Walking Sensor */
RUNNING_WALKING_SENSOR_ON_HIP = 1091, /**< On Hip Running/Walking Sensor */
GENERIC_CYCLING = 1152, /**< Generic Cycling */
CYCLING_CYCLING_COMPUTER = 1153, /**< Cycling Computer */
CYCLING_SPEED_SENSOR = 1154, /**< Cycling Speed Senspr */
CYCLING_CADENCE_SENSOR = 1155, /**< Cycling Cadence Sensor */
CYCLING_POWER_SENSOR = 1156, /**< Cycling Power Sensor */
CYCLING_SPEED_AND_CADENCE_SENSOR = 1157, /**< Cycling Speed and Cadence Sensor */
PULSE_OXIMETER_GENERIC = 3136, /**< Generic Pulse Oximeter */
PULSE_OXIMETER_FINGERTIP = 3137, /**< Fingertip Pulse Oximeter */
PULSE_OXIMETER_WRIST_WORN = 3138, /**< Wrist Worn Pulse Oximeter */
OUTDOOR_GENERIC = 5184, /**< Generic Outdoor */
OUTDOOR_LOCATION_DISPLAY_DEVICE = 5185, /**< Outdoor Location Display Device */
OUTDOOR_LOCATION_AND_NAVIGATION_DISPLAY_DEVICE = 5186, /**< Outdoor Location and Navigation Display Device */
OUTDOOR_LOCATION_POD = 5187, /**< Outdoor Location Pod */
OUTDOOR_LOCATION_AND_NAVIGATION_POD = 5188 /**< Outdoor Location and Navigation Pod */
UNKNOWN = 0, /**< Unknown
*of
*unspecified
*appearance
*type */
GENERIC_PHONE = 64, /**< Generic
*Phone */
GENERIC_COMPUTER = 128, /**< Generic
*Computer */
GENERIC_WATCH = 192, /**< Generic
*Watch */
WATCH_SPORTS_WATCH = 193, /**< Sports
*Watch */
GENERIC_CLOCK = 256, /**< Generic
*Clock */
GENERIC_DISPLAY = 320, /**< Generic
*Display */
GENERIC_REMOTE_CONTROL = 384, /**< Generic
*Remote
*Control */
GENERIC_EYE_GLASSES = 448, /**< Generic
*Eye Glasses
**/
GENERIC_TAG = 512, /**< Generic
*Tag */
GENERIC_KEYRING = 576, /**< Generic
*Keyring */
GENERIC_MEDIA_PLAYER = 640, /**< Generic
*Media Player
**/
GENERIC_BARCODE_SCANNER = 704, /**< Generic
*Barcode
*Scanner */
GENERIC_THERMOMETER = 768, /**< Generic
*Thermometer
**/
THERMOMETER_EAR = 769, /**< Ear
*Thermometer
**/
GENERIC_HEART_RATE_SENSOR = 832, /**< Generic
*Heart Rate
*Sensor */
HEART_RATE_SENSOR_HEART_RATE_BELT = 833, /**< Belt
*Heart Rate
*Sensor */
GENERIC_BLOOD_PRESSURE = 896, /**< Generic
*Blood
*Pressure */
BLOOD_PRESSURE_ARM = 897, /**< Arm Blood
*Pressure */
BLOOD_PRESSURE_WRIST = 898, /**< Wrist
*Blood
*Pressure */
HUMAN_INTERFACE_DEVICE_HID = 960, /**< Human
*Interface
*Device (HID)
**/
KEYBOARD = 961, /**< Keyboard
**/
MOUSE = 962, /**< Mouse */
JOYSTICK = 963, /**< Joystick
**/
GAMEPAD = 964, /**< Gamepad
**/
DIGITIZER_TABLET = 965, /**< Digitizer
*Tablet */
CARD_READER = 966, /**< Card Read
**/
DIGITAL_PEN = 967, /**< Digital
*Pen */
BARCODE_SCANNER = 968, /**< Barcode
*Scanner */
GENERIC_GLUCOSE_METER = 1024, /**< Generic
*Glucose
*Meter */
GENERIC_RUNNING_WALKING_SENSOR = 1088, /**< Generic
*Running/Walking
*Sensor */
RUNNING_WALKING_SENSOR_IN_SHOE = 1089, /**< In Shoe
*Running/Walking
*Sensor */
RUNNING_WALKING_SENSOR_ON_SHOE = 1090, /**< On Shoe
*Running/Walking
*Sensor */
RUNNING_WALKING_SENSOR_ON_HIP = 1091, /**< On Hip
*Running/Walking
*Sensor */
GENERIC_CYCLING = 1152, /**< Generic
*Cycling */
CYCLING_CYCLING_COMPUTER = 1153, /**< Cycling
*Computer */
CYCLING_SPEED_SENSOR = 1154, /**< Cycling
*Speed Senspr
**/
CYCLING_CADENCE_SENSOR = 1155, /**< Cycling
*Cadence
*Sensor */
CYCLING_POWER_SENSOR = 1156, /**< Cycling
*Power Sensor
**/
CYCLING_SPEED_AND_CADENCE_SENSOR = 1157, /**< Cycling
*Speed and
*Cadence
*Sensor */
PULSE_OXIMETER_GENERIC = 3136, /**< Generic
*Pulse
*Oximeter */
PULSE_OXIMETER_FINGERTIP = 3137, /**< Fingertip
*Pulse
*Oximeter */
PULSE_OXIMETER_WRIST_WORN = 3138, /**< Wrist
*Worn Pulse
*Oximeter */
OUTDOOR_GENERIC = 5184, /**< Generic
*Outdoor */
OUTDOOR_LOCATION_DISPLAY_DEVICE = 5185, /**< Outdoor
*Location
*Display
*Device */
OUTDOOR_LOCATION_AND_NAVIGATION_DISPLAY_DEVICE = 5186, /**< Outdoor
*Location and
*Navigation
*Display
*Device */
OUTDOOR_LOCATION_POD = 5187, /**< Outdoor
*Location Pod
**/
OUTDOOR_LOCATION_AND_NAVIGATION_POD = 5188 /**< Outdoor
*Location and
*Navigation
*Pod */
};
GapAdvertisingData(void);
@ -199,14 +355,14 @@ class GapAdvertisingData
ble_error_t addFlags(Flags flag = LE_GENERAL_DISCOVERABLE);
ble_error_t addTxPower(int8_t txPower);
void clear(void);
uint8_t * getPayload(void);
uint8_t *getPayload(void);
uint8_t getPayloadLen(void);
uint16_t getAppearance(void);
private:
private:
uint8_t _payload[GAP_ADVERTISING_DATA_MAX_PAYLOAD];
uint8_t _payloadLen;
uint16_t _appearance;
};
#endif
#endif // ifndef __GAP_ADVERTISING_DATA_H__

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <stdio.h>
#include <string.h>
@ -31,11 +31,11 @@
\par ADV_NON_CONNECTABLE_UNDIRECTED
All connections to the peripheral device will be refused.
\par ADV_CONNECTABLE_DIRECTED
Only connections from a pre-defined central device will be
accepted.
\par ADV_CONNECTABLE_UNDIRECTED
Any central device can connect to this peripheral.
@ -43,7 +43,7 @@
Any central device can connect to this peripheral, and
the secondary Scan Response payload will be included or
available to central devices.
\par
See Bluetooth Core Specification 4.0 (Vol. 3), Part C,
Section 9.3 and Core Specification 4.0 (Vol. 6), Part B,
@ -60,19 +60,19 @@
Increasing this value will allow central devices to detect
your peripheral faster at the expense of more power being
used by the radio due to the higher data transmit rate.
\par
This field must be set to 0 if connectionMode is equal
to ADV_CONNECTABLE_DIRECTED
\par
See Bluetooth Core Specification, Vol 3., Part C,
Appendix A for suggested advertising intervals.
\param[in] timeout
Advertising timeout between 0x1 and 0x3FFF (1 and 16383)
in seconds. Enter 0 to disable the advertising timeout.
\par EXAMPLE
\code
@ -80,49 +80,40 @@
\endcode
*/
/**************************************************************************/
GapAdvertisingParams::GapAdvertisingParams(AdvertisingType advType, uint16_t interval, uint16_t timeout)
GapAdvertisingParams::GapAdvertisingParams(AdvertisingType advType,
uint16_t interval,
uint16_t timeout)
{
_advType = advType;
_advType = advType;
_interval = interval;
_timeout = timeout;
_timeout = timeout;
/* Interval checks */
if (_advType == ADV_CONNECTABLE_DIRECTED)
{
if (_advType == ADV_CONNECTABLE_DIRECTED) {
/* Interval must be 0 in directed connectable mode */
_interval = 0;
}
else if (_advType == ADV_NON_CONNECTABLE_UNDIRECTED)
{
} else if (_advType == ADV_NON_CONNECTABLE_UNDIRECTED) {
/* Min interval is slightly larger than in other modes */
if (_interval < GAP_ADV_PARAMS_INTERVAL_MIN_NONCON)
{
if (_interval < GAP_ADV_PARAMS_INTERVAL_MIN_NONCON) {
_interval = GAP_ADV_PARAMS_INTERVAL_MIN_NONCON;
}
if (_interval > GAP_ADV_PARAMS_INTERVAL_MAX)
{
if (_interval > GAP_ADV_PARAMS_INTERVAL_MAX) {
_interval = GAP_ADV_PARAMS_INTERVAL_MAX;
}
}
else
{
} else {
/* Stay within interval limits */
if (_interval < GAP_ADV_PARAMS_INTERVAL_MIN)
{
if (_interval < GAP_ADV_PARAMS_INTERVAL_MIN) {
_interval = GAP_ADV_PARAMS_INTERVAL_MIN;
}
if (_interval > GAP_ADV_PARAMS_INTERVAL_MAX)
{
if (_interval > GAP_ADV_PARAMS_INTERVAL_MAX) {
_interval = GAP_ADV_PARAMS_INTERVAL_MAX;
}
}
/* Timeout checks */
if (timeout)
{
if (timeout) {
/* Stay within timeout limits */
if (_timeout > GAP_ADV_PARAMS_TIMEOUT_MAX)
{
if (_timeout > GAP_ADV_PARAMS_TIMEOUT_MAX) {
_timeout = GAP_ADV_PARAMS_TIMEOUT_MAX;
}
}

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __GAP_ADVERTISING_PARAMS_H__
#define __GAP_ADVERTISING_PARAMS_H__
@ -34,22 +34,22 @@
\par
See the following for more information on advertising types:
\li \c Bluetooth Core Specification 4.0 (Vol. 6), Part B, Section 2.3.1
\li \c Bluetooth Core Specification 4.0 (Vol. 3), Part C, Section 9.3
\par EXAMPLE
\code
// ToDo
\endcode
*/
/**************************************************************************/
class GapAdvertisingParams
{
public:
public:
/**************************************************************************/
/*!
\brief
@ -58,32 +58,40 @@ class GapAdvertisingParams
\par
See the following for more information on advertising types:
\li \c Bluetooth Core Specification 4.0 (Vol. 6), Part B, Section 2.3.1
\li \c Bluetooth Core Specification 4.0 (Vol. 3), Part C, Section 9.3
*/
/**************************************************************************/
enum AdvertisingType
{
ADV_CONNECTABLE_UNDIRECTED, /**< Vol 3, Part C, Section 9.3.4 and Vol 6, Part B, Section 2.3.1.1 */
ADV_CONNECTABLE_DIRECTED, /**< Vol 3, Part C, Section 9.3.3 and Vol 6, Part B, Section 2.3.1.2 */
ADV_SCANNABLE_UNDIRECTED, /**< Include support for Scan Response payloads, see Vol 6, Part B, Section 2.3.1.4 */
ADV_NON_CONNECTABLE_UNDIRECTED /**< Vol 3, Part C, Section 9.3.2 and Vol 6, Part B, Section 2.3.1.3 */
ADV_CONNECTABLE_UNDIRECTED, /**< Vol 3, Part C, Section 9.3.4 and
*Vol 6, Part B, Section 2.3.1.1 */
ADV_CONNECTABLE_DIRECTED, /**< Vol 3, Part C, Section 9.3.3 and
*Vol 6, Part B, Section 2.3.1.2 */
ADV_SCANNABLE_UNDIRECTED, /**< Include support for Scan Response
*payloads, see Vol 6, Part B, Section
*2.3.1.4 */
ADV_NON_CONNECTABLE_UNDIRECTED /**< Vol 3, Part C, Section 9.3.2 and
*Vol 6, Part B, Section 2.3.1.3 */
};
GapAdvertisingParams(AdvertisingType advType = GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED,
uint16_t interval = GAP_ADV_PARAMS_INTERVAL_MIN_NONCON,
uint16_t timeout = 0);
GapAdvertisingParams(
AdvertisingType advType =
GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED,
uint16_t interval =
GAP_ADV_PARAMS_INTERVAL_MIN_NONCON,
uint16_t timeout = 0);
virtual ~GapAdvertisingParams(void);
virtual AdvertisingType getAdvertisingType(void);
virtual uint16_t getInterval(void);
virtual uint16_t getTimeout(void);
private:
AdvertisingType _advType;
uint16_t _interval;
uint16_t _timeout;
private:
AdvertisingType _advType;
uint16_t _interval;
uint16_t _timeout;
};
#endif
#endif // ifndef __GAP_ADVERTISING_PARAMS_H__

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <stdio.h>
#include <string.h>
@ -23,7 +23,7 @@
/*!
@brief Creates a new GattCharacteristic using the specified 16-bit
UUID, value length, and properties
@note The UUID value must be unique in the service and is normally >1
@param[in] id
@ -42,17 +42,20 @@
// UUID = 0x2A19, Min length 2, Max len = 2, Properties = write
GattCharacteristic c = GattCharacteristic( 0x2A19, 2, 2, BLE_GATT_CHAR_PROPERTIES_WRITE );
@endcode
*/
/**************************************************************************/
GattCharacteristic::GattCharacteristic(uint16_t id, uint16_t minLen, uint16_t maxLen, uint8_t props)
GattCharacteristic::GattCharacteristic(uint16_t id,
uint16_t minLen,
uint16_t maxLen,
uint8_t props)
{
uuid = id;
memcpy(&properties, &props, 1);
lenMin = minLen;
lenMax = maxLen;
// handle = 0;
// handle = 0;
}
/**************************************************************************/

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __GATT_CHARACTERISTIC_H__
#define __GATT_CHARACTERISTIC_H__
@ -31,90 +31,90 @@
/**************************************************************************/
class GattCharacteristic
{
public:
enum
{
UUID_BATTERY_LEVEL_STATE_CHAR = 0x2A1B,
UUID_BATTERY_POWER_STATE_CHAR = 0x2A1A,
UUID_REMOVABLE_CHAR = 0x2A3A,
UUID_SERVICE_REQUIRED_CHAR = 0x2A3B,
UUID_ALERT_CATEGORY_ID_CHAR = 0x2A43,
UUID_ALERT_CATEGORY_ID_BIT_MASK_CHAR = 0x2A42,
UUID_ALERT_LEVEL_CHAR = 0x2A06,
UUID_ALERT_NOTIFICATION_CONTROL_POINT_CHAR = 0x2A44,
UUID_ALERT_STATUS_CHAR = 0x2A3F,
UUID_BATTERY_LEVEL_CHAR = 0x2A19,
UUID_BLOOD_PRESSURE_FEATURE_CHAR = 0x2A49,
UUID_BLOOD_PRESSURE_MEASUREMENT_CHAR = 0x2A35,
UUID_BODY_SENSOR_LOCATION_CHAR = 0x2A38,
UUID_BOOT_KEYBOARD_INPUT_REPORT_CHAR = 0x2A22,
UUID_BOOT_KEYBOARD_OUTPUT_REPORT_CHAR = 0x2A32,
UUID_BOOT_MOUSE_INPUT_REPORT_CHAR = 0x2A33,
UUID_CURRENT_TIME_CHAR = 0x2A2B,
UUID_DATE_TIME_CHAR = 0x2A08,
UUID_DAY_DATE_TIME_CHAR = 0x2A0A,
UUID_DAY_OF_WEEK_CHAR = 0x2A09,
UUID_DST_OFFSET_CHAR = 0x2A0D,
UUID_EXACT_TIME_256_CHAR = 0x2A0C,
UUID_FIRMWARE_REVISION_STRING_CHAR = 0x2A26,
UUID_GLUCOSE_FEATURE_CHAR = 0x2A51,
UUID_GLUCOSE_MEASUREMENT_CHAR = 0x2A18,
UUID_GLUCOSE_MEASUREMENT_CONTEXT_CHAR = 0x2A34,
UUID_HARDWARE_REVISION_STRING_CHAR = 0x2A27,
UUID_HEART_RATE_CONTROL_POINT_CHAR = 0x2A39,
UUID_HEART_RATE_MEASUREMENT_CHAR = 0x2A37,
UUID_HID_CONTROL_POINT_CHAR = 0x2A4C,
UUID_HID_INFORMATION_CHAR = 0x2A4A,
UUID_IEEE_REGULATORY_CERTIFICATION_DATA_LIST_CHAR = 0x2A2A,
UUID_INTERMEDIATE_CUFF_PRESSURE_CHAR = 0x2A36,
UUID_INTERMEDIATE_TEMPERATURE_CHAR = 0x2A1E,
UUID_LOCAL_TIME_INFORMATION_CHAR = 0x2A0F,
UUID_MANUFACTURER_NAME_STRING_CHAR = 0x2A29,
UUID_MEASUREMENT_INTERVAL_CHAR = 0x2A21,
UUID_MODEL_NUMBER_STRING_CHAR = 0x2A24,
UUID_UNREAD_ALERT_CHAR = 0x2A45,
UUID_NEW_ALERT_CHAR = 0x2A46,
UUID_PNP_ID_CHAR = 0x2A50,
UUID_PROTOCOL_MODE_CHAR = 0x2A4E,
UUID_RECORD_ACCESS_CONTROL_POINT_CHAR = 0x2A52,
UUID_REFERENCE_TIME_INFORMATION_CHAR = 0x2A14,
UUID_REPORT_CHAR = 0x2A4D,
UUID_REPORT_MAP_CHAR = 0x2A4B,
UUID_RINGER_CONTROL_POINT_CHAR = 0x2A40,
UUID_RINGER_SETTING_CHAR = 0x2A41,
UUID_SCAN_INTERVAL_WINDOW_CHAR = 0x2A4F,
UUID_SCAN_REFRESH_CHAR = 0x2A31,
UUID_SERIAL_NUMBER_STRING_CHAR = 0x2A25,
UUID_SOFTWARE_REVISION_STRING_CHAR = 0x2A28,
UUID_SUPPORTED_NEW_ALERT_CATEGORY_CHAR = 0x2A47,
UUID_SUPPORTED_UNREAD_ALERT_CATEGORY_CHAR = 0x2A48,
UUID_SYSTEM_ID_CHAR = 0x2A23,
UUID_TEMPERATURE_MEASUREMENT_CHAR = 0x2A1C,
UUID_TEMPERATURE_TYPE_CHAR = 0x2A1D,
UUID_TIME_ACCURACY_CHAR = 0x2A12,
UUID_TIME_SOURCE_CHAR = 0x2A13,
UUID_TIME_UPDATE_CONTROL_POINT_CHAR = 0x2A16,
UUID_TIME_UPDATE_STATE_CHAR = 0x2A17,
UUID_TIME_WITH_DST_CHAR = 0x2A11,
UUID_TIME_ZONE_CHAR = 0x2A0E,
UUID_TX_POWER_LEVEL_CHAR = 0x2A07,
UUID_CSC_FEATURE_CHAR = 0x2A5C,
UUID_CSC_MEASUREMENT_CHAR = 0x2A5B,
UUID_RSC_FEATURE_CHAR = 0x2A54,
UUID_RSC_MEASUREMENT_CHAR = 0x2A53,
};
public:
enum
{
UUID_BATTERY_LEVEL_STATE_CHAR = 0x2A1B,
UUID_BATTERY_POWER_STATE_CHAR = 0x2A1A,
UUID_REMOVABLE_CHAR = 0x2A3A,
UUID_SERVICE_REQUIRED_CHAR = 0x2A3B,
UUID_ALERT_CATEGORY_ID_CHAR = 0x2A43,
UUID_ALERT_CATEGORY_ID_BIT_MASK_CHAR = 0x2A42,
UUID_ALERT_LEVEL_CHAR = 0x2A06,
UUID_ALERT_NOTIFICATION_CONTROL_POINT_CHAR = 0x2A44,
UUID_ALERT_STATUS_CHAR = 0x2A3F,
UUID_BATTERY_LEVEL_CHAR = 0x2A19,
UUID_BLOOD_PRESSURE_FEATURE_CHAR = 0x2A49,
UUID_BLOOD_PRESSURE_MEASUREMENT_CHAR = 0x2A35,
UUID_BODY_SENSOR_LOCATION_CHAR = 0x2A38,
UUID_BOOT_KEYBOARD_INPUT_REPORT_CHAR = 0x2A22,
UUID_BOOT_KEYBOARD_OUTPUT_REPORT_CHAR = 0x2A32,
UUID_BOOT_MOUSE_INPUT_REPORT_CHAR = 0x2A33,
UUID_CURRENT_TIME_CHAR = 0x2A2B,
UUID_DATE_TIME_CHAR = 0x2A08,
UUID_DAY_DATE_TIME_CHAR = 0x2A0A,
UUID_DAY_OF_WEEK_CHAR = 0x2A09,
UUID_DST_OFFSET_CHAR = 0x2A0D,
UUID_EXACT_TIME_256_CHAR = 0x2A0C,
UUID_FIRMWARE_REVISION_STRING_CHAR = 0x2A26,
UUID_GLUCOSE_FEATURE_CHAR = 0x2A51,
UUID_GLUCOSE_MEASUREMENT_CHAR = 0x2A18,
UUID_GLUCOSE_MEASUREMENT_CONTEXT_CHAR = 0x2A34,
UUID_HARDWARE_REVISION_STRING_CHAR = 0x2A27,
UUID_HEART_RATE_CONTROL_POINT_CHAR = 0x2A39,
UUID_HEART_RATE_MEASUREMENT_CHAR = 0x2A37,
UUID_HID_CONTROL_POINT_CHAR = 0x2A4C,
UUID_HID_INFORMATION_CHAR = 0x2A4A,
UUID_IEEE_REGULATORY_CERTIFICATION_DATA_LIST_CHAR = 0x2A2A,
UUID_INTERMEDIATE_CUFF_PRESSURE_CHAR = 0x2A36,
UUID_INTERMEDIATE_TEMPERATURE_CHAR = 0x2A1E,
UUID_LOCAL_TIME_INFORMATION_CHAR = 0x2A0F,
UUID_MANUFACTURER_NAME_STRING_CHAR = 0x2A29,
UUID_MEASUREMENT_INTERVAL_CHAR = 0x2A21,
UUID_MODEL_NUMBER_STRING_CHAR = 0x2A24,
UUID_UNREAD_ALERT_CHAR = 0x2A45,
UUID_NEW_ALERT_CHAR = 0x2A46,
UUID_PNP_ID_CHAR = 0x2A50,
UUID_PROTOCOL_MODE_CHAR = 0x2A4E,
UUID_RECORD_ACCESS_CONTROL_POINT_CHAR = 0x2A52,
UUID_REFERENCE_TIME_INFORMATION_CHAR = 0x2A14,
UUID_REPORT_CHAR = 0x2A4D,
UUID_REPORT_MAP_CHAR = 0x2A4B,
UUID_RINGER_CONTROL_POINT_CHAR = 0x2A40,
UUID_RINGER_SETTING_CHAR = 0x2A41,
UUID_SCAN_INTERVAL_WINDOW_CHAR = 0x2A4F,
UUID_SCAN_REFRESH_CHAR = 0x2A31,
UUID_SERIAL_NUMBER_STRING_CHAR = 0x2A25,
UUID_SOFTWARE_REVISION_STRING_CHAR = 0x2A28,
UUID_SUPPORTED_NEW_ALERT_CATEGORY_CHAR = 0x2A47,
UUID_SUPPORTED_UNREAD_ALERT_CATEGORY_CHAR = 0x2A48,
UUID_SYSTEM_ID_CHAR = 0x2A23,
UUID_TEMPERATURE_MEASUREMENT_CHAR = 0x2A1C,
UUID_TEMPERATURE_TYPE_CHAR = 0x2A1D,
UUID_TIME_ACCURACY_CHAR = 0x2A12,
UUID_TIME_SOURCE_CHAR = 0x2A13,
UUID_TIME_UPDATE_CONTROL_POINT_CHAR = 0x2A16,
UUID_TIME_UPDATE_STATE_CHAR = 0x2A17,
UUID_TIME_WITH_DST_CHAR = 0x2A11,
UUID_TIME_ZONE_CHAR = 0x2A0E,
UUID_TX_POWER_LEVEL_CHAR = 0x2A07,
UUID_CSC_FEATURE_CHAR = 0x2A5C,
UUID_CSC_MEASUREMENT_CHAR = 0x2A5B,
UUID_RSC_FEATURE_CHAR = 0x2A54,
UUID_RSC_MEASUREMENT_CHAR = 0x2A53,
};
/**************************************************************************/
/*!
\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
{
/**************************************************************************/
/*!
\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 */
@ -224,95 +224,204 @@ class GattCharacteristic
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 */
uint16_t handle;
uint8_t properties;
private:
} 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 */
uint16_t handle;
uint8_t properties;
private:
};
#endif
#endif // ifndef __GATT_CHARACTERISTIC_H__

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <stdio.h>
#include <string.h>
@ -23,7 +23,7 @@
/**************************************************************************/
/*!
@brief Creates a new GattService using the specified 128-bit UUID
@note The UUID value must be unique on the device
@param[in] uuid
@ -32,7 +32,7 @@
@section EXAMPLE
@code
@endcode
*/
/**************************************************************************/
@ -40,13 +40,13 @@ GattService::GattService(uint8_t base_uuid[16])
{
primaryServiceID.update(base_uuid);
characteristicCount = 0;
handle = 0;
handle = 0;
}
/**************************************************************************/
/*!
@brief Creates a new GattService using the specified 16-bit BLE UUID
@param[in] ble_uuid
The standardised 16-bit (2 byte) BLE UUID to use for this
characteristic
@ -54,7 +54,7 @@ GattService::GattService(uint8_t base_uuid[16])
@section EXAMPLE
@code
@endcode
*/
/**************************************************************************/
@ -62,7 +62,7 @@ GattService::GattService(uint16_t ble_uuid)
{
primaryServiceID.update( ble_uuid );
characteristicCount = 0;
handle = 0;
handle = 0;
}
/**************************************************************************/
@ -77,10 +77,10 @@ GattService::~GattService(void)
/**************************************************************************/
/*!
@brief Adds a GattCharacterisic to the service.
@note This function will not update the .handle field in the
GattCharacteristic. This value is updated when the parent
service is added via the radio driver.
service is added via the radio driver.
@param[in] characteristic
The GattCharacteristic object describing the characteristic
@ -94,7 +94,7 @@ GattService::~GattService(void)
@section EXAMPLE
@code