High level Bluetooth Low Energy API and radio abstraction layer

Dependencies:   nRF51822

Dependents:   LinkNode_LIS3DH

Fork of BLE_API by Bluetooth Low Energy

Committer:
rgrover1
Date:
Fri Jun 19 15:52:07 2015 +0100
Revision:
531:bdcd44b03974
Parent:
331:10f190629734
Child:
567:e4b38e43de7c
Synchronized with git rev e74eb3b4
Author: Rohit Grover
moved GAP related members out of BLE and into GAP

Who changed what in which revision?

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