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:
Wolfgang Betz
Date:
Thu Jul 23 14:22:55 2015 +0200
Revision:
92:709d44dc869a
Parent:
90:26c0c9807ab4
Child:
93:728699ac5613
Child:
99:c6e075b517c2
Get rid of compilation warnings

Who changed what in which revision?

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