X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=altoslib%2FAltosState.java;h=fd2684db4c0ce6b06aa9392476b294a97ceb692d;hb=217d77dadbef4192d2f32e290a5c5f50159f2e0d;hp=a3c6cc34d1f930cb63ab423db1e851dca2f81206;hpb=1b5ea911049a8afae6af475a4a2bf62a6e3aa57b;p=fw%2Faltos diff --git a/altoslib/AltosState.java b/altoslib/AltosState.java index a3c6cc34..fd2684db 100644 --- a/altoslib/AltosState.java +++ b/altoslib/AltosState.java @@ -3,7 +3,8 @@ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License. + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of @@ -23,7 +24,7 @@ package org.altusmetrum.altoslib_11; import java.io.*; -public class AltosState implements Cloneable, AltosHashable { +public class AltosState implements Cloneable { public static final int set_position = 1; public static final int set_gps = 2; @@ -46,7 +47,7 @@ public class AltosState implements Cloneable, AltosHashable { private int prev_tick; public int boost_tick; - class AltosValue implements AltosHashable, AltosJsonable { + class AltosValue { double value; double prev_value; private double max_value; @@ -177,50 +178,6 @@ public class AltosState implements Cloneable, AltosHashable { prev_set_time = set_time; } - public AltosHashSet hashSet() { - AltosHashSet h = new AltosHashSet(); - - h.putDouble("value", value); - h.putDouble("prev_value", prev_value); - h.putDouble("max_value", max_value); - h.putDouble("set_time", set_time); - h.putDouble("prev_set_time", prev_set_time); - return h; - } - - public AltosJson json() { - AltosJson j = new AltosJson(); - - j.put("value", value); - j.put("prev_value", prev_value); - j.put("max_value", max_value); - j.put("set_time", set_time); - j.put("prev_set_time", prev_set_time); - return j; - } - - AltosValue(AltosHashSet h) { - this(); - if (h != null) { - value = h.getDouble("value", value); - prev_value = h.getDouble("prev_value", prev_value); - max_value = h.getDouble("max_value", max_value); - set_time = h.getDouble("set_time", 0); - prev_set_time = h.getDouble("prev_set_time", 0); - } - } - - AltosValue(AltosJson j) { - this(); - if (j != null) { - value = j.get_double("value", value); - prev_value = j.get_double("prev_value", prev_value); - max_value = j.get_double("max_value", max_value); - set_time = j.get_double("set_time", 0); - prev_set_time = j.get_double("prev_set_time", 0); - } - } - AltosValue() { value = AltosLib.MISSING; prev_value = AltosLib.MISSING; @@ -229,21 +186,9 @@ public class AltosState implements Cloneable, AltosHashable { } - AltosValue AltosValue_fromHashSet(AltosHashSet h, AltosValue def) { - if (h == null) - return def; - return new AltosValue(h); - } + class AltosCValue { - AltosValue AltosValue_fromJson(AltosJson j, AltosValue def) { - if (j == null) - return def; - return new AltosValue(j); - } - - class AltosCValue implements AltosHashable, AltosJsonable { - - class AltosIValue extends AltosValue implements AltosHashable, AltosJsonable { + class AltosIValue extends AltosValue { boolean can_max() { return c_can_max(); } @@ -251,14 +196,6 @@ public class AltosState implements Cloneable, AltosHashable { AltosIValue() { super(); } - - AltosIValue(AltosHashSet h) { - super(h); - } - - AltosIValue(AltosJson j) { - super(j); - } }; public AltosIValue measured; @@ -347,48 +284,10 @@ public class AltosState implements Cloneable, AltosHashable { computed.finish_update(); } - AltosCValue() { + public AltosCValue() { measured = new AltosIValue(); computed = new AltosIValue(); } - - public AltosHashSet hashSet() { - AltosHashSet h = new AltosHashSet(); - - h.putHashable("measured", measured); - h.putHashable("computed", computed); - return h; - } - - public AltosJson json() { - AltosJson j = new AltosJson(); - - j.put("measured", measured.json()); - j.put("computed", computed.json()); - return j; - } - - AltosCValue(AltosHashSet h) { - measured = new AltosIValue(h.getHash("measured")); - computed = new AltosIValue(h.getHash("computed")); - } - - AltosCValue(AltosJson j) { - measured = new AltosIValue(j.get("measured")); - computed = new AltosIValue(j.get("computed")); - } - } - - AltosCValue AltosCValue_fromHashSet(AltosHashSet h, AltosCValue def) { - if (h == null) - return def; - return new AltosCValue(h); - } - - AltosCValue AltosCValue_fromJson(AltosJson j, AltosCValue def) { - if (j == null) - return def; - return new AltosCValue(j); } private int state; @@ -440,24 +339,6 @@ public class AltosState implements Cloneable, AltosHashable { AltosGpsGroundAltitude() { super(); } - - AltosGpsGroundAltitude (AltosHashSet h) { - super(h); - } - - AltosGpsGroundAltitude (AltosJson j) { - super(j); - } - } - - AltosGpsGroundAltitude AltosGpsGroundAltitude_fromHashSet(AltosHashSet h, AltosGpsGroundAltitude def) { - if (h == null) return def; - return new AltosGpsGroundAltitude(h); - } - - AltosGpsGroundAltitude AltosGpsGroundAltitude_fromJson(AltosJson j, AltosGpsGroundAltitude def) { - if (j == null) return def; - return new AltosGpsGroundAltitude(j); } private AltosGpsGroundAltitude gps_ground_altitude; @@ -485,24 +366,6 @@ public class AltosState implements Cloneable, AltosHashable { AltosGroundPressure () { super(); } - - AltosGroundPressure (AltosHashSet h) { - super(h); - } - - AltosGroundPressure (AltosJson j) { - super(j); - } - } - - AltosGroundPressure AltosGroundPressure_fromHashSet(AltosHashSet h, AltosGroundPressure def) { - if (h == null) return def; - return new AltosGroundPressure(h); - } - - AltosGroundPressure AltosGroundPressure_fromJson(AltosJson j, AltosGroundPressure def) { - if (j == null) return def; - return new AltosGroundPressure(j); } private AltosGroundPressure ground_pressure; @@ -515,7 +378,7 @@ public class AltosState implements Cloneable, AltosHashable { ground_pressure.set_measured(pressure, time); } - class AltosAltitude extends AltosCValue implements AltosHashable { + class AltosAltitude extends AltosCValue { private void set_speed(AltosValue v) { if (!acceleration.is_measured() || !ascent) @@ -537,29 +400,11 @@ public class AltosState implements Cloneable, AltosHashable { AltosAltitude() { super(); } - - AltosAltitude (AltosHashSet h) { - super(h); - } - - AltosAltitude (AltosJson j) { - super(j); - } - } - - AltosAltitude AltosAltitude_fromHashSet(AltosHashSet h, AltosAltitude def) { - if (h == null) return def; - return new AltosAltitude(h); - } - - AltosAltitude AltosAltitude_fromJson(AltosJson j, AltosAltitude def) { - if (j == null) return def; - return new AltosAltitude(j); } private AltosAltitude altitude; - class AltosGpsAltitude extends AltosValue implements AltosHashable { + class AltosGpsAltitude extends AltosValue { private void set_gps_height() { double a = value(); @@ -579,24 +424,6 @@ public class AltosState implements Cloneable, AltosHashable { AltosGpsAltitude() { super(); } - - AltosGpsAltitude (AltosHashSet h) { - super(h); - } - - AltosGpsAltitude (AltosJson j) { - super(j); - } - } - - AltosGpsAltitude AltosGpsAltitude_fromHashSet(AltosHashSet h, AltosGpsAltitude def) { - if (h == null) return def; - return new AltosGpsAltitude(h); - } - - AltosGpsAltitude AltosGpsAltitude_fromJson(AltosJson j, AltosGpsAltitude def) { - if (j == null) return def; - return new AltosGpsAltitude(j); } private AltosGpsAltitude gps_altitude; @@ -676,24 +503,6 @@ public class AltosState implements Cloneable, AltosHashable { AltosPressure() { super(); } - - AltosPressure (AltosHashSet h) { - super(h); - } - - AltosPressure (AltosJson j) { - super(j); - } - } - - AltosPressure AltosPressure_fromHashSet(AltosHashSet h, AltosPressure def) { - if (h == null) return def; - return new AltosPressure(h); - } - - AltosPressure AltosPressure_fromJson(AltosJson j, AltosPressure def) { - if (j == null) return def; - return new AltosPressure(j); } private AltosPressure pressure; @@ -756,7 +565,7 @@ public class AltosState implements Cloneable, AltosHashable { return AltosLib.MISSING; } - class AltosSpeed extends AltosCValue implements AltosHashable { + class AltosSpeed extends AltosCValue { boolean can_max() { return state < AltosLib.ao_flight_fast || state == AltosLib.ao_flight_stateless; @@ -784,24 +593,6 @@ public class AltosState implements Cloneable, AltosHashable { 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; @@ -832,7 +623,7 @@ public class AltosState implements Cloneable, AltosHashable { return AltosLib.MISSING; } - class AltosAccel extends AltosCValue implements AltosHashable { + class AltosAccel extends AltosCValue { boolean can_max() { return state < AltosLib.ao_flight_fast || state == AltosLib.ao_flight_stateless; @@ -847,24 +638,6 @@ public class AltosState implements Cloneable, AltosHashable { 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; @@ -1752,29 +1525,27 @@ public class AltosState implements Cloneable, AltosHashable { AltosState s = new AltosState(); s.copy(this); + /* Code to test state save/restore. Enable only for that purpose + */ if (false) { - AltosJson json = json(); + AltosJson json = new AltosJson(this); String onetrip = json.toPrettyString(); AltosJson back = AltosJson.fromString(onetrip); - AltosState tripstate = AltosState.fromJson(back); - AltosJson tripjson = tripstate.json(); + AltosState tripstate = (AltosState) back.make(this.getClass()); + AltosJson tripjson = new AltosJson(tripstate); 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); + try { + FileWriter one_file = new FileWriter("one.json", true); + one_file.write(onetrip); + one_file.flush(); + FileWriter two_file = new FileWriter("two.json", true); + two_file.write(twotrip); + two_file.flush(); + } catch (Exception e) { + } + System.out.printf("json error\n"); System.exit(1); } } @@ -1784,439 +1555,4 @@ public class AltosState implements Cloneable, AltosHashable { 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); - } - - public static AltosState fromJson(AltosJson j) { - if (j == null) - return null; - if (!j.get_boolean("valid", false)) - return null; - return new AltosState(j); - } }