diff options
author | Chris Kuethe <chris.kuethe@gmail.com> | 2009-03-02 20:47:18 +0000 |
---|---|---|
committer | Chris Kuethe <chris.kuethe@gmail.com> | 2009-03-02 20:47:18 +0000 |
commit | 6bc85b03ed3794d3d4549c25ba864eabffdfc39f (patch) | |
tree | 3aa743673efedc5f9b7c2fae5115fe2ab3006b2e /test_gpsmm.cpp | |
parent | f36209db311e0c1b7fd6fcde1cd5058691c6d453 (diff) | |
download | gpsd-6bc85b03ed3794d3d4549c25ba864eabffdfc39f.tar.gz |
repository beautification, part 2:
rename the test programs to test_$(subsystem).c
Diffstat (limited to 'test_gpsmm.cpp')
-rw-r--r-- | test_gpsmm.cpp | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/test_gpsmm.cpp b/test_gpsmm.cpp new file mode 100644 index 00000000..23a8e3ed --- /dev/null +++ b/test_gpsmm.cpp @@ -0,0 +1,71 @@ +/* $Id$ */ +/* + * Copyright (C) 2005 Alfredo Pironti + * + * This software is distributed under a BSD-style license. See the + * file "COPYING" for more information. + * + */ + +/* This simple program shows the basic functionality of the C++ wrapper class */ +#include <iostream> +#include <string> +#include <unistd.h> + +#include "libgpsmm.h" + +using namespace std; + +static void callback(struct gps_data_t* p, char* buf, size_t len, int level); + +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); + } + + 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"; + + 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); + + cout << "Exiting\n"; + return 0; +} + +static void callback(struct gps_data_t* p, char* buf, size_t len, int level) { + + 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"; + } +} |