]> sigrok.org Git - libsigrok.git/blame - src/hardware/yokogawa-dlm/api.c
Fix a few "value never read" scan-build warnings.
[libsigrok.git] / src / hardware / yokogawa-dlm / api.c
CommitLineData
10763937
SA
1/*
2 * This file is part of the libsigrok project.
3 *
4 * Copyright (C) 2014 abraxa (Soeren Apel) <soeren@apelpie.net>
5 * Based on the Hameg HMO driver by poljar (Damir Jelić) <poljarinho@gmail.com>
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
6ec6c43b 21#include <config.h>
10763937 22#include <stdlib.h>
5a1afc09 23#include "scpi.h"
10763937
SA
24#include "protocol.h"
25
8ab929d6 26SR_PRIV struct sr_dev_driver yokogawa_dlm_driver_info;
8ab929d6 27
329733d9
UH
28static const char *MANUFACTURER_ID = "YOKOGAWA";
29static const char *MANUFACTURER_NAME = "Yokogawa";
8ab929d6 30
f3c60fb6
SA
31static const uint32_t dlm_scanopts[] = {
32 SR_CONF_CONN,
33};
34
35static const uint32_t dlm_drvopts[] = {
cf0280fa
AJ
36 SR_CONF_LOGIC_ANALYZER,
37 SR_CONF_OSCILLOSCOPE,
38};
39
f3c60fb6
SA
40static const uint32_t dlm_devopts[] = {
41 SR_CONF_LIMIT_FRAMES | SR_CONF_GET | SR_CONF_SET,
42 SR_CONF_SAMPLERATE | SR_CONF_GET,
43 SR_CONF_TIMEBASE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
44 SR_CONF_NUM_HDIV | SR_CONF_GET,
45 SR_CONF_HORIZ_TRIGGERPOS | SR_CONF_GET | SR_CONF_SET,
46 SR_CONF_TRIGGER_SLOPE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
47 SR_CONF_TRIGGER_SOURCE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
48};
49
50static const uint32_t dlm_analog_devopts[] = {
51 SR_CONF_COUPLING | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
52 SR_CONF_VDIV | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
53 SR_CONF_NUM_VDIV | SR_CONF_GET,
54};
55
56static const uint32_t dlm_digital_devopts[] = {
57};
58
8ab929d6
SA
59enum {
60 CG_INVALID = -1,
61 CG_NONE,
62 CG_ANALOG,
63 CG_DIGITAL,
64};
65
4f840ce9 66static int init(struct sr_dev_driver *di, struct sr_context *sr_ctx)
8ab929d6
SA
67{
68 return std_init(sr_ctx, di, LOG_PREFIX);
69}
70
71static struct sr_dev_inst *probe_usbtmc_device(struct sr_scpi_dev_inst *scpi)
72{
73 struct sr_dev_inst *sdi;
74 struct dev_context *devc;
75 struct sr_scpi_hw_info *hw_info;
76 char *model_name;
77 int model_index;
78
79 sdi = NULL;
80 devc = NULL;
81 hw_info = NULL;
82
83 if (sr_scpi_get_hw_id(scpi, &hw_info) != SR_OK) {
84 sr_info("Couldn't get IDN response.");
85 goto fail;
86 }
87
88 if (strcmp(hw_info->manufacturer, MANUFACTURER_ID) != 0)
89 goto fail;
90
91 if (dlm_model_get(hw_info->model, &model_name, &model_index) != SR_OK)
92 goto fail;
93
aac29cc1 94 sdi = g_malloc0(sizeof(struct sr_dev_inst));
0af636be
UH
95 sdi->status = SR_ST_ACTIVE;
96 sdi->vendor = g_strdup(MANUFACTURER_NAME);
97 sdi->model = g_strdup(model_name);
98 sdi->version = g_strdup(hw_info->firmware_version);
8ab929d6 99
d1314831
SA
100 sdi->serial_num = g_strdup(hw_info->serial_number);
101
8ab929d6
SA
102 sr_scpi_hw_info_free(hw_info);
103 hw_info = NULL;
104
ac10a927 105 devc = g_malloc0(sizeof(struct dev_context));
8ab929d6 106
4f840ce9 107 sdi->driver = &yokogawa_dlm_driver_info;
8ab929d6
SA
108 sdi->priv = devc;
109 sdi->inst_type = SR_INST_SCPI;
110 sdi->conn = scpi;
111
112 if (dlm_device_init(sdi, model_index) != SR_OK)
113 goto fail;
114
115 sr_scpi_close(sdi->conn);
116
117 sdi->status = SR_ST_INACTIVE;
118 return sdi;
119
120fail:
121 if (hw_info)
122 sr_scpi_hw_info_free(hw_info);
123 if (sdi)
124 sr_dev_inst_free(sdi);
b1f83103 125 g_free(devc);
8ab929d6
SA
126
127 return NULL;
128}
129
4f840ce9 130static GSList *scan(struct sr_dev_driver *di, GSList *options)
8ab929d6 131{
41812aca 132 return sr_scpi_scan(di->context, options, probe_usbtmc_device);
8ab929d6
SA
133}
134
4f840ce9 135static GSList *dev_list(const struct sr_dev_driver *di)
8ab929d6 136{
41812aca 137 return ((struct drv_context *)(di->context))->instances;
8ab929d6
SA
138}
139
140static void clear_helper(void *priv)
141{
142 struct dev_context *devc;
143
144 devc = priv;
145
146 dlm_scope_state_destroy(devc->model_state);
147
148 g_free(devc->analog_groups);
149 g_free(devc->digital_groups);
150 g_free(devc);
151}
152
4f840ce9 153static int dev_clear(const struct sr_dev_driver *di)
8ab929d6
SA
154{
155 return std_dev_clear(di, clear_helper);
156}
157
158static int dev_open(struct sr_dev_inst *sdi)
159{
160 if (sdi->status != SR_ST_ACTIVE && sr_scpi_open(sdi->conn) != SR_OK)
161 return SR_ERR;
162
163 if (dlm_scope_state_query(sdi) != SR_OK)
164 return SR_ERR;
165
166 sdi->status = SR_ST_ACTIVE;
167
168 return SR_OK;
169}
170
171static int dev_close(struct sr_dev_inst *sdi)
172{
173 if (sdi->status == SR_ST_INACTIVE)
174 return SR_OK;
175
176 sr_scpi_close(sdi->conn);
177
178 sdi->status = SR_ST_INACTIVE;
179
180 return SR_OK;
181}
182
4f840ce9 183static int cleanup(const struct sr_dev_driver *di)
8ab929d6 184{
4f840ce9 185 dev_clear(di);
8ab929d6
SA
186
187 return SR_OK;
188}
189
190/**
191 * Check which category a given channel group belongs to.
192 *
193 * @param devc Our internal device context.
a9308652 194 * @param cg The channel group to check.
8ab929d6 195 *
a9308652
UH
196 * @retval CG_NONE cg is NULL
197 * @retval CG_ANALOG cg is an analog group
8ab929d6
SA
198 * @retval CG_DIGITAL cg is a digital group
199 * @retval CG_INVALID cg is something else
200 */
201static int check_channel_group(struct dev_context *devc,
ac10a927 202 const struct sr_channel_group *cg)
8ab929d6
SA
203{
204 unsigned int i;
329733d9 205 const struct scope_config *model;
8ab929d6
SA
206
207 model = devc->model_config;
208
209 if (!cg)
210 return CG_NONE;
211
a9308652 212 for (i = 0; i < model->analog_channels; i++)
8ab929d6
SA
213 if (cg == devc->analog_groups[i])
214 return CG_ANALOG;
215
a9308652 216 for (i = 0; i < model->pods; i++)
8ab929d6
SA
217 if (cg == devc->digital_groups[i])
218 return CG_DIGITAL;
219
220 sr_err("Invalid channel group specified.");
221 return CG_INVALID;
222}
223
584560f1 224static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
ac10a927 225 const struct sr_channel_group *cg)
8ab929d6
SA
226{
227 int ret, cg_type;
228 unsigned int i;
229 struct dev_context *devc;
329733d9 230 const struct scope_config *model;
8ab929d6
SA
231 struct scope_state *state;
232
233 if (!sdi || !(devc = sdi->priv))
234 return SR_ERR_ARG;
235
236 if ((cg_type = check_channel_group(devc, cg)) == CG_INVALID)
237 return SR_ERR;
238
8ab929d6
SA
239 model = devc->model_config;
240 state = devc->model_state;
241
242 switch (key) {
bf622e6d 243 case SR_CONF_NUM_HDIV:
8ab929d6
SA
244 *data = g_variant_new_int32(model->num_xdivs);
245 ret = SR_OK;
246 break;
247 case SR_CONF_TIMEBASE:
248 *data = g_variant_new("(tt)",
f3c60fb6
SA
249 dlm_timebases[state->timebase][0],
250 dlm_timebases[state->timebase][1]);
8ab929d6
SA
251 ret = SR_OK;
252 break;
253 case SR_CONF_NUM_VDIV:
254 if (cg_type == CG_NONE) {
255 sr_err("No channel group specified.");
256 return SR_ERR_CHANNEL_GROUP;
257 } else if (cg_type == CG_ANALOG) {
258 *data = g_variant_new_int32(model->num_ydivs);
259 ret = SR_OK;
260 break;
261 } else {
262 ret = SR_ERR_NA;
263 }
264 break;
265 case SR_CONF_VDIV:
266 ret = SR_ERR_NA;
267 if (cg_type == CG_NONE) {
268 sr_err("No channel group specified.");
269 return SR_ERR_CHANNEL_GROUP;
270 } else if (cg_type != CG_ANALOG)
271 break;
272
a9308652 273 for (i = 0; i < model->analog_channels; i++) {
8ab929d6
SA
274 if (cg != devc->analog_groups[i])
275 continue;
276 *data = g_variant_new("(tt)",
f3c60fb6
SA
277 dlm_vdivs[state->analog_states[i].vdiv][0],
278 dlm_vdivs[state->analog_states[i].vdiv][1]);
8ab929d6
SA
279 ret = SR_OK;
280 break;
281 }
282 break;
283 case SR_CONF_TRIGGER_SOURCE:
284 *data = g_variant_new_string((*model->trigger_sources)[state->trigger_source]);
285 ret = SR_OK;
286 break;
287 case SR_CONF_TRIGGER_SLOPE:
f3c60fb6 288 *data = g_variant_new_string(dlm_trigger_slopes[state->trigger_slope]);
8ab929d6
SA
289 ret = SR_OK;
290 break;
291 case SR_CONF_HORIZ_TRIGGERPOS:
292 *data = g_variant_new_double(state->horiz_triggerpos);
293 ret = SR_OK;
294 break;
295 case SR_CONF_COUPLING:
296 ret = SR_ERR_NA;
297 if (cg_type == CG_NONE) {
298 sr_err("No channel group specified.");
299 return SR_ERR_CHANNEL_GROUP;
300 } else if (cg_type != CG_ANALOG)
301 break;
302
a9308652 303 for (i = 0; i < model->analog_channels; i++) {
8ab929d6
SA
304 if (cg != devc->analog_groups[i])
305 continue;
306 *data = g_variant_new_string((*model->coupling_options)[state->analog_states[i].coupling]);
307 ret = SR_OK;
308 break;
309 }
310 break;
311 case SR_CONF_SAMPLERATE:
312 *data = g_variant_new_uint64(state->sample_rate);
313 ret = SR_OK;
314 break;
315 default:
316 ret = SR_ERR_NA;
317 }
318
319 return ret;
320}
321
322static GVariant *build_tuples(const uint64_t (*array)[][2], unsigned int n)
323{
324 unsigned int i;
325 GVariant *rational[2];
326 GVariantBuilder gvb;
327
328 g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
329
330 for (i = 0; i < n; i++) {
331 rational[0] = g_variant_new_uint64((*array)[i][0]);
332 rational[1] = g_variant_new_uint64((*array)[i][1]);
333
334 /* FIXME: Valgrind reports a memory leak here. */
335 g_variant_builder_add_value(&gvb, g_variant_new_tuple(rational, 2));
336 }
337
338 return g_variant_builder_end(&gvb);
339}
340
584560f1 341static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi,
ac10a927 342 const struct sr_channel_group *cg)
8ab929d6
SA
343{
344 int ret, cg_type;
345 unsigned int i, j;
346 char float_str[30];
347 struct dev_context *devc;
329733d9 348 const struct scope_config *model;
8ab929d6
SA
349 struct scope_state *state;
350 const char *tmp;
351 uint64_t p, q;
352 double tmp_d;
353 gboolean update_sample_rate;
354
355 if (!sdi || !(devc = sdi->priv))
356 return SR_ERR_ARG;
357
358 if ((cg_type = check_channel_group(devc, cg)) == CG_INVALID)
359 return SR_ERR;
360
361 model = devc->model_config;
362 state = devc->model_state;
363 update_sample_rate = FALSE;
364
365 ret = SR_ERR_NA;
366
367 switch (key) {
368 case SR_CONF_LIMIT_FRAMES:
369 devc->frame_limit = g_variant_get_uint64(data);
370 ret = SR_OK;
371 break;
372 case SR_CONF_TRIGGER_SOURCE:
373 tmp = g_variant_get_string(data, NULL);
374 for (i = 0; (*model->trigger_sources)[i]; i++) {
375 if (g_strcmp0(tmp, (*model->trigger_sources)[i]) != 0)
376 continue;
377 state->trigger_source = i;
378 /* TODO: A and B trigger support possible? */
379 ret = dlm_trigger_source_set(sdi->conn, (*model->trigger_sources)[i]);
380 break;
381 }
382 break;
383 case SR_CONF_VDIV:
384 if (cg_type == CG_NONE) {
385 sr_err("No channel group specified.");
386 return SR_ERR_CHANNEL_GROUP;
387 }
388
389 g_variant_get(data, "(tt)", &p, &q);
390
f3c60fb6
SA
391 for (i = 0; i < ARRAY_SIZE(dlm_vdivs); i++) {
392 if (p != dlm_vdivs[i][0] ||
393 q != dlm_vdivs[i][1])
8ab929d6 394 continue;
a9308652 395 for (j = 1; j <= model->analog_channels; j++) {
8ab929d6
SA
396 if (cg != devc->analog_groups[j - 1])
397 continue;
398 state->analog_states[j - 1].vdiv = i;
399 g_ascii_formatd(float_str, sizeof(float_str),
400 "%E", (float) p / q);
401 if (dlm_analog_chan_vdiv_set(sdi->conn, j, float_str) != SR_OK ||
ac10a927 402 sr_scpi_get_opc(sdi->conn) != SR_OK)
8ab929d6
SA
403 return SR_ERR;
404
405 break;
406 }
407
408 ret = SR_OK;
409 break;
410 }
411 break;
412 case SR_CONF_TIMEBASE:
413 g_variant_get(data, "(tt)", &p, &q);
414
f3c60fb6
SA
415 for (i = 0; i < ARRAY_SIZE(dlm_timebases); i++) {
416 if (p != dlm_timebases[i][0] ||
417 q != dlm_timebases[i][1])
8ab929d6
SA
418 continue;
419 state->timebase = i;
420 g_ascii_formatd(float_str, sizeof(float_str),
421 "%E", (float) p / q);
422 ret = dlm_timebase_set(sdi->conn, float_str);
423 update_sample_rate = TRUE;
424 break;
425 }
426 break;
427 case SR_CONF_HORIZ_TRIGGERPOS:
428 tmp_d = g_variant_get_double(data);
429
430 /* TODO: Check if the calculation makes sense for the DLM. */
431 if (tmp_d < 0.0 || tmp_d > 1.0)
432 return SR_ERR;
433
434 state->horiz_triggerpos = tmp_d;
435 tmp_d = -(tmp_d - 0.5) *
f3c60fb6
SA
436 ((double) dlm_timebases[state->timebase][0] /
437 dlm_timebases[state->timebase][1])
ac10a927 438 * model->num_xdivs;
8ab929d6
SA
439
440 g_ascii_formatd(float_str, sizeof(float_str), "%E", tmp_d);
441 ret = dlm_horiz_trigger_pos_set(sdi->conn, float_str);
442 break;
443 case SR_CONF_TRIGGER_SLOPE:
444 tmp = g_variant_get_string(data, NULL);
445
446 if (!tmp || !(tmp[0] == 'f' || tmp[0] == 'r'))
447 return SR_ERR_ARG;
448
449 /* Note: See dlm_trigger_slopes[] in protocol.c. */
450 state->trigger_slope = (tmp[0] == 'r') ?
451 SLOPE_POSITIVE : SLOPE_NEGATIVE;
452
453 ret = dlm_trigger_slope_set(sdi->conn, state->trigger_slope);
454 break;
455 case SR_CONF_COUPLING:
456 if (cg_type == CG_NONE) {
457 sr_err("No channel group specified.");
458 return SR_ERR_CHANNEL_GROUP;
459 }
460
461 tmp = g_variant_get_string(data, NULL);
462
463 for (i = 0; (*model->coupling_options)[i]; i++) {
464 if (strcmp(tmp, (*model->coupling_options)[i]) != 0)
465 continue;
a9308652 466 for (j = 1; j <= model->analog_channels; j++) {
8ab929d6
SA
467 if (cg != devc->analog_groups[j - 1])
468 continue;
469 state->analog_states[j-1].coupling = i;
470
471 if (dlm_analog_chan_coupl_set(sdi->conn, j, tmp) != SR_OK ||
ac10a927 472 sr_scpi_get_opc(sdi->conn) != SR_OK)
8ab929d6
SA
473 return SR_ERR;
474 break;
475 }
476
477 ret = SR_OK;
478 break;
479 }
480 break;
481 default:
482 ret = SR_ERR_NA;
483 break;
484 }
485
486 if (ret == SR_OK)
487 ret = sr_scpi_get_opc(sdi->conn);
488
489 if (ret == SR_OK && update_sample_rate)
490 ret = dlm_sample_rate_query(sdi);
491
492 return ret;
493}
494
c65a021c
SA
495static int config_channel_set(const struct sr_dev_inst *sdi,
496 struct sr_channel *ch, unsigned int changes)
497{
a9308652 498 /* Currently we only handle SR_CHANNEL_SET_ENABLED. */
c65a021c
SA
499 if (changes != SR_CHANNEL_SET_ENABLED)
500 return SR_ERR_NA;
501
502 return dlm_channel_state_set(sdi, ch->index, ch->enabled);
503}
504
584560f1 505static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
ac10a927 506 const struct sr_channel_group *cg)
8ab929d6 507{
cf0280fa
AJ
508 int cg_type = CG_NONE;
509 struct dev_context *devc = NULL;
329733d9 510 const struct scope_config *model = NULL;
8ab929d6 511
f3c60fb6
SA
512 /* SR_CONF_SCAN_OPTIONS is always valid, regardless of sdi or probe group. */
513 if (key == SR_CONF_SCAN_OPTIONS) {
514 *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
515 dlm_scanopts, ARRAY_SIZE(dlm_scanopts), sizeof(uint32_t));
516 return SR_OK;
517 }
8ab929d6 518
f3c60fb6
SA
519 /* If sdi is NULL, nothing except SR_CONF_DEVICE_OPTIONS can be provided. */
520 if (key == SR_CONF_DEVICE_OPTIONS && !sdi) {
521 *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
522 dlm_drvopts, ARRAY_SIZE(dlm_drvopts), sizeof(uint32_t));
523 return SR_OK;
cf0280fa 524 }
8ab929d6 525
f3c60fb6
SA
526 if (!sdi)
527 return SR_ERR_ARG;
528
529 devc = sdi->priv;
530 model = devc->model_config;
531
a9308652
UH
532 /*
533 * If cg is NULL, only the SR_CONF_DEVICE_OPTIONS that are not
534 * specific to a probe group must be returned.
535 */
f3c60fb6
SA
536 if (!cg) {
537 switch (key) {
538 case SR_CONF_DEVICE_OPTIONS:
539 *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
540 dlm_devopts, ARRAY_SIZE(dlm_devopts), sizeof(uint32_t));
541 return SR_OK;
542 case SR_CONF_TIMEBASE:
543 *data = build_tuples(&dlm_timebases, ARRAY_SIZE(dlm_timebases));
544 return SR_OK;
545 case SR_CONF_TRIGGER_SOURCE:
546 if (!model)
547 return SR_ERR_ARG;
548 *data = g_variant_new_strv(*model->trigger_sources,
549 g_strv_length((char **)*model->trigger_sources));
550 return SR_OK;
551 case SR_CONF_TRIGGER_SLOPE:
552 *data = g_variant_new_strv(dlm_trigger_slopes,
553 g_strv_length((char **)dlm_trigger_slopes));
554 return SR_OK;
555 case SR_CONF_NUM_HDIV:
49f49cb5 556 *data = g_variant_new_uint32(model->num_xdivs);
f3c60fb6
SA
557 return SR_OK;
558 default:
559 return SR_ERR_NA;
560 }
561 }
562
563 if ((cg_type = check_channel_group(devc, cg)) == CG_INVALID)
564 return SR_ERR;
565
8ab929d6 566 switch (key) {
8ab929d6 567 case SR_CONF_DEVICE_OPTIONS:
f3c60fb6 568 if (cg_type == CG_ANALOG) {
584560f1 569 *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
f3c60fb6
SA
570 dlm_analog_devopts, ARRAY_SIZE(dlm_analog_devopts), sizeof(uint32_t));
571 } else if (cg_type == CG_DIGITAL) {
572 *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
573 dlm_digital_devopts, ARRAY_SIZE(dlm_digital_devopts), sizeof(uint32_t));
8ab929d6 574 } else {
584560f1
BV
575 *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
576 NULL, 0, sizeof(uint32_t));
8ab929d6
SA
577 }
578 break;
579 case SR_CONF_COUPLING:
580 if (cg_type == CG_NONE)
581 return SR_ERR_CHANNEL_GROUP;
582 *data = g_variant_new_strv(*model->coupling_options,
ac10a927 583 g_strv_length((char **)*model->coupling_options));
8ab929d6 584 break;
8ab929d6
SA
585 case SR_CONF_VDIV:
586 if (cg_type == CG_NONE)
587 return SR_ERR_CHANNEL_GROUP;
f3c60fb6 588 *data = build_tuples(&dlm_vdivs, ARRAY_SIZE(dlm_vdivs));
8ab929d6
SA
589 break;
590 default:
591 return SR_ERR_NA;
592 }
593
594 return SR_OK;
595}
596
597static int dlm_check_channels(GSList *channels)
598{
599 GSList *l;
600 struct sr_channel *ch;
601 gboolean enabled_pod1, enabled_chan4;
602
603 enabled_pod1 = enabled_chan4 = FALSE;
604
605 /* Note: On the DLM2000, CH4 and Logic are shared. */
606 /* TODO Handle non-DLM2000 models. */
607 for (l = channels; l; l = l->next) {
608 ch = l->data;
609 switch (ch->type) {
610 case SR_CHANNEL_ANALOG:
611 if (ch->index == 3)
612 enabled_chan4 = TRUE;
613 break;
614 case SR_CHANNEL_LOGIC:
615 enabled_pod1 = TRUE;
616 break;
617 default:
618 return SR_ERR;
619 }
620 }
621
622 if (enabled_pod1 && enabled_chan4)
623 return SR_ERR;
624
625 return SR_OK;
626}
627
8ab929d6
SA
628static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
629{
630 GSList *l;
631 gboolean digital_added;
632 struct sr_channel *ch;
633 struct dev_context *devc;
634 struct sr_scpi_dev_inst *scpi;
635
636 (void)cb_data;
637
ac10a927
SA
638 if (sdi->status != SR_ST_ACTIVE)
639 return SR_ERR_DEV_CLOSED;
8ab929d6
SA
640
641 scpi = sdi->conn;
642 devc = sdi->priv;
643 digital_added = FALSE;
644
645 g_slist_free(devc->enabled_channels);
646 devc->enabled_channels = NULL;
647
648 for (l = sdi->channels; l; l = l->next) {
649 ch = l->data;
650 if (!ch->enabled)
651 continue;
652 /* Only add a single digital channel. */
653 if (ch->type != SR_CHANNEL_LOGIC || !digital_added) {
654 devc->enabled_channels = g_slist_append(
ac10a927
SA
655 devc->enabled_channels, ch);
656 if (ch->type == SR_CHANNEL_LOGIC)
657 digital_added = TRUE;
8ab929d6
SA
658 }
659 }
660
661 if (!devc->enabled_channels)
662 return SR_ERR;
663
664 if (dlm_check_channels(devc->enabled_channels) != SR_OK) {
665 sr_err("Invalid channel configuration specified!");
666 return SR_ERR_NA;
667 }
668
af3487ec
SA
669 /* Request data for the first enabled channel. */
670 devc->current_channel = devc->enabled_channels;
671 dlm_channel_data_request(sdi);
672
0028d5a1
SA
673 /* Call our callback when data comes in or after 5ms. */
674 sr_scpi_source_add(sdi->session, scpi, G_IO_IN, 5,
8ab929d6
SA
675 dlm_data_receive, (void *)sdi);
676
677 return SR_OK;
678}
679
680static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
681{
682 struct dev_context *devc;
8ab929d6
SA
683 struct sr_datafeed_packet packet;
684
685 (void)cb_data;
686
687 packet.type = SR_DF_END;
688 packet.payload = NULL;
689 sr_session_send(sdi, &packet);
690
691 if (sdi->status != SR_ST_ACTIVE)
692 return SR_ERR_DEV_CLOSED;
693
694 devc = sdi->priv;
695
696 devc->num_frames = 0;
697 g_slist_free(devc->enabled_channels);
698 devc->enabled_channels = NULL;
af3487ec
SA
699
700 sr_scpi_source_remove(sdi->session, sdi->conn);
8ab929d6
SA
701
702 return SR_OK;
703}
10763937
SA
704
705SR_PRIV struct sr_dev_driver yokogawa_dlm_driver_info = {
706 .name = "yokogawa-dlm",
ac10a927 707 .longname = "Yokogawa DL/DLM",
10763937 708 .api_version = 1,
8ab929d6
SA
709 .init = init,
710 .cleanup = cleanup,
711 .scan = scan,
712 .dev_list = dev_list,
713 .dev_clear = dev_clear,
714 .config_get = config_get,
715 .config_set = config_set,
c65a021c 716 .config_channel_set = config_channel_set,
8ab929d6
SA
717 .config_list = config_list,
718 .dev_open = dev_open,
719 .dev_close = dev_close,
720 .dev_acquisition_start = dev_acquisition_start,
721 .dev_acquisition_stop = dev_acquisition_stop,
41812aca 722 .context = NULL,
10763937 723};