diff options
| author | Keith Packard <keithp@keithp.com> | 2016-09-02 16:13:25 -0500 | 
|---|---|---|
| committer | Keith Packard <keithp@keithp.com> | 2016-09-02 16:13:25 -0500 | 
| commit | 8bbef0c7039f4a0c6ac368fd994c2e52d84d293c (patch) | |
| tree | 8a613e100589c90b2e2eddb730aa693e594d606a /altosui/AltosConfigTD.java | |
| parent | b2d013aef5b76ff527e8174dff7f6ffe0dfaefae (diff) | |
altosui: Deal with connect failure in AltosConfigTD
When the USB connection times out, abort any pending operations and
clean up the thread correctly. Also, deal with the serial line being
closed by checking for null.
Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'altosui/AltosConfigTD.java')
| -rw-r--r-- | altosui/AltosConfigTD.java | 21 | 
1 files changed, 16 insertions, 5 deletions
| diff --git a/altosui/AltosConfigTD.java b/altosui/AltosConfigTD.java index 13eced99..621db3c0 100644 --- a/altosui/AltosConfigTD.java +++ b/altosui/AltosConfigTD.java @@ -198,6 +198,9 @@ public class AltosConfigTD implements ActionListener {  	final static int	serial_mode_save = 1;  	final static int	serial_mode_reboot = 2; +	SerialData serial_data; +	Thread serial_thread; +  	class SerialData implements Runnable {  		AltosConfigTD	config;  		int		serial_mode; @@ -207,9 +210,9 @@ public class AltosConfigTD implements ActionListener {  				boolean	been_there = false;  				config.reset_data(); -				for (;;) { +				while (config.serial_line != null) {  					config.serial_line.printf("c s\nf\nv\n"); -					for (;;) { +					while (config.serial_line != null) {  						try {  							String line = config.serial_line.get_reply(5000);  							config.process_line(line); @@ -256,6 +259,7 @@ public class AltosConfigTD implements ActionListener {  				/* fall through ... */  			case serial_mode_read:  				get_data(); +				serial_thread = null;  				break;  			}  		} @@ -267,11 +271,17 @@ public class AltosConfigTD implements ActionListener {  	}  	void run_serial_thread(int serial_mode) { -		SerialData	sd = new SerialData(this, serial_mode); -		Thread		st = new Thread(sd); -		st.start(); +		serial_data = new SerialData(this, serial_mode); +		serial_thread = new Thread(serial_data); +		serial_thread.start();  	} +	void abort_serial_thread() { +		if (serial_thread != null) { +			serial_thread.interrupt(); +			serial_thread = null; +		} +	}  	void init_ui () throws InterruptedException, TimeoutException {  		config_ui = new AltosConfigTDUI(owner);  		config_ui.addActionListener(this); @@ -280,6 +290,7 @@ public class AltosConfigTD implements ActionListener {  	}  	void abort() { +		abort_serial_thread();  		if (serial_line != null) {  			serial_line.close();  			serial_line = null; | 
