hantek-dso: Use physical USB connection instead of sdi->index

This commit is contained in:
Soeren Apel 2014-09-27 21:51:56 +02:00 committed by Bert Vermeulen
parent ee4f9bb1bd
commit 395206f460
2 changed files with 25 additions and 29 deletions

View File

@ -158,7 +158,7 @@ static struct sr_dev_driver *di = &hantek_dso_driver_info;
static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data); static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data);
static struct sr_dev_inst *dso_dev_new(int index, const struct dso_profile *prof) static struct sr_dev_inst *dso_dev_new(const struct dso_profile *prof)
{ {
struct sr_dev_inst *sdi; struct sr_dev_inst *sdi;
struct sr_channel *ch; struct sr_channel *ch;
@ -166,7 +166,7 @@ static struct sr_dev_inst *dso_dev_new(int index, const struct dso_profile *prof
struct dev_context *devc; struct dev_context *devc;
int i; int i;
sdi = sr_dev_inst_new(index, SR_ST_INITIALIZING, sdi = sr_dev_inst_new(0, SR_ST_INITIALIZING,
prof->vendor, prof->model, NULL); prof->vendor, prof->model, NULL);
if (!sdi) if (!sdi)
return NULL; return NULL;
@ -266,12 +266,12 @@ static GSList *scan(GSList *options)
GSList *l, *devices, *conn_devices; GSList *l, *devices, *conn_devices;
struct libusb_device_descriptor des; struct libusb_device_descriptor des;
libusb_device **devlist; libusb_device **devlist;
int devcnt, ret, i, j; int ret, i, j;
const char *conn; const char *conn;
char connection_id[64];
drvc = di->priv; drvc = di->priv;
devcnt = 0;
devices = 0; devices = 0;
conn = NULL; conn = NULL;
@ -310,6 +310,8 @@ static GSList *scan(GSList *options)
continue; continue;
} }
usb_get_port_path(devlist[i], connection_id, sizeof(connection_id));
prof = NULL; prof = NULL;
for (j = 0; dev_profiles[j].orig_vid; j++) { for (j = 0; dev_profiles[j].orig_vid; j++) {
if (des.idVendor == dev_profiles[j].orig_vid if (des.idVendor == dev_profiles[j].orig_vid
@ -317,7 +319,8 @@ static GSList *scan(GSList *options)
/* Device matches the pre-firmware profile. */ /* Device matches the pre-firmware profile. */
prof = &dev_profiles[j]; prof = &dev_profiles[j];
sr_dbg("Found a %s %s.", prof->vendor, prof->model); sr_dbg("Found a %s %s.", prof->vendor, prof->model);
sdi = dso_dev_new(devcnt, prof); sdi = dso_dev_new(prof);
sdi->connection_id = g_strdup(connection_id);
devices = g_slist_append(devices, sdi); devices = g_slist_append(devices, sdi);
devc = sdi->priv; devc = sdi->priv;
if (ezusb_upload_firmware(devlist[i], USB_CONFIGURATION, if (ezusb_upload_firmware(devlist[i], USB_CONFIGURATION,
@ -325,19 +328,18 @@ static GSList *scan(GSList *options)
/* Remember when the firmware on this device was updated */ /* Remember when the firmware on this device was updated */
devc->fw_updated = g_get_monotonic_time(); devc->fw_updated = g_get_monotonic_time();
else else
sr_err("Firmware upload failed for " sr_err("Firmware upload failed");
"device %d.", devcnt);
/* Dummy USB address of 0xff will get overwritten later. */ /* Dummy USB address of 0xff will get overwritten later. */
sdi->conn = sr_usb_dev_inst_new( sdi->conn = sr_usb_dev_inst_new(
libusb_get_bus_number(devlist[i]), 0xff, NULL); libusb_get_bus_number(devlist[i]), 0xff, NULL);
devcnt++;
break; break;
} else if (des.idVendor == dev_profiles[j].fw_vid } else if (des.idVendor == dev_profiles[j].fw_vid
&& des.idProduct == dev_profiles[j].fw_pid) { && des.idProduct == dev_profiles[j].fw_pid) {
/* Device matches the post-firmware profile. */ /* Device matches the post-firmware profile. */
prof = &dev_profiles[j]; prof = &dev_profiles[j];
sr_dbg("Found a %s %s.", prof->vendor, prof->model); sr_dbg("Found a %s %s.", prof->vendor, prof->model);
sdi = dso_dev_new(devcnt, prof); sdi = dso_dev_new(prof);
sdi->connection_id = g_strdup(connection_id);
sdi->status = SR_ST_INACTIVE; sdi->status = SR_ST_INACTIVE;
devices = g_slist_append(devices, sdi); devices = g_slist_append(devices, sdi);
devc = sdi->priv; devc = sdi->priv;
@ -345,7 +347,6 @@ static GSList *scan(GSList *options)
sdi->conn = sr_usb_dev_inst_new( sdi->conn = sr_usb_dev_inst_new(
libusb_get_bus_number(devlist[i]), libusb_get_bus_number(devlist[i]),
libusb_get_device_address(devlist[i]), NULL); libusb_get_device_address(devlist[i]), NULL);
devcnt++;
break; break;
} }
} }

View File

@ -113,7 +113,8 @@ SR_PRIV int dso_open(struct sr_dev_inst *sdi)
struct sr_usb_dev_inst *usb; struct sr_usb_dev_inst *usb;
struct libusb_device_descriptor des; struct libusb_device_descriptor des;
libusb_device **devlist; libusb_device **devlist;
int err, skip, i; int err, i;
char connection_id[64];
devc = sdi->priv; devc = sdi->priv;
usb = sdi->conn; usb = sdi->conn;
@ -122,7 +123,6 @@ SR_PRIV int dso_open(struct sr_dev_inst *sdi)
/* already in use */ /* already in use */
return SR_ERR; return SR_ERR;
skip = 0;
libusb_get_device_list(drvc->sr_ctx->libusb_ctx, &devlist); libusb_get_device_list(drvc->sr_ctx->libusb_ctx, &devlist);
for (i = 0; devlist[i]; i++) { for (i = 0; devlist[i]; i++) {
if ((err = libusb_get_device_descriptor(devlist[i], &des))) { if ((err = libusb_get_device_descriptor(devlist[i], &des))) {
@ -135,20 +135,14 @@ SR_PRIV int dso_open(struct sr_dev_inst *sdi)
|| des.idProduct != devc->profile->fw_pid) || des.idProduct != devc->profile->fw_pid)
continue; continue;
if (sdi->status == SR_ST_INITIALIZING) { if ((sdi->status == SR_ST_INITIALIZING) ||
if (skip != sdi->index) { (sdi->status == SR_ST_INACTIVE)) {
/* Skip devices of this type that aren't the one we want. */
skip += 1;
continue;
}
} else if (sdi->status == SR_ST_INACTIVE) {
/* /*
* This device is fully enumerated, so we need to find * Check device by its physical USB bus/port address.
* this device by vendor, product, bus and address.
*/ */
if (libusb_get_bus_number(devlist[i]) != usb->bus usb_get_port_path(devlist[i], connection_id, sizeof(connection_id));
|| libusb_get_device_address(devlist[i]) != usb->address) if (strcmp(sdi->connection_id, connection_id))
/* this is not the one */ /* This is not the one. */
continue; continue;
} }
@ -164,9 +158,10 @@ SR_PRIV int dso_open(struct sr_dev_inst *sdi)
sr_err("Wrong endpoint profile."); sr_err("Wrong endpoint profile.");
else { else {
sdi->status = SR_ST_ACTIVE; sdi->status = SR_ST_ACTIVE;
sr_info("Opened device %d on %d.%d interface %d.", sr_info("Opened device on %d.%d (logical) / "
sdi->index, usb->bus, "%s (physical) interface %d.",
usb->address, USB_INTERFACE); usb->bus, usb->address,
sdi->connection_id, USB_INTERFACE);
} }
} else { } else {
sr_err("Failed to open device: %s.", sr_err("Failed to open device: %s.",
@ -193,8 +188,8 @@ SR_PRIV void dso_close(struct sr_dev_inst *sdi)
if (usb->devhdl == NULL) if (usb->devhdl == NULL)
return; return;
sr_info("Closing device %d on %d.%d interface %d.", sdi->index, sr_info("Closing device on %d.%d (logical) / %s (physical) interface %d.",
usb->bus, usb->address, USB_INTERFACE); usb->bus, usb->address, sdi->connection_id, USB_INTERFACE);
libusb_release_interface(usb->devhdl, USB_INTERFACE); libusb_release_interface(usb->devhdl, USB_INTERFACE);
libusb_close(usb->devhdl); libusb_close(usb->devhdl);
usb->devhdl = NULL; usb->devhdl = NULL;