diff options
| author | Keith Packard <keithp@keithp.com> | 2012-07-29 19:34:00 -0700 | 
|---|---|---|
| committer | Keith Packard <keithp@keithp.com> | 2012-07-29 19:34:00 -0700 | 
| commit | 0bf21399d3d47d58410df4c6ce89fc20fcd42c89 (patch) | |
| tree | f1c39fbbc5470e7d5489f6fcef2d0fe5ac2a461e | |
| parent | 59588ba34159b27c02e1a886b46497ecfa0cf4d3 (diff) | |
altosui: Handle Monitor Idle errors better
Deal with missing data by checking for MISSING in more places.
Handle serial communication failures during send by reporting back
from libaltos.
Signed-off-by: Keith Packard <keithp@keithp.com>
| -rw-r--r-- | altoslib/AltosIdleMonitor.java | 67 | ||||
| -rw-r--r-- | altoslib/AltosLink.java | 20 | ||||
| -rw-r--r-- | altoslib/AltosRecord.java | 2 | ||||
| -rw-r--r-- | altoslib/AltosRecordTM.java | 16 | ||||
| -rw-r--r-- | altoslib/AltosState.java | 2 | ||||
| -rw-r--r-- | altosui/AltosSerial.java | 14 | ||||
| -rw-r--r-- | altosui/libaltos/libaltos.c | 4 | 
7 files changed, 70 insertions, 55 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..fd5db7e9 100644 --- a/altoslib/AltosLink.java +++ b/altoslib/AltosLink.java @@ -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(); diff --git a/altosui/AltosSerial.java b/altosui/AltosSerial.java index c4e9c697..8b692fa9 100644 --- a/altosui/AltosSerial.java +++ b/altosui/AltosSerial.java @@ -54,13 +54,19 @@ public class AltosSerial extends AltosLink implements Runnable {  	Frame frame;  	public int getchar() { +		if (altos == null) +			return ERROR;  		return libaltos.altos_getchar(altos, 0);  	}  	public void flush_output() {  		super.flush_output();  		if (altos != null) { -			libaltos.altos_flush(altos); +			if (libaltos.altos_flush(altos) != 0) { +				libaltos.altos_close(altos); +				altos = null; +				abort_reply(); +			}  		}  	} @@ -155,7 +161,11 @@ public class AltosSerial extends AltosLink implements Runnable {  	private void putc(char c) {  		if (altos != null) -			libaltos.altos_putchar(altos, c); +			if (libaltos.altos_putchar(altos, c) != 0) { +				libaltos.altos_close(altos); +				altos = null; +				abort_reply(); +			}  	}  	public void print(String data) { diff --git a/altosui/libaltos/libaltos.c b/altosui/libaltos/libaltos.c index 1cc27cbe..515432f9 100644 --- a/altosui/libaltos/libaltos.c +++ b/altosui/libaltos/libaltos.c @@ -221,7 +221,7 @@ altos_flush(struct altos_file *file)  #endif  		if (ret < 0) {  			altos_set_last_posix_error(); -			return -errno; +			return -last_error.code;  		}  		if (ret) {  			memmove(file->out_data, file->out_data + ret, @@ -247,7 +247,7 @@ altos_putchar(struct altos_file *file, char c)  	ret = 0;  	if (file->out_used == USB_BUF_SIZE)  		ret = altos_flush(file); -	return 0; +	return ret;  }  #ifdef USE_POLL  | 
