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.util.concurrent.*;
25 class AltosTelemetryReader extends AltosFlightReader {
33 LinkedBlockingQueue<AltosLine> telem;
35 AltosRecord read() throws InterruptedException, ParseException, AltosCRCException, IOException {
36 AltosLine l = telem.take();
38 throw new IOException("IO error");
39 AltosRecord next = AltosTelemetry.parse(l.line, previous);
48 void close(boolean interrupted) {
49 serial.remove_monitor(telem);
54 public void set_frequency(double in_frequency) throws InterruptedException, TimeoutException {
55 frequency = in_frequency;
56 serial.set_radio_frequency(frequency);
59 public boolean supports_telemetry(int telemetry) {
62 /* Version 1.0 or later firmware supports all telemetry formats */
63 if (serial.config_data().compare_version("1.0") >= 0)
66 /* Version 0.9 firmware only supports 0.9 telemetry */
67 if (serial.config_data().compare_version("0.9") >= 0) {
68 if (telemetry == Altos.ao_telemetry_0_9)
74 /* Version 0.8 firmware only supports 0.8 telemetry */
75 if (telemetry == Altos.ao_telemetry_0_8)
79 } catch (InterruptedException ie) {
81 } catch (TimeoutException te) {
86 void save_frequency() {
87 AltosUIPreferences.set_frequency(device.getSerial(), frequency);
90 void set_telemetry(int in_telemetry) {
91 telemetry = in_telemetry;
92 serial.set_telemetry(telemetry);
95 void save_telemetry() {
96 AltosUIPreferences.set_telemetry(device.getSerial(), telemetry);
103 public AltosTelemetryReader (AltosDevice in_device)
104 throws FileNotFoundException, AltosSerialInUseException, IOException, InterruptedException, TimeoutException {
106 serial = new AltosSerial(device);
107 log = new AltosLog(serial);
108 name = device.toShortString();
111 telem = new LinkedBlockingQueue<AltosLine>();
112 frequency = AltosUIPreferences.frequency(device.getSerial());
113 set_frequency(frequency);
114 telemetry = AltosUIPreferences.telemetry(device.getSerial());
115 set_telemetry(telemetry);
116 serial.set_callsign(AltosUIPreferences.callsign());
117 serial.add_monitor(telem);