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_4;
21 import java.util.concurrent.*;
24 public class AltosIdleMonitor extends Thread {
26 AltosIdleMonitorListener listener;
34 AltosListenerState listener_state;
35 AltosConfigData config_data;
38 int AltosRSSI() throws TimeoutException, InterruptedException {
40 String line = link.get_reply_no_dialog(5000);
42 throw new TimeoutException();
43 String[] items = line.split("\\s+");
46 if (!items[0].equals("RSSI:"))
48 int rssi = Integer.parseInt(items[1]);
52 void start_link() throws InterruptedException, TimeoutException {
54 link.set_radio_frequency(frequency);
55 link.set_callsign(callsign);
61 void stop_link() throws InterruptedException, TimeoutException {
66 void update_state(AltosState state) throws InterruptedException, TimeoutException {
67 boolean worked = false;
71 fetch.update_state(state);
77 state.set_rssi(link.rssi(), 0);
78 listener_state.battery = link.monitor_battery();
83 public void set_frequency(double in_frequency) {
84 frequency = in_frequency;
88 public void set_callsign(String in_callsign) {
89 callsign = in_callsign;
93 public void abort() throws InterruptedException {
103 AltosState state = new AltosState();
105 while (!link.has_error) {
109 listener.update(state, listener_state);
110 } catch (TimeoutException te) {
114 } catch (InterruptedException ie) {
118 } catch (InterruptedException ie) {
122 public AltosIdleMonitor(AltosIdleMonitorListener in_listener, AltosLink in_link, boolean in_remote)
123 throws FileNotFoundException, InterruptedException, TimeoutException {
124 listener = in_listener;
127 listener_state = new AltosListenerState();
128 fetch = new AltosIdleFetch(link);