2 * Copyright © 2012 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
18 package org.altusmetrum.altoslib_1;
20 import java.util.concurrent.*;
22 class AltosGPSQuery extends AltosGPS {
23 public AltosGPSQuery (AltosLink link, AltosConfigData config_data)
24 throws TimeoutException, InterruptedException {
25 boolean says_done = config_data.compare_version("1.0") >= 0;
28 String line = link.get_reply_no_dialog(5000);
30 throw new TimeoutException();
31 String[] bits = line.split("\\s+");
34 if (line.startsWith("Date:")) {
37 String[] d = bits[1].split(":");
40 year = Integer.parseInt(d[0]) + 2000;
41 month = Integer.parseInt(d[1]);
42 day = Integer.parseInt(d[2]);
45 if (line.startsWith("Time:")) {
48 String[] d = bits[1].split("/");
51 hour = Integer.parseInt(d[0]);
52 minute = Integer.parseInt(d[1]);
53 second = Integer.parseInt(d[2]);
56 if (line.startsWith("Lat/Lon:")) {
59 lat = Integer.parseInt(bits[1]) * 1.0e-7;
60 lon = Integer.parseInt(bits[2]) * 1.0e-7;
63 if (line.startsWith("Alt:")) {
66 alt = Integer.parseInt(bits[1]);
69 if (line.startsWith("Flags:")) {
72 int status = Integer.decode(bits[1]);
73 connected = (status & AltosLib.AO_GPS_RUNNING) != 0;
74 locked = (status & AltosLib.AO_GPS_VALID) != 0;
79 if (line.startsWith("Sats:")) {
82 nsat = Integer.parseInt(bits[1]);
83 cc_gps_sat = new AltosGPSSat[nsat];
84 for (int i = 0; i < nsat; i++) {
85 int svid = Integer.parseInt(bits[2+i*2]);
86 int cc_n0 = Integer.parseInt(bits[3+i*2]);
87 cc_gps_sat[i] = new AltosGPSSat(svid, cc_n0);
90 if (line.startsWith("done"))
92 if (line.startsWith("Syntax error"))