+ AltosPressure AltosPressure_fromJson(AltosJson j, AltosPressure def) {
+ if (j == null) return def;
+ return new AltosPressure(j);
+ }
+
+ private AltosPressure pressure;
+
+ public double pressure() {
+ return pressure.value();
+ }
+
+ public void set_pressure(double p) {
+ pressure.set(p, time);
+ }
+
+ public double baro_height() {
+ double a = altitude();
+ double g = ground_altitude();
+ if (a != AltosLib.MISSING && g != AltosLib.MISSING)
+ return a - g;
+ return AltosLib.MISSING;
+ }
+
+ public double height() {
+ double k = kalman_height.value();
+ if (k != AltosLib.MISSING)
+ return k;
+
+ double b = baro_height();
+ if (b != AltosLib.MISSING)
+ return b;
+
+ return gps_height();
+ }
+
+ public double max_height() {
+ double k = kalman_height.max();
+ if (k != AltosLib.MISSING)
+ return k;
+
+ double a = altitude.max();
+ double g = ground_altitude();
+ if (a != AltosLib.MISSING && g != AltosLib.MISSING)
+ return a - g;
+ return max_gps_height();
+ }
+
+ public double gps_height() {
+ double a = gps_altitude();
+ double g = gps_ground_altitude();
+
+ if (a != AltosLib.MISSING && g != AltosLib.MISSING)
+ return a - g;
+ return AltosLib.MISSING;
+ }
+
+ public double max_gps_height() {
+ double a = gps_altitude.max();
+ double g = gps_ground_altitude();
+
+ if (a != AltosLib.MISSING && g != AltosLib.MISSING)
+ return a - g;
+ return AltosLib.MISSING;
+ }
+
+ class AltosSpeed extends AltosCValue implements AltosHashable {
+
+ boolean can_max() {
+ return state < AltosLib.ao_flight_fast || state == AltosLib.ao_flight_stateless;
+ }
+
+ void set_accel() {
+ acceleration.set_derivative(this);
+ }
+
+ void set_derivative(AltosCValue in) {
+ super.set_derivative(in);
+ set_accel();
+ }
+
+ void set_computed(double new_value, double time) {
+ super.set_computed(new_value, time);
+ set_accel();
+ }
+
+ void set_measured(double new_value, double time) {
+ super.set_measured(new_value, time);
+ set_accel();
+ }
+
+ AltosSpeed() {
+ super();
+ }
+
+ AltosSpeed (AltosHashSet h) {
+ super(h);
+ }
+
+ AltosSpeed (AltosJson j) {
+ super(j);
+ }
+ }
+
+ AltosSpeed AltosSpeed_fromHashSet(AltosHashSet h, AltosSpeed def) {
+ if (h == null) return def;
+ return new AltosSpeed(h);
+ }
+
+ AltosSpeed AltosSpeed_fromJson(AltosJson j, AltosSpeed def) {
+ if (j == null) return def;
+ return new AltosSpeed(j);
+ }
+
+ private AltosSpeed speed;
+
+ public double speed() {
+ double v = kalman_speed.value();
+ if (v != AltosLib.MISSING)
+ return v;
+ v = speed.value();
+ if (v != AltosLib.MISSING)
+ return v;
+ v = gps_speed();
+ if (v != AltosLib.MISSING)
+ return v;
+ return AltosLib.MISSING;
+ }
+
+ public double max_speed() {
+ double v = kalman_speed.max();
+ if (v != AltosLib.MISSING)
+ return v;
+ v = speed.max();
+ if (v != AltosLib.MISSING)
+ return v;
+ v = max_gps_speed();
+ if (v != AltosLib.MISSING)
+ return v;
+ return AltosLib.MISSING;
+ }
+
+ class AltosAccel extends AltosCValue implements AltosHashable {
+
+ boolean can_max() {
+ return state < AltosLib.ao_flight_fast || state == AltosLib.ao_flight_stateless;
+ }
+
+ void set_measured(double a, double time) {
+ super.set_measured(a, time);
+ if (ascent)
+ speed.set_integral(this.measured);
+ }
+
+ AltosAccel() {
+ super();
+ }
+
+ AltosAccel (AltosHashSet h) {
+ super(h);
+ }
+
+ AltosAccel (AltosJson j) {
+ super(j);
+ }
+ }
+
+ AltosAccel AltosAccel_fromHashSet(AltosHashSet h, AltosAccel def) {
+ if (h == null) return def;
+ return new AltosAccel(h);
+ }
+
+ AltosAccel AltosAccel_fromJson(AltosJson j, AltosAccel def) {
+ if (j == null) return def;
+ return new AltosAccel(j);
+ }
+
+ AltosAccel acceleration;
+
+ public double acceleration() {
+ return acceleration.value();
+ }
+
+ public double max_acceleration() {
+ return acceleration.max();
+ }
+
+ public AltosCValue orient;
+
+ public void set_orient(double new_orient) {
+ orient.set_measured(new_orient, time);
+ }
+
+ public double orient() {
+ return orient.value();
+ }
+
+ public double max_orient() {
+ return orient.max();
+ }
+
+ public AltosValue kalman_height, kalman_speed, kalman_acceleration;
+
+ public void set_kalman(double height, double speed, double acceleration) {
+ kalman_height.set(height, time);
+ kalman_speed.set(speed, time);
+ kalman_acceleration.set(acceleration, time);
+ }
+
+ public double battery_voltage;
+ public double pyro_voltage;
+ public double temperature;
+ public double apogee_voltage;
+ public double main_voltage;
+
+ public double ignitor_voltage[];
+
+ public AltosGPS gps;
+ public AltosGPS temp_gps;
+ public int temp_gps_sat_tick;
+ public boolean gps_pending;
+ public int gps_sequence;
+
+ public AltosIMU imu;
+ public AltosMag mag;
+
+ public static final int MIN_PAD_SAMPLES = 10;
+
+ public int npad;
+ public int gps_waiting;
+ public boolean gps_ready;
+
+ public int ngps;
+
+ public AltosGreatCircle from_pad;
+ public double elevation; /* from pad */
+ public double range; /* total distance */
+
+ public double gps_height;
+
+ public double pad_lat, pad_lon, pad_alt;
+
+ public int speak_tick;
+ public double speak_altitude;
+
+ public String callsign;
+ public String firmware_version;
+
+ public double accel_plus_g;
+ public double accel_minus_g;
+ public double accel;
+ public double ground_accel;
+ public double ground_accel_avg;
+
+ public int log_format;
+ public int log_space;
+ public String product;
+
+ public AltosMs5607 baro;
+
+ public AltosCompanion companion;
+
+ public int pyro_fired;
+
+ public void set_npad(int npad) {
+ this.npad = npad;
+ gps_waiting = MIN_PAD_SAMPLES - npad;
+ if (this.gps_waiting < 0)
+ gps_waiting = 0;
+ gps_ready = gps_waiting == 0;
+ }
+
+ public void init() {
+ set = 0;
+
+ received_time = System.currentTimeMillis();
+ time = AltosLib.MISSING;
+ time_change = AltosLib.MISSING;
+ prev_time = AltosLib.MISSING;
+ tick = AltosLib.MISSING;
+ prev_tick = AltosLib.MISSING;
+ boost_tick = AltosLib.MISSING;
+ state = AltosLib.ao_flight_invalid;
+ flight = AltosLib.MISSING;
+ landed = false;
+ boost = false;
+ rssi = AltosLib.MISSING;
+ status = 0;
+ device_type = AltosLib.MISSING;
+ config_major = AltosLib.MISSING;
+ config_minor = AltosLib.MISSING;
+ apogee_delay = AltosLib.MISSING;
+ main_deploy = AltosLib.MISSING;
+ flight_log_max = AltosLib.MISSING;
+
+ ground_altitude = new AltosCValue();
+ ground_pressure = new AltosGroundPressure();
+ altitude = new AltosAltitude();
+ pressure = new AltosPressure();
+ speed = new AltosSpeed();
+ acceleration = new AltosAccel();
+ orient = new AltosCValue();
+
+ temperature = AltosLib.MISSING;
+ battery_voltage = AltosLib.MISSING;
+ pyro_voltage = AltosLib.MISSING;
+ apogee_voltage = AltosLib.MISSING;
+ main_voltage = AltosLib.MISSING;
+ ignitor_voltage = null;
+
+ kalman_height = new AltosValue();
+ kalman_speed = new AltosValue();
+ kalman_acceleration = new AltosValue();
+
+ gps = null;
+ temp_gps = null;
+ temp_gps_sat_tick = 0;
+ gps_sequence = 0;
+ gps_pending = false;
+
+ imu = null;
+ last_imu_time = AltosLib.MISSING;
+ rotation = null;
+ ground_rotation = null;
+
+ mag = null;
+ accel_zero_along = AltosLib.MISSING;
+ accel_zero_across = AltosLib.MISSING;
+ accel_zero_through = AltosLib.MISSING;
+
+ accel_ground_along = AltosLib.MISSING;
+ accel_ground_across = AltosLib.MISSING;
+ accel_ground_through = AltosLib.MISSING;
+
+ pad_orientation = AltosLib.MISSING;
+
+ gyro_zero_roll = AltosLib.MISSING;
+ gyro_zero_pitch = AltosLib.MISSING;
+ gyro_zero_yaw = AltosLib.MISSING;
+
+ set_npad(0);
+ ngps = 0;
+
+ from_pad = null;
+ elevation = AltosLib.MISSING;
+ range = AltosLib.MISSING;
+ gps_height = AltosLib.MISSING;
+
+ pad_lat = AltosLib.MISSING;
+ pad_lon = AltosLib.MISSING;
+ pad_alt = AltosLib.MISSING;
+
+ gps_altitude = new AltosGpsAltitude();
+ gps_ground_altitude = new AltosGpsGroundAltitude();
+ gps_ground_speed = new AltosValue();
+ gps_speed = new AltosValue();
+ gps_ascent_rate = new AltosValue();
+ gps_course = new AltosValue();
+
+ speak_tick = AltosLib.MISSING;
+ speak_altitude = AltosLib.MISSING;
+
+ callsign = null;
+ firmware_version = null;
+
+ accel_plus_g = AltosLib.MISSING;
+ accel_minus_g = AltosLib.MISSING;
+ accel = AltosLib.MISSING;
+
+ ground_accel = AltosLib.MISSING;
+ ground_accel_avg = AltosLib.MISSING;
+
+ log_format = AltosLib.MISSING;
+ log_space = AltosLib.MISSING;
+ product = null;
+ serial = AltosLib.MISSING;
+ receiver_serial = AltosLib.MISSING;
+ altitude_32 = AltosLib.MISSING;
+
+ baro = null;
+ companion = null;
+
+ pyro_fired = 0;
+ }
+
+ void finish_update() {
+ prev_tick = tick;
+
+ ground_altitude.finish_update();
+ altitude.finish_update();
+ pressure.finish_update();
+ speed.finish_update();
+ acceleration.finish_update();
+ orient.finish_update();
+
+ kalman_height.finish_update();
+ kalman_speed.finish_update();
+ kalman_acceleration.finish_update();
+ }
+
+ void copy(AltosState old) {
+
+ if (old == null) {
+ init();
+ return;
+ }
+
+ received_time = old.received_time;
+ time = old.time;
+ time_change = old.time_change;
+ prev_time = old.time;
+
+ tick = old.tick;
+ prev_tick = old.tick;
+ boost_tick = old.boost_tick;
+
+ state = old.state;
+ flight = old.flight;
+ landed = old.landed;
+ ascent = old.ascent;
+ boost = old.boost;
+ rssi = old.rssi;
+ status = old.status;
+ device_type = old.device_type;
+ config_major = old.config_major;
+ config_minor = old.config_minor;
+ apogee_delay = old.apogee_delay;
+ main_deploy = old.main_deploy;
+ flight_log_max = old.flight_log_max;
+
+ set = 0;
+
+ ground_pressure.copy(old.ground_pressure);
+ ground_altitude.copy(old.ground_altitude);
+ altitude.copy(old.altitude);
+ pressure.copy(old.pressure);
+ speed.copy(old.speed);
+ acceleration.copy(old.acceleration);
+ orient.copy(old.orient);
+
+ battery_voltage = old.battery_voltage;
+ pyro_voltage = old.pyro_voltage;
+ temperature = old.temperature;
+ apogee_voltage = old.apogee_voltage;
+ main_voltage = old.main_voltage;
+ ignitor_voltage = old.ignitor_voltage;
+
+ kalman_height.copy(old.kalman_height);
+ kalman_speed.copy(old.kalman_speed);
+ kalman_acceleration.copy(old.kalman_acceleration);
+
+ if (old.gps != null)
+ gps = old.gps.clone();
+ else
+ gps = null;
+ if (old.temp_gps != null)
+ temp_gps = old.temp_gps.clone();
+ else
+ temp_gps = null;
+ temp_gps_sat_tick = old.temp_gps_sat_tick;
+ gps_sequence = old.gps_sequence;
+ gps_pending = old.gps_pending;
+
+ if (old.imu != null)
+ imu = old.imu.clone();
+ else
+ imu = null;
+ last_imu_time = old.last_imu_time;
+
+ if (old.rotation != null)
+ rotation = new AltosRotation (old.rotation);
+
+ if (old.ground_rotation != null) {
+ ground_rotation = new AltosRotation(old.ground_rotation);
+ }
+
+ accel_zero_along = old.accel_zero_along;
+ accel_zero_across = old.accel_zero_across;
+ accel_zero_through = old.accel_zero_through;
+
+ accel_ground_along = old.accel_ground_along;
+ accel_ground_across = old.accel_ground_across;
+ accel_ground_through = old.accel_ground_through;
+ pad_orientation = old.pad_orientation;
+
+ gyro_zero_roll = old.gyro_zero_roll;
+ gyro_zero_pitch = old.gyro_zero_pitch;
+ gyro_zero_yaw = old.gyro_zero_yaw;
+
+ if (old.mag != null)
+ mag = old.mag.clone();
+ else
+ mag = null;
+
+ npad = old.npad;
+ gps_waiting = old.gps_waiting;
+ gps_ready = old.gps_ready;
+ ngps = old.ngps;
+
+ if (old.from_pad != null)
+ from_pad = old.from_pad.clone();
+ else
+ from_pad = null;
+
+ elevation = old.elevation;
+ range = old.range;
+
+ gps_height = old.gps_height;
+
+ gps_altitude.copy(old.gps_altitude);
+ gps_ground_altitude.copy(old.gps_ground_altitude);
+ gps_ground_speed.copy(old.gps_ground_speed);
+ gps_ascent_rate.copy(old.gps_ascent_rate);
+ gps_course.copy(old.gps_course);
+ gps_speed.copy(old.gps_speed);
+
+ pad_lat = old.pad_lat;
+ pad_lon = old.pad_lon;
+ pad_alt = old.pad_alt;
+
+ speak_tick = old.speak_tick;
+ speak_altitude = old.speak_altitude;
+
+ callsign = old.callsign;
+ firmware_version = old.firmware_version;
+
+ accel_plus_g = old.accel_plus_g;
+ accel_minus_g = old.accel_minus_g;
+ accel = old.accel;
+ ground_accel = old.ground_accel;
+ ground_accel_avg = old.ground_accel_avg;
+
+ log_format = old.log_format;
+ log_space = old.log_space;
+ product = old.product;
+ serial = old.serial;
+ receiver_serial = old.receiver_serial;
+ altitude_32 = old.altitude_32;
+
+ baro = old.baro;
+ companion = old.companion;
+
+ pyro_fired = old.pyro_fired;
+ }
+
+ void update_time() {
+ }
+
+ void update_gps() {
+ elevation = AltosLib.MISSING;
+ range = AltosLib.MISSING;
+
+ 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 || state == AltosLib.ao_flight_stateless) {
+ set_npad(npad+1);
+ if (pad_lat != AltosLib.MISSING && (npad < 10 || state == AltosLib.ao_flight_pad)) {
+ pad_lat = (pad_lat * 31 + gps.lat) / 32;
+ pad_lon = (pad_lon * 31 + gps.lon) / 32;
+ gps_ground_altitude.set_filtered(gps.alt, time);
+ }
+ }
+ if (pad_lat == AltosLib.MISSING) {
+ pad_lat = gps.lat;
+ pad_lon = gps.lon;
+ gps_ground_altitude.set(gps.alt, time);
+ }
+ gps_altitude.set(gps.alt, time);
+ if (gps.climb_rate != AltosLib.MISSING)
+ gps_ascent_rate.set(gps.climb_rate, time);
+ if (gps.ground_speed != AltosLib.MISSING)
+ gps_ground_speed.set(gps.ground_speed, time);
+ if (gps.climb_rate != AltosLib.MISSING && gps.ground_speed != AltosLib.MISSING)
+ gps_speed.set(Math.sqrt(gps.ground_speed * gps.ground_speed +
+ gps.climb_rate * gps.climb_rate), time);
+ if (gps.course != AltosLib.MISSING)
+ gps_course.set(gps.course, time);
+ }
+ if (gps.lat != 0 && gps.lon != 0 &&
+ pad_lat != AltosLib.MISSING &&
+ pad_lon != AltosLib.MISSING)
+ {
+ double h = height();
+
+ if (h == AltosLib.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;
+ }
+ }
+
+ 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_product(String product) {
+ this.product = product;
+ }
+
+ 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 int state() {
+ return state;
+ }
+
+ public void set_device_type(int device_type) {
+ this.device_type = device_type;
+ switch (device_type) {
+ case AltosLib.product_telegps:
+ this.state = AltosLib.ao_flight_stateless;
+ break;
+ }
+ }
+
+ public void set_log_format(int log_format) {
+ this.log_format = log_format;
+ switch (log_format) {
+ case AltosLib.AO_LOG_FORMAT_TELEGPS:
+ this.state = AltosLib.ao_flight_stateless;
+ break;
+ }
+ }
+
+ public void set_log_space(int log_space) {
+ this.log_space = log_space;
+ }
+
+ public void set_flight_params(int apogee_delay, int main_deploy) {
+ this.apogee_delay = apogee_delay;
+ this.main_deploy = main_deploy;
+ }
+
+ public void set_config(int major, int minor, int flight_log_max) {
+ config_major = major;
+ config_minor = minor;
+ 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 int compare_version(String other_version) {
+ if (firmware_version == null)
+ return AltosLib.MISSING;
+ return AltosLib.compare_version(firmware_version, other_version);
+ }
+
+ private void re_init() {
+ int bt = boost_tick;
+ int rs = receiver_serial;
+ init();
+ boost_tick = bt;
+ receiver_serial = rs;
+ }
+
+ public void set_flight(int flight) {
+
+ /* When the flight changes, reset the state */
+ if (flight != AltosLib.MISSING) {
+ if (this.flight != AltosLib.MISSING &&
+ this.flight != flight) {
+ re_init();
+ }
+ 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) {
+ re_init();
+ }
+ this.serial = serial;
+ }
+ }
+
+ public void set_receiver_serial(int serial) {
+ if (serial != AltosLib.MISSING)
+ receiver_serial = serial;
+ }
+
+ public boolean altitude_32() {
+ return altitude_32 == 1;
+ }
+
+ public void set_altitude_32(int altitude_32) {
+ if (altitude_32 != AltosLib.MISSING)
+ this.altitude_32 = altitude_32;
+ }
+
+ 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 double accel_zero_along;
+ public double accel_zero_across;
+ public double accel_zero_through;
+
+ public AltosRotation rotation;
+ public AltosRotation ground_rotation;
+
+ public void set_accel_zero(double zero_along, double zero_across, double zero_through) {
+ if (zero_along != AltosLib.MISSING) {
+ accel_zero_along = zero_along;
+ accel_zero_across = zero_across;
+ accel_zero_through = zero_through;
+ }
+ }
+
+ public int pad_orientation;
+
+ public double accel_ground_along, accel_ground_across, accel_ground_through;
+
+ void update_pad_rotation() {
+ if (pad_orientation != AltosLib.MISSING && accel_ground_along != AltosLib.MISSING) {
+ rotation = new AltosRotation(AltosIMU.convert_accel(accel_ground_across - accel_zero_across),
+ AltosIMU.convert_accel(accel_ground_through - accel_zero_through),
+ AltosIMU.convert_accel(accel_ground_along - accel_zero_along),
+ pad_orientation);
+ ground_rotation = rotation;
+ orient.set_computed(rotation.tilt(), time);
+ }
+ }
+
+ public void set_accel_ground(double ground_along, double ground_across, double ground_through) {
+ accel_ground_along = ground_along;
+ accel_ground_across = ground_across;
+ accel_ground_through = ground_through;
+ update_pad_rotation();
+ }
+
+ public void set_pad_orientation(int pad_orientation) {
+ this.pad_orientation = pad_orientation;
+ update_pad_rotation();
+ }
+
+ public double gyro_zero_roll;
+ public double gyro_zero_pitch;
+ public double gyro_zero_yaw;
+
+ public void set_gyro_zero(double roll, double pitch, double yaw) {
+ if (roll != AltosLib.MISSING) {
+ gyro_zero_roll = roll;
+ gyro_zero_pitch = pitch;
+ gyro_zero_yaw = yaw;
+ }
+ }
+
+ public double last_imu_time;
+
+ private double radians(double degrees) {
+ if (degrees == AltosLib.MISSING)
+ return AltosLib.MISSING;
+ return degrees * Math.PI / 180.0;
+ }
+
+ private void update_orient() {
+ if (last_imu_time != AltosLib.MISSING) {
+ double t = time - last_imu_time;
+
+ double pitch = radians(gyro_pitch());
+ double yaw = radians(gyro_yaw());
+ double roll = radians(gyro_roll());
+
+ if (t > 0 & pitch != AltosLib.MISSING && rotation != null) {
+ rotation.rotate(t, pitch, yaw, roll);
+ orient.set_computed(rotation.tilt(), time);
+ }
+ }
+ last_imu_time = time;
+ }
+
+ public void set_imu(AltosIMU imu) {
+ if (imu != null)
+ imu = imu.clone();
+ this.imu = imu;
+ update_orient();
+ }
+
+ private double gyro_zero_overflow(double first) {
+ double v = first / 128.0;
+ if (v < 0)
+ v = Math.ceil(v);
+ else
+ v = Math.floor(v);
+ return v * 128.0;
+ }
+
+ public void check_imu_wrap(AltosIMU imu) {
+ if (this.imu == null) {
+ gyro_zero_roll += gyro_zero_overflow(imu.gyro_roll);
+ gyro_zero_pitch += gyro_zero_overflow(imu.gyro_pitch);
+ gyro_zero_yaw += gyro_zero_overflow(imu.gyro_yaw);
+ }
+ }
+
+ public double accel_along() {
+ if (imu != null && accel_zero_along != AltosLib.MISSING)
+ return AltosIMU.convert_accel(imu.accel_along - accel_zero_along);
+ return AltosLib.MISSING;
+ }
+
+ public double accel_across() {
+ if (imu != null && accel_zero_across != AltosLib.MISSING)
+ return AltosIMU.convert_accel(imu.accel_across - accel_zero_across);
+ return AltosLib.MISSING;
+ }
+
+ public double accel_through() {
+ if (imu != null && accel_zero_through != AltosLib.MISSING)
+ return AltosIMU.convert_accel(imu.accel_through - accel_zero_through);
+ return AltosLib.MISSING;
+ }
+
+ public double gyro_roll() {
+ if (imu != null && gyro_zero_roll != AltosLib.MISSING) {
+ return AltosIMU.convert_gyro(imu.gyro_roll - gyro_zero_roll);
+ }
+ return AltosLib.MISSING;
+ }
+
+ public double gyro_pitch() {
+ if (imu != null && gyro_zero_pitch != AltosLib.MISSING) {
+ return AltosIMU.convert_gyro(imu.gyro_pitch - gyro_zero_pitch);
+ }
+ return AltosLib.MISSING;
+ }
+
+ public double gyro_yaw() {
+ if (imu != null && gyro_zero_yaw != AltosLib.MISSING) {
+ return AltosIMU.convert_gyro(imu.gyro_yaw - gyro_zero_yaw);
+ }
+ return AltosLib.MISSING;
+ }
+
+ public void set_mag(AltosMag mag) {
+ this.mag = mag.clone();
+ }
+
+ public double mag_along() {
+ if (mag != null)
+ return AltosMag.convert_gauss(mag.along);
+ return AltosLib.MISSING;
+ }
+
+ public double mag_across() {
+ if (mag != null)
+ return AltosMag.convert_gauss(mag.across);
+ return AltosLib.MISSING;
+ }
+
+ public double mag_through() {
+ if (mag != null)
+ return AltosMag.convert_gauss(mag.through);
+ return AltosLib.MISSING;
+ }
+
+ 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 set_companion(AltosCompanion companion) {
+ this.companion = companion;
+ }
+
+ void update_accel() {
+ if (accel == 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((accel_plus_g - 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;
+ }
+
+ 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;
+ }
+ }
+ update_accel();
+ }
+
+ public void set_temperature(double temperature) {
+ if (temperature != AltosLib.MISSING) {
+ this.temperature = temperature;
+ set |= set_data;
+ }
+ }
+
+ public void set_battery_voltage(double battery_voltage) {
+ if (battery_voltage != AltosLib.MISSING) {
+ this.battery_voltage = battery_voltage;
+ set |= set_data;
+ }
+ }
+
+ public void set_pyro_voltage(double pyro_voltage) {
+ if (pyro_voltage != AltosLib.MISSING) {
+ this.pyro_voltage = pyro_voltage;
+ set |= set_data;
+ }
+ }
+
+ public void set_apogee_voltage(double apogee_voltage) {
+ if (apogee_voltage != AltosLib.MISSING) {
+ this.apogee_voltage = apogee_voltage;
+ set |= set_data;
+ }
+ }
+
+ public void set_main_voltage(double main_voltage) {
+ if (main_voltage != AltosLib.MISSING) {
+ this.main_voltage = main_voltage;
+ set |= set_data;
+ }
+ }
+
+ public void set_ignitor_voltage(double[] voltage) {
+ this.ignitor_voltage = voltage;
+ }
+
+ public void set_pyro_fired(int fired) {
+ this.pyro_fired = fired;
+ }
+
+ public double time_since_boost() {
+ if (tick == AltosLib.MISSING)
+ return 0.0;
+
+ if (boost_tick == AltosLib.MISSING)
+ return tick / 100.0;
+ return (tick - boost_tick) / 100.0;
+ }
+
+ public boolean valid() {
+ return tick != AltosLib.MISSING && serial != AltosLib.MISSING;
+ }
+
+ public AltosGPS make_temp_gps(boolean sats) {
+ if (temp_gps == null) {
+ temp_gps = new AltosGPS(gps);
+ }
+ gps_pending = true;
+ if (sats) {
+ if (tick != temp_gps_sat_tick)
+ temp_gps.cc_gps_sat = null;
+ temp_gps_sat_tick = tick;
+ }
+ 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);
+
+ if (false) {
+ AltosJson json = json();
+ String onetrip = json.toPrettyString();
+ AltosJson back = AltosJson.fromString(onetrip);
+ AltosState tripstate = AltosState.fromJson(back);
+ AltosJson tripjson = tripstate.json();
+ String twotrip = tripjson.toPrettyString();
+
+ if (!onetrip.equals(twotrip)) {
+ System.out.printf("one:\n%s\ntwo:\n%s\n", onetrip, twotrip);
+ System.exit(1);
+ }
+ }
+ if (false) {
+ AltosHashSet hash = hashSet();
+ String onetrip = hash.toString();
+ AltosHashSet back = AltosHashSet.fromString(onetrip);
+ AltosState tripstate = AltosState.fromHashSet(back);
+ AltosHashSet triphash = tripstate.hashSet();
+ String twotrip = triphash.toString();
+
+ if (!onetrip.equals(twotrip)) {
+ System.out.printf("%s\n%s\n", onetrip, twotrip);
+ System.exit(1);
+ }
+ }
+ return s;
+ }
+
+ public AltosState () {
+ init();
+ }
+
+ public AltosHashSet hashSet() {
+ AltosHashSet h = new AltosHashSet();
+
+ h.putBoolean("valid", true);
+ h.putInt("set", set);
+ h.putLong("received_time", received_time);
+ h.putDouble("time", time);
+ h.putDouble("prev_time", prev_time);
+ h.putDouble("time_change", time_change);
+ h.putInt("tick", tick);
+ h.putInt("prev_tick", prev_tick);
+ h.putInt("boost_tick", boost_tick);
+ h.putInt("state", state);
+ h.putInt("flight", flight);
+ h.putInt("serial", serial);
+ h.putInt("altitude_32", altitude_32);
+ h.putInt("receiver_serial", receiver_serial);
+ h.putBoolean("landed", landed);
+ h.putBoolean("ascent", ascent);
+ h.putBoolean("boost", boost);
+ h.putInt("rssi", rssi);
+ h.putInt("status", status);
+ h.putInt("device_type", device_type);
+ h.putInt("config_major", config_major);
+ h.putInt("config_minor", config_minor);
+ h.putInt("apogee_delay", apogee_delay);
+ h.putInt("main_deploy", main_deploy);
+ h.putInt("flight_log_max", flight_log_max);
+ h.putHashable("ground_altitude", ground_altitude);
+ h.putHashable("gps_ground_altitude", gps_ground_altitude);
+ h.putHashable("ground_pressure", ground_pressure);
+ h.putHashable("altitude", altitude);
+ h.putHashable("gps_altitude", gps_altitude);
+ h.putHashable("gps_ground_speed", gps_ground_speed);
+ h.putHashable("gps_ascent_rate", gps_ascent_rate);
+ h.putHashable("gps_course", gps_course);
+ h.putHashable("gps_speed", gps_speed);
+ h.putHashable("pressure", pressure);
+ h.putHashable("speed", speed);
+ h.putHashable("acceleration", acceleration);
+ h.putHashable("orient", orient);
+ h.putHashable("kalman_height", kalman_height);
+ h.putHashable("kalman_speed", kalman_speed);
+ h.putHashable("kalman_acceleration", kalman_acceleration);
+
+ h.putDouble("battery_voltage",battery_voltage);
+ h.putDouble("pyro_voltage",pyro_voltage);
+ h.putDouble("temperature",temperature);
+ h.putDouble("apogee_voltage",apogee_voltage);
+ h.putDouble("main_voltage",main_voltage);
+ h.putDoubleArray("ignitor_voltage",ignitor_voltage);
+ h.putHashable("gps", gps);
+ h.putHashable("temp_gps", temp_gps);
+ h.putInt("temp_gps_sat_tick", temp_gps_sat_tick);
+ h.putBoolean("gps_pending", gps_pending);
+ h.putInt("gps_sequence", gps_sequence);
+ h.putHashable("imu", imu);
+ h.putHashable("mag", mag);
+
+ h.putInt("npad", npad);
+ h.putInt("gps_waiting", gps_waiting);
+ h.putBoolean("gps_ready", gps_ready);
+ h.putInt("ngps", ngps);
+ h.putHashable("from_pad", from_pad);
+ h.putDouble("elevation", elevation);
+ h.putDouble("range", range);
+ h.putDouble("gps_height", gps_height);
+ h.putDouble("pad_lat", pad_lat);
+ h.putDouble("pad_lon", pad_lon);
+ h.putDouble("pad_alt", pad_alt);
+ h.putInt("speak_tick", speak_tick);
+ h.putDouble("speak_altitude", speak_altitude);
+ h.putString("callsign", callsign);
+ h.putString("firmware_version", firmware_version);
+ h.putDouble("accel_plus_g", accel_plus_g);
+ h.putDouble("accel_minus_g", accel_minus_g);
+ h.putDouble("accel", accel);
+ h.putDouble("ground_accel", ground_accel);
+ h.putDouble("ground_accel_avg", ground_accel_avg);
+ h.putInt("log_format", log_format);
+ h.putInt("log_space", log_space);
+ h.putString("product", product);
+ h.putHashable("baro", baro);
+ h.putHashable("companion", companion);
+ h.putInt("pyro_fired", pyro_fired);
+ h.putDouble("accel_zero_along", accel_zero_along);
+ h.putDouble("accel_zero_across", accel_zero_across);
+ h.putDouble("accel_zero_through", accel_zero_through);
+
+ h.putHashable("rotation", rotation);
+ h.putHashable("ground_rotation", ground_rotation);
+
+ h.putInt("pad_orientation", pad_orientation);
+
+ h.putDouble("accel_ground_along", accel_ground_along);
+ h.putDouble("accel_ground_across", accel_ground_across);
+ h.putDouble("accel_ground_through", accel_ground_through);
+
+ h.putDouble("gyro_zero_roll", gyro_zero_roll);
+ h.putDouble("gyro_zero_pitch", gyro_zero_pitch);
+ h.putDouble("gyro_zero_yaw", gyro_zero_yaw);
+
+ h.putDouble("last_imu_time", last_imu_time);
+ return h;
+ }
+
+ public AltosJson json() {
+ AltosJson j = new AltosJson();
+
+ j.put("valid", true);
+ j.put("set", set);
+ j.put("received_time", received_time);
+ j.put("time", time);
+ j.put("prev_time", prev_time);
+ j.put("time_change", time_change);
+ j.put("tick", tick);
+ j.put("prev_tick", prev_tick);
+ j.put("boost_tick", boost_tick);
+ j.put("state", state);
+ j.put("flight", flight);
+ j.put("serial", serial);
+ j.put("altitude_32", altitude_32);
+ j.put("receiver_serial", receiver_serial);
+ j.put("landed", landed);
+ j.put("ascent", ascent);
+ j.put("boost", boost);
+ j.put("rssi", rssi);
+ j.put("status", status);
+ j.put("device_type", device_type);
+ j.put("config_major", config_major);
+ j.put("config_minor", config_minor);
+ j.put("apogee_delay", apogee_delay);
+ j.put("main_deploy", main_deploy);
+ j.put("flight_log_max", flight_log_max);
+ j.put("ground_altitude", ground_altitude);
+ j.put("gps_ground_altitude", gps_ground_altitude);
+ j.put("ground_pressure", ground_pressure);
+ j.put("altitude", altitude);
+ j.put("gps_altitude", gps_altitude);
+ j.put("gps_ground_speed", gps_ground_speed);
+ j.put("gps_ascent_rate", gps_ascent_rate);
+ j.put("gps_course", gps_course);
+ j.put("gps_speed", gps_speed);
+ j.put("pressure", pressure);
+ j.put("speed", speed);
+ j.put("acceleration", acceleration);
+ j.put("orient", orient);
+ j.put("kalman_height", kalman_height);
+ j.put("kalman_speed", kalman_speed);
+ j.put("kalman_acceleration", kalman_acceleration);
+
+ j.put("battery_voltage",battery_voltage);
+ j.put("pyro_voltage",pyro_voltage);
+ j.put("temperature",temperature);
+ j.put("apogee_voltage",apogee_voltage);
+ j.put("main_voltage",main_voltage);
+ j.put("ignitor_voltage",ignitor_voltage);
+ j.put("gps", gps);
+ j.put("temp_gps", temp_gps);
+ j.put("temp_gps_sat_tick", temp_gps_sat_tick);
+ j.put("gps_pending", gps_pending);
+ j.put("gps_sequence", gps_sequence);
+ j.put("imu", imu);
+ j.put("mag", mag);
+
+ j.put("npad", npad);
+ j.put("gps_waiting", gps_waiting);
+ j.put("gps_ready", gps_ready);
+ j.put("ngps", ngps);
+ j.put("from_pad", from_pad);
+ j.put("elevation", elevation);
+ j.put("range", range);
+ j.put("gps_height", gps_height);
+ j.put("pad_lat", pad_lat);
+ j.put("pad_lon", pad_lon);
+ j.put("pad_alt", pad_alt);
+ j.put("speak_tick", speak_tick);
+ j.put("speak_altitude", speak_altitude);
+ j.put("callsign", callsign);
+ j.put("firmware_version", firmware_version);
+ j.put("accel_plus_g", accel_plus_g);
+ j.put("accel_minus_g", accel_minus_g);
+ j.put("accel", accel);
+ j.put("ground_accel", ground_accel);
+ j.put("ground_accel_avg", ground_accel_avg);
+ j.put("log_format", log_format);
+ j.put("log_space", log_space);
+ j.put("product", product);
+ j.put("baro", baro);
+ j.put("companion", companion);
+ j.put("pyro_fired", pyro_fired);
+ j.put("accel_zero_along", accel_zero_along);
+ j.put("accel_zero_across", accel_zero_across);
+ j.put("accel_zero_through", accel_zero_through);
+
+ j.put("rotation", rotation);
+ j.put("ground_rotation", ground_rotation);
+
+ j.put("pad_orientation", pad_orientation);
+
+ j.put("accel_ground_along", accel_ground_along);
+ j.put("accel_ground_across", accel_ground_across);
+ j.put("accel_ground_through", accel_ground_through);
+
+ j.put("gyro_zero_roll", gyro_zero_roll);
+ j.put("gyro_zero_pitch", gyro_zero_pitch);
+ j.put("gyro_zero_yaw", gyro_zero_yaw);
+
+ j.put("last_imu_time", last_imu_time);
+ return j;
+ }
+
+ public AltosState(AltosHashSet h) {
+ this();
+
+ set = h.getInt("set", set);
+ received_time = h.getLong("received_time", received_time);
+ time = h.getDouble("time", time);
+ prev_time = h.getDouble("prev_time", prev_time);
+ time_change = h.getDouble("time_change", time_change);
+ tick = h.getInt("tick", tick);
+ prev_tick = h.getInt("prev_tick", prev_tick);
+ boost_tick = h.getInt("boost_tick", boost_tick);
+ state = h.getInt("state", state);
+ flight = h.getInt("flight", flight);
+ serial = h.getInt("serial", serial);
+ altitude_32 = h.getInt("altitude_32", altitude_32);
+ receiver_serial = h.getInt("receiver_serial", receiver_serial);
+ landed = h.getBoolean("landed", landed);
+ ascent = h.getBoolean("ascent", ascent);
+ boost = h.getBoolean("boost", boost);
+ rssi = h.getInt("rssi", rssi);
+ status = h.getInt("status", status);
+ device_type = h.getInt("device_type", device_type);
+ config_major = h.getInt("config_major", config_major);
+ config_minor = h.getInt("config_minor", config_minor);
+ apogee_delay = h.getInt("apogee_delay", apogee_delay);
+ main_deploy = h.getInt("main_deploy", main_deploy);
+ flight_log_max = h.getInt("flight_log_max", flight_log_max);
+ ground_altitude = AltosCValue_fromHashSet(h.getHash("ground_altitude"), ground_altitude);
+ gps_ground_altitude = AltosGpsGroundAltitude_fromHashSet(h.getHash("gps_ground_altitude"), gps_ground_altitude);
+ ground_pressure = AltosGroundPressure_fromHashSet(h.getHash("ground_pressure"), ground_pressure);
+ altitude = AltosAltitude_fromHashSet(h.getHash("altitude"), altitude);
+ gps_altitude = AltosGpsAltitude_fromHashSet(h.getHash("gps_altitude"), gps_altitude);
+ gps_ground_speed = AltosValue_fromHashSet(h.getHash("gps_ground_speed"), gps_ground_speed);
+ gps_ascent_rate = AltosValue_fromHashSet(h.getHash("gps_ascent_rate"), gps_ascent_rate);
+ gps_course = AltosValue_fromHashSet(h.getHash("gps_course"), gps_course);
+ gps_speed = AltosValue_fromHashSet(h.getHash("gps_speed"), gps_speed);
+ pressure = AltosPressure_fromHashSet(h.getHash("pressure"), pressure);
+ speed = AltosSpeed_fromHashSet(h.getHash("speed"), speed);
+ acceleration = AltosAccel_fromHashSet(h.getHash("acceleration"), acceleration);
+ orient = AltosCValue_fromHashSet(h.getHash("orient"), orient);
+ kalman_height = AltosValue_fromHashSet(h.getHash("kalman_height"), kalman_height);
+ kalman_speed = AltosValue_fromHashSet(h.getHash("kalman_speed"), kalman_speed);
+ kalman_acceleration = AltosValue_fromHashSet(h.getHash("kalman_acceleration"), kalman_acceleration);
+
+ battery_voltage = h.getDouble("battery_voltage", battery_voltage);
+ pyro_voltage = h.getDouble("pyro_voltage", pyro_voltage);
+ temperature = h.getDouble("temperature", temperature);
+ apogee_voltage = h.getDouble("apogee_voltage", apogee_voltage);
+ main_voltage= h.getDouble("main_voltage", main_voltage);
+ ignitor_voltage = h.getDoubleArray("ignitor_voltage", ignitor_voltage);
+ gps = AltosGPS.fromHashSet(h.getHash("gps"), gps);
+ temp_gps = AltosGPS.fromHashSet(h.getHash("temp_gps"), temp_gps);
+ temp_gps_sat_tick = h.getInt("temp_gps_sat_tick", temp_gps_sat_tick);
+ gps_pending = h.getBoolean("gps_pending", gps_pending);
+ gps_sequence = h.getInt("gps_sequence", gps_sequence);
+ imu = AltosIMU.fromHashSet(h.getHash("imu"), imu);
+ mag = AltosMag.fromHashSet(h.getHash("mag"), mag);
+
+ npad = h.getInt("npad", npad);
+ gps_waiting = h.getInt("gps_waiting", gps_waiting);
+ gps_ready = h.getBoolean("gps_ready", gps_ready);
+ ngps = h.getInt("ngps", ngps);
+ from_pad = AltosGreatCircle.fromHashSet(h.getHash("from_pad"), from_pad);
+ elevation = h.getDouble("elevation", elevation);
+ range = h.getDouble("range", range);
+ gps_height = h.getDouble("gps_height", gps_height);
+ pad_lat = h.getDouble("pad_lat", pad_lat);
+ pad_lon = h.getDouble("pad_lon", pad_lon);
+ pad_alt = h.getDouble("pad_alt", pad_alt);
+ speak_tick = h.getInt("speak_tick", speak_tick);
+ speak_altitude = h.getDouble("speak_altitude", speak_altitude);
+ callsign = h.getString("callsign", callsign);
+ firmware_version = h.getString("firmware_version", firmware_version);
+ accel_plus_g = h.getDouble("accel_plus_g", accel_plus_g);
+ accel_minus_g = h.getDouble("accel_minus_g", accel_minus_g);
+ accel = h.getDouble("accel", accel);
+ ground_accel = h.getDouble("ground_accel", ground_accel);
+ ground_accel_avg = h.getDouble("ground_accel_avg", ground_accel_avg);
+ log_format = h.getInt("log_format", log_format);
+ log_space = h.getInt("log_space", log_space);
+ product = h.getString("product", product);
+ baro = AltosMs5607.fromHashSet(h.getHash("baro"), baro);
+ companion = AltosCompanion.fromHashSet(h.getHash("companion"), companion);
+ pyro_fired = h.getInt("pyro_fired", pyro_fired);
+ accel_zero_along = h.getDouble("accel_zero_along", accel_zero_along);
+ accel_zero_across = h.getDouble("accel_zero_across", accel_zero_across);
+ accel_zero_through = h.getDouble("accel_zero_through", accel_zero_through);
+
+ rotation = AltosRotation.fromHashSet(h.getHash("rotation"), rotation);
+ ground_rotation = AltosRotation.fromHashSet(h.getHash("ground_rotation"), ground_rotation);
+
+ pad_orientation = h.getInt("pad_orientation", pad_orientation);
+
+ accel_ground_along = h.getDouble("accel_ground_along", accel_ground_along);
+ accel_ground_across = h.getDouble("accel_ground_across", accel_ground_across);
+ accel_ground_through = h.getDouble("accel_ground_through", accel_ground_through);
+
+ gyro_zero_roll = h.getDouble("gyro_zero_roll", gyro_zero_roll);
+ gyro_zero_pitch = h.getDouble("gyro_zero_pitch", gyro_zero_pitch);
+ gyro_zero_yaw = h.getDouble("gyro_zero_yaw", gyro_zero_yaw);
+
+ last_imu_time = h.getDouble("last_imu_time", last_imu_time);
+ }
+
+ public AltosState(AltosJson j) {
+ this();
+
+ set = j.get_int("set", set);
+ received_time = j.get_long("received_time", received_time);
+ time = j.get_double("time", time);
+ prev_time = j.get_double("prev_time", prev_time);
+ time_change = j.get_double("time_change", time_change);
+ tick = j.get_int("tick", tick);
+ prev_tick = j.get_int("prev_tick", prev_tick);
+ boost_tick = j.get_int("boost_tick", boost_tick);
+ state = j.get_int("state", state);
+ flight = j.get_int("flight", flight);
+ serial = j.get_int("serial", serial);
+ altitude_32 = j.get_int("altitude_32", altitude_32);
+ receiver_serial = j.get_int("receiver_serial", receiver_serial);
+ landed = j.get_boolean("landed", landed);
+ ascent = j.get_boolean("ascent", ascent);
+ boost = j.get_boolean("boost", boost);
+ rssi = j.get_int("rssi", rssi);
+ status = j.get_int("status", status);
+ device_type = j.get_int("device_type", device_type);
+ config_major = j.get_int("config_major", config_major);
+ config_minor = j.get_int("config_minor", config_minor);
+ apogee_delay = j.get_int("apogee_delay", apogee_delay);
+ main_deploy = j.get_int("main_deploy", main_deploy);
+ flight_log_max = j.get_int("flight_log_max", flight_log_max);
+ ground_altitude = AltosCValue_fromJson(j.get("ground_altitude"), ground_altitude);
+ gps_ground_altitude = AltosGpsGroundAltitude_fromJson(j.get("gps_ground_altitude"), gps_ground_altitude);
+ ground_pressure = AltosGroundPressure_fromJson(j.get("ground_pressure"), ground_pressure);
+ altitude = AltosAltitude_fromJson(j.get("altitude"), altitude);
+ gps_altitude = AltosGpsAltitude_fromJson(j.get("gps_altitude"), gps_altitude);
+ gps_ground_speed = AltosValue_fromJson(j.get("gps_ground_speed"), gps_ground_speed);
+ gps_ascent_rate = AltosValue_fromJson(j.get("gps_ascent_rate"), gps_ascent_rate);
+ gps_course = AltosValue_fromJson(j.get("gps_course"), gps_course);
+ gps_speed = AltosValue_fromJson(j.get("gps_speed"), gps_speed);
+ pressure = AltosPressure_fromJson(j.get("pressure"), pressure);
+ speed = AltosSpeed_fromJson(j.get("speed"), speed);
+ acceleration = AltosAccel_fromJson(j.get("acceleration"), acceleration);
+ orient = AltosCValue_fromJson(j.get("orient"), orient);
+ kalman_height = AltosValue_fromJson(j.get("kalman_height"), kalman_height);
+ kalman_speed = AltosValue_fromJson(j.get("kalman_speed"), kalman_speed);
+ kalman_acceleration = AltosValue_fromJson(j.get("kalman_acceleration"), kalman_acceleration);
+
+ battery_voltage = j.get_double("battery_voltage", battery_voltage);
+ pyro_voltage = j.get_double("pyro_voltage", pyro_voltage);
+ temperature = j.get_double("temperature", temperature);
+ apogee_voltage = j.get_double("apogee_voltage", apogee_voltage);
+ main_voltage= j.get_double("main_voltage", main_voltage);
+ ignitor_voltage = j.get_double_array("ignitor_voltage", ignitor_voltage);
+ gps = AltosGPS.fromJson(j.get("gps"), gps);
+ temp_gps = AltosGPS.fromJson(j.get("temp_gps"), temp_gps);
+ temp_gps_sat_tick = j.get_int("temp_gps_sat_tick", temp_gps_sat_tick);
+ gps_pending = j.get_boolean("gps_pending", gps_pending);
+ gps_sequence = j.get_int("gps_sequence", gps_sequence);
+ imu = AltosIMU.fromJson(j.get("imu"), imu);
+ mag = AltosMag.fromJson(j.get("mag"), mag);
+
+ npad = j.get_int("npad", npad);
+ gps_waiting = j.get_int("gps_waiting", gps_waiting);
+ gps_ready = j.get_boolean("gps_ready", gps_ready);
+ ngps = j.get_int("ngps", ngps);
+ from_pad = AltosGreatCircle.fromJson(j.get("from_pad"), from_pad);
+ elevation = j.get_double("elevation", elevation);
+ range = j.get_double("range", range);
+ gps_height = j.get_double("gps_height", gps_height);
+ pad_lat = j.get_double("pad_lat", pad_lat);
+ pad_lon = j.get_double("pad_lon", pad_lon);
+ pad_alt = j.get_double("pad_alt", pad_alt);
+ speak_tick = j.get_int("speak_tick", speak_tick);
+ speak_altitude = j.get_double("speak_altitude", speak_altitude);
+ callsign = j.get_string("callsign", callsign);
+ firmware_version = j.get_string("firmware_version", firmware_version);
+ accel_plus_g = j.get_double("accel_plus_g", accel_plus_g);
+ accel_minus_g = j.get_double("accel_minus_g", accel_minus_g);
+ accel = j.get_double("accel", accel);
+ ground_accel = j.get_double("ground_accel", ground_accel);
+ ground_accel_avg = j.get_double("ground_accel_avg", ground_accel_avg);
+ log_format = j.get_int("log_format", log_format);
+ log_space = j.get_int("log_space", log_space);
+ product = j.get_string("product", product);
+ baro = AltosMs5607.fromJson(j.get("baro"), baro);
+ companion = AltosCompanion.fromJson(j.get("companion"), companion);
+ pyro_fired = j.get_int("pyro_fired", pyro_fired);
+ accel_zero_along = j.get_double("accel_zero_along", accel_zero_along);
+ accel_zero_across = j.get_double("accel_zero_across", accel_zero_across);
+ accel_zero_through = j.get_double("accel_zero_through", accel_zero_through);
+
+ rotation = AltosRotation.fromJson(j.get("rotation"), rotation);
+ ground_rotation = AltosRotation.fromJson(j.get("ground_rotation"), ground_rotation);
+
+ pad_orientation = j.get_int("pad_orientation", pad_orientation);
+
+ accel_ground_along = j.get_double("accel_ground_along", accel_ground_along);
+ accel_ground_across = j.get_double("accel_ground_across", accel_ground_across);
+ accel_ground_through = j.get_double("accel_ground_through", accel_ground_through);
+
+ gyro_zero_roll = j.get_double("gyro_zero_roll", gyro_zero_roll);
+ gyro_zero_pitch = j.get_double("gyro_zero_pitch", gyro_zero_pitch);
+ gyro_zero_yaw = j.get_double("gyro_zero_yaw", gyro_zero_yaw);
+
+ last_imu_time = j.get_double("last_imu_time", last_imu_time);
+ }
+ public static AltosState fromHashSet(AltosHashSet h) {
+ if (h == null)
+ return null;
+ if (!h.getBoolean("valid", false))
+ return null;
+ return new AltosState(h);