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
12 *Default constructor of this class.
14 GPSData::GPSData(Maemo5Location *maemo5location)
16 location = maemo5location;
18 connect(location,SIGNAL(agnss()),this,SLOT(agnss()));
19 connect(location,SIGNAL(awcp()),this,SLOT(awcp()));
20 connect(location,SIGNAL(locationUpdated()),this,SLOT(locationUpdated()));
21 connect(location,SIGNAL(gps_connected()),this,SLOT(gpsConnected()));
22 connect(location,SIGNAL(gps_disconnected()),this,SLOT(gpsDisconnected()));
23 connect(location,SIGNAL(gps_error(int)),this,SLOT(gpsError()));
24 connect(location,SIGNAL(gpsd_running()),this,SLOT(gpsdRunning()));
25 connect(location,SIGNAL(gpsd_stopped()),this,SLOT(gpsdStopped()));
27 gpsDateTime = new QDateTime();
32 *Destructor of this class. Deletes all dynamic objects and sets them to NULL.
40 void GPSData::resetAll()
59 longitudePrevious = 0;
62 sLatitudePrevious = "";
63 sLongitudePrevious = "";
66 recordingStatus = false;
71 *This slot function is called when GPS update location.
75 //satellitesInUse = location->getSatellitesInUse()); //Returns number of satellites in use.
76 //satellitesInView = location->getSatellitesInView(); //Returns number of satellites in view.
77 //signalStrength = location->getSignalStrength(); //Returns average signal strength of satellites which are in use.
78 //gpsOnline = location->getGpsOnline(); //Returns gsp online
79 //ept = location->getEpt(); //Returns time accuracy in seconds.
80 //eph = location->getEph(); //Returns horizontal position accuracy in cm.
81 //track = location->getTrack(); //Returns direction of motion in degrees(0-359).
82 //epd = location->getEpd(); //Returns track accuracy in degrees.
83 //climb = location->getClimb(); //Returns current rate of climb in m/s.
84 //epc = location->getEpc(); //Returns climb accuracy in m/s.
85 //time = location->getTime(); //Returns timestamp of the update in seconds.
86 //epv = location->getEpv(); //Returns altitude accuracy in meters.
87 //eps = location->getEps(); //Returns speed accuracy in km/h.
88 //distance = location->distance_between_two_points(double latitude_s, double longitude_s, double latitude_f, double longitude_f);
90 //If route recording true
91 if ( recordingStatus == true )
93 latitudePrevious = latitude;
94 longitudePrevious = longitude;
95 latitude = location->getLatitude(); //Returns latitude.
96 longitude = location->getLongitude(); //Returns longitude.
97 altitude = location->getAltitude(); //Returns fix altitude in meters.
98 speed = location->getSpeed(); //Returns current speed in km/h.
100 QFile routeTempFile("routetemp.xml");//Temp xml.
103 if (roundCounter == 0)
105 if (!routeTempFile.open(QIODevice::WriteOnly | QIODevice::Text))
107 writeRouteXml(&routeTempFile, 0);
108 routeTempFile.close();
112 //Points writing round.
115 sLatitudeNow.sprintf("%.4f", latitude); //Latitude now to string
116 sLongitudeNow.sprintf("%.4f", longitude);//Longitude now to string
117 sLatitudePrevious.sprintf("%.4f", latitudePrevious); //Previous latitude to string
118 sLongitudePrevious.sprintf("%.4f", longitudePrevious); //Previous longitude to string
120 //If latitude or longitude change
121 if ( sLatitudeNow != sLatitudePrevious || sLongitudeNow != sLongitudePrevious )
123 if (!routeTempFile.open(QIODevice::Append | QIODevice::Text))
126 writeRouteXml(&routeTempFile, 0);
128 routeTempFile.close();
135 *This slot function is called when gprs update location.
143 *This slot function is called when .
145 void GPSData::locationUpdated()
151 *This slot function is called when .
153 void GPSData::gpsConnected()
159 *This slot function is called when .
161 void GPSData::gpsDisconnected()
167 *This slot function is called when .
169 void GPSData::gpsError()
175 *This slot function is called when .
177 void GPSData::gpsdRunning()
183 *This slot function is called when .
185 void GPSData::gpsdStopped()
191 *This function start route recording.
192 *@param QString time recording start time.
194 void GPSData::startRouteRecording()
196 if (recordingStatus == false)
198 //Get start time and start recording.
199 gpsDateTime->setTime_t(location->getTime());
200 routeStartTime = gpsDateTime->toString("dd.MM.yyyy hh:mm:ss");
201 recordingStatus = true;
207 *This function stop route recording.
208 *@param QString time recording stop time.
210 void GPSData::stopRouteRecording()
212 if (recordingStatus == true)
214 //Get stop time and stop recording.
215 gpsDateTime->setTime_t(location->getTime());
216 routeStopTime = gpsDateTime->toString("dd.MM.yyyy hh:mm:ss");
217 recordingStatus = false;
220 QFile file("route.xml");
221 if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
223 writeRouteXml(&file, 1);
230 *This function write route to .xml file.
232 void GPSData::writeRouteXml(QIODevice *device, int round)
234 xmlwriter.setDevice(device);
236 //Write temp xml (routetemp.xml).
239 xmlwriter.writeStartElement("Point");
240 xmlwriter.writeAttribute("Latitude", QString::number(latitude));
241 xmlwriter.writeAttribute("Longitude", QString::number(longitude));
242 xmlwriter.writeAttribute("Altitude", QString::number(altitude));
243 xmlwriter.writeAttribute("Speed", QString::number(speed));
244 xmlwriter.writeEndElement();//Point
247 //Write final xml (route.xml).
248 else if ( round == 1 )
250 xmlwriter.writeStartDocument();
251 xmlwriter.writeStartElement("Route");
252 xmlwriter.writeAttribute("Start-time", routeStartTime);
253 xmlwriter.writeAttribute("Stop-time", routeStopTime);
254 xmlwriter.writeAttribute("Points", QString::number(roundCounter));
256 //Open temp xml and read points
257 QFile tempFile("routetemp.xml");
258 if (!tempFile.open(QIODevice::ReadOnly | QIODevice::Text))
260 QTextStream readRoute(&tempFile);
261 QTextStream writeRoute(device);
262 writeRoute << readRoute.readLine();
263 tempFile.close();//Close temp xml
265 xmlwriter.writeEndElement();//Route
266 xmlwriter.writeEndDocument();