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