summaryrefslogtreecommitdiff
path: root/monitor_proto.c
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2009-02-19 09:39:25 +0000
committerEric S. Raymond <esr@thyrsus.com>2009-02-19 09:39:25 +0000
commit532a13085e216418dcb11d95c155a3690aa5e0dc (patch)
tree050b1f09c2a58e5a02fbe064006d2ebaa89abd7f /monitor_proto.c
parent9ae53e370187ecee0a91e6ddea363ead23fe0b22 (diff)
downloadgpsd-532a13085e216418dcb11d95c155a3690aa5e0dc.tar.gz
Create monitor_proto.c as a prototype for monitor objects.
Diffstat (limited to 'monitor_proto.c')
-rw-r--r--monitor_proto.c121
1 files changed, 121 insertions, 0 deletions
diff --git a/monitor_proto.c b/monitor_proto.c
new file mode 100644
index 00000000..c4c1cf02
--- /dev/null
+++ b/monitor_proto.c
@@ -0,0 +1,121 @@
+/*
+ * Prototype file for a gpsmon monitor object.
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <math.h>
+#include <ctype.h>
+#ifndef S_SPLINT_S
+#include <unistd.h>
+#endif /* S_SPLINT_S */
+#include <stdarg.h>
+#include <stdbool.h>
+#include <assert.h>
+
+#include "gpsd_config.h"
+#ifdef HAVE_NCURSES_H
+#include <ncurses.h>
+#else
+#include <curses.h>
+#endif /* HAVE_NCURSES_H */
+#include "gpsd.h"
+
+#include "bits.h"
+#include "gpsmon.h"
+
+/*
+ * Replace PROTO everywhere with the name of the GPSD driver describing
+ * the device you want to support.
+ *
+ * gpsmon basically sits in a loop reading packets, using the same layer
+ * as gpsd to dispatch on packet type to select an active device driver.
+ * Your monitor object will become the handler for incoming packets whenever
+ * the driver your object points at is selected.
+ */
+
+extern const struct gps_type_t PROTO;
+
+static bool PROTO_initialize(void)
+{
+ /*
+ * This function is called when your monitor object is activated.
+ *
+ * When you enter it, two windows will be accessible to you; (1)
+ * devicewin, just below the status and command line at top of
+ * screen, and (2) packetwin, taking up the rest of the screen below
+ * it; packetwin will be enabled for scrolling.
+ *
+ * Use this method to paint windowframes and legends on the
+ * freshly initialized device window. You can also use this
+ * method to send probes to the device, e.g. to elicit a response
+ * telling you firmware rev levels or whatever.
+ */
+
+ /* return false if the window allocation failed; gpsmon will abort */
+ return true;
+}
+
+static void PROTO_update(size_t len)
+{
+ /*
+ * Called on each packet received. The packet will be accessible in
+ * session.packet.outbuffer and the length in session.packet.outbuflen.
+ * If the device is NMEA, session.driver.nmea.fields[] will contain the
+ * array of unconverted field strings, including the tag in slot zero
+ * but not including the checksum or trailing \r\n.
+ *
+ * Use this function to update devicewin. The packet will be echoed to
+ * packetwin immediately after this function is called; you can use this
+ * function to write a prefix on the line.
+ */
+}
+
+static int PROTO_command(char line[])
+{
+ /*
+ * Interpret a command line. Whatever characters the user types will
+ * be echoed in the command buffer at the top right of the display. When
+ * he/she presses enter the command line will be passed to this function
+ * for interpretation. Note: packet receipt is suspended while this
+ * function is executing.
+ */
+
+ /*
+ * Return COMMAND_UNKNOWN to tell gpsmon you can't interpret the line, and
+ * it will be passed to the generic command interpreter to be handled there.
+ * You can alse return COMMAND_MATCH to tell it you handled the command,
+ * or COMMAND_TERMINATE to tell gpsmon you handled it and gpsmon should
+ * terminate.
+ */
+ return COMMAND_UNKNOWN;
+}
+
+static void PROTO_wrap(void)
+{
+ /*
+ * Deinitialize any windows you created in PROTO_initialize.
+ * This will be called when gpsmon switches drivers due to seeing
+ * a new packet type.
+ */
+}
+
+/*
+ * Use mmt = monitor method table as a suffix for naming these things
+ * Yours will need to be added to the monitor_objects table in gpsmon.c,
+ * then of course you need to link your module into gpsmon.
+ */
+const struct monitor_object_t PROTO_mmt = {
+ .initialize = PROTO_initialize,
+ .update = PROTO_update,
+ .command = PROTO_command,
+ .wrap = PROTO_wrap,
+ .min_y = 23, .min_x = 80, /* size of the device window */
+ /*
+ * The gpsd driver type for your device. gpsmon will use the mode_switcher
+ * method for 'n', the speed_switcher for 'b', and the control_send method
+ * for 's'. Additionally, the driver type name will be displayed before
+ * the '>' command prompt in the top line of the display.
+ */
+ .driver = &PROTO,
+};