Dreamforce 2015 BLE-based mDS HeartRate Monitor Endpoint

Dependencies:   GroveEarbudSensor mbed mbedConnectorInterface mbedEndpointNetwork_BLE

Files at this revision

API Documentation at this revision

Comitter:
ansond
Date:
Mon Sep 07 04:52:10 2015 +0000
Parent:
52:bd3177c6d7fd
Commit message:
updates and tweaks for static location option and android 5.x

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
mbedConnectorInterface.lib Show annotated file Show diff for this revision Revisions of this file
mbedEndpointNetwork.lib Show annotated file Show diff for this revision Revisions of this file
mbedEndpointResources/HeartrateResource.h Show annotated file Show diff for this revision Revisions of this file
mbedEndpointResources/LocationResource.h Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Sat Sep 05 20:51:19 2015 +0000
+++ b/main.cpp	Mon Sep 07 04:52:10 2015 +0000
@@ -33,7 +33,10 @@
 
 // Heartrate Resource
 #include "HeartrateResource.h"
-HeartrateResource hr(&logger,"888/0/5850",true); // observable   
+HeartrateResource hr(&logger,"888/0/5850",true);     // observable   
+
+// Enable BLE-based Location
+#define ENABLE_BLE_LOCATION                     false // true - enable BLELocation from Proxy (experimental!!). false - use default location below
 
 // Location Resource
 #include "LocationResource.h"
@@ -75,8 +78,8 @@
                  
                  // add the heartrate resource
                  .addResource(&light)
-                 .addResource(&hr)                   // Resource implements its own observationing...
-                 .addResource(&location,9000)        // observe every 9 seconds
+                 .addResource(&hr)                    // Resource implements its own observationing...
+                 .addResource(&location,13245)        // observe every 13.245 seconds
                                       
                  // finalize the configuration...
                  .build();
@@ -87,7 +90,7 @@
 {    
     // Announce
     logger.log("\r\n\r\nmbed mDS BLE Heartrate Endpoint");
-    
+        
     // we have to plumb our network first
     Connector::Endpoint::plumbNetwork();
      
--- a/mbed.bld	Sat Sep 05 20:51:19 2015 +0000
+++ b/mbed.bld	Mon Sep 07 04:52:10 2015 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/8ed44a420e5c
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/mbed/builds/ba1f97679dad
\ No newline at end of file
--- a/mbedConnectorInterface.lib	Sat Sep 05 20:51:19 2015 +0000
+++ b/mbedConnectorInterface.lib	Mon Sep 07 04:52:10 2015 +0000
@@ -1,1 +1,1 @@
-http://developer.mbed.org/users/ansond/code/mbedConnectorInterface/#167e8f021e30
+http://developer.mbed.org/users/ansond/code/mbedConnectorInterface/#143beb6d8800
--- a/mbedEndpointNetwork.lib	Sat Sep 05 20:51:19 2015 +0000
+++ b/mbedEndpointNetwork.lib	Mon Sep 07 04:52:10 2015 +0000
@@ -1,1 +1,1 @@
-https://developer.mbed.org/users/ansond/code/mbedEndpointNetwork_BLE/#71eb3663ecbd
+https://developer.mbed.org/users/ansond/code/mbedEndpointNetwork_BLE/#aa73681951ad
--- a/mbedEndpointResources/HeartrateResource.h	Sat Sep 05 20:51:19 2015 +0000
+++ b/mbedEndpointResources/HeartrateResource.h	Mon Sep 07 04:52:10 2015 +0000
@@ -46,7 +46,7 @@
 GroveEarbudSensor __earbud(ENDPOINT_INTERRUPT_PIN,&pc);
 
 // HRM sensor value
-static char __hrm[10] = {0};
+static char __hrm[10];
 
 // forward declaration
 extern void __hrm_callback(float value,void *instance);
@@ -64,6 +64,10 @@
     @param observable input the resource is Observable (default: FALSE)
     */
     HeartrateResource(const Logger *logger,const char *name,const bool observable = false) : DynamicResource(logger,name,"Heartrate",SN_GRS_GET_ALLOWED,observable) {
+        // init...
+        memset(__hrm,0,10);
+        sprintf(__hrm,"0.0");
+        
         // finish setup of the earbud sensor
         __earbud.registerCallback(&__hrm_callback,this);
         
--- a/mbedEndpointResources/LocationResource.h	Sat Sep 05 20:51:19 2015 +0000
+++ b/mbedEndpointResources/LocationResource.h	Mon Sep 07 04:52:10 2015 +0000
@@ -26,13 +26,23 @@
 // Base class
 #include "DynamicResource.h"
 
-// our Location source
-#include "BLELocation.h"
-extern RawSerial pc;               // main.cpp
-BLELocation _ble_location(&pc);    // BLE Location from the UART Proxy application
+// main.cpp can enable/disable the experimental location source 
+#if ENABLE_BLE_LOCATION
+    // our BLE Location source
+    #include "BLELocation.h"
+    extern RawSerial pc;               // main.cpp
+    BLELocation _ble_location(&pc);    // BLE Location from the UART Proxy application
+#endif
+
+// We have a static location by default - Moscone West - 37.783879,-122.4012538, altitude 30m msl
+#define DEF_LATITUDE          37.783879
+#define DEF_LONGITUDE        -122.4012538
+#define DEF_ALTITUDE          30.0
+#define DEF_SPEED             0.0
 
 // Maximum Location JSON Length : {"latitude":XXX.YYYYYY, "longitude":XXX.YYYYYY, "msl":XXXXXX, "speed":XXXXXX}
 #define LOCATION_JSON_LENGTH  256
+char __location_json[LOCATION_JSON_LENGTH+1];
 
 /** LocationResource class
  */
@@ -46,6 +56,10 @@
     @param observable input the resource is Observable (default: FALSE)
     */
     LocationResource(const Logger *logger,const char *name,const bool observable = false) : DynamicResource(logger,name,"Location",SN_GRS_GET_ALLOWED,observable) {
+        memset(__location_json,0,LOCATION_JSON_LENGTH+1);
+#if ENABLE_BLE_LOCATION 
+        _ble_location.setDefault(DEF_LATITUDE,DEF_LONGITUDE,DEF_ALTITUDE,DEF_SPEED);
+#endif
     }
 
     /**
@@ -53,15 +67,22 @@
     @returns string containing the location value
     */
     virtual string get() {
-        _ble_location.updateLocation();
-        char json[LOCATION_JSON_LENGTH+1];
-        memset(json,0,LOCATION_JSON_LENGTH+1);
-        sprintf(json,"{\"latitude\":%s,\"longitude\":%s,\"msl\":%s,\"speed\":%s}",
+        //_ble_location.updateLocation();
+        memset(__location_json,0,LOCATION_JSON_LENGTH);
+#if ENABLE_BLE_LOCATION
+        sprintf(__location_json,"{\"latitude\":%s,\"longitude\":%s,\"msl\":%s,\"speed\":%s,\"src\":\"proxy\"}",
                     _ble_location.getLatitude(),
                     _ble_location.getLongitude(),
                     _ble_location.getMSLAltitude(),    // in meters
                     _ble_location.getSpeed());         // in meters/second
-        return string(json);
+#else
+        sprintf(__location_json,"{\"latitude\":%.6f,\"longitude\":%.6f,\"msl\":%.1f,\"speed\":%.1f,\"src\":\"static\"}",
+                    DEF_LATITUDE,
+                    DEF_LONGITUDE,
+                    DEF_ALTITUDE,       // in meters
+                    DEF_SPEED);         // in meters/second
+#endif
+        return string(__location_json);
     }
 };