summaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
authorDavid J Taylor <gm8arv@yahoo.co.uk>2018-06-16 17:53:23 -0700
committerGary E. Miller <gem@rellim.com>2018-06-16 17:53:23 -0700
commit12b40099693a4f6780b1473245cf1d4330eb231f (patch)
treea12813c44c3ad86ed512d5567cc54acd59626091 /contrib
parentaed938aacb07f304265c36638b081b0d65007bd5 (diff)
downloadgpsd-12b40099693a4f6780b1473245cf1d4330eb231f.tar.gz
gpssnmp: a simple program to poll gpsd for a few SNMP OID variables.
Signed-off-by: Gary E. Miller <gem@rellim.com>
Diffstat (limited to 'contrib')
-rw-r--r--contrib/README1
-rw-r--r--contrib/gpssnmp.c91
2 files changed, 92 insertions, 0 deletions
diff --git a/contrib/README b/contrib/README
index 74811000..c060ec29 100644
--- a/contrib/README
+++ b/contrib/README
@@ -2,6 +2,7 @@ The following tools are not production-ready. They are included only as
conveniences, examples or rudimetary starting points for other development
efforts.
+gpssnmp a tool to return some SNMP values from the running local gpsd.
clock_test is used to test the latency of the system call clock_getttime().
diff --git a/contrib/gpssnmp.c b/contrib/gpssnmp.c
new file mode 100644
index 00000000..4b109738
--- /dev/null
+++ b/contrib/gpssnmp.c
@@ -0,0 +1,91 @@
+/* gpssnmp - poll local gpsd for SNMP variables
+ *
+ * Copyright (c) 2016 David Taylor <gpsd@david.taylor.name>
+ *
+ * Copyright (c)2018 by the GPSD project
+ * SPDX-License-Identifier: BSD-2-clause
+ *
+ * To build this:
+ * gcc -o gpssnmp gpssnmp.c -lgps
+ *
+ */
+
+#include <gps.h>
+#include <stdio.h>
+#include <string.h>
+
+static void usage() {
+ printf("\n"
+ "Usage:\n"
+ "\n"
+ "to get OID_VISIBLE\n"
+ " $ gpssnmp -g .1.3.6.1.2.1.25.1.31\n"
+ " .1.3.6.1.2.1.25.1.31\n"
+ " gauge\n"
+ " 13\n"
+ "\n"
+ "to get OID_USED\n"
+ " $ gpssnmp -g .1.3.6.1.2.1.25.1.32\n"
+ " .1.3.6.1.2.1.25.1.32\n"
+ " gauge\n"
+ " 4\n"
+ "\n"
+ "to get OID_SNR_AVG\n"
+ " $ gpssnmp -g .1.3.6.1.2.1.25.1.33\n"
+ " .1.3.6.1.2.1.25.1.33\n"
+ " gauge\n"
+ " 22.250000\n"
+ "\n");
+}
+
+int main (int argc, char **argv) {
+ int status, used, visible;
+ struct gps_data_t gpsdata;
+
+ #define OID_VISIBLE ".1.3.6.1.2.1.25.1.31"
+ #define OID_USED ".1.3.6.1.2.1.25.1.32"
+ #define OID_SNR_AVG ".1.3.6.1.2.1.25.1.33"
+
+ if ((argc > 2) && (strcmp ("-g", argv[1]) == 0)) {
+ int i;
+ double snr_total=0;
+ double snr_avg = 0.0;
+
+ status = gps_open (GPSD_SHARED_MEMORY, DEFAULT_GPSD_PORT, &gpsdata);
+ status = gps_read (&gpsdata);
+ used = gpsdata.satellites_used;
+ visible = gpsdata.satellites_visible;
+ for(i=0; i<=used; i++) {
+ if (gpsdata.skyview[i].used > 0 && gpsdata.skyview[i].ss > 1) {
+// printf ("i: %d, P:%d, ss: %f\n", i, gpsdata.skyview[i].PRN,
+// gpsdata.skyview[i].ss);
+ snr_total+=gpsdata.skyview[i].ss;
+ }
+ }
+ gps_close (&gpsdata);
+ if (used > 0) {
+ snr_avg = snr_total / used;
+ }
+ if (strcmp (OID_VISIBLE, argv[2]) == 0) {
+ printf (OID_VISIBLE);
+ printf ("\n");
+ printf ("gauge\n");
+ printf ("%d\n", visible);
+ }
+ if (strcmp (OID_USED, argv[2]) == 0) {
+ printf (OID_USED);
+ printf ("\n");
+ printf ("gauge\n");
+ printf ("%d\n", used);
+ }
+ if (strcmp (OID_SNR_AVG, argv[2]) == 0) {
+ printf (OID_SNR_AVG);
+ printf ("\n");
+ printf ("gauge\n");
+ printf ("%lf\n", snr_avg);
+ }
+ } else {
+ usage();
+ }
+ return 0;
+}