Station API

Dependents:   GMCStation

Committer:
yamaguch
Date:
Mon Dec 12 11:41:24 2011 +0000
Revision:
2:a9d1a9c92927
Parent:
1:a22e390c70b3
Child:
5:3df13e2e928e

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
yamaguch 2:a9d1a9c92927 1 /*
yamaguch 2:a9d1a9c92927 2 Copyright (c) 2011, Senio Networks, Inc.
yamaguch 2:a9d1a9c92927 3
yamaguch 2:a9d1a9c92927 4 Permission is hereby granted, free of charge, to any person obtaining a copy
yamaguch 2:a9d1a9c92927 5 of this software and associated documentation files (the "Software"), to deal
yamaguch 2:a9d1a9c92927 6 in the Software without restriction, including without limitation the rights
yamaguch 2:a9d1a9c92927 7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
yamaguch 2:a9d1a9c92927 8 copies of the Software, and to permit persons to whom the Software is
yamaguch 2:a9d1a9c92927 9 furnished to do so, subject to the following conditions:
yamaguch 2:a9d1a9c92927 10
yamaguch 2:a9d1a9c92927 11 The above copyright notice and this permission notice shall be included in
yamaguch 2:a9d1a9c92927 12 all copies or substantial portions of the Software.
yamaguch 2:a9d1a9c92927 13
yamaguch 2:a9d1a9c92927 14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
yamaguch 2:a9d1a9c92927 15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
yamaguch 2:a9d1a9c92927 16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
yamaguch 2:a9d1a9c92927 17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
yamaguch 2:a9d1a9c92927 18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
yamaguch 2:a9d1a9c92927 19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
yamaguch 2:a9d1a9c92927 20 THE SOFTWARE.
yamaguch 2:a9d1a9c92927 21 */
yamaguch 2:a9d1a9c92927 22
yamaguch 1:a22e390c70b3 23 #ifndef LOCATION_H
yamaguch 1:a22e390c70b3 24 #define LOCATION_H
yamaguch 1:a22e390c70b3 25
yamaguch 2:a9d1a9c92927 26 /**
yamaguch 2:a9d1a9c92927 27 * Location info object
yamaguch 2:a9d1a9c92927 28 */
yamaguch 1:a22e390c70b3 29 class Location {
yamaguch 1:a22e390c70b3 30 public:
yamaguch 1:a22e390c70b3 31 /**
yamaguch 2:a9d1a9c92927 32 * Constructor
yamaguch 2:a9d1a9c92927 33 *
yamaguch 2:a9d1a9c92927 34 * @param longitude longitude in degrees
yamaguch 2:a9d1a9c92927 35 * @param latitude latutude in degrees
yamaguch 2:a9d1a9c92927 36 * @param elevation elevation in meters
yamaguch 2:a9d1a9c92927 37 */
yamaguch 2:a9d1a9c92927 38 Location(double longitude = 0, double latitude = 0, float elavation = 0)
yamaguch 2:a9d1a9c92927 39 : longitude(longitude), latitude(latitude), elevation(elevation) {}
yamaguch 2:a9d1a9c92927 40
yamaguch 2:a9d1a9c92927 41 /**
yamaguch 2:a9d1a9c92927 42 * creates a Location object from a config file
yamaguch 2:a9d1a9c92927 43 *
yamaguch 2:a9d1a9c92927 44 * @param filename name of the config file
yamaguch 2:a9d1a9c92927 45 * @param verbose if true display debug info
yamaguch 2:a9d1a9c92927 46 */
yamaguch 2:a9d1a9c92927 47 static Location create(char *filename, bool verbose = false) {
yamaguch 2:a9d1a9c92927 48 double longitude = 0, latitude = 0;
yamaguch 2:a9d1a9c92927 49 float elevation = 0;
yamaguch 2:a9d1a9c92927 50
yamaguch 2:a9d1a9c92927 51 if (filename) {
yamaguch 2:a9d1a9c92927 52 char path[32];
yamaguch 2:a9d1a9c92927 53 LocalFileSystem local("local");
yamaguch 2:a9d1a9c92927 54 sprintf(path, "/local/%s", filename);
yamaguch 2:a9d1a9c92927 55 if (FILE *fp = fopen(path, "r")) {
yamaguch 2:a9d1a9c92927 56 Utils::fgetValues(fp, "longitude:%lf", &longitude);
yamaguch 2:a9d1a9c92927 57 Utils::fgetValues(fp, "latitude:%lf", &latitude);
yamaguch 2:a9d1a9c92927 58 Utils::fgetValues(fp, "elevation:%f", &elevation);
yamaguch 2:a9d1a9c92927 59 fclose(fp);
yamaguch 2:a9d1a9c92927 60 if (verbose) {
yamaguch 2:a9d1a9c92927 61 printf( "longitude:%lf\n", longitude);
yamaguch 2:a9d1a9c92927 62 printf( "latitude:%lf\n", latitude);
yamaguch 2:a9d1a9c92927 63 printf( "elevation:%f\n", elevation);
yamaguch 2:a9d1a9c92927 64 }
yamaguch 2:a9d1a9c92927 65 }
yamaguch 2:a9d1a9c92927 66 }
yamaguch 2:a9d1a9c92927 67
yamaguch 2:a9d1a9c92927 68 return Location(longitude, latitude, elevation);
yamaguch 2:a9d1a9c92927 69 }
yamaguch 2:a9d1a9c92927 70
yamaguch 2:a9d1a9c92927 71 /**
yamaguch 1:a22e390c70b3 72 * Returns longitude
yamaguch 1:a22e390c70b3 73 *
yamaguch 1:a22e390c70b3 74 * @returns longitude in degrees
yamaguch 1:a22e390c70b3 75 */
yamaguch 1:a22e390c70b3 76 double getLongitude() {
yamaguch 1:a22e390c70b3 77 return longitude;
yamaguch 1:a22e390c70b3 78 }
yamaguch 1:a22e390c70b3 79
yamaguch 1:a22e390c70b3 80 /**
yamaguch 1:a22e390c70b3 81 * Sets longitude
yamaguch 1:a22e390c70b3 82 *
yamaguch 1:a22e390c70b3 83 * @param longitude longitude in degrees
yamaguch 1:a22e390c70b3 84 */
yamaguch 1:a22e390c70b3 85 void setLongitude(double longitude) {
yamaguch 1:a22e390c70b3 86 this->longitude = longitude;
yamaguch 1:a22e390c70b3 87 }
yamaguch 1:a22e390c70b3 88
yamaguch 1:a22e390c70b3 89 /**
yamaguch 1:a22e390c70b3 90 * Returns longitude
yamaguch 1:a22e390c70b3 91 *
yamaguch 1:a22e390c70b3 92 * @returns longitude in degrees
yamaguch 1:a22e390c70b3 93 */ double getLatitude() {
yamaguch 1:a22e390c70b3 94 return latitude;
yamaguch 1:a22e390c70b3 95 }
yamaguch 2:a9d1a9c92927 96
yamaguch 1:a22e390c70b3 97 /**
yamaguch 1:a22e390c70b3 98 * Sets latitude
yamaguch 1:a22e390c70b3 99 *
yamaguch 1:a22e390c70b3 100 * @param latitude latitude in degrees
yamaguch 1:a22e390c70b3 101 */
yamaguch 1:a22e390c70b3 102 void setLatitude(double latinude) {
yamaguch 1:a22e390c70b3 103 this->latitude = latitude;
yamaguch 1:a22e390c70b3 104 }
yamaguch 1:a22e390c70b3 105
yamaguch 1:a22e390c70b3 106 /**
yamaguch 1:a22e390c70b3 107 * Returns elevation
yamaguch 1:a22e390c70b3 108 *
yamaguch 1:a22e390c70b3 109 * @returns elevation in meters
yamaguch 1:a22e390c70b3 110 */
yamaguch 2:a9d1a9c92927 111 float getElevation() {
yamaguch 1:a22e390c70b3 112 return elevation;
yamaguch 1:a22e390c70b3 113 }
yamaguch 2:a9d1a9c92927 114
yamaguch 1:a22e390c70b3 115 /**
yamaguch 1:a22e390c70b3 116 * Sets elevation
yamaguch 1:a22e390c70b3 117 *
yamaguch 1:a22e390c70b3 118 * @param elevation elevation in meters
yamaguch 1:a22e390c70b3 119 */
yamaguch 1:a22e390c70b3 120 void setElavation(float elevation) {
yamaguch 1:a22e390c70b3 121 this->elevation = elevation;
yamaguch 1:a22e390c70b3 122 }
yamaguch 1:a22e390c70b3 123
yamaguch 1:a22e390c70b3 124 private:
yamaguch 1:a22e390c70b3 125 double longitude, latitude;
yamaguch 1:a22e390c70b3 126 float elevation;
yamaguch 1:a22e390c70b3 127 };
yamaguch 1:a22e390c70b3 128
yamaguch 1:a22e390c70b3 129 #endif