}
}
+ public boolean has_monitor_battery() {
+ if (product.startsWith("TeleBT"))
+ return true;
+ return false;
+ }
+
int[] parse_version(String v) {
String[] parts = v.split("\\.");
int r[] = new int[parts.length];
public boolean supports_telemetry(int telemetry) { return false; }
public File backing_file() { return null; }
+
+ public boolean has_monitor_battery() { return false; }
+
+ public double monitor_battery() { return AltosRecord.MISSING; }
}
}
public AltosGPS(AltosGPS old) {
- nsat = old.nsat;
- locked = old.locked;
- connected = old.connected;
- lat = old.lat; /* degrees (+N -S) */
- lon = old.lon; /* degrees (+E -W) */
- alt = old.alt; /* m */
- year = old.year;
- month = old.month;
- day = old.day;
- hour = old.hour;
- minute = old.minute;
- second = old.second;
-
- ground_speed = old.ground_speed; /* m/s */
- course = old.course; /* degrees */
- climb_rate = old.climb_rate; /* m/s */
- hdop = old.hdop; /* unitless? */
- h_error = old.h_error; /* m */
- v_error = old.v_error; /* m */
-
- if (old.cc_gps_sat != null) {
- cc_gps_sat = new AltosGPSSat[old.cc_gps_sat.length];
- for (int i = 0; i < old.cc_gps_sat.length; i++) {
- cc_gps_sat[i] = new AltosGPSSat();
- cc_gps_sat[i].svid = old.cc_gps_sat[i].svid;
- cc_gps_sat[i].c_n0 = old.cc_gps_sat[i].c_n0;
+ if (old != null) {
+ nsat = old.nsat;
+ locked = old.locked;
+ connected = old.connected;
+ lat = old.lat; /* degrees (+N -S) */
+ lon = old.lon; /* degrees (+E -W) */
+ alt = old.alt; /* m */
+ year = old.year;
+ month = old.month;
+ day = old.day;
+ hour = old.hour;
+ minute = old.minute;
+ second = old.second;
+
+ ground_speed = old.ground_speed; /* m/s */
+ course = old.course; /* degrees */
+ climb_rate = old.climb_rate; /* m/s */
+ hdop = old.hdop; /* unitless? */
+ h_error = old.h_error; /* m */
+ v_error = old.v_error; /* m */
+
+ if (old.cc_gps_sat != null) {
+ cc_gps_sat = new AltosGPSSat[old.cc_gps_sat.length];
+ for (int i = 0; i < old.cc_gps_sat.length; i++) {
+ cc_gps_sat[i] = new AltosGPSSat();
+ cc_gps_sat[i].svid = old.cc_gps_sat[i].svid;
+ cc_gps_sat[i].c_n0 = old.cc_gps_sat[i].c_n0;
+ }
}
+ } else {
+ ClearGPSTime();
+ cc_gps_sat = null;
}
}
}
} finally {
if (remote) {
link.stop_remote();
- if (record != null)
- record.rssi = AltosRSSI();
+ if (record != null) {
+ record.rssi = link.rssi();
+ record.monitor_battery = link.monitor_battery();
+ }
} else {
if (record != null)
record.rssi = 0;
remote = false;
}
+ public int rssi() throws TimeoutException, InterruptedException {
+ if (remote)
+ return 0;
+ printf("s\n");
+ String line = get_reply_no_dialog(5000);
+ if (line == null)
+ throw new TimeoutException();
+ String[] items = line.split("\\s+");
+ if (items.length < 2)
+ return 0;
+ if (!items[0].equals("RSSI:"))
+ return 0;
+ int rssi = Integer.parseInt(items[1]);
+ return rssi;
+ }
+
+ public String[] adc() throws TimeoutException, InterruptedException {
+ printf("a\n");
+ for (;;) {
+ String line = get_reply_no_dialog(5000);
+ if (line == null) {
+ throw new TimeoutException();
+ }
+ if (!line.startsWith("tick:"))
+ continue;
+ String[] items = line.split("\\s+");
+ return items;
+ }
+ }
+
+ public boolean has_monitor_battery() {
+ return config_data.has_monitor_battery();
+ }
+
+ public double monitor_battery() {
+ int monitor_batt = AltosRecord.MISSING;
+
+ if (config_data.has_monitor_battery()) {
+ try {
+ String[] items = adc();
+ for (int i = 0; i < items.length;) {
+ if (items[i].equals("batt")) {
+ monitor_batt = Integer.parseInt(items[i+1]);
+ i += 2;
+ continue;
+ }
+ i++;
+ }
+ } catch (InterruptedException ie) {
+ } catch (TimeoutException te) {
+ }
+ }
+ if (monitor_batt == AltosRecord.MISSING)
+ return AltosRecord.MISSING;
+ return AltosConvert.cc_battery_to_voltage(monitor_batt);
+ }
+
public AltosLink() {
callsign = "";
}
--- /dev/null
+/*
+ * Copyright © 2013 Keith Packard <keithp@keithp.com>
+ *
+ * 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.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+
+package org.altusmetrum.altoslib_1;
+
+public class AltosListenerState {
+ public int crc_errors;
+ public double battery;
+
+ public AltosListenerState() {
+ crc_errors = 0;
+ battery = AltosRecord.MISSING;
+ }
+}
package org.altusmetrum.altoslib_1;
-public abstract class AltosRecord implements Comparable <AltosRecord>, Cloneable {
+public class AltosRecord implements Comparable <AltosRecord>, Cloneable {
public static final int seen_flight = 1;
public static final int seen_sensor = 2;
* temperature: °C
*/
- abstract public double pressure();
- abstract public double ground_pressure();
- abstract public double acceleration();
+ public double pressure() { return MISSING; }
+ public double ground_pressure() { return MISSING; }
+ public double acceleration() { return MISSING; }
public double altitude() {
double p = pressure();
- if (p == MISSING)
+ if (p == MISSING) {
+ System.out.printf ("altitude missing\n");
return MISSING;
+ }
return AltosConvert.pressure_to_altitude(p);
}
return tick - o.tick;
}
- abstract public AltosRecord clone();
+ public AltosRecord clone() {
+ AltosRecord n = new AltosRecord();
+ n.copy(this);
+ return n;
+ }
public void copy(AltosRecord old) {
seen = old.seen;
seen = 0;
version = 0;
callsign = "N0CALL";
- serial = 0;
- flight = 0;
+ serial = MISSING;
+ flight = MISSING;
rssi = 0;
status = 0;
state = AltosLib.ao_flight_startup;
tick = 0;
- gps = new AltosGPS();
+ gps = null;
new_gps = false;
companion = null;
int accel_ref;
public AltosSensorMM(AltosLink link) throws InterruptedException, TimeoutException {
- link.printf("a\n");
- for (;;) {
- String line = link.get_reply_no_dialog(5000);
- if (line == null) {
- throw new TimeoutException();
+ String[] items = link.adc();
+ sense = new int[6];
+ for (int i = 0; i < items.length;) {
+ if (items[i].equals("tick:")) {
+ tick = Integer.parseInt(items[i+1]);
+ i += 2;
+ continue;
+ }
+ if (items[i].equals("0:")) {
+ sense[0] = Integer.parseInt(items[i+1]);
+ i += 2;
+ continue;
+ }
+ if (items[i].equals("1:")) {
+ sense[1] = Integer.parseInt(items[i+1]);
+ i += 2;
+ continue;
+ }
+ if (items[i].equals("2:")) {
+ sense[2] = Integer.parseInt(items[i+1]);
+ i += 2;
+ continue;
+ }
+ if (items[i].equals("3:")) {
+ sense[3] = Integer.parseInt(items[i+1]);
+ i += 2;
+ continue;
+ }
+ if (items[i].equals("4:")) {
+ sense[4] = Integer.parseInt(items[i+1]);
+ i += 2;
+ continue;
+ }
+ if (items[i].equals("5:")) {
+ sense[5] = Integer.parseInt(items[i+1]);
+ i += 2;
+ continue;
+ }
+ if (items[i].equals("6:")) {
+ v_batt = Integer.parseInt(items[i+1]);
+ i += 2;
+ continue;
+ }
+ if (items[i].equals("7:")) {
+ v_pyro = Integer.parseInt(items[i+1]);
+ i += 2;
+ continue;
+ }
+ if (items[i].equals("8:")) {
+ accel = Integer.parseInt(items[i+1]);
+ i += 2;
+ continue;
}
- if (!line.startsWith("tick:"))
+ if (items[i].equals("9:")) {
+ accel_ref = Integer.parseInt(items[i+1]);
+ i += 2;
continue;
- String[] items = line.split("\\s+");
- sense = new int[6];
- for (int i = 0; i < items.length;) {
- if (items[i].equals("tick:")) {
- tick = Integer.parseInt(items[i+1]);
- i += 2;
- continue;
- }
- if (items[i].equals("0:")) {
- sense[0] = Integer.parseInt(items[i+1]);
- i += 2;
- continue;
- }
- if (items[i].equals("1:")) {
- sense[1] = Integer.parseInt(items[i+1]);
- i += 2;
- continue;
- }
- if (items[i].equals("2:")) {
- sense[2] = Integer.parseInt(items[i+1]);
- i += 2;
- continue;
- }
- if (items[i].equals("3:")) {
- sense[3] = Integer.parseInt(items[i+1]);
- i += 2;
- continue;
- }
- if (items[i].equals("4:")) {
- sense[4] = Integer.parseInt(items[i+1]);
- i += 2;
- continue;
- }
- if (items[i].equals("5:")) {
- sense[5] = Integer.parseInt(items[i+1]);
- i += 2;
- continue;
- }
- if (items[i].equals("6:")) {
- v_batt = Integer.parseInt(items[i+1]);
- i += 2;
- continue;
- }
- if (items[i].equals("7:")) {
- v_pyro = Integer.parseInt(items[i+1]);
- i += 2;
- continue;
- }
- if (items[i].equals("8:")) {
- accel = Integer.parseInt(items[i+1]);
- i += 2;
- continue;
- }
- if (items[i].equals("9:")) {
- accel_ref = Integer.parseInt(items[i+1]);
- i += 2;
- continue;
- }
- i++;
}
- break;
+ i++;
}
}
}
public AltosSensorTM(AltosLink link, AltosConfigData config_data) throws InterruptedException, TimeoutException {
super();
- link.printf("a\n");
- for (;;) {
- String line = link.get_reply_no_dialog(5000);
- if (line == null) {
- throw new TimeoutException();
+ String[] items = link.adc();
+ for (int i = 0; i < items.length;) {
+ if (items[i].equals("tick:")) {
+ tick = Integer.parseInt(items[i+1]);
+ i += 2;
+ continue;
+ }
+ if (items[i].equals("accel:")) {
+ accel = Integer.parseInt(items[i+1]);
+ i += 2;
+ continue;
+ }
+ if (items[i].equals("pres:")) {
+ pres = Integer.parseInt(items[i+1]);
+ i += 2;
+ continue;
+ }
+ if (items[i].equals("temp:")) {
+ temp = Integer.parseInt(items[i+1]);
+ i += 2;
+ continue;
+ }
+ if (items[i].equals("batt:")) {
+ batt = Integer.parseInt(items[i+1]);
+ i += 2;
+ continue;
+ }
+ if (items[i].equals("drogue:")) {
+ drogue = Integer.parseInt(items[i+1]);
+ i += 2;
+ continue;
}
- if (!line.startsWith("tick:"))
+ if (items[i].equals("main:")) {
+ main = Integer.parseInt(items[i+1]);
+ i += 2;
continue;
- String[] items = line.split("\\s+");
- for (int i = 0; i < items.length;) {
- if (items[i].equals("tick:")) {
- tick = Integer.parseInt(items[i+1]);
- i += 2;
- continue;
- }
- if (items[i].equals("accel:")) {
- accel = Integer.parseInt(items[i+1]);
- i += 2;
- continue;
- }
- if (items[i].equals("pres:")) {
- pres = Integer.parseInt(items[i+1]);
- i += 2;
- continue;
- }
- if (items[i].equals("temp:")) {
- temp = Integer.parseInt(items[i+1]);
- i += 2;
- continue;
- }
- if (items[i].equals("batt:")) {
- batt = Integer.parseInt(items[i+1]);
- i += 2;
- continue;
- }
- if (items[i].equals("drogue:")) {
- drogue = Integer.parseInt(items[i+1]);
- i += 2;
- continue;
- }
- if (items[i].equals("main:")) {
- main = Integer.parseInt(items[i+1]);
- i += 2;
- continue;
- }
- i++;
}
- break;
+ i++;
}
ground_accel = config_data.accel_cal_plus;
ground_pres = pres;
/* compute barometric speed */
double height_change = height - prev_state.height;
+
+ double prev_baro_speed = prev_state.baro_speed;
+ if (prev_baro_speed == AltosRecord.MISSING)
+ prev_baro_speed = 0;
+
if (time_change > 0)
- baro_speed = (prev_state.baro_speed * 3 + (height_change / time_change)) / 4.0;
+ baro_speed = (prev_baro_speed * 3 + (height_change / time_change)) / 4.0;
else
baro_speed = prev_state.baro_speed;
+ double prev_accel_speed = prev_state.accel_speed;
+
+ if (prev_accel_speed == AltosRecord.MISSING)
+ prev_accel_speed = 0;
+
if (acceleration == AltosRecord.MISSING) {
/* Fill in mising acceleration value */
accel_speed = baro_speed;
- if (time_change > 0)
- acceleration = (accel_speed - prev_state.accel_speed) / time_change;
+
+ if (time_change > 0 && accel_speed != AltosRecord.MISSING)
+ acceleration = (accel_speed - prev_accel_speed) / time_change;
else
acceleration = prev_state.acceleration;
} else {
/* compute accelerometer speed */
- accel_speed = prev_state.accel_speed + acceleration * time_change;
+ accel_speed = prev_accel_speed + acceleration * time_change;
}
}
-
} else {
npad = 0;
ngps = 0;
gps = null;
baro_speed = AltosRecord.MISSING;
accel_speed = AltosRecord.MISSING;
+ pad_alt = AltosRecord.MISSING;
max_baro_speed = 0;
max_accel_speed = 0;
max_height = 0;
return log.file();
}
+ public boolean has_monitor_battery() {
+ return link.has_monitor_battery();
+ }
+
+ public double monitor_battery() {
+ return link.monitor_battery();
+ }
+
public AltosTelemetryReader (AltosLink in_link)
throws IOException, InterruptedException, TimeoutException {
link = in_link;
AltosIMUQuery.java \
AltosLine.java \
AltosLink.java \
+ AltosListenerState.java \
AltosLog.java \
AltosMs5607.java \
AltosMs5607Query.java \
label.setVisible(false);
}
- void show(AltosState state, int crc_errors) {}
+ void show(AltosState state, AltosListenerState listener_state) {}
void show(String s) {
show();
public class AscentValue {
JLabel label;
JTextField value;
- void show(AltosState state, int crc_errors) {}
+ void show(AltosState state, AltosListenerState listener_state) {}
void reset() {
value.setText("");
JTextField max_value;
double max;
- void show(AltosState state, int crc_errors) {}
+ void show(AltosState state, AltosListenerState listener_state) {}
void reset() {
value.setText("");
class Height extends AscentValueHold {
- void show (AltosState state, int crc_errors) {
+ void show (AltosState state, AltosListenerState listener_state) {
show(AltosConvert.height, state.height);
}
public Height (GridBagLayout layout, int y) {
Height height;
class Speed extends AscentValueHold {
- void show (AltosState state, int crc_errors) {
+ void show (AltosState state, AltosListenerState listener_state) {
double speed = state.accel_speed;
if (!state.ascent)
speed = state.baro_speed;
Speed speed;
class Accel extends AscentValueHold {
- void show (AltosState state, int crc_errors) {
+ void show (AltosState state, AltosListenerState listener_state) {
show(AltosConvert.accel, state.acceleration);
}
public Accel (GridBagLayout layout, int y) {
}
class Apogee extends AscentStatus {
- void show (AltosState state, int crc_errors) {
+ void show (AltosState state, AltosListenerState listener_state) {
show("%4.2f V", state.drogue_sense);
lights.set(state.drogue_sense > 3.2);
}
Apogee apogee;
class Main extends AscentStatus {
- void show (AltosState state, int crc_errors) {
+ void show (AltosState state, AltosListenerState listener_state) {
show("%4.2f V", state.main_sense);
lights.set(state.main_sense > 3.2);
}
Main main;
class Lat extends AscentValue {
- void show (AltosState state, int crc_errors) {
+ void show (AltosState state, AltosListenerState listener_state) {
if (state.gps != null)
show(pos(state.gps.lat,"N", "S"));
else
Lat lat;
class Lon extends AscentValue {
- void show (AltosState state, int crc_errors) {
+ void show (AltosState state, AltosListenerState listener_state) {
if (state.gps != null)
show(pos(state.gps.lon,"E", "W"));
else
accel.set_font();
}
- public void show(AltosState state, int crc_errors) {
+ public void show(AltosState state, AltosListenerState listener_state) {
if (state.gps != null && state.gps.connected) {
- lat.show(state, crc_errors);
- lon.show(state, crc_errors);
+ lat.show(state, listener_state);
+ lon.show(state, listener_state);
} else {
lat.hide();
lon.hide();
}
- height.show(state, crc_errors);
+ height.show(state, listener_state);
if (state.main_sense != AltosRecord.MISSING)
- main.show(state, crc_errors);
+ main.show(state, listener_state);
else
main.hide();
if (state.drogue_sense != AltosRecord.MISSING)
- apogee.show(state, crc_errors);
+ apogee.show(state, listener_state);
else
apogee.hide();
- speed.show(state, crc_errors);
- accel.show(state, crc_errors);
+ speed.show(state, listener_state);
+ accel.show(state, listener_state);
}
public void labels(GridBagLayout layout, int y) {
}
}
- public void show(AltosState state, int crc_errors) {
+ public void show(AltosState state, AltosListenerState listener_state) {
if (state == null)
return;
if (state.data.companion != null)
JTextField value;
AltosLights lights;
- abstract void show(AltosState state, int crc_errors);
+ abstract void show(AltosState state, AltosListenerState listener_state);
void show() {
label.setVisible(true);
value.setText("");
}
- abstract void show(AltosState state, int crc_errors);
+ abstract void show(AltosState state, AltosListenerState listener_state);
void show() {
label.setVisible(true);
value2.setFont(Altos.value_font);
}
- abstract void show(AltosState state, int crc_errors);
+ abstract void show(AltosState state, AltosListenerState listener_state);
void show(String v1, String v2) {
show();
}
class Height extends DescentValue {
- void show (AltosState state, int crc_errors) {
+ void show (AltosState state, AltosListenerState listener_state) {
show(AltosConvert.height, state.height);
}
public Height (GridBagLayout layout, int x, int y) {
Height height;
class Speed extends DescentValue {
- void show (AltosState state, int crc_errors) {
+ void show (AltosState state, AltosListenerState listener_state) {
double speed = state.accel_speed;
if (!state.ascent)
speed = state.baro_speed;
}
class Lat extends DescentValue {
- void show (AltosState state, int crc_errors) {
+ void show (AltosState state, AltosListenerState listener_state) {
if (state.gps != null && state.gps.connected)
show(pos(state.gps.lat,"N", "S"));
else
Lat lat;
class Lon extends DescentValue {
- void show (AltosState state, int crc_errors) {
+ void show (AltosState state, AltosListenerState listener_state) {
if (state.gps != null && state.gps.connected)
show(pos(state.gps.lon,"W", "E"));
else
Lon lon;
class Distance extends DescentValue {
- void show(AltosState state, int crc_errors) {
+ void show(AltosState state, AltosListenerState listener_state) {
if (state.from_pad != null)
show(AltosConvert.distance, state.from_pad.distance);
else
class Apogee extends DescentStatus {
- void show (AltosState state, int crc_errors) {
+ void show (AltosState state, AltosListenerState listener_state) {
show("%4.2f V", state.drogue_sense);
lights.set(state.drogue_sense > 3.2);
}
Apogee apogee;
class Main extends DescentStatus {
- void show (AltosState state, int crc_errors) {
+ void show (AltosState state, AltosListenerState listener_state) {
show("%4.2f V", state.main_sense);
lights.set(state.main_sense > 3.2);
}
Main main;
class Bearing extends DescentDualValue {
- void show (AltosState state, int crc_errors) {
+ void show (AltosState state, AltosListenerState listener_state) {
if (state.from_pad != null) {
show( String.format("%3.0f°", state.from_pad.bearing),
state.from_pad.bearing_words(
Bearing bearing;
class Range extends DescentValue {
- void show (AltosState state, int crc_errors) {
+ void show (AltosState state, AltosListenerState listener_state) {
show(AltosConvert.distance, state.range);
}
public Range (GridBagLayout layout, int x, int y) {
Range range;
class Elevation extends DescentValue {
- void show (AltosState state, int crc_errors) {
+ void show (AltosState state, AltosListenerState listener_state) {
show("%3.0f°", state.elevation);
}
public Elevation (GridBagLayout layout, int x, int y) {
apogee.set_font();
}
- public void show(AltosState state, int crc_errors) {
- height.show(state, crc_errors);
- speed.show(state, crc_errors);
+ public void show(AltosState state, AltosListenerState listener_state) {
+ height.show(state, listener_state);
+ speed.show(state, listener_state);
if (state.gps != null && state.gps.connected) {
- bearing.show(state, crc_errors);
- range.show(state, crc_errors);
- distance.show(state, crc_errors);
- elevation.show(state, crc_errors);
- lat.show(state, crc_errors);
- lon.show(state, crc_errors);
+ bearing.show(state, listener_state);
+ range.show(state, listener_state);
+ distance.show(state, listener_state);
+ elevation.show(state, listener_state);
+ lat.show(state, listener_state);
+ lon.show(state, listener_state);
} else {
bearing.hide();
range.hide();
lon.hide();
}
if (state.main_sense != AltosRecord.MISSING)
- main.show(state, crc_errors);
+ main.show(state, listener_state);
else
main.hide();
if (state.drogue_sense != AltosRecord.MISSING)
- apogee.show(state, crc_errors);
+ apogee.show(state, listener_state);
else
apogee.hide();
}
IdleThread idle_thread;
AltosVoice voice;
AltosFlightReader reader;
- int crc_errors;
+ AltosState old_state, state;
+ AltosListenerState listener_state;
AltosFlightDisplay display;
- void show_internal(AltosState state, int crc_errors) {
- if (state != null)
- display.show(state, crc_errors);
- }
-
- void show_safely(AltosState in_state, int in_crc_errors) {
- final AltosState state = in_state;
- final int crc_errors = in_crc_errors;
+ synchronized void show_safely() {
+ final AltosState my_state = state;
+ final AltosListenerState my_listener_state = listener_state;
Runnable r = new Runnable() {
public void run() {
try {
- show_internal(state, crc_errors);
+ display.show(my_state, my_listener_state);
} catch (Exception ex) {
}
}
class IdleThread extends Thread {
boolean started;
- private AltosState state;
int reported_landing;
int report_interval;
long report_time;
++reported_landing;
if (state.state != Altos.ao_flight_landed) {
state.state = Altos.ao_flight_landed;
- show_safely(state, 0);
+ show_safely();
}
}
}
public void run () {
try {
for (;;) {
+ if (reader.has_monitor_battery()) {
+ listener_state.battery = reader.monitor_battery();
+ show_safely();
+ }
set_report_time();
for (;;) {
voice.drain();
wait(sleep_time);
}
}
+
report(false);
}
} catch (InterruptedException ie) {
}
}
- public synchronized void notice(AltosState new_state, boolean spoken) {
- AltosState old_state = state;
- state = new_state;
- if (!started && state.state > Altos.ao_flight_pad) {
- started = true;
- start();
- }
-
- if (state.state < Altos.ao_flight_drogue)
- report_interval = 10000;
- else
- report_interval = 20000;
+ public synchronized void notice(boolean spoken) {
if (old_state != null && old_state.state != state.state) {
report_time = now();
this.notify();
}
public IdleThread() {
- state = null;
reported_landing = 0;
report_interval = 10000;
}
}
- boolean tell(AltosState state, AltosState old_state) {
+ synchronized boolean tell() {
boolean ret = false;
if (old_state == null || old_state.state != state.state) {
voice.speak(state.data.state());
public void run() {
boolean interrupted = false;
- //String line;
- AltosState state = null;
- AltosState old_state = null;
boolean told;
idle_thread = new IdleThread();
+ idle_thread.start();
try {
for (;;) {
old_state = state;
state = new AltosState(record, state);
reader.update(state);
- show_safely(state, crc_errors);
- told = tell(state, old_state);
- idle_thread.notice(state, told);
+ show_safely();
+ told = tell();
+ idle_thread.notice(told);
} catch (ParseException pp) {
System.out.printf("Parse error: %d \"%s\"\n", pp.getErrorOffset(), pp.getMessage());
} catch (AltosCRCException ce) {
- ++crc_errors;
- show_safely(state, crc_errors);
+ ++listener_state.crc_errors;
+ show_safely();
}
}
} catch (InterruptedException ee) {
}
public AltosDisplayThread(Frame in_parent, AltosVoice in_voice, AltosFlightDisplay in_display, AltosFlightReader in_reader) {
+ listener_state = new AltosListenerState();
parent = in_parent;
voice = in_voice;
display = in_display;
public interface AltosFlightDisplay {
void reset();
- void show(AltosState state, int crc_errors);
+ void show(AltosState state, AltosListenerState listener_state);
void set_font();
}
JLabel label;
JTextField value;
- void show(AltosState state, int crc_errors) {}
+ void show(AltosState state, AltosListenerState listener_state) {}
void reset() {
value.setText("");
}
class Call extends FlightValue {
- void show(AltosState state, int crc_errors) {
+ void show(AltosState state, AltosListenerState listener_state) {
value.setText(state.data.callsign);
}
public Call (GridBagLayout layout, int x) {
Call call;
class Serial extends FlightValue {
- void show(AltosState state, int crc_errors) {
- value.setText(String.format("%d", state.data.serial));
+ void show(AltosState state, AltosListenerState listener_state) {
+ if (state.data.serial == AltosRecord.MISSING)
+ value.setText("none");
+ else
+ value.setText(String.format("%d", state.data.serial));
}
public Serial (GridBagLayout layout, int x) {
super (layout, x, "Serial");
Serial serial;
class Flight extends FlightValue {
- void show(AltosState state, int crc_errors) {
- value.setText(String.format("%d", state.data.flight));
+ void show(AltosState state, AltosListenerState listener_state) {
+ if (state.data.flight == AltosRecord.MISSING)
+ value.setText("none");
+ else
+ value.setText(String.format("%d", state.data.flight));
}
public Flight (GridBagLayout layout, int x) {
super (layout, x, "Flight");
Flight flight;
class FlightState extends FlightValue {
- void show(AltosState state, int crc_errors) {
+ void show(AltosState state, AltosListenerState listener_state) {
value.setText(state.data.state());
}
public FlightState (GridBagLayout layout, int x) {
FlightState flight_state;
class RSSI extends FlightValue {
- void show(AltosState state, int crc_errors) {
+ void show(AltosState state, AltosListenerState listener_state) {
value.setText(String.format("%d", state.data.rssi));
}
public RSSI (GridBagLayout layout, int x) {
RSSI rssi;
class LastPacket extends FlightValue {
- void show(AltosState state, int crc_errors) {
+ void show(AltosState state, AltosListenerState listener_state) {
long secs = (System.currentTimeMillis() - state.report_time + 500) / 1000;
value.setText(String.format("%d", secs));
}
last_packet.set_font();
}
- public void show (AltosState state, int crc_errors) {
- call.show(state, crc_errors);
- serial.show(state, crc_errors);
- flight.show(state, crc_errors);
- flight_state.show(state, crc_errors);
- rssi.show(state, crc_errors);
- last_packet.show(state, crc_errors);
+ public void show (AltosState state, AltosListenerState listener_state) {
+ call.show(state, listener_state);
+ serial.show(state, listener_state);
+ flight.show(state, listener_state);
+ flight_state.show(state, listener_state);
+ rssi.show(state, listener_state);
+ last_packet.show(state, listener_state);
}
public int height() {
public class AltosFlightStatusUpdate implements ActionListener {
- public AltosState saved_state;
- AltosFlightStatus flightStatus;
+ public AltosState saved_state;
+ public AltosListenerState saved_listener_state;
+ AltosFlightStatus flightStatus;
public void actionPerformed (ActionEvent e) {
- if (saved_state != null)
- flightStatus.show(saved_state, 0);
+ if (saved_state != null) {
+ if (saved_listener_state == null)
+ saved_listener_state = new AltosListenerState();
+ flightStatus.show(saved_state, saved_listener_state);
+ }
}
public AltosFlightStatusUpdate (AltosFlightStatus in_flightStatus) {
AltosFlightStatusUpdate status_update;
- public void show(AltosState state, int crc_errors) {
+ public void show(AltosState state, AltosListenerState listener_state) {
status_update.saved_state = state;
- JComponent tab = which_tab(state);
- try {
- pad.show(state, crc_errors);
+
+ if (state == null) {
+ System.out.printf ("no state provided\n");
+ state = new AltosState(new AltosRecord());
+ }
+
+ pad.show(state, listener_state);
if (state.state != Altos.ao_flight_startup) {
if (!has_state) {
}
}
- ascent.show(state, crc_errors);
- descent.show(state, crc_errors);
- landed.show(state, crc_errors);
+ ascent.show(state, listener_state);
+ descent.show(state, listener_state);
+ landed.show(state, listener_state);
+ JComponent tab = which_tab(state);
if (tab != cur_tab) {
if (cur_tab == pane.getSelectedComponent()) {
pane.setSelectedComponent(tab);
}
cur_tab = tab;
}
- flightStatus.show(state, crc_errors);
- flightInfo.show(state, crc_errors);
+ flightStatus.show(state, listener_state);
+ flightInfo.show(state, listener_state);
if (state.data.companion != null) {
if (!has_companion) {
pane.add("Companion", companion);
has_companion= true;
}
- companion.show(state, crc_errors);
+ companion.show(state, listener_state);
} else {
if (has_companion) {
pane.remove(companion);
pane.add("Site Map", sitemap);
has_map = true;
}
- sitemap.show(state, crc_errors);
+ sitemap.show(state, listener_state);
} else {
if (has_map) {
pane.remove(sitemap);
has_map = false;
}
}
- } catch (Exception e) {
- System.out.print("Show exception " + e + "\n");
- e.printStackTrace();
- }
}
public void set_exit_on_close() {
if (state.gps != null && state.gps.locked && state.gps.nsat >= 4) {
if (map == null)
map = new AltosSiteMap();
- map.show(state, 0);
+ map.show(state, null);
has_gps = true;
}
}
AltosFlightStatusUpdate status_update;
- public void show(AltosState state, int crc_errors) {
+ public void show(AltosState state, AltosListenerState listener_state) {
status_update.saved_state = state;
try {
- pad.show(state, crc_errors);
- flightStatus.show(state, crc_errors);
- flightInfo.show(state, crc_errors);
+ pad.show(state, listener_state);
+ flightStatus.show(state, listener_state);
+ flightInfo.show(state, listener_state);
} catch (Exception e) {
System.out.print("Show exception" + e);
}
public void update(final AltosState state) {
Runnable r = new Runnable() {
public void run() {
- show(state, 0);
+ show(state, null);
}
};
SwingUtilities.invokeLater(r);
model.clear();
}
- public void show(AltosState state, int crc_errors) {
- if (state == null)
- return;
+ public void show(AltosState state, AltosListenerState listener_state) {
info_reset();
- if (state.altitude != AltosRecord.MISSING)
- info_add_row(0, "Altitude", "%6.0f m", state.altitude);
- if (state.ground_altitude != AltosRecord.MISSING)
- info_add_row(0, "Pad altitude", "%6.0f m", state.ground_altitude);
- if (state.height != AltosRecord.MISSING)
- info_add_row(0, "Height", "%6.0f m", state.height);
- if (state.max_height != AltosRecord.MISSING)
- info_add_row(0, "Max height", "%6.0f m", state.max_height);
- if (state.acceleration != AltosRecord.MISSING)
- info_add_row(0, "Acceleration", "%8.1f m/s²", state.acceleration);
- if (state.max_acceleration != AltosRecord.MISSING)
- info_add_row(0, "Max acceleration", "%8.1f m/s²", state.max_acceleration);
- if (state.speed() != AltosRecord.MISSING)
- info_add_row(0, "Speed", "%8.1f m/s", state.speed());
- if (state.max_speed() != AltosRecord.MISSING)
- info_add_row(0, "Max Speed", "%8.1f m/s", state.max_accel_speed);
- if (state.temperature != AltosRecord.MISSING)
- info_add_row(0, "Temperature", "%9.2f °C", state.temperature);
- if (state.battery != AltosRecord.MISSING)
- info_add_row(0, "Battery", "%9.2f V", state.battery);
- if (state.drogue_sense != AltosRecord.MISSING)
- info_add_row(0, "Drogue", "%9.2f V", state.drogue_sense);
- if (state.main_sense != AltosRecord.MISSING)
- info_add_row(0, "Main", "%9.2f V", state.main_sense);
- info_add_row(0, "CRC Errors", "%6d", crc_errors);
-
- if (state.gps == null || !state.gps.connected) {
- info_add_row(1, "GPS", "not available");
- } else {
- if (state.gps_ready)
- info_add_row(1, "GPS state", "%s", "ready");
- else
- info_add_row(1, "GPS state", "wait (%d)",
- state.gps_waiting);
- if (state.data.gps.locked)
- info_add_row(1, "GPS", " locked");
- else if (state.data.gps.connected)
- info_add_row(1, "GPS", " unlocked");
- else
- info_add_row(1, "GPS", " missing");
- info_add_row(1, "Satellites", "%6d", state.data.gps.nsat);
- info_add_deg(1, "Latitude", state.gps.lat, 'N', 'S');
- info_add_deg(1, "Longitude", state.gps.lon, 'E', 'W');
- info_add_row(1, "GPS altitude", "%6d", state.gps.alt);
- info_add_row(1, "GPS height", "%6.0f", state.gps_height);
-
- /* The SkyTraq GPS doesn't report these values */
- /*
- if (false) {
- info_add_row(1, "GPS ground speed", "%8.1f m/s %3d°",
- state.gps.ground_speed,
- state.gps.course);
- info_add_row(1, "GPS climb rate", "%8.1f m/s",
- state.gps.climb_rate);
- info_add_row(1, "GPS error", "%6d m(h)%3d m(v)",
- state.gps.h_error, state.gps.v_error);
- }
- */
-
- info_add_row(1, "GPS hdop", "%8.1f", state.gps.hdop);
-
- if (state.npad > 0) {
- if (state.from_pad != null) {
- info_add_row(1, "Distance from pad", "%6d m",
- (int) (state.from_pad.distance + 0.5));
- info_add_row(1, "Direction from pad", "%6d°",
- (int) (state.from_pad.bearing + 0.5));
- info_add_row(1, "Elevation from pad", "%6d°",
- (int) (state.elevation + 0.5));
- info_add_row(1, "Range from pad", "%6d m",
- (int) (state.range + 0.5));
- } else {
- info_add_row(1, "Distance from pad", "unknown");
- info_add_row(1, "Direction from pad", "unknown");
- info_add_row(1, "Elevation from pad", "unknown");
- info_add_row(1, "Range from pad", "unknown");
+ if (state != null) {
+ if (state.altitude != AltosRecord.MISSING)
+ info_add_row(0, "Altitude", "%6.0f m", state.altitude);
+ if (state.ground_altitude != AltosRecord.MISSING)
+ info_add_row(0, "Pad altitude", "%6.0f m", state.ground_altitude);
+ if (state.height != AltosRecord.MISSING)
+ info_add_row(0, "Height", "%6.0f m", state.height);
+ if (state.height != AltosRecord.MISSING)
+ info_add_row(0, "Max height", "%6.0f m", state.max_height);
+ if (state.acceleration != AltosRecord.MISSING)
+ info_add_row(0, "Acceleration", "%8.1f m/s²", state.acceleration);
+ if (state.acceleration != AltosRecord.MISSING)
+ info_add_row(0, "Max acceleration", "%8.1f m/s²", state.max_acceleration);
+ if (state.speed() != AltosRecord.MISSING)
+ info_add_row(0, "Speed", "%8.1f m/s", state.speed());
+ if (state.speed() != AltosRecord.MISSING)
+ info_add_row(0, "Max Speed", "%8.1f m/s", state.max_accel_speed);
+ if (state.temperature != AltosRecord.MISSING)
+ info_add_row(0, "Temperature", "%9.2f °C", state.temperature);
+ if (state.battery != AltosRecord.MISSING)
+ info_add_row(0, "Battery", "%9.2f V", state.battery);
+ if (state.drogue_sense != AltosRecord.MISSING)
+ info_add_row(0, "Drogue", "%9.2f V", state.drogue_sense);
+ if (state.main_sense != AltosRecord.MISSING)
+ info_add_row(0, "Main", "%9.2f V", state.main_sense);
+ }
+ if (listener_state != null) {
+ info_add_row(0, "CRC Errors", "%6d", listener_state.crc_errors);
+
+ if (listener_state.battery != AltosRecord.MISSING)
+ info_add_row(0, "Receiver Battery", "%9.2f", listener_state.battery);
+ }
+
+ if (state != null) {
+ if (state.gps == null || !state.gps.connected) {
+ info_add_row(1, "GPS", "not available");
+ } else {
+ if (state.gps_ready)
+ info_add_row(1, "GPS state", "%s", "ready");
+ else
+ info_add_row(1, "GPS state", "wait (%d)",
+ state.gps_waiting);
+ if (state.data.gps.locked)
+ info_add_row(1, "GPS", " locked");
+ else if (state.data.gps.connected)
+ info_add_row(1, "GPS", " unlocked");
+ else
+ info_add_row(1, "GPS", " missing");
+ info_add_row(1, "Satellites", "%6d", state.data.gps.nsat);
+ info_add_deg(1, "Latitude", state.gps.lat, 'N', 'S');
+ info_add_deg(1, "Longitude", state.gps.lon, 'E', 'W');
+ info_add_row(1, "GPS altitude", "%6d", state.gps.alt);
+ info_add_row(1, "GPS height", "%6.0f", state.gps_height);
+
+ /* The SkyTraq GPS doesn't report these values */
+ /*
+ if (false) {
+ info_add_row(1, "GPS ground speed", "%8.1f m/s %3d°",
+ state.gps.ground_speed,
+ state.gps.course);
+ info_add_row(1, "GPS climb rate", "%8.1f m/s",
+ state.gps.climb_rate);
+ info_add_row(1, "GPS error", "%6d m(h)%3d m(v)",
+ state.gps.h_error, state.gps.v_error);
+ }
+ */
+
+ info_add_row(1, "GPS hdop", "%8.1f", state.gps.hdop);
+
+ if (state.npad > 0) {
+ if (state.from_pad != null) {
+ info_add_row(1, "Distance from pad", "%6d m",
+ (int) (state.from_pad.distance + 0.5));
+ info_add_row(1, "Direction from pad", "%6d°",
+ (int) (state.from_pad.bearing + 0.5));
+ info_add_row(1, "Elevation from pad", "%6d°",
+ (int) (state.elevation + 0.5));
+ info_add_row(1, "Range from pad", "%6d m",
+ (int) (state.range + 0.5));
+ } else {
+ info_add_row(1, "Distance from pad", "unknown");
+ info_add_row(1, "Direction from pad", "unknown");
+ info_add_row(1, "Elevation from pad", "unknown");
+ info_add_row(1, "Range from pad", "unknown");
+ }
+ info_add_deg(1, "Pad latitude", state.pad_lat, 'N', 'S');
+ info_add_deg(1, "Pad longitude", state.pad_lon, 'E', 'W');
+ info_add_row(1, "Pad GPS alt", "%6.0f m", state.pad_alt);
}
- info_add_deg(1, "Pad latitude", state.pad_lat, 'N', 'S');
- info_add_deg(1, "Pad longitude", state.pad_lon, 'E', 'W');
- info_add_row(1, "Pad GPS alt", "%6.0f m", state.pad_alt);
- }
- info_add_row(1, "GPS date", "%04d-%02d-%02d",
- state.gps.year,
- state.gps.month,
- state.gps.day);
- info_add_row(1, "GPS time", " %02d:%02d:%02d",
- state.gps.hour,
- state.gps.minute,
- state.gps.second);
- //int nsat_vis = 0;
- int c;
-
- if (state.gps.cc_gps_sat == null)
- info_add_row(2, "Satellites Visible", "%4d", 0);
- else {
- info_add_row(2, "Satellites Visible", "%4d", state.gps.cc_gps_sat.length);
- for (c = 0; c < state.gps.cc_gps_sat.length; c++) {
- info_add_row(2, "Satellite id,C/N0",
- "%4d, %4d",
- state.gps.cc_gps_sat[c].svid,
- state.gps.cc_gps_sat[c].c_n0);
+ info_add_row(1, "GPS date", "%04d-%02d-%02d",
+ state.gps.year,
+ state.gps.month,
+ state.gps.day);
+ info_add_row(1, "GPS time", " %02d:%02d:%02d",
+ state.gps.hour,
+ state.gps.minute,
+ state.gps.second);
+ //int nsat_vis = 0;
+ int c;
+
+ if (state.gps.cc_gps_sat == null)
+ info_add_row(2, "Satellites Visible", "%4d", 0);
+ else {
+ info_add_row(2, "Satellites Visible", "%4d", state.gps.cc_gps_sat.length);
+ for (c = 0; c < state.gps.cc_gps_sat.length; c++) {
+ info_add_row(2, "Satellite id,C/N0",
+ "%4d, %4d",
+ state.gps.cc_gps_sat[c].svid,
+ state.gps.cc_gps_sat[c].c_n0);
+ }
}
}
}
public class LandedValue {
JLabel label;
JTextField value;
- void show(AltosState state, int crc_errors) {}
+ void show(AltosState state, AltosListenerState listener_state) {}
void reset() {
value.setText("");
}
class Lat extends LandedValue {
- void show (AltosState state, int crc_errors) {
+ void show (AltosState state, AltosListenerState listener_state) {
if (state.gps != null && state.gps.connected)
show(pos(state.gps.lat,"N", "S"));
else
Lat lat;
class Lon extends LandedValue {
- void show (AltosState state, int crc_errors) {
+ void show (AltosState state, AltosListenerState listener_state) {
show();
if (state.gps != null && state.gps.connected)
show(pos(state.gps.lon,"E", "W"));
Lon lon;
class Bearing extends LandedValue {
- void show (AltosState state, int crc_errors) {
+ void show (AltosState state, AltosListenerState listener_state) {
show();
if (state.from_pad != null)
show("%3.0f°", state.from_pad.bearing);
Bearing bearing;
class Distance extends LandedValue {
- void show (AltosState state, int crc_errors) {
+ void show (AltosState state, AltosListenerState listener_state) {
show();
if (state.from_pad != null)
show(AltosConvert.distance, state.from_pad.distance);
Distance distance;
class Height extends LandedValue {
- void show (AltosState state, int crc_errors) {
+ void show (AltosState state, AltosListenerState listener_state) {
show(AltosConvert.height, state.max_height);
}
public Height (GridBagLayout layout, int y) {
Height height;
class Speed extends LandedValue {
- void show (AltosState state, int crc_errors) {
+ void show (AltosState state, AltosListenerState listener_state) {
show(AltosConvert.speed, state.max_speed());
}
public Speed (GridBagLayout layout, int y) {
Speed speed;
class Accel extends LandedValue {
- void show (AltosState state, int crc_errors) {
+ void show (AltosState state, AltosListenerState listener_state) {
show(AltosConvert.accel, state.max_acceleration);
}
public Accel (GridBagLayout layout, int y) {
accel.set_font();
}
- public void show(AltosState state, int crc_errors) {
+ public void show(AltosState state, AltosListenerState listener_state) {
if (state.gps != null && state.gps.connected) {
- bearing.show(state, crc_errors);
- distance.show(state, crc_errors);
- lat.show(state, crc_errors);
- lon.show(state, crc_errors);
+ bearing.show(state, listener_state);
+ distance.show(state, listener_state);
+ lat.show(state, listener_state);
+ lon.show(state, listener_state);
} else {
bearing.hide();
distance.hide();
lat.hide();
lon.hide();
}
- height.show(state, crc_errors);
- speed.show(state, crc_errors);
- accel.show(state, crc_errors);
+ height.show(state, listener_state);
+ speed.show(state, listener_state);
+ accel.show(state, listener_state);
if (reader.backing_file() != null)
graph.setEnabled(true);
}
JTextField value;
AltosLights lights;
- void show(AltosState state, int crc_errors) {}
+ void show(AltosState state, AltosListenerState listener_state) {}
void reset() {
value.setText("");
public class LaunchValue {
JLabel label;
JTextField value;
- void show(AltosState state, int crc_errors) {}
+ void show(AltosState state, AltosListenerState listener_state) {}
void show() {
label.setVisible(true);
}
class Battery extends LaunchStatus {
- void show (AltosState state, int crc_errors) {
- if (state.battery == AltosRecord.MISSING)
+ void show (AltosState state, AltosListenerState listener_state) {
+ if (state == null || state.battery == AltosRecord.MISSING)
hide();
else {
show("%4.2f V", state.battery);
Battery battery;
class Apogee extends LaunchStatus {
- void show (AltosState state, int crc_errors) {
- show("%4.2f V", state.drogue_sense);
- lights.set(state.drogue_sense > 3.2);
+ void show (AltosState state, AltosListenerState listener_state) {
+ if (state == null || state.drogue_sense == AltosRecord.MISSING)
+ hide();
+ else {
+ show("%4.2f V", state.drogue_sense);
+ lights.set(state.drogue_sense > 3.2);
+ }
}
public Apogee (GridBagLayout layout, int y) {
super(layout, y, "Apogee Igniter Voltage");
Apogee apogee;
class Main extends LaunchStatus {
- void show (AltosState state, int crc_errors) {
- show("%4.2f V", state.main_sense);
- lights.set(state.main_sense > 3.2);
+ void show (AltosState state, AltosListenerState listener_state) {
+ if (state == null || state.main_sense == AltosRecord.MISSING)
+ hide();
+ else {
+ show("%4.2f V", state.main_sense);
+ lights.set(state.main_sense > 3.2);
+ }
}
public Main (GridBagLayout layout, int y) {
super(layout, y, "Main Igniter Voltage");
Main main;
class LoggingReady extends LaunchStatus {
- void show (AltosState state, int crc_errors) {
- if (state.data.flight != 0) {
- if (state.data.state <= Altos.ao_flight_pad)
- show("Ready to record");
- else if (state.data.state < Altos.ao_flight_landed)
- show("Recording data");
- else
- show("Recorded data");
+ void show (AltosState state, AltosListenerState listener_state) {
+ if (state == null || state.data.flight == AltosRecord.MISSING) {
+ hide();
+ } else {
+ if (state.data.flight != 0) {
+ if (state.data.state <= Altos.ao_flight_pad)
+ show("Ready to record");
+ else if (state.data.state < Altos.ao_flight_landed)
+ show("Recording data");
+ else
+ show("Recorded data");
+ } else
+ show("Storage full");
+ lights.set(state.data.flight != 0);
}
- else
- show("Storage full");
- lights.set(state.data.flight != 0);
}
public LoggingReady (GridBagLayout layout, int y) {
super(layout, y, "On-board Data Logging");
LoggingReady logging_ready;
class GPSLocked extends LaunchStatus {
- void show (AltosState state, int crc_errors) {
- show("%4d sats", state.gps.nsat);
- lights.set(state.gps.locked && state.gps.nsat >= 4);
+ void show (AltosState state, AltosListenerState listener_state) {
+ if (state == null || state.gps == null)
+ hide();
+ else {
+ show("%4d sats", state.gps.nsat);
+ lights.set(state.gps.locked && state.gps.nsat >= 4);
+ }
}
public GPSLocked (GridBagLayout layout, int y) {
super (layout, y, "GPS Locked");
GPSLocked gps_locked;
class GPSReady extends LaunchStatus {
- void show (AltosState state, int crc_errors) {
- if (state.gps_ready)
- show("Ready");
- else
- show("Waiting %d", state.gps_waiting);
- lights.set(state.gps_ready);
+ void show (AltosState state, AltosListenerState listener_state) {
+ if (state == null || state.gps == null)
+ hide();
+ else {
+ if (state.gps_ready)
+ show("Ready");
+ else
+ show("Waiting %d", state.gps_waiting);
+ lights.set(state.gps_ready);
+ }
}
public GPSReady (GridBagLayout layout, int y) {
super (layout, y, "GPS Ready");
GPSReady gps_ready;
+ class ReceiverBattery extends LaunchStatus {
+ void show (AltosState state, AltosListenerState listener_state) {
+ if (listener_state == null || listener_state.battery == AltosRecord.MISSING)
+ hide();
+ else {
+ show("%4.2f V", listener_state.battery);
+ lights.set(listener_state.battery > 3.7);
+ }
+ }
+ public ReceiverBattery (GridBagLayout layout, int y) {
+ super(layout, y, "Receiver Battery");
+ }
+ }
+
+ ReceiverBattery receiver_battery;
+
String pos(double p, String pos, String neg) {
String h = pos;
if (p < 0) {
}
class PadLat extends LaunchValue {
- void show (AltosState state, int crc_errors) {
- if (state.state < AltosLib.ao_flight_pad && state.gps != null) {
- show(pos(state.gps.lat,"N", "S"));
- set_label("Latitude");
- } else {
- show(pos(state.pad_lat,"N", "S"));
- set_label("Pad Latitude");
+ void show (AltosState state, AltosListenerState listener_state) {
+ if (state == null || state.gps == null) {
+ hide();
+ } else {
+ if (state.state < AltosLib.ao_flight_pad) {
+ show(pos(state.gps.lat,"N", "S"));
+ set_label("Latitude");
+ } else {
+ show(pos(state.pad_lat,"N", "S"));
+ set_label("Pad Latitude");
+ }
}
}
public PadLat (GridBagLayout layout, int y) {
PadLat pad_lat;
class PadLon extends LaunchValue {
- void show (AltosState state, int crc_errors) {
- if (state.state < AltosLib.ao_flight_pad && state.gps != null) {
- show(pos(state.gps.lon,"E", "W"));
- set_label("Longitude");
- } else {
- show(pos(state.pad_lon,"E", "W"));
- set_label("Pad Longitude");
+ void show (AltosState state, AltosListenerState listener_state) {
+ if (state == null || state.gps == null) {
+ hide();
+ } else {
+ if (state.state < AltosLib.ao_flight_pad) {
+ show(pos(state.gps.lon,"E", "W"));
+ set_label("Longitude");
+ } else {
+ show(pos(state.pad_lon,"E", "W"));
+ set_label("Pad Longitude");
+ }
}
}
public PadLon (GridBagLayout layout, int y) {
PadLon pad_lon;
class PadAlt extends LaunchValue {
- void show (AltosState state, int crc_errors) {
- if (state.state < AltosLib.ao_flight_pad && state.gps != null) {
- show("%4.0f m", state.gps.alt);
- set_label("Altitude");
- } else {
- if (state.pad_alt == AltosRecord.MISSING)
- hide();
- else {
- show("%4.0f m", state.pad_alt);
- set_label("Pad Altitude");
+ void show (AltosState state, AltosListenerState listener_state) {
+ if (state == null)
+ hide();
+ else {
+ if (state.state < AltosLib.ao_flight_pad && state.gps != null) {
+ show("%4.0f m", state.gps.alt);
+ set_label("Altitude");
+ } else {
+ if (state.pad_alt == AltosRecord.MISSING)
+ hide();
+ else {
+ show("%4.0f m", state.pad_alt);
+ set_label("Pad Altitude");
+ }
}
}
}
logging_ready.reset();
gps_locked.reset();
gps_ready.reset();
+ receiver_battery.reset();
pad_lat.reset();
pad_lon.reset();
pad_alt.reset();
logging_ready.set_font();
gps_locked.set_font();
gps_ready.set_font();
+ receiver_battery.set_font();
pad_lat.set_font();
pad_lon.set_font();
pad_alt.set_font();
}
- public void show(AltosState state, int crc_errors) {
- battery.show(state, crc_errors);
- if (state.drogue_sense == AltosRecord.MISSING)
- apogee.hide();
- else
- apogee.show(state, crc_errors);
- if (state.main_sense == AltosRecord.MISSING)
- main.hide();
- else
- main.show(state, crc_errors);
- logging_ready.show(state, crc_errors);
- pad_alt.show(state, crc_errors);
- if (state.gps != null && state.gps.connected) {
- gps_locked.show(state, crc_errors);
- gps_ready.show(state, crc_errors);
- pad_lat.show(state, crc_errors);
- pad_lon.show(state, crc_errors);
- } else {
- gps_locked.hide();
- gps_ready.hide();
- pad_lat.hide();
- pad_lon.hide();
- }
+ public void show(AltosState state, AltosListenerState listener_state) {
+ battery.show(state, listener_state);
+ apogee.show(state, listener_state);
+ main.show(state, listener_state);
+ logging_ready.show(state, listener_state);
+ pad_alt.show(state, listener_state);
+ receiver_battery.show(state, listener_state);
+ gps_locked.show(state, listener_state);
+ gps_ready.show(state, listener_state);
+ pad_lat.show(state, listener_state);
+ pad_lon.show(state, listener_state);
}
public AltosPad() {
logging_ready = new LoggingReady(layout, 3);
gps_locked = new GPSLocked(layout, 4);
gps_ready = new GPSReady(layout, 5);
- pad_lat = new PadLat(layout, 6);
- pad_lon = new PadLon(layout, 7);
- pad_alt = new PadAlt(layout, 8);
+ receiver_battery = new ReceiverBattery(layout, 6);
+ pad_lat = new PadLat(layout, 7);
+ pad_lon = new PadLon(layout, 8);
+ pad_alt = new PadAlt(layout, 9);
+ show(null, null);
}
}
initMaps(lat, lon);
scrollRocketToVisible(pt(lat, lon));
}
- public void show(final AltosState state, final int crc_errors) {
+ public void show(final AltosState state, final AltosListenerState listener_state) {
// if insufficient gps data, nothing to update
if (!state.gps.locked && state.gps.nsat < 4)
return;
Point2D.Double ref, lref;
ref = translatePoint(pt, tileCoordOffset(offset));
lref = translatePoint(last_pt, tileCoordOffset(offset));
- tile.show(state, crc_errors, lref, ref);
+ tile.show(state, listener_state, lref, ref);
if (0 <= ref.x && ref.x < px_size)
if (0 <= ref.y && ref.y < px_size)
in_any = true;
lref = translatePoint(last_pt, tileCoordOffset(offset));
AltosSiteMapTile tile = createTile(offset);
- tile.show(state, crc_errors, lref, ref);
+ tile.show(state, listener_state, lref, ref);
initMap(offset);
finishTileLater(tile, offset);
}
private boolean drawn_landed_circle = false;
private boolean drawn_boost_circle = false;
- public synchronized void show(AltosState state, int crc_errors,
+ public synchronized void show(AltosState state, AltosListenerState listener_state,
Point2D.Double last_pt, Point2D.Double pt)
{
if (0 <= state.state && state.state < stateColors.length) {
#define AO_SEC_TO_TICKS(s) ((s) * AO_HERTZ)
/* Returns the current time in ticks */
-uint16_t
+AO_TICK_TYPE
ao_time(void);
/* Suspend the current task until ticks time has passed */
#include "ao.h"
#include <ao_task.h>
-volatile __data AO_TICK_TYPE ao_tick_count;
+volatile AO_TICK_TYPE ao_tick_count;
-uint16_t ao_time(void)
+AO_TICK_TYPE
+ao_time(void)
{
- uint16_t v;
- ao_arch_critical(
- v = ao_tick_count;
- );
- return v;
+ return ao_tick_count;
}
#if AO_DATA_ALL