40e2f1288551caf1417a28901e6b20af76d639b0
[speedfreak] / Client / gpsdata.cpp
1 /*
2  * GPS data
3  *
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
7  */
8
9 #include "gpsdata.h"
10
11 /**
12   *Default constructor of this class.
13   */
14 GPSData::GPSData(Maemo5Location *maemo5location)
15 {
16     location = maemo5location;
17
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()));
26 }
27
28 /**
29   *Destructor of this class. Deletes all dynamic objects and sets them to NULL.
30   */
31 GPSData::~GPSData()
32 {
33     delete location;
34     location = NULL;
35 }
36
37 void GPSData::resetAll()
38 {
39     satellitesInUse = 0;
40     satellitesInView = 0;
41     signalStrength = 0;
42     latitude = 0;
43     longitude = 0;
44     time = 0;
45     ept = 0;
46     eph = 0;
47     altitude = 0;
48     epv = 0;
49     track = 0;
50     epd = 0;
51     speed = 0;
52     eps = 0;
53     climb = 0;
54     epc = 0;
55
56     recordingStatus = false;
57     roundCounter = 0;
58 }
59
60 /**
61   *This slot function is called when GPS update location.
62   */
63 void GPSData::agnss()
64 {
65     //satellitesInUse = QString::number(location->getSatellitesInUse());  //Returns number of satellites in use.
66     //satellitesInView = QString::number(location->getSatellitesInView());//Returns number of satellites in view.
67     //signalStrength = QString::number(location->getSignalStrength());    //Returns average signal strength of satellites which are in use.
68     //gpsOnline = QString::number(location->getGpsOnline());              //Returns gsp online                     
69     //ept = QString::number(location->getEpt());                          //Returns time accuracy in seconds.
70     //eph = QString::number(location->getEph());                          //Returns horizontal position accuracy in cm.
71     //epv = QString::number(location->getEpv());                          //Returns altitude accuracy in meters.
72     //track = QString::number(location->getTrack());                      //Returns direction of motion in degrees(0-359).
73     //epd = QString::number(location->getEpd());                          //Returns track accuracy in degrees.
74     //eps = QString::number(location->getEps());                          //Returns speed accuracy in km/h.
75     //climb = QString::number(location->getClimb());                      //Returns current rate of climb in m/s.
76     //epc = QString::number(location->getEpc());                          //Returns climb accuracy in m/s.
77     //location->distance_between_two_points(double latitude_s, double longitude_s, double latitude_f, double longitude_f);
78     //time = location->getTime();//Returns timestamp of the update in seconds.
79
80     latitude    = location->getLatitude();  //Returns latitude.
81     longitude   = location->getLongitude(); //Returns longitude.
82     altitude    = location->getAltitude();  //Returns fix altitude in meters.
83     speed       = location->getSpeed();     //Returns current speed in km/h.
84
85     latitudeNow.sprintf("%.4f", latitude);  //Latitude now to string
86     longitudeNow.sprintf("%.4f", longitude);//Longitude now to string
87     latitudePrevious.sprintf("%.4f", gpsDataArray[roundCounter-1][0]);  //Previous latitude to string
88     longitudePrevious.sprintf("%.4f", gpsDataArray[roundCounter-1][1]); //Previous longitude to string
89
90     if ( recordingStatus == true )
91     {
92         if ( roundCounter == 0 || latitudeNow != latitudePrevious || longitudeNow != longitudePrevious )
93         {
94             gpsDataArray[roundCounter][0] = latitude;
95             gpsDataArray[roundCounter][1] = longitude;
96             gpsDataArray[roundCounter][2] = altitude;
97             gpsDataArray[roundCounter][3] = speed;
98             roundCounter ++;
99         }
100     }
101 }
102
103 /**
104   *This slot function is called when gprs update location.
105   */
106 void GPSData::awcp()
107 {
108
109 }
110
111 /**
112   *This slot function is called when .
113   */
114 void GPSData::locationUpdated()
115 {
116
117 }
118
119 /**
120   *This slot function is called when .
121   */
122 void GPSData::gpsConnected()
123 {
124
125 }
126
127 /**
128   *This slot function is called when .
129   */
130 void GPSData::gpsDisconnected()
131 {
132
133 }
134
135 /**
136   *This slot function is called when .
137   */
138 void GPSData::gpsError()
139 {
140
141 }
142
143 /**
144   *This slot function is called when .
145   */
146 void GPSData::gpsdRunning()
147 {
148
149 }
150
151 /**
152   *This slot function is called when .
153   */
154 void GPSData::gpsdStopped()
155 {
156
157 }
158
159 void GPSData::startRouteRecording(QString time)
160 {
161     if (recordingStatus == false)
162     {
163         routeStartTime = time;
164         recordingStatus = true;
165         roundCounter = 0;
166     }
167 }
168
169 void GPSData::stopRouteRecording(QString time)
170 {
171     routeStopTime = time;
172     saveRoute();
173     if (recordingStatus == true)
174     {
175         recordingStatus = false;
176         roundCounter = 0;
177     }
178 }
179
180 void GPSData::saveRoute()
181 {
182     QFile file("testroute.txt");
183     if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
184     {
185         return;
186     }
187     QTextStream route(&file);
188
189     route << "Start: " << routeStartTime << "\n";
190     for (int i = 0 ; i <= roundCounter ; i++)
191     {
192         route << " lat: " << gpsDataArray[i][0]
193               << " lon: " << gpsDataArray[i][1]
194               << " alt: " << gpsDataArray[i][2]
195               << " spe: " << gpsDataArray[i][3]
196               << "\n";
197     }
198     route << "Stop: " << routeStopTime << "\n";
199     file.close();
200 }
201
202 double* GPSData::getGpsDataArray()
203 {
204     return *gpsDataArray;
205 }
206
207 int GPSData::getRoundCounter()
208 {
209     return roundCounter;
210 }