Station API

Dependents:   GMCStation

Revision:
2:a9d1a9c92927
Parent:
1:a22e390c70b3
Child:
5:3df13e2e928e
--- a/Location.h	Mon Dec 12 02:33:21 2011 +0000
+++ b/Location.h	Mon Dec 12 11:41:24 2011 +0000
@@ -1,9 +1,74 @@
+/*
+Copyright (c) 2011, Senio Networks, Inc.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+*/
+
 #ifndef LOCATION_H
 #define LOCATION_H
 
+/**
+ * Location info object
+ */
 class Location {
 public:
     /**
+     * Constructor
+     *
+     * @param longitude longitude in degrees
+     * @param latitude latutude in degrees
+     * @param elevation elevation in meters
+     */
+    Location(double longitude = 0, double latitude = 0, float elavation = 0)
+            : longitude(longitude), latitude(latitude), elevation(elevation) {}
+
+    /**
+     * creates a Location object from a config file
+     *
+     * @param filename name of the config file
+     * @param verbose if true display debug info
+     */
+    static Location create(char *filename, bool verbose = false) {
+        double longitude = 0, latitude = 0;
+        float elevation = 0;
+
+        if (filename) {
+            char path[32];
+            LocalFileSystem local("local");
+            sprintf(path, "/local/%s", filename);
+            if (FILE *fp = fopen(path, "r")) {
+                Utils::fgetValues(fp, "longitude:%lf", &longitude);
+                Utils::fgetValues(fp, "latitude:%lf", &latitude);
+                Utils::fgetValues(fp, "elevation:%f", &elevation);
+                fclose(fp);
+                if (verbose) {
+                    printf( "longitude:%lf\n", longitude);
+                    printf( "latitude:%lf\n", latitude);
+                    printf( "elevation:%f\n", elevation);
+                }
+            }
+        }
+
+        return Location(longitude, latitude, elevation);
+    }
+
+    /**
      * Returns longitude
      *
      * @returns longitude in degrees
@@ -28,7 +93,7 @@
      */    double getLatitude() {
         return latitude;
     }
-    
+
     /**
      * Sets latitude
      *
@@ -43,10 +108,10 @@
      *
      * @returns elevation in meters
      */
-    float getElevaion() {
+    float getElevation() {
         return elevation;
     }
-    
+
     /**
      * Sets elevation
      *