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;
21 import java.util.concurrent.*;
24 public class AltosIdleMonitor extends Thread {
26 AltosIdleMonitorListener listener;
30 AltosState previous_state;
31 AltosConfigData config_data;
34 int AltosRSSI() throws TimeoutException, InterruptedException {
36 String line = link.get_reply_no_dialog(5000);
38 throw new TimeoutException();
39 String[] items = line.split("\\s+");
42 if (!items[0].equals("RSSI:"))
44 int rssi = Integer.parseInt(items[1]);
48 void update_state() throws InterruptedException, TimeoutException {
49 AltosRecord record = null;
53 link.set_radio_frequency(frequency);
57 config_data = new AltosConfigData(link);
58 if (config_data.product.startsWith("TeleMetrum")) {
59 record = new AltosSensorTM(link, config_data);
60 } else if (config_data.product.startsWith("MegaMetrum")) {
61 AltosRecordMM record_mm = new AltosRecordMM();
62 AltosSensorMM sensor = new AltosSensorMM(link);
63 AltosMs5607 ms5607 = new AltosMs5607Query(link);
64 AltosIMU imu = new AltosIMUQuery(link);
66 record_mm.accel_plus_g = config_data.accel_cal_plus;
67 record_mm.accel_minus_g = config_data.accel_cal_minus;
69 record_mm.ground_accel = sensor.accel;
70 record_mm.accel = sensor.accel;
71 record_mm.ground_pres = ms5607.pa;
72 record_mm.pres = ms5607.pa;
73 record_mm.temp = ms5607.cc;
75 record_mm.v_batt = sensor.v_batt;
76 record_mm.v_pyro = sensor.v_pyro;
77 record_mm.sense = sensor.sense;
83 record = new AltosRecord();
85 gps = new AltosGPSQuery(link, config_data);
88 record.callsign = config_data.callsign;
89 record.serial = config_data.serial;
90 record.flight = config_data.log_available() > 0 ? 255 : 0;
92 record.state = AltosLib.ao_flight_idle;
94 record.new_gps = true;
95 state = new AltosState (record, state);
100 record.rssi = AltosRSSI();
109 public void set_frequency(double in_frequency) {
110 frequency = in_frequency;
113 public void post_state() {
114 listener.update(state);
123 } catch (TimeoutException te) {
127 } catch (InterruptedException ie) {
132 public AltosIdleMonitor(AltosIdleMonitorListener in_listener, AltosLink in_link, boolean in_remote)
133 throws FileNotFoundException, InterruptedException, TimeoutException {
134 listener = in_listener;