2012-11-02 19:47:06 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the libsigrok project.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 Bert Vermeulen <bert@biot.com>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <glib.h>
|
2012-11-06 14:14:34 +00:00
|
|
|
#include <libusb.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2012-11-11 08:28:30 +00:00
|
|
|
#include "libsigrok.h"
|
|
|
|
#include "libsigrok-internal.h"
|
|
|
|
#include "protocol.h"
|
2012-11-06 14:14:34 +00:00
|
|
|
|
|
|
|
#define VICTOR_VID 0x1244
|
|
|
|
#define VICTOR_PID 0xd237
|
|
|
|
#define VICTOR_VENDOR "Victor"
|
|
|
|
#define VICTOR_INTERFACE 0
|
|
|
|
#define VICTOR_ENDPOINT LIBUSB_ENDPOINT_IN | 1
|
2012-11-02 19:47:06 +00:00
|
|
|
|
|
|
|
SR_PRIV struct sr_dev_driver victor_dmm_driver_info;
|
|
|
|
static struct sr_dev_driver *di = &victor_dmm_driver_info;
|
2013-05-10 17:37:54 +00:00
|
|
|
static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data);
|
2012-11-06 14:14:34 +00:00
|
|
|
|
2013-04-18 20:48:09 +00:00
|
|
|
static const int32_t hwopts[] = {
|
|
|
|
SR_CONF_CONN,
|
|
|
|
};
|
|
|
|
|
2013-03-30 18:29:44 +00:00
|
|
|
static const int32_t hwcaps[] = {
|
2013-01-21 22:22:47 +00:00
|
|
|
SR_CONF_MULTIMETER,
|
|
|
|
SR_CONF_LIMIT_MSEC,
|
|
|
|
SR_CONF_LIMIT_SAMPLES,
|
|
|
|
SR_CONF_CONTINUOUS,
|
2012-11-06 14:14:34 +00:00
|
|
|
};
|
|
|
|
|
2013-05-10 17:37:54 +00:00
|
|
|
static int init(struct sr_context *sr_ctx)
|
2012-11-02 19:47:06 +00:00
|
|
|
{
|
2013-05-31 13:46:57 +00:00
|
|
|
return std_init(sr_ctx, di, LOG_PREFIX);
|
2012-11-02 19:47:06 +00:00
|
|
|
}
|
|
|
|
|
2013-05-10 17:37:54 +00:00
|
|
|
static GSList *scan(GSList *options)
|
2012-11-02 19:47:06 +00:00
|
|
|
{
|
|
|
|
struct drv_context *drvc;
|
2012-11-06 14:14:34 +00:00
|
|
|
struct dev_context *devc;
|
|
|
|
struct sr_dev_inst *sdi;
|
|
|
|
struct sr_probe *probe;
|
|
|
|
struct libusb_device_descriptor des;
|
|
|
|
libusb_device **devlist;
|
2012-11-02 19:47:06 +00:00
|
|
|
GSList *devices;
|
2012-11-06 14:14:34 +00:00
|
|
|
int ret, devcnt, i;
|
2012-11-02 19:47:06 +00:00
|
|
|
|
|
|
|
(void)options;
|
|
|
|
|
2013-01-28 19:00:54 +00:00
|
|
|
drvc = di->priv;
|
2012-11-06 14:14:34 +00:00
|
|
|
|
2012-11-02 19:47:06 +00:00
|
|
|
devices = NULL;
|
2012-12-03 02:33:24 +00:00
|
|
|
libusb_get_device_list(drvc->sr_ctx->libusb_ctx, &devlist);
|
2012-11-06 14:14:34 +00:00
|
|
|
for (i = 0; devlist[i]; i++) {
|
|
|
|
if ((ret = libusb_get_device_descriptor(devlist[i], &des)) != 0) {
|
|
|
|
sr_warn("Failed to get device descriptor: %s",
|
|
|
|
libusb_error_name(ret));
|
|
|
|
continue;
|
|
|
|
}
|
2012-11-02 19:47:06 +00:00
|
|
|
|
2012-11-06 14:14:34 +00:00
|
|
|
if (des.idVendor != VICTOR_VID || des.idProduct != VICTOR_PID)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
devcnt = g_slist_length(drvc->instances);
|
2012-11-11 08:28:30 +00:00
|
|
|
if (!(sdi = sr_dev_inst_new(devcnt, SR_ST_INACTIVE,
|
|
|
|
VICTOR_VENDOR, NULL, NULL)))
|
2012-11-06 14:14:34 +00:00
|
|
|
return NULL;
|
|
|
|
sdi->driver = di;
|
|
|
|
|
|
|
|
if (!(devc = g_try_malloc0(sizeof(struct dev_context))))
|
|
|
|
return NULL;
|
|
|
|
sdi->priv = devc;
|
|
|
|
|
|
|
|
if (!(probe = sr_probe_new(0, SR_PROBE_ANALOG, TRUE, "P1")))
|
|
|
|
return NULL;
|
|
|
|
sdi->probes = g_slist_append(NULL, probe);
|
|
|
|
|
2013-04-18 20:48:09 +00:00
|
|
|
if (!(sdi->conn = sr_usb_dev_inst_new(libusb_get_bus_number(devlist[i]),
|
2012-11-06 14:14:34 +00:00
|
|
|
libusb_get_device_address(devlist[i]), NULL)))
|
|
|
|
return NULL;
|
2013-04-18 20:48:09 +00:00
|
|
|
sdi->inst_type = SR_INST_USB;
|
2012-11-06 14:14:34 +00:00
|
|
|
|
|
|
|
drvc->instances = g_slist_append(drvc->instances, sdi);
|
|
|
|
devices = g_slist_append(devices, sdi);
|
|
|
|
}
|
|
|
|
libusb_free_device_list(devlist, 1);
|
2012-11-02 19:47:06 +00:00
|
|
|
|
|
|
|
return devices;
|
|
|
|
}
|
|
|
|
|
2013-05-10 17:37:54 +00:00
|
|
|
static GSList *dev_list(void)
|
2012-11-02 19:47:06 +00:00
|
|
|
{
|
2013-02-02 18:52:26 +00:00
|
|
|
return ((struct drv_context *)(di->priv))->instances;
|
2012-11-02 19:47:06 +00:00
|
|
|
}
|
|
|
|
|
2013-05-10 17:37:54 +00:00
|
|
|
static int dev_open(struct sr_dev_inst *sdi)
|
2012-11-02 19:47:06 +00:00
|
|
|
{
|
2012-12-03 02:33:24 +00:00
|
|
|
struct drv_context *drvc = di->priv;
|
2013-04-18 20:48:09 +00:00
|
|
|
struct sr_usb_dev_inst *usb;
|
2012-11-06 14:14:34 +00:00
|
|
|
libusb_device **devlist;
|
|
|
|
int ret, i;
|
|
|
|
|
|
|
|
if (!di->priv) {
|
|
|
|
sr_err("Driver was not initialized.");
|
|
|
|
return SR_ERR;
|
|
|
|
}
|
|
|
|
|
2013-04-18 20:48:09 +00:00
|
|
|
usb = sdi->conn;
|
|
|
|
|
2012-12-03 02:33:24 +00:00
|
|
|
libusb_get_device_list(drvc->sr_ctx->libusb_ctx, &devlist);
|
2012-11-06 14:14:34 +00:00
|
|
|
for (i = 0; devlist[i]; i++) {
|
2013-04-18 20:48:09 +00:00
|
|
|
if (libusb_get_bus_number(devlist[i]) != usb->bus
|
|
|
|
|| libusb_get_device_address(devlist[i]) != usb->address)
|
2012-11-06 14:14:34 +00:00
|
|
|
continue;
|
2013-04-18 20:48:09 +00:00
|
|
|
if ((ret = libusb_open(devlist[i], &usb->devhdl))) {
|
2012-11-11 08:28:30 +00:00
|
|
|
sr_err("Failed to open device: %s.", libusb_error_name(ret));
|
2012-11-06 14:14:34 +00:00
|
|
|
return SR_ERR;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
libusb_free_device_list(devlist, 1);
|
|
|
|
if (!devlist[i]) {
|
|
|
|
sr_err("Device not found.");
|
|
|
|
return SR_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The device reports as HID class, so the kernel would have
|
|
|
|
* claimed it. */
|
2013-04-18 20:48:09 +00:00
|
|
|
if (libusb_kernel_driver_active(usb->devhdl, 0) == 1) {
|
|
|
|
if ((ret = libusb_detach_kernel_driver(usb->devhdl, 0)) < 0) {
|
2012-12-04 20:11:25 +00:00
|
|
|
sr_err("Failed to detach kernel driver: %s.",
|
|
|
|
libusb_error_name(ret));
|
2012-11-06 14:14:34 +00:00
|
|
|
return SR_ERR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-18 20:48:09 +00:00
|
|
|
if ((ret = libusb_claim_interface(usb->devhdl,
|
2012-11-06 14:14:34 +00:00
|
|
|
VICTOR_INTERFACE))) {
|
2012-11-11 08:28:30 +00:00
|
|
|
sr_err("Failed to claim interface: %s.", libusb_error_name(ret));
|
2012-11-06 14:14:34 +00:00
|
|
|
return SR_ERR;
|
|
|
|
}
|
|
|
|
sdi->status = SR_ST_ACTIVE;
|
2012-11-02 19:47:06 +00:00
|
|
|
|
|
|
|
return SR_OK;
|
|
|
|
}
|
|
|
|
|
2013-05-10 17:37:54 +00:00
|
|
|
static int dev_close(struct sr_dev_inst *sdi)
|
2012-11-02 19:47:06 +00:00
|
|
|
{
|
2013-04-18 20:48:09 +00:00
|
|
|
struct sr_usb_dev_inst *usb;
|
2012-11-06 14:14:34 +00:00
|
|
|
|
|
|
|
if (!di->priv) {
|
|
|
|
sr_err("Driver was not initialized.");
|
|
|
|
return SR_ERR;
|
|
|
|
}
|
|
|
|
|
2013-04-18 20:48:09 +00:00
|
|
|
usb = sdi->conn;
|
|
|
|
|
|
|
|
if (!usb->devhdl)
|
2012-11-06 14:14:34 +00:00
|
|
|
/* Nothing to do. */
|
|
|
|
return SR_OK;
|
|
|
|
|
2013-04-18 20:48:09 +00:00
|
|
|
libusb_release_interface(usb->devhdl, VICTOR_INTERFACE);
|
|
|
|
libusb_close(usb->devhdl);
|
|
|
|
usb->devhdl = NULL;
|
2012-11-06 14:14:34 +00:00
|
|
|
sdi->status = SR_ST_INACTIVE;
|
2012-11-02 19:47:06 +00:00
|
|
|
|
|
|
|
return SR_OK;
|
|
|
|
}
|
|
|
|
|
2013-05-10 17:37:54 +00:00
|
|
|
static int cleanup(void)
|
2012-11-02 19:47:06 +00:00
|
|
|
{
|
2013-05-31 12:10:59 +00:00
|
|
|
int ret;
|
2012-11-06 14:14:34 +00:00
|
|
|
struct drv_context *drvc;
|
|
|
|
|
|
|
|
if (!(drvc = di->priv))
|
|
|
|
/* Can get called on an unused driver, doesn't matter. */
|
|
|
|
return SR_OK;
|
2012-11-02 19:47:06 +00:00
|
|
|
|
2014-02-26 20:37:18 +00:00
|
|
|
|
|
|
|
ret = std_dev_clear(di, NULL);
|
2012-11-06 14:14:34 +00:00
|
|
|
g_free(drvc);
|
|
|
|
di->priv = NULL;
|
2012-11-02 19:47:06 +00:00
|
|
|
|
2013-05-31 12:10:59 +00:00
|
|
|
return ret;
|
2012-11-02 19:47:06 +00:00
|
|
|
}
|
|
|
|
|
2013-04-20 00:00:49 +00:00
|
|
|
static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi,
|
2014-03-20 20:58:01 +00:00
|
|
|
const struct sr_channel_group *cg)
|
2013-04-18 20:48:09 +00:00
|
|
|
{
|
|
|
|
struct sr_usb_dev_inst *usb;
|
|
|
|
char str[128];
|
|
|
|
|
2014-03-20 20:58:01 +00:00
|
|
|
(void)cg;
|
2013-04-20 00:00:49 +00:00
|
|
|
|
2013-04-18 20:48:09 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-04-20 00:00:49 +00:00
|
|
|
static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi,
|
2014-03-20 20:58:01 +00:00
|
|
|
const struct sr_channel_group *cg)
|
2012-11-02 19:47:06 +00:00
|
|
|
{
|
2012-11-06 14:14:34 +00:00
|
|
|
struct dev_context *devc;
|
|
|
|
gint64 now;
|
2012-11-02 19:47:06 +00:00
|
|
|
int ret;
|
|
|
|
|
2014-03-20 20:58:01 +00:00
|
|
|
(void)cg;
|
2013-04-20 00:00:49 +00:00
|
|
|
|
2013-04-23 13:14:42 +00:00
|
|
|
if (sdi->status != SR_ST_ACTIVE)
|
|
|
|
return SR_ERR_DEV_CLOSED;
|
|
|
|
|
2012-11-06 14:14:34 +00:00
|
|
|
if (!di->priv) {
|
|
|
|
sr_err("Driver was not initialized.");
|
|
|
|
return SR_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
devc = sdi->priv;
|
2012-11-02 19:47:06 +00:00
|
|
|
ret = SR_OK;
|
2013-01-24 18:19:09 +00:00
|
|
|
switch (id) {
|
2013-01-21 22:22:47 +00:00
|
|
|
case SR_CONF_LIMIT_MSEC:
|
2013-03-30 18:29:44 +00:00
|
|
|
devc->limit_msec = g_variant_get_uint64(data);
|
2012-11-11 08:28:30 +00:00
|
|
|
now = g_get_monotonic_time() / 1000;
|
|
|
|
devc->end_time = now + devc->limit_msec;
|
|
|
|
sr_dbg("Setting time limit to %" PRIu64 "ms.",
|
|
|
|
devc->limit_msec);
|
|
|
|
break;
|
2013-01-21 22:22:47 +00:00
|
|
|
case SR_CONF_LIMIT_SAMPLES:
|
2013-03-30 18:29:44 +00:00
|
|
|
devc->limit_samples = g_variant_get_uint64(data);
|
2012-11-11 08:28:30 +00:00
|
|
|
sr_dbg("Setting sample limit to %" PRIu64 ".",
|
|
|
|
devc->limit_samples);
|
|
|
|
break;
|
2012-11-02 19:47:06 +00:00
|
|
|
default:
|
2013-04-16 00:33:03 +00:00
|
|
|
ret = SR_ERR_NA;
|
2012-11-02 19:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-04-20 00:00:49 +00:00
|
|
|
static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi,
|
2014-03-20 20:58:01 +00:00
|
|
|
const struct sr_channel_group *cg)
|
2013-01-25 01:32:05 +00:00
|
|
|
{
|
|
|
|
(void)sdi;
|
2014-03-20 20:58:01 +00:00
|
|
|
(void)cg;
|
2013-01-25 01:32:05 +00:00
|
|
|
|
|
|
|
switch (key) {
|
2013-04-18 20:48:09 +00:00
|
|
|
case SR_CONF_SCAN_OPTIONS:
|
|
|
|
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32,
|
|
|
|
hwopts, ARRAY_SIZE(hwopts), sizeof(int32_t));
|
|
|
|
break;
|
2013-01-25 14:01:49 +00:00
|
|
|
case SR_CONF_DEVICE_OPTIONS:
|
2013-03-30 18:29:44 +00:00
|
|
|
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32,
|
|
|
|
hwcaps, ARRAY_SIZE(hwcaps), sizeof(int32_t));
|
2013-01-25 14:01:49 +00:00
|
|
|
break;
|
2013-01-25 01:32:05 +00:00
|
|
|
default:
|
2013-04-16 00:33:03 +00:00
|
|
|
return SR_ERR_NA;
|
2013-01-25 01:32:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return SR_OK;
|
|
|
|
}
|
|
|
|
|
2012-11-06 14:14:34 +00:00
|
|
|
static void receive_transfer(struct libusb_transfer *transfer)
|
|
|
|
{
|
|
|
|
struct dev_context *devc;
|
|
|
|
struct sr_dev_inst *sdi;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
sdi = transfer->user_data;
|
|
|
|
devc = sdi->priv;
|
|
|
|
if (transfer->status == LIBUSB_TRANSFER_NO_DEVICE) {
|
|
|
|
/* USB device was unplugged. */
|
2013-05-10 17:37:54 +00:00
|
|
|
dev_acquisition_stop(sdi, sdi);
|
2012-11-06 14:14:34 +00:00
|
|
|
} else if (transfer->status == LIBUSB_TRANSFER_COMPLETED) {
|
2012-11-11 08:28:30 +00:00
|
|
|
sr_dbg("Got %d-byte packet.", transfer->actual_length);
|
2012-11-06 18:37:33 +00:00
|
|
|
if (transfer->actual_length == DMM_DATA_SIZE) {
|
|
|
|
victor_dmm_receive_data(sdi, transfer->buffer);
|
2012-11-06 14:14:34 +00:00
|
|
|
if (devc->limit_samples) {
|
|
|
|
if (devc->num_samples >= devc->limit_samples)
|
2013-05-10 17:37:54 +00:00
|
|
|
dev_acquisition_stop(sdi, sdi);
|
2012-11-06 14:14:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Anything else is either an error or a timeout, which is fine:
|
|
|
|
* we were just going to send another transfer request anyway. */
|
|
|
|
|
|
|
|
if (sdi->status == SR_ST_ACTIVE) {
|
|
|
|
/* Send the same request again. */
|
|
|
|
if ((ret = libusb_submit_transfer(transfer) != 0)) {
|
2012-11-11 08:28:30 +00:00
|
|
|
sr_err("Unable to resubmit transfer: %s.",
|
|
|
|
libusb_error_name(ret));
|
2012-11-06 14:14:34 +00:00
|
|
|
g_free(transfer->buffer);
|
2012-12-09 13:40:12 +00:00
|
|
|
libusb_free_transfer(transfer);
|
2013-05-10 17:37:54 +00:00
|
|
|
dev_acquisition_stop(sdi, sdi);
|
2012-11-06 14:14:34 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* This was the last transfer we're going to receive, so
|
|
|
|
* clean up now. */
|
|
|
|
g_free(transfer->buffer);
|
2012-12-09 13:40:12 +00:00
|
|
|
libusb_free_transfer(transfer);
|
2012-11-06 14:14:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int handle_events(int fd, int revents, void *cb_data)
|
|
|
|
{
|
|
|
|
struct dev_context *devc;
|
2012-12-03 02:33:24 +00:00
|
|
|
struct drv_context *drvc = di->priv;
|
2012-11-06 14:14:34 +00:00
|
|
|
struct sr_datafeed_packet packet;
|
|
|
|
struct sr_dev_inst *sdi;
|
|
|
|
struct timeval tv;
|
|
|
|
gint64 now;
|
|
|
|
|
|
|
|
(void)fd;
|
|
|
|
(void)revents;
|
|
|
|
|
|
|
|
sdi = cb_data;
|
|
|
|
devc = sdi->priv;
|
|
|
|
|
|
|
|
if (devc->limit_msec) {
|
|
|
|
now = g_get_monotonic_time() / 1000;
|
|
|
|
if (now > devc->end_time)
|
2013-05-10 17:37:54 +00:00
|
|
|
dev_acquisition_stop(sdi, sdi);
|
2012-11-06 14:14:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (sdi->status == SR_ST_STOPPING) {
|
2013-12-21 23:03:24 +00:00
|
|
|
usb_source_remove(drvc->sr_ctx);
|
2012-11-06 14:14:34 +00:00
|
|
|
|
2013-05-10 17:37:54 +00:00
|
|
|
dev_close(sdi);
|
2012-11-06 14:14:34 +00:00
|
|
|
|
|
|
|
packet.type = SR_DF_END;
|
|
|
|
sr_session_send(cb_data, &packet);
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(&tv, 0, sizeof(struct timeval));
|
2012-12-03 02:33:24 +00:00
|
|
|
libusb_handle_events_timeout_completed(drvc->sr_ctx->libusb_ctx, &tv,
|
|
|
|
NULL);
|
2012-11-06 14:14:34 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2013-05-10 17:37:54 +00:00
|
|
|
static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
|
2012-11-02 19:47:06 +00:00
|
|
|
{
|
2012-11-06 14:14:34 +00:00
|
|
|
struct dev_context *devc;
|
2012-12-03 02:33:24 +00:00
|
|
|
struct drv_context *drvc = di->priv;
|
2013-04-18 20:48:09 +00:00
|
|
|
struct sr_usb_dev_inst *usb;
|
2012-11-06 14:14:34 +00:00
|
|
|
struct libusb_transfer *transfer;
|
2013-12-21 23:03:24 +00:00
|
|
|
int ret;
|
2012-11-06 14:14:34 +00:00
|
|
|
unsigned char *buf;
|
|
|
|
|
2013-04-23 13:14:42 +00:00
|
|
|
if (sdi->status != SR_ST_ACTIVE)
|
|
|
|
return SR_ERR_DEV_CLOSED;
|
|
|
|
|
2012-11-06 14:14:34 +00:00
|
|
|
if (!di->priv) {
|
|
|
|
sr_err("Driver was not initialized.");
|
|
|
|
return SR_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
devc = sdi->priv;
|
2013-04-18 20:48:09 +00:00
|
|
|
usb = sdi->conn;
|
2012-11-06 14:14:34 +00:00
|
|
|
devc->cb_data = cb_data;
|
|
|
|
|
|
|
|
/* Send header packet to the session bus. */
|
2013-05-03 19:59:32 +00:00
|
|
|
std_session_send_df_header(cb_data, LOG_PREFIX);
|
2012-11-06 14:14:34 +00:00
|
|
|
|
2013-12-21 23:03:24 +00:00
|
|
|
usb_source_add(drvc->sr_ctx, 100, handle_events, (void *)sdi);
|
2012-11-06 14:14:34 +00:00
|
|
|
|
2012-11-06 18:37:33 +00:00
|
|
|
buf = g_try_malloc(DMM_DATA_SIZE);
|
2012-11-06 14:14:34 +00:00
|
|
|
transfer = libusb_alloc_transfer(0);
|
|
|
|
/* Each transfer request gets 100ms to arrive before it's restarted.
|
|
|
|
* 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. */
|
2013-04-18 20:48:09 +00:00
|
|
|
libusb_fill_interrupt_transfer(transfer, usb->devhdl,
|
2012-11-11 08:28:30 +00:00
|
|
|
VICTOR_ENDPOINT, buf, DMM_DATA_SIZE, receive_transfer,
|
|
|
|
cb_data, 100);
|
2012-11-06 14:14:34 +00:00
|
|
|
if ((ret = libusb_submit_transfer(transfer) != 0)) {
|
2012-11-11 08:28:30 +00:00
|
|
|
sr_err("Unable to submit transfer: %s.", libusb_error_name(ret));
|
2012-11-06 14:14:34 +00:00
|
|
|
libusb_free_transfer(transfer);
|
|
|
|
g_free(buf);
|
|
|
|
return SR_ERR;
|
|
|
|
}
|
2012-11-02 19:47:06 +00:00
|
|
|
|
|
|
|
return SR_OK;
|
|
|
|
}
|
|
|
|
|
2013-05-10 17:37:54 +00:00
|
|
|
static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
|
2012-11-02 19:47:06 +00:00
|
|
|
{
|
|
|
|
(void)cb_data;
|
|
|
|
|
2012-11-06 14:14:34 +00:00
|
|
|
if (!di->priv) {
|
|
|
|
sr_err("Driver was not initialized.");
|
|
|
|
return SR_ERR;
|
|
|
|
}
|
|
|
|
|
2012-11-02 19:47:06 +00:00
|
|
|
if (sdi->status != SR_ST_ACTIVE) {
|
2012-11-06 14:14:34 +00:00
|
|
|
sr_err("Device not active, can't stop acquisition.");
|
2012-11-02 19:47:06 +00:00
|
|
|
return SR_ERR;
|
|
|
|
}
|
|
|
|
|
2012-11-06 14:14:34 +00:00
|
|
|
sdi->status = SR_ST_STOPPING;
|
2012-11-02 19:47:06 +00:00
|
|
|
|
|
|
|
return SR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
SR_PRIV struct sr_dev_driver victor_dmm_driver_info = {
|
|
|
|
.name = "victor-dmm",
|
2012-11-06 14:14:34 +00:00
|
|
|
.longname = "Victor DMMs",
|
2012-11-02 19:47:06 +00:00
|
|
|
.api_version = 1,
|
2013-05-10 17:37:54 +00:00
|
|
|
.init = init,
|
|
|
|
.cleanup = cleanup,
|
|
|
|
.scan = scan,
|
|
|
|
.dev_list = dev_list,
|
2014-02-26 20:37:18 +00:00
|
|
|
.dev_clear = NULL,
|
2013-04-18 20:48:09 +00:00
|
|
|
.config_get = config_get,
|
2013-01-24 18:19:09 +00:00
|
|
|
.config_set = config_set,
|
2013-01-25 01:32:05 +00:00
|
|
|
.config_list = config_list,
|
2013-05-10 17:37:54 +00:00
|
|
|
.dev_open = dev_open,
|
|
|
|
.dev_close = dev_close,
|
|
|
|
.dev_acquisition_start = dev_acquisition_start,
|
|
|
|
.dev_acquisition_stop = dev_acquisition_stop,
|
2012-11-02 19:47:06 +00:00
|
|
|
.priv = NULL,
|
|
|
|
};
|