X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Ftesto%2Fapi.c;h=6c975eed61d6f9e5b56eb298fe9dabb93d97f4ad;hb=e66d1892d0dd16ed166fc8f13493f95de0607362;hp=505df6757a6ae7744825cfbf882e31df0f1b6065;hpb=566007e15e8ec0a23b064ba8ea44baae305508b5;p=libsigrok.git diff --git a/src/hardware/testo/api.c b/src/hardware/testo/api.c index 505df675..6c975eed 100644 --- a/src/hardware/testo/api.c +++ b/src/hardware/testo/api.c @@ -22,7 +22,6 @@ #include "protocol.h" #define SERIALCOMM "115200/8n1" -static int dev_acquisition_stop(struct sr_dev_inst *sdi); static const uint32_t scanopts[] = { SR_CONF_CONN, @@ -128,13 +127,12 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) sdi->priv = devc; if (testo_probe_channels(sdi) != SR_OK) continue; - drvc->instances = g_slist_append(drvc->instances, sdi); devices = g_slist_append(devices, sdi); } libusb_free_device_list(devlist, 1); g_slist_free_full(conn_devices, (GDestroyNotify)sr_usb_dev_inst_free); - return devices; + return std_scan_complete(di, devices); } static int dev_open(struct sr_dev_inst *sdi) @@ -164,7 +162,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; } @@ -174,14 +171,13 @@ static int dev_close(struct sr_dev_inst *sdi) struct sr_usb_dev_inst *usb; usb = sdi->conn; + if (!usb->devhdl) - /* Nothing to do. */ - return SR_OK; + return SR_ERR_BUG; libusb_release_interface(usb->devhdl, 0); libusb_close(usb->devhdl); usb->devhdl = NULL; - sdi->status = SR_ST_INACTIVE; return SR_OK; } @@ -220,32 +216,13 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd (void)cg; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - return sr_sw_limits_config_set(&devc->sw_limits, key, data); } 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: - *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, NULL, devopts); } static void receive_data(struct sr_dev_inst *sdi, unsigned char *data, int len) @@ -286,7 +263,7 @@ static void receive_data(struct sr_dev_inst *sdi, unsigned char *data, int len) devc->reply_size = 0; if (sr_sw_limits_check(&devc->sw_limits)) - dev_acquisition_stop(sdi); + sr_dev_acquisition_stop(sdi); else testo_request_packet(sdi); @@ -306,7 +283,7 @@ SR_PRIV void LIBUSB_CALL receive_transfer(struct libusb_transfer *transfer) 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) { /* First two bytes in any transfer are FTDI status bytes. */ if (transfer->actual_length > 2) @@ -321,7 +298,7 @@ SR_PRIV 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 @@ -348,12 +325,12 @@ static int handle_events(int fd, int revents, void *cb_data) drvc = di->context; if (sr_sw_limits_check(&devc->sw_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)); @@ -374,15 +351,11 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) unsigned char *buf; drvc = di->context; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - - devc = sdi->priv; usb = sdi->conn; devc->reply_size = 0; - 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); @@ -413,9 +386,6 @@ 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) - return SR_ERR_DEV_CLOSED; - sdi->status = SR_ST_STOPPING; return SR_OK; @@ -429,6 +399,7 @@ static struct sr_dev_driver testo_driver_info = { .cleanup = std_cleanup, .scan = scan, .dev_list = std_dev_list, + .dev_clear = std_dev_clear, .config_get = config_get, .config_set = config_set, .config_list = config_list,