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;
52 state = new AltosState();
54 state = state.clone();
56 long delay = next_millis - System.currentTimeMillis();
60 next_millis = System.currentTimeMillis() + report_interval;
64 fetch.update_state(state);
65 if (!link.has_error && !link.reply_abort)
67 } catch (TimeoutException te) {
68 } catch (AltosUnknownProduct ue) {
73 aborted = stop_link();
74 } catch (TimeoutException te) {
80 state.set_rssi(link.rssi(), 0);
81 } catch (TimeoutException te) {
88 long finish = System.currentTimeMillis();
90 if (next_millis - finish < minimum_delay)
91 next_millis = finish + minimum_delay;
96 public void close(boolean interrupted) {
99 } catch (InterruptedException ie) {
103 public void set_frequency(double frequency) throws InterruptedException, TimeoutException {
104 link.set_radio_frequency(frequency);
107 public void save_frequency() {
108 AltosPreferences.set_frequency(link.serial, link.frequency);
111 public void set_callsign(String callsign) throws InterruptedException, TimeoutException {
112 link.set_callsign(callsign);
115 public AltosIdleReader (AltosLink link, boolean remote)
116 throws IOException, InterruptedException, TimeoutException {
118 this.remote = remote;
119 this.next_millis = System.currentTimeMillis();
120 fetch = new AltosIdleFetch(link);