]>
Commit | Line | Data |
---|---|---|
2be182e6 BV |
1 | /* |
2 | * This file is part of the sigrok-cli project. | |
3 | * | |
4 | * Copyright (C) 2013 Bert Vermeulen <bert@biot.com> | |
5 | * | |
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. | |
10 | * | |
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. | |
15 | * | |
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/>. | |
18 | */ | |
19 | ||
20fb52e0 | 20 | #include "sigrok-cli.h" |
2be182e6 BV |
21 | #include "config.h" |
22 | #include <glib.h> | |
55de58a2 | 23 | #include <string.h> |
2be182e6 BV |
24 | |
25 | extern struct sr_context *sr_ctx; | |
2be182e6 | 26 | |
2be182e6 BV |
27 | static void free_drvopts(struct sr_config *src) |
28 | { | |
29 | g_variant_unref(src->data); | |
30 | g_free(src); | |
31 | } | |
32 | ||
33 | GSList *device_scan(void) | |
34 | { | |
35 | struct sr_dev_driver **drivers, *driver; | |
2be182e6 BV |
36 | GSList *drvopts, *devices, *tmpdevs, *l; |
37 | int i; | |
2be182e6 BV |
38 | |
39 | if (opt_drv) { | |
d75c8529 | 40 | if (!parse_driver(opt_drv, &driver, &drvopts)) |
2be182e6 | 41 | return NULL; |
2be182e6 BV |
42 | devices = sr_driver_scan(driver, drvopts); |
43 | g_slist_free_full(drvopts, (GDestroyNotify)free_drvopts); | |
44 | } else { | |
45 | /* No driver specified, let them all scan on their own. */ | |
46 | devices = NULL; | |
47 | drivers = sr_driver_list(); | |
48 | for (i = 0; drivers[i]; i++) { | |
49 | driver = drivers[i]; | |
50 | if (sr_driver_init(sr_ctx, driver) != SR_OK) { | |
51 | g_critical("Failed to initialize driver."); | |
52 | return NULL; | |
53 | } | |
54 | tmpdevs = sr_driver_scan(driver, NULL); | |
55 | for (l = tmpdevs; l; l = l->next) | |
56 | devices = g_slist_append(devices, l->data); | |
57 | g_slist_free(tmpdevs); | |
58 | } | |
59 | } | |
60 | ||
61 | return devices; | |
62 | } | |
63 | ||
ca50f4b3 | 64 | struct sr_channel_group *select_channel_group(struct sr_dev_inst *sdi) |
2be182e6 | 65 | { |
ca50f4b3 | 66 | struct sr_channel_group *cg; |
c6fa2b2e | 67 | GSList *l, *channel_groups; |
2be182e6 | 68 | |
ca50f4b3 | 69 | if (!opt_channel_group) |
2be182e6 BV |
70 | return NULL; |
71 | ||
c6fa2b2e UH |
72 | channel_groups = sr_dev_inst_channel_groups_get(sdi); |
73 | ||
74 | if (!channel_groups) { | |
ca50f4b3 | 75 | g_critical("This device does not have any channel groups."); |
2be182e6 BV |
76 | return NULL; |
77 | } | |
78 | ||
c6fa2b2e | 79 | for (l = channel_groups; l; l = l->next) { |
ca50f4b3 UH |
80 | cg = l->data; |
81 | if (!strcasecmp(opt_channel_group, cg->name)) { | |
82 | return cg; | |
2be182e6 BV |
83 | } |
84 | } | |
ac1e997d | 85 | g_critical("Invalid channel group '%s'", opt_channel_group); |
2be182e6 BV |
86 | |
87 | return NULL; | |
88 | } | |
89 |