extern struct sr_context *sr_ctx;
-/* Convert driver options hash to GSList of struct sr_config. */
-static GSList *hash_to_hwopt(GHashTable *hash)
-{
- struct sr_config *src;
- GList *gl, *keys;
- GSList *opts;
- char *key;
-
- keys = g_hash_table_get_keys(hash);
- opts = NULL;
- for (gl = keys; gl; gl = gl->next) {
- key = gl->data;
- src = g_malloc(sizeof(struct sr_config));
- if (opt_to_gvar(key, g_hash_table_lookup(hash, key), src) != 0)
- return NULL;
- opts = g_slist_append(opts, src);
- }
- g_list_free(keys);
-
- return opts;
-}
-
static void free_drvopts(struct sr_config *src)
{
g_variant_unref(src->data);
GSList *device_scan(void)
{
struct sr_dev_driver **drivers, *driver;
- GHashTable *drvargs;
GSList *drvopts, *devices, *tmpdevs, *l;
int i;
- char *drvname;
if (opt_drv) {
- drvargs = parse_generic_arg(opt_drv, TRUE);
- drvname = g_strdup(g_hash_table_lookup(drvargs, "sigrok_key"));
- g_hash_table_remove(drvargs, "sigrok_key");
- driver = NULL;
- drivers = sr_driver_list();
- for (i = 0; drivers[i]; i++) {
- if (strcmp(drivers[i]->name, drvname))
- continue;
- driver = drivers[i];
- }
- if (!driver) {
- g_critical("Driver %s not found.", drvname);
- g_hash_table_destroy(drvargs);
- g_free(drvname);
- return NULL;
- }
- g_free(drvname);
- if (sr_driver_init(sr_ctx, driver) != SR_OK) {
- g_critical("Failed to initialize driver.");
- g_hash_table_destroy(drvargs);
+ if (!parse_driver(opt_drv, &driver, &drvopts))
return NULL;
- }
- drvopts = NULL;
- if (g_hash_table_size(drvargs) > 0) {
- if (!(drvopts = hash_to_hwopt(drvargs))) {
- /* Unknown options, already logged. */
- g_hash_table_destroy(drvargs);
- return NULL;
- }
- }
- g_hash_table_destroy(drvargs);
devices = sr_driver_scan(driver, drvopts);
g_slist_free_full(drvopts, (GDestroyNotify)free_drvopts);
} else {
#include <string.h>
#include <glib.h>
+extern struct sr_context *sr_ctx;
+
struct sr_channel *find_channel(GSList *channellist, const char *channelname)
{
struct sr_channel *ch;
return ret;
}
+
+/* Convert driver options hash to GSList of struct sr_config. */
+static GSList *hash_to_hwopt(GHashTable *hash)
+{
+ struct sr_config *src;
+ GList *gl, *keys;
+ GSList *opts;
+ char *key;
+
+ keys = g_hash_table_get_keys(hash);
+ opts = NULL;
+ for (gl = keys; gl; gl = gl->next) {
+ key = gl->data;
+ src = g_malloc(sizeof(struct sr_config));
+ if (opt_to_gvar(key, g_hash_table_lookup(hash, key), src) != 0)
+ return NULL;
+ opts = g_slist_append(opts, src);
+ }
+ g_list_free(keys);
+
+ return opts;
+}
+
+int parse_driver(char *arg, struct sr_dev_driver **driver, GSList **drvopts)
+{
+ struct sr_dev_driver **drivers;
+ GHashTable *drvargs;
+ int i;
+ char *drvname;
+
+ drvargs = parse_generic_arg(arg, TRUE);
+
+ drvname = g_strdup(g_hash_table_lookup(drvargs, "sigrok_key"));
+ g_hash_table_remove(drvargs, "sigrok_key");
+ *driver = NULL;
+ drivers = sr_driver_list();
+ for (i = 0; drivers[i]; i++) {
+ if (strcmp(drivers[i]->name, drvname))
+ continue;
+ *driver = drivers[i];
+ }
+ if (!*driver) {
+ g_critical("Driver %s not found.", drvname);
+ g_hash_table_destroy(drvargs);
+ g_free(drvname);
+ return FALSE;
+ }
+ g_free(drvname);
+ if (sr_driver_init(sr_ctx, *driver) != SR_OK) {
+ g_critical("Failed to initialize driver.");
+ g_hash_table_destroy(drvargs);
+ return FALSE;
+ }
+
+ if (drvopts) {
+ *drvopts = NULL;
+ if (g_hash_table_size(drvargs) > 0) {
+ if (!(*drvopts = hash_to_hwopt(drvargs))) {
+ /* Unknown options, already logged. */
+ g_hash_table_destroy(drvargs);
+ return FALSE;
+ }
+ }
+ }
+
+ g_hash_table_destroy(drvargs);
+
+ return TRUE;
+}
+
}
+void show_drv_detail(struct sr_dev_driver *driver)
+{
+ const struct sr_config_info *srci;
+ GVariant *gvar_opts;
+ const uint32_t *opts;
+ gsize num_elements, i;
+
+ if ((sr_config_list(driver, NULL, NULL, SR_CONF_DEVICE_OPTIONS,
+ &gvar_opts) == SR_OK)) {
+ opts = g_variant_get_fixed_array(gvar_opts, &num_elements,
+ sizeof(uint32_t));
+ if (num_elements) {
+ printf("Driver functions:\n");
+ for (i = 0; i < num_elements; i++) {
+ if (!(srci = sr_config_info_get(opts[i] & SR_CONF_MASK)))
+ continue;
+ printf(" %s\n", srci->name);
+ }
+ }
+ g_variant_unref(gvar_opts);
+ }
+
+ if ((sr_config_list(driver, NULL, NULL, SR_CONF_SCAN_OPTIONS,
+ &gvar_opts) == SR_OK)) {
+ opts = g_variant_get_fixed_array(gvar_opts, &num_elements,
+ sizeof(uint32_t));
+ if (num_elements) {
+ printf("Scan options:\n");
+ for (i = 0; i < num_elements; i++) {
+ if (!(srci = sr_config_info_get(opts[i] & SR_CONF_MASK)))
+ continue;
+ printf(" %s\n", srci->id);
+ }
+ }
+ g_variant_unref(gvar_opts);
+ }
+}
+
void show_dev_detail(void)
{
+ struct sr_dev_driver *driver;
struct sr_dev_inst *sdi;
const struct sr_config_info *srci;
struct sr_channel *ch;
char *tmp_str, *s, c;
const char **stropts;
+ if (parse_driver(opt_drv, &driver, NULL)) {
+ /* A driver was specified, report driver-wide options now. */
+ show_drv_detail(driver);
+ }
+
if (!(devices = device_scan())) {
g_critical("No devices found.");
return;
return;
}
- if ((sr_config_list(sdi->driver, NULL, NULL, SR_CONF_SCAN_OPTIONS,
- &gvar_opts) == SR_OK)) {
- opts = g_variant_get_fixed_array(gvar_opts, &num_elements,
- sizeof(int32_t));
- printf("Supported driver options:\n");
- for (i = 0; i < num_elements; i++) {
- if (!(srci = sr_config_info_get(opts[i])))
- continue;
- printf(" %s\n", srci->id);
- }
- g_variant_unref(gvar_opts);
- }
-
/* Selected channels and channel group may affect which options are
* returned, or which values for them. */
select_channels(sdi);
GHashTable *parse_generic_arg(const char *arg, gboolean sep_first);
GHashTable *generic_arg_to_opt(const struct sr_option **opts, GHashTable *genargs);
int canon_cmp(const char *str1, const char *str2);
+int parse_driver(char *arg, struct sr_dev_driver **driver, GSList **drvopts);
/* anykey.c */
void add_anykey(struct sr_session *session);