2 * Copyright © 2010 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.
23 import java.text.ParseException;
24 import java.util.concurrent.LinkedBlockingQueue;
25 import altosui.AltosSerial;
26 import altosui.AltosFile;
27 import altosui.AltosLine;
30 * This creates a thread to capture telemetry data and write it to
33 class AltosLog implements Runnable {
35 LinkedBlockingQueue<AltosLine> input_queue;
36 LinkedBlockingQueue<String> pending_queue;
42 void close() throws IOException {
47 boolean open (AltosTelemetry telem) throws IOException {
48 AltosFile a = new AltosFile(telem);
50 log_file = new FileWriter(a, true);
51 if (log_file != null) {
52 while (!pending_queue.isEmpty()) {
54 String s = pending_queue.take();
57 } catch (InterruptedException ie) {
62 return log_file != null;
68 AltosLine line = input_queue.take();
69 if (line.line == null)
72 AltosTelemetry telem = new AltosTelemetry(line.line);
73 if (telem.serial != serial || telem.flight != flight || log_file == null) {
75 serial = telem.serial;
76 flight = telem.flight;
79 } catch (ParseException pe) {
80 } catch (AltosCRCException ce) {
82 if (log_file != null) {
83 log_file.write(line.line);
87 pending_queue.put(line.line);
89 } catch (InterruptedException ie) {
90 } catch (IOException ie) {
94 } catch (IOException ie) {
98 public AltosLog (AltosSerial s) {
99 pending_queue = new LinkedBlockingQueue<String> ();
100 input_queue = new LinkedBlockingQueue<AltosLine> ();
101 s.add_monitor(input_queue);
105 log_thread = new Thread(this);