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@3:46de446e82ed, 2013-12-11 (annotated)
- Committer:
- ktownsend
- Date:
- Wed Dec 11 22:15:59 2013 +0000
- Revision:
- 3:46de446e82ed
- Parent:
- 2:ffc5216bd2cc
- Child:
- 4:50a31ff5f974
Incremental changes for GAP Advertising API
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 | 3:46de446e82ed | 13 | |
| ktownsend | 3:46de446e82ed | 14 | @section Advertising and Scan Response Payloads |
| ktownsend | 3:46de446e82ed | 15 | |
| ktownsend | 3:46de446e82ed | 16 | @para |
| ktownsend | 3:46de446e82ed | 17 | Advertising data and Scan Response data are organized around a set of |
| ktownsend | 3:46de446e82ed | 18 | data types called 'AD types' in the Bluetooth 4.0 specification. |
| ktownsend | 3:46de446e82ed | 19 | |
| ktownsend | 3:46de446e82ed | 20 | @para |
| ktownsend | 3:46de446e82ed | 21 | Each AD type has it's own standardized 'assigned number', as defined |
| ktownsend | 3:46de446e82ed | 22 | by the Bluetooth SIG: |
| ktownsend | 3:46de446e82ed | 23 | https://www.bluetooth.org/en-us/specification/assigned-numbers/generic-access-profile |
| ktownsend | 3:46de446e82ed | 24 | |
| ktownsend | 3:46de446e82ed | 25 | @para |
| ktownsend | 3:46de446e82ed | 26 | For convenience sake, all appropriate AD types have been encapsulated |
| ktownsend | 3:46de446e82ed | 27 | into an enum at \ref ble_gap_adv_datatype_t. |
| ktownsend | 3:46de446e82ed | 28 | |
| ktownsend | 3:46de446e82ed | 29 | @para |
| ktownsend | 3:46de446e82ed | 30 | Raw Advertising or Scan Response payloads are formatted as follows: |
| ktownsend | 3:46de446e82ed | 31 | |
| ktownsend | 3:46de446e82ed | 32 | - Record length (1 byte) |
| ktownsend | 3:46de446e82ed | 33 | - AD Type (1 byte) |
| ktownsend | 3:46de446e82ed | 34 | - AD payload (optional, only present if record length > 1) |
| ktownsend | 3:46de446e82ed | 35 | |
| ktownsend | 3:46de446e82ed | 36 | @para |
| ktownsend | 3:46de446e82ed | 37 | When multiple AD types are present, the individual records are simply |
| ktownsend | 3:46de446e82ed | 38 | appended one after the other, up to the maximum payload length of 31 |
| ktownsend | 3:46de446e82ed | 39 | bytes. |
| ktownsend | 3:46de446e82ed | 40 | |
| ktownsend | 3:46de446e82ed | 41 | @note See Bluetooth Specification 4.0 (Vol. 3) Section 11, 18 for |
| ktownsend | 3:46de446e82ed | 42 | further information on Advertising and Scan Response data. |
| ktownsend | 3:46de446e82ed | 43 | |
| ktownsend | 3:46de446e82ed | 44 | @section Sample Advertising Payload |
| ktownsend | 3:46de446e82ed | 45 | |
| ktownsend | 3:46de446e82ed | 46 | // Two record payload containing BLE_GAP_ADV_DATATYPE_FLAGS (0x01) and |
| ktownsend | 3:46de446e82ed | 47 | // BLE_GAP_ADV_DATATYPE_COMPLETE_LOCAL_NAME (0x09) fields |
| ktownsend | 3:46de446e82ed | 48 | 02 01 01 0A 09 50 65 64 6F 6D 65 74 65 72 |
| ktownsend | 3:46de446e82ed | 49 | |
| ktownsend | 3:46de446e82ed | 50 | // Record 1 (FLAGS) |
| ktownsend | 3:46de446e82ed | 51 | 02 01 01 |
| ktownsend | 3:46de446e82ed | 52 | 02 = record length (2 bytes) |
| ktownsend | 3:46de446e82ed | 53 | 01 = BLE_GAP_ADV_DATATYPE_FLAGS |
| ktownsend | 3:46de446e82ed | 54 | 01 = BLE_GAP_ADV_FLAGS_LE_LIMITED_DISCOVERABLE |
| ktownsend | 3:46de446e82ed | 55 | |
| ktownsend | 3:46de446e82ed | 56 | // Record 2 (COMPLETE LOCAL NAME) |
| ktownsend | 3:46de446e82ed | 57 | 0A 09 50 65 64 6F 6D 65 74 65 72 |
| ktownsend | 3:46de446e82ed | 58 | 0A = record length (10 bytes) |
| ktownsend | 3:46de446e82ed | 59 | 09 = BLE_GAP_ADV_DATATYPE_COMPLETE_LOCAL_NAME |
| ktownsend | 3:46de446e82ed | 60 | 50 65 64 6F 6D 65 74 65 72 = "Pedometer" |
| ktownsend | 3:46de446e82ed | 61 | */ |
| ktownsend | 3:46de446e82ed | 62 | /**************************************************************************/ |
| ktownsend | 2:ffc5216bd2cc | 63 | class GapAdvertisingData |
| ktownsend | 2:ffc5216bd2cc | 64 | { |
| ktownsend | 3:46de446e82ed | 65 | public: |
| ktownsend | 2:ffc5216bd2cc | 66 | GapAdvertisingData(void); |
| ktownsend | 2:ffc5216bd2cc | 67 | virtual ~GapAdvertisingData(void); |
| ktownsend | 3:46de446e82ed | 68 | |
| ktownsend | 3:46de446e82ed | 69 | ble_error_t addData(ble_gap_adv_datatype_t, uint8_t *, uint8_t); |
| ktownsend | 3:46de446e82ed | 70 | uint8_t getPayloadLen(void); |
| ktownsend | 2:ffc5216bd2cc | 71 | |
| ktownsend | 2:ffc5216bd2cc | 72 | private: |
| ktownsend | 3:46de446e82ed | 73 | uint8_t _payload[GAP_ADVERTISING_DATA_MAX_PAYLOAD]; |
| ktownsend | 3:46de446e82ed | 74 | uint8_t _payloadLen; |
| ktownsend | 2:ffc5216bd2cc | 75 | }; |
| ktownsend | 2:ffc5216bd2cc | 76 | |
| ktownsend | 2:ffc5216bd2cc | 77 | #endif |
