X-Git-Url: http://git.maemo.org/git/?p=speedfreak;a=blobdiff_plain;f=Client%2Fgpsdata.cpp;h=f0f53eb3816f1abe5bfa83669f7c196811c6a8d9;hp=457e609deda85fb9fd072ac33fe6e2d5bc091fc1;hb=16f76b90231274365c45d9efa6d662a819ac525d;hpb=8cd96a1b5263df9359b602a63743edf1ca32941b diff --git a/Client/gpsdata.cpp b/Client/gpsdata.cpp index 457e609..f0f53eb 100644 --- a/Client/gpsdata.cpp +++ b/Client/gpsdata.cpp @@ -7,12 +7,14 @@ */ #include "gpsdata.h" +#include /** - *Default constructor of this class. + * Default constructor of this class. */ GPSData::GPSData(Maemo5Location *maemo5location) { + qDebug() << "__GPSData"; location = maemo5location; connect(location,SIGNAL(agnss()),this,SLOT(agnss())); @@ -24,22 +26,25 @@ GPSData::GPSData(Maemo5Location *maemo5location) connect(location,SIGNAL(gpsd_running()),this,SLOT(gpsdRunning())); connect(location,SIGNAL(gpsd_stopped()),this,SLOT(gpsdStopped())); - gpsTimer = new QTimer(); - gpsTimeMS = 0; - connect(gpsTimer, SIGNAL(timeout()),this, SLOT(gpsTimerTimeout())); - + gpsDateTime = new QDateTime(); resetAll(); } /** - *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() { - delete location; + qDebug() << "__~GPSData"; location = NULL; + + if(gpsDateTime) + delete gpsDateTime; } +/** + * This function reset all variables. + */ void GPSData::resetAll() { satellitesInUse = 0; @@ -58,9 +63,17 @@ void GPSData::resetAll() eps = 0; climb = 0; epc = 0; - + latitudePrevious = 0; + longitudePrevious = 0; + sLatitudeNow = ""; + sLongitudeNow = ""; + sLatitudePrevious = ""; + sLongitudePrevious = ""; + routeStartTime = ""; + routeStopTime = ""; recordingStatus = false; roundCounter = 0; + distance = 0; } /** @@ -68,212 +81,221 @@ void GPSData::resetAll() */ void GPSData::agnss() { - //satellitesInUse = QString::number(location->getSatellitesInUse()); //Returns number of satellites in use. - //satellitesInView = QString::number(location->getSatellitesInView());//Returns number of satellites in view. - //signalStrength = QString::number(location->getSignalStrength()); //Returns average signal strength of satellites which are in use. - //gpsOnline = QString::number(location->getGpsOnline()); //Returns gsp online - //ept = QString::number(location->getEpt()); //Returns time accuracy in seconds. - //eph = QString::number(location->getEph()); //Returns horizontal position accuracy in cm. - //track = QString::number(location->getTrack()); //Returns direction of motion in degrees(0-359). - //epd = QString::number(location->getEpd()); //Returns track accuracy in degrees. - //climb = QString::number(location->getClimb()); //Returns current rate of climb in m/s. - //epc = QString::number(location->getEpc()); //Returns climb accuracy in m/s. - //location->distance_between_two_points(double latitude_s, double longitude_s, double latitude_f, double longitude_f); - //time = location->getTime();//Returns timestamp of the update in seconds. + //satellitesInUse = location->getSatellitesInUse()); //Returns number of satellites in use. + //satellitesInView = location->getSatellitesInView(); //Returns number of satellites in view. + //signalStrength = location->getSignalStrength(); //Returns average signal strength of satellites which are in use. + //gpsOnline = location->getGpsOnline(); //Returns gsp online + //ept = location->getEpt(); //Returns time accuracy in seconds. + //eph = location->getEph(); //Returns horizontal position accuracy in cm. + //track = location->getTrack(); //Returns direction of motion in degrees(0-359). + //epd = location->getEpd(); //Returns track accuracy in degrees. + //climb = location->getClimb(); //Returns current rate of climb in m/s. + //epc = location->getEpc(); //Returns climb accuracy in m/s. + //time = location->getTime(); //Returns timestamp of the update in seconds. + //epv = location->getEpv(); //Returns altitude accuracy in meters. + //eps = location->getEps(); //Returns speed accuracy in km/h. + //distance = location->distance_between_two_points(double latitude_s, double longitude_s, double latitude_f, double longitude_f); //If route recording true if ( recordingStatus == true ) { + latitudePrevious = latitude; + longitudePrevious = longitude; latitude = location->getLatitude(); //Returns latitude. longitude = location->getLongitude(); //Returns longitude. altitude = location->getAltitude(); //Returns fix altitude in meters. - epv = location->getEpv(); //Returns altitude accuracy in meters. speed = location->getSpeed(); //Returns current speed in km/h. - eps = location->getEps(); //Returns speed accuracy in km/h. + track = location->getTrack(); //Returns direction of motion in degrees(0-359). - gpsTimer->start(1); + QFile routeTempFile("/home/user/MyDocs/speedfreak/route/routetemp.xml");//Temp xml. - //If first round - if (roundCounter == 0) + //If GPS find 4 or more satellite and signal stregth is 30 or more. + if (location->getSatellitesInUse() >= 4 && location->getSignalStrength() >= 30) { - saveRoute(); - } - - else - { - latitudeNow.sprintf("%.4f", latitude); //Latitude now to string - longitudeNow.sprintf("%.4f", longitude);//Longitude now to string - latitudePrevious.sprintf("%.4f", gpsDataArray[0]); //Previous latitude to string - longitudePrevious.sprintf("%.4f", gpsDataArray[1]); //Previous longitude to string + //If first round + if (roundCounter == 0) + { + if (!routeTempFile.open(QIODevice::WriteOnly | QIODevice::Text)) + return; + writeRouteXml(&routeTempFile, 0); + routeTempFile.close(); + roundCounter ++; + } - //If latitude or longitude change - if ( latitudeNow != latitudePrevious || longitudeNow != longitudePrevious ) + //Points writing round. + else { - saveRoute(); + sLatitudeNow.sprintf("%.4f", latitude); //Latitude now to string + sLongitudeNow.sprintf("%.4f", longitude);//Longitude now to string + sLatitudePrevious.sprintf("%.4f", latitudePrevious); //Previous latitude to string + sLongitudePrevious.sprintf("%.4f", longitudePrevious); //Previous longitude to string + + //If latitude or longitude change + if ( sLatitudeNow != sLatitudePrevious || sLongitudeNow != sLongitudePrevious ) + { + if (!routeTempFile.open(QIODevice::Append | QIODevice::Text)) + return; + + distance += location->distance_between_two_points(latitudePrevious, longitudePrevious, latitude, longitude); + writeRouteXml(&routeTempFile, 0); + roundCounter ++; + routeTempFile.close(); + } } } } } /** - *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(QString time) +void GPSData::startRouteRecording() { if (recordingStatus == false) { - routeStartTime = time; + //Get start time and start recording. + gpsDateTime->setTime_t(location->getTime()); + routeStartTime = gpsDateTime->toString("dd.MM.yyyy hh:mm:ss"); recordingStatus = true; roundCounter = 0; } } /** - *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(QString time) +void GPSData::stopRouteRecording() { if (recordingStatus == true) { - routeStopTime = time; + //Get stop time and stop recording. + gpsDateTime->setTime_t(location->getTime()); + routeStopTime = gpsDateTime->toString("dd.MM.yyyy hh:mm:ss"); recordingStatus = false; + + //Write final xml. + QFile file("/home/user/MyDocs/speedfreak/route/route.xml"); + if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) + return; + writeRouteXml(&file, 1); + file.close(); roundCounter = 0; - saveRoute(); } } /** - *This slot function is called when gps timer timeout(10s). + * This function write route to .xml file. + * + * @param QIODevice *device + * @param int round */ -void GPSData::gpsTimerTimeout() +void GPSData::writeRouteXml(QIODevice *device, int round) { - gpsTimeMS++; -} - -/** - *This function save route to .txt file. - */ -void GPSData::saveRoute() -{ - QFile file("route" + routeStartTime + ".txt"); - QTextStream route(&file); + xmlwriter.setDevice(device); - if ( recordingStatus == true ) + //Write temp xml (/home/user/MyDocs/speedfreak/route/routetemp.xml). + if ( round == 0 ) { - //First round. - if ( roundCounter == 0 ) - { - if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) - return; - - route << "Start: " << routeStartTime << "\n"; - } - - else - { - if (!file.open(QIODevice::Append | QIODevice::Text)) - return; - } - - gpsDataArray[0] = latitude; - gpsDataArray[1] = longitude; - gpsDataArray[2] = altitude; - gpsDataArray[3] = speed; - roundCounter ++; - - route << " la: " << latitude - << " \t lo: " << longitude - << " \t al: " << altitude - << " \t epv: " << epv - << " \t sp: " << speed - << " \t eps: " << eps - << " \t ms: " << gpsTimeMS - << "\n"; - - gpsTimeMS = 0; - file.close(); + xmlwriter.writeStartElement("Point"); + xmlwriter.writeAttribute("Latitude", QString::number(latitude)); + xmlwriter.writeAttribute("Longitude", QString::number(longitude)); + xmlwriter.writeAttribute("Altitude", QString::number(altitude)); + xmlwriter.writeAttribute("Speed", QString::number(speed)); + xmlwriter.writeEndElement();//Point } - //Final round. - else + //Write final xml (/home/user/MyDocs/speedfreak/route/route.xml). + else if ( round == 1 ) { - if (!file.open(QIODevice::Append | QIODevice::Text)) + xmlwriter.writeStartDocument(); + xmlwriter.writeStartElement("Route"); + xmlwriter.writeAttribute("Start-time", routeStartTime); + xmlwriter.writeAttribute("Stop-time", routeStopTime); + xmlwriter.writeAttribute("Points", QString::number(roundCounter)); + + //Open temp xml and read points + QFile tempFile("/home/user/MyDocs/speedfreak/route/routetemp.xml"); + if (!tempFile.open(QIODevice::ReadOnly | QIODevice::Text)) return; - route << "Stop: " << routeStopTime << "\n"; - file.close(); + QTextStream readRoute(&tempFile); + QTextStream writeRoute(device); + writeRoute << readRoute.readLine(); + tempFile.close();//Close temp xml + + xmlwriter.writeEndElement();//Route + xmlwriter.writeEndDocument(); } } /** - *@return Pointer to gpsDataArray[][]. + * This function returns distance traveled since recording started. + * + * @return double distance */ -double* GPSData::getGpsDataArray() +double GPSData::getDistanceTraveled() { - return *gpsDataArray; + return distance; } /** - *@return RoundCounter, the number of gpsDataArray[][] rows. + * This function returns direction of motion in degrees(0-359). + * + * @return double track */ -int GPSData::getRoundCounter() +double GPSData::getDirection() { - return roundCounter; + return track; }