testing for double to float

Dependencies:   ADXL345_nRF51 BLE_API advertiser_data mbed nRF51822

Fork of BLE_GAP_Acceleration_Observer_2_Advertisers by Ames HCI IoT

Revision:
10:0733d4800ed1
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp.orig	Thu Jul 23 12:38:40 2015 +0000
@@ -0,0 +1,96 @@
+/* mbed Microcontroller Library
+ * Copyright (c) 2006-2015 ARM Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "mbed.h"
+#include "BLE.h"
+
+BLE        ble;
+
+typedef union _accleration_data {
+  float f;
+  uint8_t  b[4];
+} acceleration_data;
+
+typedef enum _parse_state {
+    PARSE_SIZE,
+    PARSE_TYPE,
+    PARSE_DATA
+} ParseState;
+
+Serial pc(USBTX, USBRX);
+
+void advertisementCallback(const Gap::AdvertisementCallbackParams_t *params)
+{
+    if (params->peerAddr[5] == 0xe5 && params->peerAddr[4] == 0x4f) {
+        
+        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 index = 0; index < params->advertisingDataLen; index++) {
+           pc.printf("%02x ", params->advertisingData[index]);
+        }
+        pc.printf("\r\n");
+        
+        /* Quick and dirty naive way */
+        /*acceleration_data acceleration;
+        acceleration.f = 4.5;
+        if (params->advertisingDataLen != 6) return;
+        for (unsigned i = 0; i < 4; i++) {
+            acceleration.b[i] = params->advertisingData[i+2];
+        }
+        pc.printf("Acceleration: %.2f", acceleration.f);
+        pc.printf("\r\n");*/
+        
+        
+        /* Printing the boolean for being picked up or not*/
+        bool p = params->advertisingData[2];
+        pc.printf("Picked up: %p",p);
+        pc.printf("\r\n");
+        
+        /*
+        
+        unsigned index = 0;
+        uint8_t data_size = 0;
+        unsigned data_index = 0;
+        while (index < params->advertisingDataLen) {
+            data_size = params->advertisingData[index];
+            data_index = index;
+            // TODO: CHECK for size > dataLen
+            for (index; index < data_index + data_size; index++) { 
+                // do something with the data 
+            }
+        }
+        */
+    }
+}
+
+int main(void)
+{
+    ble.init();
+
+    // Set scan to be constant by interval == window
+    ble.gap().setScanParams(500 /* scan interval */, 500 /* scan window */);
+    ble.gap().startScan(advertisementCallback);
+    
+    pc.baud(9600);
+    wait(8);
+    pc.printf("Started scanning...\n\r");
+    
+
+    while (true) {
+        ble.waitForEvent();
+    }
+}