diff options
| -rw-r--r-- | altosdroid/src/org/altusmetrum/AltosDroid/TelemetryService.java | 4 | ||||
| -rw-r--r-- | altoslib/AltosConfigData.java | 12 | ||||
| -rw-r--r-- | altoslib/AltosIdleFetch.java | 8 | ||||
| -rw-r--r-- | altoslib/AltosIdleMonitor.java | 4 | ||||
| -rw-r--r-- | altoslib/AltosIdleMonitorListener.java | 1 | ||||
| -rw-r--r-- | altoslib/AltosMma655x.java | 14 | ||||
| -rw-r--r-- | altoslib/AltosStateUpdate.java | 4 | ||||
| -rw-r--r-- | altoslib/AltosUnknownProduct.java | 26 | ||||
| -rw-r--r-- | altoslib/Makefile.am | 1 | ||||
| -rw-r--r-- | altosui/AltosIdleMonitorUI.java | 13 | 
10 files changed, 78 insertions, 9 deletions
| diff --git a/altosdroid/src/org/altusmetrum/AltosDroid/TelemetryService.java b/altosdroid/src/org/altusmetrum/AltosDroid/TelemetryService.java index 7c5fde50..3c1a1782 100644 --- a/altosdroid/src/org/altusmetrum/AltosDroid/TelemetryService.java +++ b/altosdroid/src/org/altusmetrum/AltosDroid/TelemetryService.java @@ -700,4 +700,8 @@ public class TelemetryService extends Service implements AltosIdleMonitorListene  	public void failed() {  	} + +	public void error(String reason) { +		stop_idle_monitor(); +	}  } diff --git a/altoslib/AltosConfigData.java b/altoslib/AltosConfigData.java index 7affbdec..812296f3 100644 --- a/altoslib/AltosConfigData.java +++ b/altoslib/AltosConfigData.java @@ -476,6 +476,18 @@ public class AltosConfigData implements Iterable<String> {  	} +	public boolean mma655x_inverted() throws AltosUnknownProduct { +		if (product.startsWith("EasyMega-v1")) +			return false; +		if (product.startsWith("TeleMetrum-v2")) +			return true; +		if (product.startsWith("TeleMega-v2")) +			return false; +		if (product.startsWith("TeleMega-v1")) +			return false; +		throw new AltosUnknownProduct(product); +	} +  	public void get_values(AltosConfigValues source) throws AltosConfigDataException {  		/* HAS_FLIGHT */ diff --git a/altoslib/AltosIdleFetch.java b/altoslib/AltosIdleFetch.java index 3e96f3b8..0095bb73 100644 --- a/altoslib/AltosIdleFetch.java +++ b/altoslib/AltosIdleFetch.java @@ -40,7 +40,7 @@ class AltosIdler {  	static final int	idle_sensor_tmini = 14;  	static final int	idle_sensor_tgps = 15; -	public void update_state(AltosState state, AltosLink link, AltosConfigData config_data) throws InterruptedException, TimeoutException { +	public void update_state(AltosState state, AltosLink link, AltosConfigData config_data) throws InterruptedException, TimeoutException, AltosUnknownProduct {  		for (int idler : idlers) {  			AltosIdle idle = null;  			switch (idler) { @@ -137,8 +137,9 @@ public class AltosIdleFetch implements AltosStateUpdate {  	double			frequency;  	String			callsign; -	public void update_state(AltosState state) throws InterruptedException { +	public void update_state(AltosState state) throws InterruptedException, AltosUnknownProduct {  		try { +			boolean	matched = false;  			/* Fetch config data from remote */  			AltosConfigData config_data = new AltosConfigData(link);  			state.set_state(AltosLib.ao_flight_stateless); @@ -150,9 +151,12 @@ public class AltosIdleFetch implements AltosStateUpdate {  			for (AltosIdler idler : idlers) {  				if (idler.matches(config_data)) {  					idler.update_state(state, link, config_data); +					matched = true;  					break;  				}  			} +			if (!matched) +				throw new AltosUnknownProduct(config_data.product);  			state.set_received_time(System.currentTimeMillis());  		} catch (TimeoutException te) {  		} diff --git a/altoslib/AltosIdleMonitor.java b/altoslib/AltosIdleMonitor.java index bcf20ef3..c67b4d8a 100644 --- a/altoslib/AltosIdleMonitor.java +++ b/altoslib/AltosIdleMonitor.java @@ -51,7 +51,7 @@ public class AltosIdleMonitor extends Thread {  		return link.reply_abort;  	} -	boolean update_state(AltosState state) throws InterruptedException, TimeoutException { +	boolean update_state(AltosState state) throws InterruptedException, TimeoutException, AltosUnknownProduct {  		boolean		worked = false;  		boolean		aborted = false; @@ -99,6 +99,8 @@ public class AltosIdleMonitor extends Thread {  					update_state(state);  					listener.update(state, listener_state);  				} catch (TimeoutException te) { +				} catch (AltosUnknownProduct ae) { +					listener.error(String.format("Unknown product \"%s\"", ae.product));  				}  				if (link.has_error || link.reply_abort) {  					listener.failed(); diff --git a/altoslib/AltosIdleMonitorListener.java b/altoslib/AltosIdleMonitorListener.java index 235e609e..36857f58 100644 --- a/altoslib/AltosIdleMonitorListener.java +++ b/altoslib/AltosIdleMonitorListener.java @@ -19,5 +19,6 @@ package org.altusmetrum.altoslib_10;  public interface AltosIdleMonitorListener {  	public void update(AltosState state, AltosListenerState listener_state); +	public void error(String reason);  	public void failed();  } diff --git a/altoslib/AltosMma655x.java b/altoslib/AltosMma655x.java index da57c27f..b09ec74b 100644 --- a/altoslib/AltosMma655x.java +++ b/altoslib/AltosMma655x.java @@ -21,7 +21,7 @@ import java.util.concurrent.*;  public class AltosMma655x implements Cloneable { -	int	accel; +	private int	accel;  	public boolean parse_line(String line) throws NumberFormatException {  		if (line.startsWith("MMA655X value")) { @@ -45,12 +45,18 @@ public class AltosMma655x implements Cloneable {  		return n;  	} -	static public void update_state(AltosState state, AltosLink link, AltosConfigData config_data) throws InterruptedException { +	static public void update_state(AltosState state, AltosLink link, AltosConfigData config_data) throws InterruptedException, AltosUnknownProduct {  		try {  			AltosMma655x	mma655x = new AltosMma655x(link); -			if (mma655x != null) -				state.set_accel(mma655x.accel); +			if (mma655x != null) { +				int accel = mma655x.accel; +				if (config_data.mma655x_inverted()) +					accel = 4095 - accel; +				if (config_data.pad_orientation == 1) +					accel = 4095 - accel; +				state.set_accel(accel); +			}  		} catch (TimeoutException te) {  		} catch (NumberFormatException ne) {  		} diff --git a/altoslib/AltosStateUpdate.java b/altoslib/AltosStateUpdate.java index cfc010a1..12d4dd41 100644 --- a/altoslib/AltosStateUpdate.java +++ b/altoslib/AltosStateUpdate.java @@ -18,5 +18,5 @@  package org.altusmetrum.altoslib_10;  public interface AltosStateUpdate { -	public void	update_state(AltosState state) throws InterruptedException; -}
\ No newline at end of file +	public void	update_state(AltosState state) throws InterruptedException, AltosUnknownProduct; +} diff --git a/altoslib/AltosUnknownProduct.java b/altoslib/AltosUnknownProduct.java new file mode 100644 index 00000000..ff536f57 --- /dev/null +++ b/altoslib/AltosUnknownProduct.java @@ -0,0 +1,26 @@ +/* + * Copyright © 2010 Keith Packard <keithp@keithp.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ + +package org.altusmetrum.altoslib_10; + +public class AltosUnknownProduct extends Exception { +	public String product; + +	public AltosUnknownProduct (String in_product) { +		product = in_product; +	} +} diff --git a/altoslib/Makefile.am b/altoslib/Makefile.am index 73638782..dc9da8fd 100644 --- a/altoslib/Makefile.am +++ b/altoslib/Makefile.am @@ -113,6 +113,7 @@ altoslib_JAVA = \  	AltosTelemetrySatellite.java \  	AltosTelemetryStandard.java \  	AltosUnitsListener.java \ +	AltosUnknownProduct.java \  	AltosMs5607.java \  	AltosIMU.java \  	AltosMag.java \ diff --git a/altosui/AltosIdleMonitorUI.java b/altosui/AltosIdleMonitorUI.java index 2f14e2df..d789de77 100644 --- a/altosui/AltosIdleMonitorUI.java +++ b/altosui/AltosIdleMonitorUI.java @@ -128,6 +128,19 @@ public class AltosIdleMonitorUI extends AltosUIFrame implements AltosFlightDispl  		SwingUtilities.invokeLater(r);  	} +	public void error(final String reason) { +		Runnable r = new Runnable() { +				public void run() { +					disconnect(); +					JOptionPane.showMessageDialog(AltosIdleMonitorUI.this, +								      reason, +								      "Error fetching data", +								      JOptionPane.ERROR_MESSAGE); +				} +			}; +		SwingUtilities.invokeLater(r); +	} +  	Container	bag;  	AltosUIFreqList	frequencies;  	JTextField	callsign_value; | 
