mbedConnectorInterface sample endpoint utilizing 3g cellular radio as the underlying connection transport.
Dependencies: LM75B mbed mbedConnectorInterface mbedEndpointNetwork_Ublox
mbedEndpointResources/LocationResource.h@7:68f1eadf4a63, 2015-07-25 (annotated)
- Committer:
- ansond
- Date:
- Sat Jul 25 05:16:06 2015 +0000
- Revision:
- 7:68f1eadf4a63
- Child:
- 9:0370006a6988
added initial support for GPS location. Removed nsp_configuration.h
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ansond | 7:68f1eadf4a63 | 1 | /** |
ansond | 7:68f1eadf4a63 | 2 | * @file LocationResource.h |
ansond | 7:68f1eadf4a63 | 3 | * @brief mbed CoAP Endpoint Location resource supporting CoAP GET |
ansond | 7:68f1eadf4a63 | 4 | * @author Doug Anson |
ansond | 7:68f1eadf4a63 | 5 | * @version 1.0 |
ansond | 7:68f1eadf4a63 | 6 | * @see |
ansond | 7:68f1eadf4a63 | 7 | * |
ansond | 7:68f1eadf4a63 | 8 | * Copyright (c) 2014 |
ansond | 7:68f1eadf4a63 | 9 | * |
ansond | 7:68f1eadf4a63 | 10 | * Licensed under the Apache License, Version 2.0 (the "License"); |
ansond | 7:68f1eadf4a63 | 11 | * you may not use this file except in compliance with the License. |
ansond | 7:68f1eadf4a63 | 12 | * You may obtain a copy of the License at |
ansond | 7:68f1eadf4a63 | 13 | * |
ansond | 7:68f1eadf4a63 | 14 | * http://www.apache.org/licenses/LICENSE-2.0 |
ansond | 7:68f1eadf4a63 | 15 | * |
ansond | 7:68f1eadf4a63 | 16 | * Unless required by applicable law or agreed to in writing, software |
ansond | 7:68f1eadf4a63 | 17 | * distributed under the License is distributed on an "AS IS" BASIS, |
ansond | 7:68f1eadf4a63 | 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
ansond | 7:68f1eadf4a63 | 19 | * See the License for the specific language governing permissions and |
ansond | 7:68f1eadf4a63 | 20 | * limitations under the License. |
ansond | 7:68f1eadf4a63 | 21 | */ |
ansond | 7:68f1eadf4a63 | 22 | |
ansond | 7:68f1eadf4a63 | 23 | #ifndef __LOCATION_RESOURCE_H__ |
ansond | 7:68f1eadf4a63 | 24 | #define __LOCATION_RESOURCE_H__ |
ansond | 7:68f1eadf4a63 | 25 | |
ansond | 7:68f1eadf4a63 | 26 | // Base class |
ansond | 7:68f1eadf4a63 | 27 | #include "DynamicResource.h" |
ansond | 7:68f1eadf4a63 | 28 | |
ansond | 7:68f1eadf4a63 | 29 | // our Location source |
ansond | 7:68f1eadf4a63 | 30 | #include "MBEDUbloxGPS.h" |
ansond | 7:68f1eadf4a63 | 31 | extern RawSerial pc; // main.cpp |
ansond | 7:68f1eadf4a63 | 32 | MBEDUbloxGPS _ublox_gps(&pc); // U-blox GPS support |
ansond | 7:68f1eadf4a63 | 33 | |
ansond | 7:68f1eadf4a63 | 34 | // Maximum Location JSON Length : {"latitude":XXX.YYYYYY, "longitude":XXX.YYYYYY, "msl":XXXXXX, "speed":XXXXXX} |
ansond | 7:68f1eadf4a63 | 35 | #define LOCATION_JSON_LENGTH 96 |
ansond | 7:68f1eadf4a63 | 36 | |
ansond | 7:68f1eadf4a63 | 37 | /** LocationResource class |
ansond | 7:68f1eadf4a63 | 38 | */ |
ansond | 7:68f1eadf4a63 | 39 | class LocationResource : public DynamicResource |
ansond | 7:68f1eadf4a63 | 40 | { |
ansond | 7:68f1eadf4a63 | 41 | public: |
ansond | 7:68f1eadf4a63 | 42 | /** |
ansond | 7:68f1eadf4a63 | 43 | Default constructor |
ansond | 7:68f1eadf4a63 | 44 | @param logger input logger instance for this resource |
ansond | 7:68f1eadf4a63 | 45 | @param name input the Location resource name |
ansond | 7:68f1eadf4a63 | 46 | @param observable input the resource is Observable (default: FALSE) |
ansond | 7:68f1eadf4a63 | 47 | */ |
ansond | 7:68f1eadf4a63 | 48 | LocationResource(const Logger *logger,const char *name,const bool observable = false) : DynamicResource(logger,name,"Location",SN_GRS_GET_ALLOWED,observable) { |
ansond | 7:68f1eadf4a63 | 49 | } |
ansond | 7:68f1eadf4a63 | 50 | |
ansond | 7:68f1eadf4a63 | 51 | /** |
ansond | 7:68f1eadf4a63 | 52 | Get the value of the Location sensor |
ansond | 7:68f1eadf4a63 | 53 | @returns string containing the temperature sensor value |
ansond | 7:68f1eadf4a63 | 54 | */ |
ansond | 7:68f1eadf4a63 | 55 | virtual string get() { |
ansond | 7:68f1eadf4a63 | 56 | _ublox_gps.updateLocation(); |
ansond | 7:68f1eadf4a63 | 57 | char json[LOCATION_JSON_LENGTH+1]; |
ansond | 7:68f1eadf4a63 | 58 | memset(json,0,LOCATION_JSON_LENGTH+1); |
ansond | 7:68f1eadf4a63 | 59 | sprintf(json,"{\"latitude\":%s,\"longitude\":%s,\"msl\":%s,\"speed\":%s}", |
ansond | 7:68f1eadf4a63 | 60 | _ublox_gps.getLatitude(), |
ansond | 7:68f1eadf4a63 | 61 | _ublox_gps.getLongitude(), |
ansond | 7:68f1eadf4a63 | 62 | _ublox_gps.getMSLAltitude(), |
ansond | 7:68f1eadf4a63 | 63 | _ublox_gps.getSpeed()); |
ansond | 7:68f1eadf4a63 | 64 | return string(json); |
ansond | 7:68f1eadf4a63 | 65 | } |
ansond | 7:68f1eadf4a63 | 66 | }; |
ansond | 7:68f1eadf4a63 | 67 | |
ansond | 7:68f1eadf4a63 | 68 | #endif // __TEMPERATURE_RESOURCE_H__ |