altoslib: Make sure AltosFlightSeries is filled in before use
[fw/altos] / altoslib / AltosGPS.java
index ba2eda1bfba5aa931ecd4ae385c0a91a092696aa..a730957b2566bc5c0b872820d69fa682b38994cc 100644 (file)
@@ -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,8 +21,9 @@ package org.altusmetrum.altoslib_11;
 import java.text.*;
 import java.util.concurrent.*;
 import java.io.*;
+import java.time.*;
 
-public class AltosGPS implements Cloneable, AltosJsonable {
+public class AltosGPS implements Cloneable {
 
        public final static int MISSING = AltosLib.MISSING;
 
@@ -72,6 +74,24 @@ public class AltosGPS implements Cloneable, AltosJsonable {
                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, AltosJsonable {
                }
        }
 
-       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 {
@@ -388,65 +404,4 @@ public class AltosGPS implements Cloneable, AltosJsonable {
                                break;
                }
        }
-
-       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(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 fromJson(AltosJson j, AltosGPS def) {
-               if (j == null)
-                       return def;
-
-               return new AltosGPS(j);
-       }
 }