cleanup specfile for packaging
[profile/ivi/gpsd.git] / monitor_superstar2.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 SUPERSTAR2_ENABLE
30 #include "driver_superstar2.h"
31 extern const struct gps_type_t superstar2_binary;
32 static WINDOW *satwin;
33
34 static bool superstar2_initialize(void)
35 {
36     int i;
37
38     /*@ -onlytrans @*/
39     /* "heavily inspired" by monitor_nmea.c */
40     if ((satwin = derwin(devicewin, 15, 27, 7, 0)) == NULL)
41         return false;
42     (void)wborder(satwin, 0, 0, 0, 0, 0, 0, 0, 0), (void)syncok(satwin, true);
43     (void)wattrset(satwin, A_BOLD);
44     (void)mvwprintw(satwin, 1, 1, "Ch PRN  Az El S/N Fl U");
45     for (i = 0; i < 12; i++)
46         (void)mvwprintw(satwin, (int)(i + 2), 1, "%2d", i);
47     (void)mvwprintw(satwin, 14, 1, " Satellite Data & Status ");
48     (void)wattrset(satwin, A_NORMAL);
49     /*@ +onlytrans @*/
50
51     return true;
52 }
53
54 static void display_superstar2_svinfo(unsigned char *buf, size_t data_len)
55 {
56     int i;
57
58     if (data_len != 67)
59         return;
60
61     for (i = 0; i < 12; i++) {
62         /* get info for one channel/satellite */
63         int off = i * 5 + 5;
64         unsigned char fl, porn, ss;
65         char el;
66         unsigned short az;
67
68         /*@ +charint */
69         if ((porn = (unsigned char)getub(buf, off) & 0x1f) == 0)
70             porn = ((unsigned char)getub(buf, off + 3) >> 1) + 87;
71         /*@ -charint */
72
73         ss = (unsigned char)getub(buf, off + 4);
74         el = getsb(buf, off + 1);
75         az = (unsigned short)(getub(buf, off + 2) +
76                               ((getub(buf, off + 3) & 0x1) << 1));
77         fl = (unsigned char)getub(buf, off) & 0xe0;
78         (void)wmove(satwin, i + 2, 4);
79         /*@ +charint */
80         (void)wprintw(satwin, "%3u %3d %2d  %02d %02x %c",
81                       porn, az, el, ss, fl,
82                       ((fl & 0x60) == 0x60) ? 'Y' : ' ');
83         /*@ -charint */
84     }
85     (void)wnoutrefresh(satwin);
86     return;
87 }
88
89 static void superstar2_update(void)
90 {
91     unsigned char *buf;
92     size_t len;
93     unsigned char type;
94
95     buf = session.packet.outbuffer;
96     len = session.packet.outbuflen;
97     type = buf[SUPERSTAR2_TYPE_OFFSET];
98     switch (type) {
99     case SUPERSTAR2_SVINFO:
100         display_superstar2_svinfo(buf, len - 3);
101         break;
102     default:
103         break;
104     }
105 }
106
107 static int superstar2_command(char line[]UNUSED)
108 {
109     return COMMAND_UNKNOWN;
110 }
111
112 static void superstar2_wrap(void)
113 {
114 }
115
116 const struct monitor_object_t superstar2_mmt = {
117     .initialize = superstar2_initialize,
118     .update = superstar2_update,
119     .command = superstar2_command,
120     .wrap = superstar2_wrap,
121     .min_y = 23,.min_x = 80,    /* size of the device window */
122     .driver = &superstar2_binary,
123 };
124 #endif