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.
Dependencies: BLE_API mbed nRF51822
Diff: main.cpp
- Revision:
- 1:df5573997c91
- Parent:
- 0:51c847e94a29
- Child:
- 2:1f1ab7f55a45
--- a/main.cpp Mon Aug 17 09:17:25 2015 +0000
+++ b/main.cpp Tue Aug 18 10:40:55 2015 +0000
@@ -22,7 +22,17 @@
DigitalOut led1(LED1);
Serial pc(USBTX, USBRX);
+/* Declare the array */
+static const unsigned ADDR_LEN = 6;
+static const unsigned NUM_LIST = 3;
+typedef uint8_t Address_t[ADDR_LEN]; /* 48-bit address, LSB format. */
+typedef Address_t address_t; /* @Note: deprecated. Use Address_t instead. */
+
+/* Declare the pointer */
+uint8_t pt_addr = 0;
+uint8_t list_addr[NUM_LIST][ADDR_LEN]={0,0,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,0,0};
+int8_t list_rssi[NUM_LIST];
void periodicCallback(void)
{
led1 = !led1; /* Do blinky on LED1 while we're waiting for BLE events */
@@ -33,9 +43,51 @@
pc.printf("Adv peerAddr: [%02x %02x %02x %02x %02x %02x] rssi %d, ScanResp: %u, AdvType: %u\r\n",
params->peerAddr[5], params->peerAddr[4], params->peerAddr[3], params->peerAddr[2], params->peerAddr[1], params->peerAddr[0],
params->rssi, params->isScanResponse, params->type);
-
+
+ for(unsigned i = 0; i < NUM_LIST; i++) {
+ if(list_addr[i][5] == params->peerAddr[5] && list_addr[i][4] == params->peerAddr[4] && list_addr[i][3] == params->peerAddr[3] && list_addr[i][2] == params->peerAddr[2] && list_addr[i][1] == params->peerAddr[1] && list_addr[i][0] == params->peerAddr[0]) {
+ /* Only RSSI Value update */
+ list_rssi[i] = params->rssi;
+ break;
+ }
+ if(list_addr[i][5] == 0 && list_addr[i][4] == 0 && list_addr[i][3] == 0 && list_addr[i][2] == 0 && list_addr[i][1] == 0 && list_addr[i][0] == 0) {
+ /* Save the address */
+ list_addr[i][5] = params->peerAddr[5];
+ list_addr[i][4] = params->peerAddr[4];
+ list_addr[i][3] = params->peerAddr[3];
+ list_addr[i][2] = params->peerAddr[2];
+ list_addr[i][1] = params->peerAddr[1];
+ list_addr[i][0] = params->peerAddr[0];
+ /* Save RSSI value */
+ list_rssi[i] = params->rssi;
+ if ( i==2 ) {
+ /* Find Maximum RSSI value */
+ for(unsigned j=0;j<NUM_LIST;j++) {
+ for(unsigned k=j ; k<NUM_LIST ; k++) {
+ if(list_rssi[j] > list_rssi[j+1]) {
+ /* Swap RSSI Value */
+ temp = list_rssi[j];
+ list_rssi[j] = list_rssi[j+1];
+ list_rssi[j+1] = temp;
+
+ /* Swap the address */
+ for(unsigned l = 0; l < 6 ; l++) {
+ temp = list_addr[j][l];
+ list_addr[j][l] = list_addr[j+1][l];
+ list_addr[j+1][l] = temp;
+ }
+ }
+ }
+ }
+ break;
+ }
+
+ }
- pc.printf("%s", params->advertisingData);
+
+
+
+ pc.printf("%s", params->advertisingData);
pc.printf("\r\n");
@@ -96,13 +148,14 @@
/* */
- ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED);
+ ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED);
ble.gap().setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
- ble.accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME,
+ ble.accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME,
(const uint8_t *)"DDUDDU", sizeof("DDUDDU") - 1);
- ble.gap().setAdvertisingInterval(100); /* 1second. */
- ble.gap().startAdvertising();
+ /* We don't need any advertising because of its role */
+ //ble.gap().setAdvertisingInterval(100); /* 1second. */
+ //ble.gap().startAdvertising();
ble.gap().setScanParams(500 /* scan interval */, 200 /* scan window */);
ble.gap().startScan(advertisementCallback);