doc: Add 1.9 release notes
[fw/altos] / altoslib / AltosGPS.java
index f28108334ade41b1f9400e3a61c31557c1037524..8037eb93deb37ec63e44b49d5b3975c7e31b8dd8 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
  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  */
 
-package org.altusmetrum.altoslib_4;
+package org.altusmetrum.altoslib_13;
 
 import java.text.*;
 import java.util.concurrent.*;
+import java.io.*;
+import java.time.*;
 
 public class AltosGPS implements Cloneable {
 
@@ -40,14 +43,11 @@ public class AltosGPS implements Cloneable {
        public double   ground_speed;   /* m/s */
        public int      course;         /* degrees */
        public double   climb_rate;     /* m/s */
+       public double   pdop;           /* unitless */
        public double   hdop;           /* unitless */
        public double   vdop;           /* unitless */
-       public int      h_error;        /* m */
-       public int      v_error;        /* m */
-
-       public int      state;          /* for TeleGPS */
-
-       static final int AO_GPS_STATE_VALID = 0x80;
+       public double   h_error;        /* m */
+       public double   v_error;        /* m */
 
        public AltosGPSSat[] cc_gps_sat;        /* tracking data */
 
@@ -74,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);
@@ -99,6 +117,7 @@ public class AltosGPS implements Cloneable {
                                                      AltosLib.MISSING, 1/100.0);
                        course = map.get_int(AltosTelemetryLegacy.AO_TELEM_GPS_COURSE,
                                             AltosLib.MISSING);
+                       pdop = map.get_double(AltosTelemetryLegacy.AO_TELEM_GPS_PDOP, MISSING, 1.0);
                        hdop = map.get_double(AltosTelemetryLegacy.AO_TELEM_GPS_HDOP, MISSING, 1.0);
                        vdop = map.get_double(AltosTelemetryLegacy.AO_TELEM_GPS_VDOP, MISSING, 1.0);
                        h_error = map.get_int(AltosTelemetryLegacy.AO_TELEM_GPS_HERROR, MISSING);
@@ -196,10 +215,10 @@ public class AltosGPS implements Cloneable {
                        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++]);
                        }
@@ -272,14 +291,26 @@ public class AltosGPS implements Cloneable {
                cc_gps_sat[cc_gps_sat.length - 1] = sat;
        }
 
-       public AltosGPS() {
+       private void init() {
                lat = AltosLib.MISSING;
                lon = AltosLib.MISSING;
                alt = AltosLib.MISSING;
+               ground_speed = AltosLib.MISSING;
+               course = AltosLib.MISSING;
+               climb_rate = AltosLib.MISSING;
+               pdop = AltosLib.MISSING;
+               hdop = AltosLib.MISSING;
+               vdop = AltosLib.MISSING;
+               h_error = AltosLib.MISSING;
+               v_error = AltosLib.MISSING;
                ClearGPSTime();
                cc_gps_sat = null;
        }
 
+       public AltosGPS() {
+               init();
+       }
+
        public AltosGPS clone() {
                AltosGPS        g = new AltosGPS();
 
@@ -299,10 +330,11 @@ public class AltosGPS implements Cloneable {
                g.ground_speed = ground_speed;  /* m/s */
                g.course = course;              /* degrees */
                g.climb_rate = climb_rate;      /* m/s */
-               g.hdop = hdop;          /* unitless? */
+               g.pdop = pdop;          /* unitless */
+               g.hdop = hdop;          /* unitless */
+               g.vdop = vdop;          /* unitless */
                g.h_error = h_error;    /* m */
                g.v_error = v_error;    /* m */
-               g.state = state;
 
                if (cc_gps_sat != null) {
                        g.cc_gps_sat = new AltosGPSSat[cc_gps_sat.length];
@@ -332,10 +364,11 @@ public class AltosGPS implements Cloneable {
                        ground_speed = old.ground_speed;        /* m/s */
                        course = old.course;            /* degrees */
                        climb_rate = old.climb_rate;    /* m/s */
+                       pdop = old.pdop;                /* unitless? */
                        hdop = old.hdop;                /* unitless? */
-                       h_error = old.h_error;  /* m */
-                       v_error = old.v_error;  /* m */
-                       state = old.state;
+                       vdop = old.vdop;                /* unitless? */
+                       h_error = old.h_error;          /* m */
+                       v_error = old.v_error;          /* m */
 
                        if (old.cc_gps_sat != null) {
                                cc_gps_sat = new AltosGPSSat[old.cc_gps_sat.length];
@@ -346,30 +379,22 @@ public class AltosGPS implements Cloneable {
                                }
                        }
                } else {
-                       lat = AltosLib.MISSING;
-                       lon = AltosLib.MISSING;
-                       alt = AltosLib.MISSING;
-                       ClearGPSTime();
-                       cc_gps_sat = null;
-                       state = 0;
+                       init();
                }
        }
 
-       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);
                } catch (TimeoutException te) {
                }
-               state.set_gps(null, 0);
        }
 
        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);