+ public void set_pressure(double pressure) {
+ if (pressure != AltosRecord.MISSING) {
+ this.pressure = pressure;
+ set_altitude(AltosConvert.pressure_to_altitude(pressure));
+ }
+ }
+
+ public void make_baro() {
+ if (baro == null)
+ baro = new AltosMs5607();
+ }
+
+ public void set_ms5607(int pres, int temp) {
+ if (baro != null) {
+ baro.set(pres, temp);
+
+ set_pressure(baro.pa);
+ set_temperature(baro.cc / 100.0);
+ }
+ }
+
+ public void make_companion (int nchannels) {
+ if (companion == null)
+ companion = new AltosRecordCompanion(nchannels);
+ }
+
+ public void set_companion(AltosRecordCompanion companion) {
+ this.companion = companion;
+ }
+
+ public void set_accel_g(double accel_plus_g, double accel_minus_g) {
+ if (accel_plus_g != AltosRecord.MISSING) {
+ this.accel_plus_g = accel_plus_g;
+ this.accel_minus_g = accel_minus_g;
+ update_accel();
+ }
+ }
+ public void set_ground_accel(double ground_accel) {
+ if (ground_accel != AltosRecord.MISSING) {
+ this.ground_accel = ground_accel;
+ update_accel();
+ }
+ }
+
+ public void set_accel(double accel) {
+ if (accel != AltosRecord.MISSING) {
+ this.accel = accel;
+ if (state == AltosLib.ao_flight_pad) {
+ if (ground_accel_avg == AltosRecord.MISSING)
+ ground_accel_avg = accel;
+ else
+ ground_accel_avg = (ground_accel_avg * 7 + accel) / 8;
+ }
+ }
+ update_accel();
+ }
+
+ public void set_temperature(double temperature) {
+ if (temperature != AltosRecord.MISSING) {
+ this.temperature = temperature;
+ set |= set_data;
+ }
+ }
+
+ public void set_battery_voltage(double battery_voltage) {
+ if (battery_voltage != AltosRecord.MISSING) {
+ this.battery_voltage = battery_voltage;
+ set |= set_data;
+ }
+ }
+
+ public void set_pyro_voltage(double pyro_voltage) {
+ if (pyro_voltage != AltosRecord.MISSING) {
+ this.pyro_voltage = pyro_voltage;
+ set |= set_data;
+ }
+ }
+
+ public void set_apogee_voltage(double apogee_voltage) {
+ if (apogee_voltage != AltosRecord.MISSING) {
+ this.apogee_voltage = apogee_voltage;
+ set |= set_data;
+ }
+ }
+
+ public void set_main_voltage(double main_voltage) {
+ if (main_voltage != AltosRecord.MISSING) {
+ this.main_voltage = main_voltage;
+ set |= set_data;
+ }
+ }
+
+ public void set_ignitor_voltage(double[] voltage) {
+ this.ignitor_voltage = voltage;
+ }
+
+ public double time_since_boost() {
+ if (tick == AltosRecord.MISSING)
+ return 0.0;
+
+ if (boost_tick != AltosRecord.MISSING) {
+ return (tick - boost_tick) / 100.0;
+ }
+ return tick / 100.0;
+ }
+
+ public boolean valid() {
+ return tick != AltosRecord.MISSING && serial != AltosRecord.MISSING;
+ }
+
+ public AltosGPS make_temp_gps() {
+ if (temp_gps == null) {
+ temp_gps = new AltosGPS(gps);
+ temp_gps.cc_gps_sat = null;
+ }
+ gps_pending = true;
+ return temp_gps;
+ }
+
+ public void set_temp_gps() {
+ set_gps(temp_gps, gps_sequence + 1);
+ gps_pending = false;
+ temp_gps = null;
+ }
+
+ public AltosState clone() {
+ AltosState s = new AltosState();
+ s.copy(this);
+ return s;
+ }
+
+
+ public void init (AltosRecord cur, AltosState prev_state) {
+
+ System.out.printf ("init\n");
+ if (cur == null)
+ cur = new AltosRecord();
+
+ record = cur;
+
+ /* Discard previous state if it was for a different board */
+ if (prev_state != null && prev_state.serial != cur.serial)
+ prev_state = null;
+
+ copy(prev_state);
+
+ set_ground_altitude(cur.ground_altitude());
+ set_altitude(cur.altitude());
+
+ set_kalman(cur.kalman_height, cur.kalman_speed, cur.kalman_acceleration);
+
+ received_time = System.currentTimeMillis();
+
+ set_temperature(cur.temperature());
+ set_apogee_voltage(cur.drogue_voltage());
+ set_main_voltage(cur.main_voltage());
+ set_battery_voltage(cur.battery_voltage());
+
+ set_pressure(cur.pressure());
+
+ set_tick(cur.tick);
+ set_state(cur.state);
+
+ set_accel_g (cur.accel_minus_g, cur.accel_plus_g);
+ set_ground_accel(cur.ground_accel);
+ set_accel (cur.accel);
+
+ if (cur.gps_sequence != gps_sequence)
+ set_gps(cur.gps, cur.gps_sequence);
+
+ }
+