X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fvictor-dmm%2Fapi.c;h=6a9b774fc98d6988a8e4b2f0083585cdd9a1e170;hb=95c1fe62f77d347bf173b1236c38a9043efabd2b;hp=9a07cc8309a97b10477a52d39612894a7d150130;hpb=c2fdcc25a47c4c8f25e3ea96ea36a674a151e839;p=libsigrok.git diff --git a/src/hardware/victor-dmm/api.c b/src/hardware/victor-dmm/api.c index 9a07cc83..6a9b774f 100644 --- a/src/hardware/victor-dmm/api.c +++ b/src/hardware/victor-dmm/api.c @@ -28,21 +28,17 @@ #define VICTOR_VID 0x1244 #define VICTOR_PID 0xd237 -#define VICTOR_VENDOR "Victor" #define VICTOR_INTERFACE 0 #define VICTOR_ENDPOINT (LIBUSB_ENDPOINT_IN | 1) -SR_PRIV struct sr_dev_driver victor_dmm_driver_info; -static int dev_acquisition_stop(struct sr_dev_inst *sdi); +static const uint32_t scanopts[] = { + SR_CONF_CONN, +}; static const uint32_t drvopts[] = { SR_CONF_MULTIMETER, }; -static const uint32_t scanopts[] = { - SR_CONF_CONN, -}; - static const uint32_t devopts[] = { SR_CONF_CONTINUOUS, SR_CONF_LIMIT_SAMPLES | SR_CONF_SET, @@ -77,8 +73,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) sdi = g_malloc0(sizeof(struct sr_dev_inst)); sdi->status = SR_ST_INACTIVE; - sdi->vendor = g_strdup(VICTOR_VENDOR); - sdi->driver = di; + sdi->vendor = g_strdup("Victor"); sdi->connection_id = g_strdup(connection_id); devc = g_malloc0(sizeof(struct dev_context)); sr_sw_limits_init(&devc->limits); @@ -89,12 +84,11 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) libusb_get_device_address(devlist[i]), NULL); sdi->inst_type = SR_INST_USB; - drvc->instances = g_slist_append(drvc->instances, sdi); devices = g_slist_append(devices, sdi); } libusb_free_device_list(devlist, 1); - return devices; + return std_scan_complete(di, devices); } static int dev_open(struct sr_dev_inst *sdi) @@ -110,8 +104,6 @@ static int dev_open(struct sr_dev_inst *sdi) if (ret != SR_OK) return ret; - /* The device reports as HID class, so the kernel would have - * claimed it. */ 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.", @@ -125,7 +117,6 @@ static int dev_open(struct sr_dev_inst *sdi) sr_err("Failed to claim interface: %s.", libusb_error_name(ret)); return SR_ERR; } - sdi->status = SR_ST_ACTIVE; return SR_OK; } @@ -137,23 +128,20 @@ static int dev_close(struct sr_dev_inst *sdi) usb = sdi->conn; if (!usb->devhdl) - /* Nothing to do. */ - return SR_OK; + return SR_ERR_BUG; libusb_release_interface(usb->devhdl, VICTOR_INTERFACE); libusb_close(usb->devhdl); usb->devhdl = NULL; - sdi->status = SR_ST_INACTIVE; return SR_OK; } -static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, - const struct sr_channel_group *cg) +static int config_get(uint32_t key, GVariant **data, + const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { struct dev_context *devc = sdi->priv; struct sr_usb_dev_inst *usb; - char str[128]; (void)cg; @@ -162,8 +150,7 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s 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); + *data = g_variant_new_printf("%d.%d", usb->bus, usb->address); break; case SR_CONF_LIMIT_SAMPLES: case SR_CONF_LIMIT_MSEC: @@ -175,45 +162,22 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s return SR_OK; } -static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi, - const struct sr_channel_group *cg) +static int config_set(uint32_t key, GVariant *data, + const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { struct dev_context *devc; (void)cg; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - devc = sdi->priv; return sr_sw_limits_config_set(&devc->limits, key, data); } -static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, - const struct sr_channel_group *cg) +static int config_list(uint32_t key, GVariant **data, + const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { - (void)sdi; - (void)cg; - - switch (key) { - case SR_CONF_SCAN_OPTIONS: - *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, - scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t)); - break; - case SR_CONF_DEVICE_OPTIONS: - if (!sdi) - *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, - drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t)); - else - *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, - devopts, ARRAY_SIZE(devopts), sizeof(uint32_t)); - break; - default: - return SR_ERR_NA; - } - - return SR_OK; + return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts); } static void LIBUSB_CALL receive_transfer(struct libusb_transfer *transfer) @@ -226,13 +190,13 @@ static void LIBUSB_CALL receive_transfer(struct libusb_transfer *transfer) devc = sdi->priv; if (transfer->status == LIBUSB_TRANSFER_NO_DEVICE) { /* USB device was unplugged. */ - dev_acquisition_stop(sdi); + sr_dev_acquisition_stop(sdi); } else if (transfer->status == LIBUSB_TRANSFER_COMPLETED) { sr_dbg("Got %d-byte packet.", transfer->actual_length); if (transfer->actual_length == DMM_DATA_SIZE) { victor_dmm_receive_data(sdi, transfer->buffer); if (sr_sw_limits_check(&devc->limits)) - dev_acquisition_stop(sdi); + sr_dev_acquisition_stop(sdi); } } /* Anything else is either an error or a timeout, which is fine: @@ -245,7 +209,7 @@ static void LIBUSB_CALL receive_transfer(struct libusb_transfer *transfer) libusb_error_name(ret)); g_free(transfer->buffer); libusb_free_transfer(transfer); - dev_acquisition_stop(sdi); + sr_dev_acquisition_stop(sdi); } } else { /* This was the last transfer we're going to receive, so @@ -272,12 +236,12 @@ static int handle_events(int fd, int revents, void *cb_data) drvc = di->context; if (sr_sw_limits_check(&devc->limits)) - dev_acquisition_stop(sdi); + sr_dev_acquisition_stop(sdi); if (sdi->status == SR_ST_STOPPING) { usb_source_remove(sdi->session, drvc->sr_ctx); dev_close(sdi); - std_session_send_df_end(sdi, LOG_PREFIX); + std_session_send_df_end(sdi); } memset(&tv, 0, sizeof(struct timeval)); @@ -296,12 +260,9 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) int ret; unsigned char *buf; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - usb = sdi->conn; - std_session_send_df_header(sdi, LOG_PREFIX); + std_session_send_df_header(sdi); usb_source_add(sdi->session, drvc->sr_ctx, 100, handle_events, (void *)sdi); @@ -327,17 +288,12 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) static int dev_acquisition_stop(struct sr_dev_inst *sdi) { - if (sdi->status != SR_ST_ACTIVE) { - sr_err("Device not active, can't stop acquisition."); - return SR_ERR; - } - sdi->status = SR_ST_STOPPING; return SR_OK; } -SR_PRIV struct sr_dev_driver victor_dmm_driver_info = { +static struct sr_dev_driver victor_dmm_driver_info = { .name = "victor-dmm", .longname = "Victor DMMs", .api_version = 1, @@ -345,7 +301,7 @@ SR_PRIV struct sr_dev_driver victor_dmm_driver_info = { .cleanup = std_cleanup, .scan = scan, .dev_list = std_dev_list, - .dev_clear = NULL, + .dev_clear = std_dev_clear, .config_get = config_get, .config_set = config_set, .config_list = config_list, @@ -355,3 +311,4 @@ SR_PRIV struct sr_dev_driver victor_dmm_driver_info = { .dev_acquisition_stop = dev_acquisition_stop, .context = NULL, }; +SR_REGISTER_DEV_DRIVER(victor_dmm_driver_info);