diff options
| author | Keith Packard <keithp@keithp.com> | 2016-06-15 22:40:27 -0700 | 
|---|---|---|
| committer | Keith Packard <keithp@keithp.com> | 2016-06-15 22:40:27 -0700 | 
| commit | 1b5ea911049a8afae6af475a4a2bf62a6e3aa57b (patch) | |
| tree | 7f896e587da5e7911b7b5a42aade1b7692670200 /altoslib/AltosGPS.java | |
| parent | 1de8b6c340cec0b5a327392686c5a4e00f201e98 (diff) | |
altoslib: Switch preserved state format to JSON
This is much easier to debug than the icky strings with backslashes everywhere.
Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'altoslib/AltosGPS.java')
| -rw-r--r-- | altoslib/AltosGPS.java | 63 | 
1 files changed, 62 insertions, 1 deletions
| diff --git a/altoslib/AltosGPS.java b/altoslib/AltosGPS.java index 371fd7bf..d3710e4e 100644 --- a/altoslib/AltosGPS.java +++ b/altoslib/AltosGPS.java @@ -21,7 +21,7 @@ import java.text.*;  import java.util.concurrent.*;  import java.io.*; -public class AltosGPS implements Cloneable, AltosHashable { +public class AltosGPS implements Cloneable, AltosHashable, AltosJsonable {  	public final static int MISSING = AltosLib.MISSING; @@ -417,6 +417,34 @@ public class AltosGPS implements Cloneable, AltosHashable {  		return h;  	} +	public AltosJson json() { +		AltosJson	j = new AltosJson(); + +		j.put("nsat", nsat); +		j.put("locked", locked); +		j.put("connected", connected); +		j.put("lat", lat); +		j.put("lon", lon); +		j.put("alt", alt); +		j.put("year", year); +		j.put("month", month); +		j.put("day", day); +		j.put("hour", hour); +		j.put("minute", minute); +		j.put("second", second); + +		j.put("ground_speed", ground_speed); +		j.put("course", course); +		j.put("climb_rate", climb_rate); +		j.put("pdop", pdop); +		j.put("hdop", hdop); +		j.put("vdop", vdop); +		j.put("h_error", h_error); +		j.put("v_error", v_error); +		j.put("cc_gps_sat", cc_gps_sat); +		return j; +	} +  	public AltosGPS(AltosHashSet h) {  		init();  		nsat = h.getInt("nsat", nsat); @@ -443,10 +471,43 @@ public class AltosGPS implements Cloneable, AltosHashable {  		cc_gps_sat = AltosGPSSat.array(h.getString("cc_gps_sat", null));  	} +	public AltosGPS(AltosJson j) { +		init(); +		nsat = j.get_int("nsat", nsat); +		locked = j.get_boolean("locked", locked); +		connected = j.get_boolean("connected", connected); +		lat = j.get_double("lat", lat); +		lon = j.get_double("lon", lon); +		alt = j.get_double("alt", alt); +		year = j.get_int("year", year); +		month = j.get_int("month", month); +		day = j.get_int("day", day); +		hour = j.get_int("hour", hour); +		minute = j.get_int("minute", minute); +		second = j.get_int("second", second); + +		ground_speed = j.get_double("ground_speed", ground_speed); +		course = j.get_int("course", course); +		climb_rate = j.get_double("climb_rate", climb_rate); +		pdop = j.get_double("pdop", pdop); +		hdop = j.get_double("hdop", hdop); +		vdop = j.get_double("vdop", vdop); +		h_error = j.get_double("h_error", h_error); +		v_error = j.get_double("v_error", v_error); +		cc_gps_sat = AltosGPSSat.json_array(j.get("cc_gps_sat")); +	} +  	public static AltosGPS fromHashSet(AltosHashSet h, AltosGPS def) {  		if (h == null)  			return def;  		return new AltosGPS(h);  	} + +	public static AltosGPS fromJson(AltosJson j, AltosGPS def) { +		if (j == null) +			return def; + +		return new AltosGPS(j); +	}  } | 
