24 #include "libsigrok-internal.h"
27 #define LOG_PREFIX "device"
69 ch->
name = g_strdup(name);
71 sdi->channels = g_slist_append(sdi->channels, ch);
96 g_free(channel->
name);
97 channel->
name = g_strdup(name);
117 gboolean was_enabled;
118 struct sr_dev_inst *sdi;
124 was_enabled = channel->
enabled;
126 if (!state != !was_enabled && sdi->driver
127 && sdi->driver->config_channel_set) {
128 ret = sdi->driver->config_channel_set(
129 sdi, channel, SR_CHANNEL_SET_ENABLED);
140 SR_PRIV struct sr_channel *sr_next_enabled_channel(
const struct sr_dev_inst *sdi,
147 next_channel = cur_channel;
149 l = g_slist_find(sdi->channels, next_channel);
151 next_channel = l->next->data;
153 next_channel = sdi->channels->data;
154 }
while (!next_channel->
enabled);
183 if (!sdi || !sdi->driver || !sdi->driver->config_list)
186 if (sdi->driver->config_list(SR_CONF_DEVICE_OPTIONS,
187 &gvar, sdi, NULL) !=
SR_OK)
191 devopts = g_variant_get_fixed_array(gvar, &num_opts,
sizeof(int32_t));
192 for (i = 0; i < num_opts; i++) {
193 if ((devopts[i] & SR_CONF_MASK) == key) {
198 g_variant_unref(gvar);
222 const uint32_t *opts;
230 if (sdi && sdi->driver != driver)
236 opts = g_variant_get_fixed_array(gvar, &num_opts,
sizeof(uint32_t));
238 result = g_array_sized_new(FALSE, FALSE,
sizeof(uint32_t), num_opts);
240 for (i = 0; i < num_opts; i++) {
241 opt = opts[i] & SR_CONF_MASK;
242 g_array_insert_val(result, i, opt);
245 g_variant_unref(gvar);
276 if (!sdi || !sdi->driver || !sdi->driver->config_list)
279 if (sdi->driver->config_list(SR_CONF_DEVICE_OPTIONS,
280 &gvar, sdi, cg) !=
SR_OK)
284 devopts = g_variant_get_fixed_array(gvar, &num_opts,
sizeof(int32_t));
285 for (i = 0; i < num_opts; i++) {
286 if ((devopts[i] & SR_CONF_MASK) == key) {
287 ret = devopts[i] & ~SR_CONF_MASK;
291 g_variant_unref(gvar);
307 const char *model,
const char *version)
309 struct sr_dev_inst *sdi;
311 sdi = g_malloc0(
sizeof(
struct sr_dev_inst));
313 sdi->vendor = g_strdup(vendor);
314 sdi->model = g_strdup(model);
315 sdi->version = g_strdup(version);
333 if (!sdi || sdi->inst_type !=
SR_INST_USER || index < 0)
336 sr_channel_new(sdi, index, type, TRUE, name);
348 SR_PRIV void sr_dev_inst_free(
struct sr_dev_inst *sdi)
357 for (l = sdi->channels; l; l = l->next) {
363 g_slist_free(sdi->channels);
365 for (l = sdi->channel_groups; l; l = l->next) {
372 g_slist_free(sdi->channel_groups);
379 g_free(sdi->version);
380 g_free(sdi->serial_num);
381 g_free(sdi->connection_id);
385 #ifdef HAVE_LIBUSB_1_0
398 SR_PRIV struct sr_usb_dev_inst *sr_usb_dev_inst_new(uint8_t bus,
399 uint8_t address,
struct libusb_device_handle *hdl)
401 struct sr_usb_dev_inst *udi;
403 udi = g_malloc0(
sizeof(
struct sr_usb_dev_inst));
405 udi->address = address;
419 SR_PRIV void sr_usb_dev_inst_free(
struct sr_usb_dev_inst *usb)
426 #ifdef HAVE_LIBSERIALPORT
447 SR_PRIV struct sr_serial_dev_inst *sr_serial_dev_inst_new(
const char *port,
448 const char *serialcomm)
450 struct sr_serial_dev_inst *serial;
452 serial = g_malloc0(
sizeof(
struct sr_serial_dev_inst));
453 serial->port = g_strdup(port);
455 serial->serialcomm = g_strdup(serialcomm);
468 SR_PRIV void sr_serial_dev_inst_free(
struct sr_serial_dev_inst *serial)
473 g_free(serial->port);
474 g_free(serial->serialcomm);
480 SR_PRIV struct sr_usbtmc_dev_inst *sr_usbtmc_dev_inst_new(
const char *device)
482 struct sr_usbtmc_dev_inst *usbtmc;
484 usbtmc = g_malloc0(
sizeof(
struct sr_usbtmc_dev_inst));
485 usbtmc->device = g_strdup(device);
492 SR_PRIV void sr_usbtmc_dev_inst_free(
struct sr_usbtmc_dev_inst *usbtmc)
497 g_free(usbtmc->device);
535 sr_err(
"Invalid driver.");
542 ret = std_dev_clear(driver, NULL);
560 if (!sdi || !sdi->driver || !sdi->driver->dev_open)
563 ret = sdi->driver->dev_open(sdi);
581 if (!sdi || !sdi->driver || !sdi->driver->dev_close)
584 ret = sdi->driver->dev_close(sdi);
598 if (!sdi || !sdi->driver)
661 return sdi->serial_num;
674 #ifdef HAVE_LIBUSB_1_0
675 struct drv_context *drvc;
677 char connection_id[64];
678 struct sr_usb_dev_inst *usb;
679 struct libusb_device **devlist;
685 #ifdef HAVE_LIBSERIALPORT
686 struct sr_serial_dev_inst *serial;
688 if ((!sdi->connection_id) && (sdi->inst_type ==
SR_INST_SERIAL)) {
692 ((
struct sr_dev_inst *)sdi)->connection_id = g_strdup(serial->port);
696 #ifdef HAVE_LIBUSB_1_0
697 if ((!sdi->connection_id) && (sdi->inst_type ==
SR_INST_USB)) {
700 drvc = sdi->driver->context;
703 if ((cnt = libusb_get_device_list(drvc->sr_ctx->libusb_ctx, &devlist)) < 0) {
704 sr_err(
"Failed to retrieve device list: %s.",
705 libusb_error_name(cnt));
709 for (i = 0; i < cnt; i++) {
711 b = libusb_get_bus_number(devlist[i]);
712 a = libusb_get_device_address(devlist[i]);
713 if (b != usb->bus || a != usb->address)
716 usb_get_port_path(devlist[i], connection_id,
sizeof(connection_id));
717 ((
struct sr_dev_inst *)sdi)->connection_id = g_strdup(connection_id);
721 libusb_free_device_list(devlist, 1);
725 return sdi->connection_id;
740 return sdi->channels;
755 return sdi->channel_groups;
Generic/unspecified error.
const char * sr_dev_inst_sernum_get(const struct sr_dev_inst *sdi)
Queries a device instances' serial number.
void * priv
Private data for driver use.
int sr_dev_open(struct sr_dev_inst *sdi)
Open the specified device.
int sr_dev_clear(const struct sr_dev_driver *driver)
Clear the list of device instances a driver knows about.
gboolean enabled
Is this channel enabled?
GSList * sr_dev_inst_channels_get(const struct sr_dev_inst *sdi)
Queries a device instances' channel list.
int sr_dev_channel_enable(struct sr_channel *channel, gboolean state)
Enable or disable a channel.
const char * sr_dev_inst_model_get(const struct sr_dev_inst *sdi)
Queries a device instances' model.
The public libsigrok header file to be used by frontends.
GSList * channels
List of sr_channel structs of the channels belonging to this group.
struct sr_dev_inst * sr_dev_inst_user_new(const char *vendor, const char *model, const char *version)
Allocate and init a new user-generated device instance.
GSList *(* dev_list)(const struct sr_dev_driver *driver)
Get list of device instances the driver knows about.
const char * sr_dev_inst_vendor_get(const struct sr_dev_inst *sdi)
Queries a device instances' vendor.
int sr_dev_config_capabilities_list(const struct sr_dev_inst *sdi, const struct sr_channel_group *cg, const int key)
Enumerate the configuration capabilities supported by a device instance for a given configuration key...
void * priv
Private data for driver use.
Device-instance type for user-created "devices".
int sr_dev_channel_name_set(struct sr_channel *channel, const char *name)
Set the name of the specified channel.
const char * sr_dev_inst_connid_get(const struct sr_dev_inst *sdi)
Queries a device instances' connection identifier.
int(* config_list)(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
List all possible values for a configuration key in a device instance.
const char * sr_dev_inst_version_get(const struct sr_dev_inst *sdi)
Queries a device instances' version.
int(* dev_clear)(const struct sr_dev_driver *driver)
Clear list of devices the driver knows about.
Structure for groups of channels that have common properties.
Device instance type for serial port devices.
int type
Channel type (SR_CHANNEL_LOGIC, ...)
GSList * sr_dev_list(const struct sr_dev_driver *driver)
Get the list of devices/instances of the specified driver.
int sr_dev_inst_channel_add(struct sr_dev_inst *sdi, int index, int type, const char *name)
Add a new channel to the specified device instance.
char * name
Name of the channel group.
char * name
Name of channel.
GArray * sr_dev_options(const struct sr_dev_driver *driver, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
Enumerate the configuration options of the specified item.
struct sr_dev_driver * sr_dev_inst_driver_get(const struct sr_dev_inst *sdi)
Queries a device instances' driver.
struct sr_dev_inst * sdi
The device this channel is attached to.
int index
The index of this channel, starting at 0.
Device instance type for USB devices.
GSList * sr_dev_inst_channel_groups_get(const struct sr_dev_inst *sdi)
Queries a device instances' channel groups list.
Information on single channel.
gboolean sr_dev_has_option(const struct sr_dev_inst *sdi, int key)
Determine whether the specified device instance has the specified capability.
int sr_dev_close(struct sr_dev_inst *sdi)
Close the specified device.
int sr_session_dev_remove(struct sr_session *session, struct sr_dev_inst *sdi)
Remove a device instance from a session.