With the per-serial UI, there's never a reason to create a serial
device without opening it right away. This eliminates the bug caused
by not opening the serial device for telemetry reception.
Serial devices can now be opened only once; this eliminates errors
when trying to reflash or configure devices while receiving telemetry.
Signed-off-by: Keith Packard <keithp@keithp.com>
product = new string_ref("unknown");
device = AltosDeviceDialog.show(owner, AltosDevice.product_any);
product = new string_ref("unknown");
device = AltosDeviceDialog.show(owner, AltosDevice.product_any);
- serial_line = new AltosSerial();
if (device != null) {
try {
if (device != null) {
try {
- serial_line.open(device);
+ serial_line = new AltosSerial(device);
if (!device.matchProduct(AltosDevice.product_telemetrum))
remote = true;
config_thread = new Thread(this);
if (!device.matchProduct(AltosDevice.product_telemetrum))
remote = true;
config_thread = new Thread(this);
device.getPath()),
"Cannot open target device",
JOptionPane.ERROR_MESSAGE);
device.getPath()),
"Cannot open target device",
JOptionPane.ERROR_MESSAGE);
+ } catch (AltosSerialInUseException si) {
+ JOptionPane.showMessageDialog(owner,
+ String.format("Device \"%s\" already in use",
+ device.getPath()),
+ "Device in use",
+ JOptionPane.ERROR_MESSAGE);
} catch (IOException ee) {
JOptionPane.showMessageDialog(owner,
device.getPath(),
} catch (IOException ee) {
JOptionPane.showMessageDialog(owner,
device.getPath(),
import java.lang.*;
import java.io.*;
import java.lang.*;
import java.io.*;
-import java.util.concurrent.LinkedBlockingQueue;
-import java.util.LinkedList;
-import java.util.Iterator;
+import java.util.concurrent.*;
+import java.util.*;
+
+import libaltosJNI.*;
public class AltosDebug extends AltosSerial {
public class AltosDebug extends AltosSerial {
public void reset() {
printf ("R\n");
}
public void reset() {
printf ("R\n");
}
+
+ public AltosDebug (altos_device in_device) throws FileNotFoundException, AltosSerialInUseException {
+ super(in_device);
+ }
}
\ No newline at end of file
}
\ No newline at end of file
frame = given_frame;
device = AltosDeviceDialog.show(frame, AltosDevice.product_any);
frame = given_frame;
device = AltosDeviceDialog.show(frame, AltosDevice.product_any);
- serial_line = new AltosSerial();
remote = false;
if (device != null) {
try {
remote = false;
if (device != null) {
try {
- serial_line.open(device);
+ serial_line = new AltosSerial(device);
if (!device.matchProduct(AltosDevice.product_telemetrum))
remote = true;
eeprom_thread = new Thread(this);
if (!device.matchProduct(AltosDevice.product_telemetrum))
remote = true;
eeprom_thread = new Thread(this);
device.getPath()),
"Cannot open target device",
JOptionPane.ERROR_MESSAGE);
device.getPath()),
"Cannot open target device",
JOptionPane.ERROR_MESSAGE);
+ } catch (AltosSerialInUseException si) {
+ JOptionPane.showMessageDialog(frame,
+ String.format("Device \"%s\" already in use",
+ device.getPath()),
+ "Device in use",
+ JOptionPane.ERROR_MESSAGE);
} catch (IOException ee) {
JOptionPane.showMessageDialog(frame,
device.getPath(),
} catch (IOException ee) {
JOptionPane.showMessageDialog(frame,
device.getPath(),
- public void open() throws IOException, FileNotFoundException, InterruptedException {
+ public AltosFlash(File in_file, AltosDevice in_debug_dongle)
+ throws IOException, FileNotFoundException, AltosSerialInUseException, InterruptedException {
+ file = in_file;
+ debug_dongle = in_debug_dongle;
+ debug = new AltosDebug(in_debug_dongle);
input = new FileInputStream(file);
image = new AltosHexfile(input);
input = new FileInputStream(file);
image = new AltosHexfile(input);
- debug.open(debug_dongle);
if (!debug.check_connection())
throw new IOException("Debug port not connected");
}
if (!debug.check_connection())
throw new IOException("Debug port not connected");
}
-
- public AltosFlash(File in_file, AltosDevice in_debug_dongle) {
- file = in_file;
- debug_dongle = in_debug_dongle;
- debug = new AltosDebug();
- }
}
\ No newline at end of file
}
\ No newline at end of file
- flash = new AltosFlash(file, debug_dongle);
- flash.addActionListener(this);
+ flash = new AltosFlash(file, debug_dongle);
+ flash.addActionListener(this);
AltosRomconfigUI romconfig_ui = new AltosRomconfigUI (frame);
romconfig_ui.set(flash.romconfig());
AltosRomconfigUI romconfig_ui = new AltosRomconfigUI (frame);
romconfig_ui.set(flash.romconfig());
"Cannot open image",
file.toString(),
JOptionPane.ERROR_MESSAGE);
"Cannot open image",
file.toString(),
JOptionPane.ERROR_MESSAGE);
+ } catch (AltosSerialInUseException si) {
+ JOptionPane.showMessageDialog(frame,
+ String.format("Device \"%s\" already in use",
+ debug_dongle.getPath()),
+ "Device in use",
+ JOptionPane.ERROR_MESSAGE);
} catch (IOException e) {
JOptionPane.showMessageDialog(frame,
e.getMessage(),
} catch (IOException e) {
JOptionPane.showMessageDialog(frame,
e.getMessage(),
import java.lang.*;
import java.io.*;
import java.lang.*;
import java.io.*;
-import java.util.concurrent.LinkedBlockingQueue;
-import java.util.LinkedList;
-import java.util.Iterator;
+import java.util.concurrent.*;
+import java.util.*;
public class AltosSerial implements Runnable {
public class AltosSerial implements Runnable {
+ static List<String> devices_opened = Collections.synchronizedList(new LinkedList<String>());
+
+ altos_device device;
SWIGTYPE_p_altos_file altos;
LinkedList<LinkedBlockingQueue<AltosLine>> monitors;
LinkedBlockingQueue<AltosLine> reply_queue;
SWIGTYPE_p_altos_file altos;
LinkedList<LinkedBlockingQueue<AltosLine>> monitors;
LinkedBlockingQueue<AltosLine> reply_queue;
- public boolean opened() {
- return altos != null;
- }
-
public void close() {
if (altos != null) {
libaltos.altos_close(altos);
public void close() {
if (altos != null) {
libaltos.altos_close(altos);
libaltos.altos_free(altos);
altos = null;
}
libaltos.altos_free(altos);
altos = null;
}
+ synchronized (devices_opened) {
+ devices_opened.remove(device.getPath());
+ }
}
public void putc(char c) {
}
public void putc(char c) {
print(String.format(format, arguments));
}
print(String.format(format, arguments));
}
- public void open(altos_device device) throws FileNotFoundException {
+ private void open() throws FileNotFoundException, AltosSerialInUseException {
+ synchronized (devices_opened) {
+ if (devices_opened.contains(device.getPath()))
+ throw new AltosSerialInUseException(device);
+ devices_opened.add(device.getPath());
+ }
close();
altos = libaltos.altos_open(device);
if (altos == null)
close();
altos = libaltos.altos_open(device);
if (altos == null)
- public AltosSerial() {
- altos = null;
- input_thread = null;
+ public AltosSerial(altos_device in_device) throws FileNotFoundException, AltosSerialInUseException {
+ device = in_device;
line = "";
monitor_mode = false;
monitors = new LinkedList<LinkedBlockingQueue<AltosLine>> ();
reply_queue = new LinkedBlockingQueue<AltosLine> ();
line = "";
monitor_mode = false;
monitors = new LinkedList<LinkedBlockingQueue<AltosLine>> ();
reply_queue = new LinkedBlockingQueue<AltosLine> ();
serial.set_callsign(callsign);
}
serial.set_callsign(callsign);
}
- public AltosTelemetryReader (AltosDevice in_device) throws FileNotFoundException, IOException {
+ public AltosTelemetryReader (AltosDevice in_device)
+ throws FileNotFoundException, AltosSerialInUseException, IOException {
- serial = new AltosSerial();
+ serial = new AltosSerial(device);
log = new AltosLog(serial);
name = device.getPath();
log = new AltosLog(serial);
name = device.getPath();
device.getPath()),
"Cannot open target device",
JOptionPane.ERROR_MESSAGE);
device.getPath()),
"Cannot open target device",
JOptionPane.ERROR_MESSAGE);
+ } catch (AltosSerialInUseException si) {
+ JOptionPane.showMessageDialog(AltosUI.this,
+ String.format("Device \"%s\" already in use",
+ device.getPath()),
+ "Device in use",
+ JOptionPane.ERROR_MESSAGE);
} catch (IOException ee) {
JOptionPane.showMessageDialog(AltosUI.this,
device.getPath(),
} catch (IOException ee) {
JOptionPane.showMessageDialog(AltosUI.this,
device.getPath(),
AltosRomconfig.java \
AltosRomconfigUI.java \
AltosSerial.java \
AltosRomconfig.java \
AltosRomconfigUI.java \
AltosSerial.java \
+ AltosSerialInUseException.java \
AltosSerialMonitor.java \
AltosState.java \
AltosStatusTable.java \
AltosSerialMonitor.java \
AltosState.java \
AltosStatusTable.java \