cleanup specfile for packaging
[profile/ivi/gpsd.git] / monitor_italk.c
1 /*
2  * This file is Copyright (c) 2010 by the GPSD project
3  * BSD terms apply: see the file COPYING in the distribution root for details.
4  */
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <string.h>
8 #include <math.h>
9 #include <ctype.h>
10 #ifndef S_SPLINT_S
11 #include <unistd.h>
12 #endif /* S_SPLINT_S */
13 #include <stdarg.h>
14 #include <stdbool.h>
15 #include <assert.h>
16
17 #include "gpsd_config.h"
18
19 #ifdef HAVE_NCURSES_H
20 #include <ncurses.h>
21 #else
22 #include <curses.h>
23 #endif /* HAVE_NCURSES_H */
24 #include "gpsd.h"
25
26 #include "bits.h"
27 #include "gpsmon.h"
28
29 #ifdef ITRAX_ENABLE
30 #include "driver_italk.h"
31
32 extern const struct gps_type_t italk_binary;
33 static WINDOW *satwin, *navfixwin;
34
35 #define display (void)mvwprintw
36 static bool italk_initialize(void)
37 {
38     int i;
39
40     /*@ -onlytrans @*/
41     /* "heavily inspired" by monitor_nmea.c */
42     if ((satwin =
43          derwin(devicewin, MAX_NR_VISIBLE_PRNS + 3, 27, 0, 0)) == NULL)
44         return false;
45     (void)wborder(satwin, 0, 0, 0, 0, 0, 0, 0, 0), (void)syncok(satwin, true);
46     (void)wattrset(satwin, A_BOLD);
47     display(satwin, 1, 1, "Ch PRN  Az El S/N Flag U");
48     for (i = 0; i < MAX_NR_VISIBLE_PRNS; i++)
49         display(satwin, (int)(i + 2), 1, "%2d", i);
50     display(satwin, MAX_NR_VISIBLE_PRNS + 2, 7, " PRN_STATUS ");
51     (void)wattrset(satwin, A_NORMAL);
52
53     /* "heavily inspired" by monitor_nmea.c */
54     if ((navfixwin = derwin(devicewin, 13, 52, 0, 27)) == NULL)
55         return false;
56     (void)wborder(navfixwin, 0, 0, 0, 0, 0, 0, 0, 0),
57         (void)wattrset(navfixwin, A_BOLD);
58     (void)wmove(navfixwin, 1, 1);
59     (void)wprintw(navfixwin, "ECEF Pos:");
60     (void)wmove(navfixwin, 2, 1);
61     (void)wprintw(navfixwin, "ECEF Vel:");
62
63     (void)wmove(navfixwin, 4, 1);
64     (void)wprintw(navfixwin, "LTP Pos:");
65     (void)wmove(navfixwin, 5, 1);
66     (void)wprintw(navfixwin, "LTP Vel:");
67
68     (void)wmove(navfixwin, 7, 1);
69     (void)wprintw(navfixwin, "Time UTC:");
70     (void)wmove(navfixwin, 8, 1);
71     (void)wprintw(navfixwin, "Time GPS:                  Day:");
72
73     (void)wmove(navfixwin, 10, 1);
74     (void)wprintw(navfixwin, "DOP [H]      [V]      [P]      [T]      [G]");
75     (void)wmove(navfixwin, 11, 1);
76     (void)wprintw(navfixwin, "Fix:");
77
78     display(navfixwin, 12, 20, " NAV_FIX ");
79     (void)wattrset(navfixwin, A_NORMAL);
80     return true;
81     /*@ +onlytrans @*/
82 }
83
84 static void display_itk_navfix(unsigned char *buf, size_t len)
85 {
86
87     unsigned int tow, tod, nsec, d, svlist;
88     unsigned short gps_week, flags, cflags, pflags, nsv;
89     unsigned short year, mon, day, hour, min, sec;
90     double epx, epy, epz, evx, evy, evz;
91     double latitude, longitude;
92     float altitude, speed, track, climb;
93     float hdop, gdop, pdop, vdop, tdop;
94
95     if (len != 296)
96         return;
97
98     flags = (ushort) getleuw(buf, 7 + 4);
99     cflags = (ushort) getleuw(buf, 7 + 6);
100     pflags = (ushort) getleuw(buf, 7 + 8);
101
102 #define MAX(a,b) (((a) > (b)) ? (a) : (b))
103     nsv = (ushort) MAX(getleuw(buf, 7 + 12), getleuw(buf, 7 + 14));
104     svlist = (ushort) getleul(buf, 7 + 16) | getleul(buf, 7 + 24);
105
106     hour = (ushort) getleuw(buf, 7 + 66);
107     min = (ushort) getleuw(buf, 7 + 68);
108     sec = (ushort) getleuw(buf, 7 + 70);
109     nsec = (ushort) getleul(buf, 7 + 72);
110     year = (ushort) getleuw(buf, 7 + 76);
111     mon = (ushort) getleuw(buf, 7 + 78);
112     day = (ushort) getleuw(buf, 7 + 80);
113     gps_week = (ushort) getlesw(buf, 7 + 82);
114     tow = (ushort) getleul(buf, 7 + 84);
115
116     epx = (double)(getlesl(buf, 7 + 96) / 100.0);
117     epy = (double)(getlesl(buf, 7 + 100) / 100.0);
118     epz = (double)(getlesl(buf, 7 + 104) / 100.0);
119     evx = (double)(getlesl(buf, 7 + 186) / 1000.0);
120     evy = (double)(getlesl(buf, 7 + 190) / 1000.0);
121     evz = (double)(getlesl(buf, 7 + 194) / 1000.0);
122
123     latitude = (double)(getlesl(buf, 7 + 144) / 1e7);
124     longitude = (double)(getlesl(buf, 7 + 148) / 1e7);
125     altitude = (float)(getlesl(buf, 7 + 152) / 1e3);
126     climb = (float)(getlesl(buf, 7 + 206) / 1e3);
127     speed = (float)(getleul(buf, 7 + 210) / 1e3);
128     track = (float)(getleuw(buf, 7 + 214) / 1e2);
129
130     hdop = (float)(getleuw(buf, 7 + 56) / 100.0);
131     gdop = (float)(getleuw(buf, 7 + 58) / 100.0);
132     pdop = (float)(getleuw(buf, 7 + 60) / 100.0);
133     vdop = (float)(getleuw(buf, 7 + 62) / 100.0);
134     tdop = (float)(getleuw(buf, 7 + 64) / 100.0);
135
136     (void)wmove(navfixwin, 1, 11);
137     (void)wprintw(navfixwin, "%12.2lf %12.2lf %12.2lfm", epx, epy, epz);
138     (void)wmove(navfixwin, 2, 11);
139     (void)wprintw(navfixwin, "%11.2lf %11.2lf %11.2lfm/s", evx, evy, evz);
140
141     (void)wmove(navfixwin, 4, 11);
142     (void)wprintw(navfixwin, "%11.8lf   %13.8lf %8.1lfm",
143                   latitude, longitude, altitude);
144     (void)mvwaddch(navfixwin, 4, 22, ACS_DEGREE);
145     (void)mvwaddch(navfixwin, 4, 38, ACS_DEGREE);
146     (void)wmove(navfixwin, 5, 11);
147     (void)wprintw(navfixwin, "%6.2lfm/s  %5.1lf  %6.2lfm/s climb",
148                   speed, track, climb);
149     (void)mvwaddch(navfixwin, 5, 27, ACS_DEGREE);
150
151     (void)wmove(navfixwin, 7, 11);
152     (void)wprintw(navfixwin, "%04u-%02u-%02u %02u:%02u:%02u",
153                   year, mon, day, hour, min, sec);
154     (void)wmove(navfixwin, 8, 11);
155     (void)wprintw(navfixwin, "%04u+%010.3lf", gps_week, tow / 1000.0);
156     (void)wmove(navfixwin, 8, 33);
157     d = (tow / 1000) / 86400;
158     tod = (tow / 1000) - (d * 86400);
159     sec = (unsigned short)tod % 60;
160     min = (unsigned short)(tod / 60) % 60;
161     hour = (unsigned short)tod / 3600;
162     (void)wprintw(navfixwin, "%1d %02d:%02d:%02d", d, hour, min, sec);
163
164     (void)wmove(navfixwin, 10, 9);
165     (void)wprintw(navfixwin, "%-5.1f", hdop);
166     (void)wmove(navfixwin, 10, 18);
167     (void)wprintw(navfixwin, "%-5.1f", vdop);
168     (void)wmove(navfixwin, 10, 27);
169     (void)wprintw(navfixwin, "%-5.1f", pdop);
170     (void)wmove(navfixwin, 10, 36);
171     (void)wprintw(navfixwin, "%-5.1f", tdop);
172     (void)wmove(navfixwin, 10, 45);
173     (void)wprintw(navfixwin, "%-5.1f", gdop);
174
175     (void)wmove(navfixwin, 11, 6);
176     {
177         char prn[4], satlist[38];
178         unsigned int i;
179         satlist[0] = '\0';
180         for (i = 0; i < 32; i++) {
181             if (svlist & (1 << i)) {
182                 (void)snprintf(prn, 4, "%u ", i + 1);
183                 (void)strlcat(satlist, prn, 38);
184             }
185         }
186         (void)wprintw(navfixwin, "%02d = %-38s", nsv, satlist);
187     }
188     (void)wnoutrefresh(navfixwin);
189
190 }
191
192 static void display_itk_prnstatus(unsigned char *buf, size_t len)
193 {
194     int i, nchan;
195     if (len < 62)
196         return;
197
198     nchan = (int)getleuw(buf, 7 + 50);
199     if (nchan > MAX_NR_VISIBLE_PRNS)
200         nchan = MAX_NR_VISIBLE_PRNS;
201     for (i = 0; i < nchan; i++) {
202         int off = 7 + 52 + 10 * i;
203         unsigned short fl;
204         unsigned char ss, prn, el, az;
205
206         fl = (unsigned short)getleuw(buf, off);
207         ss = (unsigned char)getleuw(buf, off + 2) & 0xff;
208         prn = (unsigned char)getleuw(buf, off + 4) & 0xff;
209         el = (unsigned char)getlesw(buf, off + 6) & 0xff;
210         az = (unsigned char)getlesw(buf, off + 8) & 0xff;
211         (void)wmove(satwin, i + 2, 4);
212         (void)wprintw(satwin, "%3d %3d %2d  %02d %04x %c",
213                       prn, az, el, ss, fl,
214                       (fl & PRN_FLAG_USE_IN_NAV) ? 'Y' : ' ');
215     }
216     for (; i < MAX_NR_VISIBLE_PRNS; i++) {
217         (void)wmove(satwin, (int)i + 2, 4);
218         (void)wprintw(satwin, "                      ");
219     }
220     (void)wnoutrefresh(satwin);
221     return;
222 }
223
224 static void italk_update(void)
225 {
226     unsigned char *buf;
227     size_t len;
228     unsigned char type;
229
230     buf = session.packet.outbuffer;
231     len = session.packet.outbuflen;
232     type = (unsigned char)getub(buf, 4);
233     switch (type) {
234     case ITALK_NAV_FIX:
235         display_itk_navfix(buf, len);
236         break;
237     case ITALK_PRN_STATUS:
238         display_itk_prnstatus(buf, len);
239         break;
240     default:
241         break;
242     }
243 }
244
245 static int italk_command(char line[]UNUSED)
246 {
247     return COMMAND_UNKNOWN;
248 }
249
250 static void italk_wrap(void)
251 {
252     (void)delwin(satwin);
253     return;
254 }
255
256 const struct monitor_object_t italk_mmt = {
257     .initialize = italk_initialize,
258     .update = italk_update,
259     .command = italk_command,
260     .wrap = italk_wrap,
261     .min_y = 23,.min_x = 80,    /* size of the device window */
262     .driver = &italk_binary,
263 };
264 #endif