diff options
| author | Mike Beattie <mike@ethernal.org> | 2012-08-08 06:46:56 +1200 | 
|---|---|---|
| committer | Mike Beattie <mike@ethernal.org> | 2012-08-08 06:46:56 +1200 | 
| commit | bd02349111ae0f39b320e6a10a330051ddc39fdf (patch) | |
| tree | ab7a29204eea195db77aa302fbe3e2012ef5049e /altoslib | |
| parent | 8e4ebd1f6eb928b5cb7bcda4ed88851aa9e61bdf (diff) | |
| parent | c7f228503870c44dfd278ede8b0980dbac73d3c7 (diff) | |
Merge branch 'master' of git://git.gag.com/fw/altos
Diffstat (limited to 'altoslib')
| -rw-r--r-- | altoslib/AltosIdleMonitor.java | 67 | ||||
| -rw-r--r-- | altoslib/AltosLink.java | 22 | ||||
| -rw-r--r-- | altoslib/AltosRecord.java | 2 | ||||
| -rw-r--r-- | altoslib/AltosRecordTM.java | 16 | ||||
| -rw-r--r-- | altoslib/AltosState.java | 2 | 
5 files changed, 57 insertions, 52 deletions
diff --git a/altoslib/AltosIdleMonitor.java b/altoslib/AltosIdleMonitor.java index 57c4da71..27ea3a2b 100644 --- a/altoslib/AltosIdleMonitor.java +++ b/altoslib/AltosIdleMonitor.java @@ -23,16 +23,10 @@ import java.text.*;  import java.util.prefs.*;  import java.util.concurrent.*; -class AltosSensorTM { -	int	tick; -	int	accel; -	int	pres; -	int	temp; -	int	batt; -	int	drogue; -	int	main; +class AltosSensorTM extends AltosRecordTM { -	public AltosSensorTM(AltosLink link) throws InterruptedException, TimeoutException { +	public AltosSensorTM(AltosLink link, AltosConfigData config_data) throws InterruptedException, TimeoutException { +		super();  		link.printf("a\n");  		for (;;) {  			String line = link.get_reply_no_dialog(5000); @@ -82,6 +76,10 @@ class AltosSensorTM {  			}  			break;  		} +		ground_accel = config_data.accel_cal_plus; +		ground_pres = pres; +		accel_plus_g = config_data.accel_cal_plus; +		accel_minus_g = config_data.accel_cal_minus;  	}  } @@ -253,7 +251,7 @@ class AltosGPSQuery extends AltosGPS {  			if (line.startsWith("Date:")) {  				if (bits.length < 2)  					continue; -				String[] d = bits[1].split(":"); +				String[] d = bits[1].split("/");  				if (d.length < 3)  					continue;  				year = Integer.parseInt(d[0]) + 2000; @@ -264,7 +262,7 @@ class AltosGPSQuery extends AltosGPS {  			if (line.startsWith("Time:")) {  				if (bits.length < 2)  					continue; -				String[] d = bits[1].split("/"); +				String[] d = bits[1].split(":");  				if (d.length < 3)  					continue;  				hour = Integer.parseInt(d[0]); @@ -339,8 +337,7 @@ public class AltosIdleMonitor extends Thread {  	}  	void update_state() throws InterruptedException, TimeoutException { -		AltosRecord	record; -		int		rssi; +		AltosRecord	record = null;  		try {  			if (remote) { @@ -350,20 +347,7 @@ public class AltosIdleMonitor extends Thread {  				link.flush_input();  			config_data = new AltosConfigData(link);  			if (config_data.product.startsWith("TeleMetrum")) { -				AltosRecordTM record_tm = new AltosRecordTM(); -				AltosSensorTM sensor = new AltosSensorTM(link); -				record_tm.accel = sensor.accel; -				record_tm.pres = sensor.pres; -				record_tm.batt = sensor.batt; -				record_tm.temp = sensor.temp; -				record_tm.drogue = sensor.drogue; -				record_tm.main = sensor.main; -				record_tm.ground_accel = record_tm.accel; -				record_tm.ground_pres = record_tm.pres; -				record_tm.accel_plus_g = config_data.accel_cal_plus; -				record_tm.accel_minus_g = config_data.accel_cal_minus; -				record_tm.tick = sensor.tick; -				record = record_tm; +				record = new AltosSensorTM(link, config_data);  			} else if (config_data.product.startsWith("MegaMetrum")) {  				AltosRecordMM record_mm = new AltosRecordMM();  				AltosSensorMM sensor = new AltosSensorMM(link); @@ -390,24 +374,27 @@ public class AltosIdleMonitor extends Thread {  				record = new AltosRecord();  			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.new_gps = true; +			state = new AltosState (record, state);  		} finally {  			if (remote) {  				link.stop_remote(); -				rssi = AltosRSSI(); -			} else -				rssi = 0; +				if (record != null) +					record.rssi = AltosRSSI(); +			} else { +				if (record != null) +					record.rssi = 0; +			}  		} -		record.version = 0; -		record.callsign = config_data.callsign; -		record.serial = config_data.serial; -		record.flight = config_data.log_available() > 0 ? 255 : 0; -		record.rssi = rssi; -		record.status = 0; -		record.state = AltosLib.ao_flight_idle; - -		record.gps = gps; -		state = new AltosState (record, state);  	}  	public void set_frequency(double in_frequency) { diff --git a/altoslib/AltosLink.java b/altoslib/AltosLink.java index d59e73ba..415c3c64 100644 --- a/altoslib/AltosLink.java +++ b/altoslib/AltosLink.java @@ -23,7 +23,7 @@ import java.util.concurrent.*;  import java.util.*;  import java.text.*; -public abstract class AltosLink { +public abstract class AltosLink implements Runnable {  	public final static int ERROR = -1;  	public final static int TIMEOUT = -2; @@ -101,15 +101,23 @@ public abstract class AltosLink {  		try {  			for (;;) {  				c = getchar(); -				if (Thread.interrupted()) +				if (Thread.interrupted()) { +					if (debug) +						System.out.printf("INTERRUPTED\n");  					break; +				}  				if (c == ERROR) { +					if (debug) +						System.out.printf("ERROR\n");  					add_telem (new AltosLine());  					add_reply (new AltosLine());  					break;  				} -				if (c == TIMEOUT) +				if (c == TIMEOUT) { +					if (debug) +						System.out.printf("TIMEOUT\n");  					continue; +				}  				if (c == '\r')  					continue;  				synchronized(this) { @@ -180,6 +188,14 @@ public abstract class AltosLink {  		reply_queue.put (line);  	} +	public void abort_reply() { +		try { +			add_telem (new AltosLine()); +			add_reply (new AltosLine()); +		} catch (InterruptedException e) { +		} +	} +  	public void add_string(String line) throws InterruptedException {  		if (line.startsWith("TELEM") || line.startsWith("VERSION") || line.startsWith("CRC")) {  			add_telem(new AltosLine(line)); diff --git a/altoslib/AltosRecord.java b/altoslib/AltosRecord.java index e468f84b..8722bc05 100644 --- a/altoslib/AltosRecord.java +++ b/altoslib/AltosRecord.java @@ -127,7 +127,7 @@ public class AltosRecord implements Comparable <AltosRecord>, Cloneable {  		double	p = filtered_pressure();  		if (p == MISSING) -			return MISSING; +			return raw_altitude();  		return AltosConvert.pressure_to_altitude(p);  	} diff --git a/altoslib/AltosRecordTM.java b/altoslib/AltosRecordTM.java index afb70790..37accef6 100644 --- a/altoslib/AltosRecordTM.java +++ b/altoslib/AltosRecordTM.java @@ -177,14 +177,14 @@ public class AltosRecordTM extends AltosRecord {  		drogue = MISSING;  		main = MISSING; -		flight_accel = 0; -		flight_vel = 0; -		flight_pres = 0; - -		ground_accel = 0; -		ground_pres = 0; -		accel_plus_g = 0; -		accel_minus_g = 0; +		flight_accel = MISSING; +		flight_vel = MISSING; +		flight_pres = MISSING; + +		ground_accel = MISSING; +		ground_pres = MISSING; +		accel_plus_g = MISSING; +		accel_minus_g = MISSING;  	}  	public AltosRecordTM(AltosRecord old) { diff --git a/altoslib/AltosState.java b/altoslib/AltosState.java index e20ec9a7..3b37a3d4 100644 --- a/altoslib/AltosState.java +++ b/altoslib/AltosState.java @@ -38,6 +38,7 @@ public class AltosState {  	public boolean boost;	/* under power */  	public double	ground_altitude; +	public double	altitude;  	public double	height;  	public double	speed;  	public double	acceleration; @@ -82,6 +83,7 @@ public class AltosState {  		data = cur;  		ground_altitude = data.ground_altitude(); +		altitude = data.raw_altitude();  		height = data.filtered_height();  		report_time = System.currentTimeMillis();  | 
