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.
15 package org.altusmetrum.altoslib_11;
17 public class AltosEepromRecordFull extends AltosEepromRecord {
18 public static final int record_length = 8;
20 public static final int max_sat = 12;
22 public static final int two_g_default = 16294 - 15758;
24 public void update_state(AltosFlightListener state) {
26 super.update_state(state);
29 /* Flush any pending GPS changes */
30 if (state.gps_pending()) {
32 case AltosLib.AO_LOG_GPS_LAT:
33 case AltosLib.AO_LOG_GPS_LON:
34 case AltosLib.AO_LOG_GPS_ALT:
35 case AltosLib.AO_LOG_GPS_SAT:
36 case AltosLib.AO_LOG_GPS_DATE:
45 case AltosLib.AO_LOG_FLIGHT:
46 state.set_state(AltosLib.ao_flight_pad);
47 state.set_ground_accel(data16(0));
48 state.set_flight(data16(2));
49 if (state.accel_plus_g == AltosLib.MISSING)
50 state.set_accel_g(data16(0), data16(0) + two_g_default);
52 case AltosLib.AO_LOG_SENSOR:
53 state.set_accel(data16(0));
54 state.set_pressure(AltosConvert.barometer_to_pressure(data16(2)));
56 case AltosLib.AO_LOG_PRESSURE:
57 state.set_pressure(AltosConvert.barometer_to_pressure(data16(2)));
59 case AltosLib.AO_LOG_TEMP_VOLT:
60 state.set_temperature(AltosConvert.thermometer_to_temperature(data16(0)));
61 state.set_battery_voltage(AltosConvert.cc_battery_to_voltage(data16(2)));
63 case AltosLib.AO_LOG_DEPLOY:
64 state.set_apogee_voltage(AltosConvert.cc_ignitor_to_voltage(data16(0)));
65 state.set_main_voltage(AltosConvert.cc_ignitor_to_voltage(data16(2)));
67 case AltosLib.AO_LOG_STATE:
68 state.set_state(data16(0));
70 case AltosLib.AO_LOG_GPS_TIME:
71 gps = state.make_temp_gps(false);
74 gps.minute = data8(1);
75 gps.second = data8(2);
79 gps.connected = (flags & AltosLib.AO_GPS_RUNNING) != 0;
80 gps.locked = (flags & AltosLib.AO_GPS_VALID) != 0;
81 gps.nsat = (flags & AltosLib.AO_GPS_NUM_SAT_MASK) >>
82 AltosLib.AO_GPS_NUM_SAT_SHIFT;
84 case AltosLib.AO_LOG_GPS_LAT:
85 gps = state.make_temp_gps(false);
87 int lat32 = data32(0);
88 gps.lat = (double) lat32 / 1e7;
90 case AltosLib.AO_LOG_GPS_LON:
91 gps = state.make_temp_gps(false);
93 int lon32 = data32(0);
94 gps.lon = (double) lon32 / 1e7;
96 case AltosLib.AO_LOG_GPS_ALT:
97 gps = state.make_temp_gps(false);
100 case AltosLib.AO_LOG_GPS_SAT:
101 gps = state.make_temp_gps(true);
102 int svid = data16(0);
103 int c_n0 = data16(3);
104 gps.add_sat(svid, c_n0);
106 case AltosLib.AO_LOG_GPS_DATE:
107 gps = state.make_temp_gps(false);
108 gps.year = data8(0) + 2000;
109 gps.month = data8(1);
115 public AltosEepromRecord next() {
116 int s = next_start();
119 return new AltosEepromRecordFull(eeprom, s);
122 public AltosEepromRecordFull(AltosEepromNew eeprom, int start) {
123 super(eeprom, start, record_length);
126 public AltosEepromRecordFull(AltosEepromNew eeprom) {