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_9;
21 import java.util.concurrent.*;
24 public class AltosIdleMonitor extends Thread {
26 AltosIdleMonitorListener listener;
34 AltosListenerState listener_state;
35 AltosConfigData config_data;
38 void start_link() throws InterruptedException, TimeoutException {
40 link.set_radio_frequency(frequency);
41 link.set_callsign(callsign);
47 boolean stop_link() throws InterruptedException, TimeoutException {
50 return link.reply_abort;
53 boolean update_state(AltosState state) throws InterruptedException, TimeoutException {
54 boolean worked = false;
55 boolean aborted = false;
59 fetch.update_state(state);
60 if (!link.has_error && !link.reply_abort)
63 aborted = stop_link();
66 state.set_rssi(link.rssi(), 0);
67 listener_state.battery = link.monitor_battery();
73 public void set_frequency(double in_frequency) {
74 frequency = in_frequency;
78 public void set_callsign(String in_callsign) {
79 callsign = in_callsign;
83 public void abort() throws InterruptedException {
93 AltosState state = new AltosState();
99 listener.update(state, listener_state);
100 } catch (TimeoutException te) {
102 if (link.has_error || link.reply_abort) {
108 } catch (InterruptedException ie) {
112 } catch (InterruptedException ie) {
116 public AltosIdleMonitor(AltosIdleMonitorListener in_listener, AltosLink in_link, boolean in_remote)
117 throws FileNotFoundException, InterruptedException, TimeoutException {
118 listener = in_listener;
121 listener_state = new AltosListenerState();
122 fetch = new AltosIdleFetch(link);