diff options
Diffstat (limited to 'altoslib')
| -rw-r--r-- | altoslib/AltosAccelCal.java | 21 | ||||
| -rw-r--r-- | altoslib/AltosCalData.java | 2 | ||||
| -rw-r--r-- | altoslib/AltosConfigData.java | 98 | ||||
| -rw-r--r-- | altoslib/AltosDebug.java | 4 | ||||
| -rw-r--r-- | altoslib/AltosFlightSeries.java | 9 | ||||
| -rw-r--r-- | altoslib/AltosFlightStats.java | 4 | ||||
| -rw-r--r-- | altoslib/AltosHexfile.java | 20 | ||||
| -rw-r--r-- | altoslib/AltosIMU.java | 35 | ||||
| -rw-r--r-- | altoslib/AltosIdleFetch.java | 20 | ||||
| -rw-r--r-- | altoslib/AltosLib.java | 3 | ||||
| -rw-r--r-- | altoslib/AltosLink.java | 19 | ||||
| -rw-r--r-- | altoslib/AltosPyro.java | 19 | ||||
| -rw-r--r-- | altoslib/AltosRomconfig.java | 6 | 
13 files changed, 209 insertions, 51 deletions
diff --git a/altoslib/AltosAccelCal.java b/altoslib/AltosAccelCal.java index 03d9fbf2..f98090ef 100644 --- a/altoslib/AltosAccelCal.java +++ b/altoslib/AltosAccelCal.java @@ -174,22 +174,23 @@ public class AltosAccelCal implements Runnable {  				if (worked)  					new_config = new AltosConfigData(link);  			} finally { +				int plus = config_data.accel_cal_plus(config_data.pad_orientation); +				int minus = config_data.accel_cal_minus(config_data.pad_orientation);  				System.out.printf("Restore orientation %d +g %d -g %d\n",  						  config_data.pad_orientation, -						  config_data.accel_cal_plus, -						  config_data.accel_cal_minus); -				if (config_data.pad_orientation != AltosLib.MISSING && config_data.pad_orientation != 0) +						  plus, minus); +				if (config_data.pad_orientation != AltosLib.MISSING)  					link.printf("c o %d\n", config_data.pad_orientation); -				if (config_data.accel_cal_plus != AltosLib.MISSING && config_data.accel_cal_minus != AltosLib.MISSING) -					link.printf("c a %d %d\n", -						    config_data.accel_cal_plus, config_data.accel_cal_minus); +				if (plus != AltosLib.MISSING && minus != AltosLib.MISSING) +					link.printf("c a %d %d\n", plus, minus); +				link.flush_output();  				stop_link();  			}  			if (new_config != null) { -				System.out.printf("*** +1g %d -1g %d\n", -						  new_config.accel_cal_plus, -						  new_config.accel_cal_minus); -				listener.cal_done(this, new_config.accel_cal_plus, new_config.accel_cal_minus); +				int plus = new_config.accel_cal_plus(AltosLib.AO_PAD_ORIENTATION_ANTENNA_UP); +				int minus = new_config.accel_cal_minus(AltosLib.AO_PAD_ORIENTATION_ANTENNA_UP); +				System.out.printf("*** +1g %d -1g %d\n", plus, minus); +				listener.cal_done(this, plus, minus);  				if (!wait_signal())  					throw new InterruptedException("aborted");  			} else diff --git a/altoslib/AltosCalData.java b/altoslib/AltosCalData.java index 03e2cbd7..5bc6c4fd 100644 --- a/altoslib/AltosCalData.java +++ b/altoslib/AltosCalData.java @@ -397,7 +397,7 @@ public class AltosCalData {  		set_flight_params(config_data.apogee_delay / ticks_per_sec, config_data.apogee_lockout / ticks_per_sec);  		set_pad_orientation(config_data.pad_orientation);  		set_product(config_data.product); -		set_accel_plus_minus(config_data.accel_cal_plus, config_data.accel_cal_minus); +		set_accel_plus_minus(config_data.accel_cal_plus(config_data.pad_orientation), config_data.accel_cal_minus(config_data.pad_orientation));  		set_accel_zero(config_data.accel_zero_along, config_data.accel_zero_across, config_data.accel_zero_through);  		set_ms5607(config_data.ms5607);  		try { diff --git a/altoslib/AltosConfigData.java b/altoslib/AltosConfigData.java index dc036867..8d0bb479 100644 --- a/altoslib/AltosConfigData.java +++ b/altoslib/AltosConfigData.java @@ -22,6 +22,7 @@ import java.util.*;  import java.text.*;  import java.util.concurrent.*; +/* Don't change the field names in this structure; they're part of all .eeprom files */  public class AltosConfigData {  	/* Version information */ @@ -53,6 +54,8 @@ public class AltosConfigData {  	/* HAS_ACCEL */  	public int	accel_cal_plus, accel_cal_minus; +	private int	accel_cal_plus_cooked, accel_cal_minus_cooked; +	private boolean	accel_cal_adjusted;  	public int	pad_orientation;  	/* HAS_LOG */ @@ -186,6 +189,23 @@ public class AltosConfigData {  		}  	} +	public int invert_accel_value(int value) { +		if (value == AltosLib.MISSING) +			return AltosLib.MISSING; + +		switch (log_format) { +		case AltosLib.AO_LOG_FORMAT_FULL: +			return 0x7fff - value; +		case AltosLib.AO_LOG_FORMAT_TELEMEGA_OLD: +		case AltosLib.AO_LOG_FORMAT_TELEMETRUM: +		case AltosLib.AO_LOG_FORMAT_TELEMEGA: +		case AltosLib.AO_LOG_FORMAT_TELEMEGA_3: +			return 4095 - value; +		default: +			return AltosLib.MISSING; +		} +	} +  	public boolean has_monitor_battery() {  		if (product.startsWith("TeleBT"))  			return true; @@ -252,9 +272,12 @@ public class AltosConfigData {  		radio_setting = AltosLib.MISSING;  		telemetry_rate = AltosLib.MISSING; +		accel_cal_plus_cooked = AltosLib.MISSING; +		accel_cal_minus_cooked = AltosLib.MISSING;  		accel_cal_plus = AltosLib.MISSING;  		accel_cal_minus = AltosLib.MISSING;  		pad_orientation = AltosLib.MISSING; +		accel_cal_adjusted = false;  		flight_log_max = AltosLib.MISSING;  		log_fixed = AltosLib.MISSING; @@ -285,6 +308,59 @@ public class AltosConfigData {  		accel_zero_through = AltosLib.MISSING;  	} +	/* Return + accel calibration relative to a specific pad orientation */ +	public int accel_cal_plus(int pad_orientation) { +		adjust_accel_cal(); +		switch (pad_orientation) { +		case AltosLib.AO_PAD_ORIENTATION_ANTENNA_UP: +			return accel_cal_plus_cooked; +		case AltosLib.AO_PAD_ORIENTATION_ANTENNA_DOWN: +			return invert_accel_value(accel_cal_minus_cooked); +		default: +			return AltosLib.MISSING; +		} +	} + +	/* Return - accel calibration relative to a specific pad orientation */ +	public int accel_cal_minus(int pad_orientation) { +		adjust_accel_cal(); +		switch (pad_orientation) { +		case AltosLib.AO_PAD_ORIENTATION_ANTENNA_UP: +			return accel_cal_minus_cooked; +		case AltosLib.AO_PAD_ORIENTATION_ANTENNA_DOWN: +			return invert_accel_value(accel_cal_plus_cooked); +		default: +			return AltosLib.MISSING; +		} +	} + +	/* Once we have all of the values from the config data, compute the +	 * accel cal values relative to Antenna Up orientation. +	 */ +	private void adjust_accel_cal() { +		if (!accel_cal_adjusted && +		    pad_orientation != AltosLib.MISSING && +		    accel_cal_plus != AltosLib.MISSING && +		    accel_cal_minus != AltosLib.MISSING && +		    log_format != AltosLib.AO_LOG_FORMAT_UNKNOWN) +		{ +			switch (pad_orientation) { +			case AltosLib.AO_PAD_ORIENTATION_ANTENNA_UP: +				accel_cal_plus_cooked = accel_cal_plus; +				accel_cal_minus_cooked = accel_cal_minus; +				accel_cal_adjusted = true; +				break; +			case AltosLib.AO_PAD_ORIENTATION_ANTENNA_DOWN: +				accel_cal_plus_cooked = invert_accel_value(accel_cal_minus); +				accel_cal_minus_cooked = invert_accel_value(accel_cal_plus); +				accel_cal_adjusted = true; +				break; +			default: +				break; +			} +		} +	} +  	public void parse_line(String line) {  		/* Version replies */ @@ -351,6 +427,7 @@ public class AltosConfigData {  				if (bits.length >= 6) {  					accel_cal_plus = Integer.parseInt(bits[3]);  					accel_cal_minus = Integer.parseInt(bits[5]); +					accel_cal_adjusted = false;  				}  			}  		} catch (Exception e) {} @@ -414,6 +491,9 @@ public class AltosConfigData {  				}  			}  		} catch (Exception e) {} + +		/* Fix accel cal as soon as all of the necessary values appear */ +		adjust_accel_cal();  	}  	public AltosConfigData() { @@ -525,11 +605,11 @@ public class AltosConfigData {  		if (pad_orientation != AltosLib.MISSING)  			pad_orientation = source.pad_orientation(); -		if (accel_cal_plus != AltosLib.MISSING) -			accel_cal_plus = source.accel_cal_plus(); +		if (accel_cal_plus_cooked != AltosLib.MISSING) +			accel_cal_plus_cooked = source.accel_cal_plus(); -		if (accel_cal_minus != AltosLib.MISSING) -			accel_cal_minus = source.accel_cal_minus(); +		if (accel_cal_minus_cooked != AltosLib.MISSING) +			accel_cal_minus_cooked = source.accel_cal_minus();  		/* HAS_LOG */  		if (flight_log_max != AltosLib.MISSING) @@ -598,7 +678,8 @@ public class AltosConfigData {  		dest.set_flight_log_max(flight_log_max);  		dest.set_ignite_mode(ignite_mode);  		dest.set_pad_orientation(pad_orientation); -		dest.set_accel_cal(accel_cal_plus, accel_cal_minus); +		dest.set_accel_cal(accel_cal_plus(AltosLib.AO_PAD_ORIENTATION_ANTENNA_UP), +				   accel_cal_minus(AltosLib.AO_PAD_ORIENTATION_ANTENNA_UP));  		dest.set_callsign(callsign);  		if (npyro != AltosLib.MISSING)  			dest.set_pyros(pyros); @@ -676,10 +757,13 @@ public class AltosConfigData {  			link.printf("c e %d\n", radio_enable);  		/* HAS_ACCEL */ +		/* set orientation first so that we know how to set the accel cal */  		if (pad_orientation != AltosLib.MISSING)  			link.printf("c o %d\n", pad_orientation); -		if (accel_cal_plus != AltosLib.MISSING && accel_cal_minus != AltosLib.MISSING) -			link.printf("c a %d %d\n", accel_cal_plus, accel_cal_minus); +		int plus = accel_cal_plus(pad_orientation); +		int minus = accel_cal_minus(pad_orientation); +		if (plus != AltosLib.MISSING && minus != AltosLib.MISSING) +			link.printf("c a %d %d\n", plus, minus);  		/* HAS_LOG */  		if (flight_log_max != 0) diff --git a/altoslib/AltosDebug.java b/altoslib/AltosDebug.java index 24a25933..a44eb12f 100644 --- a/altoslib/AltosDebug.java +++ b/altoslib/AltosDebug.java @@ -264,8 +264,8 @@ public class AltosDebug {  	public AltosRomconfig romconfig() throws InterruptedException {  		try { -			byte[] bytes = read_memory(0xa0, 10); -			AltosHexfile hexfile = new AltosHexfile (bytes, 0xa0); +			byte[] bytes = read_memory(0x00, 0x200); +			AltosHexfile hexfile = new AltosHexfile (bytes, 0x00);  			return new AltosRomconfig(hexfile);  		} catch (IOException ie) {  		} diff --git a/altoslib/AltosFlightSeries.java b/altoslib/AltosFlightSeries.java index d130d3ad..182bdd19 100644 --- a/altoslib/AltosFlightSeries.java +++ b/altoslib/AltosFlightSeries.java @@ -257,6 +257,15 @@ public class AltosFlightSeries extends AltosDataListener {  	public AltosTimeSeries height_series; +	public double max_height = AltosLib.MISSING; + +	public	void set_min_pressure(double pa) { +		double ground_altitude = cal_data().ground_altitude; +		if (ground_altitude != AltosLib.MISSING) +			max_height = AltosConvert.pressure_to_altitude(pa) - +				ground_altitude; +	} +  	public static final String height_name = "Height";  	public  void set_pressure(double pa) { diff --git a/altoslib/AltosFlightStats.java b/altoslib/AltosFlightStats.java index 6bb83581..2760321d 100644 --- a/altoslib/AltosFlightStats.java +++ b/altoslib/AltosFlightStats.java @@ -266,8 +266,8 @@ public class AltosFlightStats {  			}  		} -		max_height = AltosLib.MISSING; -		if (series.height_series != null) +		max_height = series.max_height; +		if (max_height == AltosLib.MISSING && series.height_series != null)  			max_height = series.height_series.max().value;  		max_gps_height = AltosLib.MISSING;  		if (series.gps_height != null) { diff --git a/altoslib/AltosHexfile.java b/altoslib/AltosHexfile.java index 6aa98383..f2ab4bea 100644 --- a/altoslib/AltosHexfile.java +++ b/altoslib/AltosHexfile.java @@ -294,15 +294,19 @@ public class AltosHexfile {  		if (usb_descriptors == null)  			return -1; -		/* Walk the descriptors looking for the device */ -		a = usb_descriptors.address; -		while (get_u8(a+1) != AO_USB_DESC_DEVICE) { -			int delta = get_u8(a); -			a += delta; -			if (delta == 0 || a >= max_address) -				return -1; +		try { +			/* Walk the descriptors looking for the device */ +			a = usb_descriptors.address; +			while (get_u8(a+1) != AO_USB_DESC_DEVICE) { +				int delta = get_u8(a); +				a += delta; +				if (delta == 0 || a >= max_address) +					return -1; +			} +			return a; +		} catch (ArrayIndexOutOfBoundsException ae) { +			return -1;  		} -		return a;  	}  	public AltosUsbId find_usb_id() { diff --git a/altoslib/AltosIMU.java b/altoslib/AltosIMU.java index ba6f1a82..df81c9dd 100644 --- a/altoslib/AltosIMU.java +++ b/altoslib/AltosIMU.java @@ -22,13 +22,17 @@ import java.util.concurrent.*;  import java.io.*;  public class AltosIMU implements Cloneable { -	public int		accel_x; -	public int		accel_y; -	public int		accel_z; +	public int		accel_x = AltosLib.MISSING; +	public int		accel_y = AltosLib.MISSING; +	public int		accel_z = AltosLib.MISSING; -	public int		gyro_x; -	public int		gyro_y; -	public int		gyro_z; +	public int		gyro_x = AltosLib.MISSING; +	public int		gyro_y = AltosLib.MISSING; +	public int		gyro_z = AltosLib.MISSING; + +	public int		mag_x = AltosLib.MISSING; +	public int		mag_y = AltosLib.MISSING; +	public int		mag_z = AltosLib.MISSING;  	public static final double	counts_per_g = 2048.0; @@ -58,6 +62,11 @@ public class AltosIMU implements Cloneable {  			gyro_y = Integer.parseInt(items[6]);  			gyro_z = Integer.parseInt(items[7]);  		} +		if (items.length >= 12) { +			mag_x = Integer.parseInt(items[9]); +			mag_y = Integer.parseInt(items[10]); +			mag_z = Integer.parseInt(items[11]); +		}  		return true;  	} @@ -71,6 +80,11 @@ public class AltosIMU implements Cloneable {  		n.gyro_x = gyro_x;  		n.gyro_y = gyro_y;  		n.gyro_z = gyro_z; + +		n.mag_x = mag_x; +		n.mag_y = mag_y; +		n.mag_z = mag_z; +  		return n;  	} @@ -86,6 +100,11 @@ public class AltosIMU implements Cloneable {  				listener.set_accel_ground(imu.accel_y,  							  imu.accel_x,  							  imu.accel_z); +				if (imu.mag_x != AltosLib.MISSING) { +					listener.set_mag(cal_data.mag_along(imu.mag_y), +							 cal_data.mag_across(imu.mag_x), +							 cal_data.mag_through(imu.mag_z)); +				}  			}  		} catch (TimeoutException te) {  		} @@ -99,6 +118,10 @@ public class AltosIMU implements Cloneable {  		gyro_x = AltosLib.MISSING;  		gyro_y = AltosLib.MISSING;  		gyro_z = AltosLib.MISSING; + +		mag_x = AltosLib.MISSING; +		mag_y = AltosLib.MISSING; +		mag_z = AltosLib.MISSING;  	}  	public AltosIMU(AltosLink link) throws InterruptedException, TimeoutException { diff --git a/altoslib/AltosIdleFetch.java b/altoslib/AltosIdleFetch.java index 058df0a1..88a5dab4 100644 --- a/altoslib/AltosIdleFetch.java +++ b/altoslib/AltosIdleFetch.java @@ -133,12 +133,30 @@ public class AltosIdleFetch implements AltosDataProvider {  			       AltosIdler.idle_ms5607,  			       AltosIdler.idle_sensor_metrum), -		new AltosIdler("TeleMega", +		new AltosIdler("TeleMega-v0",  			       AltosIdler.idle_gps,  			       AltosIdler.idle_mma655x,  			       AltosIdler.idle_ms5607,  			       AltosIdler.idle_imu, AltosIdler.idle_mag,  			       AltosIdler.idle_sensor_mega), +		new AltosIdler("TeleMega-v1", +			       AltosIdler.idle_gps, +			       AltosIdler.idle_mma655x, +			       AltosIdler.idle_ms5607, +			       AltosIdler.idle_imu, AltosIdler.idle_mag, +			       AltosIdler.idle_sensor_mega), +		new AltosIdler("TeleMega-v2", +			       AltosIdler.idle_gps, +			       AltosIdler.idle_mma655x, +			       AltosIdler.idle_ms5607, +			       AltosIdler.idle_imu, AltosIdler.idle_mag, +			       AltosIdler.idle_sensor_mega), +		new AltosIdler("TeleMega-v3", +			       AltosIdler.idle_gps, +			       AltosIdler.idle_mma655x, +			       AltosIdler.idle_ms5607, +			       AltosIdler.idle_imu, +			       AltosIdler.idle_sensor_mega),  		new AltosIdler("EasyMega",  			       AltosIdler.idle_mma655x,  			       AltosIdler.idle_ms5607, diff --git a/altoslib/AltosLib.java b/altoslib/AltosLib.java index c25a6273..7d2b68e0 100644 --- a/altoslib/AltosLib.java +++ b/altoslib/AltosLib.java @@ -348,6 +348,9 @@ public class AltosLib {  	public static final int AO_GPS_NUM_SAT_SHIFT = 0;  	public static final int AO_GPS_NUM_SAT_MASK = 0xf; +	public static final int AO_PAD_ORIENTATION_ANTENNA_UP = 0; +	public static final int AO_PAD_ORIENTATION_ANTENNA_DOWN = 1; +  	public static final int AO_LOG_FORMAT_UNKNOWN = 0;  	public static final int AO_LOG_FORMAT_FULL = 1;  	public static final int AO_LOG_FORMAT_TINY = 2; diff --git a/altoslib/AltosLink.java b/altoslib/AltosLink.java index 829a1a63..3ad34891 100644 --- a/altoslib/AltosLink.java +++ b/altoslib/AltosLink.java @@ -339,9 +339,22 @@ public abstract class AltosLink implements Runnable {  	public void flush_input() throws InterruptedException { -		if (remote) -			flush_input(500); -		else +		if (remote) { +			int timeout = 500; +			switch (telemetry_rate) { +			case AltosLib.ao_telemetry_rate_38400: +			default: +				timeout = 500; +				break; +			case AltosLib.ao_telemetry_rate_9600: +				timeout = 1000; +				break; +			case AltosLib.ao_telemetry_rate_2400: +				timeout = 2000; +				break; +			} +			flush_input(timeout); +		} else  			flush_input(100);  	} diff --git a/altoslib/AltosPyro.java b/altoslib/AltosPyro.java index 0ea3bfc1..fea4fd59 100644 --- a/altoslib/AltosPyro.java +++ b/altoslib/AltosPyro.java @@ -29,24 +29,24 @@ public class AltosPyro {  	public static final int pyro_accel_greater		= 0x00000002;  	public static final String pyro_accel_less_string	= "a<";  	public static final String pyro_accel_greater_string	= "a>"; -	public static final String pyro_accel_less_name		= "Acceleration less than"; -	public static final String pyro_accel_greater_name	= "Acceleration greater than"; +	public static final String pyro_accel_less_name		= "Vertical acceleration less than"; +	public static final String pyro_accel_greater_name	= "Vertical acceleration greater than";  	public static final double pyro_accel_scale		= 16.0;  	public static final int pyro_speed_less			= 0x00000004;  	public static final int pyro_speed_greater		= 0x00000008;  	public static final String pyro_speed_less_string	= "s<";  	public static final String pyro_speed_greater_string	= "s>"; -	public static final String pyro_speed_less_name		= "Speed less than"; -	public static final String pyro_speed_greater_name	= "Speed greater than"; +	public static final String pyro_speed_less_name		= "Ascent rate less than"; +	public static final String pyro_speed_greater_name	= "Ascent rate greater than";  	public static final double pyro_speed_scale		= 16.0;  	public static final int pyro_height_less		= 0x00000010;  	public static final int pyro_height_greater		= 0x00000020;  	public static final String pyro_height_less_string	= "h<";  	public static final String pyro_height_greater_string	= "h>"; -	public static final String pyro_height_less_name	= "Height less than"; -	public static final String pyro_height_greater_name	= "Height greater than"; +	public static final String pyro_height_less_name	= "Height above pad less than"; +	public static final String pyro_height_greater_name	= "Height above pad greater than";  	public static final double pyro_height_scale		= 1.0;  	public static final int pyro_orient_less		= 0x00000040; @@ -61,8 +61,8 @@ public class AltosPyro {  	public static final int pyro_time_greater		= 0x00000200;  	public static final String pyro_time_less_string	= "t<";  	public static final String pyro_time_greater_string	= "t>"; -	public static final String pyro_time_less_name		= "Time since boost less than (s)"; -	public static final String pyro_time_greater_name	= "Time since boost greater than (s)"; +	public static final String pyro_time_less_name		= "Time since launch less than (s)"; +	public static final String pyro_time_greater_name	= "Time since launch greater than (s)";  	public static final double pyro_time_scale		= 100.0;  	public static final int pyro_ascending			= 0x00000400; @@ -90,7 +90,10 @@ public class AltosPyro {  	public static final String pyro_state_greater_or_equal_name	= "Flight state after";  	public static final double pyro_state_scale		= 1.0; +	public static final int pyro_deprecate			= pyro_ascending | pyro_descending; +  	public static final int	pyro_all			= 0x0000ffff; +	public static final int pyro_all_useful			= pyro_all ^ pyro_deprecate;  	public static final int pyro_no_value			= (pyro_ascending |  								   pyro_descending); diff --git a/altoslib/AltosRomconfig.java b/altoslib/AltosRomconfig.java index 1fbb4115..44a3fa60 100644 --- a/altoslib/AltosRomconfig.java +++ b/altoslib/AltosRomconfig.java @@ -35,12 +35,12 @@ public class AltosRomconfig {  			System.out.printf("no symbol %s\n", name);  			throw new AltosNoSymbol(name);  		} -		if (hexfile.address <= symbol.address && symbol.address + len < hexfile.max_address) { +		if (hexfile.address <= symbol.address && symbol.address + len <= hexfile.max_address) {  			System.out.printf("%s: %x\n", name, symbol.address);  			return symbol.address;  		} -		System.out.printf("invalid symbol addr %x range is %x - %x\n", -				  symbol.address, hexfile.address, hexfile.max_address); +		System.out.printf("invalid symbol addr %x len %d range is %x - %x\n", +				  symbol.address, len, hexfile.address, hexfile.max_address);  		throw new AltosNoSymbol(name);  	}  | 
