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_3;
22 import java.util.concurrent.*;
24 public class AltosTelemetryReader extends AltosFlightReader {
29 AltosState state = null;
31 LinkedBlockingQueue<AltosLine> telem;
33 public AltosState read() throws InterruptedException, ParseException, AltosCRCException, IOException {
34 AltosLine l = telem.take();
36 throw new IOException("IO error");
37 AltosTelemetry telem = AltosTelemetry.parse(l.line);
39 state = new AltosState();
41 state = state.clone();
42 telem.update_state(state);
54 public void close(boolean interrupted) {
55 link.remove_monitor(telem);
59 } catch (InterruptedException ie) {
63 public void set_frequency(double in_frequency) throws InterruptedException, TimeoutException {
64 frequency = in_frequency;
65 link.set_radio_frequency(frequency);
68 public boolean supports_telemetry(int telemetry) {
71 /* Version 1.0 or later firmware supports all telemetry formats */
72 if (link.config_data().compare_version("1.0") >= 0)
75 /* Version 0.9 firmware only supports 0.9 telemetry */
76 if (link.config_data().compare_version("0.9") >= 0) {
77 if (telemetry == AltosLib.ao_telemetry_0_9)
83 /* Version 0.8 firmware only supports 0.8 telemetry */
84 if (telemetry == AltosLib.ao_telemetry_0_8)
88 } catch (InterruptedException ie) {
90 } catch (TimeoutException te) {
95 public void save_frequency() {
96 AltosPreferences.set_frequency(link.serial, frequency);
99 public void set_telemetry(int in_telemetry) {
100 telemetry = in_telemetry;
101 link.set_telemetry(telemetry);
104 public void save_telemetry() {
105 AltosPreferences.set_telemetry(link.serial, telemetry);
108 public void set_monitor(boolean monitor) {
109 link.set_monitor(monitor);
112 public File backing_file() {
116 public boolean has_monitor_battery() {
117 return link.has_monitor_battery();
120 public double monitor_battery() throws InterruptedException {
121 return link.monitor_battery();
124 public AltosTelemetryReader (AltosLink in_link)
125 throws IOException, InterruptedException, TimeoutException {
127 boolean success = false;
129 log = new AltosLog(link);
131 telem = new LinkedBlockingQueue<AltosLine>();
132 frequency = AltosPreferences.frequency(link.serial);
133 set_frequency(frequency);
134 telemetry = AltosPreferences.telemetry(link.serial);
135 set_telemetry(telemetry);
136 link.add_monitor(telem);