- static final int seen_basic = AltosRecord.seen_flight|AltosRecord.seen_sensor;
-
- boolean has_accel;
- boolean has_gps;
- boolean has_ignite;
-
- AltosEepromRecord flight_record;
- AltosEepromRecord gps_date_record;
-
- TreeSet<AltosOrderedRecord> records;
-
- LinkedList<AltosRecord> list;
-
- class EepromState {
- int seen;
- int n_pad_samples;
- double ground_pres;
- int gps_tick;
- int boost_tick;
- int sensor_tick;
-
- EepromState() {
- seen = 0;
- n_pad_samples = 0;
- ground_pres = 0.0;
- gps_tick = 0;
- }
- }
-
- void update_state(AltosRecordTM state, AltosEepromRecord record, EepromState eeprom) {
- state.tick = record.tick;
- switch (record.cmd) {
- case AltosLib.AO_LOG_FLIGHT:
- eeprom.seen |= AltosRecord.seen_flight;
- state.ground_accel = record.a;
- state.flight_accel = record.a;
- state.flight = record.b;
- eeprom.boost_tick = record.tick;
- break;
- case AltosLib.AO_LOG_SENSOR:
- state.accel = record.a;
- state.pres = record.b;
- if (state.state < AltosLib.ao_flight_boost) {
- eeprom.n_pad_samples++;
- eeprom.ground_pres += state.pres;
- state.ground_pres = (int) (eeprom.ground_pres / eeprom.n_pad_samples);
- state.flight_pres = state.ground_pres;
- } else {
- state.flight_pres = (state.flight_pres * 15 + state.pres) / 16;
- }
- state.flight_accel = (state.flight_accel * 15 + state.accel) / 16;
- if ((eeprom.seen & AltosRecord.seen_sensor) == 0)
- eeprom.sensor_tick = record.tick - 1;
- state.flight_vel += (state.accel_plus_g - state.accel) * (record.tick - eeprom.sensor_tick);
- eeprom.seen |= AltosRecord.seen_sensor;
- eeprom.sensor_tick = record.tick;
- has_accel = true;
- break;
- case AltosLib.AO_LOG_PRESSURE:
- state.pres = record.b;
- state.flight_pres = state.pres;
- if (eeprom.n_pad_samples == 0) {
- eeprom.n_pad_samples++;
- state.ground_pres = state.pres;
- }
- eeprom.seen |= AltosRecord.seen_sensor;
- break;
- case AltosLib.AO_LOG_TEMP_VOLT:
- state.temp = record.a;
- state.batt = record.b;
- eeprom.seen |= AltosRecord.seen_temp_volt;
- break;
- case AltosLib.AO_LOG_DEPLOY:
- state.drogue = record.a;
- state.main = record.b;
- eeprom.seen |= AltosRecord.seen_deploy;
- has_ignite = true;
- break;
- case AltosLib.AO_LOG_STATE:
- state.state = record.a;
- break;
- case AltosLib.AO_LOG_GPS_TIME:
- eeprom.gps_tick = state.tick;
- eeprom.seen |= AltosRecord.seen_gps_time;
- AltosGPS old = state.gps;
- state.gps = new AltosGPS();
-
- /* GPS date doesn't get repeated through the file */
- if (old != null) {
- state.gps.year = old.year;
- state.gps.month = old.month;
- state.gps.day = old.day;
- }
- state.gps.hour = (record.a & 0xff);
- state.gps.minute = (record.a >> 8);
- state.gps.second = (record.b & 0xff);
-
- int flags = (record.b >> 8);
- state.gps.connected = (flags & AltosLib.AO_GPS_RUNNING) != 0;
- state.gps.locked = (flags & AltosLib.AO_GPS_VALID) != 0;
- state.gps.nsat = (flags & AltosLib.AO_GPS_NUM_SAT_MASK) >>
- AltosLib.AO_GPS_NUM_SAT_SHIFT;
- state.new_gps = true;
- has_gps = true;
- break;
- case AltosLib.AO_LOG_GPS_LAT:
- eeprom.seen |= AltosRecord.seen_gps_lat;
- int lat32 = record.a | (record.b << 16);
- state.gps.lat = (double) lat32 / 1e7;
- break;
- case AltosLib.AO_LOG_GPS_LON:
- eeprom.seen |= AltosRecord.seen_gps_lon;
- int lon32 = record.a | (record.b << 16);
- state.gps.lon = (double) lon32 / 1e7;
- break;
- case AltosLib.AO_LOG_GPS_ALT:
- state.gps.alt = record.a;
- break;
- case AltosLib.AO_LOG_GPS_SAT:
- if (state.tick == eeprom.gps_tick) {
- int svid = record.a;
- int c_n0 = record.b >> 8;
- state.gps.add_sat(svid, c_n0);
- }
- break;
- case AltosLib.AO_LOG_GPS_DATE:
- state.gps.year = (record.a & 0xff) + 2000;
- state.gps.month = record.a >> 8;
- state.gps.day = record.b & 0xff;
- break;
-
- case AltosLib.AO_LOG_CONFIG_VERSION:
- break;
- case AltosLib.AO_LOG_MAIN_DEPLOY:
- break;
- case AltosLib.AO_LOG_APOGEE_DELAY:
- break;
- case AltosLib.AO_LOG_RADIO_CHANNEL:
- break;
- case AltosLib.AO_LOG_CALLSIGN:
- state.callsign = record.data;
- break;
- case AltosLib.AO_LOG_ACCEL_CAL:
- state.accel_plus_g = record.a;
- state.accel_minus_g = record.b;
- break;
- case AltosLib.AO_LOG_RADIO_CAL:
- break;
- case AltosLib.AO_LOG_MANUFACTURER:
- break;
- case AltosLib.AO_LOG_PRODUCT:
- break;
- case AltosLib.AO_LOG_SERIAL_NUMBER:
- state.serial = record.a;
- break;
- case AltosLib.AO_LOG_SOFTWARE_VERSION:
- break;
- }
- state.seen |= eeprom.seen;