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;
38 aoview_monitor_parse(const char *input_line)
40 struct cc_telem telem;
42 if (!cc_telem_parse(input_line, &telem))
44 aoview_state_notify(&telem);
49 aoview_monitor_callback(gpointer user_data,
50 struct aoview_serial *serial,
55 if (revents & (G_IO_HUP|G_IO_ERR)) {
56 aoview_monitor_disconnect();
59 if (revents & G_IO_IN) {
61 c = aoview_serial_getc(serial);
67 monitor_line[monitor_pos] = '\0';
69 if (aoview_monitor_parse(monitor_line)) {
70 aoview_log_set_serial(aostate.data.serial);
71 aoview_log_set_flight(aostate.data.flight);
72 if (aoview_log_get_serial())
73 aoview_log_printf ("%s\n", monitor_line);
77 } else if (monitor_pos < MONITOR_LEN)
78 monitor_line[monitor_pos++] = c;
84 aoview_monitor_set_channel(int channel)
87 aoview_serial_printf(monitor_serial, "m 0\n");
88 aoview_serial_printf(monitor_serial, "c r %d\n", channel);
89 aoview_serial_printf(monitor_serial, "m 1\n");
94 aoview_monitor_connect(char *tty)
97 aoview_monitor_disconnect();
98 monitor_serial = aoview_serial_open(tty);
101 aoview_table_clear();
102 aoview_state_reset();
103 channel = aoview_channel_current();
104 aoview_monitor_set_channel(channel);
105 aoview_serial_set_callback(monitor_serial,
106 aoview_monitor_callback);