]>
Commit | Line | Data |
---|---|---|
f4816ac6 ML |
1 | /* |
2 | * This file is part of the libsigrok project. | |
3 | * | |
4 | * Copyright (C) 2012 Martin Ling <martin-git@earth.li> | |
88e429c9 | 5 | * Copyright (C) 2013 Bert Vermeulen <bert@biot.com> |
f4816ac6 ML |
6 | * |
7 | * This program is free software: you can redistribute it and/or modify | |
8 | * it under the terms of the GNU General Public License as published by | |
9 | * the Free Software Foundation, either version 3 of the License, or | |
10 | * (at your option) any later version. | |
11 | * | |
12 | * This program is distributed in the hope that it will be useful, | |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | * GNU General Public License for more details. | |
16 | * | |
17 | * You should have received a copy of the GNU General Public License | |
18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 | */ | |
20 | ||
e0b7d23c ML |
21 | #include <fcntl.h> |
22 | #include <unistd.h> | |
23 | #include <stdlib.h> | |
24 | #include <string.h> | |
f4816ac6 ML |
25 | #include <glib.h> |
26 | #include "libsigrok.h" | |
27 | #include "libsigrok-internal.h" | |
28 | #include "protocol.h" | |
29 | ||
d62d7ad1 BV |
30 | #define NUM_TIMEBASE 12 |
31 | #define NUM_VDIV 8 | |
32 | ||
f6a0ac9f | 33 | static const int32_t hwcaps[] = { |
1953564a BV |
34 | SR_CONF_OSCILLOSCOPE, |
35 | SR_CONF_LIMIT_SAMPLES, | |
36 | SR_CONF_TIMEBASE, | |
37 | SR_CONF_TRIGGER_SOURCE, | |
38 | SR_CONF_TRIGGER_SLOPE, | |
39 | SR_CONF_HORIZ_TRIGGERPOS, | |
40 | SR_CONF_VDIV, | |
41 | SR_CONF_COUPLING, | |
d62d7ad1 BV |
42 | SR_CONF_NUM_TIMEBASE, |
43 | SR_CONF_NUM_VDIV, | |
e0b7d23c ML |
44 | }; |
45 | ||
f6a0ac9f | 46 | static const uint64_t timebases[][2] = { |
e0b7d23c ML |
47 | /* nanoseconds */ |
48 | { 2, 1000000000 }, | |
49 | { 5, 1000000000 }, | |
50 | { 10, 1000000000 }, | |
51 | { 20, 1000000000 }, | |
52 | { 50, 1000000000 }, | |
53 | { 100, 1000000000 }, | |
54 | { 500, 1000000000 }, | |
55 | /* microseconds */ | |
56 | { 1, 1000000 }, | |
57 | { 2, 1000000 }, | |
58 | { 5, 1000000 }, | |
59 | { 10, 1000000 }, | |
60 | { 20, 1000000 }, | |
61 | { 50, 1000000 }, | |
62 | { 100, 1000000 }, | |
63 | { 200, 1000000 }, | |
64 | { 500, 1000000 }, | |
65 | /* milliseconds */ | |
66 | { 1, 1000 }, | |
67 | { 2, 1000 }, | |
68 | { 5, 1000 }, | |
69 | { 10, 1000 }, | |
70 | { 20, 1000 }, | |
71 | { 50, 1000 }, | |
72 | { 100, 1000 }, | |
73 | { 200, 1000 }, | |
74 | { 500, 1000 }, | |
75 | /* seconds */ | |
76 | { 1, 1 }, | |
77 | { 2, 1 }, | |
78 | { 5, 1 }, | |
79 | { 10, 1 }, | |
80 | { 20, 1 }, | |
81 | { 50, 1 }, | |
e0b7d23c ML |
82 | }; |
83 | ||
f6a0ac9f | 84 | static const uint64_t vdivs[][2] = { |
e0b7d23c ML |
85 | /* millivolts */ |
86 | { 2, 1000 }, | |
87 | { 5, 1000 }, | |
88 | { 10, 1000 }, | |
89 | { 20, 1000 }, | |
90 | { 50, 1000 }, | |
91 | { 100, 1000 }, | |
92 | { 200, 1000 }, | |
93 | { 500, 1000 }, | |
94 | /* volts */ | |
95 | { 1, 1 }, | |
96 | { 2, 1 }, | |
97 | { 5, 1 }, | |
98 | { 10, 1 }, | |
e0b7d23c ML |
99 | }; |
100 | ||
101 | static const char *trigger_sources[] = { | |
102 | "CH1", | |
103 | "CH2", | |
104 | "EXT", | |
105 | "AC Line", | |
e0b7d23c ML |
106 | }; |
107 | ||
108 | static const char *coupling[] = { | |
109 | "AC", | |
110 | "DC", | |
111 | "GND", | |
e0b7d23c ML |
112 | }; |
113 | ||
512bb890 BV |
114 | static const char *supported_models[] = { |
115 | "DS1052E", | |
116 | "DS1102E", | |
117 | "DS1052D", | |
333bf022 | 118 | "DS1102D", |
512bb890 BV |
119 | }; |
120 | ||
f4816ac6 ML |
121 | SR_PRIV struct sr_dev_driver rigol_ds1xx2_driver_info; |
122 | static struct sr_dev_driver *di = &rigol_ds1xx2_driver_info; | |
123 | ||
124 | /* Properly close and free all devices. */ | |
125 | static int clear_instances(void) | |
126 | { | |
127 | struct sr_dev_inst *sdi; | |
128 | struct drv_context *drvc; | |
129 | struct dev_context *devc; | |
130 | GSList *l; | |
131 | ||
132 | if (!(drvc = di->priv)) | |
133 | return SR_OK; | |
134 | ||
135 | for (l = drvc->instances; l; l = l->next) { | |
136 | if (!(sdi = l->data)) | |
137 | continue; | |
138 | if (!(devc = sdi->priv)) | |
139 | continue; | |
140 | ||
fb6e5ba8 | 141 | g_free(devc->device); |
254dd102 BV |
142 | g_free(devc->coupling[0]); |
143 | g_free(devc->coupling[1]); | |
144 | g_free(devc->trigger_source); | |
145 | g_free(devc->trigger_slope); | |
e0b7d23c | 146 | close(devc->fd); |
f4816ac6 ML |
147 | |
148 | sr_dev_inst_free(sdi); | |
149 | } | |
150 | ||
151 | g_slist_free(drvc->instances); | |
152 | drvc->instances = NULL; | |
153 | ||
154 | return SR_OK; | |
155 | } | |
156 | ||
254dd102 BV |
157 | static int set_cfg(const struct sr_dev_inst *sdi, const char *format, ...) |
158 | { | |
159 | struct dev_context *devc; | |
254dd102 BV |
160 | va_list args; |
161 | char buf[256]; | |
162 | ||
163 | devc = sdi->priv; | |
164 | ||
165 | va_start(args, format); | |
166 | vsnprintf(buf, 255, format, args); | |
167 | va_end(args); | |
168 | if (rigol_ds1xx2_send(devc, buf) != SR_OK) | |
169 | return SR_ERR; | |
170 | ||
171 | /* When setting a bunch of parameters in a row, the DS1052E scrambles | |
172 | * some of them unless there is at least 100ms delay in between. */ | |
8f35be72 BV |
173 | sr_spew("delay %dms", 100); |
174 | g_usleep(100); | |
254dd102 BV |
175 | |
176 | return SR_OK; | |
177 | } | |
178 | ||
e0b7d23c | 179 | static int hw_init(struct sr_context *sr_ctx) |
f4816ac6 | 180 | { |
063e7aef | 181 | return std_hw_init(sr_ctx, di, DRIVER_LOG_DOMAIN); |
f4816ac6 ML |
182 | } |
183 | ||
184 | static GSList *hw_scan(GSList *options) | |
185 | { | |
186 | struct drv_context *drvc; | |
e0b7d23c ML |
187 | struct sr_dev_inst *sdi; |
188 | struct dev_context *devc; | |
189 | struct sr_probe *probe; | |
f4816ac6 | 190 | GSList *devices; |
fb6e5ba8 ML |
191 | GDir *dir; |
192 | const gchar *dev_name; | |
193 | const gchar *dev_dir = "/dev/"; | |
194 | const gchar *prefix = "usbtmc"; | |
195 | gchar *device; | |
196 | const gchar *idn_query = "*IDN?"; | |
f6a0ac9f BV |
197 | unsigned int i; |
198 | int len, num_tokens, fd; | |
fb6e5ba8 ML |
199 | const gchar *delimiter = ","; |
200 | gchar **tokens; | |
512bb890 | 201 | const char *manufacturer, *model, *version; |
512bb890 | 202 | gboolean matched = FALSE; |
fb6e5ba8 ML |
203 | char buf[256]; |
204 | ||
f4816ac6 ML |
205 | (void)options; |
206 | ||
f4816ac6 ML |
207 | drvc = di->priv; |
208 | drvc->instances = NULL; | |
209 | ||
4b97c74e UH |
210 | devices = NULL; |
211 | ||
fb6e5ba8 | 212 | dir = g_dir_open("/sys/class/usb/", 0, NULL); |
e0b7d23c | 213 | |
fb6e5ba8 ML |
214 | if (dir == NULL) |
215 | return NULL; | |
e0b7d23c | 216 | |
29d957ce | 217 | while ((dev_name = g_dir_read_name(dir)) != NULL) { |
fb6e5ba8 ML |
218 | if (strncmp(dev_name, prefix, strlen(prefix))) |
219 | continue; | |
220 | ||
221 | device = g_strconcat(dev_dir, dev_name, NULL); | |
222 | ||
223 | fd = open(device, O_RDWR); | |
224 | len = write(fd, idn_query, strlen(idn_query)); | |
225 | len = read(fd, buf, sizeof(buf)); | |
226 | close(fd); | |
29d957ce | 227 | if (len == 0) { |
fb6e5ba8 ML |
228 | g_free(device); |
229 | return NULL; | |
230 | } | |
231 | ||
232 | buf[len] = 0; | |
233 | tokens = g_strsplit(buf, delimiter, 0); | |
234 | close(fd); | |
512bb890 | 235 | sr_dbg("response: %s %d [%s]", device, len, buf); |
fb6e5ba8 ML |
236 | |
237 | for (num_tokens = 0; tokens[num_tokens] != NULL; num_tokens++); | |
238 | ||
512bb890 | 239 | if (num_tokens < 4) { |
fb6e5ba8 ML |
240 | g_strfreev(tokens); |
241 | g_free(device); | |
e0b7d23c | 242 | return NULL; |
fb6e5ba8 | 243 | } |
512bb890 BV |
244 | |
245 | manufacturer = tokens[0]; | |
246 | model = tokens[1]; | |
247 | version = tokens[3]; | |
248 | ||
249 | if (strcmp(manufacturer, "Rigol Technologies")) { | |
250 | g_strfreev(tokens); | |
251 | g_free(device); | |
252 | return NULL; | |
253 | } | |
254 | ||
333bf022 | 255 | for (i = 0; i < ARRAY_SIZE(supported_models); i++) { |
512bb890 BV |
256 | if (!strcmp(model, supported_models[i])) { |
257 | matched = 1; | |
258 | break; | |
259 | } | |
260 | } | |
261 | ||
262 | if (!matched || !(sdi = sr_dev_inst_new(0, SR_ST_ACTIVE, | |
263 | manufacturer, model, version))) { | |
264 | g_strfreev(tokens); | |
265 | g_free(device); | |
266 | return NULL; | |
267 | } | |
268 | ||
fb6e5ba8 ML |
269 | g_strfreev(tokens); |
270 | ||
29d957ce UH |
271 | if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) { |
272 | sr_err("Device context malloc failed."); | |
fb6e5ba8 ML |
273 | g_free(device); |
274 | return NULL; | |
275 | } | |
254dd102 | 276 | devc->limit_frames = 0; |
fb6e5ba8 | 277 | devc->device = device; |
fb6e5ba8 ML |
278 | sdi->priv = devc; |
279 | sdi->driver = di; | |
280 | ||
29d957ce UH |
281 | for (i = 0; i < 2; i++) { |
282 | if (!(probe = sr_probe_new(0, SR_PROBE_ANALOG, TRUE, | |
283 | i == 0 ? "CH1" : "CH2"))) | |
fb6e5ba8 ML |
284 | return NULL; |
285 | sdi->probes = g_slist_append(sdi->probes, probe); | |
286 | } | |
287 | ||
288 | drvc->instances = g_slist_append(drvc->instances, sdi); | |
289 | devices = g_slist_append(devices, sdi); | |
e0b7d23c | 290 | } |
fb6e5ba8 ML |
291 | |
292 | g_dir_close(dir); | |
f4816ac6 ML |
293 | |
294 | return devices; | |
295 | } | |
296 | ||
297 | static GSList *hw_dev_list(void) | |
298 | { | |
0e94d524 | 299 | return ((struct drv_context *)(di->priv))->instances; |
f4816ac6 ML |
300 | } |
301 | ||
302 | static int hw_dev_open(struct sr_dev_inst *sdi) | |
303 | { | |
29d957ce UH |
304 | struct dev_context *devc; |
305 | int fd; | |
fb6e5ba8 | 306 | |
29d957ce | 307 | devc = sdi->priv; |
e0b7d23c | 308 | |
29d957ce | 309 | if ((fd = open(devc->device, O_RDWR)) == -1) |
e0b7d23c | 310 | return SR_ERR; |
e0b7d23c ML |
311 | devc->fd = fd; |
312 | ||
254dd102 BV |
313 | if (rigol_ds1xx2_get_dev_cfg(sdi) != SR_OK) |
314 | /* TODO: force configuration? */ | |
315 | return SR_ERR; | |
f4816ac6 ML |
316 | |
317 | return SR_OK; | |
318 | } | |
319 | ||
320 | static int hw_dev_close(struct sr_dev_inst *sdi) | |
321 | { | |
29d957ce UH |
322 | struct dev_context *devc; |
323 | ||
324 | devc = sdi->priv; | |
e0b7d23c ML |
325 | |
326 | close(devc->fd); | |
f4816ac6 ML |
327 | |
328 | return SR_OK; | |
329 | } | |
330 | ||
331 | static int hw_cleanup(void) | |
332 | { | |
333 | clear_instances(); | |
334 | ||
f4816ac6 ML |
335 | return SR_OK; |
336 | } | |
337 | ||
d62d7ad1 BV |
338 | static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi) |
339 | { | |
340 | ||
341 | (void)sdi; | |
342 | ||
343 | switch (id) { | |
344 | case SR_CONF_NUM_TIMEBASE: | |
345 | *data = g_variant_new_int32(NUM_TIMEBASE); | |
346 | break; | |
347 | case SR_CONF_NUM_VDIV: | |
348 | *data = g_variant_new_int32(NUM_VDIV); | |
349 | break; | |
350 | default: | |
351 | return SR_ERR_ARG; | |
352 | } | |
353 | ||
354 | return SR_OK; | |
355 | } | |
356 | ||
f6a0ac9f | 357 | static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi) |
f4816ac6 | 358 | { |
29d957ce | 359 | struct dev_context *devc; |
f6a0ac9f | 360 | uint64_t tmp_u64, p, q; |
254dd102 | 361 | double t_dbl; |
f6a0ac9f | 362 | unsigned int i; |
254dd102 BV |
363 | int ret; |
364 | const char *tmp_str; | |
f4816ac6 | 365 | |
29d957ce UH |
366 | devc = sdi->priv; |
367 | ||
f4816ac6 ML |
368 | if (sdi->status != SR_ST_ACTIVE) { |
369 | sr_err("Device inactive, can't set config options."); | |
370 | return SR_ERR; | |
371 | } | |
372 | ||
373 | ret = SR_OK; | |
035a1078 | 374 | switch (id) { |
1953564a | 375 | case SR_CONF_LIMIT_FRAMES: |
f6a0ac9f | 376 | devc->limit_frames = g_variant_get_uint64(data); |
e0b7d23c | 377 | break; |
1953564a | 378 | case SR_CONF_TRIGGER_SLOPE: |
f6a0ac9f | 379 | tmp_u64 = g_variant_get_uint64(data); |
254dd102 BV |
380 | if (tmp_u64 != 0 && tmp_u64 != 1) |
381 | return SR_ERR; | |
382 | g_free(devc->trigger_slope); | |
383 | devc->trigger_slope = g_strdup(tmp_u64 ? "POS" : "NEG"); | |
384 | ret = set_cfg(sdi, ":TRIG:EDGE:SLOP %s", devc->trigger_slope); | |
e0b7d23c | 385 | break; |
1953564a | 386 | case SR_CONF_HORIZ_TRIGGERPOS: |
254dd102 BV |
387 | t_dbl = g_variant_get_double(data); |
388 | if (t_dbl < 0.0 || t_dbl > 1.0) | |
389 | return SR_ERR; | |
390 | devc->horiz_triggerpos = t_dbl; | |
391 | /* We have the trigger offset as a percentage of the frame, but | |
392 | * need to express this in seconds. */ | |
393 | t_dbl = -(devc->horiz_triggerpos - 0.5) * devc->timebase * NUM_TIMEBASE; | |
394 | ret = set_cfg(sdi, ":TIM:OFFS %.6f", t_dbl); | |
e0b7d23c | 395 | break; |
1953564a | 396 | case SR_CONF_TIMEBASE: |
f6a0ac9f | 397 | g_variant_get(data, "(tt)", &p, &q); |
f6a0ac9f BV |
398 | for (i = 0; i < ARRAY_SIZE(timebases); i++) { |
399 | if (timebases[i][0] == p && timebases[i][1] == q) { | |
254dd102 BV |
400 | devc->timebase = (float)p / q; |
401 | ret = set_cfg(sdi, ":TIM:SCAL %.9f", devc->timebase); | |
f6a0ac9f BV |
402 | break; |
403 | } | |
404 | } | |
254dd102 BV |
405 | if (i == ARRAY_SIZE(timebases)) |
406 | ret = SR_ERR_ARG; | |
e0b7d23c | 407 | break; |
1953564a | 408 | case SR_CONF_TRIGGER_SOURCE: |
f6a0ac9f | 409 | tmp_str = g_variant_get_string(data, NULL); |
254dd102 BV |
410 | for (i = 0; i < ARRAY_SIZE(trigger_sources); i++) { |
411 | if (!strcmp(trigger_sources[i], tmp_str)) { | |
412 | g_free(devc->trigger_source); | |
413 | devc->trigger_source = g_strdup(trigger_sources[i]); | |
414 | if (!strcmp(devc->trigger_source, "AC Line")) | |
415 | tmp_str = "ACL"; | |
416 | else if (!strcmp(devc->trigger_source, "CH1")) | |
417 | tmp_str = "CHAN1"; | |
418 | else if (!strcmp(devc->trigger_source, "CH2")) | |
419 | tmp_str = "CHAN2"; | |
420 | else | |
421 | tmp_str = (char *)devc->trigger_source; | |
422 | ret = set_cfg(sdi, ":TRIG:EDGE:SOUR %s", tmp_str); | |
423 | break; | |
424 | } | |
4e108ace | 425 | } |
254dd102 BV |
426 | if (i == ARRAY_SIZE(trigger_sources)) |
427 | ret = SR_ERR_ARG; | |
e0b7d23c | 428 | break; |
1953564a | 429 | case SR_CONF_VDIV: |
f6a0ac9f | 430 | g_variant_get(data, "(tt)", &p, &q); |
f6a0ac9f BV |
431 | for (i = 0; i < ARRAY_SIZE(vdivs); i++) { |
432 | if (vdivs[i][0] != p || vdivs[i][1] != q) | |
433 | continue; | |
254dd102 BV |
434 | devc->vdiv[0] = devc->vdiv[1] = (float)p / q; |
435 | set_cfg(sdi, ":CHAN1:SCAL %.3f", devc->vdiv[0]); | |
436 | ret = set_cfg(sdi, ":CHAN2:SCAL %.3f", devc->vdiv[1]); | |
f6a0ac9f | 437 | break; |
e0b7d23c | 438 | } |
f6a0ac9f | 439 | if (i == ARRAY_SIZE(vdivs)) |
e0b7d23c ML |
440 | ret = SR_ERR_ARG; |
441 | break; | |
1953564a | 442 | case SR_CONF_COUPLING: |
e0b7d23c | 443 | /* TODO: Not supporting coupling per channel yet. */ |
f6a0ac9f BV |
444 | tmp_str = g_variant_get_string(data, NULL); |
445 | for (i = 0; i < ARRAY_SIZE(coupling); i++) { | |
446 | if (!strcmp(tmp_str, coupling[i])) { | |
254dd102 BV |
447 | g_free(devc->coupling[0]); |
448 | g_free(devc->coupling[1]); | |
449 | devc->coupling[0] = g_strdup(coupling[i]); | |
450 | devc->coupling[1] = g_strdup(coupling[i]); | |
451 | set_cfg(sdi, ":CHAN1:COUP %s", devc->coupling[0]); | |
452 | ret = set_cfg(sdi, ":CHAN2:COUP %s", devc->coupling[1]); | |
e0b7d23c ML |
453 | break; |
454 | } | |
455 | } | |
f6a0ac9f | 456 | if (i == ARRAY_SIZE(coupling)) |
e0b7d23c ML |
457 | ret = SR_ERR_ARG; |
458 | break; | |
f4816ac6 | 459 | default: |
035a1078 | 460 | sr_err("Unknown hardware capability: %d.", id); |
f4816ac6 | 461 | ret = SR_ERR_ARG; |
29d957ce | 462 | break; |
f4816ac6 ML |
463 | } |
464 | ||
465 | return ret; | |
466 | } | |
467 | ||
f6a0ac9f | 468 | static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi) |
a1c743fc | 469 | { |
861c447b BV |
470 | GVariant *tuple, *rational[2]; |
471 | GVariantBuilder gvb; | |
472 | unsigned int i; | |
a1c743fc BV |
473 | |
474 | (void)sdi; | |
475 | ||
476 | switch (key) { | |
9a6517d1 | 477 | case SR_CONF_DEVICE_OPTIONS: |
f6a0ac9f BV |
478 | *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32, |
479 | hwcaps, ARRAY_SIZE(hwcaps), sizeof(int32_t)); | |
9a6517d1 | 480 | break; |
2a7b113d | 481 | case SR_CONF_COUPLING: |
169dbe85 UH |
482 | *data = g_variant_new_strv(coupling, ARRAY_SIZE(coupling)); |
483 | break; | |
e4f2b2ad | 484 | case SR_CONF_VDIV: |
861c447b BV |
485 | g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY); |
486 | for (i = 0; i < ARRAY_SIZE(vdivs); i++) { | |
487 | rational[0] = g_variant_new_uint64(vdivs[i][0]); | |
488 | rational[1] = g_variant_new_uint64(vdivs[i][1]); | |
489 | tuple = g_variant_new_tuple(rational, 2); | |
490 | g_variant_builder_add_value(&gvb, tuple); | |
491 | } | |
492 | *data = g_variant_builder_end(&gvb); | |
e4f2b2ad | 493 | break; |
41f5bd09 | 494 | case SR_CONF_TIMEBASE: |
861c447b BV |
495 | g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY); |
496 | for (i = 0; i < ARRAY_SIZE(timebases); i++) { | |
497 | rational[0] = g_variant_new_uint64(timebases[i][0]); | |
498 | rational[1] = g_variant_new_uint64(timebases[i][1]); | |
499 | tuple = g_variant_new_tuple(rational, 2); | |
500 | g_variant_builder_add_value(&gvb, tuple); | |
501 | } | |
502 | *data = g_variant_builder_end(&gvb); | |
41f5bd09 | 503 | break; |
328bafab | 504 | case SR_CONF_TRIGGER_SOURCE: |
f6a0ac9f BV |
505 | *data = g_variant_new_strv(trigger_sources, |
506 | ARRAY_SIZE(trigger_sources)); | |
328bafab | 507 | break; |
a1c743fc BV |
508 | default: |
509 | return SR_ERR_ARG; | |
510 | } | |
511 | ||
512 | return SR_OK; | |
513 | } | |
514 | ||
254dd102 | 515 | static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) |
f4816ac6 | 516 | { |
29d957ce | 517 | struct dev_context *devc; |
254dd102 BV |
518 | struct sr_probe *probe; |
519 | GSList *l; | |
520 | int probenum; | |
521 | char cmd[256]; | |
29d957ce | 522 | |
e0b7d23c ML |
523 | (void)cb_data; |
524 | ||
29d957ce UH |
525 | devc = sdi->priv; |
526 | ||
254dd102 BV |
527 | for (l = sdi->probes; l; l = l->next) { |
528 | probe = l->data; | |
529 | probenum = probe->name[2] == '1' ? 0 : 1; | |
530 | if (probe->enabled) | |
531 | devc->enabled_probes = g_slist_append(devc->enabled_probes, probe); | |
532 | ||
533 | if (probe->enabled != devc->channels[probenum]) { | |
534 | /* Enabled channel is currently disabled, or vice versa. */ | |
535 | sprintf(cmd, ":CHAN%d:DISP %s", probenum + 1, | |
536 | probe->enabled ? "ON" : "OFF"); | |
537 | if (rigol_ds1xx2_send(devc, cmd) != SR_OK) | |
538 | return SR_ERR; | |
539 | } | |
540 | } | |
541 | if (!devc->enabled_probes) | |
542 | return SR_ERR; | |
e0b7d23c | 543 | |
254dd102 | 544 | sr_source_add(devc->fd, G_IO_IN, 50, rigol_ds1xx2_receive, (void *)sdi); |
e0b7d23c ML |
545 | |
546 | /* Send header packet to the session bus. */ | |
4afdfd46 | 547 | std_session_send_df_header(cb_data, DRIVER_LOG_DOMAIN); |
e0b7d23c | 548 | |
254dd102 BV |
549 | /* Fetch the first frame. */ |
550 | devc->channel_frame = devc->enabled_probes->data; | |
551 | if (rigol_ds1xx2_send(devc, ":WAV:DATA? CHAN%c", | |
552 | devc->channel_frame->name[2]) != SR_OK) | |
553 | return SR_ERR; | |
f4816ac6 ML |
554 | |
555 | return SR_OK; | |
556 | } | |
557 | ||
254dd102 | 558 | static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data) |
f4816ac6 | 559 | { |
29d957ce UH |
560 | struct dev_context *devc; |
561 | ||
f4816ac6 ML |
562 | (void)cb_data; |
563 | ||
29d957ce UH |
564 | devc = sdi->priv; |
565 | ||
f4816ac6 ML |
566 | if (sdi->status != SR_ST_ACTIVE) { |
567 | sr_err("Device inactive, can't stop acquisition."); | |
568 | return SR_ERR; | |
569 | } | |
570 | ||
254dd102 BV |
571 | g_slist_free(devc->enabled_probes); |
572 | devc->enabled_probes = NULL; | |
e0b7d23c | 573 | sr_source_remove(devc->fd); |
f4816ac6 ML |
574 | |
575 | return SR_OK; | |
576 | } | |
577 | ||
578 | SR_PRIV struct sr_dev_driver rigol_ds1xx2_driver_info = { | |
579 | .name = "rigol-ds1xx2", | |
580 | .longname = "Rigol DS1xx2", | |
581 | .api_version = 1, | |
582 | .init = hw_init, | |
583 | .cleanup = hw_cleanup, | |
584 | .scan = hw_scan, | |
585 | .dev_list = hw_dev_list, | |
586 | .dev_clear = clear_instances, | |
d62d7ad1 | 587 | .config_get = config_get, |
035a1078 | 588 | .config_set = config_set, |
a1c743fc | 589 | .config_list = config_list, |
f4816ac6 ML |
590 | .dev_open = hw_dev_open, |
591 | .dev_close = hw_dev_close, | |
254dd102 BV |
592 | .dev_acquisition_start = dev_acquisition_start, |
593 | .dev_acquisition_stop = dev_acquisition_stop, | |
f4816ac6 ML |
594 | .priv = NULL, |
595 | }; |