AndroidのBLEラジコンプロポアプリ「BLEPropo」と接続し、RCサーボとDCモータを制御するプログラムです。 mbed HRM1017で動作を確認しています。 BLEPropo → https://github.com/lipoyang/BLEPropo

Dependencies:   BLE_API mbed

Fork of BLE_RCBController2 by Junichi Katsu

BLEを使ったAndroid用ラジコンプロポアプリ「BLEPropo」に対応するmbed HRM1017用ファームウェアです。
BLEPropoは、GitHubにて公開中。
https://github.com/lipoyang/BLEPropo
/media/uploads/lipoyang/blepropo_ui.png
ラジコンは、mbed HRM1017とRCサーボやDCモータを組み合わせて作ります。
/media/uploads/lipoyang/ble_wiring.png

Committer:
lipoyang
Date:
Sat Mar 14 11:51:38 2015 +0000
Revision:
7:505a9a98b776
Parent:
4:ebda47d22091
- adjust servo center position

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jksoft 1:48f6e08a3ac2 1 /* mbed Microcontroller Library
jksoft 1:48f6e08a3ac2 2 * Copyright (c) 2006-2013 ARM Limited
jksoft 1:48f6e08a3ac2 3 *
jksoft 1:48f6e08a3ac2 4 * Licensed under the Apache License, Version 2.0 (the "License");
jksoft 1:48f6e08a3ac2 5 * you may not use this file except in compliance with the License.
jksoft 1:48f6e08a3ac2 6 * You may obtain a copy of the License at
jksoft 1:48f6e08a3ac2 7 *
jksoft 1:48f6e08a3ac2 8 * http://www.apache.org/licenses/LICENSE-2.0
jksoft 1:48f6e08a3ac2 9 *
jksoft 1:48f6e08a3ac2 10 * Unless required by applicable law or agreed to in writing, software
jksoft 1:48f6e08a3ac2 11 * distributed under the License is distributed on an "AS IS" BASIS,
jksoft 1:48f6e08a3ac2 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
jksoft 1:48f6e08a3ac2 13 * See the License for the specific language governing permissions and
jksoft 1:48f6e08a3ac2 14 * limitations under the License.
jksoft 1:48f6e08a3ac2 15 */
jksoft 1:48f6e08a3ac2 16
jksoft 1:48f6e08a3ac2 17 #include "nRF51Gap.h"
jksoft 1:48f6e08a3ac2 18 #include "mbed.h"
jksoft 1:48f6e08a3ac2 19
jksoft 1:48f6e08a3ac2 20 #include "common/common.h"
jksoft 1:48f6e08a3ac2 21 #include "ble_advdata.h"
jksoft 1:48f6e08a3ac2 22 #include "ble_hci.h"
jksoft 1:48f6e08a3ac2 23
jksoft 1:48f6e08a3ac2 24 /**************************************************************************/
jksoft 1:48f6e08a3ac2 25 /*!
jksoft 1:48f6e08a3ac2 26 @brief Sets the advertising parameters and payload for the device
jksoft 1:48f6e08a3ac2 27
jksoft 1:48f6e08a3ac2 28 @param[in] params
jksoft 1:48f6e08a3ac2 29 Basic advertising details, including the advertising
jksoft 1:48f6e08a3ac2 30 delay, timeout and how the device should be advertised
jksoft 1:48f6e08a3ac2 31 @params[in] advData
jksoft 1:48f6e08a3ac2 32 The primary advertising data payload
jksoft 1:48f6e08a3ac2 33 @params[in] scanResponse
jksoft 1:48f6e08a3ac2 34 The optional Scan Response payload if the advertising
jksoft 1:48f6e08a3ac2 35 type is set to \ref GapAdvertisingParams::ADV_SCANNABLE_UNDIRECTED
jksoft 1:48f6e08a3ac2 36 in \ref GapAdveritinngParams
jksoft 1:48f6e08a3ac2 37
jksoft 1:48f6e08a3ac2 38 @returns \ref ble_error_t
jksoft 1:48f6e08a3ac2 39
jksoft 1:48f6e08a3ac2 40 @retval BLE_ERROR_NONE
jksoft 1:48f6e08a3ac2 41 Everything executed properly
jksoft 1:48f6e08a3ac2 42
jksoft 1:48f6e08a3ac2 43 @retval BLE_ERROR_BUFFER_OVERFLOW
jksoft 1:48f6e08a3ac2 44 The proposed action would cause a buffer overflow. All
jksoft 1:48f6e08a3ac2 45 advertising payloads must be <= 31 bytes, for example.
jksoft 1:48f6e08a3ac2 46
jksoft 1:48f6e08a3ac2 47 @retval BLE_ERROR_NOT_IMPLEMENTED
jksoft 1:48f6e08a3ac2 48 A feature was requested that is not yet supported in the
jksoft 1:48f6e08a3ac2 49 nRF51 firmware or hardware.
jksoft 1:48f6e08a3ac2 50
jksoft 1:48f6e08a3ac2 51 @retval BLE_ERROR_PARAM_OUT_OF_RANGE
jksoft 1:48f6e08a3ac2 52 One of the proposed values is outside the valid range.
jksoft 1:48f6e08a3ac2 53
jksoft 1:48f6e08a3ac2 54 @section EXAMPLE
jksoft 1:48f6e08a3ac2 55
jksoft 1:48f6e08a3ac2 56 @code
jksoft 1:48f6e08a3ac2 57
jksoft 1:48f6e08a3ac2 58 @endcode
jksoft 1:48f6e08a3ac2 59 */
jksoft 1:48f6e08a3ac2 60 /**************************************************************************/
jksoft 1:48f6e08a3ac2 61 ble_error_t nRF51Gap::setAdvertisingData(const GapAdvertisingData &advData, const GapAdvertisingData &scanResponse)
jksoft 1:48f6e08a3ac2 62 {
jksoft 1:48f6e08a3ac2 63 /* Make sure we don't exceed the advertising payload length */
jksoft 1:48f6e08a3ac2 64 if (advData.getPayloadLen() > GAP_ADVERTISING_DATA_MAX_PAYLOAD) {
jksoft 1:48f6e08a3ac2 65 return BLE_ERROR_BUFFER_OVERFLOW;
jksoft 1:48f6e08a3ac2 66 }
jksoft 1:48f6e08a3ac2 67
jksoft 1:48f6e08a3ac2 68 /* Make sure we have a payload! */
jksoft 1:48f6e08a3ac2 69 if (advData.getPayloadLen() == 0) {
jksoft 1:48f6e08a3ac2 70 return BLE_ERROR_PARAM_OUT_OF_RANGE;
jksoft 1:48f6e08a3ac2 71 }
jksoft 1:48f6e08a3ac2 72
jksoft 1:48f6e08a3ac2 73 /* Check the scan response payload limits */
jksoft 1:48f6e08a3ac2 74 //if ((params.getAdvertisingType() == GapAdvertisingParams::ADV_SCANNABLE_UNDIRECTED))
jksoft 1:48f6e08a3ac2 75 //{
jksoft 1:48f6e08a3ac2 76 // /* Check if we're within the upper limit */
jksoft 1:48f6e08a3ac2 77 // if (advData.getPayloadLen() > GAP_ADVERTISING_DATA_MAX_PAYLOAD)
jksoft 1:48f6e08a3ac2 78 // {
jksoft 1:48f6e08a3ac2 79 // return BLE_ERROR_BUFFER_OVERFLOW;
jksoft 1:48f6e08a3ac2 80 // }
jksoft 1:48f6e08a3ac2 81 // /* Make sure we have a payload! */
jksoft 1:48f6e08a3ac2 82 // if (advData.getPayloadLen() == 0)
jksoft 1:48f6e08a3ac2 83 // {
jksoft 1:48f6e08a3ac2 84 // return BLE_ERROR_PARAM_OUT_OF_RANGE;
jksoft 1:48f6e08a3ac2 85 // }
jksoft 1:48f6e08a3ac2 86 //}
jksoft 1:48f6e08a3ac2 87
jksoft 1:48f6e08a3ac2 88 /* Send advertising data! */
jksoft 1:48f6e08a3ac2 89 ASSERT(ERROR_NONE ==
jksoft 1:48f6e08a3ac2 90 sd_ble_gap_adv_data_set(advData.getPayload(),
jksoft 1:48f6e08a3ac2 91 advData.getPayloadLen(),
jksoft 1:48f6e08a3ac2 92 scanResponse.getPayload(),
jksoft 1:48f6e08a3ac2 93 scanResponse.getPayloadLen()),
jksoft 1:48f6e08a3ac2 94 BLE_ERROR_PARAM_OUT_OF_RANGE);
jksoft 1:48f6e08a3ac2 95
jksoft 1:48f6e08a3ac2 96 /* Make sure the GAP Service appearance value is aligned with the
jksoft 1:48f6e08a3ac2 97 *appearance from GapAdvertisingData */
jksoft 1:48f6e08a3ac2 98 ASSERT(ERROR_NONE == sd_ble_gap_appearance_set(advData.getAppearance()),
jksoft 1:48f6e08a3ac2 99 BLE_ERROR_PARAM_OUT_OF_RANGE);
jksoft 1:48f6e08a3ac2 100
jksoft 1:48f6e08a3ac2 101 /* ToDo: Perform some checks on the payload, for example the Scan Response can't */
jksoft 1:48f6e08a3ac2 102 /* contains a flags AD type, etc. */
jksoft 1:48f6e08a3ac2 103
jksoft 1:48f6e08a3ac2 104 return BLE_ERROR_NONE;
jksoft 1:48f6e08a3ac2 105 }
jksoft 1:48f6e08a3ac2 106
jksoft 1:48f6e08a3ac2 107 /**************************************************************************/
jksoft 1:48f6e08a3ac2 108 /*!
jksoft 1:48f6e08a3ac2 109 @brief Starts the BLE HW, initialising any services that were
jksoft 1:48f6e08a3ac2 110 added before this function was called.
jksoft 1:48f6e08a3ac2 111
jksoft 1:48f6e08a3ac2 112 @note All services must be added before calling this function!
jksoft 1:48f6e08a3ac2 113
jksoft 1:48f6e08a3ac2 114 @returns ble_error_t
jksoft 1:48f6e08a3ac2 115
jksoft 1:48f6e08a3ac2 116 @retval BLE_ERROR_NONE
jksoft 1:48f6e08a3ac2 117 Everything executed properly
jksoft 1:48f6e08a3ac2 118
jksoft 1:48f6e08a3ac2 119 @section EXAMPLE
jksoft 1:48f6e08a3ac2 120
jksoft 1:48f6e08a3ac2 121 @code
jksoft 1:48f6e08a3ac2 122
jksoft 1:48f6e08a3ac2 123 @endcode
jksoft 1:48f6e08a3ac2 124 */
jksoft 1:48f6e08a3ac2 125 /**************************************************************************/
jksoft 1:48f6e08a3ac2 126 ble_error_t nRF51Gap::startAdvertising(const GapAdvertisingParams &params)
jksoft 1:48f6e08a3ac2 127 {
jksoft 1:48f6e08a3ac2 128 /* Make sure we support the advertising type */
jksoft 1:48f6e08a3ac2 129 if (params.getAdvertisingType() == GapAdvertisingParams::ADV_CONNECTABLE_DIRECTED) {
jksoft 1:48f6e08a3ac2 130 /* ToDo: This requires a propery security implementation, etc. */
jksoft 1:48f6e08a3ac2 131 return BLE_ERROR_NOT_IMPLEMENTED;
jksoft 1:48f6e08a3ac2 132 }
jksoft 1:48f6e08a3ac2 133
jksoft 1:48f6e08a3ac2 134 /* Check interval range */
jksoft 1:48f6e08a3ac2 135 if (params.getAdvertisingType() == GapAdvertisingParams::ADV_NON_CONNECTABLE_UNDIRECTED) {
jksoft 1:48f6e08a3ac2 136 /* Min delay is slightly longer for unconnectable devices */
jksoft 1:48f6e08a3ac2 137 if ((params.getInterval() < GAP_ADV_PARAMS_INTERVAL_MIN_NONCON) ||
jksoft 1:48f6e08a3ac2 138 (params.getInterval() > GAP_ADV_PARAMS_INTERVAL_MAX)) {
jksoft 1:48f6e08a3ac2 139 return BLE_ERROR_PARAM_OUT_OF_RANGE;
jksoft 1:48f6e08a3ac2 140 }
jksoft 1:48f6e08a3ac2 141 } else {
jksoft 1:48f6e08a3ac2 142 if ((params.getInterval() < GAP_ADV_PARAMS_INTERVAL_MIN) ||
jksoft 1:48f6e08a3ac2 143 (params.getInterval() > GAP_ADV_PARAMS_INTERVAL_MAX)) {
jksoft 1:48f6e08a3ac2 144 return BLE_ERROR_PARAM_OUT_OF_RANGE;
jksoft 1:48f6e08a3ac2 145 }
jksoft 1:48f6e08a3ac2 146 }
jksoft 1:48f6e08a3ac2 147
jksoft 1:48f6e08a3ac2 148 /* Check timeout is zero for Connectable Directed */
jksoft 1:48f6e08a3ac2 149 if ((params.getAdvertisingType() == GapAdvertisingParams::ADV_CONNECTABLE_DIRECTED) && (params.getTimeout() != 0)) {
jksoft 1:48f6e08a3ac2 150 /* Timeout must be 0 with this type, although we'll never get here */
jksoft 1:48f6e08a3ac2 151 /* since this isn't implemented yet anyway */
jksoft 1:48f6e08a3ac2 152 return BLE_ERROR_PARAM_OUT_OF_RANGE;
jksoft 1:48f6e08a3ac2 153 }
jksoft 1:48f6e08a3ac2 154
jksoft 1:48f6e08a3ac2 155 /* Check timeout for other advertising types */
jksoft 1:48f6e08a3ac2 156 if ((params.getAdvertisingType() != GapAdvertisingParams::ADV_CONNECTABLE_DIRECTED) &&
jksoft 1:48f6e08a3ac2 157 (params.getTimeout() > GAP_ADV_PARAMS_TIMEOUT_MAX)) {
jksoft 1:48f6e08a3ac2 158 return BLE_ERROR_PARAM_OUT_OF_RANGE;
jksoft 1:48f6e08a3ac2 159 }
jksoft 1:48f6e08a3ac2 160
jksoft 1:48f6e08a3ac2 161 /* Start Advertising */
jksoft 1:48f6e08a3ac2 162 ble_gap_adv_params_t adv_para = {0};
jksoft 1:48f6e08a3ac2 163
jksoft 1:48f6e08a3ac2 164 adv_para.type = params.getAdvertisingType();
jksoft 1:48f6e08a3ac2 165 adv_para.p_peer_addr = NULL; // Undirected advertisement
jksoft 1:48f6e08a3ac2 166 adv_para.fp = BLE_GAP_ADV_FP_ANY;
jksoft 1:48f6e08a3ac2 167 adv_para.p_whitelist = NULL;
jksoft 1:48f6e08a3ac2 168 adv_para.interval = params.getInterval(); // advertising interval (in units of 0.625 ms)
jksoft 1:48f6e08a3ac2 169 adv_para.timeout = params.getTimeout();
jksoft 1:48f6e08a3ac2 170
jksoft 1:48f6e08a3ac2 171 ASSERT(ERROR_NONE == sd_ble_gap_adv_start(&adv_para),
jksoft 1:48f6e08a3ac2 172 BLE_ERROR_PARAM_OUT_OF_RANGE);
jksoft 1:48f6e08a3ac2 173
jksoft 1:48f6e08a3ac2 174 state.advertising = 1;
jksoft 1:48f6e08a3ac2 175
jksoft 1:48f6e08a3ac2 176 return BLE_ERROR_NONE;
jksoft 1:48f6e08a3ac2 177 }
jksoft 1:48f6e08a3ac2 178
jksoft 1:48f6e08a3ac2 179 /**************************************************************************/
jksoft 1:48f6e08a3ac2 180 /*!
jksoft 1:48f6e08a3ac2 181 @brief Stops the BLE HW and disconnects from any devices
jksoft 1:48f6e08a3ac2 182
jksoft 1:48f6e08a3ac2 183 @returns ble_error_t
jksoft 1:48f6e08a3ac2 184
jksoft 1:48f6e08a3ac2 185 @retval BLE_ERROR_NONE
jksoft 1:48f6e08a3ac2 186 Everything executed properly
jksoft 1:48f6e08a3ac2 187
jksoft 1:48f6e08a3ac2 188 @section EXAMPLE
jksoft 1:48f6e08a3ac2 189
jksoft 1:48f6e08a3ac2 190 @code
jksoft 1:48f6e08a3ac2 191
jksoft 1:48f6e08a3ac2 192 @endcode
jksoft 1:48f6e08a3ac2 193 */
jksoft 1:48f6e08a3ac2 194 /**************************************************************************/
jksoft 1:48f6e08a3ac2 195 ble_error_t nRF51Gap::stopAdvertising(void)
jksoft 1:48f6e08a3ac2 196 {
jksoft 1:48f6e08a3ac2 197 /* Stop Advertising */
jksoft 1:48f6e08a3ac2 198 ASSERT(ERROR_NONE == sd_ble_gap_adv_stop(), BLE_ERROR_PARAM_OUT_OF_RANGE);
jksoft 1:48f6e08a3ac2 199
jksoft 1:48f6e08a3ac2 200 state.advertising = 0;
jksoft 1:48f6e08a3ac2 201
jksoft 1:48f6e08a3ac2 202 return BLE_ERROR_NONE;
jksoft 1:48f6e08a3ac2 203 }
jksoft 1:48f6e08a3ac2 204
jksoft 1:48f6e08a3ac2 205 /**************************************************************************/
jksoft 1:48f6e08a3ac2 206 /*!
jksoft 1:48f6e08a3ac2 207 @brief Disconnects if we are connected to a central device
jksoft 1:48f6e08a3ac2 208
jksoft 1:48f6e08a3ac2 209 @returns ble_error_t
jksoft 1:48f6e08a3ac2 210
jksoft 1:48f6e08a3ac2 211 @retval BLE_ERROR_NONE
jksoft 1:48f6e08a3ac2 212 Everything executed properly
jksoft 1:48f6e08a3ac2 213
jksoft 1:48f6e08a3ac2 214 @section EXAMPLE
jksoft 1:48f6e08a3ac2 215
jksoft 1:48f6e08a3ac2 216 @code
jksoft 1:48f6e08a3ac2 217
jksoft 1:48f6e08a3ac2 218 @endcode
jksoft 1:48f6e08a3ac2 219 */
jksoft 1:48f6e08a3ac2 220 /**************************************************************************/
jksoft 1:48f6e08a3ac2 221 ble_error_t nRF51Gap::disconnect(void)
jksoft 1:48f6e08a3ac2 222 {
jksoft 1:48f6e08a3ac2 223 state.advertising = 0;
jksoft 1:48f6e08a3ac2 224 state.connected = 0;
jksoft 1:48f6e08a3ac2 225
jksoft 1:48f6e08a3ac2 226 /* Disconnect if we are connected to a central device */
jksoft 1:48f6e08a3ac2 227 ASSERT_INT(ERROR_NONE,
jksoft 1:48f6e08a3ac2 228 sd_ble_gap_disconnect(m_connectionHandle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION), BLE_ERROR_PARAM_OUT_OF_RANGE);
jksoft 1:48f6e08a3ac2 229
jksoft 1:48f6e08a3ac2 230 return BLE_ERROR_NONE;
jksoft 1:48f6e08a3ac2 231 }
jksoft 1:48f6e08a3ac2 232
jksoft 1:48f6e08a3ac2 233 ble_error_t nRF51Gap::getPreferredConnectionParams(ConnectionParams_t *params)
jksoft 1:48f6e08a3ac2 234 {
jksoft 1:48f6e08a3ac2 235 ASSERT_INT(NRF_SUCCESS,
jksoft 1:48f6e08a3ac2 236 sd_ble_gap_ppcp_get(reinterpret_cast<ble_gap_conn_params_t *>(params)),
jksoft 1:48f6e08a3ac2 237 BLE_ERROR_PARAM_OUT_OF_RANGE);
jksoft 1:48f6e08a3ac2 238
jksoft 1:48f6e08a3ac2 239 return BLE_ERROR_NONE;
jksoft 1:48f6e08a3ac2 240 }
jksoft 1:48f6e08a3ac2 241
jksoft 1:48f6e08a3ac2 242 ble_error_t nRF51Gap::setPreferredConnectionParams(const ConnectionParams_t *params)
jksoft 1:48f6e08a3ac2 243 {
jksoft 1:48f6e08a3ac2 244 ASSERT_INT(NRF_SUCCESS,
jksoft 1:48f6e08a3ac2 245 sd_ble_gap_ppcp_set(reinterpret_cast<const ble_gap_conn_params_t *>(params)),
jksoft 1:48f6e08a3ac2 246 BLE_ERROR_PARAM_OUT_OF_RANGE);
jksoft 1:48f6e08a3ac2 247
jksoft 1:48f6e08a3ac2 248 return BLE_ERROR_NONE;
jksoft 1:48f6e08a3ac2 249 }
jksoft 1:48f6e08a3ac2 250
jksoft 1:48f6e08a3ac2 251 ble_error_t nRF51Gap::updateConnectionParams(Handle_t handle, const ConnectionParams_t *newParams)
jksoft 1:48f6e08a3ac2 252 {
jksoft 1:48f6e08a3ac2 253 uint32_t rc;
jksoft 1:48f6e08a3ac2 254
jksoft 1:48f6e08a3ac2 255 rc = sd_ble_gap_conn_param_update(handle,
jksoft 1:48f6e08a3ac2 256 reinterpret_cast<ble_gap_conn_params_t *>(const_cast<ConnectionParams_t*>(newParams)));
jksoft 1:48f6e08a3ac2 257 if (rc == NRF_SUCCESS) {
jksoft 1:48f6e08a3ac2 258 return BLE_ERROR_NONE;
jksoft 1:48f6e08a3ac2 259 } else {
jksoft 1:48f6e08a3ac2 260 return BLE_ERROR_PARAM_OUT_OF_RANGE;
jksoft 1:48f6e08a3ac2 261 }
jksoft 1:48f6e08a3ac2 262 }
jksoft 1:48f6e08a3ac2 263
jksoft 1:48f6e08a3ac2 264 /**************************************************************************/
jksoft 1:48f6e08a3ac2 265 /*!
jksoft 1:48f6e08a3ac2 266 @brief Sets the 16-bit connection handle
jksoft 1:48f6e08a3ac2 267 */
jksoft 1:48f6e08a3ac2 268 /**************************************************************************/
jksoft 1:48f6e08a3ac2 269 void nRF51Gap::setConnectionHandle(uint16_t con_handle)
jksoft 1:48f6e08a3ac2 270 {
jksoft 1:48f6e08a3ac2 271 m_connectionHandle = con_handle;
jksoft 1:48f6e08a3ac2 272 }
jksoft 1:48f6e08a3ac2 273
jksoft 1:48f6e08a3ac2 274 /**************************************************************************/
jksoft 1:48f6e08a3ac2 275 /*!
jksoft 1:48f6e08a3ac2 276 @brief Gets the 16-bit connection handle
jksoft 1:48f6e08a3ac2 277 */
jksoft 1:48f6e08a3ac2 278 /**************************************************************************/
jksoft 1:48f6e08a3ac2 279 uint16_t nRF51Gap::getConnectionHandle(void)
jksoft 1:48f6e08a3ac2 280 {
jksoft 1:48f6e08a3ac2 281 return m_connectionHandle;
jksoft 1:48f6e08a3ac2 282 }
jksoft 1:48f6e08a3ac2 283
jksoft 1:48f6e08a3ac2 284 /**************************************************************************/
jksoft 1:48f6e08a3ac2 285 /*!
jksoft 1:48f6e08a3ac2 286 @brief Sets the BLE device address
jksoft 1:48f6e08a3ac2 287
jksoft 1:48f6e08a3ac2 288 @returns ble_error_t
jksoft 1:48f6e08a3ac2 289
jksoft 1:48f6e08a3ac2 290 @section EXAMPLE
jksoft 1:48f6e08a3ac2 291
jksoft 1:48f6e08a3ac2 292 @code
jksoft 1:48f6e08a3ac2 293
jksoft 1:48f6e08a3ac2 294 uint8_t device_address[6] = { 0xca, 0xfe, 0xf0, 0xf0, 0xf0, 0xf0 };
jksoft 1:48f6e08a3ac2 295 nrf.getGap().setAddress(Gap::ADDR_TYPE_RANDOM_STATIC, device_address);
jksoft 1:48f6e08a3ac2 296
jksoft 1:48f6e08a3ac2 297 @endcode
jksoft 1:48f6e08a3ac2 298 */
jksoft 1:48f6e08a3ac2 299 /**************************************************************************/
jksoft 1:48f6e08a3ac2 300 ble_error_t nRF51Gap::setAddress(addr_type_t type, const uint8_t address[6])
jksoft 1:48f6e08a3ac2 301 {
jksoft 1:48f6e08a3ac2 302 if (type > ADDR_TYPE_RANDOM_PRIVATE_NON_RESOLVABLE) {
jksoft 1:48f6e08a3ac2 303 return BLE_ERROR_PARAM_OUT_OF_RANGE;
jksoft 1:48f6e08a3ac2 304 }
jksoft 1:48f6e08a3ac2 305
jksoft 1:48f6e08a3ac2 306 ble_gap_addr_t dev_addr;
jksoft 1:48f6e08a3ac2 307 dev_addr.addr_type = type;
jksoft 1:48f6e08a3ac2 308 memcpy(dev_addr.addr, address, 6);
jksoft 1:48f6e08a3ac2 309
jksoft 1:48f6e08a3ac2 310 ASSERT_INT(ERROR_NONE,
jksoft 1:48f6e08a3ac2 311 sd_ble_gap_address_set(BLE_GAP_ADDR_CYCLE_MODE_NONE, &dev_addr),
jksoft 1:48f6e08a3ac2 312 BLE_ERROR_PARAM_OUT_OF_RANGE);
jksoft 1:48f6e08a3ac2 313
jksoft 1:48f6e08a3ac2 314
jksoft 1:48f6e08a3ac2 315 return BLE_ERROR_NONE;
jksoft 1:48f6e08a3ac2 316 }