X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=blobdiff_plain;f=aoview%2Faoview_monitor.c;h=5810be5b91fb006117ac57f048421685a1a86930;hp=faa24474de50feaee06b02277ed653a21300dd33;hb=19630ef084866f4230e68ccf11284b30c68128b1;hpb=2e06772c8b6fd74f86e640ed97f0d5bc8c095c2f diff --git a/aoview/aoview_monitor.c b/aoview/aoview_monitor.c index faa24474..5810be5b 100644 --- a/aoview/aoview_monitor.c +++ b/aoview/aoview_monitor.c @@ -31,7 +31,6 @@ aoview_monitor_disconnect(void) aoview_serial_close(monitor_serial); monitor_serial = NULL; } - aoview_table_clear(); aoview_log_new(); } @@ -69,12 +68,17 @@ aoview_parse_pos(double *target, char *source) static struct aostate state; gboolean -aoview_monitor_parse(char *line) +aoview_monitor_parse(const char *input_line) { char *saveptr; char *words[64]; int nword; + char line_buf[8192], *line; + /* avoid smashing our input parameter */ + strncpy (line_buf, input_line, sizeof (line_buf)-1); + line_buf[sizeof(line_buf) - 1] = '\0'; + line = line_buf; for (nword = 0; nword < 64; nword++) { words[nword] = strtok_r(line, " \t\n", &saveptr); line = NULL; @@ -134,6 +138,12 @@ aoview_monitor_parse(char *line) return TRUE; } +void +aoview_monitor_reset(void) +{ + memset(&state, '\0', sizeof (state)); +} + static void aoview_monitor_callback(gpointer user_data, struct aoview_serial *serial, @@ -175,6 +185,8 @@ aoview_monitor_connect(char *tty) monitor_serial = aoview_serial_open(tty); if (!monitor_serial) return FALSE; + aoview_table_clear(); + aoview_monitor_reset(); aoview_serial_set_callback(monitor_serial, aoview_monitor_callback, monitor_serial,