Devchannel Team / X_NUCLEO_IDB0XA1

Dependents:   Hello_BLE F446RE-BLE

Fork of X_NUCLEO_IDB0XA1 by ST

Committer:
mridup
Date:
Wed Nov 12 09:41:31 2014 +0000
Revision:
61:929885305c17
Parent:
60:b0b2d639c0f5
Child:
64:6d7b775c3f6d
Configuration of pinNames according to platforms. Platform.h defines all tested platform pins used for configuration and testing. Device Init configuration parameters.

Who changed what in which revision?

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