1 /*
2  * monitor_tnt.c - gpsmon support for True North Revolution devices.
3  *
4  * This file is Copyright (c) 2010-2018 by the GPSD project
5  * SPDX-License-Identifier: BSD-2-clause
6  */
7 
8 #include "gpsd_config.h"  /* must be before all includes */
9 
10 #include <assert.h>
11 
12 #include "gpsd.h"
13 #include "gpsmon.h"
14 
15 #ifdef TNT_ENABLE
16 extern const struct gps_type_t driver_trueNorth;
17 
18 static WINDOW *thtmwin;
19 
tnt_initialize(void)20 static bool tnt_initialize(void)
21 {
22     thtmwin = derwin(devicewin, 6, 80, 0, 0);
23     assert(thtmwin != NULL);
24     (void)wborder(thtmwin, 0, 0, 0, 0, 0, 0, 0, 0),
25 	(void)syncok(thtmwin, true);
26     (void)wattrset(thtmwin, A_BOLD);
27     (void)mvwaddstr(thtmwin, 0, 35, " PTNTHTM ");
28     (void)mvwaddstr(thtmwin, 1, 1, "Heading:          ");
29     (void)mvwaddstr(thtmwin, 2, 1, "Pitch:            ");
30     (void)mvwaddstr(thtmwin, 3, 1, "Roll:             ");
31     (void)mvwaddstr(thtmwin, 4, 1, "Dip:              ");
32 
33     (void)mvwaddstr(thtmwin, 1, 40, "Magnetometer Status: ");
34     (void)mvwaddstr(thtmwin, 2, 40, "Pitch Status:        ");
35     (void)mvwaddstr(thtmwin, 3, 40, "Roll Status          ");
36     (void)mvwaddstr(thtmwin, 4, 40, "Horizontal Field:    ");
37     (void)wattrset(thtmwin, A_NORMAL);
38     return true;
39 }
40 
tnt_update(void)41 static void tnt_update(void)
42 {
43     /*
44      * We have to do our own field parsing because the way this
45      * gets called, nmea_parse() is never called on the sentence.
46      */
47     (void)nmea_parse((char *)session.lexer.outbuffer, &session);
48 
49     (void)mvwaddstr(thtmwin, 1, 19, session.nmea.field[1]);
50     (void)mvwaddstr(thtmwin, 2, 19, session.nmea.field[3]);
51     (void)mvwaddstr(thtmwin, 3, 19, session.nmea.field[5]);
52     (void)mvwaddstr(thtmwin, 4, 19, session.nmea.field[7]);
53 
54     (void)mvwaddstr(thtmwin, 1, 61, session.nmea.field[2]);
55     (void)mvwaddstr(thtmwin, 2, 61, session.nmea.field[4]);
56     (void)mvwaddstr(thtmwin, 3, 61, session.nmea.field[6]);
57     (void)mvwaddstr(thtmwin, 4, 61, session.nmea.field[8]);
58 }
59 
tnt_command(char line[]UNUSED)60 static int tnt_command(char line[] UNUSED)
61 {
62     /*
63      * Interpret a command line.  Whatever characters the user types will
64      * be echoed in the command buffer at the top right of the display. When
65      * he/she presses enter the command line will be passed to this function
66      * for interpretation.  Note: packet receipt is suspended while this
67      * function is executing.
68      *
69      * This method is optional.  If you set the command method pointer to
70      * NULL, gpsmon will behave sanely, accepting no device-specific commands.
71      *
72      * It is a useful convention to use uppercase letters for
73      * driver-specific commands and leave lowercase ones for the
74      * generic gpsmon ones.
75      */
76 
77     /*
78      * Return COMMAND_UNKNOWN to tell gpsmon you can't interpret the line, and
79      * it will be passed to the generic command interpreter to be handled there.
80      * You can alse return COMMAND_MATCH to tell it you handled the command,
81      * or COMMAND_TERMINATE to tell gpsmon you handled it and gpsmon should
82      * terminate.
83      */
84     return COMMAND_UNKNOWN;
85 }
86 
tnt_wrap(void)87 static void tnt_wrap(void)
88 {
89     (void)delwin(thtmwin);
90 }
91 
92 /*
93  * Use mmt = monitor method table as a suffix for naming these things
94  * Yours will need to be added to the monitor_objects table in gpsmon.c,
95  * then of course you need to link your module into gpsmon.
96  */
97 const struct monitor_object_t tnt_mmt = {
98     .initialize = tnt_initialize,
99     .update = tnt_update,
100     .command = tnt_command,
101     .wrap = tnt_wrap,
102     .min_y = 6,.min_x = 80,	/* size of the device window */
103     .driver = &driver_trueNorth,
104 };
105 #endif /* TNT_ENABLE */
106 
107 /*
108  * Helpers:
109  *
110  * bool monitor_control_send(unsigned char *buf, size_t len)
111  *    Ship a packet payload to the device.  Calls the driver send_control()
112  *    method to add headers/trailers/checksum; also dumps the sent
113  *    packet to the packet window, if the send_control() is playing
114  *    nice by using session.msgbuf to assemble the message.
115  *
116  * void monitor_log(const char *fmt, ...)
117  *    Write a message to the packet window.  Safe if the packet window
118  *    is not on screen.
119  *
120  * void monitor_complain(const char *fmt, ...)
121  *    Post an error message to the command window, wait till user presses a key.
122  *    You get to make sure the message will fit.
123  *
124  * void monitor_fixframe(WINDOW *win)
125  *    Fix the frame of win to the right of the current location by redrawing
126  *    ACS_VLINE there.  Useful after doing wclrtoeol() and writing on the
127  *    line.
128  *
129  * The libgpsd session object is accessible as the global variable 'session'.
130  */
131