UpdatedDecryp

Dependencies:   BahlDecrypModified CyaSSL mbed nRF51822

Fork of Decryptulator by Mobius IoT

Revision:
7:91324daa3bfa
Parent:
6:850f44146c9f
Child:
8:649bd171929e
--- a/main.cpp	Wed Jul 15 02:53:12 2015 +0000
+++ b/main.cpp	Mon Jul 20 09:00:24 2015 +0000
@@ -16,6 +16,24 @@
 
 #include "mbed.h"
 #include "BLE.h"
+#include "TMP_nrf51/TMP_nrf51.h"
+
+#define COMP_ID_TEST 0xFEFE
+
+#pragma pack(1)
+/* Advertising data  */
+typedef struct advertisingData {
+    uint8_t length; /* doesn't include itself*/
+    GapAdvertisingData::DataType dataType;
+    uint8_t data[1];
+} advertisingData_t;
+
+typedef struct manufacturerData {
+    uint16_t companyId;
+    /* User defined manufacture data */
+    TMP_nrf51::tmpSensorValue_t tmpSensorValue;
+} manufacturerData_t;
+#pragma pack()
 
 BLE        ble;
 DigitalOut led1(LED1);
@@ -27,19 +45,20 @@
 
 void advertisementCallback(const Gap::AdvertisementCallbackParams_t *params)
 {
-    if((params->advertisingData[9] == 0xFE) && (params->advertisingData[10] == 0xFE)) {
-        float tempVal = 0;
-        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);
+    advertisingData_t *pAdvData = NULL;
+    uint8_t len = 0;
     
-        for (unsigned index = 0; index < params->advertisingDataLen; index++) {
-            printf("%02x ", params->advertisingData[index]);
+    /* Search for the manufacturer data */
+    while(len < params->advertisingDataLen) {
+        pAdvData = (advertisingData_t *)&params->advertisingData[len];
+        if(pAdvData->dataType == GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA) {
+            manufacturerData_t *pManuData = (manufacturerData_t *)pAdvData->data;
+            if(pManuData->companyId == COMP_ID_TEST) {
+                printf("Recv temp is %f\r\n", (float)pManuData->tmpSensorValue);
+                break;
+            }
         }
-        
-        memcpy(&tempVal, &params->advertisingData[11], 4); /* temperature value */
-        printf("temp is %f\r\n", tempVal);
-
+        len += (pAdvData->length + 1);
     }
 }
 
@@ -50,7 +69,6 @@
     ticker.attach(periodicCallback, 1);
 
     ble.init();
-
     ble.gap().setScanParams(1800 /* scan interval */, 1500 /* scan window */);
     ble.gap().startScan(advertisementCallback);