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