HW layer for the Nucleo board, it only work with old BLE_API

Dependents:   Hello_BLE F446RE-BLE

Fork of X_NUCLEO_IDB0XA1 by ST

Committer:
hemddabral
Date:
Wed Apr 15 09:56:53 2015 +0000
Revision:
69:2c340304de64
Parent:
67:23f9772ef7bf
Implementation of BlueNRGGap::getMaxAdvertisingInterval(), BlueNRGGap::getMinAdvertisingInterval(), and BlueNRGGap::getMinNonConnectableAdvertisingInterval().

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mridup 2:a2b623661316 1 /* mbed Microcontroller Library
hemddabral 58:027c65a54097 2 * Copyright (c) 2006-2013 ARM Limited
hemddabral 58:027c65a54097 3 *
hemddabral 58:027c65a54097 4 * Licensed under the Apache License, Version 2.0 (the "License");
hemddabral 58:027c65a54097 5 * you may not use this file except in compliance with the License.
hemddabral 58:027c65a54097 6 * You may obtain a copy of the License at
hemddabral 58:027c65a54097 7 *
hemddabral 58:027c65a54097 8 * http://www.apache.org/licenses/LICENSE-2.0
hemddabral 58:027c65a54097 9 *
hemddabral 58:027c65a54097 10 * Unless required by applicable law or agreed to in writing, software
hemddabral 58:027c65a54097 11 * distributed under the License is distributed on an "AS IS" BASIS,
hemddabral 58:027c65a54097 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
hemddabral 58:027c65a54097 13 * See the License for the specific language governing permissions and
hemddabral 58:027c65a54097 14 * limitations under the License.
hemddabral 58:027c65a54097 15 */
mridup 2:a2b623661316 16
mridup 64:6d7b775c3f6d 17
mridup 64:6d7b775c3f6d 18 /**
mridup 64:6d7b775c3f6d 19 ******************************************************************************
mridup 64:6d7b775c3f6d 20 * @file BlueNRGGap.cpp
mridup 64:6d7b775c3f6d 21 * @author STMicroelectronics
mridup 64:6d7b775c3f6d 22 * @brief Implementation of BLE_API Gap Class
mridup 64:6d7b775c3f6d 23 ******************************************************************************
mridup 64:6d7b775c3f6d 24 * @copy
mridup 64:6d7b775c3f6d 25 *
mridup 64:6d7b775c3f6d 26 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
mridup 64:6d7b775c3f6d 27 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
mridup 64:6d7b775c3f6d 28 * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
mridup 64:6d7b775c3f6d 29 * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
mridup 64:6d7b775c3f6d 30 * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
mridup 64:6d7b775c3f6d 31 * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
mridup 64:6d7b775c3f6d 32 *
mridup 64:6d7b775c3f6d 33 * <h2><center>&copy; COPYRIGHT 2013 STMicroelectronics</center></h2>
mridup 64:6d7b775c3f6d 34 */
mridup 64:6d7b775c3f6d 35
mridup 64:6d7b775c3f6d 36 /** @defgroup BlueNRGGap
mridup 64:6d7b775c3f6d 37 * @brief BlueNRG BLE_API GAP Adaptation
mridup 64:6d7b775c3f6d 38 * @{
mridup 64:6d7b775c3f6d 39 */
mridup 64:6d7b775c3f6d 40
mridup 64:6d7b775c3f6d 41
mridup 2:a2b623661316 42 #include "BlueNRGDevice.h"
mridup 2:a2b623661316 43 #include "mbed.h"
hemddabral 10:814262eb0746 44 #include "Payload.h"
hemddabral 12:a5d7db4a1e49 45 #include "Utils.h"
mridup 2:a2b623661316 46
mridup 3:9c4c13795643 47 //Local Variables
hemddabral 10:814262eb0746 48 const char *local_name = NULL;
hemddabral 10:814262eb0746 49 uint8_t local_name_length = 0;
mridup 44:b4a986b33c7d 50 const uint8_t *scan_response_payload = NULL;
mridup 44:b4a986b33c7d 51 uint8_t scan_rsp_length = 0;
hemddabral 14:baa7a1464517 52 uint8_t servUuidlength = 0;
hemddabral 14:baa7a1464517 53 uint8_t* servUuidData = NULL;
hemddabral 14:baa7a1464517 54
hemddabral 69:2c340304de64 55 uint32_t advtInterval = BLUENRG_GAP_ADV_INTERVAL_MAX;
mridup 2:a2b623661316 56
mridup 2:a2b623661316 57 /**************************************************************************/
mridup 2:a2b623661316 58 /*!
hemddabral 25:f3ea48a2008b 59 @brief Sets the advertising parameters and payload for the device.
hemddabral 25:f3ea48a2008b 60 Note: Some data types give error when their adv data is updated using aci_gap_update_adv_data() API
mridup 2:a2b623661316 61
mridup 2:a2b623661316 62 @params[in] advData
mridup 2:a2b623661316 63 The primary advertising data payload
mridup 2:a2b623661316 64 @params[in] scanResponse
mridup 2:a2b623661316 65 The optional Scan Response payload if the advertising
mridup 2:a2b623661316 66 type is set to \ref GapAdvertisingParams::ADV_SCANNABLE_UNDIRECTED
mridup 2:a2b623661316 67 in \ref GapAdveritinngParams
mridup 2:a2b623661316 68
mridup 2:a2b623661316 69 @returns \ref ble_error_t
mridup 2:a2b623661316 70
mridup 2:a2b623661316 71 @retval BLE_ERROR_NONE
mridup 2:a2b623661316 72 Everything executed properly
mridup 2:a2b623661316 73
mridup 2:a2b623661316 74 @retval BLE_ERROR_BUFFER_OVERFLOW
mridup 2:a2b623661316 75 The proposed action would cause a buffer overflow. All
mridup 2:a2b623661316 76 advertising payloads must be <= 31 bytes, for example.
mridup 2:a2b623661316 77
mridup 2:a2b623661316 78 @retval BLE_ERROR_NOT_IMPLEMENTED
mridup 2:a2b623661316 79 A feature was requested that is not yet supported in the
mridup 2:a2b623661316 80 nRF51 firmware or hardware.
mridup 2:a2b623661316 81
mridup 2:a2b623661316 82 @retval BLE_ERROR_PARAM_OUT_OF_RANGE
mridup 2:a2b623661316 83 One of the proposed values is outside the valid range.
mridup 2:a2b623661316 84
mridup 2:a2b623661316 85 @section EXAMPLE
mridup 2:a2b623661316 86
mridup 2:a2b623661316 87 @code
mridup 2:a2b623661316 88
mridup 2:a2b623661316 89 @endcode
mridup 2:a2b623661316 90 */
mridup 2:a2b623661316 91 /**************************************************************************/
mridup 2:a2b623661316 92 ble_error_t BlueNRGGap::setAdvertisingData(const GapAdvertisingData &advData, const GapAdvertisingData &scanResponse)
hemddabral 19:0f87aaf1362d 93 {
mridup 20:718d56821672 94 DEBUG("BlueNRGGap::setAdvertisingData\n\r");
mridup 2:a2b623661316 95 /* Make sure we don't exceed the advertising payload length */
mridup 2:a2b623661316 96 if (advData.getPayloadLen() > GAP_ADVERTISING_DATA_MAX_PAYLOAD) {
mridup 2:a2b623661316 97 return BLE_ERROR_BUFFER_OVERFLOW;
mridup 2:a2b623661316 98 }
mridup 2:a2b623661316 99
mridup 2:a2b623661316 100 /* Make sure we have a payload! */
hemddabral 10:814262eb0746 101 if (advData.getPayloadLen() <= 0) {
mridup 2:a2b623661316 102 return BLE_ERROR_PARAM_OUT_OF_RANGE;
hemddabral 18:6d5f4c638f6a 103 } else {
hemddabral 18:6d5f4c638f6a 104 PayloadPtr loadPtr(advData.getPayload(), advData.getPayloadLen());
hemddabral 24:1c7266497633 105 for(uint8_t index=0; index<loadPtr.getPayloadUnitCount(); index++) {
hemddabral 18:6d5f4c638f6a 106 PayloadUnit unit = loadPtr.getUnitAtIndex(index);
hemddabral 25:f3ea48a2008b 107
mridup 20:718d56821672 108 DEBUG("adData[%d].length=%d\n\r", index,(uint8_t)(*loadPtr.getUnitAtIndex(index).getLenPtr()));
hemddabral 58:027c65a54097 109 DEBUG("adData[%d].AdType=0x%x\n\r", index,(uint8_t)(*loadPtr.getUnitAtIndex(index).getAdTypePtr()));
hemddabral 58:027c65a54097 110
hemddabral 18:6d5f4c638f6a 111 switch(*loadPtr.getUnitAtIndex(index).getAdTypePtr()) {
hemddabral 58:027c65a54097 112 case GapAdvertisingData::FLAGS: /* ref *Flags */
mridup 60:b0b2d639c0f5 113 {
mridup 43:b69d2680b716 114 //Check if Flags are OK. BlueNRG only supports LE Mode.
mridup 43:b69d2680b716 115 uint8_t *flags = loadPtr.getUnitAtIndex(index).getDataPtr();
mridup 43:b69d2680b716 116 if((*flags & GapAdvertisingData::BREDR_NOT_SUPPORTED) != GapAdvertisingData::BREDR_NOT_SUPPORTED) {
hemddabral 58:027c65a54097 117 DEBUG("BlueNRG does not support BR/EDR Mode");
hemddabral 58:027c65a54097 118 return BLE_ERROR_PARAM_OUT_OF_RANGE;
hemddabral 58:027c65a54097 119 }
mridup 43:b69d2680b716 120
hemddabral 10:814262eb0746 121 break;
mridup 60:b0b2d639c0f5 122 }
hemddabral 58:027c65a54097 123 case GapAdvertisingData::INCOMPLETE_LIST_16BIT_SERVICE_IDS: /**< Incomplete list of 16-bit Service IDs */
mridup 60:b0b2d639c0f5 124 {
hemddabral 10:814262eb0746 125 break;
mridup 60:b0b2d639c0f5 126 }
hemddabral 58:027c65a54097 127 case GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS: /**< Complete list of 16-bit Service IDs */
mridup 60:b0b2d639c0f5 128 {
hemddabral 58:027c65a54097 129 DEBUG("Advertising type: COMPLETE_LIST_16BIT_SERVICE_IDS\n\r");
hemddabral 58:027c65a54097 130 DEBUG("Advertising type: COMPLETE_LIST_16BIT_SERVICE_IDS\n");
hemddabral 58:027c65a54097 131 #if 0
hemddabral 58:027c65a54097 132 int err = aci_gap_update_adv_data(*loadPtr.getUnitAtIndex(index).getLenPtr(), loadPtr.getUnitAtIndex(index).getAdTypePtr());
hemddabral 58:027c65a54097 133 if(BLE_STATUS_SUCCESS!=err) {
hemddabral 58:027c65a54097 134 DEBUG("error occurred while adding adv data\n");
hemddabral 58:027c65a54097 135 return BLE_ERROR_PARAM_OUT_OF_RANGE; // no other suitable error code is available
hemddabral 58:027c65a54097 136 }
hemddabral 58:027c65a54097 137 #endif
hemddabral 58:027c65a54097 138 break;
mridup 60:b0b2d639c0f5 139 }
hemddabral 58:027c65a54097 140 case GapAdvertisingData::INCOMPLETE_LIST_32BIT_SERVICE_IDS: /**< Incomplete list of 32-bit Service IDs (not relevant for Bluetooth 4.0) */
mridup 60:b0b2d639c0f5 141 {
hemddabral 10:814262eb0746 142 break;
mridup 60:b0b2d639c0f5 143 }
hemddabral 58:027c65a54097 144 case GapAdvertisingData::COMPLETE_LIST_32BIT_SERVICE_IDS: /**< Complete list of 32-bit Service IDs (not relevant for Bluetooth 4.0) */
mridup 60:b0b2d639c0f5 145 {
hemddabral 10:814262eb0746 146 break;
mridup 60:b0b2d639c0f5 147 }
hemddabral 58:027c65a54097 148 case GapAdvertisingData::INCOMPLETE_LIST_128BIT_SERVICE_IDS: /**< Incomplete list of 128-bit Service IDs */
mridup 60:b0b2d639c0f5 149 {
hemddabral 10:814262eb0746 150 break;
mridup 60:b0b2d639c0f5 151 }
hemddabral 58:027c65a54097 152 case GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS: /**< Complete list of 128-bit Service IDs */
mridup 60:b0b2d639c0f5 153 {
hemddabral 10:814262eb0746 154 break;
mridup 60:b0b2d639c0f5 155 }
hemddabral 58:027c65a54097 156 case GapAdvertisingData::SHORTENED_LOCAL_NAME: /**< Shortened Local Name */
mridup 60:b0b2d639c0f5 157 {
hemddabral 10:814262eb0746 158 break;
mridup 60:b0b2d639c0f5 159 }
hemddabral 58:027c65a54097 160 case GapAdvertisingData::COMPLETE_LOCAL_NAME: /**< Complete Local Name */
mridup 60:b0b2d639c0f5 161 {
hemddabral 58:027c65a54097 162 DEBUG("Advertising type: COMPLETE_LOCAL_NAME\n\r");
hemddabral 58:027c65a54097 163 loadPtr.getUnitAtIndex(index).printDataAsString();
hemddabral 58:027c65a54097 164 local_name_length = *loadPtr.getUnitAtIndex(index).getLenPtr()-1;
hemddabral 58:027c65a54097 165 local_name = (const char*)loadPtr.getUnitAtIndex(index).getAdTypePtr();
hemddabral 58:027c65a54097 166 //COMPLETE_LOCAL_NAME is only advertising device name. Gatt Device Name is not the same.(Must be set right after GAP/GATT init?)
hemddabral 58:027c65a54097 167
hemddabral 58:027c65a54097 168 DEBUG("device_name length=%d\n\r", local_name_length);
hemddabral 58:027c65a54097 169 break;
mridup 60:b0b2d639c0f5 170 }
hemddabral 58:027c65a54097 171 case GapAdvertisingData::TX_POWER_LEVEL: /**< TX Power Level (in dBm) */
mridup 60:b0b2d639c0f5 172 {
hemddabral 58:027c65a54097 173 DEBUG("Advertising type: TX_POWER_LEVEL\n\r");
hemddabral 58:027c65a54097 174 int8_t dbm = *loadPtr.getUnitAtIndex(index).getDataPtr();
hemddabral 58:027c65a54097 175 int8_t enHighPower = 0;
hemddabral 58:027c65a54097 176 int8_t paLevel = 0;
hemddabral 58:027c65a54097 177 int8_t dbmActuallySet = getHighPowerAndPALevelValue(dbm, enHighPower, paLevel);
hemddabral 58:027c65a54097 178 DEBUG("dbm=%d, dbmActuallySet=%d\n\r", dbm, dbmActuallySet);
hemddabral 58:027c65a54097 179 DEBUG("enHighPower=%d, paLevel=%d\n\r", enHighPower, paLevel);
hemddabral 58:027c65a54097 180 aci_hal_set_tx_power_level(enHighPower, paLevel);
hemddabral 10:814262eb0746 181 break;
mridup 60:b0b2d639c0f5 182 }
hemddabral 58:027c65a54097 183 case GapAdvertisingData::DEVICE_ID: /**< Device ID */
mridup 60:b0b2d639c0f5 184 {
hemddabral 58:027c65a54097 185 break;
mridup 60:b0b2d639c0f5 186 }
hemddabral 58:027c65a54097 187 case GapAdvertisingData::SLAVE_CONNECTION_INTERVAL_RANGE: /**< Slave :Connection Interval Range */
mridup 60:b0b2d639c0f5 188 {
hemddabral 10:814262eb0746 189 break;
mridup 60:b0b2d639c0f5 190 }
hemddabral 58:027c65a54097 191 case GapAdvertisingData::SERVICE_DATA: /**< Service Data */
mridup 60:b0b2d639c0f5 192 {
hemddabral 10:814262eb0746 193 break;
mridup 60:b0b2d639c0f5 194 }
hemddabral 58:027c65a54097 195 case GapAdvertisingData::APPEARANCE:
mridup 60:b0b2d639c0f5 196 {
hemddabral 58:027c65a54097 197 /*
hemddabral 14:baa7a1464517 198 Tested with GapAdvertisingData::GENERIC_PHONE.
hemddabral 14:baa7a1464517 199 for other appearances BLE Scanner android app is not behaving properly
hemddabral 14:baa7a1464517 200 */
hemddabral 58:027c65a54097 201 DEBUG("Advertising type: APPEARANCE\n\r");
hemddabral 58:027c65a54097 202 const char *deviceAppearance = NULL;
hemddabral 58:027c65a54097 203 deviceAppearance = (const char*)loadPtr.getUnitAtIndex(index).getDataPtr(); // to be set later when startAdvertising() is called
hemddabral 58:027c65a54097 204
hemddabral 58:027c65a54097 205 uint8_t Appearance[2];
hemddabral 58:027c65a54097 206 uint16_t devP = (uint16_t)*deviceAppearance;
hemddabral 58:027c65a54097 207 STORE_LE_16(Appearance, (uint16_t)devP);
hemddabral 58:027c65a54097 208
hemddabral 58:027c65a54097 209 DEBUG("input: deviceAppearance= 0x%x 0x%x..., strlen(deviceAppearance)=%d\n\r", Appearance[1], Appearance[0], (uint8_t)*loadPtr.getUnitAtIndex(index).getLenPtr()-1); /**< \ref Appearance */
hemddabral 58:027c65a54097 210
hemddabral 58:027c65a54097 211 aci_gatt_update_char_value(g_gap_service_handle, g_appearance_char_handle, 0, 2, (tHalUint8 *)deviceAppearance);//not using array Appearance[2]
hemddabral 10:814262eb0746 212 break;
mridup 60:b0b2d639c0f5 213 }
hemddabral 58:027c65a54097 214 case GapAdvertisingData::ADVERTISING_INTERVAL: /**< Advertising Interval */
mridup 60:b0b2d639c0f5 215 {
hemddabral 58:027c65a54097 216 advtInterval = (uint16_t)(*loadPtr.getUnitAtIndex(index).getDataPtr());
hemddabral 58:027c65a54097 217 DEBUG("advtInterval=%d\n\r", advtInterval);
hemddabral 10:814262eb0746 218 break;
mridup 60:b0b2d639c0f5 219 }
hemddabral 58:027c65a54097 220 case GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA: /**< Manufacturer Specific Data */
mridup 60:b0b2d639c0f5 221 {
hemddabral 58:027c65a54097 222 break;
mridup 60:b0b2d639c0f5 223 }
hemddabral 58:027c65a54097 224
hemddabral 19:0f87aaf1362d 225 }
hemddabral 58:027c65a54097 226 }
mridup 44:b4a986b33c7d 227 //Set the SCAN_RSP Payload
mridup 44:b4a986b33c7d 228 scan_response_payload = scanResponse.getPayload();
mridup 44:b4a986b33c7d 229 scan_rsp_length = scanResponse.getPayloadLen();
mridup 3:9c4c13795643 230 }
hemddabral 58:027c65a54097 231 return BLE_ERROR_NONE;
mridup 2:a2b623661316 232 }
mridup 2:a2b623661316 233
mridup 2:a2b623661316 234 /**************************************************************************/
mridup 2:a2b623661316 235 /*!
mridup 2:a2b623661316 236 @brief Starts the BLE HW, initialising any services that were
mridup 2:a2b623661316 237 added before this function was called.
mridup 64:6d7b775c3f6d 238
mridup 64:6d7b775c3f6d 239 @param[in] params
mridup 64:6d7b775c3f6d 240 Basic advertising details, including the advertising
mridup 64:6d7b775c3f6d 241 delay, timeout and how the device should be advertised
mridup 64:6d7b775c3f6d 242
mridup 2:a2b623661316 243 @note All services must be added before calling this function!
mridup 2:a2b623661316 244
mridup 2:a2b623661316 245 @returns ble_error_t
mridup 2:a2b623661316 246
mridup 2:a2b623661316 247 @retval BLE_ERROR_NONE
mridup 2:a2b623661316 248 Everything executed properly
mridup 2:a2b623661316 249
mridup 2:a2b623661316 250 @section EXAMPLE
mridup 2:a2b623661316 251
mridup 2:a2b623661316 252 @code
mridup 2:a2b623661316 253
mridup 2:a2b623661316 254 @endcode
mridup 2:a2b623661316 255 */
mridup 2:a2b623661316 256 /**************************************************************************/
mridup 2:a2b623661316 257 ble_error_t BlueNRGGap::startAdvertising(const GapAdvertisingParams &params)
mridup 2:a2b623661316 258 {
mridup 2:a2b623661316 259 /* Make sure we support the advertising type */
mridup 2:a2b623661316 260 if (params.getAdvertisingType() == GapAdvertisingParams::ADV_CONNECTABLE_DIRECTED) {
mridup 2:a2b623661316 261 /* ToDo: This requires a propery security implementation, etc. */
mridup 2:a2b623661316 262 return BLE_ERROR_NOT_IMPLEMENTED;
mridup 2:a2b623661316 263 }
mridup 2:a2b623661316 264
mridup 2:a2b623661316 265 /* Check interval range */
mridup 2:a2b623661316 266 if (params.getAdvertisingType() == GapAdvertisingParams::ADV_NON_CONNECTABLE_UNDIRECTED) {
mridup 2:a2b623661316 267 /* Min delay is slightly longer for unconnectable devices */
mridup 65:f9958b8f2548 268 if ((params.getInterval() < GapAdvertisingParams::GAP_ADV_PARAMS_INTERVAL_MIN_NONCON) ||
mridup 65:f9958b8f2548 269 (params.getInterval() > GapAdvertisingParams::GAP_ADV_PARAMS_INTERVAL_MAX)) {
mridup 2:a2b623661316 270 return BLE_ERROR_PARAM_OUT_OF_RANGE;
mridup 2:a2b623661316 271 }
mridup 2:a2b623661316 272 } else {
mridup 65:f9958b8f2548 273 if ((params.getInterval() < GapAdvertisingParams::GAP_ADV_PARAMS_INTERVAL_MIN) ||
mridup 65:f9958b8f2548 274 (params.getInterval() > GapAdvertisingParams::GAP_ADV_PARAMS_INTERVAL_MAX)) {
mridup 2:a2b623661316 275 return BLE_ERROR_PARAM_OUT_OF_RANGE;
mridup 2:a2b623661316 276 }
mridup 2:a2b623661316 277 }
mridup 2:a2b623661316 278
mridup 2:a2b623661316 279 /* Check timeout is zero for Connectable Directed */
mridup 2:a2b623661316 280 if ((params.getAdvertisingType() == GapAdvertisingParams::ADV_CONNECTABLE_DIRECTED) && (params.getTimeout() != 0)) {
mridup 2:a2b623661316 281 /* Timeout must be 0 with this type, although we'll never get here */
mridup 2:a2b623661316 282 /* since this isn't implemented yet anyway */
mridup 2:a2b623661316 283 return BLE_ERROR_PARAM_OUT_OF_RANGE;
mridup 2:a2b623661316 284 }
mridup 2:a2b623661316 285
mridup 2:a2b623661316 286 /* Check timeout for other advertising types */
mridup 2:a2b623661316 287 if ((params.getAdvertisingType() != GapAdvertisingParams::ADV_CONNECTABLE_DIRECTED) &&
mridup 65:f9958b8f2548 288 (params.getTimeout() > GapAdvertisingParams::GAP_ADV_PARAMS_TIMEOUT_MAX)) {
mridup 2:a2b623661316 289 return BLE_ERROR_PARAM_OUT_OF_RANGE;
mridup 2:a2b623661316 290 }
mridup 2:a2b623661316 291
hemddabral 58:027c65a54097 292 tBleStatus ret;
hemddabral 58:027c65a54097 293 const LongUUIDBytes_t HRM_SERVICE_UUID_128 = {0x18, 0x0D};
hemddabral 58:027c65a54097 294 /* set scan response data */
hemddabral 58:027c65a54097 295 hci_le_set_scan_resp_data(scan_rsp_length, scan_response_payload); /*int hci_le_set_scan_resp_data(uint8_t length, const uint8_t data[]);*/
hemddabral 58:027c65a54097 296
hemddabral 58:027c65a54097 297 /*aci_gap_set_discoverable(Advertising_Event_Type, Adv_min_intvl, Adv_Max_Intvl, Addr_Type, Adv_Filter_Policy,
mridup 2:a2b623661316 298 Local_Name_Length, local_name, service_uuid_length, service_uuid_list, Slave_conn_intvl_min, Slave_conn_intvl_max);*/
hemddabral 58:027c65a54097 299 /*LINK_LAYER.H DESCRIBES THE ADVERTISING TYPES*/
hemddabral 18:6d5f4c638f6a 300
hemddabral 58:027c65a54097 301 char* name = NULL;
hemddabral 58:027c65a54097 302 uint8_t nameLen = 0;
hemddabral 58:027c65a54097 303 if(local_name!=NULL) {
hemddabral 58:027c65a54097 304 name = (char*)local_name;
hemddabral 58:027c65a54097 305 DEBUG("name=%s\n\r", name);
hemddabral 58:027c65a54097 306 nameLen = local_name_length;
hemddabral 58:027c65a54097 307 } else {
hemddabral 58:027c65a54097 308 char str[] = "ST_BLE_DEV";
hemddabral 58:027c65a54097 309 name = new char[strlen(str)+1];
hemddabral 58:027c65a54097 310 name[0] = AD_TYPE_COMPLETE_LOCAL_NAME;
hemddabral 58:027c65a54097 311 strcpy(name+1, str);
hemddabral 58:027c65a54097 312 nameLen = strlen(name);
hemddabral 58:027c65a54097 313 DEBUG("nameLen=%d\n\r", nameLen);
hemddabral 58:027c65a54097 314 DEBUG("name=%s\n\r", name);
hemddabral 58:027c65a54097 315 }
hemddabral 58:027c65a54097 316
hemddabral 58:027c65a54097 317
hemddabral 58:027c65a54097 318 advtInterval = params.getInterval(); // set advtInterval in case it is not already set by user application
hemddabral 58:027c65a54097 319 ret = aci_gap_set_discoverable(params.getAdvertisingType(), // Advertising_Event_Type
hemddabral 69:2c340304de64 320 BLUENRG_GAP_ADV_INTERVAL_MIN, // Adv_Interval_Min
hemddabral 69:2c340304de64 321 advtInterval, // Adv_Interval_Max
hemddabral 69:2c340304de64 322 PUBLIC_ADDR, // Address_Type
hemddabral 69:2c340304de64 323 NO_WHITE_LIST_USE, // Adv_Filter_Policy
hemddabral 69:2c340304de64 324 nameLen, //local_name_length, // Local_Name_Length
hemddabral 69:2c340304de64 325 (const char*)name, //local_name, // Local_Name
hemddabral 69:2c340304de64 326 servUuidlength, //Service_Uuid_Length
hemddabral 69:2c340304de64 327 servUuidData, //Service_Uuid_List
hemddabral 69:2c340304de64 328 0, // Slave_Conn_Interval_Min
hemddabral 69:2c340304de64 329 0); // Slave_Conn_Interval_Max
hemddabral 58:027c65a54097 330
hemddabral 58:027c65a54097 331 state.advertising = 1;
hemddabral 58:027c65a54097 332
mridup 2:a2b623661316 333 return BLE_ERROR_NONE;
mridup 2:a2b623661316 334 }
mridup 2:a2b623661316 335
mridup 2:a2b623661316 336 /**************************************************************************/
mridup 2:a2b623661316 337 /*!
mridup 2:a2b623661316 338 @brief Stops the BLE HW and disconnects from any devices
mridup 2:a2b623661316 339
mridup 2:a2b623661316 340 @returns ble_error_t
mridup 2:a2b623661316 341
mridup 2:a2b623661316 342 @retval BLE_ERROR_NONE
mridup 2:a2b623661316 343 Everything executed properly
mridup 2:a2b623661316 344
mridup 2:a2b623661316 345 @section EXAMPLE
mridup 2:a2b623661316 346
mridup 2:a2b623661316 347 @code
mridup 2:a2b623661316 348
mridup 2:a2b623661316 349 @endcode
mridup 2:a2b623661316 350 */
mridup 2:a2b623661316 351 /**************************************************************************/
mridup 2:a2b623661316 352 ble_error_t BlueNRGGap::stopAdvertising(void)
mridup 2:a2b623661316 353 {
mridup 34:fdbbe839170a 354 tBleStatus ret;
mridup 2:a2b623661316 355
mridup 36:f3d80a236beb 356 if(state.advertising == 1) {
hemddabral 58:027c65a54097 357 //Set non-discoverable to stop advertising
hemddabral 58:027c65a54097 358 ret = aci_gap_set_non_discoverable();
hemddabral 58:027c65a54097 359
hemddabral 58:027c65a54097 360 if (ret != BLE_STATUS_SUCCESS){
hemddabral 58:027c65a54097 361 DEBUG("Error in stopping advertisement!!\n\r") ;
hemddabral 58:027c65a54097 362 return BLE_ERROR_PARAM_OUT_OF_RANGE ; //Not correct Error Value
hemddabral 58:027c65a54097 363 //FIXME: Define Error values equivalent to BlueNRG Error Codes.
hemddabral 58:027c65a54097 364 }
hemddabral 58:027c65a54097 365 DEBUG("Advertisement stopped!!\n\r") ;
hemddabral 58:027c65a54097 366 //Set GapState_t::advertising state
hemddabral 58:027c65a54097 367 state.advertising = 0;
mridup 36:f3d80a236beb 368 }
mridup 34:fdbbe839170a 369
mridup 2:a2b623661316 370 return BLE_ERROR_NONE;
mridup 2:a2b623661316 371 }
mridup 2:a2b623661316 372
mridup 2:a2b623661316 373 /**************************************************************************/
mridup 2:a2b623661316 374 /*!
mridup 2:a2b623661316 375 @brief Disconnects if we are connected to a central device
mridup 2:a2b623661316 376
mridup 64:6d7b775c3f6d 377 @param[in] reason
mridup 64:6d7b775c3f6d 378 Disconnection Reason
mridup 64:6d7b775c3f6d 379
mridup 2:a2b623661316 380 @returns ble_error_t
mridup 2:a2b623661316 381
mridup 2:a2b623661316 382 @retval BLE_ERROR_NONE
mridup 2:a2b623661316 383 Everything executed properly
mridup 2:a2b623661316 384
mridup 2:a2b623661316 385 @section EXAMPLE
mridup 2:a2b623661316 386
mridup 2:a2b623661316 387 @code
mridup 2:a2b623661316 388
mridup 2:a2b623661316 389 @endcode
mridup 2:a2b623661316 390 */
mridup 2:a2b623661316 391 /**************************************************************************/
hemddabral 55:0e4db6804c8d 392 ble_error_t BlueNRGGap::disconnect(Gap::DisconnectionReason_t reason)
mridup 2:a2b623661316 393 {
mridup 34:fdbbe839170a 394 tBleStatus ret;
mridup 34:fdbbe839170a 395 //For Reason codes check BlueTooth HCI Spec
mridup 34:fdbbe839170a 396
mridup 36:f3d80a236beb 397 if(m_connectionHandle != BLE_CONN_HANDLE_INVALID) {
mridup 34:fdbbe839170a 398 ret = aci_gap_terminate(m_connectionHandle, 0x16);//0x16 Connection Terminated by Local Host.
mridup 34:fdbbe839170a 399
hemddabral 58:027c65a54097 400 if (ret != BLE_STATUS_SUCCESS){
hemddabral 58:027c65a54097 401 DEBUG("Error in GAP termination!!\n\r") ;
hemddabral 58:027c65a54097 402 return BLE_ERROR_PARAM_OUT_OF_RANGE ; //Not correct Error Value
hemddabral 58:027c65a54097 403 //FIXME: Define Error values equivalent to BlueNRG Error Codes.
hemddabral 58:027c65a54097 404 }
hemddabral 58:027c65a54097 405
hemddabral 58:027c65a54097 406 //DEBUG("Disconnected from localhost!!\n\r") ;
hemddabral 58:027c65a54097 407 m_connectionHandle = BLE_CONN_HANDLE_INVALID;
mridup 36:f3d80a236beb 408 }
mridup 2:a2b623661316 409
mridup 2:a2b623661316 410 return BLE_ERROR_NONE;
mridup 2:a2b623661316 411 }
mridup 2:a2b623661316 412
mridup 2:a2b623661316 413 /**************************************************************************/
mridup 2:a2b623661316 414 /*!
mridup 2:a2b623661316 415 @brief Sets the 16-bit connection handle
mridup 64:6d7b775c3f6d 416
mridup 64:6d7b775c3f6d 417 @param[in] con_handle
mridup 64:6d7b775c3f6d 418 Connection Handle which is set in the Gap Instance
mridup 64:6d7b775c3f6d 419
mridup 64:6d7b775c3f6d 420 @returns void
mridup 2:a2b623661316 421 */
mridup 2:a2b623661316 422 /**************************************************************************/
mridup 2:a2b623661316 423 void BlueNRGGap::setConnectionHandle(uint16_t con_handle)
mridup 2:a2b623661316 424 {
mridup 2:a2b623661316 425 m_connectionHandle = con_handle;
mridup 2:a2b623661316 426 }
mridup 2:a2b623661316 427
mridup 2:a2b623661316 428 /**************************************************************************/
mridup 2:a2b623661316 429 /*!
mridup 2:a2b623661316 430 @brief Gets the 16-bit connection handle
mridup 64:6d7b775c3f6d 431
mridup 64:6d7b775c3f6d 432 @param[in] void
mridup 64:6d7b775c3f6d 433
mridup 64:6d7b775c3f6d 434 @returns uint16_t
mridup 64:6d7b775c3f6d 435 Connection Handle of the Gap Instance
mridup 2:a2b623661316 436 */
mridup 2:a2b623661316 437 /**************************************************************************/
mridup 2:a2b623661316 438 uint16_t BlueNRGGap::getConnectionHandle(void)
mridup 2:a2b623661316 439 {
mridup 2:a2b623661316 440 return m_connectionHandle;
mridup 2:a2b623661316 441 }
mridup 2:a2b623661316 442
mridup 2:a2b623661316 443 /**************************************************************************/
mridup 2:a2b623661316 444 /*!
mridup 41:95b8d531628c 445 @brief Sets the BLE device address. SetAddress will reset the BLE
mridup 41:95b8d531628c 446 device and re-initialize BTLE. Will not start advertising.
mridup 2:a2b623661316 447
mridup 64:6d7b775c3f6d 448 @param[in] type
mridup 64:6d7b775c3f6d 449 Type of Address
mridup 64:6d7b775c3f6d 450
mridup 64:6d7b775c3f6d 451 @param[in] address[6]
mridup 64:6d7b775c3f6d 452 Value of the Address to be set
mridup 64:6d7b775c3f6d 453
mridup 2:a2b623661316 454 @returns ble_error_t
mridup 2:a2b623661316 455
mridup 2:a2b623661316 456 @section EXAMPLE
mridup 2:a2b623661316 457
mridup 2:a2b623661316 458 @code
mridup 2:a2b623661316 459
mridup 2:a2b623661316 460 @endcode
mridup 2:a2b623661316 461 */
mridup 2:a2b623661316 462 /**************************************************************************/
mridup 2:a2b623661316 463 ble_error_t BlueNRGGap::setAddress(addr_type_t type, const uint8_t address[6])
mridup 2:a2b623661316 464 {
mridup 4:fa5b5693c1b5 465 tBleStatus ret;
mridup 4:fa5b5693c1b5 466
mridup 2:a2b623661316 467 if (type > ADDR_TYPE_RANDOM_PRIVATE_NON_RESOLVABLE) {
mridup 2:a2b623661316 468 return BLE_ERROR_PARAM_OUT_OF_RANGE;
mridup 2:a2b623661316 469 }
hemddabral 58:027c65a54097 470
mridup 41:95b8d531628c 471 //copy address to bdAddr[6]
mridup 41:95b8d531628c 472 for(int i=0; i<BDADDR_SIZE; i++) {
mridup 41:95b8d531628c 473 bdaddr[i] = address[i];
mridup 41:95b8d531628c 474 //DEBUG("i[%d]:0x%x\n\r",i,bdaddr[i]);
hemddabral 58:027c65a54097 475 }
hemddabral 58:027c65a54097 476
mridup 41:95b8d531628c 477 if(!isSetAddress) isSetAddress = true;
mridup 41:95b8d531628c 478
mridup 41:95b8d531628c 479 //Re-Init the BTLE Device with SetAddress as true
mridup 45:1fff7d7d5ce7 480 //if(BlueNRGDevice::getIsInitialized())//Re-init only initialization is already done
mridup 61:929885305c17 481 btle_init(isSetAddress, D11, D12, D3);
mridup 4:fa5b5693c1b5 482
mridup 4:fa5b5693c1b5 483 //if (ret==BLE_STATUS_SUCCESS)
mridup 2:a2b623661316 484 return BLE_ERROR_NONE;
mridup 2:a2b623661316 485 }
hemddabral 32:d1f250acad29 486
mridup 42:1a0220f508ca 487 /**************************************************************************/
mridup 42:1a0220f508ca 488 /*!
mridup 42:1a0220f508ca 489 @brief Returns boolean if the address of the device has been set
mridup 42:1a0220f508ca 490 or not
mridup 42:1a0220f508ca 491
mridup 42:1a0220f508ca 492 @returns bool
mridup 42:1a0220f508ca 493
mridup 42:1a0220f508ca 494 @section EXAMPLE
mridup 42:1a0220f508ca 495
mridup 42:1a0220f508ca 496 @code
mridup 42:1a0220f508ca 497
mridup 42:1a0220f508ca 498 @endcode
mridup 42:1a0220f508ca 499 */
mridup 42:1a0220f508ca 500 /**************************************************************************/
mridup 41:95b8d531628c 501 bool BlueNRGGap::getIsSetAddress()
mridup 41:95b8d531628c 502 {
mridup 41:95b8d531628c 503 return isSetAddress;
mridup 41:95b8d531628c 504 }
mridup 41:95b8d531628c 505
mridup 42:1a0220f508ca 506 /**************************************************************************/
mridup 42:1a0220f508ca 507 /*!
mridup 42:1a0220f508ca 508 @brief Returns the address of the device if set
mridup 42:1a0220f508ca 509
mridup 64:6d7b775c3f6d 510 @returns Pointer to the address is Address is set else NULL
mridup 42:1a0220f508ca 511
mridup 42:1a0220f508ca 512 @section EXAMPLE
mridup 42:1a0220f508ca 513
mridup 42:1a0220f508ca 514 @code
mridup 42:1a0220f508ca 515
mridup 42:1a0220f508ca 516 @endcode
mridup 42:1a0220f508ca 517 */
mridup 42:1a0220f508ca 518 /**************************************************************************/
mridup 65:f9958b8f2548 519 ble_error_t BlueNRGGap::getAddress(addr_type_t *typeP, address_t address)
mridup 41:95b8d531628c 520 {
mridup 65:f9958b8f2548 521 *typeP = Gap::ADDR_TYPE_PUBLIC;
mridup 65:f9958b8f2548 522
mridup 42:1a0220f508ca 523 if(isSetAddress)
mridup 65:f9958b8f2548 524 {
mridup 65:f9958b8f2548 525 for(int i=0; i<BDADDR_SIZE; i++) {
mridup 65:f9958b8f2548 526 address[i] = bdaddr[i];
mridup 65:f9958b8f2548 527 //DEBUG("i[%d]:0x%x\n\r",i,bdaddr[i]);
mridup 65:f9958b8f2548 528 }
mridup 65:f9958b8f2548 529 }
mridup 65:f9958b8f2548 530
mridup 65:f9958b8f2548 531 return BLE_ERROR_NONE;
mridup 41:95b8d531628c 532 }
mridup 41:95b8d531628c 533
hemddabral 32:d1f250acad29 534 /**************************************************************************/
hemddabral 32:d1f250acad29 535 /*!
hemddabral 32:d1f250acad29 536 @brief obtains preferred connection params
hemddabral 32:d1f250acad29 537
hemddabral 32:d1f250acad29 538 @returns ble_error_t
hemddabral 32:d1f250acad29 539
hemddabral 32:d1f250acad29 540 @section EXAMPLE
hemddabral 32:d1f250acad29 541
hemddabral 32:d1f250acad29 542 @code
hemddabral 32:d1f250acad29 543
hemddabral 32:d1f250acad29 544 @endcode
hemddabral 32:d1f250acad29 545 */
hemddabral 32:d1f250acad29 546 /**************************************************************************/
hemddabral 32:d1f250acad29 547 ble_error_t BlueNRGGap::getPreferredConnectionParams(ConnectionParams_t *params)
hemddabral 32:d1f250acad29 548 {
hemddabral 32:d1f250acad29 549 return BLE_ERROR_NONE;
hemddabral 32:d1f250acad29 550 }
hemddabral 32:d1f250acad29 551
hemddabral 32:d1f250acad29 552
hemddabral 32:d1f250acad29 553 /**************************************************************************/
hemddabral 32:d1f250acad29 554 /*!
hemddabral 32:d1f250acad29 555 @brief sets preferred connection params
hemddabral 32:d1f250acad29 556
hemddabral 32:d1f250acad29 557 @returns ble_error_t
hemddabral 32:d1f250acad29 558
hemddabral 32:d1f250acad29 559 @section EXAMPLE
hemddabral 32:d1f250acad29 560
hemddabral 32:d1f250acad29 561 @code
hemddabral 32:d1f250acad29 562
hemddabral 32:d1f250acad29 563 @endcode
hemddabral 32:d1f250acad29 564 */
hemddabral 32:d1f250acad29 565 /**************************************************************************/
hemddabral 32:d1f250acad29 566 ble_error_t BlueNRGGap::setPreferredConnectionParams(const ConnectionParams_t *params)
hemddabral 32:d1f250acad29 567 {
hemddabral 32:d1f250acad29 568 return BLE_ERROR_NONE;
hemddabral 32:d1f250acad29 569 }
hemddabral 32:d1f250acad29 570
hemddabral 32:d1f250acad29 571 /**************************************************************************/
hemddabral 32:d1f250acad29 572 /*!
hemddabral 32:d1f250acad29 573 @brief updates preferred connection params
hemddabral 32:d1f250acad29 574
hemddabral 32:d1f250acad29 575 @returns ble_error_t
hemddabral 32:d1f250acad29 576
hemddabral 32:d1f250acad29 577 @section EXAMPLE
hemddabral 32:d1f250acad29 578
hemddabral 32:d1f250acad29 579 @code
hemddabral 32:d1f250acad29 580
hemddabral 32:d1f250acad29 581 @endcode
hemddabral 32:d1f250acad29 582 */
hemddabral 32:d1f250acad29 583 /**************************************************************************/
hemddabral 32:d1f250acad29 584 ble_error_t BlueNRGGap::updateConnectionParams(Handle_t handle, const ConnectionParams_t *params)
hemddabral 32:d1f250acad29 585 {
hemddabral 32:d1f250acad29 586 return BLE_ERROR_NONE;
hemddabral 32:d1f250acad29 587 }
hemddabral 32:d1f250acad29 588
hemddabral 55:0e4db6804c8d 589 /**************************************************************************/
hemddabral 55:0e4db6804c8d 590 /*!
mridup 64:6d7b775c3f6d 591 @brief Sets the Device Name Characteristic
hemddabral 55:0e4db6804c8d 592
hemddabral 55:0e4db6804c8d 593 @param[in] deviceName
hemddabral 55:0e4db6804c8d 594 pointer to device name to be set
hemddabral 55:0e4db6804c8d 595
hemddabral 55:0e4db6804c8d 596 @returns ble_error_t
hemddabral 55:0e4db6804c8d 597
hemddabral 55:0e4db6804c8d 598 @retval BLE_ERROR_NONE
hemddabral 55:0e4db6804c8d 599 Everything executed properly
hemddabral 55:0e4db6804c8d 600
hemddabral 55:0e4db6804c8d 601 @section EXAMPLE
hemddabral 55:0e4db6804c8d 602
hemddabral 55:0e4db6804c8d 603 @code
hemddabral 55:0e4db6804c8d 604
hemddabral 55:0e4db6804c8d 605 @endcode
hemddabral 55:0e4db6804c8d 606 */
hemddabral 55:0e4db6804c8d 607 /**************************************************************************/
hemddabral 55:0e4db6804c8d 608 ble_error_t BlueNRGGap::setDeviceName(const uint8_t *deviceName)
hemddabral 55:0e4db6804c8d 609 {
hemddabral 55:0e4db6804c8d 610 int ret;
hemddabral 55:0e4db6804c8d 611 uint8_t nameLen = 0;
hemddabral 55:0e4db6804c8d 612
hemddabral 55:0e4db6804c8d 613 DeviceName = (uint8_t *)deviceName;
hemddabral 55:0e4db6804c8d 614 //DEBUG("SetDeviceName=%s\n\r", DeviceName);
hemddabral 55:0e4db6804c8d 615
hemddabral 55:0e4db6804c8d 616 nameLen = strlen((const char*)DeviceName);
hemddabral 55:0e4db6804c8d 617 //DEBUG("DeviceName Size=%d\n\r", nameLen);
hemddabral 55:0e4db6804c8d 618
hemddabral 55:0e4db6804c8d 619 ret = aci_gatt_update_char_value(g_gap_service_handle,
hemddabral 58:027c65a54097 620 g_device_name_char_handle,
hemddabral 58:027c65a54097 621 0,
hemddabral 58:027c65a54097 622 nameLen,
hemddabral 58:027c65a54097 623 (tHalUint8 *)DeviceName);
hemddabral 58:027c65a54097 624
hemddabral 55:0e4db6804c8d 625 if(ret){
hemddabral 55:0e4db6804c8d 626 DEBUG("device set name failed\n\r");
hemddabral 55:0e4db6804c8d 627 return BLE_ERROR_PARAM_OUT_OF_RANGE;//TODO:Wrong error code
hemddabral 55:0e4db6804c8d 628 }
hemddabral 58:027c65a54097 629
hemddabral 55:0e4db6804c8d 630 return BLE_ERROR_NONE;
hemddabral 55:0e4db6804c8d 631 }
hemddabral 55:0e4db6804c8d 632
hemddabral 55:0e4db6804c8d 633 /**************************************************************************/
hemddabral 55:0e4db6804c8d 634 /*!
mridup 64:6d7b775c3f6d 635 @brief Gets the Device Name Characteristic
hemddabral 55:0e4db6804c8d 636
hemddabral 55:0e4db6804c8d 637 @param[in] deviceName
mridup 64:6d7b775c3f6d 638 pointer to device name
hemddabral 55:0e4db6804c8d 639
hemddabral 55:0e4db6804c8d 640 @param[in] lengthP
hemddabral 55:0e4db6804c8d 641 pointer to device name length
hemddabral 55:0e4db6804c8d 642
hemddabral 55:0e4db6804c8d 643 @returns ble_error_t
hemddabral 55:0e4db6804c8d 644
hemddabral 55:0e4db6804c8d 645 @retval BLE_ERROR_NONE
hemddabral 55:0e4db6804c8d 646 Everything executed properly
hemddabral 55:0e4db6804c8d 647
hemddabral 55:0e4db6804c8d 648 @section EXAMPLE
hemddabral 55:0e4db6804c8d 649
hemddabral 55:0e4db6804c8d 650 @code
hemddabral 55:0e4db6804c8d 651
hemddabral 55:0e4db6804c8d 652 @endcode
hemddabral 55:0e4db6804c8d 653 */
hemddabral 55:0e4db6804c8d 654 /**************************************************************************/
hemddabral 55:0e4db6804c8d 655 ble_error_t BlueNRGGap::getDeviceName(uint8_t *deviceName, unsigned *lengthP)
hemddabral 55:0e4db6804c8d 656 {
hemddabral 55:0e4db6804c8d 657 int ret;
hemddabral 55:0e4db6804c8d 658
hemddabral 55:0e4db6804c8d 659 if(DeviceName==NULL)
hemddabral 58:027c65a54097 660 return BLE_ERROR_PARAM_OUT_OF_RANGE;
hemddabral 55:0e4db6804c8d 661
hemddabral 55:0e4db6804c8d 662 strcpy((char*)deviceName, (const char*)DeviceName);
hemddabral 55:0e4db6804c8d 663 //DEBUG("GetDeviceName=%s\n\r", deviceName);
hemddabral 55:0e4db6804c8d 664
hemddabral 55:0e4db6804c8d 665 *lengthP = strlen((const char*)DeviceName);
hemddabral 55:0e4db6804c8d 666 //DEBUG("DeviceName Size=%d\n\r", *lengthP);
hemddabral 55:0e4db6804c8d 667
hemddabral 55:0e4db6804c8d 668 return BLE_ERROR_NONE;
hemddabral 55:0e4db6804c8d 669 }
hemddabral 55:0e4db6804c8d 670
hemddabral 55:0e4db6804c8d 671 /**************************************************************************/
hemddabral 55:0e4db6804c8d 672 /*!
mridup 64:6d7b775c3f6d 673 @brief Sets the Device Appearance Characteristic
hemddabral 55:0e4db6804c8d 674
hemddabral 55:0e4db6804c8d 675 @param[in] appearance
hemddabral 55:0e4db6804c8d 676 device appearance
hemddabral 55:0e4db6804c8d 677
hemddabral 55:0e4db6804c8d 678 @returns ble_error_t
hemddabral 55:0e4db6804c8d 679
hemddabral 55:0e4db6804c8d 680 @retval BLE_ERROR_NONE
hemddabral 55:0e4db6804c8d 681 Everything executed properly
hemddabral 55:0e4db6804c8d 682
hemddabral 55:0e4db6804c8d 683 @section EXAMPLE
hemddabral 55:0e4db6804c8d 684
hemddabral 55:0e4db6804c8d 685 @code
hemddabral 55:0e4db6804c8d 686
hemddabral 55:0e4db6804c8d 687 @endcode
hemddabral 55:0e4db6804c8d 688 */
hemddabral 55:0e4db6804c8d 689 /**************************************************************************/
hemddabral 55:0e4db6804c8d 690 ble_error_t BlueNRGGap::setAppearance(uint16_t appearance)
hemddabral 55:0e4db6804c8d 691 {
hemddabral 55:0e4db6804c8d 692 /*
hemddabral 55:0e4db6804c8d 693 Tested with GapAdvertisingData::GENERIC_PHONE.
hemddabral 55:0e4db6804c8d 694 for other appearances BLE Scanner android app is not behaving properly
hemddabral 55:0e4db6804c8d 695 */
hemddabral 55:0e4db6804c8d 696 //char deviceAppearance[2];
hemddabral 55:0e4db6804c8d 697 STORE_LE_16(deviceAppearance, appearance);
hemddabral 55:0e4db6804c8d 698 DEBUG("input: incoming = %d deviceAppearance= 0x%x 0x%x\n\r", appearance, deviceAppearance[1], deviceAppearance[0]);
hemddabral 55:0e4db6804c8d 699
hemddabral 55:0e4db6804c8d 700 aci_gatt_update_char_value(g_gap_service_handle, g_appearance_char_handle, 0, 2, (tHalUint8 *)deviceAppearance);
hemddabral 55:0e4db6804c8d 701
hemddabral 55:0e4db6804c8d 702 return BLE_ERROR_NONE;
hemddabral 55:0e4db6804c8d 703 }
hemddabral 55:0e4db6804c8d 704
hemddabral 55:0e4db6804c8d 705 /**************************************************************************/
hemddabral 55:0e4db6804c8d 706 /*!
mridup 64:6d7b775c3f6d 707 @brief Gets the Device Appearance Characteristic
hemddabral 55:0e4db6804c8d 708
hemddabral 55:0e4db6804c8d 709 @param[in] appearance
hemddabral 55:0e4db6804c8d 710 pointer to device appearance value
hemddabral 55:0e4db6804c8d 711
hemddabral 55:0e4db6804c8d 712 @returns ble_error_t
hemddabral 55:0e4db6804c8d 713
hemddabral 55:0e4db6804c8d 714 @retval BLE_ERROR_NONE
hemddabral 55:0e4db6804c8d 715 Everything executed properly
hemddabral 55:0e4db6804c8d 716
hemddabral 55:0e4db6804c8d 717 @section EXAMPLE
hemddabral 55:0e4db6804c8d 718
hemddabral 55:0e4db6804c8d 719 @code
hemddabral 55:0e4db6804c8d 720
hemddabral 55:0e4db6804c8d 721 @endcode
hemddabral 55:0e4db6804c8d 722 */
hemddabral 55:0e4db6804c8d 723 /**************************************************************************/
hemddabral 55:0e4db6804c8d 724 ble_error_t BlueNRGGap::getAppearance(uint16_t *appearanceP)
hemddabral 55:0e4db6804c8d 725 {
hemddabral 55:0e4db6804c8d 726 uint16_t devP;
hemddabral 55:0e4db6804c8d 727 if(!appearanceP) return BLE_ERROR_PARAM_OUT_OF_RANGE;
hemddabral 55:0e4db6804c8d 728 devP = ((uint16_t)(0x0000|deviceAppearance[0])) | (((uint16_t)(0x0000|deviceAppearance[1]))<<8);
hemddabral 55:0e4db6804c8d 729 strcpy((char*)appearanceP, (const char*)&devP);
hemddabral 55:0e4db6804c8d 730
hemddabral 55:0e4db6804c8d 731 return BLE_ERROR_NONE;
hemddabral 55:0e4db6804c8d 732 }
hemddabral 67:23f9772ef7bf 733
hemddabral 69:2c340304de64 734 /**************************************************************************/
hemddabral 69:2c340304de64 735 /*!
hemddabral 69:2c340304de64 736 @brief Gets the value of maximum advertising interval in ms
hemddabral 69:2c340304de64 737
hemddabral 69:2c340304de64 738 @returns uint16_t
hemddabral 69:2c340304de64 739
hemddabral 69:2c340304de64 740 @retval value of maximum advertising interval in ms
hemddabral 69:2c340304de64 741
hemddabral 69:2c340304de64 742 @section EXAMPLE
hemddabral 69:2c340304de64 743
hemddabral 69:2c340304de64 744 @code
hemddabral 69:2c340304de64 745
hemddabral 69:2c340304de64 746 @endcode
hemddabral 69:2c340304de64 747 */
hemddabral 69:2c340304de64 748 /**************************************************************************/
hemddabral 67:23f9772ef7bf 749 uint16_t BlueNRGGap::getMaxAdvertisingInterval(void) const {
hemddabral 69:2c340304de64 750 return advtInterval;
hemddabral 67:23f9772ef7bf 751 }
hemddabral 67:23f9772ef7bf 752
hemddabral 69:2c340304de64 753
hemddabral 69:2c340304de64 754 /**************************************************************************/
hemddabral 69:2c340304de64 755 /*!
hemddabral 69:2c340304de64 756 @brief Gets the value of minimum advertising interval in ms
hemddabral 69:2c340304de64 757
hemddabral 69:2c340304de64 758 @returns uint16_t
hemddabral 69:2c340304de64 759
hemddabral 69:2c340304de64 760 @retval value of minimum advertising interval in ms
hemddabral 69:2c340304de64 761
hemddabral 69:2c340304de64 762 @section EXAMPLE
hemddabral 69:2c340304de64 763
hemddabral 69:2c340304de64 764 @code
hemddabral 69:2c340304de64 765
hemddabral 69:2c340304de64 766 @endcode
hemddabral 69:2c340304de64 767 */
hemddabral 69:2c340304de64 768 /**************************************************************************/
hemddabral 69:2c340304de64 769 uint16_t BlueNRGGap::getMinAdvertisingInterval(void) const {
hemddabral 69:2c340304de64 770 return 0; // minimum Advertising interval is 0
hemddabral 67:23f9772ef7bf 771 }
hemddabral 67:23f9772ef7bf 772
hemddabral 69:2c340304de64 773 /**************************************************************************/
hemddabral 69:2c340304de64 774 /*!
hemddabral 69:2c340304de64 775 @brief Gets the value of minimum non connectable advertising interval in ms
hemddabral 67:23f9772ef7bf 776
hemddabral 69:2c340304de64 777 @returns uint16_t
hemddabral 69:2c340304de64 778
hemddabral 69:2c340304de64 779 @retval value of minimum non connectable advertising interval in ms
hemddabral 69:2c340304de64 780
hemddabral 69:2c340304de64 781 @section EXAMPLE
hemddabral 69:2c340304de64 782
hemddabral 69:2c340304de64 783 @code
hemddabral 69:2c340304de64 784
hemddabral 69:2c340304de64 785 @endcode
hemddabral 69:2c340304de64 786 */
hemddabral 69:2c340304de64 787 /**************************************************************************/
hemddabral 69:2c340304de64 788 uint16_t BlueNRGGap::getMinNonConnectableAdvertisingInterval(void) const {
hemddabral 69:2c340304de64 789 return BLE_GAP_ADV_NONCON_INTERVAL_MIN;
hemddabral 67:23f9772ef7bf 790 }