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; 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 AltosIdleReader extends AltosFlightReader {
27 AltosState state = null;
30 static final long report_interval = 5 * 1000;
31 static final long minimum_delay = 1 * 1000;
33 private void start_link() throws InterruptedException, TimeoutException {
40 private boolean stop_link() throws InterruptedException, TimeoutException {
43 return link.reply_abort;
46 public AltosState read() throws InterruptedException, ParseException, AltosCRCException, IOException {
47 boolean worked = false;
48 boolean aborted = false;
51 state = new AltosState();
53 state = state.clone();
55 long delay = next_millis - System.currentTimeMillis();
59 next_millis = System.currentTimeMillis() + report_interval;
63 fetch.update_state(state);
64 if (!link.has_error && !link.reply_abort)
66 } catch (TimeoutException te) {
67 } catch (AltosUnknownProduct ue) {
72 aborted = stop_link();
73 } catch (TimeoutException te) {
79 state.set_rssi(link.rssi(), 0);
80 } catch (TimeoutException te) {
87 long finish = System.currentTimeMillis();
89 if (next_millis - finish < minimum_delay)
90 next_millis = finish + minimum_delay;
95 public void close(boolean interrupted) {
98 } catch (InterruptedException ie) {
102 public void set_frequency(double frequency) throws InterruptedException, TimeoutException {
103 link.set_radio_frequency(frequency);
106 public void save_frequency() {
107 AltosPreferences.set_frequency(link.serial, link.frequency);
110 public void set_callsign(String callsign) throws InterruptedException, TimeoutException {
111 link.set_callsign(callsign);
114 public AltosIdleReader (AltosLink link, boolean remote)
115 throws IOException, InterruptedException, TimeoutException {
117 this.remote = remote;
118 this.next_millis = System.currentTimeMillis();
119 fetch = new AltosIdleFetch(link);