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_11;
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 {
39 throw new IOException("IO error");
40 } while (!link.get_monitor());
41 AltosTelemetry telem = AltosTelemetry.parse(l.line);
43 state = new AltosState();
45 state = state.clone();
46 telem.update_state(state);
59 public void close(boolean interrupted) {
61 link.remove_monitor(telem);
65 } catch (InterruptedException ie) {
69 public void set_frequency(double in_frequency) throws InterruptedException, TimeoutException {
70 frequency = in_frequency;
71 link.set_radio_frequency(frequency);
74 public boolean supports_telemetry(int telemetry) {
77 /* Version 1.0 or later firmware supports all telemetry formats */
78 if (link.config_data().compare_version("1.0") >= 0)
81 /* Version 0.9 firmware only supports 0.9 telemetry */
82 if (link.config_data().compare_version("0.9") >= 0) {
83 if (telemetry == AltosLib.ao_telemetry_0_9)
89 /* Version 0.8 firmware only supports 0.8 telemetry */
90 if (telemetry == AltosLib.ao_telemetry_0_8)
94 } catch (InterruptedException ie) {
96 } catch (TimeoutException te) {
101 public boolean supports_telemetry_rate(int telemetry_rate) {
103 /* Version 1.4.1.1 supports all rates, older versions don't */
104 if (link.config_data().compare_version("1.4.1.1") >= 0)
107 if (telemetry_rate == AltosLib.ao_telemetry_rate_38400)
111 } catch (InterruptedException ie) {
113 } catch (TimeoutException te) {
118 public void save_frequency() {
119 AltosPreferences.set_frequency(link.serial, frequency);
122 public void set_telemetry(int in_telemetry) {
123 telemetry = in_telemetry;
124 link.set_telemetry(telemetry);
127 public void save_telemetry() {
128 AltosPreferences.set_telemetry(link.serial, telemetry);
131 public void set_telemetry_rate(int in_telemetry_rate) {
132 telemetry_rate = in_telemetry_rate;
133 link.set_telemetry_rate(telemetry_rate);
136 public void save_telemetry_rate() {
137 AltosPreferences.set_telemetry_rate(link.serial, telemetry_rate);
140 public void set_monitor(boolean monitor) {
141 link.set_monitor(monitor);
144 public File backing_file() {
148 public boolean has_monitor_battery() {
149 return link.has_monitor_battery();
152 public double monitor_battery() throws InterruptedException {
153 return link.monitor_battery();
156 public AltosTelemetryReader (AltosLink in_link)
157 throws IOException, InterruptedException, TimeoutException {
159 boolean success = false;
161 log = new AltosLog(link);
163 telem = new LinkedBlockingQueue<AltosLine>();
164 frequency = AltosPreferences.frequency(link.serial);
165 set_frequency(frequency);
166 telemetry = AltosPreferences.telemetry(link.serial);
167 set_telemetry(telemetry);
168 telemetry_rate = AltosPreferences.telemetry_rate(link.serial);
169 set_telemetry_rate(telemetry_rate);
170 link.add_monitor(telem);