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"
12 *Default constructor of this class.
13 *@param Maemo5Location pointer to public interface.
15 Maemo5LocationPrivate::Maemo5LocationPrivate(Maemo5Location* location):QObject(location)
17 //Initialize variables
21 //Get gps control object
22 control = location_gpsd_control_get_default();
24 device = (LocationGPSDevice*) g_object_new(LOCATION_TYPE_GPS_DEVICE, NULL);
26 g_signal_connect(device, "changed", G_CALLBACK(gps_data_changed), this);
27 g_signal_connect(device, "connected", G_CALLBACK(gps_connected_func), this);
28 g_signal_connect(device, "disconnected", G_CALLBACK(gps_disconnected_func), this);
30 g_signal_connect(control, "error-verbose", G_CALLBACK(gps_error_func), this);
31 g_signal_connect(control, "gpsd_running", G_CALLBACK(gpsd_running_func), this);
32 g_signal_connect(control, "gpsd_stopped", G_CALLBACK(gpsd_running_func), this);
36 *Destructor of this class. Should be used to release all allocated resources.
38 Maemo5LocationPrivate::~Maemo5LocationPrivate()
45 *This function is used to start to poll with gprs
47 void Maemo5LocationPrivate::get_acwp()
49 g_object_set(G_OBJECT(control), "preferred-method", LOCATION_METHOD_ACWP, NULL);
55 *This function starts to poll via gps interface
57 void Maemo5LocationPrivate::get_agnss()
59 g_object_set(G_OBJECT(control), "preferred-method", LOCATION_METHOD_AGNSS, NULL);
67 void Maemo5LocationPrivate::stop()
69 location_gpsd_control_stop(control);
73 *Stop and restart polling
75 void Maemo5LocationPrivate::restart()
77 location_gpsd_control_stop(control);
78 location_gpsd_control_start(control);
82 *This function is called when device managed to connect to the lcoation server.
83 *Function emits gps_connected signal.
84 *@param Pointer to LocationGPSDevice class
85 *@param Pointer to Maemo5LocationPrivate class
87 void gps_connected_func(LocationGPSDevice *device, Maemo5LocationPrivate *gps)
89 emit gps->gps_connected();
93 *This function is called when device is disconnected from the location server.
94 *Function emits gps_disconnected signal.
95 *Also this function resets all arguments of Maemo5LcoationPrivate class.
96 *@param Pointer to LocationGPSDevice class
97 *@param Pointer to Maemo5LocationPrivate class
99 void gps_disconnected_func(LocationGPSDevice *device, Maemo5LocationPrivate *gps)
102 emit gps->gps_disconnected();
106 *This function is called after the location_gpsd_control_stop has been called.
107 *@param Pointer to LocationGPSDControl class
108 *@param Pointer to Maemo5LocationPrivate class
110 void gpsd_stopped_func(LocationGPSDControl *control, Maemo5LocationPrivate *gps)
112 emit gps->gpsd_stopped();
116 *This function is called when an error has occurred.
117 *@param Pointer to LocationGPSDControl class
119 *@param Pointer to Maemo5LocationPrivate class
121 void gps_error_func(LocationGPSDControl *control, gint error, Maemo5LocationPrivate *gps)
125 case LOCATION_ERROR_USER_REJECTED_DIALOG:
126 emit gps->gps_error(0);
127 g_debug("User didn't enable requested methods");
129 case LOCATION_ERROR_USER_REJECTED_SETTINGS:
130 emit gps->gps_error(1);
131 g_debug("User changed settings, which disabled location");
133 case LOCATION_ERROR_BT_GPS_NOT_AVAILABLE:
134 emit gps->gps_error(2);
135 g_debug("Problems with BT GPS");
137 case LOCATION_ERROR_METHOD_NOT_ALLOWED_IN_OFFLINE_MODE:
138 emit gps->gps_error(3);
139 g_debug("Requested method is not allowed in offline mode");
141 case LOCATION_ERROR_SYSTEM:
142 emit gps->gps_error(4);
143 g_debug("System error");
149 *This function is called after the location_gpsd_control_start has been called.
150 *@param Pointer to LocationGPSDControl class
151 *@param Pointer to Maemo5LocationPrivate class
153 void gpsd_running_func(LocationGPSDControl *control, Maemo5LocationPrivate *gps)
155 emit gps->gpsd_running();
159 *Callback function to catch gps signals.
160 *@param Pointer to LocationGPSDControl class
161 *@param Pointer to Maemo5LocationPrivate class
163 void gps_data_changed(LocationGPSDevice *device, Maemo5LocationPrivate *gps)
165 //First check that LocationGpsDeviceFix can be found...this data structure contains the location info.
168 //Check that there are fields
169 if(gps->device->fix->fields)
171 //Store values and emit signal
172 if(gps->device->fix->fields & LOCATION_GPS_DEVICE_LATLONG_SET)
174 gps->latitude = gps->device->fix->latitude;
175 gps->longitude = gps->device->fix->longitude;
176 gps->eph = gps->device->fix->eph;
180 gps->satellites_in_use = gps->device->satellites_in_use;
181 gps->satellites_in_view = gps->device->satellites_in_view;
183 if(gps->device->fix->fields & LOCATION_GPS_DEVICE_TIME_SET)
185 gps->time = gps->device->fix->time;
186 gps->ept = gps->device->fix->ept;
189 if(gps->device->fix->fields & LOCATION_GPS_DEVICE_ALTITUDE_SET)
191 gps->altitude = gps->device->fix->altitude;
192 gps->epv = gps->device->fix->epv;
195 if(gps->device->fix->fields & LOCATION_GPS_DEVICE_TRACK_SET)
197 gps->track = gps->device->fix->track;
198 gps->epd = gps->device->fix->epd;
201 if(gps->device->fix->fields & LOCATION_GPS_DEVICE_SPEED_SET)
203 gps->speed = gps->device->fix->speed;
204 gps->eps = gps->device->fix->eps;
207 if(gps->device->fix->fields & LOCATION_GPS_DEVICE_CLIMB_SET)
209 gps->climb = gps->device->fix->climb;
210 gps->epc = gps->device->fix->epc;
214 // Calculate average signal strength of satellites in use
216 if(gps->satellites_in_use != 0)
218 for(int i=0 ; i < gps->satellites_in_use ; i++)
220 LocationGPSDeviceSatellite *view = (LocationGPSDeviceSatellite*) g_ptr_array_index (gps->device->satellites, i);
221 temp = temp + view->signal_strength;
223 gps->signal_strength = (temp / gps->satellites_in_use);
231 else if(gps->usegps == 1)
237 emit gps->locationUpdated();
245 *Resets all arguments of Maemo5LocationPrivate class.
247 void Maemo5LocationPrivate::resetAll()
252 satellites_in_view = 0;
253 satellites_in_use = 0;
267 *Returns distance between two points in kilometers.
268 *@param latitude of first point
269 *@param longitude of first point
270 *@param latitude of second point
271 *@param longitude of second point
273 double Maemo5LocationPrivate::distance_between_two_points(double latitude_s, double longitude_s, double latitude_f, double longitude_f)
276 return distance = location_distance_between(latitude_s, longitude_s, latitude_f, longitude_f);