2 * Copyright © 2009 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
20 static struct aoview_serial *monitor_serial;
22 #define MONITOR_LEN 1024
24 static char monitor_line[MONITOR_LEN + 1];
25 static int monitor_pos;
28 aoview_monitor_disconnect(void)
31 aoview_serial_close(monitor_serial);
32 monitor_serial = NULL;
39 aoview_parse_string(char *target, int len, char *source)
41 strncpy(target, source, len-1);
46 aoview_parse_int(int *target, char *source)
48 *target = strtol(source, NULL, 0);
52 aoview_parse_pos(double *target, char *source)
59 if (sscanf(source, "%d°%lf'%c", °, &min, &dir) != 3) {
64 if (dir == 'S' || dir == 'W')
70 aoview_monitor_parse(char *line)
77 if (aoview_log_get_serial())
78 aoview_log_printf ("%s\n", line);
79 for (nword = 0; nword < 64; nword++) {
80 words[nword] = strtok_r(line, " \t\n", &saveptr);
82 if (words[nword] == NULL)
87 if (strcmp(words[0], "CALL") != 0)
89 aoview_parse_string(state.callsign, sizeof (state.callsign), words[1]);
90 aoview_parse_int(&state.serial, words[3]);
91 if (!aoview_log_get_serial())
92 aoview_log_set_serial(state.serial);
94 aoview_parse_int(&state.rssi, words[5]);
95 aoview_parse_string(state.state, sizeof (state.state), words[9]);
96 aoview_parse_int(&state.tick, words[10]);
97 aoview_parse_int(&state.accel, words[12]);
98 aoview_parse_int(&state.pres, words[14]);
99 aoview_parse_int(&state.temp, words[16]);
100 aoview_parse_int(&state.batt, words[18]);
101 aoview_parse_int(&state.drogue, words[20]);
102 aoview_parse_int(&state.main, words[22]);
103 aoview_parse_int(&state.nsat, words[24]);
104 if (strcmp (words[26], "unlocked") != 0 && nword >= 29) {
106 sscanf(words[26], "%d:%d:%d", &state.gps_time.hour, &state.gps_time.minute, &state.gps_time.second);
107 aoview_parse_pos(&state.lat, words[27]);
108 aoview_parse_pos(&state.lon, words[28]);
109 sscanf(words[29], "%dm", &state.alt);
112 state.gps_time.hour = state.gps_time.minute = state.gps_time.second = 0;
113 state.lat = state.lon = 0;
116 aoview_state_notify(&state);
120 aoview_monitor_callback(gpointer user_data,
121 struct aoview_serial *serial,
126 if (revents & (G_IO_HUP|G_IO_ERR)) {
127 aoview_monitor_disconnect();
130 if (revents & G_IO_IN) {
132 c = aoview_serial_getc(serial);
138 monitor_line[monitor_pos] = '\0';
140 aoview_monitor_parse(monitor_line);
142 } else if (monitor_pos < MONITOR_LEN)
143 monitor_line[monitor_pos++] = c;
149 aoview_monitor_connect(char *tty)
151 aoview_monitor_disconnect();
152 monitor_serial = aoview_serial_open(tty);
155 aoview_serial_set_callback(monitor_serial,
156 aoview_monitor_callback,