altosui: conflating USB product and vendor IDs is a bad idea
authorKeith Packard <keithp@keithp.com>
Fri, 10 Sep 2010 03:24:42 +0000 (20:24 -0700)
committerKeith Packard <keithp@keithp.com>
Fri, 10 Sep 2010 03:26:44 +0000 (20:26 -0700)
We've now got a USB vendor ID called 'altusmetrum' for generic
altusmetrum devices (old USB ID 0x000A) while the general vendor name
for all devices is 'altusmetrum' as well.

This patch splits vendors and products into separate name spaces,
products are prefixed with product_ and vendor with (oddly) vendor_.

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

index 3d97074..7b6cd78 100644 (file)
@@ -238,12 +238,12 @@ public class AltosConfig implements Runnable, ActionListener {
                version = new string_ref("unknown");
                product = new string_ref("unknown");
 
-               device = AltosDeviceDialog.show(owner, AltosDevice.Any);
+               device = AltosDeviceDialog.show(owner, AltosDevice.product_any);
                serial_line = new AltosSerial();
                if (device != null) {
                        try {
                                serial_line.open(device);
-                               if (!device.matchProduct(AltosDevice.TeleMetrum))
+                               if (!device.matchProduct(AltosDevice.product_telemetrum))
                                        remote = true;
                                config_thread = new Thread(this);
                                config_thread.start();
index 9ae522c..d671031 100644 (file)
@@ -39,6 +39,12 @@ public class AltosDevice extends altos_device {
                return loaded_library;
        }
 
+       static int usb_vendor_altusmetrum() {
+               if (load_library())
+                       return libaltosConstants.USB_VENDOR_ALTUSMETRUM;
+               return 0x000a;
+       }
+
        static int usb_product_altusmetrum() {
                if (load_library())
                        return libaltosConstants.USB_PRODUCT_ALTUSMETRUM;
@@ -65,26 +71,27 @@ public class AltosDevice extends altos_device {
 
        static int usb_product_teledongle() {
                if (load_library())
-                       return libaltosConstants.USB_PRODUCT_ALTUSMETRUM;
+                       return libaltosConstants.USB_PRODUCT_TELEDONGLE;
                return 0x000c;
        }
 
        static int usb_product_teleterra() {
                if (load_library())
-                       return libaltosConstants.USB_PRODUCT_ALTUSMETRUM;
+                       return libaltosConstants.USB_PRODUCT_TELETERRA;
                return 0x000d;
        }
 
-       public final static int AltusMetrum = usb_product_altusmetrum();
-       public final static int TeleMetrum = usb_product_telemetrum();
-       public final static int TeleDongle = usb_product_teledongle();
-       public final static int TeleTerra = usb_product_teleterra();
-       public final static int AltusMetrumMin = usb_product_altusmetrum_min();
-       public final static int AltusMetrumMax = usb_product_altusmetrum_max();
+       public final static int vendor_altusmetrum = usb_vendor_altusmetrum();
+       public final static int product_altusmetrum = usb_product_altusmetrum();
+       public final static int product_telemetrum = usb_product_telemetrum();
+       public final static int product_teledongle = usb_product_teledongle();
+       public final static int product_teleterra = usb_product_teleterra();
+       public final static int product_altusmetrum_min = usb_product_altusmetrum_min();
+       public final static int product_altusmetrum_max = usb_product_altusmetrum_max();
 
 
-       public final static int Any = 0x10000;
-       public final static int BaseStation = 0x10000 + 1;
+       public final static int product_any = 0x10000;
+       public final static int product_basestation = 0x10000 + 1;
 
        public String toString() {
                String  name = getName();
@@ -95,29 +102,34 @@ public class AltosDevice extends altos_device {
        }
 
        public boolean isAltusMetrum() {
-               if (getVendor() != AltusMetrum)
+               if (getVendor() != vendor_altusmetrum)
                        return false;
-               if (getProduct() < AltusMetrumMin)
+               if (getProduct() < product_altusmetrum_min)
                        return false;
-               if (getProduct() > AltusMetrumMax)
+               if (getProduct() > product_altusmetrum_max)
                        return false;
                return true;
        }
 
        public boolean matchProduct(int want_product) {
 
+               System.out.printf("vendor %x product %x want %x\n",
+                                 getVendor(), getProduct(), want_product);
+               System.out.printf("vendor_altusmetrum: %d\n", vendor_altusmetrum);
+               System.out.printf("telemetrum: %d\n", product_telemetrum);
+
                if (!isAltusMetrum())
                        return false;
 
-               if (want_product == Any)
+               if (want_product == product_any)
                        return true;
 
-               if (want_product == BaseStation)
-                       return matchProduct(TeleDongle) || matchProduct(TeleTerra);
+               if (want_product == product_basestation)
+                       return matchProduct(product_teledongle) || matchProduct(product_teleterra);
 
                int have_product = getProduct();
 
-               if (have_product == AltusMetrum)        /* old devices match any request */
+               if (have_product == product_altusmetrum)        /* old devices match any request */
                        return true;
 
                if (want_product == have_product)
@@ -127,19 +139,23 @@ public class AltosDevice extends altos_device {
        }
 
        static AltosDevice[] list(int product) {
-               if (!load_library())
+               if (!load_library()) {
+                       System.out.printf("no library\n");
                        return null;
+               }
 
                SWIGTYPE_p_altos_list list = libaltos.altos_list_start();
 
                ArrayList<AltosDevice> device_list = new ArrayList<AltosDevice>();
                if (list != null) {
+                       System.out.printf("got device list\n");
                        SWIGTYPE_p_altos_file file;
 
                        for (;;) {
                                AltosDevice device = new AltosDevice();
                                if (libaltos.altos_list_next(list, device) == 0)
                                        break;
+                               System.out.printf("got device\n");
                                if (device.matchProduct(product))
                                        device_list.add(device);
                        }
index 6dbbd3e..a7f6490 100644 (file)
@@ -254,7 +254,7 @@ public class AltosEepromDownload implements Runnable {
 
        public AltosEepromDownload(JFrame given_frame) {
                frame = given_frame;
-               device = AltosDeviceDialog.show(frame, AltosDevice.Any);
+               device = AltosDeviceDialog.show(frame, AltosDevice.product_any);
 
                serial_line = new AltosSerial();
                remote = false;
@@ -262,7 +262,7 @@ public class AltosEepromDownload implements Runnable {
                if (device != null) {
                        try {
                                serial_line.open(device);
-                               if (!device.matchProduct(AltosDevice.TeleMetrum))
+                               if (!device.matchProduct(AltosDevice.product_telemetrum))
                                        remote = true;
                                eeprom_thread = new Thread(this);
                                eeprom_thread.start();
index 1879569..5ed417d 100644 (file)
@@ -187,7 +187,7 @@ public class AltosFlashUI
 
                build_dialog();
 
-               debug_dongle = AltosDeviceDialog.show(frame, AltosDevice.Any);
+               debug_dongle = AltosDeviceDialog.show(frame, AltosDevice.product_any);
 
                if (debug_dongle == null)
                        return;
index ca587b2..edee146 100644 (file)
@@ -523,7 +523,8 @@ public class AltosUI extends JFrame {
        }
 
        private void ConnectToDevice() {
-               AltosDevice     device = AltosDeviceDialog.show(AltosUI.this, AltosDevice.BaseStation);
+               AltosDevice     device = AltosDeviceDialog.show(AltosUI.this,
+                                                               AltosDevice.product_basestation);
 
                if (device != null) {
                        try {