Microbug / BLE_API_FOTA

Fork of BLE_API by Bluetooth Low Energy

Committer:
ktownsend
Date:
Wed Dec 18 19:39:19 2013 +0000
Revision:
18:86fe1e247a54
Parent:
14:6ea5d1012a64
Child:
27:4a83843f04b0
Doxygen Cleanup

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ktownsend 2:ffc5216bd2cc 1 #include <stdio.h>
ktownsend 2:ffc5216bd2cc 2 #include <string.h>
ktownsend 2:ffc5216bd2cc 3
ktownsend 2:ffc5216bd2cc 4 #include "GapAdvertisingData.h"
ktownsend 2:ffc5216bd2cc 5
ktownsend 2:ffc5216bd2cc 6 /**************************************************************************/
ktownsend 2:ffc5216bd2cc 7 /*!
ktownsend 18:86fe1e247a54 8 \brief Creates a new GapAdvertisingData instance
ktownsend 2:ffc5216bd2cc 9
ktownsend 18:86fe1e247a54 10 \par EXAMPLE
ktownsend 2:ffc5216bd2cc 11
ktownsend 18:86fe1e247a54 12 \code
ktownsend 2:ffc5216bd2cc 13
ktownsend 18:86fe1e247a54 14 \endcode
ktownsend 2:ffc5216bd2cc 15 */
ktownsend 2:ffc5216bd2cc 16 /**************************************************************************/
ktownsend 2:ffc5216bd2cc 17 GapAdvertisingData::GapAdvertisingData(void)
ktownsend 2:ffc5216bd2cc 18 {
ktownsend 3:46de446e82ed 19 memset(_payload, 0, GAP_ADVERTISING_DATA_MAX_PAYLOAD);
ktownsend 3:46de446e82ed 20 _payloadLen = 0;
ktownsend 2:ffc5216bd2cc 21 }
ktownsend 2:ffc5216bd2cc 22
ktownsend 2:ffc5216bd2cc 23 /**************************************************************************/
ktownsend 2:ffc5216bd2cc 24 /*!
ktownsend 2:ffc5216bd2cc 25 Destructor
ktownsend 2:ffc5216bd2cc 26 */
ktownsend 2:ffc5216bd2cc 27 /**************************************************************************/
ktownsend 2:ffc5216bd2cc 28 GapAdvertisingData::~GapAdvertisingData(void)
ktownsend 2:ffc5216bd2cc 29 {
ktownsend 2:ffc5216bd2cc 30 }
ktownsend 3:46de446e82ed 31
ktownsend 3:46de446e82ed 32 /**************************************************************************/
ktownsend 3:46de446e82ed 33 /*!
ktownsend 18:86fe1e247a54 34 \brief Adds advertising data based on the specified AD type (see
ktownsend 18:86fe1e247a54 35 DataType)
ktownsend 3:46de446e82ed 36
ktownsend 18:86fe1e247a54 37 \args[in] advDataType The Advertising 'DataType' to add
ktownsend 18:86fe1e247a54 38 \args[in] payload Pointer to the payload contents
ktownsend 18:86fe1e247a54 39 \args[in] len Size of the payload in bytes
ktownsend 3:46de446e82ed 40
ktownsend 18:86fe1e247a54 41 \returns ble_error_t
ktownsend 3:46de446e82ed 42
ktownsend 18:86fe1e247a54 43 \retval BLE_ERROR_NONE
ktownsend 3:46de446e82ed 44 Everything executed properly
ktownsend 4:50a31ff5f974 45
ktownsend 18:86fe1e247a54 46 \retval BLE_ERROR_BUFFER_OVERFLOW
ktownsend 4:50a31ff5f974 47 The specified data would cause the advertising buffer
ktownsend 4:50a31ff5f974 48 to overflow
ktownsend 4:50a31ff5f974 49
ktownsend 18:86fe1e247a54 50 \par EXAMPLE
ktownsend 4:50a31ff5f974 51
ktownsend 18:86fe1e247a54 52 \code
ktownsend 4:50a31ff5f974 53
ktownsend 18:86fe1e247a54 54 \endcode
ktownsend 4:50a31ff5f974 55 */
ktownsend 4:50a31ff5f974 56 /**************************************************************************/
ktownsend 4:50a31ff5f974 57 ble_error_t GapAdvertisingData::addData(DataType advDataType, uint8_t * payload, uint8_t len)
ktownsend 4:50a31ff5f974 58 {
ktownsend 4:50a31ff5f974 59 /* ToDo: Check if an AD type already exists and if the existing */
ktownsend 4:50a31ff5f974 60 /* value is exclusive or not (flags, etc.) */
ktownsend 4:50a31ff5f974 61
ktownsend 4:50a31ff5f974 62 /* Make sure we don't exceed the 31 byte payload limit */
ktownsend 14:6ea5d1012a64 63 if (_payloadLen + len + 2 >= GAP_ADVERTISING_DATA_MAX_PAYLOAD)
ktownsend 4:50a31ff5f974 64 return BLE_ERROR_BUFFER_OVERFLOW;
ktownsend 14:6ea5d1012a64 65
ktownsend 14:6ea5d1012a64 66 /* Field length */
ktownsend 14:6ea5d1012a64 67 memset(&_payload[_payloadLen], len+1, 1);
ktownsend 14:6ea5d1012a64 68 _payloadLen++;
ktownsend 4:50a31ff5f974 69
ktownsend 14:6ea5d1012a64 70 /* Field ID */
ktownsend 14:6ea5d1012a64 71 memset(&_payload[_payloadLen], (uint8_t)advDataType, 1);
ktownsend 14:6ea5d1012a64 72 _payloadLen++;
ktownsend 14:6ea5d1012a64 73
ktownsend 14:6ea5d1012a64 74 /* Payload */
ktownsend 4:50a31ff5f974 75 memcpy(&_payload[_payloadLen], payload, len);
ktownsend 4:50a31ff5f974 76 _payloadLen += len;
ktownsend 4:50a31ff5f974 77
ktownsend 4:50a31ff5f974 78 return BLE_ERROR_NONE;
ktownsend 4:50a31ff5f974 79 }
ktownsend 4:50a31ff5f974 80
ktownsend 4:50a31ff5f974 81 /**************************************************************************/
ktownsend 4:50a31ff5f974 82 /*!
ktownsend 18:86fe1e247a54 83 \brief Helper function to add APPEARANCE data to the advertising
ktownsend 4:50a31ff5f974 84 payload
ktownsend 4:50a31ff5f974 85
ktownsend 18:86fe1e247a54 86 \args[in] appearance The APPEARANCE value to add
ktownsend 4:50a31ff5f974 87
ktownsend 18:86fe1e247a54 88 \returns ble_error_t
ktownsend 4:50a31ff5f974 89
ktownsend 18:86fe1e247a54 90 \retval BLE_ERROR_NONE
ktownsend 4:50a31ff5f974 91 Everything executed properly
ktownsend 4:50a31ff5f974 92
ktownsend 18:86fe1e247a54 93 \retval BLE_ERROR_BUFFER_OVERFLOW
ktownsend 3:46de446e82ed 94 The specified data would cause the advertising buffer
ktownsend 3:46de446e82ed 95 to overflow
ktownsend 3:46de446e82ed 96
ktownsend 18:86fe1e247a54 97 \par EXAMPLE
ktownsend 3:46de446e82ed 98
ktownsend 18:86fe1e247a54 99 \code
ktownsend 3:46de446e82ed 100
ktownsend 18:86fe1e247a54 101 \endcode
ktownsend 3:46de446e82ed 102 */
ktownsend 3:46de446e82ed 103 /**************************************************************************/
ktownsend 4:50a31ff5f974 104 ble_error_t GapAdvertisingData::addAppearance(Appearance appearance)
ktownsend 3:46de446e82ed 105 {
ktownsend 4:50a31ff5f974 106 return addData(GapAdvertisingData::APPEARANCE, (uint8_t*)&appearance, 2);
ktownsend 4:50a31ff5f974 107 }
ktownsend 4:50a31ff5f974 108
ktownsend 4:50a31ff5f974 109 /**************************************************************************/
ktownsend 4:50a31ff5f974 110 /*!
ktownsend 18:86fe1e247a54 111 \brief Helper function to add FLAGS data to the advertising
ktownsend 4:50a31ff5f974 112 payload
ktownsend 4:50a31ff5f974 113
ktownsend 18:86fe1e247a54 114 \args[in] flag The FLAGS value to add
ktownsend 4:50a31ff5f974 115
ktownsend 18:86fe1e247a54 116 \par LE_LIMITED_DISCOVERABLE
ktownsend 18:86fe1e247a54 117 The peripheral is discoverable for a limited period of
ktownsend 18:86fe1e247a54 118 time
ktownsend 4:50a31ff5f974 119
ktownsend 18:86fe1e247a54 120 \par LE_GENERAL_DISCOVERABLE
ktownsend 18:86fe1e247a54 121 The peripheral is permanently discoverable
ktownsend 5:7635f81a8e09 122
ktownsend 18:86fe1e247a54 123 \par BREDR_NOT_SUPPORTED
ktownsend 18:86fe1e247a54 124 This peripheral is a Bluetooth Low Energy only device
ktownsend 18:86fe1e247a54 125 (no EDR support)
ktownsend 4:50a31ff5f974 126
ktownsend 18:86fe1e247a54 127 \returns ble_error_t
ktownsend 4:50a31ff5f974 128
ktownsend 18:86fe1e247a54 129 \retval BLE_ERROR_NONE
ktownsend 4:50a31ff5f974 130 Everything executed properly
ktownsend 4:50a31ff5f974 131
ktownsend 18:86fe1e247a54 132 \retval BLE_ERROR_BUFFER_OVERFLOW
ktownsend 4:50a31ff5f974 133 The specified data would cause the advertising buffer
ktownsend 4:50a31ff5f974 134 to overflow
ktownsend 3:46de446e82ed 135
ktownsend 18:86fe1e247a54 136 \par EXAMPLE
ktownsend 4:50a31ff5f974 137
ktownsend 18:86fe1e247a54 138 \code
ktownsend 4:50a31ff5f974 139
ktownsend 18:86fe1e247a54 140 \endcode
ktownsend 4:50a31ff5f974 141 */
ktownsend 4:50a31ff5f974 142 /**************************************************************************/
ktownsend 4:50a31ff5f974 143 ble_error_t GapAdvertisingData::addFlags(Flags flag)
ktownsend 4:50a31ff5f974 144 {
ktownsend 4:50a31ff5f974 145 return addData(GapAdvertisingData::FLAGS, (uint8_t*)&flag, 1);
ktownsend 4:50a31ff5f974 146 }
ktownsend 4:50a31ff5f974 147
ktownsend 4:50a31ff5f974 148 /**************************************************************************/
ktownsend 4:50a31ff5f974 149 /*!
ktownsend 18:86fe1e247a54 150 \brief Helper function to add TX_POWER_LEVEL data to the
ktownsend 4:50a31ff5f974 151 advertising payload
ktownsend 4:50a31ff5f974 152
ktownsend 18:86fe1e247a54 153 \args[in] flag The TX_POWER_LEVEL value to add
ktownsend 4:50a31ff5f974 154
ktownsend 18:86fe1e247a54 155 \returns ble_error_t
ktownsend 4:50a31ff5f974 156
ktownsend 18:86fe1e247a54 157 \retval BLE_ERROR_NONE
ktownsend 4:50a31ff5f974 158 Everything executed properly
ktownsend 4:50a31ff5f974 159
ktownsend 18:86fe1e247a54 160 \retval BLE_ERROR_BUFFER_OVERFLOW
ktownsend 4:50a31ff5f974 161 The specified data would cause the advertising buffer
ktownsend 4:50a31ff5f974 162 to overflow
ktownsend 3:46de446e82ed 163
ktownsend 18:86fe1e247a54 164 \par EXAMPLE
ktownsend 4:50a31ff5f974 165
ktownsend 18:86fe1e247a54 166 \code
ktownsend 4:50a31ff5f974 167
ktownsend 18:86fe1e247a54 168 \endcode
ktownsend 4:50a31ff5f974 169 */
ktownsend 4:50a31ff5f974 170 /**************************************************************************/
ktownsend 4:50a31ff5f974 171 ble_error_t GapAdvertisingData::addTxPower(int8_t txPower)
ktownsend 4:50a31ff5f974 172 {
ktownsend 4:50a31ff5f974 173 /* ToDo: Basic error checking to make sure txPower is in range */
ktownsend 4:50a31ff5f974 174 return addData(GapAdvertisingData::TX_POWER_LEVEL, (uint8_t*)&txPower, 1);
ktownsend 3:46de446e82ed 175 }
ktownsend 4:50a31ff5f974 176
ktownsend 4:50a31ff5f974 177 /**************************************************************************/
ktownsend 4:50a31ff5f974 178 /*!
ktownsend 18:86fe1e247a54 179 \brief Clears the payload and resets the payload length counter
ktownsend 4:50a31ff5f974 180 */
ktownsend 4:50a31ff5f974 181 /**************************************************************************/
ktownsend 4:50a31ff5f974 182 void GapAdvertisingData::clear(void)
ktownsend 4:50a31ff5f974 183 {
ktownsend 4:50a31ff5f974 184 memset(&_payload, 0, GAP_ADVERTISING_DATA_MAX_PAYLOAD);
ktownsend 4:50a31ff5f974 185 _payloadLen = 0;
ktownsend 4:50a31ff5f974 186 }
ktownsend 4:50a31ff5f974 187
ktownsend 4:50a31ff5f974 188 /**************************************************************************/
ktownsend 4:50a31ff5f974 189 /*!
ktownsend 18:86fe1e247a54 190 \brief Returns a pointer to the the current payload
ktownsend 7:5e1f0d7f7c7d 191
ktownsend 18:86fe1e247a54 192 \returns A pointer to the payload
ktownsend 7:5e1f0d7f7c7d 193 */
ktownsend 7:5e1f0d7f7c7d 194 /**************************************************************************/
ktownsend 7:5e1f0d7f7c7d 195 uint8_t * GapAdvertisingData::getPayload(void)
ktownsend 7:5e1f0d7f7c7d 196 {
ktownsend 7:5e1f0d7f7c7d 197 return _payload;
ktownsend 7:5e1f0d7f7c7d 198 }
ktownsend 7:5e1f0d7f7c7d 199
ktownsend 7:5e1f0d7f7c7d 200 /**************************************************************************/
ktownsend 7:5e1f0d7f7c7d 201 /*!
ktownsend 18:86fe1e247a54 202 \brief Returns the current payload length (0..31 bytes)
ktownsend 7:5e1f0d7f7c7d 203
ktownsend 18:86fe1e247a54 204 \returns The payload length in bytes
ktownsend 4:50a31ff5f974 205 */
ktownsend 4:50a31ff5f974 206 /**************************************************************************/
ktownsend 4:50a31ff5f974 207 uint8_t GapAdvertisingData::getPayloadLen(void)
ktownsend 4:50a31ff5f974 208 {
ktownsend 4:50a31ff5f974 209 return _payloadLen;
ktownsend 4:50a31ff5f974 210 }