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; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
21 static struct aoview_serial *monitor_serial;
23 #define MONITOR_LEN 1024
25 static char monitor_line[MONITOR_LEN + 1];
26 static int monitor_pos;
29 aoview_monitor_disconnect(void)
32 aoview_serial_close(monitor_serial);
33 monitor_serial = NULL;
39 aoview_monitor_parse(const char *input_line)
41 struct cc_telem telem;
43 if (!cc_telem_parse(input_line, &telem))
45 aoview_state_notify(&telem);
50 aoview_monitor_callback(gpointer user_data,
51 struct aoview_serial *serial,
56 if (revents & (G_IO_HUP|G_IO_ERR)) {
57 aoview_monitor_disconnect();
60 if (revents & G_IO_IN) {
62 c = aoview_serial_getc(serial);
68 monitor_line[monitor_pos] = '\0';
70 if (aoview_monitor_parse(monitor_line)) {
71 aoview_log_set_serial(aostate.data.serial);
72 aoview_log_set_flight(aostate.data.flight);
73 if (aoview_log_get_serial())
74 aoview_log_printf ("%s\n", monitor_line);
78 } else if (monitor_pos < MONITOR_LEN)
79 monitor_line[monitor_pos++] = c;
85 aoview_monitor_set_channel(int channel)
88 aoview_serial_printf(monitor_serial, "m 0\n");
89 aoview_serial_printf(monitor_serial, "c r %d\n", channel);
90 aoview_serial_printf(monitor_serial, "m 1\n");
95 aoview_monitor_connect(char *tty)
98 aoview_monitor_disconnect();
99 monitor_serial = aoview_serial_open(tty);
102 aoview_table_clear();
103 aoview_state_reset();
104 channel = aoview_channel_current();
105 aoview_monitor_set_channel(channel);
106 aoview_serial_set_callback(monitor_serial,
107 aoview_monitor_callback);