2 * Copyright © 2016 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; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
19 package org.altusmetrum.altoslib_11;
23 import java.util.concurrent.*;
25 public class AltosIdleReader extends AltosFlightReader {
28 AltosState state = null;
31 static final long report_interval = 5 * 1000;
32 static final long minimum_delay = 1 * 1000;
34 private void start_link() throws InterruptedException, TimeoutException {
41 private boolean stop_link() throws InterruptedException, TimeoutException {
44 return link.reply_abort;
47 public AltosState read() throws InterruptedException, ParseException, AltosCRCException, IOException {
48 boolean worked = false;
49 boolean aborted = false;
51 long delay = next_millis - System.currentTimeMillis();
55 next_millis = System.currentTimeMillis() + report_interval;
60 state = new AltosState(new AltosCalData(link.config_data()));
61 fetch.provide_data(state, state.cal_data);
62 if (!link.has_error && !link.reply_abort)
64 } catch (TimeoutException te) {
65 } catch (AltosUnknownProduct ue) {
70 aborted = stop_link();
71 } catch (TimeoutException te) {
77 state.set_rssi(link.rssi(), 0);
78 } catch (TimeoutException te) {
85 long finish = System.currentTimeMillis();
87 if (next_millis - finish < minimum_delay)
88 next_millis = finish + minimum_delay;
93 public void close(boolean interrupted) {
96 } catch (InterruptedException ie) {
100 public void set_frequency(double frequency) throws InterruptedException, TimeoutException {
101 link.set_radio_frequency(frequency);
104 public void save_frequency() {
105 AltosPreferences.set_frequency(link.serial, link.frequency);
108 public void set_callsign(String callsign) throws InterruptedException, TimeoutException {
109 link.set_callsign(callsign);
112 public AltosIdleReader (AltosLink link, boolean remote)
113 throws IOException, InterruptedException, TimeoutException {
115 this.remote = remote;
116 this.next_millis = System.currentTimeMillis();
117 fetch = new AltosIdleFetch(link);