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(AltosState state) {
25 super.update_state(state);
28 /* Flush any pending GPS changes */
29 if (state.gps_pending) {
31 case AltosLib.AO_LOG_GPS_LAT:
32 case AltosLib.AO_LOG_GPS_LON:
33 case AltosLib.AO_LOG_GPS_ALT:
34 case AltosLib.AO_LOG_GPS_SAT:
35 case AltosLib.AO_LOG_GPS_DATE:
44 case AltosLib.AO_LOG_FLIGHT:
45 state.set_state(AltosLib.ao_flight_pad);
46 state.set_ground_accel(data16(0));
47 state.set_flight(data16(2));
48 if (state.accel_plus_g == AltosLib.MISSING)
49 state.set_accel_g(data16(0), data16(0) + two_g_default);
51 case AltosLib.AO_LOG_SENSOR:
52 state.set_accel(data16(0));
53 state.set_pressure(AltosConvert.barometer_to_pressure(data16(2)));
55 case AltosLib.AO_LOG_PRESSURE:
56 state.set_pressure(AltosConvert.barometer_to_pressure(data16(2)));
58 case AltosLib.AO_LOG_TEMP_VOLT:
59 state.set_temperature(AltosConvert.thermometer_to_temperature(data16(0)));
60 state.set_battery_voltage(AltosConvert.cc_battery_to_voltage(data16(2)));
62 case AltosLib.AO_LOG_DEPLOY:
63 state.set_apogee_voltage(AltosConvert.cc_ignitor_to_voltage(data16(0)));
64 state.set_main_voltage(AltosConvert.cc_ignitor_to_voltage(data16(2)));
66 case AltosLib.AO_LOG_STATE:
67 state.set_state(data16(0));
69 case AltosLib.AO_LOG_GPS_TIME:
70 gps = state.make_temp_gps(false);
73 gps.minute = data8(1);
74 gps.second = data8(2);
78 gps.connected = (flags & AltosLib.AO_GPS_RUNNING) != 0;
79 gps.locked = (flags & AltosLib.AO_GPS_VALID) != 0;
80 gps.nsat = (flags & AltosLib.AO_GPS_NUM_SAT_MASK) >>
81 AltosLib.AO_GPS_NUM_SAT_SHIFT;
83 case AltosLib.AO_LOG_GPS_LAT:
84 gps = state.make_temp_gps(false);
86 int lat32 = data32(0);
87 gps.lat = (double) lat32 / 1e7;
89 case AltosLib.AO_LOG_GPS_LON:
90 gps = state.make_temp_gps(false);
92 int lon32 = data32(0);
93 gps.lon = (double) lon32 / 1e7;
95 case AltosLib.AO_LOG_GPS_ALT:
96 gps = state.make_temp_gps(false);
99 case AltosLib.AO_LOG_GPS_SAT:
100 gps = state.make_temp_gps(true);
101 int svid = data16(0);
102 int c_n0 = data16(3);
103 gps.add_sat(svid, c_n0);
105 case AltosLib.AO_LOG_GPS_DATE:
106 gps = state.make_temp_gps(false);
107 gps.year = data8(0) + 2000;
108 gps.month = data8(1);
114 public AltosEepromRecord next() {
115 int s = next_start();
118 return new AltosEepromRecordFull(eeprom, s);
121 public AltosEepromRecordFull(AltosEepromNew eeprom, int start) {
122 super(eeprom, start, record_length);
125 public AltosEepromRecordFull(AltosEepromNew eeprom) {