YUFEI JIANG / BLE_API_Tiny_BLE

Dependents:   CSSE4011_BLE_IMU

Fork of BLE_API by Bluetooth Low Energy

Committer:
ktownsend
Date:
Thu Dec 12 02:20:54 2013 +0000
Revision:
4:50a31ff5f974
Parent:
3:46de446e82ed
Child:
5:7635f81a8e09
More GAP refactoring

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 3:46de446e82ed 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 4:50a31ff5f974 14 @note See Bluetooth Specification 4.0 (Vol. 3), Part C, Section 11 and 18
ktownsend 4:50a31ff5f974 15 for further information on Advertising and Scan Response data.
ktownsend 4:50a31ff5f974 16
ktownsend 3:46de446e82ed 17 @section Advertising and Scan Response Payloads
ktownsend 3:46de446e82ed 18
ktownsend 3:46de446e82ed 19 @para
ktownsend 3:46de446e82ed 20 Advertising data and Scan Response data are organized around a set of
ktownsend 4:50a31ff5f974 21 data types called 'AD types' in Bluetooth 4.0 (see the Bluetooth Core
ktownsend 4:50a31ff5f974 22 Specification v4.0, Vol. 3, Part C, Sections 11 and 18).
ktownsend 4:50a31ff5f974 23
ktownsend 3:46de446e82ed 24 @para
ktownsend 3:46de446e82ed 25 Each AD type has it's own standardized 'assigned number', as defined
ktownsend 3:46de446e82ed 26 by the Bluetooth SIG:
ktownsend 3:46de446e82ed 27 https://www.bluetooth.org/en-us/specification/assigned-numbers/generic-access-profile
ktownsend 3:46de446e82ed 28
ktownsend 3:46de446e82ed 29 @para
ktownsend 3:46de446e82ed 30 For convenience sake, all appropriate AD types have been encapsulated
ktownsend 4:50a31ff5f974 31 into an enum at \ref DataType.
ktownsend 3:46de446e82ed 32
ktownsend 3:46de446e82ed 33 @para
ktownsend 4:50a31ff5f974 34 Before the AD Types and their payload (if any) can be inserted into
ktownsend 4:50a31ff5f974 35 the Advertising or Scan Response frames, they need to be formatted as
ktownsend 4:50a31ff5f974 36 follows:
ktownsend 3:46de446e82ed 37
ktownsend 3:46de446e82ed 38 - Record length (1 byte)
ktownsend 3:46de446e82ed 39 - AD Type (1 byte)
ktownsend 3:46de446e82ed 40 - AD payload (optional, only present if record length > 1)
ktownsend 4:50a31ff5f974 41
ktownsend 3:46de446e82ed 42 @para
ktownsend 4:50a31ff5f974 43 When multiple AD records are present, the individual records are
ktownsend 3:46de446e82ed 44 appended one after the other, up to the maximum payload length of 31
ktownsend 4:50a31ff5f974 45 bytes, as can be seen in the example payload below.
ktownsend 3:46de446e82ed 46
ktownsend 4:50a31ff5f974 47 @section Sample Raw Advertising Payload
ktownsend 3:46de446e82ed 48
ktownsend 3:46de446e82ed 49 // Two record payload containing BLE_GAP_ADV_DATATYPE_FLAGS (0x01) and
ktownsend 3:46de446e82ed 50 // BLE_GAP_ADV_DATATYPE_COMPLETE_LOCAL_NAME (0x09) fields
ktownsend 3:46de446e82ed 51 02 01 01 0A 09 50 65 64 6F 6D 65 74 65 72
ktownsend 3:46de446e82ed 52
ktownsend 3:46de446e82ed 53 // Record 1 (FLAGS)
ktownsend 3:46de446e82ed 54 02 01 01
ktownsend 3:46de446e82ed 55 02 = record length (2 bytes)
ktownsend 3:46de446e82ed 56 01 = BLE_GAP_ADV_DATATYPE_FLAGS
ktownsend 3:46de446e82ed 57 01 = BLE_GAP_ADV_FLAGS_LE_LIMITED_DISCOVERABLE
ktownsend 3:46de446e82ed 58
ktownsend 3:46de446e82ed 59 // Record 2 (COMPLETE LOCAL NAME)
ktownsend 3:46de446e82ed 60 0A 09 50 65 64 6F 6D 65 74 65 72
ktownsend 3:46de446e82ed 61 0A = record length (10 bytes)
ktownsend 3:46de446e82ed 62 09 = BLE_GAP_ADV_DATATYPE_COMPLETE_LOCAL_NAME
ktownsend 3:46de446e82ed 63 50 65 64 6F 6D 65 74 65 72 = "Pedometer"
ktownsend 3:46de446e82ed 64 */
ktownsend 3:46de446e82ed 65 /**************************************************************************/
ktownsend 2:ffc5216bd2cc 66 class GapAdvertisingData
ktownsend 2:ffc5216bd2cc 67 {
ktownsend 4:50a31ff5f974 68 public:
ktownsend 4:50a31ff5f974 69 /* Bluetooth Core Specification 4.0 (Vol. 3), Part C, Section 11, 18 */
ktownsend 4:50a31ff5f974 70 /* https://www.bluetooth.org/en-us/specification/assigned-numbers/generic-access-profile */
ktownsend 4:50a31ff5f974 71 enum DataType
ktownsend 4:50a31ff5f974 72 {
ktownsend 4:50a31ff5f974 73 FLAGS = 0x01,
ktownsend 4:50a31ff5f974 74 INCOMPLETE_LIST_16BIT_SERVICE_IDS = 0x02,
ktownsend 4:50a31ff5f974 75 COMPLETE_LIST_16BIT_SERVICE_IDS = 0x03,
ktownsend 4:50a31ff5f974 76 INCOMPLETE_LIST_32BIT_SERVICE_IDS = 0x04,
ktownsend 4:50a31ff5f974 77 COMPLETE_LIST_32BIT_SERVICE_IDS = 0x05,
ktownsend 4:50a31ff5f974 78 INCOMPLETE_LIST_128BIT_SERVICE_IDS = 0x06,
ktownsend 4:50a31ff5f974 79 COMPLETE_LIST_128BIT_SERVICE_IDS = 0x07,
ktownsend 4:50a31ff5f974 80 SHORTENED_LOCAL_NAME = 0x08,
ktownsend 4:50a31ff5f974 81 COMPLETE_LOCAL_NAME = 0x09,
ktownsend 4:50a31ff5f974 82 TX_POWER_LEVEL = 0x0A,
ktownsend 4:50a31ff5f974 83 DEVICE_ID = 0x10,
ktownsend 4:50a31ff5f974 84 SLAVE_CONNECTION_INTERVAL_RANGE = 0x12,
ktownsend 4:50a31ff5f974 85 SERVICE_DATA = 0x16,
ktownsend 4:50a31ff5f974 86 APPEARANCE = 0x19,
ktownsend 4:50a31ff5f974 87 ADVERTISING_INTERVAL = 0x1A,
ktownsend 4:50a31ff5f974 88 MANUFACTURER_SPECIFIC_DATA = 0xFF
ktownsend 4:50a31ff5f974 89 };
ktownsend 4:50a31ff5f974 90
ktownsend 4:50a31ff5f974 91 /* Bluetooth Core Specification 4.0 (Vol. 3), Part C, Section 18.1 */
ktownsend 4:50a31ff5f974 92 enum Flags
ktownsend 4:50a31ff5f974 93 {
ktownsend 4:50a31ff5f974 94 LE_LIMITED_DISCOVERABLE = 0x01,
ktownsend 4:50a31ff5f974 95 LE_GENERAL_DISCOVERABLE = 0x02,
ktownsend 4:50a31ff5f974 96 BREDR_NOT_SUPPORTED = 0x04,
ktownsend 4:50a31ff5f974 97 SIMULTANEOUS_LE_BREDR_C = 0x08,
ktownsend 4:50a31ff5f974 98 SIMULTANEOUS_LE_BREDR_H = 0x10
ktownsend 4:50a31ff5f974 99 };
ktownsend 4:50a31ff5f974 100
ktownsend 4:50a31ff5f974 101 /* Bluetooth Core Specification Supplement, Part A, Section 1.12 */
ktownsend 4:50a31ff5f974 102 /* Bluetooth Core Specification 4.0 (Vol. 3), Part C, Section 12.2 */
ktownsend 4:50a31ff5f974 103 /* https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.gap.appearance.xml */
ktownsend 4:50a31ff5f974 104 enum Appearance
ktownsend 4:50a31ff5f974 105 {
ktownsend 4:50a31ff5f974 106 UNKNOWN = 0,
ktownsend 4:50a31ff5f974 107 GENERIC_PHONE = 64,
ktownsend 4:50a31ff5f974 108 GENERIC_COMPUTER = 128,
ktownsend 4:50a31ff5f974 109 GENERIC_WATCH = 192,
ktownsend 4:50a31ff5f974 110 WATCH_SPORTS_WATCH = 193,
ktownsend 4:50a31ff5f974 111 GENERIC_CLOCK = 256,
ktownsend 4:50a31ff5f974 112 GENERIC_DISPLAY = 320,
ktownsend 4:50a31ff5f974 113 GENERIC_REMOTE_CONTROL = 384,
ktownsend 4:50a31ff5f974 114 GENERIC_EYE_GLASSES = 448,
ktownsend 4:50a31ff5f974 115 GENERIC_TAG = 512,
ktownsend 4:50a31ff5f974 116 GENERIC_KEYRING = 576,
ktownsend 4:50a31ff5f974 117 GENERIC_MEDIA_PLAYER = 640,
ktownsend 4:50a31ff5f974 118 GENERIC_BARCODE_SCANNER = 704,
ktownsend 4:50a31ff5f974 119 GENERIC_THERMOMETER = 768,
ktownsend 4:50a31ff5f974 120 THERMOMETER_EAR = 769,
ktownsend 4:50a31ff5f974 121 GENERIC_HEART_RATE_SENSOR = 832,
ktownsend 4:50a31ff5f974 122 HEART_RATE_SENSOR_HEART_RATE_BELT = 833,
ktownsend 4:50a31ff5f974 123 GENERIC_BLOOD_PRESSURE = 896,
ktownsend 4:50a31ff5f974 124 BLOOD_PRESSURE_ARM = 897,
ktownsend 4:50a31ff5f974 125 BLOOD_PRESSURE_WRIST = 898,
ktownsend 4:50a31ff5f974 126 HUMAN_INTERFACE_DEVICE_HID = 960,
ktownsend 4:50a31ff5f974 127 KEYBOARD = 961,
ktownsend 4:50a31ff5f974 128 MOUSE = 962,
ktownsend 4:50a31ff5f974 129 JOYSTICK = 963,
ktownsend 4:50a31ff5f974 130 GAMEPAD = 964,
ktownsend 4:50a31ff5f974 131 DIGITIZER_TABLET = 965,
ktownsend 4:50a31ff5f974 132 CARD_READER = 966,
ktownsend 4:50a31ff5f974 133 DIGITAL_PEN = 967,
ktownsend 4:50a31ff5f974 134 BARCODE_SCANNER = 968,
ktownsend 4:50a31ff5f974 135 GENERIC_GLUCOSE_METER = 1024,
ktownsend 4:50a31ff5f974 136 GENERIC_RUNNING_WALKING_SENSOR = 1088,
ktownsend 4:50a31ff5f974 137 RUNNING_WALKING_SENSOR_IN_SHOE = 1089,
ktownsend 4:50a31ff5f974 138 RUNNING_WALKING_SENSOR_ON_SHOE = 1090,
ktownsend 4:50a31ff5f974 139 RUNNING_WALKING_SENSOR_ON_HIP = 1091,
ktownsend 4:50a31ff5f974 140 GENERIC_CYCLING = 1152,
ktownsend 4:50a31ff5f974 141 CYCLING_CYCLING_COMPUTER = 1153,
ktownsend 4:50a31ff5f974 142 CYCLING_SPEED_SENSOR = 1154,
ktownsend 4:50a31ff5f974 143 CYCLING_CADENCE_SENSOR = 1155,
ktownsend 4:50a31ff5f974 144 CYCLING_POWER_SENSOR = 1156,
ktownsend 4:50a31ff5f974 145 CYCLING_SPEED_AND_CADENCE_SENSOR = 1157,
ktownsend 4:50a31ff5f974 146 PULSE_OXIMETER_GENERIC = 3136,
ktownsend 4:50a31ff5f974 147 PULSE_OXIMETER_FINGERTIP = 3137,
ktownsend 4:50a31ff5f974 148 PULSE_OXIMETER_WRIST_WORN = 3138,
ktownsend 4:50a31ff5f974 149 OUTDOOR_GENERIC = 5184,
ktownsend 4:50a31ff5f974 150 OUTDOOR_LOCATION_DISPLAY_DEVICE = 5185,
ktownsend 4:50a31ff5f974 151 OUTDOOR_LOCATION_AND_NAVIGATION_DISPLAY_DEVICE = 5186,
ktownsend 4:50a31ff5f974 152 OUTDOOR_LOCATION_POD = 5187,
ktownsend 4:50a31ff5f974 153 OUTDOOR_LOCATION_AND_NAVIGATION_POD = 5188
ktownsend 4:50a31ff5f974 154 };
ktownsend 4:50a31ff5f974 155
ktownsend 2:ffc5216bd2cc 156 GapAdvertisingData(void);
ktownsend 2:ffc5216bd2cc 157 virtual ~GapAdvertisingData(void);
ktownsend 3:46de446e82ed 158
ktownsend 4:50a31ff5f974 159 ble_error_t addData(DataType, uint8_t *, uint8_t);
ktownsend 4:50a31ff5f974 160 ble_error_t addAppearance(Appearance appearance = UNKNOWN);
ktownsend 4:50a31ff5f974 161 ble_error_t addFlags(Flags flag = LE_GENERAL_DISCOVERABLE);
ktownsend 4:50a31ff5f974 162 ble_error_t addTxPower(int8_t txPower);
ktownsend 4:50a31ff5f974 163 void clear(void);
ktownsend 3:46de446e82ed 164 uint8_t getPayloadLen(void);
ktownsend 4:50a31ff5f974 165
ktownsend 4:50a31ff5f974 166 private:
ktownsend 3:46de446e82ed 167 uint8_t _payload[GAP_ADVERTISING_DATA_MAX_PAYLOAD];
ktownsend 3:46de446e82ed 168 uint8_t _payloadLen;
ktownsend 2:ffc5216bd2cc 169 };
ktownsend 2:ffc5216bd2cc 170
ktownsend 2:ffc5216bd2cc 171 #endif