*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License.
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*/
-package org.altusmetrum.altoslib_11;
+package org.altusmetrum.altoslib_14;
import java.text.*;
import java.util.concurrent.*;
import java.io.*;
+import java.time.*;
-public class AltosGPS implements Cloneable, AltosHashable {
+public class AltosGPS implements Cloneable {
public final static int MISSING = AltosLib.MISSING;
hour = minute = second = AltosLib.MISSING;
}
+ /* Return time since epoc in seconds */
+ public long seconds() {
+ if (year == AltosLib.MISSING)
+ return AltosLib.MISSING;
+ if (month == AltosLib.MISSING)
+ return AltosLib.MISSING;
+ if (day == AltosLib.MISSING)
+ return AltosLib.MISSING;
+ if (hour == AltosLib.MISSING)
+ return AltosLib.MISSING;
+ if (minute == AltosLib.MISSING)
+ return AltosLib.MISSING;
+ if (second == AltosLib.MISSING)
+ return AltosLib.MISSING;
+ OffsetDateTime odt = OffsetDateTime.of(year, month, day, hour, minute, second, 0, ZoneOffset.UTC);
+ return odt.toEpochSecond();
+ }
+
+ public AltosLatLon lat_lon() {
+ return new AltosLatLon(lat, lon);
+ }
+
public AltosGPS(AltosTelemetryMap map) throws ParseException {
String state = map.get_string(AltosTelemetryLegacy.AO_TELEM_GPS_STATE,
AltosTelemetryLegacy.AO_TELEM_GPS_STATE_ERROR);
}
}
- static public void update_state(AltosState state, AltosLink link, AltosConfigData config_data) throws InterruptedException {
+ static public void provide_data(AltosDataListener listener, AltosLink link) throws InterruptedException {
try {
- AltosGPS gps = new AltosGPS(link, config_data);
-
- if (gps != null) {
- state.set_gps(gps, state.gps_sequence++);
- return;
- }
+ AltosGPS gps = new AltosGPS(link, link.config_data());
+ if (gps != null)
+ listener.set_gps(gps, true, true);
} catch (TimeoutException te) {
}
- state.set_gps(null, 0);
}
public AltosGPS (AltosLink link, AltosConfigData config_data) throws TimeoutException, InterruptedException {
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);
- }
}