BLE temperature profile using digital DS1820 or analog LM35 sensors

Dependencies:   DS1820

Committer:
gkroussos
Date:
Sat Mar 07 16:23:41 2015 +0000
Revision:
0:637031152314
Working version 1.0

Who changed what in which revision?

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