ble

Dependencies:   HC_SR04_Ultrasonic_Library Servo mbed

Fork of FIP_REV1 by Robotique FIP

Committer:
julientiron
Date:
Thu Jul 09 13:33:36 2015 +0000
Revision:
4:69a35a56ac48
Parent:
0:3d641e170a74
BLE

Who changed what in which revision?

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