diff options
| author | Keith Packard <keithp@keithp.com> | 2013-09-05 11:33:48 -0700 | 
|---|---|---|
| committer | Keith Packard <keithp@keithp.com> | 2013-09-05 11:35:14 -0700 | 
| commit | 5b976a6651f4eb05d30afc08b9e1f27c7e52ae00 (patch) | |
| tree | 3a8f38d92fdc3b3e9e62d7744ff93a0f9ca8f7dc /altoslib/AltosMag.java | |
| parent | b984ff81d6b8979574e0248ffe8876634b8e1942 (diff) | |
altoslib: Finish AltosState changes. Update version number.
Removes all of the AltosRecord bits, changes the monitor idle bits to
have per-object state updaters.
Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'altoslib/AltosMag.java')
| -rw-r--r-- | altoslib/AltosMag.java | 48 | 
1 files changed, 47 insertions, 1 deletions
diff --git a/altoslib/AltosMag.java b/altoslib/AltosMag.java index cb6826f3..56add8f3 100644 --- a/altoslib/AltosMag.java +++ b/altoslib/AltosMag.java @@ -15,13 +15,29 @@   * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.   */ -package org.altusmetrum.altoslib_1; +package org.altusmetrum.altoslib_2; + +import java.util.concurrent.*;  public class AltosMag implements Cloneable {  	public int		x;  	public int		y;  	public int		z; +	public boolean parse_string(String line) { +		if (!line.startsWith("X:")) +			return false; + +		String[] items = line.split("\\s+"); + +		if (items.length >= 6) { +			x = Integer.parseInt(items[1]); +			y = Integer.parseInt(items[3]); +			z = Integer.parseInt(items[5]); +		} +		return true; +	} +  	public AltosMag clone() {  		AltosMag n = new AltosMag(); @@ -30,5 +46,35 @@ public class AltosMag implements Cloneable {  		n.z = z;  		return n;  	} + +	public AltosMag() { +		x = AltosLib.MISSING; +		y = AltosLib.MISSING; +		z = AltosLib.MISSING; +	} + +	static public void update_state(AltosState state, AltosLink link, AltosConfigData config_data) { +		try { +			AltosMag	mag = new AltosMag(link); + +			if (mag != null) +				state.set_mag(mag); +		} catch (TimeoutException te) { +		} catch (InterruptedException ie) { +		} +	} + +	public AltosMag(AltosLink link) throws InterruptedException, TimeoutException { +		this(); +		link.printf("M\n"); +		for (;;) { +			String line = link.get_reply_no_dialog(5000); +			if (line == null) { +				throw new TimeoutException(); +			} +			if (parse_string(line)) +				break; +		} +	}  }  	
\ No newline at end of file  | 
