X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=altoslib%2FAltosGPS.java;h=d3710e4e60f46b5642ce1f7dd2c988d1e235a910;hb=1b5ea911049a8afae6af475a4a2bf62a6e3aa57b;hp=a4cd20618f7c93345b488d5f703f2bc57ba07729;hpb=7041c386cdf37716f8daf0bc1a9204db620e3de9;p=fw%2Faltos diff --git a/altoslib/AltosGPS.java b/altoslib/AltosGPS.java index a4cd2061..d3710e4e 100644 --- a/altoslib/AltosGPS.java +++ b/altoslib/AltosGPS.java @@ -15,13 +15,13 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_9; +package org.altusmetrum.altoslib_11; import java.text.*; import java.util.concurrent.*; import java.io.*; -public class AltosGPS implements Cloneable, Serializable { +public class AltosGPS implements Cloneable, AltosHashable, AltosJsonable { public final static int MISSING = AltosLib.MISSING; @@ -388,4 +388,126 @@ public class AltosGPS implements Cloneable, Serializable { break; } } + + public AltosHashSet hashSet() { + AltosHashSet h = new AltosHashSet(); + + h.putInt("nsat", nsat); + h.putBoolean("locked", locked); + h.putBoolean("connected", connected); + h.putDouble("lat", lat); + h.putDouble("lon", lon); + h.putDouble("alt", alt); + h.putInt("year", year); + h.putInt("month", month); + h.putInt("day", day); + h.putInt("hour", hour); + h.putInt("minute", minute); + h.putInt("second", second); + + h.putDouble("ground_speed", ground_speed); + h.putInt("course", course); + h.putDouble("climb_rate", climb_rate); + h.putDouble("pdop", pdop); + h.putDouble("hdop", hdop); + h.putDouble("vdop", vdop); + h.putDouble("h_error", h_error); + h.putDouble("v_error", v_error); + h.putString("cc_gps_sat", AltosGPSSat.toString(cc_gps_sat)); + 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); + locked = h.getBoolean("locked", locked); + connected = h.getBoolean("connected", connected); + lat = h.getDouble("lat", lat); + lon = h.getDouble("lon", lon); + alt = h.getDouble("alt", alt); + year = h.getInt("year", year); + month = h.getInt("month", month); + day = h.getInt("day", day); + hour = h.getInt("hour", hour); + minute = h.getInt("minute", minute); + second = h.getInt("second", second); + + ground_speed = h.getDouble("ground_speed", ground_speed); + course = h.getInt("course", course); + climb_rate = h.getDouble("climb_rate", climb_rate); + pdop = h.getDouble("pdop", pdop); + hdop = h.getDouble("hdop", hdop); + vdop = h.getDouble("vdop", vdop); + h_error = h.getDouble("h_error", h_error); + v_error = h.getDouble("v_error", v_error); + 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); + } }