+++ /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;
-
-import java.lang.*;
-import java.io.File;
-import java.util.*;
-import org.altusmetrum.AltosLib.*;
-
-class AltosFile extends File {
-
- public AltosFile(int year, int month, int day, int serial, int flight, String extension) {
- super (AltosUIPreferences.logdir(),
- String.format("%04d-%02d-%02d-serial-%03d-flight-%03d.%s",
- year, month, day, serial, flight, extension));
- }
-
- public AltosFile(int serial, int flight, String extension) {
- this(Calendar.getInstance().get(Calendar.YEAR),
- Calendar.getInstance().get(Calendar.MONTH) + 1,
- Calendar.getInstance().get(Calendar.DAY_OF_MONTH),
- serial,
- flight,
- extension);
- }
-
- public AltosFile(AltosRecord telem) {
- this(telem.serial, telem.flight, "telem");
- }
-}
+++ /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;
-
-import java.lang.*;
-import java.text.*;
-import java.io.*;
-import java.util.concurrent.*;
-import org.altusmetrum.AltosLib.*;
-
-public class AltosFlightReader {
- String name;
-
- int serial;
-
- void init() { }
-
- AltosRecord read() throws InterruptedException, ParseException, AltosCRCException, IOException { return null; }
-
- void close(boolean interrupted) { }
-
- void set_frequency(double frequency) throws InterruptedException, TimeoutException { }
-
- void save_frequency() { }
-
- void set_telemetry(int telemetry) { }
-
- void save_telemetry() { }
-
- void update(AltosState state) throws InterruptedException { }
-
- boolean supports_telemetry(int telemetry) { return false; }
-
- File backing_file() { return null; }
-}
+++ /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;
-
-import java.io.*;
-import java.lang.*;
-import java.util.*;
-import java.text.ParseException;
-import java.util.concurrent.LinkedBlockingQueue;
-import org.altusmetrum.AltosLib.*;
-
-/*
- * This creates a thread to capture telemetry data and write it to
- * a log file
- */
-class AltosLog implements Runnable {
-
- LinkedBlockingQueue<AltosLine> input_queue;
- LinkedBlockingQueue<String> pending_queue;
- int serial;
- int flight;
- FileWriter log_file;
- Thread log_thread;
- AltosFile file;
-
- private void close_log_file() {
- if (log_file != null) {
- try {
- log_file.close();
- } catch (IOException io) {
- }
- log_file = null;
- }
- }
-
- void close() {
- close_log_file();
- if (log_thread != null) {
- log_thread.interrupt();
- log_thread = null;
- }
- }
-
- File file() {
- return file;
- }
-
- boolean open (AltosRecord telem) throws IOException {
- AltosFile a = new AltosFile(telem);
-
- System.out.printf("open %s\n", a.toString());
- log_file = new FileWriter(a, true);
- if (log_file != null) {
- while (!pending_queue.isEmpty()) {
- try {
- String s = pending_queue.take();
- log_file.write(s);
- log_file.write('\n');
- } catch (InterruptedException ie) {
- }
- }
- log_file.flush();
- file = a;
- }
- return log_file != null;
- }
-
- public void run () {
- try {
- AltosRecord previous = null;
- for (;;) {
- AltosLine line = input_queue.take();
- if (line.line == null)
- continue;
- try {
- AltosRecord telem = AltosTelemetry.parse(line.line, previous);
- if (telem.serial != 0 && telem.flight != 0 &&
- (telem.serial != serial || telem.flight != flight || log_file == null))
- {
- close_log_file();
- serial = telem.serial;
- flight = telem.flight;
- open(telem);
- }
- previous = telem;
- } catch (ParseException pe) {
- } catch (AltosCRCException ce) {
- }
- if (log_file != null) {
- log_file.write(line.line);
- log_file.write('\n');
- log_file.flush();
- } else
- pending_queue.put(line.line);
- }
- } catch (InterruptedException ie) {
- } catch (IOException ie) {
- }
- close();
- }
-
- public AltosLog (AltosSerial s) {
- pending_queue = new LinkedBlockingQueue<String> ();
- input_queue = new LinkedBlockingQueue<AltosLine> ();
- s.add_monitor(input_queue);
- serial = -1;
- flight = -1;
- log_file = null;
- log_thread = new Thread(this);
- log_thread.start();
- }
-}
+++ /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;
-
-import java.awt.*;
-import java.awt.event.*;
-import javax.swing.*;
-import javax.swing.filechooser.FileNameExtensionFilter;
-import javax.swing.table.*;
-import java.io.*;
-import java.util.*;
-import java.text.*;
-import java.util.prefs.*;
-import java.util.concurrent.LinkedBlockingQueue;
-import org.altusmetrum.AltosLib.*;
-
-/*
- * Open an existing telemetry file and replay it in realtime
- */
-
-public class AltosReplayReader extends AltosFlightReader {
- Iterator<AltosRecord> iterator;
- File file;
-
- public AltosRecord read() {
- if (iterator.hasNext())
- return iterator.next();
- return null;
- }
-
- public void close (boolean interrupted) {
- }
-
- void update(AltosState state) throws InterruptedException {
- /* Make it run in realtime after the rocket leaves the pad */
- if (state.state > Altos.ao_flight_pad)
- Thread.sleep((int) (Math.min(state.time_change,10) * 1000));
- }
-
- public File backing_file() { return file; }
-
- public AltosReplayReader(Iterator<AltosRecord> in_iterator, File in_file) {
- iterator = in_iterator;
- file = in_file;
- name = file.getName();
- }
-}
}
void next() throws InterruptedException, TimeoutException {
- reader.serial.set_monitor(false);
+ reader.set_monitor(false);
Thread.sleep(100);
++frequency_index;
if (frequency_index >= frequencies.length ||
}
set_frequency();
set_label();
- reader.serial.set_monitor(true);
+ reader.set_monitor(true);
}
if (device == null)
return false;
try {
- reader = new AltosTelemetryReader(device);
+ reader = new AltosTelemetryReader(new AltosSerial(device));
set_frequency();
set_telemetry();
try {
device = in_device;
frame = null;
serial = device.getSerial();
+ name = device.toShortString();
open();
}
}
+++ /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;
-
-import java.lang.*;
-import java.text.*;
-import java.io.*;
-import java.util.concurrent.*;
-import org.altusmetrum.AltosLib.*;
-
-class AltosTelemetryReader extends AltosFlightReader {
- AltosDevice device;
- AltosSerial serial;
- AltosLog log;
- AltosRecord previous;
- double frequency;
- int telemetry;
-
- LinkedBlockingQueue<AltosLine> telem;
-
- AltosRecord read() throws InterruptedException, ParseException, AltosCRCException, IOException {
- AltosLine l = telem.take();
- if (l.line == null)
- throw new IOException("IO error");
- AltosRecord next = AltosTelemetry.parse(l.line, previous);
- previous = next;
- return next;
- }
-
- void flush() {
- telem.clear();
- }
-
- void close(boolean interrupted) {
- serial.remove_monitor(telem);
- log.close();
- serial.close();
- }
-
- public void set_frequency(double in_frequency) throws InterruptedException, TimeoutException {
- frequency = in_frequency;
- serial.set_radio_frequency(frequency);
- }
-
- public boolean supports_telemetry(int telemetry) {
-
- try {
- /* Version 1.0 or later firmware supports all telemetry formats */
- if (serial.config_data().compare_version("1.0") >= 0)
- return true;
-
- /* Version 0.9 firmware only supports 0.9 telemetry */
- if (serial.config_data().compare_version("0.9") >= 0) {
- if (telemetry == Altos.ao_telemetry_0_9)
- return true;
- else
- return false;
- }
-
- /* Version 0.8 firmware only supports 0.8 telemetry */
- if (telemetry == Altos.ao_telemetry_0_8)
- return true;
- else
- return false;
- } catch (InterruptedException ie) {
- return true;
- } catch (TimeoutException te) {
- return true;
- }
- }
-
- void save_frequency() {
- AltosPreferences.set_frequency(device.getSerial(), frequency);
- }
-
- void set_telemetry(int in_telemetry) {
- telemetry = in_telemetry;
- serial.set_telemetry(telemetry);
- }
-
- void save_telemetry() {
- AltosPreferences.set_telemetry(device.getSerial(), telemetry);
- }
-
- File backing_file() {
- return log.file();
- }
-
- public AltosTelemetryReader (AltosDevice in_device)
- throws FileNotFoundException, AltosSerialInUseException, IOException, InterruptedException, TimeoutException {
- device = in_device;
- serial = new AltosSerial(device);
- log = new AltosLog(serial);
- name = device.toShortString();
- previous = null;
-
- telem = new LinkedBlockingQueue<AltosLine>();
- frequency = AltosPreferences.frequency(device.getSerial());
- set_frequency(frequency);
- telemetry = AltosPreferences.telemetry(device.getSerial());
- set_telemetry(telemetry);
- serial.set_callsign(AltosUIPreferences.callsign());
- serial.add_monitor(telem);
- }
-}
void telemetry_window(AltosDevice device) {
try {
- AltosFlightReader reader = new AltosTelemetryReader(device);
+ AltosFlightReader reader = new AltosTelemetryReader(new AltosSerial(device));
if (reader != null)
new AltosFlightUI(voice, reader, device.getSerial());
} catch (FileNotFoundException ee) {
AltosIMU.java \
AltosMag.java \
AltosEepromSelect.java \
- AltosFile.java \
AltosFlash.java \
AltosFlashUI.java \
AltosFlightDisplay.java \
AltosFlightInfoTableModel.java \
- AltosFlightReader.java \
AltosFlightStats.java \
AltosFlightStatsTable.java \
AltosFlightStatus.java \
AltosLanded.java \
AltosLed.java \
AltosLights.java \
- AltosLog.java \
AltosPad.java \
AltosUIPreferences.java \
AltosReader.java \
- AltosTelemetryReader.java \
- AltosReplayReader.java \
AltosRomconfig.java \
AltosRomconfigUI.java \
AltosScanUI.java \
AltosSiteMapPreload.java \
AltosSiteMapCache.java \
AltosSiteMapTile.java \
- AltosTelemetryReader.java \
AltosUI.java \
AltosUIListener.java \
AltosFrame.java \
$(SRC)/AltosEepromLog.java \
$(SRC)/AltosEepromRecord.java \
$(SRC)/AltosEepromTeleScience.java \
+ $(SRC)/AltosFile.java \
+ $(SRC)/AltosFlightReader.java \
$(SRC)/AltosFrequency.java \
$(SRC)/AltosGPS.java \
$(SRC)/AltosGPSSat.java \
$(SRC)/AltosGreatCircle.java \
$(SRC)/AltosLine.java \
$(SRC)/AltosLink.java \
+ $(SRC)/AltosLog.java \
$(SRC)/AltosParse.java \
$(SRC)/AltosPreferences.java \
$(SRC)/AltosRecordCompanion.java \
$(SRC)/AltosRecordIterable.java \
$(SRC)/AltosRecord.java \
+ $(SRC)/AltosReplayReader.java \
$(SRC)/AltosState.java \
$(SRC)/AltosTelemetry.java \
$(SRC)/AltosTelemetryIterable.java \
$(SRC)/AltosTelemetryMap.java \
+ $(SRC)/AltosTelemetryReader.java \
$(SRC)/AltosTelemetryRecordCompanion.java \
$(SRC)/AltosTelemetryRecordConfiguration.java \
$(SRC)/AltosTelemetryRecordGeneral.java \
--- /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 org.altusmetrum.AltosLib;
+
+import java.lang.*;
+import java.io.File;
+import java.util.*;
+
+public class AltosFile extends File {
+
+ public AltosFile(int year, int month, int day, int serial, int flight, String extension) {
+ super (AltosPreferences.logdir(),
+ String.format("%04d-%02d-%02d-serial-%03d-flight-%03d.%s",
+ year, month, day, serial, flight, extension));
+ }
+
+ public AltosFile(int serial, int flight, String extension) {
+ this(Calendar.getInstance().get(Calendar.YEAR),
+ Calendar.getInstance().get(Calendar.MONTH) + 1,
+ Calendar.getInstance().get(Calendar.DAY_OF_MONTH),
+ serial,
+ flight,
+ extension);
+ }
+
+ public AltosFile(AltosRecord telem) {
+ this(telem.serial, telem.flight, "telem");
+ }
+}
--- /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 org.altusmetrum.AltosLib;
+
+import java.lang.*;
+import java.text.*;
+import java.io.*;
+import java.util.concurrent.*;
+
+public class AltosFlightReader {
+ public String name;
+
+ public int serial;
+
+ public void init() { }
+
+ public AltosRecord read() throws InterruptedException, ParseException, AltosCRCException, IOException { return null; }
+
+ public void close(boolean interrupted) { }
+
+ public void set_frequency(double frequency) throws InterruptedException, TimeoutException { }
+
+ public void save_frequency() { }
+
+ public void set_telemetry(int telemetry) { }
+
+ public void save_telemetry() { }
+
+ public void update(AltosState state) throws InterruptedException { }
+
+ public boolean supports_telemetry(int telemetry) { return false; }
+
+ public File backing_file() { return null; }
+}
import java.text.*;
public abstract class AltosLink {
+ public abstract void print(String data);
+ public abstract void close();
public static boolean debug = false;
public static void set_debug(boolean in_debug) { debug = in_debug; }
set_monitor(false);
}
- public abstract void print(String data);
-
public void printf(String format, Object ... arguments) {
String line = String.format(format, arguments);
if (debug)
public boolean remote;
public int serial;
+ public String name;
public void start_remote() throws TimeoutException, InterruptedException {
if (debug)
--- /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 org.altusmetrum.AltosLib;
+
+import java.io.*;
+import java.lang.*;
+import java.util.*;
+import java.text.ParseException;
+import java.util.concurrent.LinkedBlockingQueue;
+
+/*
+ * This creates a thread to capture telemetry data and write it to
+ * a log file
+ */
+class AltosLog implements Runnable {
+
+ LinkedBlockingQueue<AltosLine> input_queue;
+ LinkedBlockingQueue<String> pending_queue;
+ int serial;
+ int flight;
+ FileWriter log_file;
+ Thread log_thread;
+ AltosFile file;
+
+ private void close_log_file() {
+ if (log_file != null) {
+ try {
+ log_file.close();
+ } catch (IOException io) {
+ }
+ log_file = null;
+ }
+ }
+
+ void close() {
+ close_log_file();
+ if (log_thread != null) {
+ log_thread.interrupt();
+ log_thread = null;
+ }
+ }
+
+ File file() {
+ return file;
+ }
+
+ boolean open (AltosRecord telem) throws IOException {
+ AltosFile a = new AltosFile(telem);
+
+ System.out.printf("open %s\n", a.toString());
+ log_file = new FileWriter(a, true);
+ if (log_file != null) {
+ while (!pending_queue.isEmpty()) {
+ try {
+ String s = pending_queue.take();
+ log_file.write(s);
+ log_file.write('\n');
+ } catch (InterruptedException ie) {
+ }
+ }
+ log_file.flush();
+ file = a;
+ }
+ return log_file != null;
+ }
+
+ public void run () {
+ try {
+ AltosRecord previous = null;
+ for (;;) {
+ AltosLine line = input_queue.take();
+ if (line.line == null)
+ continue;
+ try {
+ AltosRecord telem = AltosTelemetry.parse(line.line, previous);
+ if (telem.serial != 0 && telem.flight != 0 &&
+ (telem.serial != serial || telem.flight != flight || log_file == null))
+ {
+ close_log_file();
+ serial = telem.serial;
+ flight = telem.flight;
+ open(telem);
+ }
+ previous = telem;
+ } catch (ParseException pe) {
+ } catch (AltosCRCException ce) {
+ }
+ if (log_file != null) {
+ log_file.write(line.line);
+ log_file.write('\n');
+ log_file.flush();
+ } else
+ pending_queue.put(line.line);
+ }
+ } catch (InterruptedException ie) {
+ } catch (IOException ie) {
+ }
+ close();
+ }
+
+ public AltosLog (AltosLink link) {
+ pending_queue = new LinkedBlockingQueue<String> ();
+ input_queue = new LinkedBlockingQueue<AltosLine> ();
+ link.add_monitor(input_queue);
+ serial = -1;
+ flight = -1;
+ log_file = null;
+ log_thread = new Thread(this);
+ log_thread.start();
+ }
+}
--- /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 org.altusmetrum.AltosLib;
+
+import java.io.*;
+import java.util.*;
+import java.text.*;
+import java.util.prefs.*;
+import java.util.concurrent.LinkedBlockingQueue;
+
+/*
+ * Open an existing telemetry file and replay it in realtime
+ */
+
+public class AltosReplayReader extends AltosFlightReader {
+ Iterator<AltosRecord> iterator;
+ File file;
+
+ public AltosRecord read() {
+ if (iterator.hasNext())
+ return iterator.next();
+ return null;
+ }
+
+ public void close (boolean interrupted) {
+ }
+
+ public void update(AltosState state) throws InterruptedException {
+ /* Make it run in realtime after the rocket leaves the pad */
+ if (state.state > AltosLib.ao_flight_pad)
+ Thread.sleep((int) (Math.min(state.time_change,10) * 1000));
+ }
+
+ public File backing_file() { return file; }
+
+ public AltosReplayReader(Iterator<AltosRecord> in_iterator, File in_file) {
+ iterator = in_iterator;
+ file = in_file;
+ name = file.getName();
+ }
+}
--- /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 org.altusmetrum.AltosLib;
+
+import java.lang.*;
+import java.text.*;
+import java.io.*;
+import java.util.concurrent.*;
+
+public class AltosTelemetryReader extends AltosFlightReader {
+ AltosLink link;
+ AltosLog log;
+ AltosRecord previous;
+ double frequency;
+ int telemetry;
+
+ LinkedBlockingQueue<AltosLine> telem;
+
+ public AltosRecord read() throws InterruptedException, ParseException, AltosCRCException, IOException {
+ AltosLine l = telem.take();
+ if (l.line == null)
+ throw new IOException("IO error");
+ AltosRecord next = AltosTelemetry.parse(l.line, previous);
+ previous = next;
+ return next;
+ }
+
+ public void flush() {
+ telem.clear();
+ }
+
+ public void close(boolean interrupted) {
+ link.remove_monitor(telem);
+ log.close();
+ link.close();
+ }
+
+ public void set_frequency(double in_frequency) throws InterruptedException, TimeoutException {
+ frequency = in_frequency;
+ link.set_radio_frequency(frequency);
+ }
+
+ public boolean supports_telemetry(int telemetry) {
+
+ try {
+ /* Version 1.0 or later firmware supports all telemetry formats */
+ if (serial.config_data().compare_version("1.0") >= 0)
+ return true;
+
+ /* Version 0.9 firmware only supports 0.9 telemetry */
+ if (serial.config_data().compare_version("0.9") >= 0) {
+ if (telemetry == Altos.ao_telemetry_0_9)
+ return true;
+ else
+ return false;
+ }
+
+ /* Version 0.8 firmware only supports 0.8 telemetry */
+ if (telemetry == Altos.ao_telemetry_0_8)
+ return true;
+ else
+ return false;
+ } catch (InterruptedException ie) {
+ return true;
+ } catch (TimeoutException te) {
+ return true;
+ }
+ }
+
+ public void save_frequency() {
+ AltosPreferences.set_frequency(link.serial, frequency);
+ }
+
+ public void set_telemetry(int in_telemetry) {
+ telemetry = in_telemetry;
+ link.set_telemetry(telemetry);
+ }
+
+ public void save_telemetry() {
+ AltosPreferences.set_telemetry(link.serial, telemetry);
+ }
+
+ public void set_monitor(boolean monitor) {
+ link.set_monitor(monitor);
+ }
+
+ public File backing_file() {
+ return log.file();
+ }
+
+ public AltosTelemetryReader (AltosLink in_link)
+ throws IOException, InterruptedException, TimeoutException {
+ log = new AltosLog(link);
+ name = link.name;
+ previous = null;
+ telem = new LinkedBlockingQueue<AltosLine>();
+ frequency = AltosPreferences.frequency(link.serial);
+ set_frequency(frequency);
+ telemetry = AltosPreferences.telemetry(link.serial);
+ set_telemetry(telemetry);
+ link.add_monitor(telem);
+ }
+}