]> sigrok.org Git - libsigrok.git/commitdiff
fx2lafw: warn on fail to open plausible devices
authorKarl Palsson <redacted>
Tue, 22 Nov 2016 13:12:55 +0000 (13:12 +0000)
committerUwe Hermann <redacted>
Mon, 5 Dec 2016 01:16:33 +0000 (02:16 +0100)
Instead of silently ignoring all devices that fail to open.

This fixes bug #867.

Signed-off-by: Karl Palsson <redacted>
src/hardware/fx2lafw/api.c

index dd82729ec9a2b398c272a3160a586c16f3bc6c33..0f9cadb64cc5337789482facc4e35a406b5a4f6b 100644 (file)
@@ -214,6 +214,20 @@ static const uint64_t dslogic_samplerates[] = {
        SR_MHZ(400),
 };
 
+static gboolean is_plausible(const struct libusb_device_descriptor *des)
+{
+       int i;
+
+       for (i = 0; supported_fx2[i].vid; i++) {
+               if (des->idVendor != supported_fx2[i].vid)
+                       continue;
+               if (des->idProduct == supported_fx2[i].pid)
+                       return TRUE;
+       }
+
+       return FALSE;
+}
+
 static GSList *scan(struct sr_dev_driver *di, GSList *options)
 {
        struct drv_context *drvc;
@@ -271,9 +285,16 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
 
                libusb_get_device_descriptor( devlist[i], &des);
 
-               if ((ret = libusb_open(devlist[i], &hdl)) < 0)
+               if (!is_plausible(&des))
                        continue;
 
+               if ((ret = libusb_open(devlist[i], &hdl)) < 0) {
+                       sr_warn("Failed to open potential device with "
+                               "VID:PID %04x:%04x: %s.", des.idVendor,
+                               des.idProduct, libusb_error_name(ret));
+                       continue;
+               }
+
                if (des.iManufacturer == 0) {
                        manufacturer[0] = '\0';
                } else if ((ret = libusb_get_string_descriptor_ascii(hdl,