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