YUFEI JIANG / BLE_API_Tiny_BLE

Dependents:   CSSE4011_BLE_IMU

Fork of BLE_API by Bluetooth Low Energy

Committer:
ktownsend
Date:
Wed Dec 18 19:39:19 2013 +0000
Revision:
18:86fe1e247a54
Parent:
7:5e1f0d7f7c7d
Child:
19:a6f33421746c
Doxygen Cleanup

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 4:50a31ff5f974 59 /* Bluetooth Core Specification 4.0 (Vol. 3), Part C, Section 11, 18 */
ktownsend 4:50a31ff5f974 60 /* https://www.bluetooth.org/en-us/specification/assigned-numbers/generic-access-profile */
ktownsend 4:50a31ff5f974 61 enum DataType
ktownsend 4:50a31ff5f974 62 {
ktownsend 4:50a31ff5f974 63 FLAGS = 0x01,
ktownsend 4:50a31ff5f974 64 INCOMPLETE_LIST_16BIT_SERVICE_IDS = 0x02,
ktownsend 4:50a31ff5f974 65 COMPLETE_LIST_16BIT_SERVICE_IDS = 0x03,
ktownsend 4:50a31ff5f974 66 INCOMPLETE_LIST_32BIT_SERVICE_IDS = 0x04,
ktownsend 4:50a31ff5f974 67 COMPLETE_LIST_32BIT_SERVICE_IDS = 0x05,
ktownsend 4:50a31ff5f974 68 INCOMPLETE_LIST_128BIT_SERVICE_IDS = 0x06,
ktownsend 4:50a31ff5f974 69 COMPLETE_LIST_128BIT_SERVICE_IDS = 0x07,
ktownsend 4:50a31ff5f974 70 SHORTENED_LOCAL_NAME = 0x08,
ktownsend 4:50a31ff5f974 71 COMPLETE_LOCAL_NAME = 0x09,
ktownsend 4:50a31ff5f974 72 TX_POWER_LEVEL = 0x0A,
ktownsend 4:50a31ff5f974 73 DEVICE_ID = 0x10,
ktownsend 4:50a31ff5f974 74 SLAVE_CONNECTION_INTERVAL_RANGE = 0x12,
ktownsend 4:50a31ff5f974 75 SERVICE_DATA = 0x16,
ktownsend 4:50a31ff5f974 76 APPEARANCE = 0x19,
ktownsend 4:50a31ff5f974 77 ADVERTISING_INTERVAL = 0x1A,
ktownsend 4:50a31ff5f974 78 MANUFACTURER_SPECIFIC_DATA = 0xFF
ktownsend 4:50a31ff5f974 79 };
ktownsend 4:50a31ff5f974 80
ktownsend 4:50a31ff5f974 81 /* Bluetooth Core Specification 4.0 (Vol. 3), Part C, Section 18.1 */
ktownsend 4:50a31ff5f974 82 enum Flags
ktownsend 4:50a31ff5f974 83 {
ktownsend 4:50a31ff5f974 84 LE_LIMITED_DISCOVERABLE = 0x01,
ktownsend 4:50a31ff5f974 85 LE_GENERAL_DISCOVERABLE = 0x02,
ktownsend 4:50a31ff5f974 86 BREDR_NOT_SUPPORTED = 0x04,
ktownsend 4:50a31ff5f974 87 SIMULTANEOUS_LE_BREDR_C = 0x08,
ktownsend 4:50a31ff5f974 88 SIMULTANEOUS_LE_BREDR_H = 0x10
ktownsend 4:50a31ff5f974 89 };
ktownsend 4:50a31ff5f974 90
ktownsend 4:50a31ff5f974 91 /* Bluetooth Core Specification Supplement, Part A, Section 1.12 */
ktownsend 4:50a31ff5f974 92 /* Bluetooth Core Specification 4.0 (Vol. 3), Part C, Section 12.2 */
ktownsend 4:50a31ff5f974 93 /* https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.gap.appearance.xml */
ktownsend 4:50a31ff5f974 94 enum Appearance
ktownsend 4:50a31ff5f974 95 {
ktownsend 4:50a31ff5f974 96 UNKNOWN = 0,
ktownsend 4:50a31ff5f974 97 GENERIC_PHONE = 64,
ktownsend 4:50a31ff5f974 98 GENERIC_COMPUTER = 128,
ktownsend 4:50a31ff5f974 99 GENERIC_WATCH = 192,
ktownsend 4:50a31ff5f974 100 WATCH_SPORTS_WATCH = 193,
ktownsend 4:50a31ff5f974 101 GENERIC_CLOCK = 256,
ktownsend 4:50a31ff5f974 102 GENERIC_DISPLAY = 320,
ktownsend 4:50a31ff5f974 103 GENERIC_REMOTE_CONTROL = 384,
ktownsend 4:50a31ff5f974 104 GENERIC_EYE_GLASSES = 448,
ktownsend 4:50a31ff5f974 105 GENERIC_TAG = 512,
ktownsend 4:50a31ff5f974 106 GENERIC_KEYRING = 576,
ktownsend 4:50a31ff5f974 107 GENERIC_MEDIA_PLAYER = 640,
ktownsend 4:50a31ff5f974 108 GENERIC_BARCODE_SCANNER = 704,
ktownsend 4:50a31ff5f974 109 GENERIC_THERMOMETER = 768,
ktownsend 4:50a31ff5f974 110 THERMOMETER_EAR = 769,
ktownsend 4:50a31ff5f974 111 GENERIC_HEART_RATE_SENSOR = 832,
ktownsend 4:50a31ff5f974 112 HEART_RATE_SENSOR_HEART_RATE_BELT = 833,
ktownsend 4:50a31ff5f974 113 GENERIC_BLOOD_PRESSURE = 896,
ktownsend 4:50a31ff5f974 114 BLOOD_PRESSURE_ARM = 897,
ktownsend 4:50a31ff5f974 115 BLOOD_PRESSURE_WRIST = 898,
ktownsend 4:50a31ff5f974 116 HUMAN_INTERFACE_DEVICE_HID = 960,
ktownsend 4:50a31ff5f974 117 KEYBOARD = 961,
ktownsend 4:50a31ff5f974 118 MOUSE = 962,
ktownsend 4:50a31ff5f974 119 JOYSTICK = 963,
ktownsend 4:50a31ff5f974 120 GAMEPAD = 964,
ktownsend 4:50a31ff5f974 121 DIGITIZER_TABLET = 965,
ktownsend 4:50a31ff5f974 122 CARD_READER = 966,
ktownsend 4:50a31ff5f974 123 DIGITAL_PEN = 967,
ktownsend 4:50a31ff5f974 124 BARCODE_SCANNER = 968,
ktownsend 4:50a31ff5f974 125 GENERIC_GLUCOSE_METER = 1024,
ktownsend 4:50a31ff5f974 126 GENERIC_RUNNING_WALKING_SENSOR = 1088,
ktownsend 4:50a31ff5f974 127 RUNNING_WALKING_SENSOR_IN_SHOE = 1089,
ktownsend 4:50a31ff5f974 128 RUNNING_WALKING_SENSOR_ON_SHOE = 1090,
ktownsend 4:50a31ff5f974 129 RUNNING_WALKING_SENSOR_ON_HIP = 1091,
ktownsend 4:50a31ff5f974 130 GENERIC_CYCLING = 1152,
ktownsend 4:50a31ff5f974 131 CYCLING_CYCLING_COMPUTER = 1153,
ktownsend 4:50a31ff5f974 132 CYCLING_SPEED_SENSOR = 1154,
ktownsend 4:50a31ff5f974 133 CYCLING_CADENCE_SENSOR = 1155,
ktownsend 4:50a31ff5f974 134 CYCLING_POWER_SENSOR = 1156,
ktownsend 4:50a31ff5f974 135 CYCLING_SPEED_AND_CADENCE_SENSOR = 1157,
ktownsend 4:50a31ff5f974 136 PULSE_OXIMETER_GENERIC = 3136,
ktownsend 4:50a31ff5f974 137 PULSE_OXIMETER_FINGERTIP = 3137,
ktownsend 4:50a31ff5f974 138 PULSE_OXIMETER_WRIST_WORN = 3138,
ktownsend 4:50a31ff5f974 139 OUTDOOR_GENERIC = 5184,
ktownsend 4:50a31ff5f974 140 OUTDOOR_LOCATION_DISPLAY_DEVICE = 5185,
ktownsend 4:50a31ff5f974 141 OUTDOOR_LOCATION_AND_NAVIGATION_DISPLAY_DEVICE = 5186,
ktownsend 4:50a31ff5f974 142 OUTDOOR_LOCATION_POD = 5187,
ktownsend 4:50a31ff5f974 143 OUTDOOR_LOCATION_AND_NAVIGATION_POD = 5188
ktownsend 4:50a31ff5f974 144 };
ktownsend 4:50a31ff5f974 145
ktownsend 2:ffc5216bd2cc 146 GapAdvertisingData(void);
ktownsend 2:ffc5216bd2cc 147 virtual ~GapAdvertisingData(void);
ktownsend 3:46de446e82ed 148
ktownsend 4:50a31ff5f974 149 ble_error_t addData(DataType, uint8_t *, uint8_t);
ktownsend 4:50a31ff5f974 150 ble_error_t addAppearance(Appearance appearance = UNKNOWN);
ktownsend 4:50a31ff5f974 151 ble_error_t addFlags(Flags flag = LE_GENERAL_DISCOVERABLE);
ktownsend 4:50a31ff5f974 152 ble_error_t addTxPower(int8_t txPower);
ktownsend 4:50a31ff5f974 153 void clear(void);
ktownsend 7:5e1f0d7f7c7d 154 uint8_t * getPayload(void);
ktownsend 3:46de446e82ed 155 uint8_t getPayloadLen(void);
ktownsend 4:50a31ff5f974 156
ktownsend 4:50a31ff5f974 157 private:
ktownsend 3:46de446e82ed 158 uint8_t _payload[GAP_ADVERTISING_DATA_MAX_PAYLOAD];
ktownsend 3:46de446e82ed 159 uint8_t _payloadLen;
ktownsend 2:ffc5216bd2cc 160 };
ktownsend 2:ffc5216bd2cc 161
ktownsend 2:ffc5216bd2cc 162 #endif