Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of BLE_API by
GapAdvertisingData.h@5:7635f81a8e09, 2013-12-12 (annotated)
- Committer:
- ktownsend
- Date:
- Thu Dec 12 02:43:22 2013 +0000
- Revision:
- 5:7635f81a8e09
- Parent:
- 4:50a31ff5f974
- Child:
- 7:5e1f0d7f7c7d
Few changes and a build test for GAP advertising changes
Who changed what in which revision?
| User | Revision | Line number | New 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 | 5:7635f81a8e09 | 31 | into \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 | 5:7635f81a8e09 | 41 | |
| ktownsend | 3:46de446e82ed | 42 | @para |
| ktownsend | 5:7635f81a8e09 | 43 | This class takes care of properly formatting the payload, performs |
| ktownsend | 5:7635f81a8e09 | 44 | some basic checks on the payload length, and tries to avoid common |
| ktownsend | 5:7635f81a8e09 | 45 | errors like adding an exclusive AD field twice in the Advertising |
| ktownsend | 5:7635f81a8e09 | 46 | or Scan Response payload. |
| ktownsend | 3:46de446e82ed | 47 | |
| ktownsend | 5:7635f81a8e09 | 48 | @section EXAMPLE |
| ktownsend | 5:7635f81a8e09 | 49 | |
| ktownsend | 5:7635f81a8e09 | 50 | @code |
| ktownsend | 3:46de446e82ed | 51 | |
| ktownsend | 5:7635f81a8e09 | 52 | // ToDo |
| ktownsend | 5:7635f81a8e09 | 53 | |
| ktownsend | 5:7635f81a8e09 | 54 | @endcode |
| ktownsend | 3:46de446e82ed | 55 | */ |
| ktownsend | 3:46de446e82ed | 56 | /**************************************************************************/ |
| ktownsend | 2:ffc5216bd2cc | 57 | class GapAdvertisingData |
| ktownsend | 2:ffc5216bd2cc | 58 | { |
| ktownsend | 4:50a31ff5f974 | 59 | public: |
| ktownsend | 4:50a31ff5f974 | 60 | /* Bluetooth Core Specification 4.0 (Vol. 3), Part C, Section 11, 18 */ |
| ktownsend | 4:50a31ff5f974 | 61 | /* https://www.bluetooth.org/en-us/specification/assigned-numbers/generic-access-profile */ |
| ktownsend | 4:50a31ff5f974 | 62 | enum DataType |
| ktownsend | 4:50a31ff5f974 | 63 | { |
| ktownsend | 4:50a31ff5f974 | 64 | FLAGS = 0x01, |
| ktownsend | 4:50a31ff5f974 | 65 | INCOMPLETE_LIST_16BIT_SERVICE_IDS = 0x02, |
| ktownsend | 4:50a31ff5f974 | 66 | COMPLETE_LIST_16BIT_SERVICE_IDS = 0x03, |
| ktownsend | 4:50a31ff5f974 | 67 | INCOMPLETE_LIST_32BIT_SERVICE_IDS = 0x04, |
| ktownsend | 4:50a31ff5f974 | 68 | COMPLETE_LIST_32BIT_SERVICE_IDS = 0x05, |
| ktownsend | 4:50a31ff5f974 | 69 | INCOMPLETE_LIST_128BIT_SERVICE_IDS = 0x06, |
| ktownsend | 4:50a31ff5f974 | 70 | COMPLETE_LIST_128BIT_SERVICE_IDS = 0x07, |
| ktownsend | 4:50a31ff5f974 | 71 | SHORTENED_LOCAL_NAME = 0x08, |
| ktownsend | 4:50a31ff5f974 | 72 | COMPLETE_LOCAL_NAME = 0x09, |
| ktownsend | 4:50a31ff5f974 | 73 | TX_POWER_LEVEL = 0x0A, |
| ktownsend | 4:50a31ff5f974 | 74 | DEVICE_ID = 0x10, |
| ktownsend | 4:50a31ff5f974 | 75 | SLAVE_CONNECTION_INTERVAL_RANGE = 0x12, |
| ktownsend | 4:50a31ff5f974 | 76 | SERVICE_DATA = 0x16, |
| ktownsend | 4:50a31ff5f974 | 77 | APPEARANCE = 0x19, |
| ktownsend | 4:50a31ff5f974 | 78 | ADVERTISING_INTERVAL = 0x1A, |
| ktownsend | 4:50a31ff5f974 | 79 | MANUFACTURER_SPECIFIC_DATA = 0xFF |
| ktownsend | 4:50a31ff5f974 | 80 | }; |
| ktownsend | 4:50a31ff5f974 | 81 | |
| ktownsend | 4:50a31ff5f974 | 82 | /* Bluetooth Core Specification 4.0 (Vol. 3), Part C, Section 18.1 */ |
| ktownsend | 4:50a31ff5f974 | 83 | enum Flags |
| ktownsend | 4:50a31ff5f974 | 84 | { |
| ktownsend | 4:50a31ff5f974 | 85 | LE_LIMITED_DISCOVERABLE = 0x01, |
| ktownsend | 4:50a31ff5f974 | 86 | LE_GENERAL_DISCOVERABLE = 0x02, |
| ktownsend | 4:50a31ff5f974 | 87 | BREDR_NOT_SUPPORTED = 0x04, |
| ktownsend | 4:50a31ff5f974 | 88 | SIMULTANEOUS_LE_BREDR_C = 0x08, |
| ktownsend | 4:50a31ff5f974 | 89 | SIMULTANEOUS_LE_BREDR_H = 0x10 |
| ktownsend | 4:50a31ff5f974 | 90 | }; |
| ktownsend | 4:50a31ff5f974 | 91 | |
| ktownsend | 4:50a31ff5f974 | 92 | /* Bluetooth Core Specification Supplement, Part A, Section 1.12 */ |
| ktownsend | 4:50a31ff5f974 | 93 | /* Bluetooth Core Specification 4.0 (Vol. 3), Part C, Section 12.2 */ |
| ktownsend | 4:50a31ff5f974 | 94 | /* https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.gap.appearance.xml */ |
| ktownsend | 4:50a31ff5f974 | 95 | enum Appearance |
| ktownsend | 4:50a31ff5f974 | 96 | { |
| ktownsend | 4:50a31ff5f974 | 97 | UNKNOWN = 0, |
| ktownsend | 4:50a31ff5f974 | 98 | GENERIC_PHONE = 64, |
| ktownsend | 4:50a31ff5f974 | 99 | GENERIC_COMPUTER = 128, |
| ktownsend | 4:50a31ff5f974 | 100 | GENERIC_WATCH = 192, |
| ktownsend | 4:50a31ff5f974 | 101 | WATCH_SPORTS_WATCH = 193, |
| ktownsend | 4:50a31ff5f974 | 102 | GENERIC_CLOCK = 256, |
| ktownsend | 4:50a31ff5f974 | 103 | GENERIC_DISPLAY = 320, |
| ktownsend | 4:50a31ff5f974 | 104 | GENERIC_REMOTE_CONTROL = 384, |
| ktownsend | 4:50a31ff5f974 | 105 | GENERIC_EYE_GLASSES = 448, |
| ktownsend | 4:50a31ff5f974 | 106 | GENERIC_TAG = 512, |
| ktownsend | 4:50a31ff5f974 | 107 | GENERIC_KEYRING = 576, |
| ktownsend | 4:50a31ff5f974 | 108 | GENERIC_MEDIA_PLAYER = 640, |
| ktownsend | 4:50a31ff5f974 | 109 | GENERIC_BARCODE_SCANNER = 704, |
| ktownsend | 4:50a31ff5f974 | 110 | GENERIC_THERMOMETER = 768, |
| ktownsend | 4:50a31ff5f974 | 111 | THERMOMETER_EAR = 769, |
| ktownsend | 4:50a31ff5f974 | 112 | GENERIC_HEART_RATE_SENSOR = 832, |
| ktownsend | 4:50a31ff5f974 | 113 | HEART_RATE_SENSOR_HEART_RATE_BELT = 833, |
| ktownsend | 4:50a31ff5f974 | 114 | GENERIC_BLOOD_PRESSURE = 896, |
| ktownsend | 4:50a31ff5f974 | 115 | BLOOD_PRESSURE_ARM = 897, |
| ktownsend | 4:50a31ff5f974 | 116 | BLOOD_PRESSURE_WRIST = 898, |
| ktownsend | 4:50a31ff5f974 | 117 | HUMAN_INTERFACE_DEVICE_HID = 960, |
| ktownsend | 4:50a31ff5f974 | 118 | KEYBOARD = 961, |
| ktownsend | 4:50a31ff5f974 | 119 | MOUSE = 962, |
| ktownsend | 4:50a31ff5f974 | 120 | JOYSTICK = 963, |
| ktownsend | 4:50a31ff5f974 | 121 | GAMEPAD = 964, |
| ktownsend | 4:50a31ff5f974 | 122 | DIGITIZER_TABLET = 965, |
| ktownsend | 4:50a31ff5f974 | 123 | CARD_READER = 966, |
| ktownsend | 4:50a31ff5f974 | 124 | DIGITAL_PEN = 967, |
| ktownsend | 4:50a31ff5f974 | 125 | BARCODE_SCANNER = 968, |
| ktownsend | 4:50a31ff5f974 | 126 | GENERIC_GLUCOSE_METER = 1024, |
| ktownsend | 4:50a31ff5f974 | 127 | GENERIC_RUNNING_WALKING_SENSOR = 1088, |
| ktownsend | 4:50a31ff5f974 | 128 | RUNNING_WALKING_SENSOR_IN_SHOE = 1089, |
| ktownsend | 4:50a31ff5f974 | 129 | RUNNING_WALKING_SENSOR_ON_SHOE = 1090, |
| ktownsend | 4:50a31ff5f974 | 130 | RUNNING_WALKING_SENSOR_ON_HIP = 1091, |
| ktownsend | 4:50a31ff5f974 | 131 | GENERIC_CYCLING = 1152, |
| ktownsend | 4:50a31ff5f974 | 132 | CYCLING_CYCLING_COMPUTER = 1153, |
| ktownsend | 4:50a31ff5f974 | 133 | CYCLING_SPEED_SENSOR = 1154, |
| ktownsend | 4:50a31ff5f974 | 134 | CYCLING_CADENCE_SENSOR = 1155, |
| ktownsend | 4:50a31ff5f974 | 135 | CYCLING_POWER_SENSOR = 1156, |
| ktownsend | 4:50a31ff5f974 | 136 | CYCLING_SPEED_AND_CADENCE_SENSOR = 1157, |
| ktownsend | 4:50a31ff5f974 | 137 | PULSE_OXIMETER_GENERIC = 3136, |
| ktownsend | 4:50a31ff5f974 | 138 | PULSE_OXIMETER_FINGERTIP = 3137, |
| ktownsend | 4:50a31ff5f974 | 139 | PULSE_OXIMETER_WRIST_WORN = 3138, |
| ktownsend | 4:50a31ff5f974 | 140 | OUTDOOR_GENERIC = 5184, |
| ktownsend | 4:50a31ff5f974 | 141 | OUTDOOR_LOCATION_DISPLAY_DEVICE = 5185, |
| ktownsend | 4:50a31ff5f974 | 142 | OUTDOOR_LOCATION_AND_NAVIGATION_DISPLAY_DEVICE = 5186, |
| ktownsend | 4:50a31ff5f974 | 143 | OUTDOOR_LOCATION_POD = 5187, |
| ktownsend | 4:50a31ff5f974 | 144 | OUTDOOR_LOCATION_AND_NAVIGATION_POD = 5188 |
| ktownsend | 4:50a31ff5f974 | 145 | }; |
| ktownsend | 4:50a31ff5f974 | 146 | |
| ktownsend | 2:ffc5216bd2cc | 147 | GapAdvertisingData(void); |
| ktownsend | 2:ffc5216bd2cc | 148 | virtual ~GapAdvertisingData(void); |
| ktownsend | 3:46de446e82ed | 149 | |
| ktownsend | 4:50a31ff5f974 | 150 | ble_error_t addData(DataType, uint8_t *, uint8_t); |
| ktownsend | 4:50a31ff5f974 | 151 | ble_error_t addAppearance(Appearance appearance = UNKNOWN); |
| ktownsend | 4:50a31ff5f974 | 152 | ble_error_t addFlags(Flags flag = LE_GENERAL_DISCOVERABLE); |
| ktownsend | 4:50a31ff5f974 | 153 | ble_error_t addTxPower(int8_t txPower); |
| ktownsend | 4:50a31ff5f974 | 154 | void clear(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 |
