YUFEI JIANG / BLE_API_Tiny_BLE

Dependents:   CSSE4011_BLE_IMU

Fork of BLE_API by Bluetooth Low Energy

Committer:
ktownsend
Date:
Thu Jan 09 11:03:10 2014 +0000
Revision:
27:4a83843f04b0
Parent:
21:5442f7c70e71
Child:
31:2c94f0501807
Matching file names and apache headers

Who changed what in which revision?

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