YUFEI JIANG / BLE_API_Tiny_BLE

Dependents:   CSSE4011_BLE_IMU

Fork of BLE_API by Bluetooth Low Energy

Committer:
ktownsend
Date:
Tue Jan 07 10:50:31 2014 +0000
Revision:
21:5442f7c70e71
Parent:
19:a6f33421746c
Child:
27:4a83843f04b0
Improved some doxygen comment

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ktownsend 2:ffc5216bd2cc 1 #ifndef __GAP_ADVERTISING_DATA_H__
ktownsend 2:ffc5216bd2cc 2 #define __GAP_ADVERTISING_DATA_H__
ktownsend 2:ffc5216bd2cc 3
ktownsend 2:ffc5216bd2cc 4 #include "blecommon.h"
ktownsend 2:ffc5216bd2cc 5
ktownsend 3:46de446e82ed 6 #define GAP_ADVERTISING_DATA_MAX_PAYLOAD (31)
ktownsend 3:46de446e82ed 7
ktownsend 3:46de446e82ed 8 /**************************************************************************/
ktownsend 3:46de446e82ed 9 /*!
ktownsend 18:86fe1e247a54 10 \brief
ktownsend 3:46de446e82ed 11 This class provides several helper functions to generate properly
ktownsend 3:46de446e82ed 12 formatted GAP Advertising and Scan Response data payloads
ktownsend 4:50a31ff5f974 13
ktownsend 18:86fe1e247a54 14 \note
ktownsend 18:86fe1e247a54 15 See Bluetooth Specification 4.0 (Vol. 3), Part C, Section 11 and 18
ktownsend 4:50a31ff5f974 16 for further information on Advertising and Scan Response data.
ktownsend 4:50a31ff5f974 17
ktownsend 18:86fe1e247a54 18 \par Advertising and Scan Response Payloads
ktownsend 3:46de446e82ed 19 Advertising data and Scan Response data are organized around a set of
ktownsend 4:50a31ff5f974 20 data types called 'AD types' in Bluetooth 4.0 (see the Bluetooth Core
ktownsend 4:50a31ff5f974 21 Specification v4.0, Vol. 3, Part C, Sections 11 and 18).
ktownsend 4:50a31ff5f974 22
ktownsend 18:86fe1e247a54 23 \par
ktownsend 3:46de446e82ed 24 Each AD type has it's own standardized 'assigned number', as defined
ktownsend 3:46de446e82ed 25 by the Bluetooth SIG:
ktownsend 3:46de446e82ed 26 https://www.bluetooth.org/en-us/specification/assigned-numbers/generic-access-profile
ktownsend 3:46de446e82ed 27
ktownsend 18:86fe1e247a54 28 \par
ktownsend 3:46de446e82ed 29 For convenience sake, all appropriate AD types have been encapsulated
ktownsend 18:86fe1e247a54 30 into GapAdvertisingData::DataType.
ktownsend 3:46de446e82ed 31
ktownsend 18:86fe1e247a54 32 \par
ktownsend 4:50a31ff5f974 33 Before the AD Types and their payload (if any) can be inserted into
ktownsend 4:50a31ff5f974 34 the Advertising or Scan Response frames, they need to be formatted as
ktownsend 4:50a31ff5f974 35 follows:
ktownsend 3:46de446e82ed 36
ktownsend 18:86fe1e247a54 37 \li \c Record length (1 byte)
ktownsend 18:86fe1e247a54 38 \li \c AD Type (1 byte)
ktownsend 18:86fe1e247a54 39 \li \c AD payload (optional, only present if record length > 1)
ktownsend 5:7635f81a8e09 40
ktownsend 18:86fe1e247a54 41 \par
ktownsend 5:7635f81a8e09 42 This class takes care of properly formatting the payload, performs
ktownsend 5:7635f81a8e09 43 some basic checks on the payload length, and tries to avoid common
ktownsend 5:7635f81a8e09 44 errors like adding an exclusive AD field twice in the Advertising
ktownsend 5:7635f81a8e09 45 or Scan Response payload.
ktownsend 3:46de446e82ed 46
ktownsend 18:86fe1e247a54 47 \par EXAMPLE
ktownsend 5:7635f81a8e09 48
ktownsend 18:86fe1e247a54 49 \code
ktownsend 3:46de446e82ed 50
ktownsend 5:7635f81a8e09 51 // ToDo
ktownsend 5:7635f81a8e09 52
ktownsend 18:86fe1e247a54 53 \endcode
ktownsend 3:46de446e82ed 54 */
ktownsend 3:46de446e82ed 55 /**************************************************************************/
ktownsend 2:ffc5216bd2cc 56 class GapAdvertisingData
ktownsend 2:ffc5216bd2cc 57 {
ktownsend 4:50a31ff5f974 58 public:
ktownsend 19:a6f33421746c 59 /**********************************************************************/
ktownsend 19:a6f33421746c 60 /*!
ktownsend 19:a6f33421746c 61 \brief
ktownsend 19:a6f33421746c 62 A list of Advertising Data types commonly used by peripherals.
ktownsend 19:a6f33421746c 63 These AD types are used to describe the capabilities of the
ktownsend 19:a6f33421746c 64 peripheral, and get inserted inside the advertising or scan
ktownsend 19:a6f33421746c 65 response payloads.
ktownsend 19:a6f33421746c 66
ktownsend 19:a6f33421746c 67 \par Source
ktownsend 19:a6f33421746c 68 \li \c Bluetooth Core Specification 4.0 (Vol. 3), Part C, Section 11, 18
ktownsend 19:a6f33421746c 69 \li \c https://www.bluetooth.org/en-us/specification/assigned-numbers/generic-access-profile
ktownsend 19:a6f33421746c 70 */
ktownsend 19:a6f33421746c 71 /**********************************************************************/
ktownsend 4:50a31ff5f974 72 enum DataType
ktownsend 4:50a31ff5f974 73 {
ktownsend 21:5442f7c70e71 74 FLAGS = 0x01, /**< \ref Flags */
ktownsend 21:5442f7c70e71 75 INCOMPLETE_LIST_16BIT_SERVICE_IDS = 0x02, /**< Incomplete list of 16-bit Service IDs */
ktownsend 21:5442f7c70e71 76 COMPLETE_LIST_16BIT_SERVICE_IDS = 0x03, /**< Complete list of 16-bit Service IDs */
ktownsend 21:5442f7c70e71 77 INCOMPLETE_LIST_32BIT_SERVICE_IDS = 0x04, /**< Incomplete list of 32-bit Service IDs (not relevant for Bluetooth 4.0) */
ktownsend 21:5442f7c70e71 78 COMPLETE_LIST_32BIT_SERVICE_IDS = 0x05, /**< Complete list of 32-bit Service IDs (not relevant for Bluetooth 4.0) */
ktownsend 21:5442f7c70e71 79 INCOMPLETE_LIST_128BIT_SERVICE_IDS = 0x06, /**< Incomplete list of 128-bit Service IDs */
ktownsend 21:5442f7c70e71 80 COMPLETE_LIST_128BIT_SERVICE_IDS = 0x07, /**< Complete list of 128-bit Service IDs */
ktownsend 21:5442f7c70e71 81 SHORTENED_LOCAL_NAME = 0x08, /**< Shortened Local Name */
ktownsend 21:5442f7c70e71 82 COMPLETE_LOCAL_NAME = 0x09, /**< Complete Local Name */
ktownsend 21:5442f7c70e71 83 TX_POWER_LEVEL = 0x0A, /**< TX Power Level (in dBm) */
ktownsend 21:5442f7c70e71 84 DEVICE_ID = 0x10, /**< Device ID */
ktownsend 21:5442f7c70e71 85 SLAVE_CONNECTION_INTERVAL_RANGE = 0x12, /**< Slave Connection Interval Range */
ktownsend 21:5442f7c70e71 86 SERVICE_DATA = 0x16, /**< Service Data */
ktownsend 21:5442f7c70e71 87 APPEARANCE = 0x19, /**< \ref Appearance */
ktownsend 21:5442f7c70e71 88 ADVERTISING_INTERVAL = 0x1A, /**< Advertising Interval */
ktownsend 21:5442f7c70e71 89 MANUFACTURER_SPECIFIC_DATA = 0xFF /**< Manufacturer Specific Data */
ktownsend 4:50a31ff5f974 90 };
ktownsend 4:50a31ff5f974 91
ktownsend 19:a6f33421746c 92 /**********************************************************************/
ktownsend 19:a6f33421746c 93 /*!
ktownsend 19:a6f33421746c 94 \brief
ktownsend 19:a6f33421746c 95 A list of values for the FLAGS AD Type
ktownsend 19:a6f33421746c 96
ktownsend 19:a6f33421746c 97 \note
ktownsend 19:a6f33421746c 98 You can use more than one value in the FLAGS AD Type (ex.
ktownsend 19:a6f33421746c 99 LE_GENERAL_DISCOVERABLE and BREDR_NOT_SUPPORTED).
ktownsend 19:a6f33421746c 100
ktownsend 19:a6f33421746c 101 \par Source
ktownsend 19:a6f33421746c 102 \li \c Bluetooth Core Specification 4.0 (Vol. 3), Part C, Section 18.1
ktownsend 19:a6f33421746c 103 */
ktownsend 19:a6f33421746c 104 /**********************************************************************/
ktownsend 4:50a31ff5f974 105 enum Flags
ktownsend 4:50a31ff5f974 106 {
ktownsend 19:a6f33421746c 107 LE_LIMITED_DISCOVERABLE = 0x01, /**< Peripheral device is discoverable for a limited period of time */
ktownsend 19:a6f33421746c 108 LE_GENERAL_DISCOVERABLE = 0x02, /**< Peripheral device is discoverable at any moment */
ktownsend 19:a6f33421746c 109 BREDR_NOT_SUPPORTED = 0x04, /**< Peripheral device is LE only */
ktownsend 19:a6f33421746c 110 SIMULTANEOUS_LE_BREDR_C = 0x08, /**< Not relevant - central mode only */
ktownsend 19:a6f33421746c 111 SIMULTANEOUS_LE_BREDR_H = 0x10 /**< Not relevant - central mode only */
ktownsend 4:50a31ff5f974 112 };
ktownsend 4:50a31ff5f974 113
ktownsend 19:a6f33421746c 114 /**********************************************************************/
ktownsend 19:a6f33421746c 115 /*!
ktownsend 19:a6f33421746c 116 \brief
ktownsend 19:a6f33421746c 117 A list of values for the APPEARANCE AD Type, which describes the
ktownsend 19:a6f33421746c 118 physical shape or appearance of the device
ktownsend 19:a6f33421746c 119
ktownsend 19:a6f33421746c 120 \par Source
ktownsend 19:a6f33421746c 121 \li \c Bluetooth Core Specification Supplement, Part A, Section 1.12
ktownsend 19:a6f33421746c 122 \li \c Bluetooth Core Specification 4.0 (Vol. 3), Part C, Section 12.2
ktownsend 19:a6f33421746c 123 \li \c https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.gap.appearance.xml
ktownsend 19:a6f33421746c 124 */
ktownsend 19:a6f33421746c 125 /**********************************************************************/
ktownsend 4:50a31ff5f974 126 enum Appearance
ktownsend 4:50a31ff5f974 127 {
ktownsend 21:5442f7c70e71 128 UNKNOWN = 0, /**< Unknown of unspecified appearance type */
ktownsend 21:5442f7c70e71 129 GENERIC_PHONE = 64, /**< Generic Phone */
ktownsend 21:5442f7c70e71 130 GENERIC_COMPUTER = 128, /**< Generic Computer */
ktownsend 21:5442f7c70e71 131 GENERIC_WATCH = 192, /**< Generic Watch */
ktownsend 21:5442f7c70e71 132 WATCH_SPORTS_WATCH = 193, /**< Sports Watch */
ktownsend 21:5442f7c70e71 133 GENERIC_CLOCK = 256, /**< Generic Clock */
ktownsend 21:5442f7c70e71 134 GENERIC_DISPLAY = 320, /**< Generic Display */
ktownsend 21:5442f7c70e71 135 GENERIC_REMOTE_CONTROL = 384, /**< Generic Remote Control */
ktownsend 21:5442f7c70e71 136 GENERIC_EYE_GLASSES = 448, /**< Generic Eye Glasses */
ktownsend 21:5442f7c70e71 137 GENERIC_TAG = 512, /**< Generic Tag */
ktownsend 21:5442f7c70e71 138 GENERIC_KEYRING = 576, /**< Generic Keyring */
ktownsend 21:5442f7c70e71 139 GENERIC_MEDIA_PLAYER = 640, /**< Generic Media Player */
ktownsend 21:5442f7c70e71 140 GENERIC_BARCODE_SCANNER = 704, /**< Generic Barcode Scanner */
ktownsend 21:5442f7c70e71 141 GENERIC_THERMOMETER = 768, /**< Generic Thermometer */
ktownsend 21:5442f7c70e71 142 THERMOMETER_EAR = 769, /**< Ear Thermometer */
ktownsend 21:5442f7c70e71 143 GENERIC_HEART_RATE_SENSOR = 832, /**< Generic Heart Rate Sensor */
ktownsend 21:5442f7c70e71 144 HEART_RATE_SENSOR_HEART_RATE_BELT = 833, /**< Belt Heart Rate Sensor */
ktownsend 21:5442f7c70e71 145 GENERIC_BLOOD_PRESSURE = 896, /**< Generic Blood Pressure */
ktownsend 21:5442f7c70e71 146 BLOOD_PRESSURE_ARM = 897, /**< Arm Blood Pressure */
ktownsend 21:5442f7c70e71 147 BLOOD_PRESSURE_WRIST = 898, /**< Wrist Blood Pressure */
ktownsend 21:5442f7c70e71 148 HUMAN_INTERFACE_DEVICE_HID = 960, /**< Human Interface Device (HID) */
ktownsend 21:5442f7c70e71 149 KEYBOARD = 961, /**< Keyboard */
ktownsend 21:5442f7c70e71 150 MOUSE = 962, /**< Mouse */
ktownsend 21:5442f7c70e71 151 JOYSTICK = 963, /**< Joystick */
ktownsend 21:5442f7c70e71 152 GAMEPAD = 964, /**< Gamepad */
ktownsend 21:5442f7c70e71 153 DIGITIZER_TABLET = 965, /**< Digitizer Tablet */
ktownsend 21:5442f7c70e71 154 CARD_READER = 966, /**< Card Read */
ktownsend 21:5442f7c70e71 155 DIGITAL_PEN = 967, /**< Digital Pen */
ktownsend 21:5442f7c70e71 156 BARCODE_SCANNER = 968, /**< Barcode Scanner */
ktownsend 21:5442f7c70e71 157 GENERIC_GLUCOSE_METER = 1024, /**< Generic Glucose Meter */
ktownsend 21:5442f7c70e71 158 GENERIC_RUNNING_WALKING_SENSOR = 1088, /**< Generic Running/Walking Sensor */
ktownsend 21:5442f7c70e71 159 RUNNING_WALKING_SENSOR_IN_SHOE = 1089, /**< In Shoe Running/Walking Sensor */
ktownsend 21:5442f7c70e71 160 RUNNING_WALKING_SENSOR_ON_SHOE = 1090, /**< On Shoe Running/Walking Sensor */
ktownsend 21:5442f7c70e71 161 RUNNING_WALKING_SENSOR_ON_HIP = 1091, /**< On Hip Running/Walking Sensor */
ktownsend 21:5442f7c70e71 162 GENERIC_CYCLING = 1152, /**< Generic Cycling */
ktownsend 21:5442f7c70e71 163 CYCLING_CYCLING_COMPUTER = 1153, /**< Cycling Computer */
ktownsend 21:5442f7c70e71 164 CYCLING_SPEED_SENSOR = 1154, /**< Cycling Speed Senspr */
ktownsend 21:5442f7c70e71 165 CYCLING_CADENCE_SENSOR = 1155, /**< Cycling Cadence Sensor */
ktownsend 21:5442f7c70e71 166 CYCLING_POWER_SENSOR = 1156, /**< Cycling Power Sensor */
ktownsend 21:5442f7c70e71 167 CYCLING_SPEED_AND_CADENCE_SENSOR = 1157, /**< Cycling Speed and Cadence Sensor */
ktownsend 21:5442f7c70e71 168 PULSE_OXIMETER_GENERIC = 3136, /**< Generic Pulse Oximeter */
ktownsend 21:5442f7c70e71 169 PULSE_OXIMETER_FINGERTIP = 3137, /**< Fingertip Pulse Oximeter */
ktownsend 21:5442f7c70e71 170 PULSE_OXIMETER_WRIST_WORN = 3138, /**< Wrist Worn Pulse Oximeter */
ktownsend 21:5442f7c70e71 171 OUTDOOR_GENERIC = 5184, /**< Generic Outdoor */
ktownsend 21:5442f7c70e71 172 OUTDOOR_LOCATION_DISPLAY_DEVICE = 5185, /**< Outdoor Location Display Device */
ktownsend 21:5442f7c70e71 173 OUTDOOR_LOCATION_AND_NAVIGATION_DISPLAY_DEVICE = 5186, /**< Outdoor Location and Navigation Display Device */
ktownsend 21:5442f7c70e71 174 OUTDOOR_LOCATION_POD = 5187, /**< Outdoor Location Pod */
ktownsend 21:5442f7c70e71 175 OUTDOOR_LOCATION_AND_NAVIGATION_POD = 5188 /**< Outdoor Location and Navigation Pod */
ktownsend 4:50a31ff5f974 176 };
ktownsend 4:50a31ff5f974 177
ktownsend 2:ffc5216bd2cc 178 GapAdvertisingData(void);
ktownsend 2:ffc5216bd2cc 179 virtual ~GapAdvertisingData(void);
ktownsend 3:46de446e82ed 180
ktownsend 4:50a31ff5f974 181 ble_error_t addData(DataType, uint8_t *, uint8_t);
ktownsend 4:50a31ff5f974 182 ble_error_t addAppearance(Appearance appearance = UNKNOWN);
ktownsend 4:50a31ff5f974 183 ble_error_t addFlags(Flags flag = LE_GENERAL_DISCOVERABLE);
ktownsend 4:50a31ff5f974 184 ble_error_t addTxPower(int8_t txPower);
ktownsend 4:50a31ff5f974 185 void clear(void);
ktownsend 7:5e1f0d7f7c7d 186 uint8_t * getPayload(void);
ktownsend 3:46de446e82ed 187 uint8_t getPayloadLen(void);
ktownsend 4:50a31ff5f974 188
ktownsend 4:50a31ff5f974 189 private:
ktownsend 3:46de446e82ed 190 uint8_t _payload[GAP_ADVERTISING_DATA_MAX_PAYLOAD];
ktownsend 3:46de446e82ed 191 uint8_t _payloadLen;
ktownsend 2:ffc5216bd2cc 192 };
ktownsend 2:ffc5216bd2cc 193
ktownsend 2:ffc5216bd2cc 194 #endif