X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=blobdiff_plain;f=altoslib%2FAltosGPS.java;h=371fd7bf1418f638f9d0494c393df46e30e1692e;hp=285b5b45aca691e916ec000be19a4feff3f2a0b6;hb=b1a90adac9f6e2a609ce1ccd6749462bb5c9adbe;hpb=60edcfe410e7fa848813d6c1ed8dc9808887d041 diff --git a/altoslib/AltosGPS.java b/altoslib/AltosGPS.java index 285b5b45..371fd7bf 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_5; +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 { public final static int MISSING = AltosLib.MISSING; @@ -195,10 +195,10 @@ public class AltosGPS implements Cloneable, Serializable { lon = AltosParse.parse_coord(words[i++]); alt = AltosParse.parse_int(words[i++]); if (version > 1 || (i < words.length && !words[i].equals("SAT"))) { - ground_speed = AltosParse.parse_double(AltosParse.strip_suffix(words[i++], "m/s(H)")); + ground_speed = AltosParse.parse_double_net(AltosParse.strip_suffix(words[i++], "m/s(H)")); course = AltosParse.parse_int(words[i++]); - climb_rate = AltosParse.parse_double(AltosParse.strip_suffix(words[i++], "m/s(V)")); - hdop = AltosParse.parse_double(AltosParse.strip_suffix(words[i++], "(hdop)")); + climb_rate = AltosParse.parse_double_net(AltosParse.strip_suffix(words[i++], "m/s(V)")); + hdop = AltosParse.parse_double_net(AltosParse.strip_suffix(words[i++], "(hdop)")); h_error = AltosParse.parse_int(words[i++]); v_error = AltosParse.parse_int(words[i++]); } @@ -378,6 +378,7 @@ public class AltosGPS implements Cloneable, Serializable { public AltosGPS (AltosLink link, AltosConfigData config_data) throws TimeoutException, InterruptedException { boolean says_done = config_data.compare_version("1.0") >= 0; + init(); link.printf("g\n"); for (;;) { String line = link.get_reply_no_dialog(5000); @@ -387,4 +388,65 @@ 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 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 static AltosGPS fromHashSet(AltosHashSet h, AltosGPS def) { + if (h == null) + return def; + + return new AltosGPS(h); + } }