From e286eb61ad2a90746c1c31f95d26d5edb48738d3 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 31 Jul 2010 09:57:49 -0700 Subject: [PATCH] altosui: rename AltosEeprom -> AltosEepromDownload, split out Altos constants Renames the eeprom downloading code and adds a new file to share the flight data constants across the various UI modules. Signed-off-by: Keith Packard --- ao-tools/altosui/Altos.java | 94 +++++++++++++++++++ ...osEeprom.java => AltosEepromDownload.java} | 40 ++------ ao-tools/altosui/AltosUI.java | 17 ++-- 3 files changed, 112 insertions(+), 39 deletions(-) create mode 100644 ao-tools/altosui/Altos.java rename ao-tools/altosui/{AltosEeprom.java => AltosEepromDownload.java} (85%) diff --git a/ao-tools/altosui/Altos.java b/ao-tools/altosui/Altos.java new file mode 100644 index 00000000..bda4080e --- /dev/null +++ b/ao-tools/altosui/Altos.java @@ -0,0 +1,94 @@ +/* + * Copyright © 2010 Keith Packard + * + * 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 altosui; + +import java.awt.*; +import java.util.*; +import java.text.*; + +public class Altos { + /* EEProm command letters */ + static final int AO_LOG_FLIGHT = 'F'; + static final int AO_LOG_SENSOR = 'A'; + static final int AO_LOG_TEMP_VOLT = 'T'; + static final int AO_LOG_DEPLOY = 'D'; + static final int AO_LOG_STATE = 'S'; + static final int AO_LOG_GPS_TIME = 'G'; + static final int AO_LOG_GPS_LAT = 'N'; + static final int AO_LOG_GPS_LON = 'W'; + static final int AO_LOG_GPS_ALT = 'H'; + static final int AO_LOG_GPS_SAT = 'V'; + static final int AO_LOG_GPS_DATE = 'Y'; + + /* Added for 'serial-number' entry in eeprom files */ + static final int AO_LOG_SERIAL_NUMBER = 1000; + + /* Added to flag invalid records */ + static final int AO_LOG_INVALID = -1; + + /* Flight state numbers and names */ + static final int ao_flight_startup = 0; + static final int ao_flight_idle = 1; + static final int ao_flight_pad = 2; + static final int ao_flight_boost = 3; + static final int ao_flight_fast = 4; + static final int ao_flight_coast = 5; + static final int ao_flight_drogue = 6; + static final int ao_flight_main = 7; + static final int ao_flight_landed = 8; + static final int ao_flight_invalid = 9; + + static HashMap string_to_state = new HashMap(); + { + string_to_state.put("startup", ao_flight_startup); + string_to_state.put("idle", ao_flight_idle); + string_to_state.put("pad", ao_flight_pad); + string_to_state.put("boost", ao_flight_boost); + string_to_state.put("fast", ao_flight_fast); + string_to_state.put("coast", ao_flight_coast); + string_to_state.put("drogue", ao_flight_drogue); + string_to_state.put("main", ao_flight_main); + string_to_state.put("landed", ao_flight_landed); + string_to_state.put("invalid", ao_flight_invalid); + } + + static String[] state_to_string = { + "startup", + "idle", + "pad", + "boost", + "fast", + "coast", + "drogue", + "main", + "landed", + "invalid", + }; + + static public int state(String state) { + if (string_to_state.containsKey(state)) + return string_to_state.get(state); + return ao_flight_invalid; + } + + static public String state_name(int state) { + if (state < 0 || state_to_string.length <= state) + return "invalid"; + return state_to_string[state]; + } +} diff --git a/ao-tools/altosui/AltosEeprom.java b/ao-tools/altosui/AltosEepromDownload.java similarity index 85% rename from ao-tools/altosui/AltosEeprom.java rename to ao-tools/altosui/AltosEepromDownload.java index 4c537a89..756b82d1 100644 --- a/ao-tools/altosui/AltosEeprom.java +++ b/ao-tools/altosui/AltosEepromDownload.java @@ -28,6 +28,7 @@ import java.text.*; import java.util.prefs.*; import java.util.concurrent.LinkedBlockingQueue; +import altosui.Altos; import altosui.AltosSerial; import altosui.AltosSerialMonitor; import altosui.AltosTelemetry; @@ -40,30 +41,7 @@ import altosui.AltosEepromMonitor; import libaltosJNI.*; -public class AltosEeprom implements Runnable { - - static final int AO_LOG_FLIGHT = 'F'; - static final int AO_LOG_SENSOR = 'A'; - static final int AO_LOG_TEMP_VOLT = 'T'; - static final int AO_LOG_DEPLOY = 'D'; - static final int AO_LOG_STATE = 'S'; - static final int AO_LOG_GPS_TIME = 'G'; - static final int AO_LOG_GPS_LAT = 'N'; - static final int AO_LOG_GPS_LON = 'W'; - static final int AO_LOG_GPS_ALT = 'H'; - static final int AO_LOG_GPS_SAT = 'V'; - static final int AO_LOG_GPS_DATE = 'Y'; - - static final int ao_flight_startup = 0; - static final int ao_flight_idle = 1; - static final int ao_flight_pad = 2; - static final int ao_flight_boost = 3; - static final int ao_flight_fast = 4; - static final int ao_flight_coast = 5; - static final int ao_flight_drogue = 6; - static final int ao_flight_main = 7; - static final int ao_flight_landed = 8; - static final int ao_flight_invalid = 9; +public class AltosEepromDownload implements Runnable { static final String[] state_names = { "startup", @@ -175,21 +153,21 @@ public class AltosEeprom implements Runnable { int a = values[5] + (values[6] << 8); int b = values[7] + (values[8] << 8); - if (cmd == AO_LOG_FLIGHT) { + if (cmd == Altos.AO_LOG_FLIGHT) { flight = b; monitor.set_flight(flight); } /* Monitor state transitions to update display */ - if (cmd == AO_LOG_STATE && a <= ao_flight_landed) { - if (a > ao_flight_pad) + if (cmd == Altos.AO_LOG_STATE && a <= Altos.ao_flight_landed) { + if (a > Altos.ao_flight_pad) want_file = true; if (a > state) state_block = block; state = a; } - if (cmd == AO_LOG_GPS_DATE) { + if (cmd == Altos.AO_LOG_GPS_DATE) { year = 2000 + (a & 0xff); month = (a >> 8) & 0xff; day = (b & 0xff); @@ -219,7 +197,7 @@ public class AltosEeprom implements Runnable { else eeprom_pending.add(log_line); - if (cmd == AO_LOG_STATE && a == ao_flight_landed) { + if (cmd == Altos.AO_LOG_STATE && a == Altos.ao_flight_landed) { done = true; } } @@ -248,7 +226,7 @@ public class AltosEeprom implements Runnable { serial_line.printf("p\n"); } - monitor = new AltosEepromMonitor(frame, ao_flight_boost, ao_flight_landed); + monitor = new AltosEepromMonitor(frame, Altos.ao_flight_boost, Altos.ao_flight_landed); monitor.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { eeprom_thread.interrupt(); @@ -269,7 +247,7 @@ public class AltosEeprom implements Runnable { serial_line.close(); } - public AltosEeprom(JFrame given_frame) { + public AltosEepromDownload(JFrame given_frame) { frame = given_frame; device = AltosDeviceDialog.show(frame, null); diff --git a/ao-tools/altosui/AltosUI.java b/ao-tools/altosui/AltosUI.java index 4994f093..824e4b5b 100644 --- a/ao-tools/altosui/AltosUI.java +++ b/ao-tools/altosui/AltosUI.java @@ -28,6 +28,7 @@ import java.text.*; import java.util.prefs.*; import java.util.concurrent.LinkedBlockingQueue; +import altosui.Altos; import altosui.AltosSerial; import altosui.AltosSerialMonitor; import altosui.AltosTelemetry; @@ -344,7 +345,7 @@ public class AltosUI extends JFrame { return; /* reset the landing count once we hear about a new flight */ - if (state.state < AltosTelemetry.ao_flight_drogue) + if (state.state < Altos.ao_flight_drogue) reported_landing = 0; /* Shut up once the rocket is on the ground */ @@ -353,7 +354,7 @@ public class AltosUI extends JFrame { } /* If the rocket isn't on the pad, then report height */ - if (state.state > AltosTelemetry.ao_flight_pad) { + if (state.state > Altos.ao_flight_pad) { voice.speak("%d meters", (int) (state.height + 0.5)); } else { reported_landing = 0; @@ -366,7 +367,7 @@ public class AltosUI extends JFrame { if (!state.ascent && (last || System.currentTimeMillis() - state.report_time >= 15000 || - state.state == AltosTelemetry.ao_flight_landed)) + state.state == Altos.ao_flight_landed)) { if (Math.abs(state.baro_speed) < 20 && state.height < 100) voice.speak("rocket landed safely"); @@ -401,12 +402,12 @@ public class AltosUI extends JFrame { private void tell(AltosState state, AltosState old_state) { if (old_state == null || old_state.state != state.state) { voice.speak(state.data.state); - if ((old_state == null || old_state.state <= AltosTelemetry.ao_flight_boost) && - state.state > AltosTelemetry.ao_flight_boost) { + if ((old_state == null || old_state.state <= Altos.ao_flight_boost) && + state.state > Altos.ao_flight_boost) { voice.speak("max speed: %d meters per second.", (int) (state.max_speed + 0.5)); - } else if ((old_state == null || old_state.state < AltosTelemetry.ao_flight_drogue) && - state.state >= AltosTelemetry.ao_flight_drogue) { + } else if ((old_state == null || old_state.state < Altos.ao_flight_drogue) && + state.state >= Altos.ao_flight_drogue) { voice.speak("max height: %d meters.", (int) (state.max_height + 0.5)); } @@ -617,7 +618,7 @@ public class AltosUI extends JFrame { * a TeleDongle over the packet link */ private void SaveFlightData() { - new AltosEeprom(AltosUI.this); + new AltosEepromDownload(AltosUI.this); } /* Create the AltosUI menus -- 2.30.2