Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: Hello_BLE F446RE-BLE
Fork of X_NUCLEO_IDB0XA1 by
Revision 41:95b8d531628c, committed 2014-08-27
- Comitter:
- mridup
- Date:
- Wed Aug 27 11:52:07 2014 +0000
- Parent:
- 40:bc6ea0d04238
- Child:
- 42:1a0220f508ca
- Commit message:
- SetAddress resets and re-inits the device.
Changed in this revision
--- a/BlueNRGDevice.cpp Wed Aug 27 06:45:31 2014 +0000
+++ b/BlueNRGDevice.cpp Wed Aug 27 11:52:07 2014 +0000
@@ -16,6 +16,8 @@
#include "mbed.h"
#include "BlueNRGDevice.h"
+#include "BlueNRGGap.h"
+#include "BlueNRGGattServer.h"
#include "btle.h"
#include "Utils.h"
@@ -73,7 +75,7 @@
ble_error_t BlueNRGDevice::init(void)
{
/* ToDo: Clear memory contents, reset the SD, etc. */
- btle_init();
+ btle_init(BlueNRGGap::getInstance().getIsSetAddress());
return BLE_ERROR_NONE;
}
@@ -100,7 +102,7 @@
wait(0.5);
/* Reset BlueNRG SPI interface */
- //BlueNRG_RST();
+ BlueNRG_RST();
/* Wait for the radio to come back up */
wait(1);
--- a/BlueNRGGap.cpp Wed Aug 27 06:45:31 2014 +0000
+++ b/BlueNRGGap.cpp Wed Aug 27 11:52:07 2014 +0000
@@ -271,7 +271,7 @@
ret = aci_gap_set_discoverable(params.getAdvertisingType(), // Advertising_Event_Type
0, // Adv_Interval_Min
advtInterval, // Adv_Interval_Max
- RANDOM_ADDR, // Address_Type <hdd> It seems there is some problem with RANDOM_ADDRESS. <problem_desc> When RANDOM_ADDRESS is selected device name is not being handled properly, i.e. wrong device name is seen by android app </problem_desc>
+ PUBLIC_ADDR, // Address_Type <hdd> It seems there is some problem with RANDOM_ADDRESS. <problem_desc> When RANDOM_ADDRESS is selected device name is not being handled properly, i.e. wrong device name is seen by android app </problem_desc>
NO_WHITE_LIST_USE, // Adv_Filter_Policy
nameLen, //local_name_length, // Local_Name_Length
(const char*)name, //local_name, // Local_Name
@@ -381,7 +381,8 @@
/**************************************************************************/
/*!
- @brief Sets the BLE device address
+ @brief Sets the BLE device address. SetAddress will reset the BLE
+ device and re-initialize BTLE. Will not start advertising.
@returns ble_error_t
@@ -400,7 +401,16 @@
return BLE_ERROR_PARAM_OUT_OF_RANGE;
}
- ret = aci_hal_write_config_data(CONFIG_DATA_PUBADDR_OFFSET, CONFIG_DATA_PUBADDR_LEN, (const tHalUint8*)address);
+ //copy address to bdAddr[6]
+ for(int i=0; i<BDADDR_SIZE; i++) {
+ bdaddr[i] = address[i];
+ //DEBUG("i[%d]:0x%x\n\r",i,bdaddr[i]);
+ }
+
+ if(!isSetAddress) isSetAddress = true;
+
+ //Re-Init the BTLE Device with SetAddress as true
+ btle_init(isSetAddress);
//if (ret==BLE_STATUS_SUCCESS)
return BLE_ERROR_NONE;
@@ -408,6 +418,16 @@
//return BLE_ERROR_PARAM_OUT_OF_RANGE;
}
+bool BlueNRGGap::getIsSetAddress()
+{
+ return isSetAddress;
+}
+
+tHalUint8* BlueNRGGap::getAddress()
+{
+ return bdaddr;
+}
+
/**************************************************************************/
/*!
@brief obtains preferred connection params
--- a/BlueNRGGap.h Wed Aug 27 06:45:31 2014 +0000
+++ b/BlueNRGGap.h Wed Aug 27 11:52:07 2014 +0000
@@ -25,6 +25,7 @@
#include "public/Gap.h"
#define BLE_CONN_HANDLE_INVALID 0x0
+#define BDADDR_SIZE 6
/**************************************************************************/
/*!
@@ -54,9 +55,14 @@
void setConnectionHandle(uint16_t con_handle);
uint16_t getConnectionHandle(void);
+
+ tHalUint8* getAddress();
+ bool getIsSetAddress();
private:
uint16_t m_connectionHandle;
+ tHalUint8 bdaddr[BDADDR_SIZE];
+ bool isSetAddress;
tBleStatus ret;
//const char local_name[];// = {AD_TYPE_COMPLETE_LOCAL_NAME,'B','l','u','e','N','R','G'};
@@ -64,6 +70,7 @@
//uint8_t *device_name;
BlueNRGGap() {
m_connectionHandle = BLE_CONN_HANDLE_INVALID;
+ isSetAddress = false;
//local_name[] = {AD_TYPE_COMPLETE_LOCAL_NAME,'B','l','u','e','N','R','G'};
}
--- a/btle/inc/btle.h Wed Aug 27 06:45:31 2014 +0000 +++ b/btle/inc/btle.h Wed Aug 27 11:52:07 2014 +0000 @@ -32,7 +32,7 @@ #include <stdio.h> #include <string.h> -void btle_init(void); +void btle_init(bool isSetAddress); void User_Process(void); void setConnectable(void);
--- a/btle/src/btle.cpp Wed Aug 27 06:45:31 2014 +0000
+++ b/btle/src/btle.cpp Wed Aug 27 11:52:07 2014 +0000
@@ -54,8 +54,8 @@
static void btle_handler(/*ble_evt_t * p_ble_evt*/);
void HCI_Input(tHciDataPacket * hciReadPacket);
-#define BDADDR_SIZE 6
-tHalUint8 bdaddr[BDADDR_SIZE]= {0xaa, 0x00, 0x00, 0xE1, 0x80, 0x02};
+//#define BDADDR_SIZE 6
+//tHalUint8 bdaddr[BDADDR_SIZE]= {0xaa, 0x00, 0x00, 0xE1, 0x80, 0x02};
uint16_t g_gap_service_handle = 0;
uint16_t g_appearance_char_handle = 0;
@@ -71,11 +71,11 @@
@returns
*/
/**************************************************************************/
-void btle_init(void)
+void btle_init(bool isSetAddress)
{
- const char *name = "BlueNRG_1";
- tHalUint8 SERVER_BDADDR[] = {0x12, 0x34, 0x00, 0xE1, 0x80, 0x02};//MPD: This is the public address of the Server/Client
- tHalUint8 bdaddr[BDADDR_SIZE];
+ DEBUG("btle_init>>");
+ const char *name = "STBlueNRG";
+ tHalUint8 *bleAddr;
int ret;
uint16_t service_handle, dev_name_char_handle, appearance_char_handle;
@@ -101,12 +101,19 @@
BlueNRG_RST();
/* The Nucleo board must be configured as SERVER */
- /*Osal_MemCpy(bdaddr, SERVER_BDADDR, sizeof(SERVER_BDADDR));
+ //check if issetAddress is set than set address.
+ if(isSetAddress)
+ {
+ bleAddr = BlueNRGGap::getInstance().getAddress();
+
+ tHalUint8 bdaddr[BDADDR_SIZE];
+ Osal_MemCpy(bdaddr, bleAddr, BDADDR_SIZE);
- ret = aci_hal_write_config_data(CONFIG_DATA_PUBADDR_OFFSET,
- CONFIG_DATA_PUBADDR_LEN,
- bdaddr);*/
-
+ ret = aci_hal_write_config_data(CONFIG_DATA_PUBADDR_OFFSET,
+ CONFIG_DATA_PUBADDR_LEN,
+ bdaddr);
+ }
+
ret = aci_gatt_init();
//GAP is always in PERIPHERAL _ROLE as mbed does not support Master role at the moment
ret = aci_gap_init(GAP_PERIPHERAL_ROLE, &service_handle, &dev_name_char_handle, &appearance_char_handle);
