fka mod

Fork of BLE_API by Bluetooth Low Energy

Committer:
rgrover1
Date:
Fri Jun 19 15:53:28 2015 +0100
Revision:
710:b2e1a2660ec2
Child:
756:503c4bd89a3d
Synchronized with git rev 7e8977d8
Author: Rohit Grover
Release 0.3.8
=============

This is a minor set of enhancements before we yotta-ize BLE_API.

Enhancements
~~~~~~~~~~~~

* Minor rework for class UUID; added a default and copy constructor; and a != operator.

* Added copy constructor and accessors for GapAdvertisingParams.

* GapScanningParams:: remove unnecessary checks for SCAN_TIMEOUT_MAX.

* Add a comment header block to explain why BLEDevice::init() may not be safe
to call from global static context.

* Introduce GattAttribute::INVALID_HANDLE.

* Replace some deprecated uses of Gap::address_t with Gap::Address_t.

Bugfixes
~~~~~~~~

* None.

Who changed what in which revision?

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