+ }
+ }
+
+ public void set_tick(int new_tick) {
+ if (new_tick != AltosLib.MISSING) {
+ if (prev_tick != AltosLib.MISSING) {
+ while (new_tick < prev_tick - 1000) {
+ new_tick += 65536;
+ }
+ }
+ tick = new_tick;
+ time = tick / 100.0;
+ time_change = time - prev_time;
+ }
+ }
+
+ public void set_boost_tick(int boost_tick) {
+ if (boost_tick != AltosLib.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_device_type(int device_type) {
+ this.device_type = device_type;
+ }
+
+ public void set_config(int major, int minor, int apogee_delay, int main_deploy, int flight_log_max) {
+ config_major = major;
+ config_minor = minor;
+ this.apogee_delay = apogee_delay;
+ this.main_deploy = main_deploy;
+ this.flight_log_max = flight_log_max;
+ }
+
+ public void set_callsign(String callsign) {
+ this.callsign = callsign;
+ }
+
+ public void set_firmware_version(String version) {
+ firmware_version = version;
+ }
+
+ public void set_flight(int flight) {
+
+ /* When the flight changes, reset the state */
+ if (flight != AltosLib.MISSING && flight != 0) {
+ if (this.flight != AltosLib.MISSING &&
+ this.flight != flight) {
+ int bt = boost_tick;
+ init();
+ boost_tick = bt;
+ }
+ this.flight = flight;
+ }
+ }
+
+ public void set_serial(int serial) {
+ /* When the serial changes, reset the state */
+ if (serial != AltosLib.MISSING) {
+ if (this.serial != AltosLib.MISSING &&
+ this.serial != serial) {
+ int bt = boost_tick;
+ init();
+ boost_tick = bt;
+ }
+ this.serial = serial;
+ }
+ }
+
+ public void set_receiver_serial(int serial) {
+ if (serial != AltosLib.MISSING)
+ receiver_serial = serial;
+ }
+
+ public int rssi() {
+ if (rssi == AltosLib.MISSING)
+ return 0;
+ return rssi;
+ }
+
+ public void set_rssi(int rssi, int status) {
+ if (rssi != AltosLib.MISSING) {
+ this.rssi = rssi;
+ this.status = status;
+ }
+ }
+
+ public void set_received_time(long ms) {
+ received_time = ms;
+ }
+
+ public void set_gps(AltosGPS gps, int sequence) {
+ if (gps != null) {
+ this.gps = gps.clone();
+ gps_sequence = sequence;
+ update_gps();
+ set |= set_gps;
+ }
+ }
+
+ public void set_imu(AltosIMU imu) {
+ if (imu != null)
+ imu = imu.clone();
+ this.imu = imu;
+ }
+
+ public void set_mag(AltosMag mag) {
+ this.mag = mag.clone();
+ }
+
+ public AltosMs5607 make_baro() {
+ if (baro == null)
+ baro = new AltosMs5607();
+ return baro;
+ }
+
+ public void set_ms5607(AltosMs5607 ms5607) {
+ baro = ms5607;
+
+ if (baro != null) {
+ set_pressure(baro.pa);
+ set_temperature(baro.cc / 100.0);
+ }
+ }
+
+ 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 AltosCompanion(nchannels);
+ }
+
+ public void set_companion(AltosCompanion companion) {
+ this.companion = companion;
+ }
+
+ void update_accel() {
+ double ground = ground_accel;
+
+ if (ground == AltosLib.MISSING)
+ ground = ground_accel_avg;
+ if (accel == AltosLib.MISSING)
+ return;
+ if (ground == AltosLib.MISSING)
+ return;
+ if (accel_plus_g == AltosLib.MISSING)
+ return;
+ if (accel_minus_g == AltosLib.MISSING)
+ return;
+
+ double counts_per_g = (accel_minus_g - accel_plus_g) / 2.0;
+ double counts_per_mss = counts_per_g / 9.80665;
+ acceleration.set_measured((ground - accel) / counts_per_mss, time);
+ }
+
+ public void set_accel_g(double accel_plus_g, double accel_minus_g) {
+ if (accel_plus_g != AltosLib.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 != AltosLib.MISSING) {
+ this.ground_accel = ground_accel;
+ update_accel();
+ }
+ }
+
+ public void set_accel(double accel) {
+ if (accel != AltosLib.MISSING) {
+ this.accel = accel;
+ if (state == AltosLib.ao_flight_pad) {
+ if (ground_accel_avg == AltosLib.MISSING)
+ ground_accel_avg = accel;
+ else
+ ground_accel_avg = (ground_accel_avg * 7 + accel) / 8;