[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gpsd-dev] [PATCH 2/4] Enable options into test_gpsmm program
From: |
Robert Norris |
Subject: |
[gpsd-dev] [PATCH 2/4] Enable options into test_gpsmm program |
Date: |
Fri, 10 Feb 2017 22:53:35 +0000 |
First enabled option give the number of times the program
iterates around the main loop.
Mainly this allows the test program to finish cleanly.
---
test_gpsmm.cpp | 31 +++++++++++++++++++++++++++++--
1 file changed, 29 insertions(+), 2 deletions(-)
diff --git a/test_gpsmm.cpp b/test_gpsmm.cpp
index c32f8fca..dab1bfc2 100644
--- a/test_gpsmm.cpp
+++ b/test_gpsmm.cpp
@@ -9,6 +9,8 @@
/* This simple program shows the basic functionality of the C++ wrapper class
*/
#include <iostream>
+#include <getopt.h>
+
#include "libgpsmm.h"
using namespace std;
@@ -102,8 +104,29 @@ static void libgps_dump_state(struct gps_data_t *collect)
}
-int main(void)
+int main(int argc, char *argv[])
{
+ uint looper = 0;
+
+ // A typical C++ program may look to use a more native option parsing
method
+ // such as boost::program_options
+ // But for this test program we don't want extra dependencies
+ // Hence use C style getopt for (build) simplicity
+ int option;
+ while ((option = getopt(argc, argv, "l:h?")) != -1) {
+ switch (option) {
+ case 'l':
+ looper = atoi(optarg);
+ break;
+ case '?':
+ case 'h':
+ default:
+ cout << "usage: " << argv[0] << " [-l n]\n";
+ exit(EXIT_FAILURE);
+ break;
+ }
+ }
+
gpsmm gps_rec("localhost", DEFAULT_GPSD_PORT);
if (gps_rec.stream(WATCH_ENABLE|WATCH_JSON) == NULL) {
@@ -111,7 +134,11 @@ int main(void)
return 1;
}
- for (;;) {
+ // Loop for the specified number of times
+ // If not specified then by default it loops until ll simply goes out of
bounds
+ // So with the 5 second wait & a 4 byte uint - this equates to ~680 years
+ // - long enough for a test program :)
+ for (uint ll = 0; ll < looper ; ll++) {
struct gps_data_t* newdata;
if (!gps_rec.waiting(5000000))
--
2.11.0
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gpsd-dev] [PATCH 2/4] Enable options into test_gpsmm program,
Robert Norris <=