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;
79 *This slot function is called when GPS update location.
83 //satellitesInUse = location->getSatellitesInUse()); //Returns number of satellites in use.
84 //satellitesInView = location->getSatellitesInView(); //Returns number of satellites in view.
85 //signalStrength = location->getSignalStrength(); //Returns average signal strength of satellites which are in use.
86 //gpsOnline = location->getGpsOnline(); //Returns gsp online
87 //ept = location->getEpt(); //Returns time accuracy in seconds.
88 //eph = location->getEph(); //Returns horizontal position accuracy in cm.
89 //track = location->getTrack(); //Returns direction of motion in degrees(0-359).
90 //epd = location->getEpd(); //Returns track accuracy in degrees.
91 //climb = location->getClimb(); //Returns current rate of climb in m/s.
92 //epc = location->getEpc(); //Returns climb accuracy in m/s.
93 //time = location->getTime(); //Returns timestamp of the update in seconds.
94 //epv = location->getEpv(); //Returns altitude accuracy in meters.
95 //eps = location->getEps(); //Returns speed accuracy in km/h.
96 //distance = location->distance_between_two_points(double latitude_s, double longitude_s, double latitude_f, double longitude_f);
98 //If route recording true
99 if ( recordingStatus == true )
101 latitudePrevious = latitude;
102 longitudePrevious = longitude;
103 latitude = location->getLatitude(); //Returns latitude.
104 longitude = location->getLongitude(); //Returns longitude.
105 altitude = location->getAltitude(); //Returns fix altitude in meters.
106 speed = location->getSpeed(); //Returns current speed in km/h.
108 QFile routeTempFile("routetemp.xml");//Temp xml.
110 //If GPS find 4 or more satellite and signal stregth is 30 or more.
111 if (location->getSatellitesInUse() >= 4 && location->getSignalStrength() >= 30)
114 if (roundCounter == 0)
116 if (!routeTempFile.open(QIODevice::WriteOnly | QIODevice::Text))
118 writeRouteXml(&routeTempFile, 0);
119 routeTempFile.close();
123 //Points writing round.
126 sLatitudeNow.sprintf("%.4f", latitude); //Latitude now to string
127 sLongitudeNow.sprintf("%.4f", longitude);//Longitude now to string
128 sLatitudePrevious.sprintf("%.4f", latitudePrevious); //Previous latitude to string
129 sLongitudePrevious.sprintf("%.4f", longitudePrevious); //Previous longitude to string
131 //If latitude or longitude change
132 if ( sLatitudeNow != sLatitudePrevious || sLongitudeNow != sLongitudePrevious )
134 if (!routeTempFile.open(QIODevice::Append | QIODevice::Text))
137 writeRouteXml(&routeTempFile, 0);
139 routeTempFile.close();
147 *This slot function is called when gprs update location.
155 *This slot function is called when .
157 void GPSData::locationUpdated()
163 *This slot function is called when .
165 void GPSData::gpsConnected()
171 *This slot function is called when .
173 void GPSData::gpsDisconnected()
179 *This slot function is called when .
181 void GPSData::gpsError()
187 *This slot function is called when .
189 void GPSData::gpsdRunning()
195 *This slot function is called when .
197 void GPSData::gpsdStopped()
203 *This function start route recording.
204 *@param QString time recording start time.
206 void GPSData::startRouteRecording()
208 if (recordingStatus == false)
210 //Get start time and start recording.
211 gpsDateTime->setTime_t(location->getTime());
212 routeStartTime = gpsDateTime->toString("dd.MM.yyyy hh:mm:ss");
213 recordingStatus = true;
219 *This function stop route recording.
220 *@param QString time recording stop time.
222 void GPSData::stopRouteRecording()
224 if (recordingStatus == true)
226 //Get stop time and stop recording.
227 gpsDateTime->setTime_t(location->getTime());
228 routeStopTime = gpsDateTime->toString("dd.MM.yyyy hh:mm:ss");
229 recordingStatus = false;
232 QFile file("route.xml");
233 if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
235 writeRouteXml(&file, 1);
242 *This function write route to .xml file.
244 void GPSData::writeRouteXml(QIODevice *device, int round)
246 xmlwriter.setDevice(device);
248 //Write temp xml (routetemp.xml).
251 xmlwriter.writeStartElement("Point");
252 xmlwriter.writeAttribute("Latitude", QString::number(latitude));
253 xmlwriter.writeAttribute("Longitude", QString::number(longitude));
254 xmlwriter.writeAttribute("Altitude", QString::number(altitude));
255 xmlwriter.writeAttribute("Speed", QString::number(speed));
256 xmlwriter.writeEndElement();//Point
259 //Write final xml (route.xml).
260 else if ( round == 1 )
262 xmlwriter.writeStartDocument();
263 xmlwriter.writeStartElement("Route");
264 xmlwriter.writeAttribute("Start-time", routeStartTime);
265 xmlwriter.writeAttribute("Stop-time", routeStopTime);
266 xmlwriter.writeAttribute("Points", QString::number(roundCounter));
268 //Open temp xml and read points
269 QFile tempFile("routetemp.xml");
270 if (!tempFile.open(QIODevice::ReadOnly | QIODevice::Text))
272 QTextStream readRoute(&tempFile);
273 QTextStream writeRoute(device);
274 writeRoute << readRoute.readLine();
275 tempFile.close();//Close temp xml
277 xmlwriter.writeEndElement();//Route
278 xmlwriter.writeEndDocument();