-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
62 lines (48 loc) · 1.47 KB
/
main.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
/********************************************
* Gpsd client example
* created by s.farmbauer@red-beard-code.de
********************************************/
#include <libgpsmm.h>
#include <iostream>
#include <thread>
#include "GpsPosition.h"
//Controlling the thread flow
bool gReadGps = true;
/// Thread which reads all position form the gpsd
/// server
void read_gpsd_data() {
gpsmm gps_rec("localhost", DEFAULT_GPSD_PORT);
if (gps_rec.stream(WATCH_ENABLE|WATCH_JSON) == NULL) {
std::cerr << "No GPSD running.\n";
return;
}
while (gReadGps) {
struct gps_data_t *newdata;
if (!gps_rec.waiting(50000000))
continue;
if ((newdata = gps_rec.read()) == NULL) {
std::cerr << "Read error.\n";
return;
} else {
GPSPosition dummy(newdata);
}
}
}
///Starts the thread which reads the position and stores
///it in a Contaier
int main(void)
{
std::thread gps_thread(read_gpsd_data);
for (int i=0; i<100; i++)
{
std::this_thread::sleep_for(std::chrono::milliseconds(500));
GPSPosition last_pos = GPSPosition::get_last_3d_fix_value();
std::cout << "Mode:" << last_pos.get_mode()
<< " Lat: " << last_pos.get_latitude()
<< " Lon: " << last_pos.get_longitude()
<< " Alt: " << last_pos.get_altitude() << std::endl;
}
gReadGps = false;
gps_thread.join();
return 0;
}