diff options
| author | Keith Packard <keithp@keithp.com> | 2013-09-05 11:33:48 -0700 | 
|---|---|---|
| committer | Keith Packard <keithp@keithp.com> | 2013-09-05 11:35:14 -0700 | 
| commit | 5b976a6651f4eb05d30afc08b9e1f27c7e52ae00 (patch) | |
| tree | 3a8f38d92fdc3b3e9e62d7744ff93a0f9ca8f7dc /altoslib/AltosIdleMonitor.java | |
| parent | b984ff81d6b8979574e0248ffe8876634b8e1942 (diff) | |
altoslib: Finish AltosState changes. Update version number.
Removes all of the AltosRecord bits, changes the monitor idle bits to
have per-object state updaters.
Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'altoslib/AltosIdleMonitor.java')
| -rw-r--r-- | altoslib/AltosIdleMonitor.java | 115 | 
1 files changed, 32 insertions, 83 deletions
diff --git a/altoslib/AltosIdleMonitor.java b/altoslib/AltosIdleMonitor.java index b3ce5b20..d858845a 100644 --- a/altoslib/AltosIdleMonitor.java +++ b/altoslib/AltosIdleMonitor.java @@ -15,7 +15,7 @@   * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.   */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2;  import java.io.*;  import java.util.concurrent.*; @@ -24,11 +24,13 @@ import java.util.concurrent.*;  public class AltosIdleMonitor extends Thread {  	AltosLink		link;  	AltosIdleMonitorListener	listener; -	AltosState		state; + +	AltosIdleFetch		fetch; +  	boolean			remote;  	double			frequency;  	String			callsign; -	AltosState		previous_state; +  	AltosListenerState	listener_state;  	AltosConfigData		config_data;  	AltosGPS		gps; @@ -47,86 +49,35 @@ public class AltosIdleMonitor extends Thread {  		return rssi;  	} -	boolean has_sensor_tm(AltosConfigData config_data) { -		return config_data.product.startsWith("TeleMetrum") || config_data.product.startsWith("TeleMini"); -	} - -	boolean has_sensor_mm(AltosConfigData config_data) { -		return config_data.product.startsWith("TeleMega"); -	} - -	boolean has_gps(AltosConfigData config_data) { -		return config_data.product.startsWith("TeleMetrum") || config_data.product.startsWith("TeleMega"); +	void start_link() throws InterruptedException, TimeoutException { +		if (remote) { +			link.set_radio_frequency(frequency); +			link.set_callsign(callsign); +			link.start_remote(); +		} else +			link.flush_input();  	} -	AltosRecord sensor_mm(AltosConfigData config_data) throws InterruptedException, TimeoutException { -		AltosRecordMM record_mm = new AltosRecordMM(); -		AltosSensorMM sensor = new AltosSensorMM(link); -		AltosMs5607 ms5607 = new AltosMs5607Query(link); -		AltosIMU imu = new AltosIMUQuery(link); - -		record_mm.accel_plus_g = config_data.accel_cal_plus; -		record_mm.accel_minus_g = config_data.accel_cal_minus; - -		record_mm.ground_accel = sensor.accel; -		record_mm.accel = sensor.accel; -		record_mm.ground_pres = ms5607.pa; -		record_mm.pres = ms5607.pa; -		record_mm.temp = ms5607.cc; - -		record_mm.v_batt = sensor.v_batt; -		record_mm.v_pyro = sensor.v_pyro; -		record_mm.sense = sensor.sense; - -		record_mm.imu = imu; - -		return record_mm; +	void stop_link() throws InterruptedException, TimeoutException { +		if (remote) +			link.stop_remote();  	} -	void update_state() throws InterruptedException, TimeoutException { -		AltosRecord	record = null; +	void update_state(AltosState state) throws InterruptedException, TimeoutException { +		boolean		worked = false;  		try { -			if (remote) { -				link.set_radio_frequency(frequency); -				link.set_callsign(callsign); -				link.start_remote(); -			} else -				link.flush_input(); -			config_data = new AltosConfigData(link); - -			if (has_sensor_tm(config_data)) -				record = new AltosSensorTM(link, config_data); -			else if (has_sensor_mm(config_data)) -				record = sensor_mm(config_data); -			else -				record = new AltosRecordNone(); - -			if (has_gps(config_data)) -				gps = new AltosGPSQuery(link, config_data); - -			record.version = 0; -			record.callsign = config_data.callsign; -			record.serial = config_data.serial; -			record.flight = config_data.log_available() > 0 ? 255 : 0; -			record.status = 0; -			record.state = AltosLib.ao_flight_idle; -			record.gps = gps; -			record.gps_sequence++; -			state = new AltosState (record, state); +			start_link(); +			fetch.update_state(state); +			worked = true;  		} finally { -			if (remote) { -				link.stop_remote(); -				if (record != null) { -					record.rssi = link.rssi(); -					listener_state.battery = link.monitor_battery(); -				} -			} else { -				if (record != null) -					record.rssi = 0; +			stop_link(); +			if (worked) { +				if (remote) +					state.set_rssi(link.rssi(), 0); +				listener_state.battery = link.monitor_battery();  			}  		} -  	}  	public void set_frequency(double in_frequency) { @@ -139,10 +90,6 @@ public class AltosIdleMonitor extends Thread {  		link.abort_reply();  	} -	public void post_state() { -		listener.update(state, listener_state); -	} -  	public void abort() {  		if (isAlive()) {  			interrupt(); @@ -155,18 +102,20 @@ public class AltosIdleMonitor extends Thread {  	}  	public void run() { +		AltosState state = new AltosState();  		try { -			for (;;) { +			while (!link.has_error) {  				try { -					update_state(); -					post_state(); +					link.config_data(); +					update_state(state); +					listener.update(state, listener_state);  				} catch (TimeoutException te) {  				}  				Thread.sleep(1000);  			}  		} catch (InterruptedException ie) { -			link.close();  		} +		link.close();  	}  	public AltosIdleMonitor(AltosIdleMonitorListener in_listener, AltosLink in_link, boolean in_remote) @@ -174,7 +123,7 @@ public class AltosIdleMonitor extends Thread {  		listener = in_listener;  		link = in_link;  		remote = in_remote; -		state = null;  		listener_state = new AltosListenerState(); +		fetch = new AltosIdleFetch(link);  	}  }  | 
