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