Dreamforce 2015 BLE-based mDS HeartRate Monitor Endpoint

Dependencies:   GroveEarbudSensor mbed mbedConnectorInterface mbedEndpointNetwork_BLE

Committer:
ansond
Date:
Mon Sep 07 04:52:10 2015 +0000
Revision:
53:d22af3b91e4c
Parent:
47:5e57fdac6765
updates and tweaks for static location option and android 5.x

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ansond 42:9741365cff35 1 /**
ansond 42:9741365cff35 2 * @file LocationResource.h
ansond 42:9741365cff35 3 * @brief mbed CoAP Endpoint Location resource supporting CoAP GET
ansond 42:9741365cff35 4 * @author Doug Anson
ansond 42:9741365cff35 5 * @version 1.0
ansond 42:9741365cff35 6 * @see
ansond 42:9741365cff35 7 *
ansond 42:9741365cff35 8 * Copyright (c) 2014
ansond 42:9741365cff35 9 *
ansond 42:9741365cff35 10 * Licensed under the Apache License, Version 2.0 (the "License");
ansond 42:9741365cff35 11 * you may not use this file except in compliance with the License.
ansond 42:9741365cff35 12 * You may obtain a copy of the License at
ansond 42:9741365cff35 13 *
ansond 42:9741365cff35 14 * http://www.apache.org/licenses/LICENSE-2.0
ansond 42:9741365cff35 15 *
ansond 42:9741365cff35 16 * Unless required by applicable law or agreed to in writing, software
ansond 42:9741365cff35 17 * distributed under the License is distributed on an "AS IS" BASIS,
ansond 42:9741365cff35 18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
ansond 42:9741365cff35 19 * See the License for the specific language governing permissions and
ansond 42:9741365cff35 20 * limitations under the License.
ansond 42:9741365cff35 21 */
ansond 42:9741365cff35 22
ansond 42:9741365cff35 23 #ifndef __LOCATION_RESOURCE_H__
ansond 42:9741365cff35 24 #define __LOCATION_RESOURCE_H__
ansond 42:9741365cff35 25
ansond 42:9741365cff35 26 // Base class
ansond 42:9741365cff35 27 #include "DynamicResource.h"
ansond 42:9741365cff35 28
ansond 53:d22af3b91e4c 29 // main.cpp can enable/disable the experimental location source
ansond 53:d22af3b91e4c 30 #if ENABLE_BLE_LOCATION
ansond 53:d22af3b91e4c 31 // our BLE Location source
ansond 53:d22af3b91e4c 32 #include "BLELocation.h"
ansond 53:d22af3b91e4c 33 extern RawSerial pc; // main.cpp
ansond 53:d22af3b91e4c 34 BLELocation _ble_location(&pc); // BLE Location from the UART Proxy application
ansond 53:d22af3b91e4c 35 #endif
ansond 53:d22af3b91e4c 36
ansond 53:d22af3b91e4c 37 // We have a static location by default - Moscone West - 37.783879,-122.4012538, altitude 30m msl
ansond 53:d22af3b91e4c 38 #define DEF_LATITUDE 37.783879
ansond 53:d22af3b91e4c 39 #define DEF_LONGITUDE -122.4012538
ansond 53:d22af3b91e4c 40 #define DEF_ALTITUDE 30.0
ansond 53:d22af3b91e4c 41 #define DEF_SPEED 0.0
ansond 42:9741365cff35 42
ansond 42:9741365cff35 43 // Maximum Location JSON Length : {"latitude":XXX.YYYYYY, "longitude":XXX.YYYYYY, "msl":XXXXXX, "speed":XXXXXX}
ansond 47:5e57fdac6765 44 #define LOCATION_JSON_LENGTH 256
ansond 53:d22af3b91e4c 45 char __location_json[LOCATION_JSON_LENGTH+1];
ansond 42:9741365cff35 46
ansond 42:9741365cff35 47 /** LocationResource class
ansond 42:9741365cff35 48 */
ansond 42:9741365cff35 49 class LocationResource : public DynamicResource
ansond 42:9741365cff35 50 {
ansond 42:9741365cff35 51 public:
ansond 42:9741365cff35 52 /**
ansond 42:9741365cff35 53 Default constructor
ansond 42:9741365cff35 54 @param logger input logger instance for this resource
ansond 42:9741365cff35 55 @param name input the Location resource name
ansond 42:9741365cff35 56 @param observable input the resource is Observable (default: FALSE)
ansond 42:9741365cff35 57 */
ansond 42:9741365cff35 58 LocationResource(const Logger *logger,const char *name,const bool observable = false) : DynamicResource(logger,name,"Location",SN_GRS_GET_ALLOWED,observable) {
ansond 53:d22af3b91e4c 59 memset(__location_json,0,LOCATION_JSON_LENGTH+1);
ansond 53:d22af3b91e4c 60 #if ENABLE_BLE_LOCATION
ansond 53:d22af3b91e4c 61 _ble_location.setDefault(DEF_LATITUDE,DEF_LONGITUDE,DEF_ALTITUDE,DEF_SPEED);
ansond 53:d22af3b91e4c 62 #endif
ansond 42:9741365cff35 63 }
ansond 42:9741365cff35 64
ansond 42:9741365cff35 65 /**
ansond 42:9741365cff35 66 Get the value of the Location sensor
ansond 47:5e57fdac6765 67 @returns string containing the location value
ansond 42:9741365cff35 68 */
ansond 42:9741365cff35 69 virtual string get() {
ansond 53:d22af3b91e4c 70 //_ble_location.updateLocation();
ansond 53:d22af3b91e4c 71 memset(__location_json,0,LOCATION_JSON_LENGTH);
ansond 53:d22af3b91e4c 72 #if ENABLE_BLE_LOCATION
ansond 53:d22af3b91e4c 73 sprintf(__location_json,"{\"latitude\":%s,\"longitude\":%s,\"msl\":%s,\"speed\":%s,\"src\":\"proxy\"}",
ansond 42:9741365cff35 74 _ble_location.getLatitude(),
ansond 42:9741365cff35 75 _ble_location.getLongitude(),
ansond 47:5e57fdac6765 76 _ble_location.getMSLAltitude(), // in meters
ansond 47:5e57fdac6765 77 _ble_location.getSpeed()); // in meters/second
ansond 53:d22af3b91e4c 78 #else
ansond 53:d22af3b91e4c 79 sprintf(__location_json,"{\"latitude\":%.6f,\"longitude\":%.6f,\"msl\":%.1f,\"speed\":%.1f,\"src\":\"static\"}",
ansond 53:d22af3b91e4c 80 DEF_LATITUDE,
ansond 53:d22af3b91e4c 81 DEF_LONGITUDE,
ansond 53:d22af3b91e4c 82 DEF_ALTITUDE, // in meters
ansond 53:d22af3b91e4c 83 DEF_SPEED); // in meters/second
ansond 53:d22af3b91e4c 84 #endif
ansond 53:d22af3b91e4c 85 return string(__location_json);
ansond 42:9741365cff35 86 }
ansond 42:9741365cff35 87 };
ansond 42:9741365cff35 88
ansond 42:9741365cff35 89 #endif // __LOCATION_RESOURCE_H__