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.
18 package org.altusmetrum.altoslib_1;
22 import java.util.concurrent.*;
24 public class AltosTelemetryReader extends AltosFlightReader {
30 AltosState state = null;
32 LinkedBlockingQueue<AltosLine> telem;
34 public AltosState read() throws InterruptedException, ParseException, AltosCRCException, IOException {
35 AltosLine l = telem.take();
37 throw new IOException("IO error");
38 AltosRecord next = AltosTelemetry.parse(l.line, previous);
40 state = new AltosState (next, state);
53 public void close(boolean interrupted) {
54 link.remove_monitor(telem);
59 public void set_frequency(double in_frequency) throws InterruptedException, TimeoutException {
60 frequency = in_frequency;
61 link.set_radio_frequency(frequency);
64 public boolean supports_telemetry(int telemetry) {
67 /* Version 1.0 or later firmware supports all telemetry formats */
68 if (link.config_data().compare_version("1.0") >= 0)
71 /* Version 0.9 firmware only supports 0.9 telemetry */
72 if (link.config_data().compare_version("0.9") >= 0) {
73 if (telemetry == AltosLib.ao_telemetry_0_9)
79 /* Version 0.8 firmware only supports 0.8 telemetry */
80 if (telemetry == AltosLib.ao_telemetry_0_8)
84 } catch (InterruptedException ie) {
86 } catch (TimeoutException te) {
91 public void save_frequency() {
92 AltosPreferences.set_frequency(link.serial, frequency);
95 public void set_telemetry(int in_telemetry) {
96 telemetry = in_telemetry;
97 link.set_telemetry(telemetry);
100 public void save_telemetry() {
101 AltosPreferences.set_telemetry(link.serial, telemetry);
104 public void set_monitor(boolean monitor) {
105 link.set_monitor(monitor);
108 public File backing_file() {
112 public boolean has_monitor_battery() {
113 return link.has_monitor_battery();
116 public double monitor_battery() {
117 return link.monitor_battery();
120 public AltosTelemetryReader (AltosLink in_link)
121 throws IOException, InterruptedException, TimeoutException {
124 log = new AltosLog(link);
127 telem = new LinkedBlockingQueue<AltosLine>();
128 frequency = AltosPreferences.frequency(link.serial);
129 set_frequency(frequency);
130 telemetry = AltosPreferences.telemetry(link.serial);
131 set_telemetry(telemetry);
132 link.add_monitor(telem);
133 } catch (TimeoutException e) {
136 } catch (InterruptedException e) {