]>
Commit | Line | Data |
---|---|---|
a1bb33af UH |
1 | /* |
2 | * This file is part of the sigrok project. | |
3 | * | |
4 | * Copyright (C) 2010 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 | ||
22b02383 | 20 | #include "config.h" |
a1bb33af UH |
21 | #include <stdlib.h> |
22 | #include <stdio.h> | |
23 | #include <sys/types.h> | |
24 | #include <dirent.h> | |
25 | #include <string.h> | |
26 | #include <glib.h> | |
62c82025 | 27 | #include <sigrok.h> |
a1bb33af | 28 | |
62c82025 | 29 | /* The list of loaded plugins lives here. */ |
a1bb33af UH |
30 | GSList *plugins; |
31 | ||
62c82025 UH |
32 | /* |
33 | * This enumerates which plugin capabilities correspond to user-settable | |
34 | * options. | |
35 | */ | |
a65de030 UH |
36 | /* TODO: This shouldn't be a global. */ |
37 | struct sr_hwcap_option sr_hwcap_options[] = { | |
5a2326a7 UH |
38 | {SR_HWCAP_SAMPLERATE, SR_T_UINT64, "Sample rate", "samplerate"}, |
39 | {SR_HWCAP_CAPTURE_RATIO, SR_T_UINT64, "Pre-trigger capture ratio", "captureratio"}, | |
40 | {SR_HWCAP_PATTERN_MODE, SR_T_CHAR, "Pattern generator mode", "patternmode"}, | |
49d0ce50 | 41 | {0, 0, NULL, NULL}, |
a1bb33af UH |
42 | }; |
43 | ||
a61b0e6a | 44 | #ifdef HAVE_LA_DEMO |
5c2d46d1 | 45 | extern struct sr_device_plugin demo_plugin_info; |
a61b0e6a | 46 | #endif |
960a75e4 | 47 | #ifdef HAVE_LA_SALEAE_LOGIC |
5c2d46d1 | 48 | extern struct sr_device_plugin saleae_logic_plugin_info; |
960a75e4 UH |
49 | #endif |
50 | #ifdef HAVE_LA_OLS | |
5c2d46d1 | 51 | extern struct sr_device_plugin ols_plugin_info; |
960a75e4 UH |
52 | #endif |
53 | #ifdef HAVE_LA_ZEROPLUS_LOGIC_CUBE | |
5c2d46d1 | 54 | extern struct sr_device_plugin zeroplus_logic_cube_plugin_info; |
960a75e4 | 55 | #endif |
5b907f9b | 56 | #ifdef HAVE_LA_ASIX_SIGMA |
5c2d46d1 | 57 | extern struct sr_device_plugin asix_sigma_plugin_info; |
5b907f9b | 58 | #endif |
f4314d7e UH |
59 | #ifdef HAVE_LA_CHRONOVU_LA8 |
60 | extern struct device_plugin chronovu_la8_plugin_info; | |
61 | #endif | |
bffed4fc | 62 | #ifdef HAVE_LA_LINK_MSO19 |
5c2d46d1 | 63 | extern struct sr_device_plugin link_mso19_plugin_info; |
bffed4fc | 64 | #endif |
6ed4f044 | 65 | #ifdef HAVE_LA_ALSA |
5c2d46d1 | 66 | extern struct sr_device_plugin alsa_plugin_info; |
6ed4f044 DR |
67 | #endif |
68 | ||
01cf8814 | 69 | |
49d0ce50 | 70 | /* TODO: No linked list needed, this can be a simple array. */ |
a1bb33af UH |
71 | int load_hwplugins(void) |
72 | { | |
a61b0e6a | 73 | #ifdef HAVE_LA_DEMO |
6239c175 | 74 | plugins = g_slist_append(plugins, (gpointer *)&demo_plugin_info); |
a61b0e6a | 75 | #endif |
960a75e4 | 76 | #ifdef HAVE_LA_SALEAE_LOGIC |
62c82025 | 77 | plugins = |
49d0ce50 | 78 | g_slist_append(plugins, (gpointer *)&saleae_logic_plugin_info); |
960a75e4 UH |
79 | #endif |
80 | #ifdef HAVE_LA_OLS | |
49d0ce50 | 81 | plugins = g_slist_append(plugins, (gpointer *)&ols_plugin_info); |
960a75e4 UH |
82 | #endif |
83 | #ifdef HAVE_LA_ZEROPLUS_LOGIC_CUBE | |
62c82025 | 84 | plugins = g_slist_append(plugins, |
49d0ce50 | 85 | (gpointer *)&zeroplus_logic_cube_plugin_info); |
960a75e4 | 86 | #endif |
5b907f9b | 87 | #ifdef HAVE_LA_ASIX_SIGMA |
28a35d8a | 88 | plugins = g_slist_append(plugins, (gpointer *)&asix_sigma_plugin_info); |
5b907f9b | 89 | #endif |
f4314d7e UH |
90 | #ifdef HAVE_LA_CHRONOVU_LA8 |
91 | plugins = g_slist_append(plugins, (gpointer *)&chronovu_la8_plugin_info); | |
92 | #endif | |
bffed4fc UH |
93 | #ifdef HAVE_LA_LINK_MSO19 |
94 | plugins = g_slist_append(plugins, (gpointer *)&link_mso19_plugin_info); | |
95 | #endif | |
6ed4f044 DR |
96 | #ifdef HAVE_LA_ALSA |
97 | plugins = g_slist_append(plugins, (gpointer *)&alsa_plugin_info); | |
98 | #endif | |
99 | ||
a1bb33af | 100 | |
e46b8fb1 | 101 | return SR_OK; |
a1bb33af UH |
102 | } |
103 | ||
ee4b6342 | 104 | GSList *sr_list_hwplugins(void) |
a1bb33af | 105 | { |
a1bb33af UH |
106 | return plugins; |
107 | } | |
108 | ||
a00ba012 | 109 | struct sr_device_instance *sr_device_instance_new(int index, int status, |
49d0ce50 | 110 | const char *vendor, const char *model, const char *version) |
a1bb33af | 111 | { |
a00ba012 | 112 | struct sr_device_instance *sdi; |
a1bb33af | 113 | |
a00ba012 | 114 | if (!(sdi = malloc(sizeof(struct sr_device_instance)))) |
a1bb33af UH |
115 | return NULL; |
116 | ||
117 | sdi->index = index; | |
118 | sdi->status = status; | |
119 | sdi->instance_type = -1; | |
4fe9a6da BV |
120 | sdi->vendor = vendor ? strdup(vendor) : NULL; |
121 | sdi->model = model ? strdup(model) : strdup("(unknown)"); | |
925dbf9f | 122 | sdi->version = version ? strdup(version) : NULL; |
01cf8814 | 123 | sdi->priv = NULL; |
a1bb33af UH |
124 | sdi->usb = NULL; |
125 | ||
126 | return sdi; | |
127 | } | |
128 | ||
d32d961d UH |
129 | struct sr_device_instance *sr_get_device_instance(GSList *device_instances, |
130 | int device_index) | |
a1bb33af | 131 | { |
a00ba012 | 132 | struct sr_device_instance *sdi; |
a1bb33af UH |
133 | GSList *l; |
134 | ||
62c82025 | 135 | for (l = device_instances; l; l = l->next) { |
a00ba012 | 136 | sdi = (struct sr_device_instance *)(l->data); |
62c82025 | 137 | if (sdi->index == device_index) |
a1bb33af UH |
138 | return sdi; |
139 | } | |
140 | g_warning("could not find device index %d instance", device_index); | |
141 | ||
142 | return NULL; | |
143 | } | |
144 | ||
a00ba012 | 145 | void sr_device_instance_free(struct sr_device_instance *sdi) |
a1bb33af | 146 | { |
62c82025 | 147 | switch (sdi->instance_type) { |
22b02383 | 148 | #ifdef HAVE_LIBUSB_1_0 |
5a2326a7 | 149 | case SR_USB_INSTANCE: |
6c290072 | 150 | sr_usb_device_instance_free(sdi->usb); |
a1bb33af | 151 | break; |
22b02383 | 152 | #endif |
5a2326a7 | 153 | case SR_SERIAL_INSTANCE: |
6c290072 | 154 | sr_serial_device_instance_free(sdi->serial); |
a1bb33af | 155 | break; |
49d0ce50 | 156 | default: |
62c82025 | 157 | /* No specific type, nothing extra to free. */ |
49d0ce50 | 158 | break; |
a1bb33af UH |
159 | } |
160 | ||
161 | free(sdi->vendor); | |
162 | free(sdi->model); | |
163 | free(sdi->version); | |
164 | free(sdi); | |
a1bb33af UH |
165 | } |
166 | ||
22b02383 UH |
167 | #ifdef HAVE_LIBUSB_1_0 |
168 | ||
6c290072 | 169 | struct sr_usb_device_instance *sr_usb_device_instance_new(uint8_t bus, |
62c82025 | 170 | uint8_t address, struct libusb_device_handle *hdl) |
a1bb33af | 171 | { |
6c290072 | 172 | struct sr_usb_device_instance *udi; |
a1bb33af | 173 | |
6c290072 | 174 | if (!(udi = malloc(sizeof(struct sr_usb_device_instance)))) |
a1bb33af UH |
175 | return NULL; |
176 | ||
177 | udi->bus = bus; | |
178 | udi->address = address; | |
49d0ce50 | 179 | udi->devhdl = hdl; /* TODO: Check if this is NULL? */ |
a1bb33af UH |
180 | |
181 | return udi; | |
182 | } | |
183 | ||
6c290072 | 184 | void sr_usb_device_instance_free(struct sr_usb_device_instance *usb) |
a1bb33af | 185 | { |
17e1afcb | 186 | /* Avoid compiler warnings. */ |
afc8e4de | 187 | usb = usb; |
a1bb33af | 188 | |
62c82025 | 189 | /* Nothing to do for this device instance type. */ |
a1bb33af UH |
190 | } |
191 | ||
22b02383 UH |
192 | #endif |
193 | ||
6c290072 | 194 | struct sr_serial_device_instance *sr_serial_device_instance_new( |
49d0ce50 | 195 | const char *port, int fd) |
a1bb33af | 196 | { |
6c290072 | 197 | struct sr_serial_device_instance *serial; |
a1bb33af | 198 | |
6c290072 | 199 | if (!(serial = malloc(sizeof(struct sr_serial_device_instance)))) |
a1bb33af UH |
200 | return NULL; |
201 | ||
202 | serial->port = strdup(port); | |
203 | serial->fd = fd; | |
204 | ||
205 | return serial; | |
206 | } | |
207 | ||
6c290072 | 208 | void sr_serial_device_instance_free(struct sr_serial_device_instance *serial) |
a1bb33af | 209 | { |
a1bb33af | 210 | free(serial->port); |
a1bb33af UH |
211 | } |
212 | ||
a65de030 | 213 | int sr_find_hwcap(int *capabilities, int hwcap) |
a1bb33af UH |
214 | { |
215 | int i; | |
216 | ||
49d0ce50 | 217 | for (i = 0; capabilities[i]; i++) { |
62c82025 | 218 | if (capabilities[i] == hwcap) |
a1bb33af | 219 | return TRUE; |
49d0ce50 | 220 | } |
a1bb33af UH |
221 | |
222 | return FALSE; | |
223 | } | |
224 | ||
a65de030 | 225 | struct sr_hwcap_option *sr_find_hwcap_option(int hwcap) |
a1bb33af | 226 | { |
a1bb33af UH |
227 | int i; |
228 | ||
a65de030 UH |
229 | for (i = 0; sr_hwcap_options[i].capability; i++) { |
230 | if (sr_hwcap_options[i].capability == hwcap) | |
231 | return &sr_hwcap_options[i]; | |
a1bb33af UH |
232 | } |
233 | ||
49d0ce50 | 234 | return NULL; |
a1bb33af UH |
235 | } |
236 | ||
544a4582 BV |
237 | /* unnecessary level of indirection follows. */ |
238 | ||
6f1be0a2 | 239 | void sr_source_remove(int fd) |
a1bb33af | 240 | { |
8a2efef2 | 241 | sr_session_source_remove(fd); |
a1bb33af UH |
242 | } |
243 | ||
6f1be0a2 | 244 | void sr_source_add(int fd, int events, int timeout, |
a887e3da | 245 | sr_receive_data_callback rcv_cb, void *user_data) |
a1bb33af | 246 | { |
8a2efef2 | 247 | sr_session_source_add(fd, events, timeout, rcv_cb, user_data); |
a1bb33af | 248 | } |