altosui: Catch errors opening USB devices. Limit list to relevant devices
authorKeith Packard <keithp@keithp.com>
Wed, 28 Jul 2010 19:24:53 +0000 (12:24 -0700)
committerKeith Packard <keithp@keithp.com>
Wed, 28 Jul 2010 19:24:53 +0000 (12:24 -0700)
Avoids a segfault when failing to open a device. Limit listed telemetry
devices to just TeleDongle units.

Signed-off-by: Keith Packard <keithp@keithp.com>
ao-tools/altosui/AltosDevice.java
ao-tools/altosui/AltosDeviceDialog.java
ao-tools/altosui/AltosSerial.java
ao-tools/altosui/AltosUI.java

index 0e7d01da757cf1f7e2729c6a4be038c2133fb873..f488174cf7677e3dc345b1a6875b78d2f5e41d7a 100644 (file)
@@ -42,7 +42,8 @@ public class AltosDevice extends altos_device {
                                AltosDevice device = new AltosDevice();
                                if (libaltos.altos_list_next(list, device) == 0)
                                        break;
                                AltosDevice device = new AltosDevice();
                                if (libaltos.altos_list_next(list, device) == 0)
                                        break;
-                               device_list.add(device);
+                               if (product == null || device.getProduct().startsWith(product))
+                                       device_list.add(device);
                        }
                        libaltos.altos_list_finish(list);
                }
                        }
                        libaltos.altos_list_finish(list);
                }
index eb70877c9b99f18559a83e81989e126623251d75..08921c3d044d308680106b529b96f2c0b4abad8e 100644 (file)
@@ -41,6 +41,10 @@ public class AltosDeviceDialog {
                                                               devices[0]);
                        return (altos_device) o;
                } else {
                                                               devices[0]);
                        return (altos_device) o;
                } else {
+                       JOptionPane.showMessageDialog(frame,
+                                                     "No AltOS devices available",
+                                                     "No AltOS devices",
+                                                     JOptionPane.ERROR_MESSAGE);
                        return null;
                }
        }
                        return null;
                }
        }
index e84f5b63e4e21c7ca5cdd0cbb0cb90c863383ced..b016c1d65fbecfe0463c0e97933148cf10c2d55b 100644 (file)
@@ -134,6 +134,8 @@ public class AltosSerial implements Runnable {
        public void open(altos_device device) throws FileNotFoundException {
                close();
                altos = libaltos.altos_open(device);
        public void open(altos_device device) throws FileNotFoundException {
                close();
                altos = libaltos.altos_open(device);
+               if (altos == null)
+                       throw new FileNotFoundException(device.getPath());
                input_thread = new Thread(this);
                input_thread.start();
        }
                input_thread = new Thread(this);
                input_thread.start();
        }
index 3dfc89527601d52d6bf685b2174b66ca9e75e883..5c92b9b4d3c0d3ead2638158ab248c89e4de4b6b 100644 (file)
@@ -493,8 +493,9 @@ public class AltosUI extends JFrame {
                                run_display(thread);
                        } catch (FileNotFoundException ee) {
                                JOptionPane.showMessageDialog(AltosUI.this,
                                run_display(thread);
                        } catch (FileNotFoundException ee) {
                                JOptionPane.showMessageDialog(AltosUI.this,
-                                                             device.getPath(),
-                                                             "Cannot open serial port",
+                                                             String.format("Cannot open device \"%s\"",
+                                                                           device.getPath()),
+                                                             "Cannot open target device",
                                                              JOptionPane.ERROR_MESSAGE);
                        } catch (IOException ee) {
                                JOptionPane.showMessageDialog(AltosUI.this,
                                                              JOptionPane.ERROR_MESSAGE);
                        } catch (IOException ee) {
                                JOptionPane.showMessageDialog(AltosUI.this,