Maemo package folder added.
[speedfreak] / Client / gpsdata.cpp
index 36dd60c..f0f53eb 100644 (file)
@@ -10,7 +10,7 @@
 #include <QDebug>
 
 /**
-  *Default constructor of this class.
+  * Default constructor of this class.
   */
 GPSData::GPSData(Maemo5Location *maemo5location)
 {
@@ -31,7 +31,7 @@ GPSData::GPSData(Maemo5Location *maemo5location)
 }
 
 /**
-  *Destructor of this class. Deletes all dynamic objects and sets them to NULL.
+  * Destructor of this class. Deletes all dynamic objects and sets them to NULL.
   */
 GPSData::~GPSData()
 {
@@ -43,7 +43,7 @@ GPSData::~GPSData()
 }
 
 /**
-  * This function reset all variables
+  * This function reset all variables.
   */
 void GPSData::resetAll()
 {
@@ -73,6 +73,7 @@ void GPSData::resetAll()
     routeStopTime = "";
     recordingStatus = false;
     roundCounter = 0;
+    distance = 0;
 }
 
 /**
@@ -104,8 +105,9 @@ void GPSData::agnss()
         longitude   = location->getLongitude(); //Returns longitude.
         altitude    = location->getAltitude();  //Returns fix altitude in meters.
         speed       = location->getSpeed();     //Returns current speed in km/h.
+        track = location->getTrack(); //Returns direction of motion in degrees(0-359).
 
-        QFile routeTempFile("routetemp.xml");//Temp xml.
+        QFile routeTempFile("/home/user/MyDocs/speedfreak/route/routetemp.xml");//Temp xml.
 
         //If GPS find 4 or more satellite and signal stregth is 30 or more.
         if (location->getSatellitesInUse() >= 4 && location->getSignalStrength() >= 30)
@@ -134,6 +136,7 @@ void GPSData::agnss()
                     if (!routeTempFile.open(QIODevice::Append | QIODevice::Text))
                         return;
 
+                    distance += location->distance_between_two_points(latitudePrevious, longitudePrevious, latitude, longitude);
                     writeRouteXml(&routeTempFile, 0);
                     roundCounter ++;
                     routeTempFile.close();
@@ -144,64 +147,58 @@ void GPSData::agnss()
 }
 
 /**
-  *This slot function is called when gprs update location.
+  * This slot function is called when gprs update location.
   */
 void GPSData::awcp()
 {
-
 }
 
 /**
-  *This slot function is called when .
+  * This slot function is called when .
   */
 void GPSData::locationUpdated()
 {
-
 }
 
 /**
-  *This slot function is called when .
+  * This slot function is called when .
   */
 void GPSData::gpsConnected()
 {
-
 }
 
 /**
-  *This slot function is called when .
+  * This slot function is called when .
   */
 void GPSData::gpsDisconnected()
 {
-
 }
 
 /**
-  *This slot function is called when .
+  * This slot function is called when .
   */
 void GPSData::gpsError()
 {
-
 }
 
 /**
-  *This slot function is called when .
+  * This slot function is called when .
   */
 void GPSData::gpsdRunning()
 {
-
 }
 
 /**
-  *This slot function is called when .
+  * This slot function is called when .
   */
 void GPSData::gpsdStopped()
 {
-
 }
 
 /**
-  *This function start route recording.
-  *@param QString time recording start time.
+  * This function start route recording.
+  *
+  * @param QString time recording start time.
   */
 void GPSData::startRouteRecording()
 {
@@ -216,8 +213,9 @@ void GPSData::startRouteRecording()
 }
 
 /**
-  *This function stop route recording.
-  *@param QString time recording stop time.
+  * This function stop route recording.
+  *
+  * @param QString time recording stop time.
   */
 void GPSData::stopRouteRecording()
 {
@@ -229,7 +227,7 @@ void GPSData::stopRouteRecording()
         recordingStatus = false;
 
         //Write final xml.
-        QFile file("route.xml");
+        QFile file("/home/user/MyDocs/speedfreak/route/route.xml");
         if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
             return;
         writeRouteXml(&file, 1);
@@ -239,13 +237,16 @@ void GPSData::stopRouteRecording()
 }
 
 /**
-  *This function write route to .xml file.
+  * This function write route to .xml file.
+  *
+  * @param QIODevice *device
+  * @param int round
   */
 void GPSData::writeRouteXml(QIODevice *device, int round)
 {
     xmlwriter.setDevice(device);
 
-    //Write temp xml (routetemp.xml).
+    //Write temp xml (/home/user/MyDocs/speedfreak/route/routetemp.xml).
     if ( round == 0 )
     {
         xmlwriter.writeStartElement("Point");
@@ -256,7 +257,7 @@ void GPSData::writeRouteXml(QIODevice *device, int round)
         xmlwriter.writeEndElement();//Point
     }
 
-    //Write final xml (route.xml).
+    //Write final xml (/home/user/MyDocs/speedfreak/route/route.xml).
     else if ( round == 1 )
     {
         xmlwriter.writeStartDocument();
@@ -266,7 +267,7 @@ void GPSData::writeRouteXml(QIODevice *device, int round)
         xmlwriter.writeAttribute("Points", QString::number(roundCounter));
 
         //Open temp xml and read points
-        QFile tempFile("routetemp.xml");
+        QFile tempFile("/home/user/MyDocs/speedfreak/route/routetemp.xml");
         if (!tempFile.open(QIODevice::ReadOnly | QIODevice::Text))
             return;
         QTextStream readRoute(&tempFile);
@@ -278,3 +279,23 @@ void GPSData::writeRouteXml(QIODevice *device, int round)
         xmlwriter.writeEndDocument();     
     }
 }
+
+/**
+  * This function returns distance traveled since recording started.
+  *
+  * @return double distance
+  */
+double GPSData::getDistanceTraveled()
+{
+    return distance;
+}
+
+/**
+  * This function returns direction of motion in degrees(0-359).
+  *
+  * @return double track
+  */
+double GPSData::getDirection()
+{
+    return track;
+}