From 12b40099693a4f6780b1473245cf1d4330eb231f Mon Sep 17 00:00:00 2001 From: David J Taylor Date: Sat, 16 Jun 2018 17:53:23 -0700 Subject: gpssnmp: a simple program to poll gpsd for a few SNMP OID variables. Signed-off-by: Gary E. Miller --- contrib/gpssnmp.c | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 contrib/gpssnmp.c (limited to 'contrib/gpssnmp.c') 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 + * + * Copyright (c)2018 by the GPSD project + * SPDX-License-Identifier: BSD-2-clause + * + * To build this: + * gcc -o gpssnmp gpssnmp.c -lgps + * + */ + +#include +#include +#include + +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; +} -- cgit v1.2.1