static GSList *scan(struct sr_dev_driver *di, GSList *options)
{
struct sr_dev_inst *sdi;
- struct drv_context *drvc;
struct dev_context *devc;
struct sr_config *src;
struct sr_serial_dev_inst *serial;
const char *conn, *serialcomm;
char *buf, **tokens;
- drvc = di->context;
-
devices = NULL;
conn = serialcomm = NULL;
for (l = options; l; l = l->next) {
sdi->inst_type = SR_INST_SERIAL;
sdi->conn = serial;
sdi->priv = devc;
- sdi->driver = di;
sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "P1");
- drvc->instances = g_slist_append(drvc->instances, sdi);
devices = g_slist_append(devices, sdi);
break;
}
if (!devices)
sr_serial_dev_inst_free(serial);
- return devices;
+ return std_scan_complete(di, devices);
}
static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi,
sdi->inst_type = SR_INST_SERIAL;
sdi->conn = serial;
sdi->priv = devc;
- sdi->driver = di;
sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "T1");
sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "T2");
- drvc->instances = g_slist_append(drvc->instances, sdi);
devices = g_slist_append(devices, sdi);
scan_cleanup:
serial_close(serial);
- return devices;
+ return std_scan_complete(di, devices);
}
static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
sdi->vendor = g_strdup("Arachnid Labs");
sdi->model = g_strdup("Re:load Pro");
sdi->version = g_strdup(buf + 8);
- sdi->driver = di;
sdi->inst_type = SR_INST_SERIAL;
sdi->conn = serial;
devc = g_malloc0(sizeof(struct dev_context));
sdi->priv = devc;
- drvc->instances = g_slist_append(drvc->instances, sdi);
devices = g_slist_append(devices, sdi);
serial_close(serial);
if (!devices)
sr_serial_dev_inst_free(serial);
- return devices;
+ return std_scan_complete(di, devices);
}
static int config_list(uint32_t key, GVariant **data,
static GSList *scan(struct sr_dev_driver *di, GSList *options)
{
struct sr_dev_inst *sdi;
- struct drv_context *drvc;
struct dev_context *devc;
GSList *devices;
struct ftdi_device_list *devlist;
(void)options;
- drvc = di->context;
-
devices = NULL;
devc = g_malloc0(sizeof(struct dev_context));
sdi->status = SR_ST_INITIALIZING;
sdi->vendor = g_strdup(USB_VENDOR_NAME);
sdi->model = g_strdup(USB_MODEL_NAME);
- sdi->driver = di;
for (i = 0; i < ARRAY_SIZE(channel_names); i++)
sr_channel_new(sdi, i, SR_CHANNEL_LOGIC, TRUE, channel_names[i]);
devices = g_slist_append(devices, sdi);
- drvc->instances = g_slist_append(drvc->instances, sdi);
sdi->priv = devc;
/* We will open the device again when we need it. */
ftdi_list_free(&devlist);
- return devices;
+ return std_scan_complete(di, devices);
free:
ftdi_deinit(&devc->ftdic);
sdi->status = SR_ST_INACTIVE;
sdi->vendor = g_strdup("Atten");
sdi->model = g_strdup(model->name);
- sdi->driver = di;
sdi->inst_type = SR_INST_SERIAL;
sdi->conn = serial;
for (i = 0; i < MAX_CHANNELS; i++) {
devc->config = g_malloc0(sizeof(struct per_channel_config) * model->num_channels);
devc->delay_ms = delay_ms;
sdi->priv = devc;
- drvc->instances = g_slist_append(drvc->instances, sdi);
devices = g_slist_append(devices, sdi);
serial_close(serial);
if (!devices)
sr_serial_dev_inst_free(serial);
- return devices;
+ return std_scan_complete(di, devices);
}
static GSList *scan_3203(struct sr_dev_driver *di, GSList *options)
static GSList *scan(struct sr_dev_driver *di, GSList *options)
{
- struct drv_context *drvc;
struct dev_context *devc;
struct sr_dev_inst *sdi;
GSList *devices;
(void)options;
- drvc = di->context;
devices = NULL;
devc = g_malloc0(sizeof(struct dev_context));
sdi->status = SR_ST_INACTIVE;
sdi->vendor = g_strdup("BayLibre");
sdi->model = g_strdup("ACME");
- sdi->driver = di;
sdi->priv = devc;
status = bl_acme_is_sane();
goto err_out;
devices = g_slist_append(devices, sdi);
- drvc->instances = g_slist_append(drvc->instances, sdi);
- return devices;
+ return std_scan_complete(di, devices);
err_out:
g_free(devc);
static GSList *scan(struct sr_dev_driver *di, GSList *options)
{
- struct drv_context *drvc;
GSList *devices, *l;
struct sr_config *src;
struct sr_dev_inst *sdi;
int i, maxch;
devices = NULL;
- drvc = di->context;
/* Probe for /dev/beaglelogic */
if (!g_file_test(BEAGLELOGIC_DEV_NODE, G_FILE_TEST_EXISTS))
sdi->status = SR_ST_INACTIVE;
sdi->model = g_strdup("BeagleLogic");
sdi->version = g_strdup("1.0");
- sdi->driver = di;
/* Unless explicitly specified, keep max channels to 8 only */
maxch = 8;
channel_names[i]);
sdi->priv = devc;
- drvc->instances = g_slist_append(drvc->instances, sdi);
devices = g_slist_append(devices, sdi);
- return devices;
+ return std_scan_complete(di, devices);
}
static int dev_open(struct sr_dev_inst *sdi)
sdi->model = g_strdup("BM869");
devc = g_malloc0(sizeof(struct dev_context));
sdi->priv = devc;
- sdi->driver = di;
sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "P1");
sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "P2");
sr_sw_limits_init(&devc->sw_limits);
- drvc->instances = g_slist_append(drvc->instances, sdi);
devices = g_slist_append(devices, sdi);
}
- return devices;
+ return std_scan_complete(di, devices);
}
static int dev_open(struct sr_dev_inst *sdi)
{
struct sr_dev_inst *sdi;
struct dev_context *devc;
- struct drv_context *drvc;
struct sr_serial_dev_inst *serial;
GSList *devices;
int ret;
sr_sw_limits_init(&devc->sw_limits);
sdi->inst_type = SR_INST_SERIAL;
sdi->conn = serial;
- drvc = di->context;
sdi->priv = devc;
- sdi->driver = di;
sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "P1");
- drvc->instances = g_slist_append(drvc->instances, sdi);
devices = g_slist_append(devices, sdi);
scan_cleanup:
serial_close(serial);
- return devices;
+ return std_scan_complete(di, devices);
}
static GSList *scan(struct sr_dev_driver *di, GSList *options)
sdi->conn = sr_serial_dev_inst_new(conn, SERIALCOMM);
sdi->inst_type = SR_INST_SERIAL;
sdi->priv = devc;
- sdi->driver = di;
sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "SPL");
- drvc->instances = g_slist_append(drvc->instances, sdi);
devices = g_slist_append(devices, sdi);
break;
}
serial_close(serial);
- return devices;
+ return std_scan_complete(di, devices);
}
static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
{
int i;
struct sr_dev_inst *sdi;
- struct drv_context *drvc;
struct dev_context *devc;
struct sr_serial_dev_inst *serial;
GSList *devices;
if (serial_open(serial, SERIAL_RDWR) != SR_OK)
return NULL;
- drvc = center_devs[idx].di->context;
devices = NULL;
serial_flush(serial);
sdi->inst_type = SR_INST_SERIAL;
sdi->conn = serial;
sdi->priv = devc;
- sdi->driver = center_devs[idx].di;
for (i = 0; i < center_devs[idx].num_channels; i++)
sr_channel_new(sdi, i, SR_CHANNEL_ANALOG, TRUE, channel_names[i]);
- drvc->instances = g_slist_append(drvc->instances, sdi);
devices = g_slist_append(devices, sdi);
serial_close(serial);
devices = center_scan(conn, center_devs[idx].conn, idx);
}
- return devices;
+ return std_scan_complete(center_devs[idx].di, devices);
}
static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi,
return std_dev_clear(di, clear_helper);
}
-static int add_device(struct sr_dev_driver *di, int model,
- struct libusb_device_descriptor *des, const char *serial_num,
- const char *connection_id, libusb_device *usbdev, GSList **devices)
+static int add_device(int model, struct libusb_device_descriptor *des,
+ const char *serial_num, const char *connection_id, libusb_device *usbdev,
+ GSList **devices)
{
int ret;
unsigned int i;
struct sr_dev_inst *sdi;
- struct drv_context *drvc;
struct dev_context *devc;
ret = SR_OK;
- drvc = di->context;
-
/* Allocate memory for our private device context. */
devc = g_malloc0(sizeof(struct dev_context));
sdi->connection_id = g_strdup(connection_id);
sdi->conn = sr_usb_dev_inst_new(libusb_get_bus_number(usbdev),
libusb_get_device_address(usbdev), NULL);
- sdi->driver = di;
sdi->priv = devc;
for (i = 0; i < devc->prof->num_channels; i++)
cv_channel_names[i]);
*devices = g_slist_append(*devices, sdi);
- drvc->instances = g_slist_append(drvc->instances, sdi);
if (ret == SR_OK)
return SR_OK;
libusb_get_bus_number(devlist[i]),
libusb_get_device_address(devlist[i]), connection_id);
- if ((ret = add_device(di, model, &des, serial_num, connection_id,
+ if ((ret = add_device(model, &des, serial_num, connection_id,
devlist[i], &devices)) < 0) {
sr_dbg("Failed to add device: %d.", ret);
}
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)
static GSList *scan(struct sr_dev_driver *di, GSList *options)
{
- struct drv_context *drvc;
struct dev_context *devc;
struct sr_dev_inst *sdi;
struct sr_config *src;
GSList *devices, *l;
const char *conn, *serialcomm;
- drvc = di->context;
-
devices = NULL;
conn = serialcomm = NULL;
sdi->conn = sr_serial_dev_inst_new(conn, serialcomm);
sdi->inst_type = SR_INST_SERIAL;
sdi->priv = devc;
- sdi->driver = di;
sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "P1");
- drvc->instances = g_slist_append(drvc->instances, sdi);
devices = g_slist_append(devices, sdi);
- return devices;
+ return std_scan_complete(di, devices);
}
static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi,
sdi->model = g_strdup("DIGI 35 CPU");
sdi->conn = serial;
sdi->priv = NULL;
- sdi->driver = di;
sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "CH1");
- drvc->instances = g_slist_append(drvc->instances, sdi);
devices = g_slist_append(devices, sdi);
- return devices;
+ return std_scan_complete(di, devices);
}
static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi,
sdi = g_malloc0(sizeof(struct sr_dev_inst));
sdi->status = SR_ST_INACTIVE;
sdi->model = g_strdup("Demo device");
- sdi->driver = di;
devc = g_malloc0(sizeof(struct dev_context));
devc->cur_samplerate = SR_KHZ(200);
sdi->priv = devc;
devices = g_slist_append(devices, sdi);
- drvc->instances = g_slist_append(drvc->instances, sdi);
- return devices;
+ return std_scan_complete(di, devices);
}
static int dev_open(struct sr_dev_inst *sdi)
#include <libsigrok/libsigrok.h>
#include "libsigrok-internal.h"
-static void std_dev_attach(struct sr_dev_driver *di, struct sr_dev_inst *sdi)
-{
- struct drv_context *drvc;
-
- drvc = di->context;
-
- sdi->driver = di;
- drvc->instances = g_slist_append(drvc->instances, sdi);
-}
-
#define LOG_PREFIX "deree-de5000"
static int dev_clear(const struct sr_dev_driver *di)
if (!(sdi = es51919_serial_scan(options, "DER EE", "DE-5000")))
return NULL;
- std_dev_attach(di, sdi);
-
- return g_slist_append(NULL, sdi);
+ return std_scan_complete(di, g_slist_append(NULL, sdi));
}
static struct sr_dev_driver deree_de5000_driver_info = {
sdi->inst_type = SR_INST_SERIAL;
sdi->conn = serial;
sdi->priv = devc;
- sdi->driver = di;
sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "P1");
- drvc->instances = g_slist_append(drvc->instances, sdi);
devices = g_slist_append(devices, sdi);
break;
}
if (!devices)
sr_serial_dev_inst_free(serial);
- return devices;
+ return std_scan_complete(di, devices);
}
static GSList *scan(struct sr_dev_driver *di, GSList *options)
&ft232r_desc,
};
-static void scan_device(struct sr_dev_driver *di, struct ftdi_context *ftdic,
+static void scan_device(struct ftdi_context *ftdic,
struct libusb_device *dev, GSList **devices)
{
struct libusb_device_descriptor usb_desc;
struct dev_context *devc;
char *vendor, *model, *serial_num;
struct sr_dev_inst *sdi;
- struct drv_context *drvc;
int rv;
- drvc = di->context;
libusb_get_device_descriptor(dev, &usb_desc);
desc = NULL;
sdi->vendor = vendor;
sdi->model = model;
sdi->serial_num = serial_num;
- sdi->driver = di;
sdi->priv = devc;
sdi->connection_id = g_strdup_printf("d:%u/%u",
libusb_get_bus_number(dev), libusb_get_device_address(dev));
SR_CHANNEL_LOGIC, TRUE, *chan);
*devices = g_slist_append(*devices, sdi);
- drvc->instances = g_slist_append(drvc->instances, sdi);
return;
err_free_strings:
g_free(devc);
}
-static GSList *scan_all(struct ftdi_context *ftdic, struct sr_dev_driver *di,
- GSList *options)
+static GSList *scan_all(struct ftdi_context *ftdic, GSList *options)
{
GSList *devices;
struct ftdi_device_list *devlist = 0;
curdev = devlist;
while (curdev) {
- scan_device(di, ftdic, curdev->dev, &devices);
+ scan_device(ftdic, curdev->dev, &devices);
curdev = curdev->next;
}
usb = l->data;
if (usb->bus == libusb_get_bus_number(devlist[i])
&& usb->address == libusb_get_device_address(devlist[i])) {
- scan_device(di, ftdic, devlist[i], &devices);
+ scan_device(ftdic, devlist[i], &devices);
}
}
}
libusb_free_device_list(devlist, 1);
} else
- devices = scan_all(ftdic, di, options);
+ devices = scan_all(ftdic, options);
ftdi_free(ftdic);
- return devices;
+ return std_scan_complete(di, devices);
}
static void clear_helper(void *priv)
sdi->vendor = g_strdup(prof->vendor);
sdi->model = g_strdup(prof->model);
sdi->version = g_strdup(prof->model_version);
- sdi->driver = di;
sdi->serial_num = g_strdup(serial_num);
sdi->connection_id = g_strdup(connection_id);
if ((prof->dev_caps & DEV_CAPS_16BIT) || (prof->dev_caps & DEV_CAPS_AX_ANALOG))
devc->sample_wide = TRUE;
sdi->priv = devc;
- drvc->instances = g_slist_append(drvc->instances, sdi);
devices = g_slist_append(devices, sdi);
if (!strcmp(prof->model, "DSLogic")
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 void clear_dev_context(void *priv)
devc->settings_ok = FALSE;
sdi->conn = serial;
sdi->priv = devc;
- sdi->driver = di;
sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "P1");
- drvc->instances = g_slist_append(drvc->instances, sdi);
devices = g_slist_append(devices, sdi);
}
- return devices;
+ return std_scan_complete(di, devices);
}
/**
sdi->version = g_strdup_printf("Firmware %d.%d", devc->fw_ver_maj, devc->fw_ver_min);
sdi->conn = serial;
sdi->priv = devc;
- sdi->driver = di;
sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "P1");
- drvc->instances = g_slist_append(drvc->instances, sdi);
devices = g_slist_append(devices, sdi);
devc = g_malloc0(sizeof(struct dev_context));
sdi = g_malloc0(sizeof(struct sr_dev_inst));
sr_dev_inst_free(sdi);
}
- return devices;
+ return std_scan_complete(di, devices);
exit_err:
sr_info("scan_2x_bd232(): Error!");
static int dev_acquisition_stop(struct sr_dev_inst *sdi);
-static struct sr_dev_inst *hantek_6xxx_dev_new(struct sr_dev_driver *di,
- const struct hantek_6xxx_profile *prof)
+static struct sr_dev_inst *hantek_6xxx_dev_new(const struct hantek_6xxx_profile *prof)
{
struct sr_dev_inst *sdi;
struct sr_channel *ch;
struct sr_channel_group *cg;
- struct drv_context *drvc;
struct dev_context *devc;
unsigned int i;
sdi->status = SR_ST_INITIALIZING;
sdi->vendor = g_strdup(prof->vendor);
sdi->model = g_strdup(prof->model);
- sdi->driver = di;
for (i = 0; i < ARRAY_SIZE(channel_names); i++) {
ch = sr_channel_new(sdi, i, SR_CHANNEL_ANALOG, TRUE, channel_names[i]);
devc->samplerate = DEFAULT_SAMPLERATE;
sdi->priv = devc;
- drvc = sdi->driver->context;
- drvc->instances = g_slist_append(drvc->instances, sdi);
return sdi;
}
/* Device matches the pre-firmware profile. */
prof = &dev_profiles[j];
sr_dbg("Found a %s %s.", prof->vendor, prof->model);
- sdi = hantek_6xxx_dev_new(di, prof);
+ sdi = hantek_6xxx_dev_new(prof);
sdi->connection_id = g_strdup(connection_id);
devices = g_slist_append(devices, sdi);
devc = sdi->priv;
/* Device matches the post-firmware profile. */
prof = &dev_profiles[j];
sr_dbg("Found a %s %s.", prof->vendor, prof->model);
- sdi = hantek_6xxx_dev_new(di, prof);
+ sdi = hantek_6xxx_dev_new(prof);
sdi->connection_id = g_strdup(connection_id);
sdi->status = SR_ST_INACTIVE;
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)
static int dev_acquisition_stop(struct sr_dev_inst *sdi);
-static struct sr_dev_inst *dso_dev_new(struct sr_dev_driver *di,
- 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_channel *ch;
struct sr_channel_group *cg;
- struct drv_context *drvc;
struct dev_context *devc;
unsigned int i;
sdi->status = SR_ST_INITIALIZING;
sdi->vendor = g_strdup(prof->vendor);
sdi->model = g_strdup(prof->model);
- sdi->driver = di;
/*
* Add only the real channels -- EXT isn't a source of data, only
devc->triggersource = g_strdup(DEFAULT_TRIGGER_SOURCE);
devc->triggerposition = DEFAULT_HORIZ_TRIGGERPOS;
sdi->priv = devc;
- drvc = di->context;
- drvc->instances = g_slist_append(drvc->instances, sdi);
return sdi;
}
/* Device matches the pre-firmware profile. */
prof = &dev_profiles[j];
sr_dbg("Found a %s %s.", prof->vendor, prof->model);
- sdi = dso_dev_new(di, prof);
+ sdi = dso_dev_new(prof);
sdi->connection_id = g_strdup(connection_id);
devices = g_slist_append(devices, sdi);
devc = sdi->priv;
/* Device matches the post-firmware profile. */
prof = &dev_profiles[j];
sr_dbg("Found a %s %s.", prof->vendor, prof->model);
- sdi = dso_dev_new(di, prof);
+ sdi = dso_dev_new(prof);
sdi->connection_id = g_strdup(connection_id);
sdi->status = SR_ST_INACTIVE;
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)
0x00, 0x08, 0x04
};
-static GSList *scan_port(GSList *devices, struct sr_dev_driver *di,
- struct parport *port)
+static GSList *scan_port(GSList *devices, struct parport *port)
{
struct sr_dev_inst *sdi;
struct sr_channel *ch;
struct sr_channel_group *cg;
struct dev_context *devc;
- struct drv_context *drvc;
int i;
if (ieee1284_open(port, 0, &i) != E1284_OK) {
sdi->status = SR_ST_INACTIVE;
sdi->vendor = g_strdup("Hung-Chang");
sdi->model = g_strdup("DSO-2100");
- sdi->driver = di;
- drvc = di->context;
sdi->inst_type = 0; /* FIXME */
sdi->conn = port;
ieee1284_ref(port);
devc->last_step = 0; /* buffersize = 1000 */
sdi->priv = devc;
- drvc->instances = g_slist_append(drvc->instances, sdi);
devices = g_slist_append(devices, sdi);
fail3:
for (i = 0; i < ports.portc; i++)
if (!strcmp(ports.portv[i]->name, conn)) {
port_found = TRUE;
- devices = scan_port(devices, di, ports.portv[i]);
+ devices = scan_port(devices, ports.portv[i]);
}
if (!port_found) {
ieee1284_free_ports(&ports);
- return devices;
+ return std_scan_complete(di, devices);
}
static void clear_private(void *priv)
sdi->version = g_strdup_printf("%u.%u", dev_info.fw_ver_major, dev_info.fw_ver_minor);
sdi->serial_num = g_strdup_printf("%d", dev_info.serial);
sdi->priv = devc;
- sdi->driver = di;
sdi->inst_type = SR_INST_USB;
sdi->conn = usb;
devc->xfer_data_out = devc->xfer_buf_out +
LIBUSB_CONTROL_SETUP_SIZE;
- drvc->instances = g_slist_append(drvc->instances, sdi);
devices = g_slist_append(devices, sdi);
}
g_slist_free(usb_devices);
- return devices;
+ return std_scan_complete(di, devices);
}
static void clear_dev_context(void *priv)
sdi->status = SR_ST_INACTIVE;
sdi->vendor = g_strdup(USB_VENDOR_NAME);
sdi->model = g_strdup(USB_MODEL_NAME);
- sdi->driver = di;
sdi->priv = devc;
for (i = 0; i < ARRAY_SIZE(channel_names); i++)
sr_channel_new(sdi, i, SR_CHANNEL_LOGIC, TRUE, channel_names[i]);
devices = g_slist_append(devices, sdi);
- drvc->instances = g_slist_append(drvc->instances, sdi);
/* Close device. We'll reopen it again when we need it. */
scanaplus_close(devc);
- return devices;
+ return std_scan_complete(di, devices);
scanaplus_close(devc);
err_free_ftdic:
sdi->status = SR_ST_INACTIVE;
sdi->vendor = g_strdup(VENDOR);
sdi->model = model; /* Already g_strndup()'d. */
- sdi->driver = di;
sdi->inst_type = SR_INST_USB;
sdi->conn = l->data;
sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "SPL");
/* TODO: Set date/time? */
- drvc->instances = g_slist_append(drvc->instances, sdi);
devices = g_slist_append(devices, sdi);
}
g_slist_free(usb_devices);
} else
g_slist_free_full(usb_devices, g_free);
- return devices;
+ return std_scan_complete(di, devices);
}
static int dev_open(struct sr_dev_inst *sdi)
GSList *l, *devices;
const char *conn, *serialcomm;
struct sr_dev_inst *sdi;
- struct drv_context *drvc;
struct dev_context *devc;
struct sr_serial_dev_inst *serial;
int ret;
sr_info("Probing serial port %s.", conn);
- drvc = di->context;
devices = NULL;
serial_flush(serial);
sdi->inst_type = SR_INST_SERIAL;
sdi->conn = serial;
sdi->priv = devc;
- sdi->driver = di;
sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "Mass");
- drvc->instances = g_slist_append(drvc->instances, sdi);
devices = g_slist_append(devices, sdi);
scan_cleanup:
serial_close(serial);
- return devices;
+ return std_scan_complete(di, devices);
}
static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi,
static GSList *scan(struct sr_dev_driver *di, GSList *options)
{
- struct drv_context *drvc;
struct dev_context *devc;
GSList *devices, *l;
struct sr_dev_inst *sdi;
devices = NULL;
conn = NULL;
serialcomm = NULL;
- drvc = di->context;
for (l = options; l; l = l->next) {
src = l->data;
sdi->model = g_strdup(models[model_id].name);
sdi->inst_type = SR_INST_SERIAL;
sdi->conn = serial;
- sdi->driver = di;
sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "CH1");
/* Get current status of device. */
if (korad_kaxxxxp_get_all_values(serial, devc) < 0)
goto exit_err;
- drvc->instances = g_slist_append(drvc->instances, sdi);
devices = g_slist_append(devices, sdi);
serial_close(serial);
if (!devices)
sr_serial_dev_inst_free(serial);
- return devices;
+ return std_scan_complete(di, devices);
exit_err:
sr_dev_inst_free(sdi);
}
sdi->inst_type = SR_INST_USB;
sdi->conn = usb;
- drvc->instances = g_slist_append(drvc->instances, sdi);
devices = g_slist_append(devices, sdi);
}
g_slist_free(usb_devices);
} else
g_slist_free_full(usb_devices, g_free);
- return devices;
+ return std_scan_complete(di, devices);
}
static int dev_open(struct sr_dev_inst *sdi)
sdi->vendor = g_strdup(LASCAR_VENDOR);
sdi->model = g_strdup(profile->modelname);
sdi->version = g_strdup(firmware);
- sdi->driver = di;
if (profile->logformat == LOG_TEMP_RH) {
/* Model this as two channels: temperature and humidity. */
SR_MHZ(500),
};
-static struct sr_dev_inst *create_device(struct sr_dev_driver *di,
- struct sr_usb_dev_inst *usb, enum sr_dev_inst_status status,
- int64_t fw_updated)
+static struct sr_dev_inst *create_device(struct sr_usb_dev_inst *usb,
+ enum sr_dev_inst_status status, int64_t fw_updated)
{
struct sr_dev_inst *sdi;
struct dev_context *devc;
sdi->status = status;
sdi->vendor = g_strdup("LeCroy");
sdi->model = g_strdup("LogicStudio16");
- sdi->driver = di;
sdi->inst_type = SR_INST_USB;
sdi->conn = usb;
usb = sr_usb_dev_inst_new(libusb_get_bus_number(devlist[i]),
libusb_get_device_address(devlist[i]), NULL);
- sdi = create_device(di, usb, SR_ST_INACTIVE, 0);
+ sdi = create_device(usb, SR_ST_INACTIVE, 0);
break;
case LOGICSTUDIO16_PID_LACK_FIRMWARE:
r = ezusb_upload_firmware(drvc->sr_ctx, devlist[i],
usb = sr_usb_dev_inst_new(libusb_get_bus_number(devlist[i]),
UNKNOWN_ADDRESS, NULL);
- sdi = create_device(di, usb, SR_ST_INITIALIZING,
+ sdi = create_device(usb, SR_ST_INITIALIZING,
g_get_monotonic_time());
break;
default:
sdi->connection_id = g_strdup(connection_id);
- 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 open_device(struct sr_dev_inst *sdi)
sdi->vendor = g_strdup(manufacturer);
sdi->model = g_strdup(product);
sdi->version = g_strdup(hwrev);
- sdi->driver = di;
sdi->priv = devc;
for (i = 0; i < ARRAY_SIZE(channel_names); i++) {
chtype = (i == 0) ? SR_CHANNEL_ANALOG : SR_CHANNEL_LOGIC;
sr_channel_new(sdi, i, chtype, TRUE, channel_names[i]);
}
-
- //Add the driver
- struct drv_context *drvc = di->context;
- drvc->instances = g_slist_append(drvc->instances, sdi);
- devices = g_slist_append(devices, sdi);
}
- return devices;
+ return std_scan_complete(di, devices);
}
static int dev_open(struct sr_dev_inst *sdi)
static GSList *scan(struct sr_dev_driver *di, GSList *options)
{
int i, model_id;
- struct drv_context *drvc;
struct dev_context *devc;
struct sr_dev_inst *sdi;
struct sr_config *src;
struct sr_serial_dev_inst *serial;
char reply[50], **tokens, *dummy;
- drvc = di->context;
devices = NULL;
conn = NULL;
serialcomm = NULL;
sdi->model = g_strdup(models[model_id].name);
sdi->inst_type = SR_INST_SERIAL;
sdi->conn = serial;
- sdi->driver = di;
sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "CH1");
devc->voltage_max_device = g_strtod(tokens[0], &dummy) * devc->model->voltage[2];
g_strfreev(tokens);
- drvc->instances = g_slist_append(drvc->instances, sdi);
devices = g_slist_append(devices, sdi);
serial_close(serial);
if (!devices)
sr_serial_dev_inst_free(serial);
- return devices;
+ return std_scan_complete(di, devices);
exit_err:
sr_dev_inst_free(sdi);
static GSList *mic_scan(const char *conn, const char *serialcomm, int idx)
{
struct sr_dev_inst *sdi;
- struct drv_context *drvc;
struct dev_context *devc;
struct sr_serial_dev_inst *serial;
GSList *devices;
if (serial_open(serial, SERIAL_RDWR) != SR_OK)
return NULL;
- drvc = mic_devs[idx].di->context;
devices = NULL;
serial_flush(serial);
sdi->inst_type = SR_INST_SERIAL;
sdi->conn = serial;
sdi->priv = devc;
- sdi->driver = mic_devs[idx].di;
sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "Temperature");
if (mic_devs[idx].has_humidity)
sr_channel_new(sdi, 1, SR_CHANNEL_ANALOG, TRUE, "Humidity");
- drvc->instances = g_slist_append(drvc->instances, sdi);
devices = g_slist_append(devices, sdi);
serial_close(serial);
- return devices;
+ return std_scan_complete(mic_devs[idx].di, devices);
}
static GSList *scan(GSList *options, int idx)
static GSList *do_scan(lps_modelid modelid, struct sr_dev_driver *drv, GSList *options)
{
struct sr_dev_inst *sdi;
- struct drv_context *drvc;
struct dev_context *devc;
struct sr_serial_dev_inst *serial;
struct sr_channel *ch;
conn = serialcomm = NULL;
devices = NULL;
- drvc = drv->context;
-
sr_spew("scan() called!");
/* Process and check options. */
sdi->vendor = g_strdup(VENDOR_MOTECH);
sdi->model = g_strdup(models[modelid].modelstr);
sdi->version = g_strdup(verstr);
- sdi->driver = drv;
sdi->inst_type = SR_INST_SERIAL;
sdi->conn = serial;
sdi->channel_groups = g_slist_append(sdi->channel_groups, cg);
}
- drvc->instances = g_slist_append(drvc->instances, sdi);
devices = g_slist_append(devices, sdi);
/* Query status */
if (!devices)
sr_serial_dev_inst_free(serial);
- return devices;
+ return std_scan_complete(drv, devices);
exit_err:
sr_info("%s: Error!", __func__);
static GSList *scan(struct sr_dev_driver *drv, GSList *options)
{
struct sr_dev_inst *sdi;
- struct drv_context *drvc;
struct dev_context *devc;
struct sr_config *src;
struct sr_serial_dev_inst *serial;
char req[10];
devices = NULL;
- drvc = drv->context;
conn = serialcomm = NULL;
for (l = options; l; l = l->next) {
devc->version = g_strdup(&buf[9]);
sdi->conn = serial;
sdi->priv = devc;
- sdi->driver = drv;
sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "P1");
- drvc->instances = g_slist_append(drvc->instances, sdi);
devices = g_slist_append(devices, sdi);
break;
}
if (!devices)
sr_serial_dev_inst_free(serial);
- return devices;
+ return std_scan_complete(drv, devices);
}
static int dev_close(struct sr_dev_inst *sdi)
{
struct sr_config *src;
struct sr_dev_inst *sdi;
- struct drv_context *drvc;
struct sr_serial_dev_inst *serial;
GSList *l, *devices;
int ret;
const char *conn, *serialcomm;
char buf[8];
- drvc = di->context;
-
devices = NULL;
conn = serialcomm = NULL;
sdi->vendor = g_strdup("Sump");
sdi->model = g_strdup("Logic Analyzer");
sdi->version = g_strdup("v1.0");
- sdi->driver = di;
for (i = 0; i < ARRAY_SIZE(ols_channel_names); i++)
sr_channel_new(sdi, i, SR_CHANNEL_LOGIC, TRUE,
ols_channel_names[i]);
sdi->inst_type = SR_INST_SERIAL;
sdi->conn = serial;
- drvc->instances = g_slist_append(drvc->instances, sdi);
devices = g_slist_append(devices, sdi);
serial_close(serial);
- return devices;
+ return std_scan_complete(di, devices);
}
static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
return SR_OK;
}
-SR_PRIV struct sr_dev_driver ols_driver_info = {
+static struct sr_dev_driver ols_driver_info = {
.name = "ols",
.longname = "Openbench Logic Sniffer",
.api_version = 1,
#include <config.h>
#include "protocol.h"
-extern SR_PRIV struct sr_dev_driver ols_driver_info;
-
SR_PRIV int send_shortcommand(struct sr_serial_dev_inst *serial,
uint8_t command)
{
sdi = g_malloc0(sizeof(struct sr_dev_inst));
sdi->status = SR_ST_INACTIVE;
- sdi->driver = &ols_driver_info;
devc = ols_dev_new();
sdi->priv = devc;
static GSList *scan(struct sr_dev_driver *di, GSList *options)
{
- struct drv_context *drvc;
struct dev_context *devc;
struct sr_config *src;
struct sr_serial_dev_inst *serial;
return NULL;
devices = NULL;
- drvc = di->context;
sdi = g_malloc0(sizeof(struct sr_dev_inst));
sdi->status = SR_ST_INACTIVE;
sdi->conn = sr_serial_dev_inst_new(conn, SERIALCOMM);
sdi->inst_type = SR_INST_SERIAL;
sdi->priv = devc;
- sdi->driver = di;
sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "SPL");
- drvc->instances = g_slist_append(drvc->instances, sdi);
devices = g_slist_append(devices, sdi);
serial_close(serial);
- return devices;
+ return std_scan_complete(di, devices);
}
static int dev_clear(const struct sr_dev_driver *di)
static GSList *scan(struct sr_dev_driver *di, GSList *options)
{
struct sr_dev_inst *sdi;
- struct drv_context *drvc;
struct dev_context *devc;
GSList *devices;
int ret, i;
(void)options;
- drvc = di->context;
-
devices = NULL;
/* Allocate memory for our private device context. */
sr_dbg("Failed to set default samplerate (%"PRIu64").",
DEFAULT_SAMPLERATE);
- drvc->instances = g_slist_append(drvc->instances, sdi);
devices = g_slist_append(devices, sdi);
- return devices;
+ return std_scan_complete(di, devices);
err_close_ftdic:
p_ols_close(devc);
#include <config.h>
#include "protocol.h"
-extern SR_PRIV struct sr_dev_driver p_ols_driver_info;
-
SR_PRIV int write_shortcommand(struct dev_context *devc, uint8_t command)
{
uint8_t buf[1];
sdi = g_malloc0(sizeof(struct sr_dev_inst));
sdi->status = SR_ST_INACTIVE;
- sdi->driver = &p_ols_driver_info;
sdi->priv = devc;
devname = g_string_new("");
sdi->status = SR_ST_INITIALIZING;
sdi->vendor = g_strdup("Saleae");
sdi->model = g_strdup("Logic16");
- sdi->driver = di;
sdi->connection_id = g_strdup(connection_id);
for (j = 0; j < ARRAY_SIZE(channel_names); j++)
devc = g_malloc0(sizeof(struct dev_context));
devc->selected_voltage_range = VOLTAGE_RANGE_18_33_V;
sdi->priv = devc;
- drvc->instances = g_slist_append(drvc->instances, sdi);
devices = g_slist_append(devices, sdi);
if (check_conf_profile(devlist[i])) {
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 logic16_dev_open(struct sr_dev_inst *sdi)
GSList *l, *devices;
const char *conn, *serialcomm;
struct sr_dev_inst *sdi;
- struct drv_context *drvc;
struct dev_context *devc;
struct sr_serial_dev_inst *serial;
int dropped, ret;
sr_info("Probing serial port %s.", conn);
- drvc = di->context;
devices = NULL;
serial_flush(serial);
sdi->inst_type = SR_INST_SERIAL;
sdi->conn = serial;
sdi->priv = devc;
- sdi->driver = di;
sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "P1");
- drvc->instances = g_slist_append(drvc->instances, sdi);
devices = g_slist_append(devices, sdi);
scan_cleanup:
serial_close(serial);
- return devices;
+ return std_scan_complete(di, devices);
}
static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi,
continue; /* no match */
/* Register device instance with driver. */
- sdi->driver = di;
- 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);
}
/* Destroy the private device context.
static GSList *scan(struct sr_dev_driver *di, GSList *options)
{
- struct drv_context *drvc;
struct dev_context *devc;
struct sr_serial_dev_inst *serial;
struct sr_dev_inst *sdi;
sr_info("Probing serial port %s.", conn);
- drvc = di->context;
serial_flush(serial);
/* Let's get a bit of data and see if we can find a packet. */
sdi->inst_type = SR_INST_SERIAL;
sdi->conn = serial;
sdi->priv = devc;
- sdi->driver = di;
sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "P");
sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "IINST");
sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "PAPP");
- drvc->instances = g_slist_append(drvc->instances, sdi);
devices = g_slist_append(devices, sdi);
scan_cleanup:
serial_close(serial);
- return devices;
+ return std_scan_complete(di, devices);
}
static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi,
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)
sdi->conn = serial;
sdi->priv = devc;
- sdi->driver = di;
sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "P1");
- drvc->instances = g_slist_append(drvc->instances, sdi);
devices = g_slist_append(devices, sdi);
- return devices;
+ return std_scan_complete(di, devices);
}
static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi,
sdi->vendor = g_strdup(dmm->vendor);
sdi->model = g_strdup(dmm->device);
sdi->priv = devc;
- sdi->driver = di;
sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "P1");
sdi->inst_type = SR_INST_USB;
sdi->conn = usb;
- drvc->instances = g_slist_append(drvc->instances, sdi);
devices = g_slist_append(devices, sdi);
}
- return devices;
+ return std_scan_complete(di, devices);
}
static int dev_open(struct sr_dev_inst *sdi)
sdi->status = SR_ST_INACTIVE;
sdi->vendor = g_strdup(VENDOR);
sdi->model = g_strdup(MODEL);
- sdi->driver = di;
sdi->inst_type = SR_INST_USB;
sdi->conn = l->data;
for (i = 0; i < ARRAY_SIZE(channel_names); i++)
sdi->priv = devc;
devc->limit_samples = 0;
devc->data_source = DEFAULT_DATA_SOURCE;
- drvc->instances = g_slist_append(drvc->instances, sdi);
devices = g_slist_append(devices, sdi);
}
g_slist_free(usb_devices);
} else
g_slist_free_full(usb_devices, g_free);
- return devices;
+ return std_scan_complete(di, devices);
}
static int dev_open(struct sr_dev_inst *sdi)
sdi = g_malloc0(sizeof(struct sr_dev_inst));
sdi->status = SR_ST_INACTIVE;
sdi->vendor = g_strdup(VICTOR_VENDOR);
- sdi->driver = di;
sdi->connection_id = g_strdup(connection_id);
devc = g_malloc0(sizeof(struct dev_context));
sr_sw_limits_init(&devc->limits);
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)
sdi->status = SR_ST_INACTIVE;
sdi->vendor = g_strdup(VENDOR_NAME);
sdi->model = g_strdup(prof->model_name);
- sdi->driver = di;
sdi->serial_num = g_strdup(serial_num);
sdi->connection_id = g_strdup(connection_id);
channel_names[j]);
devices = g_slist_append(devices, sdi);
- drvc->instances = g_slist_append(drvc->instances, sdi);
sdi->inst_type = SR_INST_USB;
sdi->conn = sr_usb_dev_inst_new(
libusb_get_bus_number(devlist[i]),
}
libusb_free_device_list(devlist, 1);
- return devices;
+ return std_scan_complete(di, devices);
}
static int dev_open(struct sr_dev_inst *sdi)
std_dev_clear_callback clear_private);
SR_PRIV GSList *std_dev_list(const struct sr_dev_driver *di);
SR_PRIV int std_serial_dev_close(struct sr_dev_inst *sdi);
+SR_PRIV GSList *std_scan_complete(struct sr_dev_driver *di, GSList *devices);
/*--- resource.c ------------------------------------------------------------*/
return drvc->instances;
}
+
+/**
+ * Standard scan() callback API helper.
+ *
+ * This function can be used to perform common tasks required by a driver's
+ * scan() callback. It will initialize the driver for each device on the list
+ * and add the devices on the list to the driver's device instance list.
+ * Usually it should be used as the last step in the scan() callback, right
+ * before returning.
+ *
+ * Note: This function can only be used if std_init() has been called
+ * previously by the driver.
+ *
+ * Example:
+ * @code{c}
+ * static GSList *scan(struct sr_dev_driver *di, GSList *options)
+ * {
+ * struct GSList *device;
+ * struct sr_dev_inst *sdi;
+ *
+ * sdi = g_new0(sr_dev_inst, 1);
+ * sdi->vendor = ...;
+ * ...
+ * devices = g_slist_append(devices, sdi);
+ * ...
+ * return std_scan_complete(di, devices);
+ * }
+ * @endcode
+ *
+ * @param di The driver instance to use.
+ * @param devices List of newly discovered devices (struct sr_dev_inst).
+ *
+ * @return The @p devices list.
+ */
+SR_PRIV GSList *std_scan_complete(struct sr_dev_driver *di, GSList *devices)
+{
+ struct drv_context *drvc = di->context;
+ GSList *l;
+
+ for (l = devices; l; l = l->next) {
+ struct sr_dev_inst *sdi = l->data;
+ sdi->driver = di;
+ }
+
+ drvc->instances = g_slist_concat(drvc->instances, g_slist_copy(devices));
+
+ return devices;
+}