summaryrefslogtreecommitdiff
path: root/test_gpsmm.cpp
blob: daf280819cea461dbec963da971c64931f465ab7 (plain)
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
65
66
67
68
69
70
71
72
73
74
75
/*
 * Copyright (C) 2005 Alfredo Pironti
 *
 * This software is distributed under a BSD-style license. See the
 * file "COPYING" in the top-level directory of the distribution for details.
 *
 */

/* This simple program shows the basic functionality of the C++ wrapper class */
#include <iostream>

#include "libgpsmm.h"

using namespace std;

#ifdef SAMPLE_USAGE
static void callback(struct gps_data_t* p, char* buf, size_t len);
#endif

int main(void) {
	gpsmm gps_rec;
	struct gps_data_t *resp;

	resp=gps_rec.open();
	if (resp==NULL) {
		cout << "Error opening gpsd\n";
		return (1);
	}

#ifdef SAMPLE_USAGE
	cout << "Going to set the callback...\n";
	if (gps_rec.set_callback(callback)!=0 ) {
		cout << "Error setting callback.\n";
		return (1);
	}

	cout << "Callback setted, sleeping...\n";
	sleep(10);
	cout << "Exited from sleep...\n";
#endif

#ifdef SAMPLE_USAGE
	if (gps_rec.del_callback()!=0) {
		cout << "Error deleting callback\n";
		return (1);
	}
	cout << "Sleeping again, to make sure the callback is disabled\n";
	sleep(4);
#endif

	cout << "Exiting\n";
	return 0;
}

#ifdef SAMPLE_USAGE
static void callback(struct gps_data_t* p, char* buf, size_t len) {
	if (p==NULL) {
		cout << "Error polling gpsd\n";
		return;
	}
	cout << "Online:\t" << p->online << "\n";
	cout << "Status:\t" << p->status << "\n";
	cout << "Mode:\t" << p->fix.mode << "\n";
	if (p->fix.mode>=MODE_2D) {
		if (p->set & LATLON_SET) {
			cout << "LatLon changed\n";
		}
		else {
			cout << "LatLon unchanged\n";
		}
		cout << "Longitude:\t" << p->fix.longitude <<"\n";
		cout << "Latitude:\t" << p->fix.latitude <<"\n";
	}
}
#endif