--- /dev/null
+/*
+ * Copyright © 2010 Keith Packard <keithp@keithp.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+
+package altosui;
+
+public class AltosLine {
+ public String line;
+
+ public AltosLine() {
+ line = null;
+ }
+
+ public AltosLine(String s) {
+ line = s;
+ }
+}
\ No newline at end of file
import java.util.concurrent.LinkedBlockingQueue;
import altosui.AltosSerial;
import altosui.AltosFile;
+import altosui.AltosLine;
/*
* This creates a thread to capture telemetry data and write it to
*/
class AltosLog implements Runnable {
- LinkedBlockingQueue<String> input_queue;
+ LinkedBlockingQueue<AltosLine> input_queue;
LinkedBlockingQueue<String> pending_queue;
int serial;
int flight;
public void run () {
try {
for (;;) {
- String line = input_queue.take();
+ AltosLine line = input_queue.take();
+ if (line.line == null)
+ continue;
try {
- AltosTelemetry telem = new AltosTelemetry(line);
+ AltosTelemetry telem = new AltosTelemetry(line.line);
if (telem.serial != serial || telem.flight != flight || log_file == null) {
close();
serial = telem.serial;
} catch (AltosCRCException ce) {
}
if (log_file != null) {
- log_file.write(line);
+ log_file.write(line.line);
log_file.write('\n');
log_file.flush();
} else
- pending_queue.put(line);
+ pending_queue.put(line.line);
}
} catch (InterruptedException ie) {
} catch (IOException ie) {
public AltosLog (AltosSerial s) {
pending_queue = new LinkedBlockingQueue<String> ();
- input_queue = new LinkedBlockingQueue<String> ();
+ input_queue = new LinkedBlockingQueue<AltosLine> ();
s.add_monitor(input_queue);
serial = -1;
flight = -1;
import java.util.LinkedList;
import java.util.Iterator;
import altosui.AltosSerialMonitor;
+import altosui.AltosLine;
import libaltosJNI.libaltos;
import libaltosJNI.altos_device;
import libaltosJNI.SWIGTYPE_p_altos_file;
import libaltosJNI.SWIGTYPE_p_altos_list;
+import libaltosJNI.libaltosConstants;
/*
* This class reads from the serial port and places each received
public class AltosSerial implements Runnable {
SWIGTYPE_p_altos_file altos;
- LinkedList<LinkedBlockingQueue<String>> monitors;
- LinkedBlockingQueue<String> reply_queue;
+ LinkedList<LinkedBlockingQueue<AltosLine>> monitors;
+ LinkedBlockingQueue<AltosLine> reply_queue;
Thread input_thread;
String line;
byte[] line_bytes;
c = libaltos.altos_getchar(altos, 0);
if (Thread.interrupted())
break;
- if (c == -1)
+ if (c == libaltosConstants.LIBALTOS_ERROR) {
+ for (int e = 0; e < monitors.size(); e++) {
+ LinkedBlockingQueue<AltosLine> q = monitors.get(e);
+ q.put(new AltosLine());
+ }
+ reply_queue.put (new AltosLine());
+ break;
+ }
+ if (c == libaltosConstants.LIBALTOS_TIMEOUT)
continue;
if (c == '\r')
continue;
}
if (line.startsWith("VERSION") || line.startsWith("CRC")) {
for (int e = 0; e < monitors.size(); e++) {
- LinkedBlockingQueue<String> q = monitors.get(e);
- q.put(line);
+ LinkedBlockingQueue<AltosLine> q = monitors.get(e);
+ q.put(new AltosLine (line));
}
} else {
// System.out.printf("GOT: %s\n", line);
- reply_queue.put(line);
+ reply_queue.put(new AltosLine (line));
}
line_count = 0;
line = "";
public String get_reply() throws InterruptedException {
flush_output();
- String line = reply_queue.take();
- return line;
+ AltosLine line = reply_queue.take();
+ return line.line;
}
- public void add_monitor(LinkedBlockingQueue<String> q) {
+ public void add_monitor(LinkedBlockingQueue<AltosLine> q) {
set_monitor(true);
monitors.add(q);
}
- public void remove_monitor(LinkedBlockingQueue<String> q) {
+ public void remove_monitor(LinkedBlockingQueue<AltosLine> q) {
monitors.remove(q);
if (monitors.isEmpty())
set_monitor(false);
input_thread = null;
line = "";
monitor_mode = false;
- monitors = new LinkedList<LinkedBlockingQueue<String>> ();
- reply_queue = new LinkedBlockingQueue<String> ();
+ monitors = new LinkedList<LinkedBlockingQueue<AltosLine>> ();
+ reply_queue = new LinkedBlockingQueue<AltosLine> ();
}
}
import altosui.AltosFlashUI;
import altosui.AltosLogfileChooser;
import altosui.AltosCSVUI;
+import altosui.AltosLine;
import libaltosJNI.*;
}
public void show(AltosState state, int crc_errors) {
+ if (state == null)
+ return;
flightStatusModel.set(state);
info_reset();
void init() { }
- AltosRecord read() throws InterruptedException, ParseException, AltosCRCException { return null; }
+ AltosRecord read() throws InterruptedException, ParseException, AltosCRCException, IOException { return null; }
void close() { }
}
}
} catch (InterruptedException ee) {
+ } catch (IOException ie) {
+ JOptionPane.showMessageDialog(AltosUI.this,
+ String.format("Error reading from \"%s\"", name),
+ "Telemetry Read Error",
+ JOptionPane.ERROR_MESSAGE);
} finally {
close();
idle_thread.interrupt();
class DeviceThread extends DisplayThread {
AltosSerial serial;
- LinkedBlockingQueue<String> telem;
+ LinkedBlockingQueue<AltosLine> telem;
- AltosRecord read() throws InterruptedException, ParseException, AltosCRCException {
- return new AltosTelemetry(telem.take());
+ AltosRecord read() throws InterruptedException, ParseException, AltosCRCException, IOException {
+ AltosLine l = telem.take();
+ if (l.line == null)
+ throw new IOException("IO error");
+ return new AltosTelemetry(l.line);
}
void close() {
serial.remove_monitor(telem);
}
- public DeviceThread(AltosSerial s) {
+ public DeviceThread(AltosSerial s, String in_name) {
serial = s;
- telem = new LinkedBlockingQueue<String>();
+ telem = new LinkedBlockingQueue<AltosLine>();
serial.add_monitor(telem);
- name = "telemetry";
+ name = in_name;
}
}
try {
stop_display();
serial_line.open(device);
- DeviceThread thread = new DeviceThread(serial_line);
+ DeviceThread thread = new DeviceThread(serial_line, device.getPath());
serial_line.set_channel(AltosPreferences.channel());
serial_line.set_callsign(AltosPreferences.callsign());
run_display(thread);
AltosGPS.class \
AltosGreatCircle.class \
AltosHexfile.class \
+ AltosLine.class \
AltosLog.class \
AltosLogfileChooser.class \
AltosParse.class \
PUBLIC int
altos_flush(struct altos_file *file)
{
+ if (file->out_used && 0) {
+ printf ("flush \"");
+ fwrite(file->out_data, 1, file->out_used, stdout);
+ printf ("\"\n");
+ }
while (file->out_used) {
int ret;
return LIBALTOS_ERROR;
#ifdef USE_POLL
fd[0].fd = file->fd;
- fd[0].events = POLLIN;
+ fd[0].events = POLLIN|POLLERR|POLLHUP|POLLNVAL;
fd[1].fd = file->pipe[0];
fd[1].events = POLLIN;
ret = poll(fd, 2, timeout);
}
if (ret == 0)
return LIBALTOS_TIMEOUT;
+
+ if (fd[0].revents & (POLLHUP|POLLERR|POLLNVAL))
+ return LIBALTOS_ERROR;
if (fd[0].revents & POLLIN)
#endif
{
#endif
}
}
+ if (file->in_used && 0) {
+ printf ("fill \"");
+ fwrite(file->in_data, 1, file->in_used, stdout);
+ printf ("\"\n");
+ }
return 0;
}