2 * Maemo5LocationPrivate
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
9 #include "maemo5locationprivate.h"
13 *Default constructor of this class.
14 *@param Maemo5Location pointer to public interface.
16 Maemo5LocationPrivate::Maemo5LocationPrivate(Maemo5Location* location):QObject(location)
18 qDebug() << "__Maemo5LocationPrivate";
19 //Initialize variables
23 //Get gps control object
25 control = location_gpsd_control_get_default();
28 device = (LocationGPSDevice*) g_object_new(LOCATION_TYPE_GPS_DEVICE, NULL);
30 g_signal_connect(device, "changed", G_CALLBACK(gps_data_changed), this);
31 g_signal_connect(device, "connected", G_CALLBACK(gps_connected_func), this);
32 g_signal_connect(device, "disconnected", G_CALLBACK(gps_disconnected_func), this);
34 g_signal_connect(control, "error-verbose", G_CALLBACK(gps_error_func), this);
35 g_signal_connect(control, "gpsd_running", G_CALLBACK(gpsd_running_func), this);
36 g_signal_connect(control, "gpsd_stopped", G_CALLBACK(gpsd_running_func), this);
40 *Destructor of this class. Should be used to release all allocated resources.
42 Maemo5LocationPrivate::~Maemo5LocationPrivate()
44 qDebug() << "__~Maemo5LocationPrivate";
50 *This function is used to start to poll with gprs
52 void Maemo5LocationPrivate::get_acwp()
54 g_object_set(G_OBJECT(control), "preferred-method", LOCATION_METHOD_ACWP, NULL);
60 *This function starts to poll via gps interface
62 void Maemo5LocationPrivate::get_agnss()
64 g_object_set(G_OBJECT(control), "preferred-method", LOCATION_METHOD_AGNSS, NULL);
72 void Maemo5LocationPrivate::stop()
74 location_gpsd_control_stop(control);
78 *Stop and restart polling
80 void Maemo5LocationPrivate::restart()
82 location_gpsd_control_stop(control);
83 location_gpsd_control_start(control);
87 *This function is called when device managed to connect to the lcoation server.
88 *Function emits gps_connected signal.
89 *@param Pointer to LocationGPSDevice class
90 *@param Pointer to Maemo5LocationPrivate class
92 void gps_connected_func(LocationGPSDevice *device, Maemo5LocationPrivate *gps)
94 emit gps->gps_connected();
98 *This function is called when device is disconnected from the location server.
99 *Function emits gps_disconnected signal.
100 *Also this function resets all arguments of Maemo5LcoationPrivate class.
101 *@param Pointer to LocationGPSDevice class
102 *@param Pointer to Maemo5LocationPrivate class
104 void gps_disconnected_func(LocationGPSDevice *device, Maemo5LocationPrivate *gps)
107 emit gps->gps_disconnected();
111 *This function is called after the location_gpsd_control_stop has been called.
112 *@param Pointer to LocationGPSDControl class
113 *@param Pointer to Maemo5LocationPrivate class
115 void gpsd_stopped_func(LocationGPSDControl *control, Maemo5LocationPrivate *gps)
117 emit gps->gpsd_stopped();
121 *This function is called when an error has occurred.
122 *@param Pointer to LocationGPSDControl class
124 *@param Pointer to Maemo5LocationPrivate class
126 void gps_error_func(LocationGPSDControl *control, gint error, Maemo5LocationPrivate *gps)
130 case LOCATION_ERROR_USER_REJECTED_DIALOG:
131 emit gps->gps_error(0);
132 g_debug("User didn't enable requested methods");
134 case LOCATION_ERROR_USER_REJECTED_SETTINGS:
135 emit gps->gps_error(1);
136 g_debug("User changed settings, which disabled location");
138 case LOCATION_ERROR_BT_GPS_NOT_AVAILABLE:
139 emit gps->gps_error(2);
140 g_debug("Problems with BT GPS");
142 case LOCATION_ERROR_METHOD_NOT_ALLOWED_IN_OFFLINE_MODE:
143 emit gps->gps_error(3);
144 g_debug("Requested method is not allowed in offline mode");
146 case LOCATION_ERROR_SYSTEM:
147 emit gps->gps_error(4);
148 g_debug("System error");
154 *This function is called after the location_gpsd_control_start has been called.
155 *@param Pointer to LocationGPSDControl class
156 *@param Pointer to Maemo5LocationPrivate class
158 void gpsd_running_func(LocationGPSDControl *control, Maemo5LocationPrivate *gps)
160 emit gps->gpsd_running();
164 *Callback function to catch gps signals.
165 *@param Pointer to LocationGPSDControl class
166 *@param Pointer to Maemo5LocationPrivate class
168 void gps_data_changed(LocationGPSDevice *device, Maemo5LocationPrivate *gps)
170 //First check that LocationGpsDeviceFix can be found...this data structure contains the location info.
173 //Check that there are fields
174 if(gps->device->fix->fields)
176 //Store values and emit signal
177 if(gps->device->fix->fields & LOCATION_GPS_DEVICE_LATLONG_SET)
179 gps->latitude = gps->device->fix->latitude;
180 gps->longitude = gps->device->fix->longitude;
181 gps->eph = gps->device->fix->eph;
185 gps->satellites_in_use = gps->device->satellites_in_use;
186 gps->satellites_in_view = gps->device->satellites_in_view;
188 if(gps->device->fix->fields & LOCATION_GPS_DEVICE_TIME_SET)
190 gps->time = gps->device->fix->time;
191 gps->ept = gps->device->fix->ept;
194 if(gps->device->fix->fields & LOCATION_GPS_DEVICE_ALTITUDE_SET)
196 gps->altitude = gps->device->fix->altitude;
197 gps->epv = gps->device->fix->epv;
200 if(gps->device->fix->fields & LOCATION_GPS_DEVICE_TRACK_SET)
202 gps->track = gps->device->fix->track;
203 gps->epd = gps->device->fix->epd;
206 if(gps->device->fix->fields & LOCATION_GPS_DEVICE_SPEED_SET)
208 gps->speed = gps->device->fix->speed;
209 gps->eps = gps->device->fix->eps;
212 if(gps->device->fix->fields & LOCATION_GPS_DEVICE_CLIMB_SET)
214 gps->climb = gps->device->fix->climb;
215 gps->epc = gps->device->fix->epc;
219 // Calculate average signal strength of satellites in use
221 if(gps->satellites_in_use != 0)
223 for(int i=0 ; i < gps->satellites_in_use ; i++)
225 LocationGPSDeviceSatellite *view = (LocationGPSDeviceSatellite*) g_ptr_array_index (gps->device->satellites, i);
226 temp = temp + view->signal_strength;
228 gps->signal_strength = (temp / gps->satellites_in_use);
236 else if(gps->usegps == 1)
242 emit gps->locationUpdated();
250 *Resets all arguments of Maemo5LocationPrivate class.
252 void Maemo5LocationPrivate::resetAll()
257 satellites_in_view = 0;
258 satellites_in_use = 0;
272 *Returns distance between two points in kilometers.
273 *@param latitude of first point
274 *@param longitude of first point
275 *@param latitude of second point
276 *@param longitude of second point
278 double Maemo5LocationPrivate::distance_between_two_points(double latitude_s, double longitude_s, double latitude_f, double longitude_f)
281 return distance = location_distance_between(latitude_s, longitude_s, latitude_f, longitude_f);