X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=blobdiff_plain;f=altoslib%2FAltosGPS.java;h=57ac4061dbadde59678979119add0c6a7aae8adf;hp=0154e95d7c96d3231d831d18973010a32f1989f9;hb=HEAD;hpb=4828be0ca5252ac9cd6061209385dcd6c4c57965 diff --git a/altoslib/AltosGPS.java b/altoslib/AltosGPS.java index 0154e95d..e5f231b4 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 @@ -15,10 +16,12 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_5; +package org.altusmetrum.altoslib_14; import java.text.*; import java.util.concurrent.*; +import java.io.*; +import java.time.*; public class AltosGPS implements Cloneable { @@ -71,6 +74,28 @@ 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 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); @@ -141,20 +166,33 @@ public class AltosGPS implements Cloneable { if (bits.length < 2) return false; alt = Integer.parseInt(bits[1]); + } else if (line.startsWith("Pdop/Hdop/Vdop:")) { + if (bits.length < 4) + return false; + pdop = Integer.parseInt(bits[1]) / 10.0; + hdop = Integer.parseInt(bits[2]) / 10.0; + vdop = Integer.parseInt(bits[3]) / 10.0; + } else if (line.startsWith("Ground Speed/Climb Rate/Course:")) { + if (bits.length < 6) + return false; + ground_speed = Integer.parseInt(bits[3]) * 1.0e-2; + climb_rate = Integer.parseInt(bits[4]) * 1.0e-2; + course = Integer.parseInt(bits[5]) * 2; } else if (line.startsWith("Flags:")) { if (bits.length < 2) return false; int status = Integer.decode(bits[1]); connected = (status & AltosLib.AO_GPS_RUNNING) != 0; locked = (status & AltosLib.AO_GPS_VALID) != 0; + nsat = (status >> AltosLib.AO_GPS_NUM_SAT_SHIFT) & AltosLib.AO_GPS_NUM_SAT_MASK; if (!says_done) return false; } else if (line.startsWith("Sats:")) { if (bits.length < 2) return false; - nsat = Integer.parseInt(bits[1]); - cc_gps_sat = new AltosGPSSat[nsat]; - for (int i = 0; i < nsat; i++) { + int nsvs = Integer.parseInt(bits[1]); + cc_gps_sat = new AltosGPSSat[nsvs]; + for (int i = 0; i < nsvs; i++) { int svid = Integer.parseInt(bits[2+i*2]); int cc_n0 = Integer.parseInt(bits[3+i*2]); cc_gps_sat[i] = new AltosGPSSat(svid, cc_n0); @@ -194,10 +232,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++]); } @@ -362,21 +400,18 @@ 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) 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 { boolean says_done = config_data.compare_version("1.0") >= 0; + init(); link.printf("g\n"); for (;;) { String line = link.get_reply_no_dialog(5000);