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 {
35 double lat; /* degrees (+N -S) */
36 double lon; /* degrees (+E -W) */
45 int gps_extended; /* has extra data */
46 double ground_speed; /* m/s */
47 int course; /* degrees */
48 double climb_rate; /* m/s */
49 double hdop; /* unitless? */
53 AltosGPSSat[] cc_gps_sat; /* tracking data */
55 void ParseGPSTime(String date, String time) throws ParseException {
56 String[] ymd = date.split("-");
58 throw new ParseException("error parsing GPS date " + date + " got " + ymd.length, 0);
59 year = AltosParse.parse_int(ymd[0]);
60 month = AltosParse.parse_int(ymd[1]);
61 day = AltosParse.parse_int(ymd[2]);
63 String[] hms = time.split(":");
65 throw new ParseException("Error parsing GPS time " + time + " got " + hms.length, 0);
66 hour = AltosParse.parse_int(hms[0]);
67 minute = AltosParse.parse_int(hms[1]);
68 second = AltosParse.parse_int(hms[2]);
72 year = month = day = 0;
73 hour = minute = second = 0;
76 public AltosGPS(String[] words, int i) throws ParseException {
77 AltosParse.word(words[i++], "GPS");
78 nsat = AltosParse.parse_int(words[i++]);
79 AltosParse.word(words[i++], "sat");
86 if ((words[i]).equals("unlocked")) {
89 } else if ((words[i]).equals("not-connected")) {
91 } else if (words.length >= 40) {
95 ParseGPSTime(words[i], words[i+1]); i += 2;
96 lat = AltosParse.parse_coord(words[i++]);
97 lon = AltosParse.parse_coord(words[i++]);
98 alt = AltosParse.parse_int(AltosParse.strip_suffix(words[i++], "m"));
99 ground_speed = AltosParse.parse_double(AltosParse.strip_suffix(words[i++], "m/s(H)"));
100 course = AltosParse.parse_int(AltosParse.strip_suffix(words[i++], "°"));
101 climb_rate = AltosParse.parse_double(AltosParse.strip_suffix(words[i++], "m/s(V)"));
102 hdop = AltosParse.parse_double(AltosParse.strip_suffix(words[i++], "(hdop)"));
103 h_error = AltosParse.parse_int(AltosParse.strip_suffix(words[i++], "(herr)"));
104 v_error = AltosParse.parse_int(AltosParse.strip_suffix(words[i++], "(verr)"));
108 AltosParse.word(words[i++], "SAT");
109 int tracking_channels = 0;
110 if (words[i].equals("not-connected"))
111 tracking_channels = 0;
113 tracking_channels = AltosParse.parse_int(words[i]);
115 cc_gps_sat = new AltosGPS.AltosGPSSat[tracking_channels];
116 for (int chan = 0; chan < tracking_channels; chan++) {
117 cc_gps_sat[chan] = new AltosGPS.AltosGPSSat();
118 cc_gps_sat[chan].svid = AltosParse.parse_int(words[i++]);
119 cc_gps_sat[chan].c_n0 = AltosParse.parse_int(words[i++]);
123 public void set_latitude(int in_lat) {
124 lat = in_lat / 10.0e7;
127 public void set_longitude(int in_lon) {
128 lon = in_lon / 10.0e7;
131 public void set_time(int hour, int minute, int second) {
137 public void set_date(int year, int month, int day) {
143 public void set_flags(int flags) {
147 public void set_altitude(int altitude) {
151 public void add_sat(int svid, int c_n0) {
152 if (cc_gps_sat == null) {
153 cc_gps_sat = new AltosGPS.AltosGPSSat[1];
155 AltosGPSSat[] new_gps_sat = new AltosGPS.AltosGPSSat[cc_gps_sat.length + 1];
156 for (int i = 0; i < cc_gps_sat.length; i++)
157 new_gps_sat[i] = cc_gps_sat[i];
158 cc_gps_sat = new_gps_sat;
160 AltosGPS.AltosGPSSat sat = new AltosGPS.AltosGPSSat();
163 cc_gps_sat[cc_gps_sat.length - 1] = sat;
171 public AltosGPS(AltosGPS old) {
174 connected = old.connected;
175 lat = old.lat; /* degrees (+N -S) */
176 lon = old.lon; /* degrees (+E -W) */
177 alt = old.alt; /* m */
185 gps_extended = old.gps_extended; /* has extra data */
186 ground_speed = old.ground_speed; /* m/s */
187 course = old.course; /* degrees */
188 climb_rate = old.climb_rate; /* m/s */
189 hdop = old.hdop; /* unitless? */
190 h_error = old.h_error; /* m */
191 v_error = old.v_error; /* m */
193 if (old.cc_gps_sat != null) {
194 cc_gps_sat = new AltosGPSSat[old.cc_gps_sat.length];
195 for (int i = 0; i < old.cc_gps_sat.length; i++) {
196 cc_gps_sat[i] = new AltosGPSSat();
197 cc_gps_sat[i].svid = old.cc_gps_sat[i].svid;
198 cc_gps_sat[i].c_n0 = old.cc_gps_sat[i].c_n0;