2 * Copyright © 2010 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.
22 import altosui.AltosParse;
25 public class AltosGPS {
26 public class AltosGPSTime {
34 public AltosGPSTime(String date, String time) throws ParseException {
35 String[] ymd = date.split("-");
37 throw new ParseException("error parsing GPS date " + date + " got " + ymd.length, 0);
38 year = AltosParse.parse_int(ymd[0]);
39 month = AltosParse.parse_int(ymd[1]);
40 day = AltosParse.parse_int(ymd[2]);
42 String[] hms = time.split(":");
44 throw new ParseException("Error parsing GPS time " + time + " got " + hms.length, 0);
45 hour = AltosParse.parse_int(hms[0]);
46 minute = AltosParse.parse_int(hms[1]);
47 second = AltosParse.parse_int(hms[2]);
50 public AltosGPSTime() {
51 year = month = day = 0;
52 hour = minute = second = 0;
57 public class AltosGPSSat {
64 boolean gps_connected;
65 AltosGPSTime gps_time;
66 double lat; /* degrees (+N -S) */
67 double lon; /* degrees (+E -W) */
70 int gps_extended; /* has extra data */
71 double ground_speed; /* m/s */
72 int course; /* degrees */
73 double climb_rate; /* m/s */
74 double hdop; /* unitless? */
78 AltosGPSSat[] cc_gps_sat; /* tracking data */
80 public AltosGPS(String[] words, int i) throws ParseException {
81 AltosParse.word(words[i++], "GPS");
82 nsat = AltosParse.parse_int(words[i++]);
83 AltosParse.word(words[i++], "sat");
85 gps_connected = false;
89 if ((words[i]).equals("unlocked")) {
91 gps_time = new AltosGPSTime();
93 } else if (words.length >= 40) {
97 gps_time = new AltosGPSTime(words[i], words[i+1]); i += 2;
98 lat = AltosParse.parse_coord(words[i++]);
99 lon = AltosParse.parse_coord(words[i++]);
100 alt = AltosParse.parse_int(AltosParse.strip_suffix(words[i++], "m"));
101 ground_speed = AltosParse.parse_double(AltosParse.strip_suffix(words[i++], "m/s(H)"));
102 course = AltosParse.parse_int(AltosParse.strip_suffix(words[i++], "°"));
103 climb_rate = AltosParse.parse_double(AltosParse.strip_suffix(words[i++], "m/s(V)"));
104 hdop = AltosParse.parse_double(AltosParse.strip_suffix(words[i++], "(hdop)"));
105 h_error = AltosParse.parse_int(AltosParse.strip_suffix(words[i++], "(herr)"));
106 v_error = AltosParse.parse_int(AltosParse.strip_suffix(words[i++], "(verr)"));
108 gps_time = new AltosGPSTime();
110 AltosParse.word(words[i++], "SAT");
111 int tracking_channels = 0;
112 if (words[i].equals("not-connected"))
113 tracking_channels = 0;
115 tracking_channels = AltosParse.parse_int(words[i]);
117 cc_gps_sat = new AltosGPS.AltosGPSSat[tracking_channels];
118 for (int chan = 0; chan < tracking_channels; chan++) {
119 cc_gps_sat[chan] = new AltosGPS.AltosGPSSat();
120 cc_gps_sat[chan].svid = AltosParse.parse_int(words[i++]);
121 cc_gps_sat[chan].c_n0 = AltosParse.parse_int(words[i++]);