2 * Copyright © 2017 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; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
19 package org.altusmetrum.altoslib_14;
25 public class AltosEepromRecordGps extends AltosEepromRecord {
26 public static final int record_length = 32;
28 /* AO_LOG_FLIGHT elements */
29 public int flight() { return data16(0); }
30 public int start_altitude() { return data16(2); }
31 public int start_latitude() { return data32(4); }
32 public int start_longitude() { return data32(8); }
34 /* AO_LOG_GPS_TIME elements */
35 public int latitude() { return data32(0); }
36 public int longitude() { return data32(4); }
37 public int altitude_low() { return data16(8); }
38 public int hour() { return data8(10); }
39 public int minute() { return data8(11); }
40 public int second() { return data8(12); }
41 public int flags() { return data8(13); }
42 public int year() { return data8(14); }
43 public int month() { return data8(15); }
44 public int day() { return data8(16); }
45 public int course() { return data8(17); }
46 public int ground_speed() { return data16(18); }
47 public int climb_rate() { return data16(20); }
48 public int pdop() { return data8(22); }
49 public int hdop() { return data8(23); }
50 public int vdop() { return data8(24); }
51 public int mode() { return data8(25); }
52 public int altitude_high() { return data16(26); }
54 private int seconds() {
56 case AltosLib.AO_LOG_GPS_TIME:
57 return second() + 60 * (minute() + 60 * (hour() + 24 * (day() + 31 * month())));
63 public int compareTo(AltosEepromRecord o) {
64 AltosEepromRecordGps og = (AltosEepromRecordGps) o;
66 int seconds_diff = seconds() - og.seconds();
68 if (seconds_diff != 0)
71 return start - o.start;
74 public void provide_data(AltosDataListener listener, AltosCalData cal_data) {
75 super.provide_data(listener, cal_data);
78 case AltosLib.AO_LOG_FLIGHT:
79 if (cal_data.flight == AltosLib.MISSING) {
80 cal_data.set_boost_tick();
81 cal_data.set_flight(flight());
83 /* no place to log start lat/lon yet */
85 case AltosLib.AO_LOG_GPS_TIME:
86 AltosGPS gps = new AltosGPS();
87 gps.lat = latitude() / 1e7;
88 gps.lon = longitude() / 1e7;
89 if (eeprom.config_data().altitude_32 == 1)
90 gps.alt = (altitude_low() & 0xffff) | (altitude_high() << 16);
92 gps.alt = altitude_low();
95 gps.minute = minute();
96 gps.second = second();
100 gps.connected = (flags & AltosLib.AO_GPS_RUNNING) != 0;
101 gps.locked = (flags & AltosLib.AO_GPS_VALID) != 0;
102 gps.nsat = (flags & AltosLib.AO_GPS_NUM_SAT_MASK) >>
103 AltosLib.AO_GPS_NUM_SAT_SHIFT;
105 gps.year = 2000 + year();
108 gps.ground_speed = ground_speed() * 1.0e-2;
109 gps.course = course() * 2;
110 gps.climb_rate = climb_rate() * 1.0e-2;
111 if (eeprom.config_data().compare_version("1.4.9") >= 0) {
112 gps.pdop = pdop() / 10.0;
113 gps.hdop = hdop() / 10.0;
114 gps.vdop = vdop() / 10.0;
116 gps.pdop = pdop() / 100.0;
119 gps.hdop = hdop() / 100.0;
122 gps.vdop = vdop() / 100.0;
126 listener.set_gps(gps, true, true);
131 public AltosEepromRecord next() {
132 int s = next_start();
135 return new AltosEepromRecordGps(eeprom, s);
138 public AltosEepromRecordGps(AltosEeprom eeprom, int start) {
139 super(eeprom, start, record_length);
142 public AltosEepromRecordGps(AltosEeprom eeprom) {