mbed Ethernet-based CoAP heartrate endpoint for Dreamforce 2015
Dependencies: GroveEarbudSensor mbed mbedConnectorInterface mbedEndpointNetwork
LocationResource.h
00001 /** 00002 * @file LocationResource.h 00003 * @brief mbed CoAP Endpoint Location resource supporting CoAP GET 00004 * @author Doug Anson 00005 * @version 1.0 00006 * @see 00007 * 00008 * Copyright (c) 2014 00009 * 00010 * Licensed under the Apache License, Version 2.0 (the "License"); 00011 * you may not use this file except in compliance with the License. 00012 * You may obtain a copy of the License at 00013 * 00014 * http://www.apache.org/licenses/LICENSE-2.0 00015 * 00016 * Unless required by applicable law or agreed to in writing, software 00017 * distributed under the License is distributed on an "AS IS" BASIS, 00018 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00019 * See the License for the specific language governing permissions and 00020 * limitations under the License. 00021 */ 00022 00023 #ifndef __LOCATION_RESOURCE_H__ 00024 #define __LOCATION_RESOURCE_H__ 00025 00026 // Base class 00027 #include "DynamicResource.h" 00028 00029 // We have a static location by default - Moscone West - 37.783879,-122.4012538 00030 #define MY_LATITUDE 37.783879 00031 #define MY_LONGITUDE -122.4012538 00032 #define MY_ALTITUDE 30.0 00033 #define MY_SPEED 0.0 00034 00035 // Maximum Location JSON Length : {"latitude":XXX.YYYYYY, "longitude":XXX.YYYYYY, "msl":XXXXXX, "speed":XXXXXX} 00036 #define LOCATION_JSON_LENGTH 256 00037 char __location_json[LOCATION_JSON_LENGTH+1]; 00038 00039 /** LocationResource class 00040 */ 00041 class LocationResource : public DynamicResource 00042 { 00043 public: 00044 /** 00045 Default constructor 00046 @param logger input logger instance for this resource 00047 @param name input the Location resource name 00048 @param observable input the resource is Observable (default: FALSE) 00049 */ 00050 LocationResource(const Logger *logger,const char *name,const bool observable = false) : DynamicResource(logger,name,"Location",SN_GRS_GET_ALLOWED,observable) { 00051 memset(__location_json,0,LOCATION_JSON_LENGTH+1); 00052 } 00053 00054 /** 00055 Get the value of the Location sensor 00056 @returns string containing the location value 00057 */ 00058 virtual string get() { 00059 memset(__location_json,0,LOCATION_JSON_LENGTH); 00060 sprintf(__location_json,"{\"latitude\":%.6f,\"longitude\":%.6f,\"msl\":%.1f,\"speed\":%.1f}", 00061 MY_LATITUDE, 00062 MY_LONGITUDE, 00063 MY_ALTITUDE, // in meters 00064 MY_SPEED); // in meters/second 00065 return string(__location_json); 00066 } 00067 }; 00068 00069 #endif // __LOCATION_RESOURCE_H__
Generated on Thu Jul 14 2022 21:41:08 by 1.7.2