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_10;
21 import java.util.concurrent.*;
24 public class AltosIdleMonitor extends Thread {
26 AltosIdleMonitorListener listener;
31 boolean close_on_exit;
35 AltosListenerState listener_state;
36 AltosConfigData config_data;
39 void start_link() throws InterruptedException, TimeoutException {
41 link.set_radio_frequency(frequency);
42 link.set_callsign(callsign);
48 boolean stop_link() throws InterruptedException, TimeoutException {
51 return link.reply_abort;
54 boolean update_state(AltosState state) throws InterruptedException, TimeoutException {
55 boolean worked = false;
56 boolean aborted = false;
60 fetch.update_state(state);
61 if (!link.has_error && !link.reply_abort)
64 aborted = stop_link();
67 state.set_rssi(link.rssi(), 0);
68 listener_state.battery = link.monitor_battery();
74 public void set_frequency(double in_frequency) {
75 frequency = in_frequency;
79 public void set_callsign(String in_callsign) {
80 callsign = in_callsign;
84 public void abort() throws InterruptedException {
94 AltosState state = new AltosState();
100 listener.update(state, listener_state);
101 } catch (TimeoutException te) {
103 if (link.has_error || link.reply_abort) {
109 } catch (InterruptedException ie) {
114 } catch (InterruptedException ie) {
119 public AltosIdleMonitor(AltosIdleMonitorListener in_listener, AltosLink in_link, boolean in_remote, boolean in_close_on_exit) {
120 listener = in_listener;
123 close_on_exit = in_close_on_exit;
124 listener_state = new AltosListenerState();
125 fetch = new AltosIdleFetch(link);
128 public AltosIdleMonitor(AltosIdleMonitorListener in_listener, AltosLink in_link, boolean in_remote) {
129 this(in_listener, in_link, in_remote, true);