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