with 2 advertisers

Dependencies:   ADXL345_nRF51 BLE_API advertiser_data mbed nRF51822

Fork of BLE_GAP_Acceleration_Observer_2_Advertisers by Matthew Chan

Files at this revision

API Documentation at this revision

Comitter:
mchan
Date:
Wed Jul 29 17:14:40 2015 +0000
Parent:
15:c82a77e2f9a5
Commit message:
Made to differentiate between advertiser 1 and advertiser 2

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r c82a77e2f9a5 -r 7593fe102c55 main.cpp
--- a/main.cpp	Mon Jul 27 18:50:30 2015 +0000
+++ b/main.cpp	Wed Jul 29 17:14:40 2015 +0000
@@ -79,6 +79,54 @@
     //pc.printf("Found device...\n\r");
 #endif
     if (params->peerAddr[5] == 0xe5 && params->peerAddr[4] == 0x4f) {
+        pc.printf("ADVERTISER 1\n\r");
+#ifdef DEBUG
+        for (unsigned index = 0; index < params->advertisingDataLen; index++) {
+          pc.printf("%02x ", params->advertisingData[index]);
+        }
+        pc.printf("\n\r");
+#endif
+        /* Using only the 3rd part of address for indexing the stored data for now */
+        advertiser_data *pdata = get_advertiser_data(params->peerAddr[3]);
+        if (!pdata) {
+#ifdef DEBUG
+            pc.printf("Too many advertisers!\n\r");
+#endif
+            return;
+        }
+
+        /* Always update the rssi */
+        uint8_t passdat = (uint8_t)(abs(params->rssi));
+        advertiser_data_update_rssi(pdata, passdat);
+
+        /* Find the manufacturers data */
+        const uint8_t *manData = NULL;
+        uint8_t manDataLen = 0;
+        get_manufacturer_data(params->advertisingData, params->advertisingDataLen, manData, manDataLen);
+
+        /* If the data is empty, skip the counter check */
+        if (!advertiser_data_is_empty(pdata)) {
+            uint8_t diff = advertiser_data_counter_difference(pdata, manData, manDataLen);
+            if (diff == 0) {
+                /* Quit early if we've seen this packet */
+                return;
+            } else if (diff > 1) {
+#ifdef DEBUG
+                pc.printf("resetting: diff is %d\n\r", diff);
+#endif
+                /* Reset the data if we missed a packet (likely lost signal for a while) */
+                advertiser_data_reset(pdata);
+                advertiser_data_update_rssi(pdata, passdat);
+            }
+        }
+
+        /* Update everything from the manufacturer data */
+        advertiser_data_update(pdata, manData, manDataLen);
+
+        // TODO: implement the rest of the algorithms
+        advertiser_data_print(pdata);
+    }else if(params->peerAddr[5] == 0xe6 && params->peerAddr[4] == 0x4f) {
+        pc.printf("ADVERTISER 2\n\r");
 #ifdef DEBUG
         for (unsigned index = 0; index < params->advertisingDataLen; index++) {
           pc.printf("%02x ", params->advertisingData[index]);