From d873dc28f0752aeb58a6263e42bdd5b9095bd392 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 23 Nov 2010 18:56:46 -0800 Subject: altos: remove unused variable from ao_igniter The 'status' variable used to hold a reported status value from the igniter after firing, but we ignore that now. Signed-off-by: Keith Packard --- src/ao_ignite.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/ao_ignite.c b/src/ao_ignite.c index 58d340d9..f2b15dd2 100644 --- a/src/ao_ignite.c +++ b/src/ao_ignite.c @@ -101,7 +101,6 @@ void ao_igniter(void) { __xdata enum ao_ignter igniter; - __xdata enum ao_igniter_status status; ao_config_get(); for (;;) { -- cgit v1.2.3 From 54468e5dc567aaac5c5c20e921859b7cec28bb88 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 23 Nov 2010 18:57:49 -0800 Subject: altos: Don't abort radio transmissions with ao_radio_abort We only want to abort pending radio reception to release the radio for other use, or to change the radio channel. Let radio transmission proceed. This fixes a problem with using packet mode to configure the radio channel; if the packet transmission is aborted, the TM ends up wedged. Signed-off-by: Keith Packard --- src/ao_radio.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/ao_radio.c b/src/ao_radio.c index 3fb4afd7..b2105ff8 100644 --- a/src/ao_radio.c +++ b/src/ao_radio.c @@ -432,8 +432,11 @@ ao_radio_rdf(int ms) void ao_radio_abort(void) { - ao_dma_abort(ao_radio_dma); - ao_radio_idle(); + /* Only abort if a task is waiting to receive data */ + if (RFST == RFST_SRX) { + ao_dma_abort(ao_radio_dma); + ao_radio_idle(); + } } void -- cgit v1.2.3 From 3b9db8c82d26a6a2e43d4ca40742fc1bdc502380 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 23 Nov 2010 19:02:54 -0800 Subject: altos: Make radio test command careful with the radio mutex. Remember whether the radio test mode is on or off and don't try to do either of them twice to prevent the mutex from being acquired or released twice. Signed-off-by: Keith Packard --- src/ao_radio.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/ao_radio.c b/src/ao_radio.c index b2105ff8..67d5f6ba 100644 --- a/src/ao_radio.c +++ b/src/ao_radio.c @@ -452,26 +452,29 @@ void ao_radio_test(void) { uint8_t mode = 2; + static __xdata radio_on; ao_cmd_white(); if (ao_cmd_lex_c != '\n') { ao_cmd_decimal(); mode = (uint8_t) ao_cmd_lex_u32; } mode++; - if (mode & 2) { + if ((mode & 2) && !radio_on) { ao_set_monitor(0); ao_packet_slave_stop(); ao_radio_get(); RFST = RFST_STX; + radio_on = 1; } if (mode == 3) { printf ("Hit a character to stop..."); flush(); getchar(); putchar('\n'); } - if (mode & 1) { + if ((mode & 1) && radio_on) { ao_radio_idle(); ao_radio_put(); + radio_on = 0; } } -- cgit v1.2.3 From ed7cf7d262fcf7c0c677c2fb981582b571de9e5e Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 23 Nov 2010 19:04:55 -0800 Subject: altosui: Make AltosSerial.flush_input keep reading while non-empty Flushing the input buffer can take a while, especially over the packet link. Keep reading while stuff is appearing on the reply queue. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosSerial.java | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/ao-tools/altosui/AltosSerial.java b/ao-tools/altosui/AltosSerial.java index ab74486b..8a6ad05e 100644 --- a/ao-tools/altosui/AltosSerial.java +++ b/ao-tools/altosui/AltosSerial.java @@ -114,16 +114,20 @@ public class AltosSerial implements Runnable { public void flush_input() { flush_output(); - try { - Thread.sleep(200); - } catch (InterruptedException ie) { - } - synchronized(this) { - if (!"VERSION".startsWith(line) && - !line.startsWith("VERSION")) - line = ""; - reply_queue.clear(); - } + boolean got_some; + do { + try { + Thread.sleep(100); + } catch (InterruptedException ie) { + } + got_some = !reply_queue.isEmpty(); + synchronized(this) { + if (!"VERSION".startsWith(line) && + !line.startsWith("VERSION")) + line = ""; + reply_queue.clear(); + } + } while (got_some); } public String get_reply() throws InterruptedException { -- cgit v1.2.3 From 6cd9be22f06f21d12ee2f668989d83d3c61d14c0 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 23 Nov 2010 19:08:07 -0800 Subject: altosui: New AltosSerial.set_radio function sets channel/call Use this anytime you need to set the device radio channel and call sign, either for telemetry reception or packet mode origination. This uses the saved callsign and per-device radio channel number. Do not use this when opening a telemetrum as there won't be a saved channel number. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosConfig.java | 7 +++---- ao-tools/altosui/AltosEepromDownload.java | 7 +++---- ao-tools/altosui/AltosFlightUI.java | 1 - ao-tools/altosui/AltosIgnite.java | 7 +++---- ao-tools/altosui/AltosSerial.java | 9 +++++++-- ao-tools/altosui/AltosTelemetryReader.java | 6 ++---- 6 files changed, 18 insertions(+), 19 deletions(-) diff --git a/ao-tools/altosui/AltosConfig.java b/ao-tools/altosui/AltosConfig.java index 6bda20d8..52dbfd79 100644 --- a/ao-tools/altosui/AltosConfig.java +++ b/ao-tools/altosui/AltosConfig.java @@ -109,9 +109,8 @@ public class AltosConfig implements Runnable, ActionListener { void start_serial() throws InterruptedException { if (remote) { - serial_line.set_channel(AltosPreferences.channel(device.getSerial())); - serial_line.set_callsign(AltosPreferences.callsign()); - serial_line.printf("p\n"); + serial_line.set_radio(); + serial_line.printf("p\nE 0\n"); serial_line.flush_input(); } } @@ -128,7 +127,7 @@ public class AltosConfig implements Runnable, ActionListener { start_serial(); serial_line.printf("c s\nv\n"); for (;;) { - String line = serial_line.get_reply(1000); + String line = serial_line.get_reply(5000); if (line == null) throw new TimeoutException(); get_int(line, "serial-number", serial); diff --git a/ao-tools/altosui/AltosEepromDownload.java b/ao-tools/altosui/AltosEepromDownload.java index fb5dcfc0..02fc36f2 100644 --- a/ao-tools/altosui/AltosEepromDownload.java +++ b/ao-tools/altosui/AltosEepromDownload.java @@ -97,7 +97,7 @@ public class AltosEepromDownload implements Runnable { /* Pull the serial number out of the version information */ for (;;) { - String line = serial_line.get_reply(1000); + String line = serial_line.get_reply(5000); if (line == null) throw new TimeoutException(); @@ -127,7 +127,7 @@ public class AltosEepromDownload implements Runnable { any_valid = false; monitor.set_value(state_names[state], state, block - state_block); for (addr = 0; addr < 0x100;) { - String line = serial_line.get_reply(1000); + String line = serial_line.get_reply(5000); if (line == null) throw new TimeoutException(); int[] values = ParseHex(line); @@ -216,8 +216,7 @@ public class AltosEepromDownload implements Runnable { public void run () { if (remote) { - serial_line.set_channel(AltosPreferences.channel(device.getSerial())); - serial_line.set_callsign(AltosPreferences.callsign()); + serial_line.set_radio(); serial_line.printf("p\nE 0\n"); serial_line.flush_input(); } diff --git a/ao-tools/altosui/AltosFlightUI.java b/ao-tools/altosui/AltosFlightUI.java index 732f7395..24d25bd7 100644 --- a/ao-tools/altosui/AltosFlightUI.java +++ b/ao-tools/altosui/AltosFlightUI.java @@ -148,7 +148,6 @@ public class AltosFlightUI extends JFrame implements AltosFlightDisplay { public void actionPerformed(ActionEvent e) { int channel = channels.getSelectedIndex(); reader.set_channel(channel); - AltosPreferences.set_channel(serial, channel); } }); c.gridx = 0; diff --git a/ao-tools/altosui/AltosIgnite.java b/ao-tools/altosui/AltosIgnite.java index 8e92ec1b..75c0a17a 100644 --- a/ao-tools/altosui/AltosIgnite.java +++ b/ao-tools/altosui/AltosIgnite.java @@ -35,9 +35,8 @@ public class AltosIgnite { private void start_serial() throws InterruptedException { if (remote) { - serial.set_channel(AltosPreferences.channel(device.getSerial())); - serial.set_callsign(AltosPreferences.callsign()); - serial.printf("~\np\n"); + serial.set_radio(); + serial.printf("p\nE 0\n"); serial.flush_input(); } } @@ -100,7 +99,7 @@ public class AltosIgnite { start_serial(); serial.printf("t\n"); for (;;) { - String line = serial.get_reply(1000); + String line = serial.get_reply(5000); if (line == null) throw new TimeoutException(); if (get_string(line, "Igniter: drogue Status: ", status_name)) diff --git a/ao-tools/altosui/AltosSerial.java b/ao-tools/altosui/AltosSerial.java index 8a6ad05e..b19143e5 100644 --- a/ao-tools/altosui/AltosSerial.java +++ b/ao-tools/altosui/AltosSerial.java @@ -198,13 +198,18 @@ public class AltosSerial implements Runnable { devices_opened.add(device.getPath()); } altos = libaltos.altos_open(device); - if (altos == null) + if (altos == null) { + close(); throw new FileNotFoundException(device.toShortString()); + } input_thread = new Thread(this); input_thread.start(); print("~\nE 0\n"); + set_monitor(false); flush_output(); - set_monitor(monitor_mode); + } + + public void set_radio() { set_channel(AltosPreferences.channel(device.getSerial())); set_callsign(AltosPreferences.callsign()); } diff --git a/ao-tools/altosui/AltosTelemetryReader.java b/ao-tools/altosui/AltosTelemetryReader.java index de5f50e9..6c5a9397 100644 --- a/ao-tools/altosui/AltosTelemetryReader.java +++ b/ao-tools/altosui/AltosTelemetryReader.java @@ -44,10 +44,7 @@ class AltosTelemetryReader extends AltosFlightReader { void set_channel(int channel) { serial.set_channel(channel); - } - - void set_callsign(String callsign) { - serial.set_callsign(callsign); + AltosPreferences.set_channel(device.getSerial(), channel); } public AltosTelemetryReader (AltosDevice in_device) @@ -58,6 +55,7 @@ class AltosTelemetryReader extends AltosFlightReader { name = device.toShortString(); telem = new LinkedBlockingQueue(); + serial.set_radio(); serial.add_monitor(telem); } } -- cgit v1.2.3 From f3233985a132e1d660e6df12d0056b6729f16faf Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 23 Nov 2010 19:09:31 -0800 Subject: altosui: Disable radio configation over packet link. Attempting to configure the radio over the packet link will only end up confusing the user, so disable it. This also works around a bug in older TM code which would lock up when trying to do this. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosConfig.java | 8 +++++--- ao-tools/altosui/AltosConfigUI.java | 6 +++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/ao-tools/altosui/AltosConfig.java b/ao-tools/altosui/AltosConfig.java index 52dbfd79..b1acd410 100644 --- a/ao-tools/altosui/AltosConfig.java +++ b/ao-tools/altosui/AltosConfig.java @@ -149,7 +149,7 @@ public class AltosConfig implements Runnable, ActionListener { } void init_ui () throws InterruptedException, TimeoutException { - config_ui = new AltosConfigUI(owner); + config_ui = new AltosConfigUI(owner, remote); config_ui.addActionListener(this); set_ui(); } @@ -191,8 +191,10 @@ public class AltosConfig implements Runnable, ActionListener { start_serial(); serial_line.printf("c m %d\n", main_deploy.get()); serial_line.printf("c d %d\n", apogee_delay.get()); - serial_line.printf("c r %d\n", radio_channel.get()); - serial_line.printf("c f %d\n", radio_calibration.get()); + if (!remote) { + serial_line.printf("c r %d\n", radio_channel.get()); + serial_line.printf("c f %d\n", radio_calibration.get()); + } serial_line.printf("c c %s\n", callsign.get()); serial_line.printf("c w\n"); } catch (InterruptedException ie) { diff --git a/ao-tools/altosui/AltosConfigUI.java b/ao-tools/altosui/AltosConfigUI.java index ca89f58d..cfa5d7b9 100644 --- a/ao-tools/altosui/AltosConfigUI.java +++ b/ao-tools/altosui/AltosConfigUI.java @@ -98,7 +98,7 @@ public class AltosConfigUI } /* Build the UI using a grid bag */ - public AltosConfigUI(JFrame in_owner) { + public AltosConfigUI(JFrame in_owner, boolean remote) { super (in_owner, "Configure TeleMetrum", false); owner = in_owner; @@ -244,6 +244,8 @@ public class AltosConfigUI radio_channel_value = new JComboBox(radio_channel_values); radio_channel_value.setEditable(false); radio_channel_value.addItemListener(this); + if (remote) + radio_channel_value.setEnabled(false); pane.add(radio_channel_value, c); /* Radio Calibration */ @@ -267,6 +269,8 @@ public class AltosConfigUI c.ipady = 5; radio_calibration_value = new JTextField(String.format("%d", 1186611)); radio_calibration_value.getDocument().addDocumentListener(this); + if (remote) + radio_calibration_value.setEnabled(false); pane.add(radio_calibration_value, c); /* Callsign */ -- cgit v1.2.3 From 7d90e2f6009e060fb59c519f7e564483a7ca6872 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 23 Nov 2010 20:17:44 -0800 Subject: altosui: Let people fire igniters that don't read as 'ready' This provides for igniter testing with LEDs or other materials that don't look like regular igniters. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosIgniteUI.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/ao-tools/altosui/AltosIgniteUI.java b/ao-tools/altosui/AltosIgniteUI.java index 0207e39f..d542729c 100644 --- a/ao-tools/altosui/AltosIgniteUI.java +++ b/ao-tools/altosui/AltosIgniteUI.java @@ -145,13 +145,11 @@ public class AltosIgniteUI if (cmd.equals("apogee") && apogee.isSelected()) { main.setSelected(false); - if (apogee_status == AltosIgnite.Ready) - arm.setEnabled(true); + arm.setEnabled(true); } if (cmd.equals("main") && main.isSelected()) { apogee.setSelected(false); - if (main_status == AltosIgnite.Ready) - arm.setEnabled(true); + arm.setEnabled(true); } if (cmd.equals("arm")) { -- cgit v1.2.3 From 7a50837ea0d92db3f469f197ec8210aee22aa143 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Wed, 24 Nov 2010 10:55:18 -0800 Subject: altosui: Make sure packet mode is turned off when the connection fails When the packet connection times out, turn packet mode off when closing the serial port. Signed-off-by: Keith Packard --- ao-tools/altosui/AltosConfig.java | 10 +++++++++- ao-tools/altosui/AltosIgnite.java | 9 +++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/ao-tools/altosui/AltosConfig.java b/ao-tools/altosui/AltosConfig.java index b1acd410..1c42870f 100644 --- a/ao-tools/altosui/AltosConfig.java +++ b/ao-tools/altosui/AltosConfig.java @@ -74,7 +74,7 @@ public class AltosConfig implements Runnable, ActionListener { string_ref product; string_ref callsign; AltosConfigUI config_ui; - + boolean serial_started; boolean get_int(String line, String label, int_ref x) { if (line.startsWith(label)) { @@ -108,6 +108,7 @@ public class AltosConfig implements Runnable, ActionListener { } void start_serial() throws InterruptedException { + serial_started = true; if (remote) { serial_line.set_radio(); serial_line.printf("p\nE 0\n"); @@ -116,6 +117,9 @@ public class AltosConfig implements Runnable, ActionListener { } void stop_serial() throws InterruptedException { + if (!serial_started) + return; + serial_started = false; if (remote) { serial_line.printf("~"); serial_line.flush_output(); @@ -160,6 +164,10 @@ public class AltosConfig implements Runnable, ActionListener { device.toShortString()), "Connection Failed", JOptionPane.ERROR_MESSAGE); + try { + stop_serial(); + } catch (InterruptedException ie) { + } serial_line.close(); serial_line = null; } diff --git a/ao-tools/altosui/AltosIgnite.java b/ao-tools/altosui/AltosIgnite.java index 75c0a17a..3cbd8a75 100644 --- a/ao-tools/altosui/AltosIgnite.java +++ b/ao-tools/altosui/AltosIgnite.java @@ -24,6 +24,7 @@ public class AltosIgnite { AltosDevice device; AltosSerial serial; boolean remote; + boolean serial_started; final static int None = 0; final static int Apogee = 1; final static int Main = 2; @@ -34,6 +35,7 @@ public class AltosIgnite { final static int Open = 3; private void start_serial() throws InterruptedException { + serial_started = true; if (remote) { serial.set_radio(); serial.printf("p\nE 0\n"); @@ -42,6 +44,9 @@ public class AltosIgnite { } private void stop_serial() throws InterruptedException { + if (!serial_started) + return; + serial_started = false; if (serial == null) return; if (remote) { @@ -148,6 +153,10 @@ public class AltosIgnite { } public void close() { + try { + stop_serial(); + } catch (InterruptedException ie) { + } serial.close(); serial = null; } -- cgit v1.2.3