X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=blobdiff_plain;f=altoslib%2FAltosGPS.java;h=a730957b2566bc5c0b872820d69fa682b38994cc;hp=d29ccdd1fbe0f6d0e035a50f1cd4aacecad797fd;hb=fd738d47bbc46d36698350d5450abe1125d990a3;hpb=1dce20f7eee56166ac61798ca26eeb323dc8f012 diff --git a/altoslib/AltosGPS.java b/altoslib/AltosGPS.java index d29ccdd1..a730957b 100644 --- a/altoslib/AltosGPS.java +++ b/altoslib/AltosGPS.java @@ -3,7 +3,8 @@ * * 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 @@ -20,6 +21,7 @@ package org.altusmetrum.altoslib_11; import java.text.*; import java.util.concurrent.*; import java.io.*; +import java.time.*; public class AltosGPS implements Cloneable { @@ -72,6 +74,24 @@ public class AltosGPS implements Cloneable { 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 AltosGPS(AltosTelemetryMap map) throws ParseException { String state = map.get_string(AltosTelemetryLegacy.AO_TELEM_GPS_STATE, AltosTelemetryLegacy.AO_TELEM_GPS_STATE_ERROR); @@ -363,17 +383,13 @@ public class AltosGPS implements Cloneable { } } - static public void update_state(AltosState state, AltosLink link, AltosConfigData config_data) throws InterruptedException { + static public void provide_data(AltosDataListener listener, AltosLink link, AltosCalData cal_data) 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); } catch (TimeoutException te) { } - state.set_gps(null, 0); } public AltosGPS (AltosLink link, AltosConfigData config_data) throws TimeoutException, InterruptedException {