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;
29 * This creates a thread to capture telemetry data and write it to
32 class AltosLog implements Runnable {
34 LinkedBlockingQueue<String> input_queue;
35 LinkedBlockingQueue<String> pending_queue;
41 void close() throws IOException {
46 boolean open (AltosTelemetry telem) throws IOException {
47 AltosFile a = new AltosFile(telem);
49 log_file = new FileWriter(a, true);
50 if (log_file != null) {
51 while (!pending_queue.isEmpty()) {
53 String s = pending_queue.take();
56 } catch (InterruptedException ie) {
61 return log_file != null;
67 String line = input_queue.take();
69 AltosTelemetry telem = new AltosTelemetry(line);
70 if (telem.serial != serial || telem.flight != flight || log_file == null) {
72 serial = telem.serial;
73 flight = telem.flight;
76 } catch (ParseException pe) {
78 if (log_file != null) {
83 pending_queue.put(line);
85 } catch (InterruptedException ie) {
86 } catch (IOException ie) {
90 } catch (IOException ie) {
94 public AltosLog (AltosSerial s) {
95 pending_queue = new LinkedBlockingQueue<String> ();
96 input_queue = new LinkedBlockingQueue<String> ();
97 s.add_monitor(input_queue);
101 log_thread = new Thread(this);