4 * @author Toni Jussila <toni.jussila@fudeco.com>
5 * @copyright (c) 2010 Speed Freak team
6 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
13 *Default constructor of this class.
15 GPSData::GPSData(Maemo5Location *maemo5location)
17 qDebug() << "__GPSData";
18 location = maemo5location;
20 connect(location,SIGNAL(agnss()),this,SLOT(agnss()));
21 connect(location,SIGNAL(awcp()),this,SLOT(awcp()));
22 connect(location,SIGNAL(locationUpdated()),this,SLOT(locationUpdated()));
23 connect(location,SIGNAL(gps_connected()),this,SLOT(gpsConnected()));
24 connect(location,SIGNAL(gps_disconnected()),this,SLOT(gpsDisconnected()));
25 connect(location,SIGNAL(gps_error(int)),this,SLOT(gpsError()));
26 connect(location,SIGNAL(gpsd_running()),this,SLOT(gpsdRunning()));
27 connect(location,SIGNAL(gpsd_stopped()),this,SLOT(gpsdStopped()));
29 gpsDateTime = new QDateTime();
34 *Destructor of this class. Deletes all dynamic objects and sets them to NULL.
38 qDebug() << "__~GPSData";
46 * This function reset all variables
48 void GPSData::resetAll()
67 longitudePrevious = 0;
70 sLatitudePrevious = "";
71 sLongitudePrevious = "";
74 recordingStatus = false;
80 *This slot function is called when GPS update location.
84 //satellitesInUse = location->getSatellitesInUse()); //Returns number of satellites in use.
85 //satellitesInView = location->getSatellitesInView(); //Returns number of satellites in view.
86 //signalStrength = location->getSignalStrength(); //Returns average signal strength of satellites which are in use.
87 //gpsOnline = location->getGpsOnline(); //Returns gsp online
88 //ept = location->getEpt(); //Returns time accuracy in seconds.
89 //eph = location->getEph(); //Returns horizontal position accuracy in cm.
90 //track = location->getTrack(); //Returns direction of motion in degrees(0-359).
91 //epd = location->getEpd(); //Returns track accuracy in degrees.
92 //climb = location->getClimb(); //Returns current rate of climb in m/s.
93 //epc = location->getEpc(); //Returns climb accuracy in m/s.
94 //time = location->getTime(); //Returns timestamp of the update in seconds.
95 //epv = location->getEpv(); //Returns altitude accuracy in meters.
96 //eps = location->getEps(); //Returns speed accuracy in km/h.
97 //distance = location->distance_between_two_points(double latitude_s, double longitude_s, double latitude_f, double longitude_f);
99 //If route recording true
100 if ( recordingStatus == true )
102 latitudePrevious = latitude;
103 longitudePrevious = longitude;
104 latitude = location->getLatitude(); //Returns latitude.
105 longitude = location->getLongitude(); //Returns longitude.
106 altitude = location->getAltitude(); //Returns fix altitude in meters.
107 speed = location->getSpeed(); //Returns current speed in km/h.
109 QFile routeTempFile("routetemp.xml");//Temp xml.
111 //If GPS find 4 or more satellite and signal stregth is 30 or more.
112 if (location->getSatellitesInUse() >= 4 && location->getSignalStrength() >= 30)
115 if (roundCounter == 0)
117 if (!routeTempFile.open(QIODevice::WriteOnly | QIODevice::Text))
119 writeRouteXml(&routeTempFile, 0);
120 routeTempFile.close();
124 //Points writing round.
127 sLatitudeNow.sprintf("%.4f", latitude); //Latitude now to string
128 sLongitudeNow.sprintf("%.4f", longitude);//Longitude now to string
129 sLatitudePrevious.sprintf("%.4f", latitudePrevious); //Previous latitude to string
130 sLongitudePrevious.sprintf("%.4f", longitudePrevious); //Previous longitude to string
132 //If latitude or longitude change
133 if ( sLatitudeNow != sLatitudePrevious || sLongitudeNow != sLongitudePrevious )
135 if (!routeTempFile.open(QIODevice::Append | QIODevice::Text))
138 distance += location->distance_between_two_points(latitudePrevious, longitudePrevious, latitude, longitude);
139 writeRouteXml(&routeTempFile, 0);
141 routeTempFile.close();
149 *This slot function is called when gprs update location.
157 *This slot function is called when .
159 void GPSData::locationUpdated()
165 *This slot function is called when .
167 void GPSData::gpsConnected()
173 *This slot function is called when .
175 void GPSData::gpsDisconnected()
181 *This slot function is called when .
183 void GPSData::gpsError()
189 *This slot function is called when .
191 void GPSData::gpsdRunning()
197 *This slot function is called when .
199 void GPSData::gpsdStopped()
205 *This function start route recording.
206 *@param QString time recording start time.
208 void GPSData::startRouteRecording()
210 if (recordingStatus == false)
212 //Get start time and start recording.
213 gpsDateTime->setTime_t(location->getTime());
214 routeStartTime = gpsDateTime->toString("dd.MM.yyyy hh:mm:ss");
215 recordingStatus = true;
221 *This function stop route recording.
222 *@param QString time recording stop time.
224 void GPSData::stopRouteRecording()
226 if (recordingStatus == true)
228 //Get stop time and stop recording.
229 gpsDateTime->setTime_t(location->getTime());
230 routeStopTime = gpsDateTime->toString("dd.MM.yyyy hh:mm:ss");
231 recordingStatus = false;
234 QFile file("route.xml");
235 if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
237 writeRouteXml(&file, 1);
244 *This function write route to .xml file.
246 void GPSData::writeRouteXml(QIODevice *device, int round)
248 xmlwriter.setDevice(device);
250 //Write temp xml (routetemp.xml).
253 xmlwriter.writeStartElement("Point");
254 xmlwriter.writeAttribute("Latitude", QString::number(latitude));
255 xmlwriter.writeAttribute("Longitude", QString::number(longitude));
256 xmlwriter.writeAttribute("Altitude", QString::number(altitude));
257 xmlwriter.writeAttribute("Speed", QString::number(speed));
258 xmlwriter.writeEndElement();//Point
261 //Write final xml (route.xml).
262 else if ( round == 1 )
264 xmlwriter.writeStartDocument();
265 xmlwriter.writeStartElement("Route");
266 xmlwriter.writeAttribute("Start-time", routeStartTime);
267 xmlwriter.writeAttribute("Stop-time", routeStopTime);
268 xmlwriter.writeAttribute("Points", QString::number(roundCounter));
270 //Open temp xml and read points
271 QFile tempFile("routetemp.xml");
272 if (!tempFile.open(QIODevice::ReadOnly | QIODevice::Text))
274 QTextStream readRoute(&tempFile);
275 QTextStream writeRoute(device);
276 writeRoute << readRoute.readLine();
277 tempFile.close();//Close temp xml
279 xmlwriter.writeEndElement();//Route
280 xmlwriter.writeEndDocument();
285 *This function returns distance traveled since recording started.
287 double GPSData::getDistanceTraveled()