2 * This file is part of the sigrok-cli project.
4 * Copyright (C) 2013 Bert Vermeulen <bert@biot.com>
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "sigrok-cli.h"
25 static void free_drvopts(struct sr_config
*src
)
27 g_variant_unref(src
->data
);
31 GSList
*device_scan(void)
33 struct sr_dev_driver
**drivers
, *driver
;
34 GSList
*drvopts
, *devices
, *tmpdevs
, *l
;
38 /* Caller specified driver. Use it. Only this one. */
39 if (!parse_driver(opt_drv
, &driver
, &drvopts
))
41 devices
= sr_driver_scan(driver
, drvopts
);
42 g_slist_free_full(drvopts
, (GDestroyNotify
)free_drvopts
);
43 } else if (opt_dont_scan
) {
44 /* No -d choice, and -D "don't scan" requested. Do nothing. */
47 /* No driver specified. Scan all available drivers. */
49 drivers
= sr_driver_list(sr_ctx
);
50 for (i
= 0; drivers
[i
]; i
++) {
52 if (sr_driver_init(sr_ctx
, driver
) != SR_OK
) {
53 g_critical("Failed to initialize driver.");
56 tmpdevs
= sr_driver_scan(driver
, NULL
);
57 for (l
= tmpdevs
; l
; l
= l
->next
)
58 devices
= g_slist_append(devices
, l
->data
);
59 g_slist_free(tmpdevs
);
67 * Lookup a channel group from its name.
69 * Uses the previously stored option value to lookup a channel group.
70 * Returns a reference to the channel group when the lookup succeeded,
71 * or #NULL after lookup failure, or #NULL for the global channel group
72 * (the device's global parameters). Emits an error message when the
73 * lookup failed while a channel group's name was specified.
75 * @param[in] sdi Device instance.
77 * @returns The channel group, or #NULL for failed lookup.
79 struct sr_channel_group
*lookup_channel_group(struct sr_dev_inst
*sdi
)
81 struct sr_channel_group
*cg
;
82 GSList
*l
, *channel_groups
;
84 if (!opt_channel_group
)
87 channel_groups
= sr_dev_inst_channel_groups_get(sdi
);
88 if (!channel_groups
) {
89 g_critical("This device does not have any channel groups.");
93 for (l
= channel_groups
; l
; l
= l
->next
) {
95 if (g_ascii_strcasecmp(opt_channel_group
, cg
->name
) != 0)
99 g_critical("Invalid channel group '%s'", opt_channel_group
);