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