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_11;
21 public class AltosEepromRecordMetrum extends AltosEepromRecord {
22 public static final int record_length = 16;
24 public int record_length() { return record_length; }
26 /* AO_LOG_FLIGHT elements */
27 public int flight() { return data16(0); }
28 public int ground_accel() { return data16(2); }
29 public int ground_pres() { return data32(4); }
30 public int ground_temp() { return data32(8); }
32 /* AO_LOG_STATE elements */
33 public int state() { return data16(0); }
34 public int reason() { return data16(2); }
36 /* AO_LOG_SENSOR elements */
37 public int pres() { return data32(0); }
38 public int temp() { return data32(4); }
39 public int accel() { return data16(8); }
41 /* AO_LOG_TEMP_VOLT elements */
42 public int v_batt() { return data16(0); }
43 public int sense_a() { return data16(2); }
44 public int sense_m() { return data16(4); }
46 /* AO_LOG_GPS_POS elements */
47 public int latitude() { return data32(0); }
48 public int longitude() { return data32(4); }
49 public int altitude_low() { return data16(8); }
50 public int altitude_high() { return data16(10); }
52 /* AO_LOG_GPS_TIME elements */
53 public int hour() { return data8(0); }
54 public int minute() { return data8(1); }
55 public int second() { return data8(2); }
56 public int flags() { return data8(3); }
57 public int year() { return data8(4); }
58 public int month() { return data8(5); }
59 public int day() { return data8(6); }
60 public int pdop() { return data8(7); }
62 /* AO_LOG_GPS_SAT elements */
63 public int nsat() { return data8(0); }
64 public int more() { return data8(1); }
65 public int svid(int n) { return data8(2 + n * 2); }
66 public int c_n(int n) { return data8(2 + n * 2 + 1); }
68 public void update_state(AltosState state) {
69 super.update_state(state);
73 /* Flush any pending GPS changes */
74 if (state.gps_pending) {
76 case AltosLib.AO_LOG_GPS_POS:
77 case AltosLib.AO_LOG_GPS_LAT:
78 case AltosLib.AO_LOG_GPS_LON:
79 case AltosLib.AO_LOG_GPS_ALT:
80 case AltosLib.AO_LOG_GPS_SAT:
81 case AltosLib.AO_LOG_GPS_DATE:
90 case AltosLib.AO_LOG_FLIGHT:
91 state.set_flight(flight());
92 state.set_ground_accel(ground_accel());
93 state.set_ground_pressure(ground_pres());
95 case AltosLib.AO_LOG_STATE:
96 state.set_state(state());
98 case AltosLib.AO_LOG_SENSOR:
99 state.set_ms5607(pres(), temp());
100 state.set_accel(accel());
103 case AltosLib.AO_LOG_TEMP_VOLT:
104 state.set_battery_voltage(AltosConvert.mega_battery_voltage(v_batt()));
106 state.set_apogee_voltage(AltosConvert.mega_pyro_voltage(sense_a()));
107 state.set_main_voltage(AltosConvert.mega_pyro_voltage(sense_m()));
110 case AltosLib.AO_LOG_GPS_POS:
111 gps = state.make_temp_gps(false);
112 gps.lat = latitude() / 1e7;
113 gps.lon = longitude() / 1e7;
114 if (state.altitude_32())
115 gps.alt = (altitude_low() & 0xffff) | (altitude_high() << 16);
117 gps.alt = altitude_low();
119 case AltosLib.AO_LOG_GPS_TIME:
120 gps = state.make_temp_gps(false);
123 gps.minute = minute();
124 gps.second = second();
128 gps.connected = (flags & AltosLib.AO_GPS_RUNNING) != 0;
129 gps.locked = (flags & AltosLib.AO_GPS_VALID) != 0;
130 gps.nsat = (flags & AltosLib.AO_GPS_NUM_SAT_MASK) >>
131 AltosLib.AO_GPS_NUM_SAT_SHIFT;
133 gps.year = 2000 + year();
136 gps.pdop = pdop() / 10.0;
138 case AltosLib.AO_LOG_GPS_SAT:
139 gps = state.make_temp_gps(true);
142 for (int i = 0; i < n; i++)
143 gps.add_sat(svid(i), c_n(i));
148 public AltosEepromRecord next() {
149 int s = next_start();
152 return new AltosEepromRecordMetrum(eeprom, s);
155 public AltosEepromRecordMetrum(AltosEepromNew eeprom, int start) {
156 super(eeprom, start, record_length);
159 public AltosEepromRecordMetrum(AltosEepromNew eeprom) {