25 #include "libsigrok-internal.h" 29 #define LOG_PREFIX "device" 65 ch = g_malloc0(
sizeof(*ch));
71 ch->
name = g_strdup(name);
73 sdi->channels = g_slist_append(sdi->channels, ch);
99 SR_PRIV void sr_channel_free_cb(
void *p)
126 g_free(channel->
name);
127 channel->
name = g_strdup(name);
147 gboolean was_enabled;
148 struct sr_dev_inst *sdi;
154 was_enabled = channel->
enabled;
156 if (!state != !was_enabled && sdi->driver
157 && sdi->driver->config_channel_set) {
158 ret = sdi->driver->config_channel_set(
159 sdi, channel, SR_CHANNEL_SET_ENABLED);
179 SR_PRIV struct sr_channel *sr_next_enabled_channel(
const struct sr_dev_inst *sdi,
185 next_channel = cur_channel;
187 l = g_slist_find(sdi->channels, next_channel);
189 next_channel = l->next->data;
191 next_channel = sdi->channels->data;
192 }
while (!next_channel->
enabled);
238 SR_PRIV gboolean sr_channel_lists_differ(GSList *l1, GSList *l2)
249 if (sr_channels_differ(ch1, ch2))
273 const char *name,
void *
priv)
277 cg = g_malloc0(
sizeof(*cg));
279 cg->
name = g_strdup(name);
283 sdi->channel_groups = g_slist_append(sdi->channel_groups, cg);
311 SR_PRIV void sr_channel_group_free_cb(
void *cg)
313 return sr_channel_group_free(cg);
340 if (!sdi || !sdi->driver || !sdi->driver->config_list)
343 if (sdi->driver->config_list(SR_CONF_DEVICE_OPTIONS,
344 &gvar, sdi, NULL) !=
SR_OK)
348 devopts = g_variant_get_fixed_array(gvar, &num_opts,
sizeof(int32_t));
349 for (i = 0; i < num_opts; i++) {
350 if ((devopts[i] & SR_CONF_MASK) == key) {
355 g_variant_unref(gvar);
379 const uint32_t *opts;
387 if (sdi && sdi->driver != driver)
393 opts = g_variant_get_fixed_array(gvar, &num_opts,
sizeof(uint32_t));
395 result = g_array_sized_new(FALSE, FALSE,
sizeof(uint32_t), num_opts);
397 for (i = 0; i < num_opts; i++) {
398 opt = opts[i] & SR_CONF_MASK;
399 g_array_insert_val(result, i, opt);
402 g_variant_unref(gvar);
433 if (!sdi || !sdi->driver || !sdi->driver->config_list)
436 if (sdi->driver->config_list(SR_CONF_DEVICE_OPTIONS,
437 &gvar, sdi, cg) !=
SR_OK)
441 devopts = g_variant_get_fixed_array(gvar, &num_opts,
sizeof(int32_t));
442 for (i = 0; i < num_opts; i++) {
443 if ((devopts[i] & SR_CONF_MASK) == key) {
444 ret = devopts[i] & ~SR_CONF_MASK;
448 g_variant_unref(gvar);
464 const char *model,
const char *version)
466 struct sr_dev_inst *sdi;
468 sdi = g_malloc0(
sizeof(*sdi));
470 sdi->vendor = g_strdup(vendor);
471 sdi->model = g_strdup(model);
472 sdi->version = g_strdup(version);
491 if (!sdi || sdi->inst_type !=
SR_INST_USER || index < 0)
494 if (!sr_channel_new(sdi, index, type, TRUE, name))
507 SR_PRIV void sr_dev_inst_free(
struct sr_dev_inst *sdi)
515 for (l = sdi->channels; l; l = l->next) {
519 g_slist_free(sdi->channels);
520 g_slist_free_full(sdi->channel_groups, sr_channel_group_free_cb);
527 g_free(sdi->version);
528 g_free(sdi->serial_num);
529 g_free(sdi->connection_id);
533 #ifdef HAVE_LIBUSB_1_0 546 SR_PRIV struct sr_usb_dev_inst *sr_usb_dev_inst_new(uint8_t bus,
547 uint8_t address,
struct libusb_device_handle *hdl)
549 struct sr_usb_dev_inst *udi;
551 udi = g_malloc0(
sizeof(*udi));
553 udi->address = address;
567 SR_PRIV void sr_usb_dev_inst_free(
struct sr_usb_dev_inst *usb)
577 SR_PRIV void sr_usb_dev_inst_free_cb(gpointer p)
579 sr_usb_dev_inst_free(p);
583 #ifdef HAVE_SERIAL_COMM 604 SR_PRIV struct sr_serial_dev_inst *sr_serial_dev_inst_new(
const char *port,
605 const char *serialcomm)
607 struct sr_serial_dev_inst *serial;
609 serial = g_malloc0(
sizeof(*serial));
610 serial->port = g_strdup(port);
612 serial->serialcomm = g_strdup(serialcomm);
625 SR_PRIV void sr_serial_dev_inst_free(
struct sr_serial_dev_inst *serial)
630 g_free(serial->port);
631 g_free(serial->serialcomm);
637 SR_PRIV struct sr_usbtmc_dev_inst *sr_usbtmc_dev_inst_new(
const char *device)
639 struct sr_usbtmc_dev_inst *usbtmc;
641 usbtmc = g_malloc0(
sizeof(*usbtmc));
642 usbtmc->device = g_strdup(device);
649 SR_PRIV void sr_usbtmc_dev_inst_free(
struct sr_usbtmc_dev_inst *usbtmc)
654 g_free(usbtmc->device);
690 sr_err(
"Invalid driver.");
730 if (!sdi || !sdi->driver || !sdi->driver->dev_open)
734 sr_err(
"%s: Device instance already active, can't re-open.",
739 sr_dbg(
"%s: Opening device instance.", sdi->driver->name);
741 ret = sdi->driver->dev_open(sdi);
770 if (!sdi || !sdi->driver || !sdi->driver->dev_close)
774 sr_err(
"%s: Device instance not active, can't close.",
781 sr_dbg(
"%s: Closing device instance.", sdi->driver->name);
783 return sdi->driver->dev_close(sdi);
795 if (!sdi || !sdi->driver)
858 return sdi->serial_num;
871 #ifdef HAVE_LIBUSB_1_0 872 struct drv_context *drvc;
874 char conn_id_usb[64];
875 struct sr_usb_dev_inst *usb;
876 struct libusb_device **devlist;
879 #ifdef HAVE_SERIAL_COMM 880 struct sr_serial_dev_inst *serial;
883 struct sr_scpi_dev_inst *scpi;
889 #ifdef HAVE_SERIAL_COMM 890 if ((!sdi->connection_id) && (sdi->inst_type ==
SR_INST_SERIAL)) {
894 ((
struct sr_dev_inst *)sdi)->connection_id = g_strdup(serial->port);
898 #ifdef HAVE_LIBUSB_1_0 899 if ((!sdi->connection_id) && (sdi->inst_type ==
SR_INST_USB)) {
902 drvc = sdi->driver->context;
905 if ((cnt = libusb_get_device_list(drvc->sr_ctx->libusb_ctx, &devlist)) < 0) {
906 sr_err(
"Failed to retrieve device list: %s.",
907 libusb_error_name(cnt));
911 for (i = 0; i < cnt; i++) {
913 b = libusb_get_bus_number(devlist[i]);
914 a = libusb_get_device_address(devlist[i]);
915 if (b != usb->bus || a != usb->address)
918 if (usb_get_port_path(devlist[i], conn_id_usb,
sizeof(conn_id_usb)) < 0)
921 ((
struct sr_dev_inst *)sdi)->connection_id = g_strdup(conn_id_usb);
925 libusb_free_device_list(devlist, 1);
929 if ((!sdi->connection_id) && (sdi->inst_type ==
SR_INST_SCPI)) {
933 sr_scpi_connection_id(scpi, &conn_id_scpi);
934 ((
struct sr_dev_inst *)sdi)->connection_id = g_strdup(conn_id_scpi);
935 g_free(conn_id_scpi);
938 return sdi->connection_id;
953 return sdi->channels;
968 return sdi->channel_groups;
Information on single channel.
GSList * sr_dev_inst_channel_groups_get(const struct sr_dev_inst *sdi)
Queries a device instances' channel groups list.
int sr_dev_open(struct sr_dev_inst *sdi)
Open the specified device instance.
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.
GSList * channels
List of sr_channel structs of the channels belonging to this group.
GSList *(* dev_list)(const struct sr_dev_driver *driver)
Get list of device instances the driver knows about.
const char * sr_dev_inst_model_get(const struct sr_dev_inst *sdi)
Queries a device instances' model.
int type
Channel type (SR_CHANNEL_LOGIC, ...)
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.
Device instance type for serial port devices.
struct sr_dev_inst * sdi
The device this channel is attached to.
int sr_dev_channel_enable(struct sr_channel *channel, gboolean state)
Enable or disable a channel.
int sr_dev_close(struct sr_dev_inst *sdi)
Close the specified device instance.
The device instance is actively in use in a session.
The device instance is live, but not in use.
const char * sr_dev_inst_sernum_get(const struct sr_dev_inst *sdi)
Queries a device instances' serial number.
int index
The index of this channel, starting at 0.
GSList * sr_dev_list(const struct sr_dev_driver *driver)
Get the list of devices/instances of the specified driver.
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.
Generic/unspecified error.
gboolean enabled
Is this channel enabled?
void * context
Device driver context, considered private.
struct sr_dev_driver * sr_dev_inst_driver_get(const struct sr_dev_inst *sdi)
Queries a device instances' driver.
void * priv
Private data for driver use.
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.
GSList * sr_dev_inst_channels_get(const struct sr_dev_inst *sdi)
Queries a device instances' channel list.
Device instance type for SCPI devices.
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.
Structure for groups of channels that have common properties.
Device instance type for USB devices.
char * name
Name of the channel 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.
gboolean sr_dev_has_option(const struct sr_dev_inst *sdi, int key)
Determine whether the specified device instance has the specified capability.
const char * sr_dev_inst_vendor_get(const struct sr_dev_inst *sdi)
Queries a device instances' vendor.
The public libsigrok header file to be used by frontends.
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.
int sr_session_dev_remove(struct sr_session *session, struct sr_dev_inst *sdi)
Remove a device instance from a session.
Device is closed, but must be open.
int sr_dev_clear(const struct sr_dev_driver *driver)
Clear the list of device instances a driver knows about.
Device-instance type for user-created "devices".
char * name
Name of channel.