2010-04-02 18:18:27 +00:00
|
|
|
/*
|
2013-04-23 20:24:30 +00:00
|
|
|
* This file is part of the libsigrok project.
|
2010-04-02 18:18:27 +00:00
|
|
|
*
|
2013-03-24 10:21:00 +00:00
|
|
|
* Copyright (C) 2013 Bert Vermeulen <bert@biot.com>
|
2010-04-02 18:18:27 +00:00
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2015-09-13 16:22:17 +00:00
|
|
|
#include <config.h>
|
2010-04-02 18:18:27 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <glib.h>
|
2015-08-12 23:18:51 +00:00
|
|
|
#include <libsigrok/libsigrok.h>
|
2012-07-04 22:55:07 +00:00
|
|
|
#include "libsigrok-internal.h"
|
2010-04-02 18:18:27 +00:00
|
|
|
|
2014-04-25 16:40:59 +00:00
|
|
|
/** @cond PRIVATE */
|
2013-12-23 03:38:35 +00:00
|
|
|
#define LOG_PREFIX "device"
|
2014-04-25 16:40:59 +00:00
|
|
|
/** @endcond */
|
2012-11-11 11:44:16 +00:00
|
|
|
|
2012-10-21 22:30:12 +00:00
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
*
|
|
|
|
* Device handling in libsigrok.
|
|
|
|
*/
|
|
|
|
|
2012-10-21 14:13:36 +00:00
|
|
|
/**
|
|
|
|
* @defgroup grp_devices Devices
|
|
|
|
*
|
|
|
|
* Device handling in libsigrok.
|
|
|
|
*
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2016-08-29 14:43:49 +00:00
|
|
|
/**
|
|
|
|
* Allocate and initialize a new struct sr_channel and add it to sdi.
|
|
|
|
*
|
|
|
|
* @param[in] sdi The device instance the channel is connected to.
|
|
|
|
* Must not be NULL.
|
|
|
|
* @param[in] index @copydoc sr_channel::index
|
|
|
|
* @param[in] type @copydoc sr_channel::type
|
|
|
|
* @param[in] enabled @copydoc sr_channel::enabled
|
|
|
|
* @param[in] name @copydoc sr_channel::name
|
|
|
|
*
|
|
|
|
* @return A new struct sr_channel*.
|
|
|
|
*
|
|
|
|
* @private
|
2013-11-22 19:40:52 +00:00
|
|
|
*/
|
2015-03-19 21:37:33 +00:00
|
|
|
SR_PRIV struct sr_channel *sr_channel_new(struct sr_dev_inst *sdi,
|
|
|
|
int index, int type, gboolean enabled, const char *name)
|
2012-07-24 22:20:06 +00:00
|
|
|
{
|
2014-03-24 20:34:20 +00:00
|
|
|
struct sr_channel *ch;
|
2012-07-24 22:20:06 +00:00
|
|
|
|
2014-11-21 08:07:04 +00:00
|
|
|
ch = g_malloc0(sizeof(struct sr_channel));
|
2015-03-19 21:41:51 +00:00
|
|
|
ch->sdi = sdi;
|
2014-03-24 20:34:20 +00:00
|
|
|
ch->index = index;
|
|
|
|
ch->type = type;
|
|
|
|
ch->enabled = enabled;
|
2012-07-24 22:20:06 +00:00
|
|
|
if (name)
|
2014-03-24 20:34:20 +00:00
|
|
|
ch->name = g_strdup(name);
|
2012-07-24 22:20:06 +00:00
|
|
|
|
2015-03-19 21:37:33 +00:00
|
|
|
sdi->channels = g_slist_append(sdi->channels, ch);
|
|
|
|
|
2014-03-24 20:34:20 +00:00
|
|
|
return ch;
|
2012-07-24 22:20:06 +00:00
|
|
|
}
|
|
|
|
|
2011-12-28 15:19:15 +00:00
|
|
|
/**
|
2015-03-19 21:55:48 +00:00
|
|
|
* Set the name of the specified channel.
|
2011-12-28 15:19:15 +00:00
|
|
|
*
|
2014-03-24 20:34:20 +00:00
|
|
|
* If the channel already has a different name assigned to it, it will be
|
2011-12-28 15:19:15 +00:00
|
|
|
* removed, and the new name will be saved instead.
|
|
|
|
*
|
2016-08-29 14:43:49 +00:00
|
|
|
* @param[in] channel The channel whose name to set. Must not be NULL.
|
|
|
|
* @param[in] name The new name that the specified channel should get.
|
|
|
|
* A copy of the string is made.
|
2011-12-28 16:16:33 +00:00
|
|
|
*
|
2012-07-22 18:05:36 +00:00
|
|
|
* @return SR_OK on success, or SR_ERR_ARG on invalid arguments.
|
2013-04-13 16:58:11 +00:00
|
|
|
*
|
2014-05-04 18:51:05 +00:00
|
|
|
* @since 0.3.0
|
2011-12-28 15:19:15 +00:00
|
|
|
*/
|
2015-03-19 21:55:48 +00:00
|
|
|
SR_API int sr_dev_channel_name_set(struct sr_channel *channel,
|
|
|
|
const char *name)
|
2010-04-02 18:18:27 +00:00
|
|
|
{
|
2016-08-29 14:43:49 +00:00
|
|
|
if (!channel)
|
2011-12-28 16:16:33 +00:00
|
|
|
return SR_ERR_ARG;
|
2011-12-28 15:19:15 +00:00
|
|
|
|
2015-03-19 21:55:48 +00:00
|
|
|
g_free(channel->name);
|
|
|
|
channel->name = g_strdup(name);
|
2016-08-29 14:43:49 +00:00
|
|
|
|
2015-03-19 21:55:48 +00:00
|
|
|
return SR_OK;
|
2010-04-02 18:18:27 +00:00
|
|
|
}
|
|
|
|
|
2012-07-22 10:23:59 +00:00
|
|
|
/**
|
2015-03-19 21:55:48 +00:00
|
|
|
* Enable or disable a channel.
|
2012-07-22 10:23:59 +00:00
|
|
|
*
|
2016-08-29 14:43:49 +00:00
|
|
|
* @param[in] channel The channel to enable or disable. Must not be NULL.
|
|
|
|
* @param[in] state TRUE to enable the channel, FALSE to disable.
|
2012-07-22 10:23:59 +00:00
|
|
|
*
|
2016-08-29 14:43:49 +00:00
|
|
|
* @return SR_OK on success or SR_ERR on failure. In case of invalid
|
2014-03-24 20:34:20 +00:00
|
|
|
* arguments, SR_ERR_ARG is returned and the channel enabled state
|
2014-01-19 19:39:11 +00:00
|
|
|
* remains unchanged.
|
2013-04-13 16:58:11 +00:00
|
|
|
*
|
2014-05-04 18:51:05 +00:00
|
|
|
* @since 0.3.0
|
2012-07-22 10:23:59 +00:00
|
|
|
*/
|
2016-08-29 14:43:49 +00:00
|
|
|
SR_API int sr_dev_channel_enable(struct sr_channel *channel, gboolean state)
|
2012-07-22 10:23:59 +00:00
|
|
|
{
|
|
|
|
int ret;
|
2014-01-19 19:39:11 +00:00
|
|
|
gboolean was_enabled;
|
2015-03-19 21:55:48 +00:00
|
|
|
struct sr_dev_inst *sdi;
|
2012-07-22 10:23:59 +00:00
|
|
|
|
2015-03-19 21:55:48 +00:00
|
|
|
if (!channel)
|
2012-07-22 10:23:59 +00:00
|
|
|
return SR_ERR_ARG;
|
|
|
|
|
2015-03-19 21:55:48 +00:00
|
|
|
sdi = channel->sdi;
|
|
|
|
was_enabled = channel->enabled;
|
|
|
|
channel->enabled = state;
|
|
|
|
if (!state != !was_enabled && sdi->driver
|
|
|
|
&& sdi->driver->config_channel_set) {
|
|
|
|
ret = sdi->driver->config_channel_set(
|
|
|
|
sdi, channel, SR_CHANNEL_SET_ENABLED);
|
|
|
|
/* Roll back change if it wasn't applicable. */
|
|
|
|
if (ret != SR_OK)
|
|
|
|
return ret;
|
2012-07-22 10:23:59 +00:00
|
|
|
}
|
|
|
|
|
2015-03-19 21:55:48 +00:00
|
|
|
return SR_OK;
|
2012-07-22 10:23:59 +00:00
|
|
|
}
|
|
|
|
|
2015-08-16 13:54:02 +00:00
|
|
|
/* Returns the next enabled channel, wrapping around if necessary. */
|
2017-06-12 00:44:28 +00:00
|
|
|
/** @private */
|
2015-08-16 13:54:02 +00:00
|
|
|
SR_PRIV struct sr_channel *sr_next_enabled_channel(const struct sr_dev_inst *sdi,
|
2017-06-12 00:44:28 +00:00
|
|
|
|
2015-08-16 13:54:02 +00:00
|
|
|
struct sr_channel *cur_channel)
|
|
|
|
{
|
|
|
|
struct sr_channel *next_channel;
|
|
|
|
GSList *l;
|
|
|
|
|
|
|
|
next_channel = cur_channel;
|
|
|
|
do {
|
|
|
|
l = g_slist_find(sdi->channels, next_channel);
|
|
|
|
if (l && l->next)
|
|
|
|
next_channel = l->next->data;
|
|
|
|
else
|
|
|
|
next_channel = sdi->channels->data;
|
|
|
|
} while (!next_channel->enabled);
|
|
|
|
|
|
|
|
return next_channel;
|
|
|
|
}
|
|
|
|
|
2011-12-28 15:19:15 +00:00
|
|
|
/**
|
2012-10-21 14:52:56 +00:00
|
|
|
* Determine whether the specified device instance has the specified
|
|
|
|
* capability.
|
2011-12-28 15:19:15 +00:00
|
|
|
*
|
2012-10-21 14:52:56 +00:00
|
|
|
* @param sdi Pointer to the device instance to be checked. Must not be NULL.
|
2012-03-21 18:28:43 +00:00
|
|
|
* If the device's 'driver' field is NULL (virtual device), this
|
|
|
|
* function will always return FALSE (virtual devices don't have
|
|
|
|
* a hardware capabilities list).
|
2013-11-22 19:40:52 +00:00
|
|
|
* @param[in] key The option that should be checked for is supported by the
|
2013-01-25 15:20:40 +00:00
|
|
|
* specified device.
|
2011-12-28 15:19:15 +00:00
|
|
|
*
|
2016-08-29 14:43:49 +00:00
|
|
|
* @retval TRUE Device has the specified option.
|
2013-11-22 19:40:52 +00:00
|
|
|
* @retval FALSE Device does not have the specified option, invalid input
|
|
|
|
* parameters or other error conditions.
|
2013-04-13 16:58:11 +00:00
|
|
|
*
|
2013-11-03 15:08:38 +00:00
|
|
|
* @since 0.2.0
|
2011-12-28 15:19:15 +00:00
|
|
|
*/
|
2013-01-25 15:20:40 +00:00
|
|
|
SR_API gboolean sr_dev_has_option(const struct sr_dev_inst *sdi, int key)
|
2011-01-31 21:34:14 +00:00
|
|
|
{
|
2013-03-25 19:21:10 +00:00
|
|
|
GVariant *gvar;
|
2013-01-25 15:20:40 +00:00
|
|
|
const int *devopts;
|
2013-03-25 19:21:10 +00:00
|
|
|
gsize num_opts, i;
|
|
|
|
int ret;
|
2011-01-31 21:34:14 +00:00
|
|
|
|
2013-03-25 19:21:10 +00:00
|
|
|
if (!sdi || !sdi->driver || !sdi->driver->config_list)
|
2012-03-21 18:28:43 +00:00
|
|
|
return FALSE;
|
2011-12-28 15:19:15 +00:00
|
|
|
|
2013-04-20 00:00:49 +00:00
|
|
|
if (sdi->driver->config_list(SR_CONF_DEVICE_OPTIONS,
|
2014-01-16 01:53:41 +00:00
|
|
|
&gvar, sdi, NULL) != SR_OK)
|
2012-03-21 18:28:43 +00:00
|
|
|
return FALSE;
|
2011-12-28 15:19:15 +00:00
|
|
|
|
2013-03-25 19:21:10 +00:00
|
|
|
ret = FALSE;
|
|
|
|
devopts = g_variant_get_fixed_array(gvar, &num_opts, sizeof(int32_t));
|
|
|
|
for (i = 0; i < num_opts; i++) {
|
2014-10-09 21:42:24 +00:00
|
|
|
if ((devopts[i] & SR_CONF_MASK) == key) {
|
2013-03-25 19:21:10 +00:00
|
|
|
ret = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
2011-12-28 15:19:15 +00:00
|
|
|
}
|
2013-03-25 19:21:10 +00:00
|
|
|
g_variant_unref(gvar);
|
2011-02-13 10:27:52 +00:00
|
|
|
|
2013-03-25 19:21:10 +00:00
|
|
|
return ret;
|
2010-04-02 18:18:27 +00:00
|
|
|
}
|
2012-01-29 12:56:06 +00:00
|
|
|
|
2015-11-02 00:40:40 +00:00
|
|
|
/**
|
|
|
|
* Enumerate the configuration options of the specified item.
|
|
|
|
*
|
|
|
|
* @param driver Pointer to the driver to be checked. Must not be NULL.
|
|
|
|
* @param sdi Pointer to the device instance to be checked. May be NULL to
|
|
|
|
* check driver options.
|
2016-08-29 14:43:49 +00:00
|
|
|
* @param cg Pointer to a channel group, if a specific channel group is to
|
|
|
|
* be checked. Must be NULL to check device-wide options.
|
|
|
|
*
|
2015-11-02 00:40:40 +00:00
|
|
|
* @return A GArray * of enum sr_configkey values, or NULL on invalid
|
|
|
|
* arguments. The array must be freed by the caller using
|
|
|
|
* g_array_free().
|
|
|
|
*
|
|
|
|
* @since 0.4.0
|
|
|
|
*/
|
2016-08-29 14:43:49 +00:00
|
|
|
SR_API GArray *sr_dev_options(const struct sr_dev_driver *driver,
|
|
|
|
const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
|
2015-11-02 00:40:40 +00:00
|
|
|
{
|
|
|
|
GVariant *gvar;
|
|
|
|
const uint32_t *opts;
|
|
|
|
uint32_t opt;
|
|
|
|
gsize num_opts, i;
|
|
|
|
GArray *result;
|
|
|
|
|
|
|
|
if (!driver || !driver->config_list)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (sdi && sdi->driver != driver)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (driver->config_list(SR_CONF_DEVICE_OPTIONS, &gvar, sdi, cg) != SR_OK)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
opts = g_variant_get_fixed_array(gvar, &num_opts, sizeof(uint32_t));
|
|
|
|
|
|
|
|
result = g_array_sized_new(FALSE, FALSE, sizeof(uint32_t), num_opts);
|
|
|
|
|
|
|
|
for (i = 0; i < num_opts; i++) {
|
|
|
|
opt = opts[i] & SR_CONF_MASK;
|
|
|
|
g_array_insert_val(result, i, opt);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_variant_unref(gvar);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2015-11-02 21:35:26 +00:00
|
|
|
/**
|
|
|
|
* Enumerate the configuration capabilities supported by a device instance
|
|
|
|
* for a given configuration key.
|
|
|
|
*
|
|
|
|
* @param sdi Pointer to the device instance to be checked. Must not be NULL.
|
|
|
|
* If the device's 'driver' field is NULL (virtual device), this
|
|
|
|
* function will always return FALSE (virtual devices don't have
|
|
|
|
* a hardware capabilities list).
|
2016-08-29 14:43:49 +00:00
|
|
|
* @param cg Pointer to a channel group, if a specific channel group is to
|
|
|
|
* be checked. Must be NULL to check device-wide options.
|
2015-11-02 21:35:26 +00:00
|
|
|
* @param[in] key The option that should be checked for is supported by the
|
|
|
|
* specified device.
|
|
|
|
*
|
|
|
|
* @retval A bitmask of enum sr_configcap values, which will be zero for
|
|
|
|
* invalid inputs or if the key is unsupported.
|
|
|
|
*
|
|
|
|
* @since 0.4.0
|
|
|
|
*/
|
2015-12-31 17:45:17 +00:00
|
|
|
SR_API int sr_dev_config_capabilities_list(const struct sr_dev_inst *sdi,
|
2015-11-02 21:35:26 +00:00
|
|
|
const struct sr_channel_group *cg, const int key)
|
|
|
|
{
|
|
|
|
GVariant *gvar;
|
|
|
|
const int *devopts;
|
|
|
|
gsize num_opts, i;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!sdi || !sdi->driver || !sdi->driver->config_list)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (sdi->driver->config_list(SR_CONF_DEVICE_OPTIONS,
|
|
|
|
&gvar, sdi, cg) != SR_OK)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
devopts = g_variant_get_fixed_array(gvar, &num_opts, sizeof(int32_t));
|
|
|
|
for (i = 0; i < num_opts; i++) {
|
|
|
|
if ((devopts[i] & SR_CONF_MASK) == key) {
|
|
|
|
ret = devopts[i] & ~SR_CONF_MASK;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
g_variant_unref(gvar);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-11-11 20:58:49 +00:00
|
|
|
/**
|
|
|
|
* Allocate and init a new user-generated device instance.
|
2014-11-21 01:01:36 +00:00
|
|
|
*
|
2016-08-29 14:43:49 +00:00
|
|
|
* @param vendor Device vendor.
|
|
|
|
* @param model Device model.
|
|
|
|
* @param version Device version.
|
2014-11-21 01:01:36 +00:00
|
|
|
*
|
|
|
|
* @retval struct sr_dev_inst *. Dynamically allocated, free using
|
|
|
|
* sr_dev_inst_free().
|
2014-11-11 20:58:49 +00:00
|
|
|
*/
|
|
|
|
SR_API struct sr_dev_inst *sr_dev_inst_user_new(const char *vendor,
|
|
|
|
const char *model, const char *version)
|
|
|
|
{
|
|
|
|
struct sr_dev_inst *sdi;
|
|
|
|
|
2014-11-21 01:01:36 +00:00
|
|
|
sdi = g_malloc0(sizeof(struct sr_dev_inst));
|
|
|
|
|
2014-11-12 01:06:15 +00:00
|
|
|
sdi->vendor = g_strdup(vendor);
|
|
|
|
sdi->model = g_strdup(model);
|
|
|
|
sdi->version = g_strdup(version);
|
2014-11-11 20:58:49 +00:00
|
|
|
sdi->inst_type = SR_INST_USER;
|
|
|
|
|
|
|
|
return sdi;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a new channel to the specified device instance.
|
2016-08-29 14:43:49 +00:00
|
|
|
*
|
|
|
|
* @param[in] index @copydoc sr_channel::index
|
|
|
|
* @param[in] type @copydoc sr_channel::type
|
|
|
|
* @param[in] name @copydoc sr_channel::name
|
|
|
|
*
|
|
|
|
* @return SR_OK Success.
|
|
|
|
* @return SR_OK Invalid argument.
|
2014-11-11 20:58:49 +00:00
|
|
|
*/
|
|
|
|
SR_API int sr_dev_inst_channel_add(struct sr_dev_inst *sdi, int index, int type, const char *name)
|
|
|
|
{
|
|
|
|
if (!sdi || sdi->inst_type != SR_INST_USER || index < 0)
|
|
|
|
return SR_ERR_ARG;
|
|
|
|
|
2015-03-19 21:37:33 +00:00
|
|
|
sr_channel_new(sdi, index, type, TRUE, name);
|
2014-11-11 20:58:49 +00:00
|
|
|
|
|
|
|
return SR_OK;
|
|
|
|
}
|
|
|
|
|
2016-08-29 14:43:49 +00:00
|
|
|
/**
|
|
|
|
* Free device instance struct created by sr_dev_inst().
|
|
|
|
*
|
2017-03-08 18:18:17 +00:00
|
|
|
* @param sdi Device instance to free. If NULL, the function will do nothing.
|
2016-08-29 14:43:49 +00:00
|
|
|
*
|
|
|
|
* @private
|
2013-11-22 19:40:52 +00:00
|
|
|
*/
|
2012-07-24 22:20:06 +00:00
|
|
|
SR_PRIV void sr_dev_inst_free(struct sr_dev_inst *sdi)
|
|
|
|
{
|
2014-03-24 20:34:20 +00:00
|
|
|
struct sr_channel *ch;
|
2014-10-18 21:09:47 +00:00
|
|
|
struct sr_channel_group *cg;
|
2012-08-04 10:03:05 +00:00
|
|
|
GSList *l;
|
|
|
|
|
2017-03-08 18:18:17 +00:00
|
|
|
if (!sdi)
|
|
|
|
return;
|
|
|
|
|
2014-03-24 20:34:20 +00:00
|
|
|
for (l = sdi->channels; l; l = l->next) {
|
|
|
|
ch = l->data;
|
|
|
|
g_free(ch->name);
|
2014-09-08 01:25:41 +00:00
|
|
|
g_free(ch->priv);
|
2014-03-24 20:34:20 +00:00
|
|
|
g_free(ch);
|
2012-08-04 10:03:05 +00:00
|
|
|
}
|
2014-03-24 20:34:20 +00:00
|
|
|
g_slist_free(sdi->channels);
|
2012-08-04 10:03:05 +00:00
|
|
|
|
2014-10-18 21:09:47 +00:00
|
|
|
for (l = sdi->channel_groups; l; l = l->next) {
|
|
|
|
cg = l->data;
|
2014-11-01 12:18:09 +00:00
|
|
|
g_free(cg->name);
|
|
|
|
g_slist_free(cg->channels);
|
2014-10-18 21:09:47 +00:00
|
|
|
g_free(cg->priv);
|
2014-11-01 12:18:09 +00:00
|
|
|
g_free(cg);
|
2014-10-18 21:09:47 +00:00
|
|
|
}
|
|
|
|
g_slist_free(sdi->channel_groups);
|
2013-11-19 00:08:18 +00:00
|
|
|
|
2015-11-26 01:30:42 +00:00
|
|
|
if (sdi->session)
|
|
|
|
sr_session_dev_remove(sdi->session, sdi);
|
|
|
|
|
2012-07-24 22:20:06 +00:00
|
|
|
g_free(sdi->vendor);
|
|
|
|
g_free(sdi->model);
|
|
|
|
g_free(sdi->version);
|
2014-09-23 15:43:27 +00:00
|
|
|
g_free(sdi->serial_num);
|
|
|
|
g_free(sdi->connection_id);
|
2012-07-24 22:20:06 +00:00
|
|
|
g_free(sdi);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef HAVE_LIBUSB_1_0
|
|
|
|
|
2016-08-29 14:43:49 +00:00
|
|
|
/**
|
|
|
|
* Allocate and init a struct for a USB device instance.
|
|
|
|
*
|
|
|
|
* @param[in] bus @copydoc sr_usb_dev_inst::bus
|
|
|
|
* @param[in] address @copydoc sr_usb_dev_inst::address
|
|
|
|
* @param[in] hdl @copydoc sr_usb_dev_inst::devhdl
|
2013-11-22 19:40:52 +00:00
|
|
|
*
|
2016-08-29 14:43:49 +00:00
|
|
|
* @return The struct sr_usb_dev_inst * for USB device instance.
|
|
|
|
*
|
|
|
|
* @private
|
2013-11-22 19:40:52 +00:00
|
|
|
*/
|
2012-07-24 22:20:06 +00:00
|
|
|
SR_PRIV struct sr_usb_dev_inst *sr_usb_dev_inst_new(uint8_t bus,
|
|
|
|
uint8_t address, struct libusb_device_handle *hdl)
|
|
|
|
{
|
|
|
|
struct sr_usb_dev_inst *udi;
|
|
|
|
|
2014-11-21 18:02:10 +00:00
|
|
|
udi = g_malloc0(sizeof(struct sr_usb_dev_inst));
|
2012-07-24 22:20:06 +00:00
|
|
|
udi->bus = bus;
|
|
|
|
udi->address = address;
|
|
|
|
udi->devhdl = hdl;
|
|
|
|
|
|
|
|
return udi;
|
|
|
|
}
|
|
|
|
|
2016-08-29 14:43:49 +00:00
|
|
|
/**
|
|
|
|
* Free struct sr_usb_dev_inst * allocated by sr_usb_dev_inst().
|
|
|
|
*
|
2017-03-08 18:31:22 +00:00
|
|
|
* @param usb The struct sr_usb_dev_inst * to free. If NULL, this
|
|
|
|
* function does nothing.
|
2016-08-29 14:43:49 +00:00
|
|
|
*
|
|
|
|
* @private
|
2013-11-22 19:40:52 +00:00
|
|
|
*/
|
2012-07-24 22:20:06 +00:00
|
|
|
SR_PRIV void sr_usb_dev_inst_free(struct sr_usb_dev_inst *usb)
|
|
|
|
{
|
2013-05-05 22:40:17 +00:00
|
|
|
g_free(usb);
|
2012-07-24 22:20:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2013-11-13 18:56:13 +00:00
|
|
|
#ifdef HAVE_LIBSERIALPORT
|
|
|
|
|
2013-04-13 16:58:11 +00:00
|
|
|
/**
|
2016-08-29 14:43:49 +00:00
|
|
|
* Allocate and init a struct for a serial device instance.
|
2012-11-11 19:38:47 +00:00
|
|
|
*
|
|
|
|
* Both parameters are copied to newly allocated strings, and freed
|
|
|
|
* automatically by sr_serial_dev_inst_free().
|
2013-04-13 16:58:11 +00:00
|
|
|
*
|
2013-11-22 19:40:52 +00:00
|
|
|
* @param[in] port OS-specific serial port specification. Examples:
|
2013-04-13 16:58:11 +00:00
|
|
|
* "/dev/ttyUSB0", "/dev/ttyACM1", "/dev/tty.Modem-0", "COM1".
|
2014-11-21 18:02:10 +00:00
|
|
|
* Must not be NULL.
|
2013-11-22 19:40:52 +00:00
|
|
|
* @param[in] serialcomm A serial communication parameters string, in the form
|
|
|
|
* of \<speed\>/\<data bits\>\<parity\>\<stopbits\>, for example
|
|
|
|
* "9600/8n1" or "600/7o2". This is an optional parameter;
|
2014-11-21 18:02:10 +00:00
|
|
|
* it may be filled in later. Can be NULL.
|
2013-04-13 16:58:11 +00:00
|
|
|
*
|
|
|
|
* @return A pointer to a newly initialized struct sr_serial_dev_inst,
|
|
|
|
* or NULL on error.
|
2016-08-29 14:43:49 +00:00
|
|
|
*
|
|
|
|
* @private
|
2012-11-11 19:38:47 +00:00
|
|
|
*/
|
2012-07-24 22:20:06 +00:00
|
|
|
SR_PRIV struct sr_serial_dev_inst *sr_serial_dev_inst_new(const char *port,
|
2012-11-11 19:38:47 +00:00
|
|
|
const char *serialcomm)
|
2012-07-24 22:20:06 +00:00
|
|
|
{
|
|
|
|
struct sr_serial_dev_inst *serial;
|
|
|
|
|
2014-11-21 18:02:10 +00:00
|
|
|
serial = g_malloc0(sizeof(struct sr_serial_dev_inst));
|
2012-07-24 22:20:06 +00:00
|
|
|
serial->port = g_strdup(port);
|
2012-11-11 19:38:47 +00:00
|
|
|
if (serialcomm)
|
|
|
|
serial->serialcomm = g_strdup(serialcomm);
|
2012-07-24 22:20:06 +00:00
|
|
|
|
|
|
|
return serial;
|
|
|
|
}
|
|
|
|
|
2016-08-29 14:43:49 +00:00
|
|
|
/**
|
|
|
|
* Free struct sr_serial_dev_inst * allocated by sr_serial_dev_inst().
|
|
|
|
*
|
2017-03-08 18:27:25 +00:00
|
|
|
* @param serial The struct sr_serial_dev_inst * to free. If NULL, this
|
|
|
|
* function will do nothing.
|
2016-08-29 14:43:49 +00:00
|
|
|
*
|
|
|
|
* @private
|
2013-11-22 19:40:52 +00:00
|
|
|
*/
|
2012-07-24 22:20:06 +00:00
|
|
|
SR_PRIV void sr_serial_dev_inst_free(struct sr_serial_dev_inst *serial)
|
|
|
|
{
|
2017-03-08 18:27:25 +00:00
|
|
|
if (!serial)
|
|
|
|
return;
|
|
|
|
|
2012-07-24 22:20:06 +00:00
|
|
|
g_free(serial->port);
|
2012-11-11 19:38:47 +00:00
|
|
|
g_free(serial->serialcomm);
|
2012-12-20 03:39:38 +00:00
|
|
|
g_free(serial);
|
2012-07-24 22:20:06 +00:00
|
|
|
}
|
2013-11-13 18:56:13 +00:00
|
|
|
#endif
|
|
|
|
|
2013-12-27 15:18:28 +00:00
|
|
|
/** @private */
|
2013-11-29 00:48:42 +00:00
|
|
|
SR_PRIV struct sr_usbtmc_dev_inst *sr_usbtmc_dev_inst_new(const char *device)
|
|
|
|
{
|
|
|
|
struct sr_usbtmc_dev_inst *usbtmc;
|
|
|
|
|
2014-11-21 18:02:10 +00:00
|
|
|
usbtmc = g_malloc0(sizeof(struct sr_usbtmc_dev_inst));
|
2013-11-29 00:48:42 +00:00
|
|
|
usbtmc->device = g_strdup(device);
|
|
|
|
usbtmc->fd = -1;
|
|
|
|
|
|
|
|
return usbtmc;
|
|
|
|
}
|
|
|
|
|
2013-12-27 15:18:28 +00:00
|
|
|
/** @private */
|
2013-11-29 00:48:42 +00:00
|
|
|
SR_PRIV void sr_usbtmc_dev_inst_free(struct sr_usbtmc_dev_inst *usbtmc)
|
|
|
|
{
|
2017-03-08 18:33:18 +00:00
|
|
|
if (!usbtmc)
|
|
|
|
return;
|
|
|
|
|
2013-11-29 00:48:42 +00:00
|
|
|
g_free(usbtmc->device);
|
|
|
|
g_free(usbtmc);
|
|
|
|
}
|
|
|
|
|
2013-05-05 15:14:20 +00:00
|
|
|
/**
|
|
|
|
* Get the list of devices/instances of the specified driver.
|
|
|
|
*
|
|
|
|
* @param driver The driver to use. Must not be NULL.
|
|
|
|
*
|
|
|
|
* @return The list of devices/instances of this driver, or NULL upon errors
|
|
|
|
* or if the list is empty.
|
|
|
|
*
|
2013-11-03 15:08:38 +00:00
|
|
|
* @since 0.2.0
|
2013-05-05 15:14:20 +00:00
|
|
|
*/
|
2013-04-22 13:55:06 +00:00
|
|
|
SR_API GSList *sr_dev_list(const struct sr_dev_driver *driver)
|
2012-08-05 22:59:25 +00:00
|
|
|
{
|
|
|
|
if (driver && driver->dev_list)
|
2015-03-21 00:47:31 +00:00
|
|
|
return driver->dev_list(driver);
|
2012-08-05 22:59:25 +00:00
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-05-05 15:14:20 +00:00
|
|
|
/**
|
2014-02-26 20:25:07 +00:00
|
|
|
* Clear the list of device instances a driver knows about.
|
2013-05-05 15:14:20 +00:00
|
|
|
*
|
2014-02-26 20:25:07 +00:00
|
|
|
* @param driver The driver to use. This must be a pointer to one of
|
|
|
|
* the entries returned by sr_driver_list(). Must not be NULL.
|
2013-05-05 15:14:20 +00:00
|
|
|
*
|
2016-08-29 14:43:49 +00:00
|
|
|
* @retval SR_OK Success.
|
|
|
|
* @retval SR_ERR_ARG Invalid driver.
|
2013-05-05 15:14:20 +00:00
|
|
|
*
|
|
|
|
* @since 0.2.0
|
|
|
|
*/
|
2013-04-22 13:55:06 +00:00
|
|
|
SR_API int sr_dev_clear(const struct sr_dev_driver *driver)
|
2012-08-05 22:59:25 +00:00
|
|
|
{
|
2014-02-26 20:25:07 +00:00
|
|
|
if (!driver) {
|
|
|
|
sr_err("Invalid driver.");
|
|
|
|
return SR_ERR_ARG;
|
|
|
|
}
|
|
|
|
|
2017-07-10 20:32:26 +00:00
|
|
|
if (!driver->context) {
|
|
|
|
/*
|
|
|
|
* Driver was never initialized, nothing to do.
|
|
|
|
*
|
|
|
|
* No log message since this usually gets called for all
|
|
|
|
* drivers, whether they were initialized or not.
|
|
|
|
*/
|
|
|
|
return SR_OK;
|
|
|
|
}
|
|
|
|
|
2017-07-11 19:06:15 +00:00
|
|
|
/* No log message here, too verbose and not very useful. */
|
|
|
|
|
2017-07-11 20:14:01 +00:00
|
|
|
return driver->dev_clear(driver);
|
2012-08-05 22:59:25 +00:00
|
|
|
}
|
|
|
|
|
2013-05-05 15:14:20 +00:00
|
|
|
/**
|
2017-07-07 20:36:24 +00:00
|
|
|
* Open the specified device instance.
|
|
|
|
*
|
|
|
|
* If the device instance is already open (sdi->status == SR_ST_ACTIVE),
|
|
|
|
* SR_ERR will be returned and no re-opening of the device will be attempted.
|
|
|
|
*
|
|
|
|
* If opening was successful, sdi->status is set to SR_ST_ACTIVE, otherwise
|
|
|
|
* it will be left unchanged.
|
2013-05-05 15:14:20 +00:00
|
|
|
*
|
|
|
|
* @param sdi Device instance to use. Must not be NULL.
|
|
|
|
*
|
2017-07-07 20:36:24 +00:00
|
|
|
* @retval SR_OK Success.
|
|
|
|
* @retval SR_ERR_ARG Invalid arguments.
|
|
|
|
* @retval SR_ERR Device instance was already active, or other error.
|
2013-05-05 15:14:20 +00:00
|
|
|
*
|
|
|
|
* @since 0.2.0
|
|
|
|
*/
|
2013-04-22 22:21:57 +00:00
|
|
|
SR_API int sr_dev_open(struct sr_dev_inst *sdi)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!sdi || !sdi->driver || !sdi->driver->dev_open)
|
2017-07-07 20:36:24 +00:00
|
|
|
return SR_ERR_ARG;
|
2013-04-22 22:21:57 +00:00
|
|
|
|
2017-07-07 19:11:56 +00:00
|
|
|
if (sdi->status == SR_ST_ACTIVE) {
|
|
|
|
sr_err("%s: Device instance already active, can't re-open.",
|
|
|
|
sdi->driver->name);
|
|
|
|
return SR_ERR;
|
|
|
|
}
|
|
|
|
|
2017-07-07 20:36:24 +00:00
|
|
|
sr_dbg("%s: Opening device instance.", sdi->driver->name);
|
2017-07-07 19:11:56 +00:00
|
|
|
|
2013-04-22 22:21:57 +00:00
|
|
|
ret = sdi->driver->dev_open(sdi);
|
|
|
|
|
2017-07-07 20:36:24 +00:00
|
|
|
if (ret == SR_OK)
|
|
|
|
sdi->status = SR_ST_ACTIVE;
|
|
|
|
|
2013-04-22 22:21:57 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-05-05 15:14:20 +00:00
|
|
|
/**
|
2017-07-07 18:42:04 +00:00
|
|
|
* Close the specified device instance.
|
|
|
|
*
|
|
|
|
* If the device instance is not open (sdi->status != SR_ST_ACTIVE),
|
|
|
|
* SR_ERR_DEV_CLOSED will be returned and no closing will be attempted.
|
|
|
|
*
|
|
|
|
* Note: sdi->status will be set to SR_ST_INACTIVE, regardless of whether
|
|
|
|
* there are any errors during closing of the device instance (any errors
|
|
|
|
* will be reported via error code and log message, though).
|
2013-05-05 15:14:20 +00:00
|
|
|
*
|
|
|
|
* @param sdi Device instance to use. Must not be NULL.
|
|
|
|
*
|
2017-07-07 18:42:04 +00:00
|
|
|
* @retval SR_OK Success.
|
|
|
|
* @retval SR_ERR_ARG Invalid arguments.
|
|
|
|
* @retval SR_ERR_DEV_CLOSED Device instance was not active.
|
|
|
|
* @retval SR_ERR Other error.
|
2013-05-05 15:14:20 +00:00
|
|
|
*
|
|
|
|
* @since 0.2.0
|
|
|
|
*/
|
2013-04-22 22:21:57 +00:00
|
|
|
SR_API int sr_dev_close(struct sr_dev_inst *sdi)
|
|
|
|
{
|
|
|
|
if (!sdi || !sdi->driver || !sdi->driver->dev_close)
|
2017-07-07 18:42:04 +00:00
|
|
|
return SR_ERR_ARG;
|
2013-04-22 22:21:57 +00:00
|
|
|
|
2017-07-06 18:24:12 +00:00
|
|
|
if (sdi->status != SR_ST_ACTIVE) {
|
|
|
|
sr_err("%s: Device instance not active, can't close.",
|
|
|
|
sdi->driver->name);
|
|
|
|
return SR_ERR_DEV_CLOSED;
|
|
|
|
}
|
|
|
|
|
2017-07-07 18:42:04 +00:00
|
|
|
sdi->status = SR_ST_INACTIVE;
|
|
|
|
|
|
|
|
sr_dbg("%s: Closing device instance.", sdi->driver->name);
|
2017-07-06 18:24:12 +00:00
|
|
|
|
2017-12-24 14:23:40 +00:00
|
|
|
return sdi->driver->dev_close(sdi);
|
2013-04-22 22:21:57 +00:00
|
|
|
}
|
|
|
|
|
2014-10-16 18:17:04 +00:00
|
|
|
/**
|
|
|
|
* Queries a device instances' driver.
|
|
|
|
*
|
|
|
|
* @param sdi Device instance to use. Must not be NULL.
|
|
|
|
*
|
|
|
|
* @return The driver instance or NULL on error.
|
|
|
|
*/
|
2014-11-11 11:44:37 +00:00
|
|
|
SR_API struct sr_dev_driver *sr_dev_inst_driver_get(const struct sr_dev_inst *sdi)
|
2014-10-16 18:17:04 +00:00
|
|
|
{
|
|
|
|
if (!sdi || !sdi->driver)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return sdi->driver;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Queries a device instances' vendor.
|
|
|
|
*
|
|
|
|
* @param sdi Device instance to use. Must not be NULL.
|
|
|
|
*
|
|
|
|
* @return The vendor string or NULL.
|
|
|
|
*/
|
2014-11-11 11:44:37 +00:00
|
|
|
SR_API const char *sr_dev_inst_vendor_get(const struct sr_dev_inst *sdi)
|
2014-10-16 18:17:04 +00:00
|
|
|
{
|
|
|
|
if (!sdi)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return sdi->vendor;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Queries a device instances' model.
|
|
|
|
*
|
|
|
|
* @param sdi Device instance to use. Must not be NULL.
|
|
|
|
*
|
|
|
|
* @return The model string or NULL.
|
|
|
|
*/
|
2014-11-11 11:44:37 +00:00
|
|
|
SR_API const char *sr_dev_inst_model_get(const struct sr_dev_inst *sdi)
|
2014-10-16 18:17:04 +00:00
|
|
|
{
|
|
|
|
if (!sdi)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return sdi->model;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Queries a device instances' version.
|
|
|
|
*
|
|
|
|
* @param sdi Device instance to use. Must not be NULL.
|
|
|
|
*
|
|
|
|
* @return The version string or NULL.
|
|
|
|
*/
|
2014-11-11 11:44:37 +00:00
|
|
|
SR_API const char *sr_dev_inst_version_get(const struct sr_dev_inst *sdi)
|
2014-10-16 18:17:04 +00:00
|
|
|
{
|
|
|
|
if (!sdi)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return sdi->version;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Queries a device instances' serial number.
|
|
|
|
*
|
|
|
|
* @param sdi Device instance to use. Must not be NULL.
|
|
|
|
*
|
|
|
|
* @return The serial number string or NULL.
|
|
|
|
*/
|
2014-11-11 11:44:37 +00:00
|
|
|
SR_API const char *sr_dev_inst_sernum_get(const struct sr_dev_inst *sdi)
|
2014-10-16 18:17:04 +00:00
|
|
|
{
|
|
|
|
if (!sdi)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return sdi->serial_num;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Queries a device instances' connection identifier.
|
|
|
|
*
|
|
|
|
* @param sdi Device instance to use. Must not be NULL.
|
|
|
|
*
|
2016-08-29 14:43:49 +00:00
|
|
|
* @return A copy of the connection ID string or NULL. The caller is responsible
|
2014-10-16 18:17:04 +00:00
|
|
|
* for g_free()ing the string when it is no longer needed.
|
|
|
|
*/
|
2014-11-11 11:44:37 +00:00
|
|
|
SR_API const char *sr_dev_inst_connid_get(const struct sr_dev_inst *sdi)
|
2014-10-16 18:17:04 +00:00
|
|
|
{
|
Fix various warnings when building without libusb.
../src/backend.c: In function 'sr_init':
../src/backend.c:435:1: warning: label 'done' defined but not used [-Wunused-label]
done:
^
../src/device.c: In function 'sr_dev_inst_connid_get':
../src/device.c:525:7: warning: unused variable 'connection_id' [-Wunused-variable]
char connection_id[64];
^
../src/device.c:524:20: warning: unused variable 'b' [-Wunused-variable]
int r, cnt, i, a, b;
^
../src/device.c:524:17: warning: unused variable 'a' [-Wunused-variable]
int r, cnt, i, a, b;
^
../src/device.c:524:14: warning: unused variable 'i' [-Wunused-variable]
int r, cnt, i, a, b;
^
../src/device.c:524:9: warning: unused variable 'cnt' [-Wunused-variable]
int r, cnt, i, a, b;
^
../src/device.c:524:6: warning: unused variable 'r' [-Wunused-variable]
int r, cnt, i, a, b;
^
../src/device.c:523:22: warning: unused variable 'drvc' [-Wunused-variable]
struct drv_context *drvc;
^
2015-04-16 20:33:29 +00:00
|
|
|
#ifdef HAVE_LIBUSB_1_0
|
2014-10-16 18:17:04 +00:00
|
|
|
struct drv_context *drvc;
|
2015-09-19 15:58:22 +00:00
|
|
|
int cnt, i, a, b;
|
2014-10-26 19:51:21 +00:00
|
|
|
char connection_id[64];
|
2014-10-16 18:17:04 +00:00
|
|
|
struct sr_usb_dev_inst *usb;
|
|
|
|
struct libusb_device **devlist;
|
2014-10-26 19:51:21 +00:00
|
|
|
#endif
|
2014-10-16 18:17:04 +00:00
|
|
|
|
|
|
|
if (!sdi)
|
|
|
|
return NULL;
|
|
|
|
|
2014-10-26 19:51:21 +00:00
|
|
|
#ifdef HAVE_LIBSERIALPORT
|
2014-10-16 20:44:31 +00:00
|
|
|
struct sr_serial_dev_inst *serial;
|
|
|
|
|
|
|
|
if ((!sdi->connection_id) && (sdi->inst_type == SR_INST_SERIAL)) {
|
|
|
|
/* connection_id isn't populated, let's do that here. */
|
|
|
|
|
|
|
|
serial = sdi->conn;
|
2014-11-11 11:44:37 +00:00
|
|
|
((struct sr_dev_inst *)sdi)->connection_id = g_strdup(serial->port);
|
2014-10-16 20:44:31 +00:00
|
|
|
}
|
2014-10-26 19:51:21 +00:00
|
|
|
#endif
|
2014-10-16 20:44:31 +00:00
|
|
|
|
2014-10-26 19:51:21 +00:00
|
|
|
#ifdef HAVE_LIBUSB_1_0
|
2014-10-16 18:17:04 +00:00
|
|
|
if ((!sdi->connection_id) && (sdi->inst_type == SR_INST_USB)) {
|
|
|
|
/* connection_id isn't populated, let's do that here. */
|
|
|
|
|
2015-07-06 19:55:36 +00:00
|
|
|
drvc = sdi->driver->context;
|
2014-10-16 18:17:04 +00:00
|
|
|
usb = sdi->conn;
|
|
|
|
|
|
|
|
if ((cnt = libusb_get_device_list(drvc->sr_ctx->libusb_ctx, &devlist)) < 0) {
|
|
|
|
sr_err("Failed to retrieve device list: %s.",
|
|
|
|
libusb_error_name(cnt));
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < cnt; i++) {
|
|
|
|
/* Find the USB device by the logical address we know. */
|
|
|
|
b = libusb_get_bus_number(devlist[i]);
|
|
|
|
a = libusb_get_device_address(devlist[i]);
|
|
|
|
if (b != usb->bus || a != usb->address)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
usb_get_port_path(devlist[i], connection_id, sizeof(connection_id));
|
2014-11-11 11:44:37 +00:00
|
|
|
((struct sr_dev_inst *)sdi)->connection_id = g_strdup(connection_id);
|
2014-10-16 18:17:04 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
libusb_free_device_list(devlist, 1);
|
|
|
|
}
|
2014-10-26 19:51:21 +00:00
|
|
|
#endif
|
2014-10-16 18:17:04 +00:00
|
|
|
|
|
|
|
return sdi->connection_id;
|
|
|
|
}
|
|
|
|
|
2014-11-11 10:51:53 +00:00
|
|
|
/**
|
|
|
|
* Queries a device instances' channel list.
|
|
|
|
*
|
|
|
|
* @param sdi Device instance to use. Must not be NULL.
|
|
|
|
*
|
|
|
|
* @return The GSList of channels or NULL.
|
|
|
|
*/
|
2014-11-11 11:44:37 +00:00
|
|
|
SR_API GSList *sr_dev_inst_channels_get(const struct sr_dev_inst *sdi)
|
2014-11-11 10:51:53 +00:00
|
|
|
{
|
|
|
|
if (!sdi)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return sdi->channels;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Queries a device instances' channel groups list.
|
|
|
|
*
|
|
|
|
* @param sdi Device instance to use. Must not be NULL.
|
|
|
|
*
|
|
|
|
* @return The GSList of channel groups or NULL.
|
|
|
|
*/
|
2014-11-11 11:44:37 +00:00
|
|
|
SR_API GSList *sr_dev_inst_channel_groups_get(const struct sr_dev_inst *sdi)
|
2014-11-11 10:51:53 +00:00
|
|
|
{
|
|
|
|
if (!sdi)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return sdi->channel_groups;
|
|
|
|
}
|
|
|
|
|
2012-10-21 14:13:36 +00:00
|
|
|
/** @} */
|