cal data split out from altos state.
altos state needed to have no-arguments constructor for JSON code.
Also messed with voice to make it stay quiet during app startup.
Signed-off-by: Keith Packard <keithp@keithp.com>
import org.altusmetrum.altoslib_11.*;
+class SavedState {
+ long received_time;
+ int state;
+ boolean locked;
+ String callsign;
+ int serial;
+ int flight;
+ int rssi;
+
+ SavedState(AltosState state) {
+ received_time = state.received_time;
+ this.state = state.state();
+ if (state.gps != null)
+ locked = state.gps.locked;
+ else
+ locked = false;
+ callsign = state.cal_data.callsign;
+ serial = state.cal_data.serial;
+ flight = state.cal_data.flight;
+ rssi = state.rssi;
+ }
+}
+
public class AltosDroid extends FragmentActivity implements AltosUnitsListener, LocationListener {
// Actions sent to the telemetry server at startup time
public Location location = null;
+ private AltosState state;
+ private SavedState saved_state;
+
// Tabs
TabHost mTabHost;
AltosViewPager mViewPager;
// Timer and Saved flight state for Age calculation
private Timer timer;
- AltosState saved_state;
+
TelemetryState telemetry_state;
Integer[] serials;
if (telemetry_state.states.containsKey(current_serial)) {
state = telemetry_state.states.get(current_serial);
- int age = state_age(state);
+ int age = state_age(state.received_time);
if (age < 20)
aged = false;
if (current_serial == selected_serial)
for (int serial : telemetry_state.states.keySet()) {
AltosState existing = telemetry_state.states.get(serial);
- int existing_age = state_age(existing);
+ int existing_age = state_age(existing.received_time);
if (newest_state == null || existing_age < newest_age) {
newest_state = existing;
state = newest_state;
}
- update_ui(telemetry_state, state);
+ update_ui(telemetry_state, state, telemetry_state.quiet);
start_timer();
}
blend_component(a, b, r, 24, 0xff));
}
- int state_age(AltosState state) {
- return (int) ((System.currentTimeMillis() - state.received_time + 500) / 1000);
+ int state_age(long received_time) {
+ return (int) ((System.currentTimeMillis() - received_time + 500) / 1000);
}
void set_screen_on(int age) {
void update_age() {
if (saved_state != null) {
- int age = state_age(saved_state);
+ int age = state_age(saved_state.received_time);
double age_scale = age / 100.0;
}
}
- void update_ui(TelemetryState telem_state, AltosState state) {
+ void update_ui(TelemetryState telem_state, AltosState state, boolean quiet) {
+
+ this.state = state;
int prev_state = AltosLib.ao_flight_invalid;
AltosGreatCircle from_receiver = null;
if (saved_state != null)
- prev_state = saved_state.state();
+ prev_state = saved_state.state;
if (state != null) {
- set_screen_on(state_age(state));
+ set_screen_on(state_age(state.received_time));
if (state.state() == AltosLib.ao_flight_stateless) {
boolean prev_locked = false;
if(state.gps != null)
locked = state.gps.locked;
- if (saved_state != null && saved_state.gps != null)
- prev_locked = saved_state.gps.locked;
+ if (saved_state != null)
+ prev_locked = saved_state.locked;
if (prev_locked != locked) {
String currentTab = mTabHost.getCurrentTabTag();
if (locked) {
state.gps.alt);
}
- if (saved_state == null || !same_string(saved_state.callsign, state.callsign)) {
- mCallsignView.setText(state.callsign);
+ if (saved_state == null || !same_string(saved_state.callsign, state.cal_data.callsign)) {
+ mCallsignView.setText(state.cal_data.callsign);
}
- if (saved_state == null || state.serial != saved_state.serial) {
- if (state.serial == AltosLib.MISSING)
+ if (saved_state == null || state.cal_data.serial != saved_state.serial) {
+ if (state.cal_data.serial == AltosLib.MISSING)
mSerialView.setText("");
else
- mSerialView.setText(String.format("%d", state.serial));
+ mSerialView.setText(String.format("%d", state.cal_data.serial));
}
- if (saved_state == null || state.flight != saved_state.flight) {
- if (state.flight == AltosLib.MISSING)
+ if (saved_state == null || state.cal_data.flight != saved_state.flight) {
+ if (state.cal_data.flight == AltosLib.MISSING)
mFlightView.setText("");
else
- mFlightView.setText(String.format("%d", state.flight));
+ mFlightView.setText(String.format("%d", state.cal_data.flight));
}
- if (saved_state == null || state.state() != saved_state.state()) {
+ if (saved_state == null || state.state() != saved_state.state) {
if (state.state() == AltosLib.ao_flight_stateless) {
mStateLayout.setVisibility(View.GONE);
} else {
else
mRSSIView.setText(String.format("%d", state.rssi));
}
+ saved_state = new SavedState(state);
}
for (AltosDroidTab mTab : mTabs)
mTab.update_ui(telem_state, state, from_receiver, location, mTab == mTabsAdapter.currentItem());
+ AltosDebug.debug("quiet %b\n", quiet);
if (mAltosVoice != null)
- mAltosVoice.tell(telem_state, state, from_receiver, location, (AltosDroidTab) mTabsAdapter.currentItem());
+ mAltosVoice.tell(telem_state, state, from_receiver, location, (AltosDroidTab) mTabsAdapter.currentItem(), quiet);
- saved_state = state;
}
private void onTimerTick() {
// Display the Version
mVersion = (TextView) findViewById(R.id.version);
mVersion.setText("Version: " + BuildInfo.version +
- " Built: " + BuildInfo.builddate + " " + BuildInfo.buildtime + " " + BuildInfo.buildtz +
- " (" + BuildInfo.branch + "-" + BuildInfo.commitnum + "-" + BuildInfo.commithash + ")");
+ (AltosVersion.has_google_maps_api_key() ? " maps" : "") +
+ " Built: " + BuildInfo.builddate + " " + BuildInfo.buildtime + " " + BuildInfo.buildtz +
+ " (" + BuildInfo.branch + "-" + BuildInfo.commitnum + "-" + BuildInfo.commithash + ")");
mCallsignView = (TextView) findViewById(R.id.callsign_value);
mRSSIView = (TextView) findViewById(R.id.rssi_value);
location.getLatitude(),
location.getLongitude());
- update_ui(telemetry_state, saved_state);
+ update_ui(telemetry_state, state, true);
}
@Override
AltosDebug.debug("Location changed to %f,%f",
location.getLatitude(),
location.getLongitude());
- update_ui(telemetry_state, saved_state);
+ update_ui(telemetry_state, state, false);
}
public void onStatusChanged(String provider, int status, Bundle extras) {
}
public String getString(String key, String def) {
- return prefs.getString(key, def);
+ String ret;
+ ret = prefs.getString(key, def);
+// AltosDebug.debug("AltosDroidPreferencesBackend get string %s:\n", key);
+// if (ret == null)
+// AltosDebug.debug(" (null)\n");
+// else {
+// String[] lines = ret.split("\n");
+// for (String l : lines)
+// AltosDebug.debug(" %s\n", l);
+// }
+ return ret;
}
public byte[] getBytes(String key, byte[] def) {
}
public void putString(String key, String value) {
+// AltosDebug.debug("AltosDroidPreferencesBackend put string %s:\n", key);
+// String[] lines = value.split("\n");
+// for (String l : lines)
+// AltosDebug.debug(" %s\n", l);
editor.putString(key, value);
}
break;
case AltosMapTile.forbidden:
message = "Too many requests, try later";
+ AltosDebug.debug("Forbidden map response %d\n", AltosMapStore.forbidden_response);
break;
}
if (message != null) {
if (t_state.gps != null) {
AltosLatLon latlon = new AltosLatLon(t_state.gps.lat, t_state.gps.lon);
rocket.set_position(latlon, t_state.received_time);
- if (state.serial == serial)
+ if (state.cal_data.serial == serial)
there = latlon;
}
if (state != null)
- rocket.set_active(state.serial == serial);
+ rocket.set_active(state.cal_data.serial == serial);
}
}
if (receiver != null) {
private Location last_receiver;
private long last_speak_time;
private int last_flight_tell = TELL_FLIGHT_NONE;
+ private boolean quiet = false;
private long now() {
return System.currentTimeMillis();
public synchronized void speak(String s) {
if (!tts_enabled) return;
last_speak_time = now();
- tts.speak(s, TextToSpeech.QUEUE_ADD, null);
+ if (!quiet)
+ tts.speak(s, TextToSpeech.QUEUE_ADD, null);
}
public synchronized long time_since_speak() {
if (state == null)
return false;
+ AltosDebug.debug("tell_pad lag %b ltm %d\n", last_apogee_good, last_tell_mode);
+
if (state.apogee_voltage != AltosLib.MISSING)
last_apogee_good = tell_gonogo("apogee",
state.apogee_voltage >= AltosLib.ao_igniter_good,
public void tell(TelemetryState telem_state, AltosState state,
AltosGreatCircle from_receiver, Location receiver,
- AltosDroidTab tab) {
+ AltosDroidTab tab, boolean quiet) {
+
+ this.quiet = quiet;
boolean spoken = false;
int tell_serial = last_tell_serial;
if (state != null)
- tell_serial = state.serial;
+ tell_serial = state.cal_data.serial;
if (tell_serial != last_tell_serial)
reset_last();
}
main_lights.set(state.main_voltage >= AltosLib.ao_igniter_good, state.main_voltage == AltosLib.MISSING);
- int num_igniter = state.ignitor_voltage == null ? 0 : state.ignitor_voltage.length;
+ int num_igniter = state.igniter_voltage == null ? 0 : state.igniter_voltage.length;
for (int i = 0; i < 4; i++) {
- double voltage = i >= num_igniter ? AltosLib.MISSING : state.ignitor_voltage[i];
+ double voltage = i >= num_igniter ? AltosLib.MISSING : state.igniter_voltage[i];
if (voltage == AltosLib.MISSING) {
ignite_row[i].setVisibility(View.GONE);
} else {
ignite_lights[i].set(voltage >= AltosLib.ao_igniter_good, voltage == AltosLib.MISSING);
}
- if (state.flight != 0) {
+ if (state.cal_data.flight != 0) {
if (state.state() <= AltosLib.ao_flight_pad)
data_logging_view.setText("Ready to record");
else if (state.state() < AltosLib.ao_flight_landed)
} else {
data_logging_view.setText("Storage full");
}
- data_logging_lights.set(state.flight != 0, state.flight == AltosLib.MISSING);
+ data_logging_lights.set(state.cal_data.flight != 0, state.cal_data.flight == AltosLib.MISSING);
if (state.gps != null) {
int soln = state.gps.nsat;
private void telemetry(AltosTelemetry telem) {
AltosState state;
- if (telemetry_state.states.containsKey(telem.serial))
- state = telemetry_state.states.get(telem.serial).clone();
+ if (telemetry_state.states.containsKey(telem.serial()))
+ state = telemetry_state.states.get(telem.serial());
else
- state = new AltosState();
- telem.update_state(state);
- telemetry_state.states.put(telem.serial, state);
+ state = new AltosState(new AltosCalData());
+ telem.provide_data(state, state.cal_data);
+ telemetry_state.states.put(telem.serial(), state);
+ telemetry_state.quiet = false;
if (state != null) {
- AltosPreferences.set_state(state);
+ AltosPreferences.set_state(state,telem.serial());
}
send_to_clients();
}
telemetry_state.latest_serial = AltosPreferences.latest_state();
+ telemetry_state.quiet = true;
+
AltosDebug.debug("latest serial %d\n", telemetry_state.latest_serial);
for (int serial : serials) {
AltosDebug.debug("recovered old state serial %d flight %d",
serial,
- saved_state.flight);
+ saved_state.cal_data.flight);
if (saved_state.gps != null)
AltosDebug.debug("\tposition %f,%f",
saved_state.gps.lat,
/* AltosIdleMonitorListener */
public void update(AltosState state, AltosListenerState listener_state) {
- telemetry_state.states.put(state.serial, state);
+ telemetry_state.states.put(state.cal_data.serial, state);
telemetry_state.receiver_battery = listener_state.battery;
send_to_clients();
}
double frequency;
int telemetry_rate;
+ boolean quiet;
+
HashMap<Integer,AltosState> states;
int latest_serial;
public abstract class AltosDataListener {
- public AltosCalData cal_data;
-
- public double time = AltosLib.MISSING;
+ public AltosCalData cal_data = null;
+ public double time = AltosLib.MISSING;
+ public int state = AltosLib.MISSING;
public void set_time(double time) {
if (time != AltosLib.MISSING)
return time;
}
- public int state = AltosLib.MISSING;
-
public void set_state(int state) {
if (state != AltosLib.MISSING)
this.state = state;
public abstract void set_pyro_fired(int pyro_mask);
public abstract void set_companion(AltosCompanion companion);
+ public AltosDataListener() {
+ }
+
public AltosDataListener(AltosCalData cal_data) {
this.cal_data = cal_data;
}
private void compute_height() {
double ground_altitude = cal_data.ground_altitude;
- if (height_series == null && ground_altitude != AltosLib.MISSING) {
+ if (height_series == null && ground_altitude != AltosLib.MISSING && altitude_series != null) {
height_series = add_series(height_name, AltosConvert.height);
for (AltosTimeValue alt : altitude_series)
height_series.add(alt.time, alt.value - ground_altitude);
double landed_time(AltosFlightSeries series) {
double landed_state_time = AltosLib.MISSING;
- for (AltosTimeValue state : series.state_series) {
- if (state.value == AltosLib.ao_flight_landed) {
- landed_state_time = state.time;
- break;
+ if (series.state_series != null) {
+ for (AltosTimeValue state : series.state_series) {
+ if (state.value == AltosLib.ao_flight_landed) {
+ landed_state_time = state.time;
+ break;
+ }
}
}
- if (landed_state_time == AltosLib.MISSING)
+ if (landed_state_time == AltosLib.MISSING && series.height_series != null)
landed_state_time = series.height_series.get(series.height_series.size()-1).time;
double landed_height = AltosLib.MISSING;
- for (AltosTimeValue height : series.height_series) {
- if (height.time >= landed_state_time) {
- landed_height = height.value;
- break;
+
+ if (series.height_series != null) {
+ for (AltosTimeValue height : series.height_series) {
+ if (height.time >= landed_state_time) {
+ landed_height = height.value;
+ break;
+ }
}
}
double landed_time = AltosLib.MISSING;
- for (AltosTimeValue height : series.height_series) {
- if (height.value > landed_height + 10) {
- above = true;
- } else {
- if (above && Math.abs(height.value - landed_height) < 2) {
- above = false;
- landed_time = height.time;
+ if (series.height_series != null) {
+ for (AltosTimeValue height : series.height_series) {
+ if (height.value > landed_height + 10) {
+ above = true;
+ } else {
+ if (above && Math.abs(height.value - landed_height) < 2) {
+ above = false;
+ landed_time = height.time;
+ }
}
}
}
double boost_time = AltosLib.MISSING;
double boost_state_time = AltosLib.MISSING;
- for (AltosTimeValue state : series.state_series) {
- if (state.value >= AltosLib.ao_flight_boost && state.value <= AltosLib.ao_flight_landed) {
- boost_state_time = state.time;
- break;
+ if (series.state_series != null) {
+ for (AltosTimeValue state : series.state_series) {
+ if (state.value >= AltosLib.ao_flight_boost && state.value <= AltosLib.ao_flight_landed) {
+ boost_state_time = state.time;
+ break;
+ }
}
}
- for (AltosTimeValue accel : series.accel_series) {
- if (accel.value < 1)
- boost_time = accel.time;
- if (boost_state_time != AltosLib.MISSING && accel.time >= boost_state_time)
- break;
+ if (series.accel_series != null) {
+ for (AltosTimeValue accel : series.accel_series) {
+ if (accel.value < 1)
+ boost_time = accel.time;
+ if (boost_state_time != AltosLib.MISSING && accel.time >= boost_state_time)
+ break;
+ }
}
return boost_time;
}
if (s == AltosLib.ao_flight_boost)
state_start[s] = boost_time;
- else
+ else if (series.state_series != null)
state_start[s] = series.state_series.time_of(s);
+ else
+ state_start[s] = AltosLib.MISSING;
if (s == AltosLib.ao_flight_main)
state_end[s] = landed_time;
- else
+ else if (series.state_series != null)
state_end[s] = series.state_series.time_of(s+1);
+ else
+ state_end[s] = AltosLib.MISSING;
if (series.speed_series != null)
state_speed[s] = series.speed_series.average(state_start[s], state_end[s]);
static Object forbidden_lock = new Object();
static long forbidden_time;
static boolean forbidden_set;
+ public static int forbidden_response;
private int fetch_url() {
URL u;
synchronized (forbidden_lock) {
forbidden_time = System.nanoTime();
forbidden_set = true;
+ forbidden_response = response;
return AltosMapTile.forbidden;
}
}
public int rssi;
public int status;
- public double time;
-
class AltosValue {
double value;
double prev_value;
}
}
- private int state;
public boolean landed;
public boolean ascent; /* going up? */
public boolean boost; /* under power */
pressure.set(p, time);
}
- class AltosForce extends AltosValue {
- void set(double p, double time) {
- super.set(p, time);
- }
-
- AltosForce() {
- super();
- }
- }
- private AltosForce thrust;
-
- public double thrust() {
- return thrust.value();
- }
-
public void set_thrust(double N) {
- thrust.set(N, time);
}
public double baro_height() {
public int speak_tick;
public double speak_altitude;
- public String callsign;
- public String firmware_version;
-
public double ground_accel;
- public int log_format;
- public int log_space;
- public String product;
-
public AltosCompanion companion;
public int pyro_fired;
ground_pressure = new AltosGroundPressure();
altitude = new AltosAltitude();
pressure = new AltosPressure();
- thrust = new AltosForce();
speed = new AltosSpeed();
acceleration = new AltosAccel();
orient = new AltosCValue();
speak_tick = AltosLib.MISSING;
speak_altitude = AltosLib.MISSING;
- callsign = null;
- firmware_version = null;
-
ground_accel = AltosLib.MISSING;
- log_format = AltosLib.MISSING;
- log_space = AltosLib.MISSING;
- product = null;
-
companion = null;
pyro_fired = 0;
this.pyro_fired = fired;
}
+ public AltosState() {
+ init();
+ }
+
public AltosState (AltosCalData cal_data) {
super(cal_data);
init();
cal_data.set_tick(tick);
if (cal_data.time() >= -1)
telem.provide_data(listener, cal_data);
+ if (listener.state == AltosLib.ao_flight_landed)
+ break;
}
listener.finish();
}
boolean any_gps = false;
AltosGPSTimeValue gtv_last = null;
- for (AltosGPSTimeValue gtv : flight_series.gps_series) {
- gtv_last = gtv;
- AltosGPS gps = gtv.gps;
- if (gps != null &&
- gps.locked &&
- gps.nsat >= 4) {
- if (map == null)
- map = new AltosUIMap();
- map.show(gps, (int) flight_series.value_before(AltosFlightSeries.state_name, gtv.time));
- this.gps = gps;
- has_gps = true;
+ if (flight_series.gps_series != null) {
+ for (AltosGPSTimeValue gtv : flight_series.gps_series) {
+ gtv_last = gtv;
+ AltosGPS gps = gtv.gps;
+ if (gps != null &&
+ gps.locked &&
+ gps.nsat >= 4) {
+ if (map == null)
+ map = new AltosUIMap();
+ map.show(gps, (int) flight_series.value_before(AltosFlightSeries.state_name, gtv.time));
+ this.gps = gps;
+ has_gps = true;
+ }
}
}
if (gtv_last != null) {