+
+ if (gps == null)
+ return;
+
+ if (gps.locked && gps.nsat >= 4) {
+ /* Track consecutive 'good' gps reports, waiting for 10 of them */
+ if (state == AltosLib.ao_flight_pad) {
+ set_npad(npad+1);
+ if (pad_lat != AltosRecord.MISSING) {
+ pad_lat = (pad_lat * 31 + gps.lat) / 32;
+ pad_lon = (pad_lon * 31 + gps.lon) / 32;
+ pad_alt = (pad_alt * 31 + gps.alt) / 32;
+ }
+ }
+ if (pad_lat == AltosRecord.MISSING) {
+ pad_lat = gps.lat;
+ pad_lon = gps.lon;
+ pad_alt = gps.alt;
+ }
+ }
+ if (gps.lat != 0 && gps.lon != 0 &&
+ pad_lat != AltosRecord.MISSING &&
+ pad_lon != AltosRecord.MISSING)
+ {
+ double h = height;
+
+ if (h == AltosRecord.MISSING)
+ h = 0;
+ from_pad = new AltosGreatCircle(pad_lat, pad_lon, 0, gps.lat, gps.lon, h);
+ elevation = from_pad.elevation;
+ range = from_pad.range;
+ gps_height = gps.alt - pad_alt;
+ }
+ }
+
+ public void set_tick(int tick) {
+ if (tick != AltosRecord.MISSING) {
+ if (this.tick != AltosRecord.MISSING) {
+ while (tick < this.tick)
+ tick += 65536;
+ time_change = (tick - this.tick) / 100.0;
+ } else
+ time_change = 0;
+ this.tick = tick;
+ update_time();
+ }
+ }
+
+ public void set_boost_tick(int boost_tick) {
+ if (boost_tick != AltosRecord.MISSING)
+ this.boost_tick = boost_tick;
+ }
+
+ public String state_name() {
+ return AltosLib.state_name(state);
+ }
+
+ public void set_state(int state) {
+ if (state != AltosLib.ao_flight_invalid) {
+ this.state = state;
+ ascent = (AltosLib.ao_flight_boost <= state &&
+ state <= AltosLib.ao_flight_coast);
+ boost = (AltosLib.ao_flight_boost == state);
+ }
+
+ }
+
+ public void set_flight(int flight) {
+
+ /* When the flight changes, reset the state */
+ if (flight != AltosRecord.MISSING) {
+ if (this.flight != AltosRecord.MISSING &&
+ this.flight != flight) {
+ init();
+ }
+ this.flight = flight;
+ }
+ }
+
+ public void set_serial(int serial) {
+ /* When the serial changes, reset the state */
+ if (serial != AltosRecord.MISSING) {
+ if (this.serial != AltosRecord.MISSING &&
+ this.serial != serial) {
+ init();
+ }
+ this.serial = serial;
+ }
+ }
+
+ public int rssi() {
+ if (rssi == AltosRecord.MISSING)
+ return 0;
+ return rssi;
+ }
+
+ public void set_rssi(int rssi, int status) {
+ if (rssi != AltosRecord.MISSING) {
+ this.rssi = rssi;
+ this.status = status;
+ }
+ }
+
+ public void set_altitude(double altitude) {
+ if (altitude != AltosRecord.MISSING) {
+ this.altitude = altitude;
+ update_vertical_pos();
+ set |= set_position;
+ }
+ }
+
+ public void set_ground_altitude(double ground_altitude) {
+ if (ground_altitude != AltosRecord.MISSING) {
+ this.ground_altitude = ground_altitude;
+ update_vertical_pos();
+ }
+ }
+
+ public void set_ground_pressure (double pressure) {
+ if (pressure != AltosRecord.MISSING) {
+ this.ground_pressure = pressure;
+ set_ground_altitude(AltosConvert.pressure_to_altitude(pressure));
+ update_vertical_pos();
+ }
+ }
+
+ public void set_gps(AltosGPS gps, int sequence) {
+ if (gps != null) {
+ this.gps = gps.clone();
+ gps_sequence = sequence;
+ update_gps();
+ update_vertical_pos();
+ set |= set_gps;
+ }
+ }
+
+ public void set_kalman(double height, double speed, double acceleration) {
+ if (height != AltosRecord.MISSING) {
+ kalman_height = height;
+ kalman_speed = speed;
+ kalman_acceleration = acceleration;
+ update_vertical_pos();
+ }
+ }
+
+ 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;