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 AltosGPSSat {
33 boolean gps_connected;
34 double lat; /* degrees (+N -S) */
35 double lon; /* degrees (+E -W) */
44 int gps_extended; /* has extra data */
45 double ground_speed; /* m/s */
46 int course; /* degrees */
47 double climb_rate; /* m/s */
48 double hdop; /* unitless? */
52 AltosGPSSat[] cc_gps_sat; /* tracking data */
54 void ParseGPSTime(String date, String time) throws ParseException {
55 String[] ymd = date.split("-");
57 throw new ParseException("error parsing GPS date " + date + " got " + ymd.length, 0);
58 year = AltosParse.parse_int(ymd[0]);
59 month = AltosParse.parse_int(ymd[1]);
60 day = AltosParse.parse_int(ymd[2]);
62 String[] hms = time.split(":");
64 throw new ParseException("Error parsing GPS time " + time + " got " + hms.length, 0);
65 hour = AltosParse.parse_int(hms[0]);
66 minute = AltosParse.parse_int(hms[1]);
67 second = AltosParse.parse_int(hms[2]);
71 year = month = day = 0;
72 hour = minute = second = 0;
75 public AltosGPS(String[] words, int i) throws ParseException {
76 AltosParse.word(words[i++], "GPS");
77 nsat = AltosParse.parse_int(words[i++]);
78 AltosParse.word(words[i++], "sat");
80 gps_connected = false;
85 if ((words[i]).equals("unlocked")) {
88 } else if ((words[i]).equals("not-connected")) {
90 } else if (words.length >= 40) {
94 ParseGPSTime(words[i], words[i+1]); i += 2;
95 lat = AltosParse.parse_coord(words[i++]);
96 lon = AltosParse.parse_coord(words[i++]);
97 alt = AltosParse.parse_int(AltosParse.strip_suffix(words[i++], "m"));
98 ground_speed = AltosParse.parse_double(AltosParse.strip_suffix(words[i++], "m/s(H)"));
99 course = AltosParse.parse_int(AltosParse.strip_suffix(words[i++], "°"));
100 climb_rate = AltosParse.parse_double(AltosParse.strip_suffix(words[i++], "m/s(V)"));
101 hdop = AltosParse.parse_double(AltosParse.strip_suffix(words[i++], "(hdop)"));
102 h_error = AltosParse.parse_int(AltosParse.strip_suffix(words[i++], "(herr)"));
103 v_error = AltosParse.parse_int(AltosParse.strip_suffix(words[i++], "(verr)"));
107 AltosParse.word(words[i++], "SAT");
108 int tracking_channels = 0;
109 if (words[i].equals("not-connected"))
110 tracking_channels = 0;
112 tracking_channels = AltosParse.parse_int(words[i]);
114 cc_gps_sat = new AltosGPS.AltosGPSSat[tracking_channels];
115 for (int chan = 0; chan < tracking_channels; chan++) {
116 cc_gps_sat[chan] = new AltosGPS.AltosGPSSat();
117 cc_gps_sat[chan].svid = AltosParse.parse_int(words[i++]);
118 cc_gps_sat[chan].c_n0 = AltosParse.parse_int(words[i++]);
122 public void set_latitude(int in_lat) {
123 lat = in_lat / 10.0e7;
126 public void set_longitude(int in_lon) {
127 lon = in_lon / 10.0e7;
130 public void set_time(int hour, int minute, int second) {
136 public void set_date(int year, int month, int day) {
142 public void set_flags(int flags) {
146 public void set_altitude(int altitude) {
150 public void add_sat(int svid, int c_n0) {
151 if (cc_gps_sat == null) {
152 cc_gps_sat = new AltosGPS.AltosGPSSat[1];
154 AltosGPSSat[] new_gps_sat = new AltosGPS.AltosGPSSat[cc_gps_sat.length + 1];
155 for (int i = 0; i < cc_gps_sat.length; i++)
156 new_gps_sat[i] = cc_gps_sat[i];
157 cc_gps_sat = new_gps_sat;
159 AltosGPS.AltosGPSSat sat = new AltosGPS.AltosGPSSat();
162 cc_gps_sat[cc_gps_sat.length - 1] = sat;