テスト用です。

Dependencies:   mbed

Committer:
jksoft
Date:
Tue Oct 11 11:09:42 2016 +0000
Revision:
0:8468a4403fea
SB??ver;

Who changed what in which revision?

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