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;
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 provide_data(AltosDataListener listener, AltosCalData cal_data) {
69 super.provide_data(listener, cal_data);
74 case AltosLib.AO_LOG_FLIGHT:
75 cal_data.set_flight(flight());
76 cal_data.set_ground_accel(ground_accel());
77 cal_data.set_ground_pressure(ground_pres());
79 case AltosLib.AO_LOG_STATE:
80 listener.set_state(state());
82 case AltosLib.AO_LOG_SENSOR:
83 AltosPresTemp pt = eeprom.config_data().ms5607().pres_temp(pres(), temp());
84 listener.set_pressure(pt.pres);
85 listener.set_temperature(pt.temp);
86 listener.set_acceleration(cal_data.acceleration(accel()));
88 case AltosLib.AO_LOG_TEMP_VOLT:
89 listener.set_battery_voltage(AltosConvert.mega_battery_voltage(v_batt()));
90 listener.set_apogee_voltage(AltosConvert.mega_pyro_voltage(sense_a()));
91 listener.set_main_voltage(AltosConvert.mega_pyro_voltage(sense_m()));
93 case AltosLib.AO_LOG_GPS_POS:
94 gps = listener.make_temp_gps(false);
95 gps.lat = latitude() / 1e7;
96 gps.lon = longitude() / 1e7;
97 if (config_data().altitude_32())
98 gps.alt = (altitude_low() & 0xffff) | (altitude_high() << 16);
100 gps.alt = altitude_low();
102 case AltosLib.AO_LOG_GPS_TIME:
103 gps = listener.make_temp_gps(false);
106 gps.minute = minute();
107 gps.second = second();
111 gps.connected = (flags & AltosLib.AO_GPS_RUNNING) != 0;
112 gps.locked = (flags & AltosLib.AO_GPS_VALID) != 0;
113 gps.nsat = (flags & AltosLib.AO_GPS_NUM_SAT_MASK) >>
114 AltosLib.AO_GPS_NUM_SAT_SHIFT;
116 gps.year = 2000 + year();
119 gps.pdop = pdop() / 10.0;
121 case AltosLib.AO_LOG_GPS_SAT:
122 gps = listener.make_temp_gps(true);
125 for (int i = 0; i < n; i++)
126 gps.add_sat(svid(i), c_n(i));
131 public AltosEepromRecord next() {
132 int s = next_start();
135 return new AltosEepromRecordMetrum(eeprom, s);
138 public AltosEepromRecordMetrum(AltosEeprom eeprom, int start) {
139 super(eeprom, start, record_length);
142 public AltosEepromRecordMetrum(AltosEeprom eeprom) {