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_5;
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);
58 public void close(boolean interrupted) {
60 link.remove_monitor(telem);
64 } catch (InterruptedException ie) {
68 public void set_frequency(double in_frequency) throws InterruptedException, TimeoutException {
69 frequency = in_frequency;
70 link.set_radio_frequency(frequency);
73 public boolean supports_telemetry(int telemetry) {
76 /* Version 1.0 or later firmware supports all telemetry formats */
77 if (link.config_data().compare_version("1.0") >= 0)
80 /* Version 0.9 firmware only supports 0.9 telemetry */
81 if (link.config_data().compare_version("0.9") >= 0) {
82 if (telemetry == AltosLib.ao_telemetry_0_9)
88 /* Version 0.8 firmware only supports 0.8 telemetry */
89 if (telemetry == AltosLib.ao_telemetry_0_8)
93 } catch (InterruptedException ie) {
95 } catch (TimeoutException te) {
100 public boolean supports_telemetry_rate(int telemetry_rate) {
102 /* Version 1.4.1.1 supports all rates, older versions don't */
103 if (link.config_data().compare_version("1.4.1.1") >= 0)
106 if (telemetry_rate == AltosLib.ao_telemetry_rate_38400)
110 } catch (InterruptedException ie) {
112 } catch (TimeoutException te) {
117 public void save_frequency() {
118 AltosPreferences.set_frequency(link.serial, frequency);
121 public void set_telemetry(int in_telemetry) {
122 telemetry = in_telemetry;
123 link.set_telemetry(telemetry);
126 public void save_telemetry() {
127 AltosPreferences.set_telemetry(link.serial, telemetry);
130 public void set_telemetry_rate(int in_telemetry_rate) {
131 telemetry_rate = in_telemetry_rate;
132 link.set_telemetry_rate(telemetry_rate);
135 public void save_telemetry_rate() {
136 AltosPreferences.set_telemetry_rate(link.serial, telemetry_rate);
139 public void set_monitor(boolean monitor) {
140 link.set_monitor(monitor);
143 public File backing_file() {
147 public boolean has_monitor_battery() {
148 return link.has_monitor_battery();
151 public double monitor_battery() throws InterruptedException {
152 return link.monitor_battery();
155 public AltosTelemetryReader (AltosLink in_link)
156 throws IOException, InterruptedException, TimeoutException {
158 boolean success = false;
160 log = new AltosLog(link);
162 telem = new LinkedBlockingQueue<AltosLine>();
163 frequency = AltosPreferences.frequency(link.serial);
164 set_frequency(frequency);
165 telemetry = AltosPreferences.telemetry(link.serial);
166 set_telemetry(telemetry);
167 telemetry_rate = AltosPreferences.telemetry_rate(link.serial);
168 set_telemetry_rate(telemetry_rate);
169 link.add_monitor(telem);