Andriy Makukha / Mbed 2 deprecated football_project_wo_output

Dependencies:   mbed

Fork of football_project by MZJ

Committer:
AntonLS
Date:
Sat Jul 11 01:57:40 2015 +0000
Revision:
16:3c873f2c8a27
Converted BLE_API lib to folder so the version stays frozen.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AntonLS 16:3c873f2c8a27 1 /* mbed Microcontroller Library
AntonLS 16:3c873f2c8a27 2 * Copyright (c) 2006-2013 ARM Limited
AntonLS 16:3c873f2c8a27 3 *
AntonLS 16:3c873f2c8a27 4 * Licensed under the Apache License, Version 2.0 (the "License");
AntonLS 16:3c873f2c8a27 5 * you may not use this file except in compliance with the License.
AntonLS 16:3c873f2c8a27 6 * You may obtain a copy of the License at
AntonLS 16:3c873f2c8a27 7 *
AntonLS 16:3c873f2c8a27 8 * http://www.apache.org/licenses/LICENSE-2.0
AntonLS 16:3c873f2c8a27 9 *
AntonLS 16:3c873f2c8a27 10 * Unless required by applicable law or agreed to in writing, software
AntonLS 16:3c873f2c8a27 11 * distributed under the License is distributed on an "AS IS" BASIS,
AntonLS 16:3c873f2c8a27 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
AntonLS 16:3c873f2c8a27 13 * See the License for the specific language governing permissions and
AntonLS 16:3c873f2c8a27 14 * limitations under the License.
AntonLS 16:3c873f2c8a27 15 */
AntonLS 16:3c873f2c8a27 16
AntonLS 16:3c873f2c8a27 17 #include <stdio.h>
AntonLS 16:3c873f2c8a27 18 #include <string.h>
AntonLS 16:3c873f2c8a27 19
AntonLS 16:3c873f2c8a27 20 #include "GapAdvertisingData.h"
AntonLS 16:3c873f2c8a27 21
AntonLS 16:3c873f2c8a27 22 /**************************************************************************/
AntonLS 16:3c873f2c8a27 23 /*!
AntonLS 16:3c873f2c8a27 24 \brief Creates a new GapAdvertisingData instance
AntonLS 16:3c873f2c8a27 25
AntonLS 16:3c873f2c8a27 26 \par EXAMPLE
AntonLS 16:3c873f2c8a27 27
AntonLS 16:3c873f2c8a27 28 \code
AntonLS 16:3c873f2c8a27 29
AntonLS 16:3c873f2c8a27 30 \endcode
AntonLS 16:3c873f2c8a27 31 */
AntonLS 16:3c873f2c8a27 32 /**************************************************************************/
AntonLS 16:3c873f2c8a27 33 GapAdvertisingData::GapAdvertisingData(void) : _payload(), _payloadLen(0), _appearance(GENERIC_TAG) {
AntonLS 16:3c873f2c8a27 34 /* empty */
AntonLS 16:3c873f2c8a27 35 }
AntonLS 16:3c873f2c8a27 36
AntonLS 16:3c873f2c8a27 37 /**************************************************************************/
AntonLS 16:3c873f2c8a27 38 /*!
AntonLS 16:3c873f2c8a27 39 Destructor
AntonLS 16:3c873f2c8a27 40 */
AntonLS 16:3c873f2c8a27 41 /**************************************************************************/
AntonLS 16:3c873f2c8a27 42 GapAdvertisingData::~GapAdvertisingData(void)
AntonLS 16:3c873f2c8a27 43 {
AntonLS 16:3c873f2c8a27 44 }
AntonLS 16:3c873f2c8a27 45
AntonLS 16:3c873f2c8a27 46 /**************************************************************************/
AntonLS 16:3c873f2c8a27 47 /*!
AntonLS 16:3c873f2c8a27 48 \brief Adds advertising data based on the specified AD type (see
AntonLS 16:3c873f2c8a27 49 DataType)
AntonLS 16:3c873f2c8a27 50
AntonLS 16:3c873f2c8a27 51 \args[in] advDataType The Advertising 'DataType' to add
AntonLS 16:3c873f2c8a27 52 \args[in] payload Pointer to the payload contents
AntonLS 16:3c873f2c8a27 53 \args[in] len Size of the payload in bytes
AntonLS 16:3c873f2c8a27 54
AntonLS 16:3c873f2c8a27 55 \returns ble_error_t
AntonLS 16:3c873f2c8a27 56
AntonLS 16:3c873f2c8a27 57 \retval BLE_ERROR_NONE
AntonLS 16:3c873f2c8a27 58 Everything executed properly
AntonLS 16:3c873f2c8a27 59
AntonLS 16:3c873f2c8a27 60 \retval BLE_ERROR_BUFFER_OVERFLOW
AntonLS 16:3c873f2c8a27 61 The specified data would cause the advertising buffer
AntonLS 16:3c873f2c8a27 62 to overflow
AntonLS 16:3c873f2c8a27 63
AntonLS 16:3c873f2c8a27 64 \par EXAMPLE
AntonLS 16:3c873f2c8a27 65
AntonLS 16:3c873f2c8a27 66 \code
AntonLS 16:3c873f2c8a27 67
AntonLS 16:3c873f2c8a27 68 \endcode
AntonLS 16:3c873f2c8a27 69 */
AntonLS 16:3c873f2c8a27 70 /**************************************************************************/
AntonLS 16:3c873f2c8a27 71 ble_error_t GapAdvertisingData::addData(DataType advDataType, const uint8_t *payload, uint8_t len)
AntonLS 16:3c873f2c8a27 72 {
AntonLS 16:3c873f2c8a27 73 /* ToDo: Check if an AD type already exists and if the existing */
AntonLS 16:3c873f2c8a27 74 /* value is exclusive or not (flags, etc.) */
AntonLS 16:3c873f2c8a27 75
AntonLS 16:3c873f2c8a27 76 /* Make sure we don't exceed the 31 byte payload limit */
AntonLS 16:3c873f2c8a27 77 if (_payloadLen + len + 2 > GAP_ADVERTISING_DATA_MAX_PAYLOAD) {
AntonLS 16:3c873f2c8a27 78 return BLE_ERROR_BUFFER_OVERFLOW;
AntonLS 16:3c873f2c8a27 79 }
AntonLS 16:3c873f2c8a27 80
AntonLS 16:3c873f2c8a27 81 /* Field length */
AntonLS 16:3c873f2c8a27 82 memset(&_payload[_payloadLen], len + 1, 1);
AntonLS 16:3c873f2c8a27 83 _payloadLen++;
AntonLS 16:3c873f2c8a27 84
AntonLS 16:3c873f2c8a27 85 /* Field ID */
AntonLS 16:3c873f2c8a27 86 memset(&_payload[_payloadLen], (uint8_t)advDataType, 1);
AntonLS 16:3c873f2c8a27 87 _payloadLen++;
AntonLS 16:3c873f2c8a27 88
AntonLS 16:3c873f2c8a27 89 /* Payload */
AntonLS 16:3c873f2c8a27 90 memcpy(&_payload[_payloadLen], payload, len);
AntonLS 16:3c873f2c8a27 91 _payloadLen += len;
AntonLS 16:3c873f2c8a27 92
AntonLS 16:3c873f2c8a27 93 return BLE_ERROR_NONE;
AntonLS 16:3c873f2c8a27 94 }
AntonLS 16:3c873f2c8a27 95
AntonLS 16:3c873f2c8a27 96 /**************************************************************************/
AntonLS 16:3c873f2c8a27 97 /*!
AntonLS 16:3c873f2c8a27 98 \brief Helper function to add APPEARANCE data to the advertising
AntonLS 16:3c873f2c8a27 99 payload
AntonLS 16:3c873f2c8a27 100
AntonLS 16:3c873f2c8a27 101 \args[in] appearance The APPEARANCE value to add
AntonLS 16:3c873f2c8a27 102
AntonLS 16:3c873f2c8a27 103 \returns ble_error_t
AntonLS 16:3c873f2c8a27 104
AntonLS 16:3c873f2c8a27 105 \retval BLE_ERROR_NONE
AntonLS 16:3c873f2c8a27 106 Everything executed properly
AntonLS 16:3c873f2c8a27 107
AntonLS 16:3c873f2c8a27 108 \retval BLE_ERROR_BUFFER_OVERFLOW
AntonLS 16:3c873f2c8a27 109 The specified data would cause the advertising buffer
AntonLS 16:3c873f2c8a27 110 to overflow
AntonLS 16:3c873f2c8a27 111
AntonLS 16:3c873f2c8a27 112 \par EXAMPLE
AntonLS 16:3c873f2c8a27 113
AntonLS 16:3c873f2c8a27 114 \code
AntonLS 16:3c873f2c8a27 115
AntonLS 16:3c873f2c8a27 116 \endcode
AntonLS 16:3c873f2c8a27 117 */
AntonLS 16:3c873f2c8a27 118 /**************************************************************************/
AntonLS 16:3c873f2c8a27 119 ble_error_t GapAdvertisingData::addAppearance(Appearance appearance)
AntonLS 16:3c873f2c8a27 120 {
AntonLS 16:3c873f2c8a27 121 _appearance = appearance;
AntonLS 16:3c873f2c8a27 122 return addData(GapAdvertisingData::APPEARANCE, (uint8_t *)&appearance, 2);
AntonLS 16:3c873f2c8a27 123 }
AntonLS 16:3c873f2c8a27 124
AntonLS 16:3c873f2c8a27 125 /**************************************************************************/
AntonLS 16:3c873f2c8a27 126 /*!
AntonLS 16:3c873f2c8a27 127 \brief Helper function to add FLAGS data to the advertising
AntonLS 16:3c873f2c8a27 128 payload
AntonLS 16:3c873f2c8a27 129
AntonLS 16:3c873f2c8a27 130 \args[in] flag The FLAGS value to add
AntonLS 16:3c873f2c8a27 131
AntonLS 16:3c873f2c8a27 132 \par LE_LIMITED_DISCOVERABLE
AntonLS 16:3c873f2c8a27 133 The peripheral is discoverable for a limited period of
AntonLS 16:3c873f2c8a27 134 time
AntonLS 16:3c873f2c8a27 135
AntonLS 16:3c873f2c8a27 136 \par LE_GENERAL_DISCOVERABLE
AntonLS 16:3c873f2c8a27 137 The peripheral is permanently discoverable
AntonLS 16:3c873f2c8a27 138
AntonLS 16:3c873f2c8a27 139 \par BREDR_NOT_SUPPORTED
AntonLS 16:3c873f2c8a27 140 This peripheral is a Bluetooth Low Energy only device
AntonLS 16:3c873f2c8a27 141 (no EDR support)
AntonLS 16:3c873f2c8a27 142
AntonLS 16:3c873f2c8a27 143 \returns ble_error_t
AntonLS 16:3c873f2c8a27 144
AntonLS 16:3c873f2c8a27 145 \retval BLE_ERROR_NONE
AntonLS 16:3c873f2c8a27 146 Everything executed properly
AntonLS 16:3c873f2c8a27 147
AntonLS 16:3c873f2c8a27 148 \retval BLE_ERROR_BUFFER_OVERFLOW
AntonLS 16:3c873f2c8a27 149 The specified data would cause the advertising buffer
AntonLS 16:3c873f2c8a27 150 to overflow
AntonLS 16:3c873f2c8a27 151
AntonLS 16:3c873f2c8a27 152 \par EXAMPLE
AntonLS 16:3c873f2c8a27 153
AntonLS 16:3c873f2c8a27 154 \code
AntonLS 16:3c873f2c8a27 155
AntonLS 16:3c873f2c8a27 156 \endcode
AntonLS 16:3c873f2c8a27 157 */
AntonLS 16:3c873f2c8a27 158 /**************************************************************************/
AntonLS 16:3c873f2c8a27 159 ble_error_t GapAdvertisingData::addFlags(uint8_t flags)
AntonLS 16:3c873f2c8a27 160 {
AntonLS 16:3c873f2c8a27 161 return addData(GapAdvertisingData::FLAGS, &flags, 1);
AntonLS 16:3c873f2c8a27 162 }
AntonLS 16:3c873f2c8a27 163
AntonLS 16:3c873f2c8a27 164 /**************************************************************************/
AntonLS 16:3c873f2c8a27 165 /*!
AntonLS 16:3c873f2c8a27 166 \brief Helper function to add TX_POWER_LEVEL data to the
AntonLS 16:3c873f2c8a27 167 advertising payload
AntonLS 16:3c873f2c8a27 168
AntonLS 16:3c873f2c8a27 169 \args[in] flag The TX_POWER_LEVEL value to add
AntonLS 16:3c873f2c8a27 170
AntonLS 16:3c873f2c8a27 171 \returns ble_error_t
AntonLS 16:3c873f2c8a27 172
AntonLS 16:3c873f2c8a27 173 \retval BLE_ERROR_NONE
AntonLS 16:3c873f2c8a27 174 Everything executed properly
AntonLS 16:3c873f2c8a27 175
AntonLS 16:3c873f2c8a27 176 \retval BLE_ERROR_BUFFER_OVERFLOW
AntonLS 16:3c873f2c8a27 177 The specified data would cause the advertising buffer
AntonLS 16:3c873f2c8a27 178 to overflow
AntonLS 16:3c873f2c8a27 179
AntonLS 16:3c873f2c8a27 180 \par EXAMPLE
AntonLS 16:3c873f2c8a27 181
AntonLS 16:3c873f2c8a27 182 \code
AntonLS 16:3c873f2c8a27 183
AntonLS 16:3c873f2c8a27 184 \endcode
AntonLS 16:3c873f2c8a27 185 */
AntonLS 16:3c873f2c8a27 186 /**************************************************************************/
AntonLS 16:3c873f2c8a27 187 ble_error_t GapAdvertisingData::addTxPower(int8_t txPower)
AntonLS 16:3c873f2c8a27 188 {
AntonLS 16:3c873f2c8a27 189 /* ToDo: Basic error checking to make sure txPower is in range */
AntonLS 16:3c873f2c8a27 190 return addData(GapAdvertisingData::TX_POWER_LEVEL, (uint8_t *)&txPower, 1);
AntonLS 16:3c873f2c8a27 191 }
AntonLS 16:3c873f2c8a27 192
AntonLS 16:3c873f2c8a27 193 /**************************************************************************/
AntonLS 16:3c873f2c8a27 194 /*!
AntonLS 16:3c873f2c8a27 195 \brief Clears the payload and resets the payload length counter
AntonLS 16:3c873f2c8a27 196 */
AntonLS 16:3c873f2c8a27 197 /**************************************************************************/
AntonLS 16:3c873f2c8a27 198 void GapAdvertisingData::clear(void)
AntonLS 16:3c873f2c8a27 199 {
AntonLS 16:3c873f2c8a27 200 memset(&_payload, 0, GAP_ADVERTISING_DATA_MAX_PAYLOAD);
AntonLS 16:3c873f2c8a27 201 _payloadLen = 0;
AntonLS 16:3c873f2c8a27 202 }
AntonLS 16:3c873f2c8a27 203
AntonLS 16:3c873f2c8a27 204 /**************************************************************************/
AntonLS 16:3c873f2c8a27 205 /*!
AntonLS 16:3c873f2c8a27 206 \brief Returns a pointer to the the current payload
AntonLS 16:3c873f2c8a27 207
AntonLS 16:3c873f2c8a27 208 \returns A pointer to the payload
AntonLS 16:3c873f2c8a27 209 */
AntonLS 16:3c873f2c8a27 210 /**************************************************************************/
AntonLS 16:3c873f2c8a27 211 const uint8_t *GapAdvertisingData::getPayload(void) const
AntonLS 16:3c873f2c8a27 212 {
AntonLS 16:3c873f2c8a27 213 return (_payloadLen > 0) ? _payload : NULL;
AntonLS 16:3c873f2c8a27 214 }
AntonLS 16:3c873f2c8a27 215
AntonLS 16:3c873f2c8a27 216 /**************************************************************************/
AntonLS 16:3c873f2c8a27 217 /*!
AntonLS 16:3c873f2c8a27 218 \brief Returns the current payload length (0..31 bytes)
AntonLS 16:3c873f2c8a27 219
AntonLS 16:3c873f2c8a27 220 \returns The payload length in bytes
AntonLS 16:3c873f2c8a27 221 */
AntonLS 16:3c873f2c8a27 222 /**************************************************************************/
AntonLS 16:3c873f2c8a27 223 uint8_t GapAdvertisingData::getPayloadLen(void) const
AntonLS 16:3c873f2c8a27 224 {
AntonLS 16:3c873f2c8a27 225 return _payloadLen;
AntonLS 16:3c873f2c8a27 226 }
AntonLS 16:3c873f2c8a27 227
AntonLS 16:3c873f2c8a27 228 /**************************************************************************/
AntonLS 16:3c873f2c8a27 229 /*!
AntonLS 16:3c873f2c8a27 230 \brief Returns the 16-bit appearance value for this device
AntonLS 16:3c873f2c8a27 231
AntonLS 16:3c873f2c8a27 232 \returns The 16-bit appearance value
AntonLS 16:3c873f2c8a27 233 */
AntonLS 16:3c873f2c8a27 234 /**************************************************************************/
AntonLS 16:3c873f2c8a27 235 uint16_t GapAdvertisingData::getAppearance(void) const
AntonLS 16:3c873f2c8a27 236 {
AntonLS 16:3c873f2c8a27 237 return (uint16_t)_appearance;
AntonLS 16:3c873f2c8a27 238 }