-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgpsinfo.cpp
64 lines (54 loc) · 1.09 KB
/
gpsinfo.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
* This class watches the GPS and fires a dispatcher when there's new data. Mainly used for speedo.
*/
#include "gpsinfo.h"
using namespace std;
GpsInfo::GpsInfo()
: thread(0)
{
thread = Glib::Thread::create(sigc::mem_fun(*this, &GpsInfo::watch), true);
}
void GpsInfo::watch()
{
// Start the GPS
gpsmm gps_rec("localhost", DEFAULT_GPSD_PORT);
if (gps_rec.stream(WATCH_ENABLE|WATCH_JSON) == NULL)
{
cout << "No GPSD running." << endl;
return;
}
bool running = true;
while (running)
{
struct gps_data_t* newdata;
if (!gps_rec.waiting(50000000))
{
continue;
}
if ((newdata = gps_rec.read()) == NULL)
{
cout << "Read error." << endl;
running = false;
}
else
{
{
Glib::Mutex::Lock lock (mutex);
latitude = newdata->fix.latitude;
longitude = newdata->fix.longitude;
speed = newdata->fix.speed;
}
dataReady();
}
}
}
// This function is called by the client object to get the data
void GpsInfo::getData(double& lat, double& lng, double& spd)
{
{
Glib::Mutex::Lock lock(mutex);
lat = latitude;
lng = longitude;
spd = speed;
}
}