static int hw_dev_close(struct sr_dev_inst *sdi);
static int hw_dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data);
+static const int32_t hwopts[] = {
+ SR_CONF_CONN,
+};
+
static const int32_t hwcaps[] = {
SR_CONF_MULTIMETER,
SR_CONF_LIMIT_MSEC,
if (!(devc = sdi->priv))
continue;
hw_dev_close(sdi);
- sr_usb_dev_inst_free(devc->usb);
+ sr_usb_dev_inst_free(sdi->conn);
sr_dev_inst_free(sdi);
}
return NULL;
sdi->probes = g_slist_append(NULL, probe);
- if (!(devc->usb = sr_usb_dev_inst_new(libusb_get_bus_number(devlist[i]),
+ if (!(sdi->conn = sr_usb_dev_inst_new(libusb_get_bus_number(devlist[i]),
libusb_get_device_address(devlist[i]), NULL)))
return NULL;
+ sdi->inst_type = SR_INST_USB;
drvc->instances = g_slist_append(drvc->instances, sdi);
devices = g_slist_append(devices, sdi);
static int hw_dev_open(struct sr_dev_inst *sdi)
{
- struct dev_context *devc;
struct drv_context *drvc = di->priv;
+ struct sr_usb_dev_inst *usb;
libusb_device **devlist;
int ret, i;
return SR_ERR;
}
- devc = sdi->priv;
+ usb = sdi->conn;
+
libusb_get_device_list(drvc->sr_ctx->libusb_ctx, &devlist);
for (i = 0; devlist[i]; i++) {
- if (libusb_get_bus_number(devlist[i]) != devc->usb->bus
- || libusb_get_device_address(devlist[i]) != devc->usb->address)
+ if (libusb_get_bus_number(devlist[i]) != usb->bus
+ || libusb_get_device_address(devlist[i]) != usb->address)
continue;
- if ((ret = libusb_open(devlist[i], &devc->usb->devhdl))) {
+ if ((ret = libusb_open(devlist[i], &usb->devhdl))) {
sr_err("Failed to open device: %s.", libusb_error_name(ret));
return SR_ERR;
}
/* The device reports as HID class, so the kernel would have
* claimed it. */
- if (libusb_kernel_driver_active(devc->usb->devhdl, 0) == 1) {
- if ((ret = libusb_detach_kernel_driver(devc->usb->devhdl, 0)) < 0) {
+ if (libusb_kernel_driver_active(usb->devhdl, 0) == 1) {
+ if ((ret = libusb_detach_kernel_driver(usb->devhdl, 0)) < 0) {
sr_err("Failed to detach kernel driver: %s.",
libusb_error_name(ret));
return SR_ERR;
}
}
- if ((ret = libusb_claim_interface(devc->usb->devhdl,
+ if ((ret = libusb_claim_interface(usb->devhdl,
VICTOR_INTERFACE))) {
sr_err("Failed to claim interface: %s.", libusb_error_name(ret));
return SR_ERR;
static int hw_dev_close(struct sr_dev_inst *sdi)
{
- struct dev_context *devc;
+ struct sr_usb_dev_inst *usb;
if (!di->priv) {
sr_err("Driver was not initialized.");
return SR_ERR;
}
- devc = sdi->priv;
- if (!devc->usb->devhdl)
+ usb = sdi->conn;
+
+ if (!usb->devhdl)
/* Nothing to do. */
return SR_OK;
- libusb_release_interface(devc->usb->devhdl, VICTOR_INTERFACE);
- libusb_close(devc->usb->devhdl);
- devc->usb->devhdl = NULL;
+ libusb_release_interface(usb->devhdl, VICTOR_INTERFACE);
+ libusb_close(usb->devhdl);
+ usb->devhdl = NULL;
sdi->status = SR_ST_INACTIVE;
return SR_OK;
return SR_OK;
}
+static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi)
+{
+ struct sr_usb_dev_inst *usb;
+ char str[128];
+
+ switch (id) {
+ case SR_CONF_CONN:
+ if (!sdi || !sdi->conn)
+ return SR_ERR_ARG;
+ usb = sdi->conn;
+ snprintf(str, 128, "%d.%d", usb->bus, usb->address);
+ *data = g_variant_new_string(str);
+ break;
+ default:
+ return SR_ERR_NA;
+ }
+
+ return SR_OK;
+}
+
static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi)
{
struct dev_context *devc;
(void)sdi;
switch (key) {
+ case SR_CONF_SCAN_OPTIONS:
+ *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32,
+ hwopts, ARRAY_SIZE(hwopts), sizeof(int32_t));
+ break;
case SR_CONF_DEVICE_OPTIONS:
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32,
hwcaps, ARRAY_SIZE(hwcaps), sizeof(int32_t));
struct dev_context *devc;
struct drv_context *drvc = di->priv;
const struct libusb_pollfd **pfd;
+ struct sr_usb_dev_inst *usb;
struct libusb_transfer *transfer;
int ret, i;
unsigned char *buf;
}
devc = sdi->priv;
+ usb = sdi->conn;
devc->cb_data = cb_data;
/* Send header packet to the session bus. */
* The device only sends 1 transfer/second no matter how many
* times you ask, but we want to keep step with the USB events
* handling above. */
- libusb_fill_interrupt_transfer(transfer, devc->usb->devhdl,
+ libusb_fill_interrupt_transfer(transfer, usb->devhdl,
VICTOR_ENDPOINT, buf, DMM_DATA_SIZE, receive_transfer,
cb_data, 100);
if ((ret = libusb_submit_transfer(transfer) != 0)) {
.scan = hw_scan,
.dev_list = hw_dev_list,
.dev_clear = clear_instances,
- .config_get = NULL,
+ .config_get = config_get,
.config_set = config_set,
.config_list = config_list,
.dev_open = hw_dev_open,