mbed Ethernet-based CoAP heartrate endpoint for Dreamforce 2015
Dependencies: GroveEarbudSensor mbed mbedConnectorInterface mbedEndpointNetwork
mbedEndpointResources/LocationResource.h@7:ccfb09b66c0b, 2015-09-06 (annotated)
- Committer:
- ansond
- Date:
- Sun Sep 06 22:11:18 2015 +0000
- Revision:
- 7:ccfb09b66c0b
- Parent:
- 4:7efe785afc7f
updates and fixes
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ansond | 0:b1fc60dd398f | 1 | /** |
ansond | 0:b1fc60dd398f | 2 | * @file LocationResource.h |
ansond | 0:b1fc60dd398f | 3 | * @brief mbed CoAP Endpoint Location resource supporting CoAP GET |
ansond | 0:b1fc60dd398f | 4 | * @author Doug Anson |
ansond | 0:b1fc60dd398f | 5 | * @version 1.0 |
ansond | 0:b1fc60dd398f | 6 | * @see |
ansond | 0:b1fc60dd398f | 7 | * |
ansond | 0:b1fc60dd398f | 8 | * Copyright (c) 2014 |
ansond | 0:b1fc60dd398f | 9 | * |
ansond | 0:b1fc60dd398f | 10 | * Licensed under the Apache License, Version 2.0 (the "License"); |
ansond | 0:b1fc60dd398f | 11 | * you may not use this file except in compliance with the License. |
ansond | 0:b1fc60dd398f | 12 | * You may obtain a copy of the License at |
ansond | 0:b1fc60dd398f | 13 | * |
ansond | 0:b1fc60dd398f | 14 | * http://www.apache.org/licenses/LICENSE-2.0 |
ansond | 0:b1fc60dd398f | 15 | * |
ansond | 0:b1fc60dd398f | 16 | * Unless required by applicable law or agreed to in writing, software |
ansond | 0:b1fc60dd398f | 17 | * distributed under the License is distributed on an "AS IS" BASIS, |
ansond | 0:b1fc60dd398f | 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
ansond | 0:b1fc60dd398f | 19 | * See the License for the specific language governing permissions and |
ansond | 0:b1fc60dd398f | 20 | * limitations under the License. |
ansond | 0:b1fc60dd398f | 21 | */ |
ansond | 0:b1fc60dd398f | 22 | |
ansond | 0:b1fc60dd398f | 23 | #ifndef __LOCATION_RESOURCE_H__ |
ansond | 0:b1fc60dd398f | 24 | #define __LOCATION_RESOURCE_H__ |
ansond | 0:b1fc60dd398f | 25 | |
ansond | 0:b1fc60dd398f | 26 | // Base class |
ansond | 0:b1fc60dd398f | 27 | #include "DynamicResource.h" |
ansond | 0:b1fc60dd398f | 28 | |
ansond | 0:b1fc60dd398f | 29 | // We have a static location by default - Moscone West - 37.783879,-122.4012538 |
ansond | 4:7efe785afc7f | 30 | #define MY_LATITUDE 37.783879 |
ansond | 4:7efe785afc7f | 31 | #define MY_LONGITUDE -122.4012538 |
ansond | 4:7efe785afc7f | 32 | #define MY_ALTITUDE 30.0 |
ansond | 4:7efe785afc7f | 33 | #define MY_SPEED 0.0 |
ansond | 0:b1fc60dd398f | 34 | |
ansond | 0:b1fc60dd398f | 35 | // Maximum Location JSON Length : {"latitude":XXX.YYYYYY, "longitude":XXX.YYYYYY, "msl":XXXXXX, "speed":XXXXXX} |
ansond | 0:b1fc60dd398f | 36 | #define LOCATION_JSON_LENGTH 256 |
ansond | 7:ccfb09b66c0b | 37 | char __location_json[LOCATION_JSON_LENGTH+1]; |
ansond | 0:b1fc60dd398f | 38 | |
ansond | 0:b1fc60dd398f | 39 | /** LocationResource class |
ansond | 0:b1fc60dd398f | 40 | */ |
ansond | 0:b1fc60dd398f | 41 | class LocationResource : public DynamicResource |
ansond | 0:b1fc60dd398f | 42 | { |
ansond | 0:b1fc60dd398f | 43 | public: |
ansond | 0:b1fc60dd398f | 44 | /** |
ansond | 0:b1fc60dd398f | 45 | Default constructor |
ansond | 0:b1fc60dd398f | 46 | @param logger input logger instance for this resource |
ansond | 0:b1fc60dd398f | 47 | @param name input the Location resource name |
ansond | 0:b1fc60dd398f | 48 | @param observable input the resource is Observable (default: FALSE) |
ansond | 0:b1fc60dd398f | 49 | */ |
ansond | 0:b1fc60dd398f | 50 | LocationResource(const Logger *logger,const char *name,const bool observable = false) : DynamicResource(logger,name,"Location",SN_GRS_GET_ALLOWED,observable) { |
ansond | 7:ccfb09b66c0b | 51 | memset(__location_json,0,LOCATION_JSON_LENGTH+1); |
ansond | 0:b1fc60dd398f | 52 | } |
ansond | 0:b1fc60dd398f | 53 | |
ansond | 0:b1fc60dd398f | 54 | /** |
ansond | 0:b1fc60dd398f | 55 | Get the value of the Location sensor |
ansond | 0:b1fc60dd398f | 56 | @returns string containing the location value |
ansond | 0:b1fc60dd398f | 57 | */ |
ansond | 0:b1fc60dd398f | 58 | virtual string get() { |
ansond | 7:ccfb09b66c0b | 59 | memset(__location_json,0,LOCATION_JSON_LENGTH); |
ansond | 7:ccfb09b66c0b | 60 | sprintf(__location_json,"{\"latitude\":%.6f,\"longitude\":%.6f,\"msl\":%.1f,\"speed\":%.1f}", |
ansond | 0:b1fc60dd398f | 61 | MY_LATITUDE, |
ansond | 0:b1fc60dd398f | 62 | MY_LONGITUDE, |
ansond | 0:b1fc60dd398f | 63 | MY_ALTITUDE, // in meters |
ansond | 0:b1fc60dd398f | 64 | MY_SPEED); // in meters/second |
ansond | 7:ccfb09b66c0b | 65 | return string(__location_json); |
ansond | 0:b1fc60dd398f | 66 | } |
ansond | 0:b1fc60dd398f | 67 | }; |
ansond | 0:b1fc60dd398f | 68 | |
ansond | 0:b1fc60dd398f | 69 | #endif // __LOCATION_RESOURCE_H__ |