2 * This file is part of the libsigrok project.
4 * Copyright (C) 2013 poljar (Damir Jelić) <poljarinho@gmail.com>
5 * Copyright (C) 2018 Guido Trentalancia <guido@trentalancia.com>
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.
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.
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/>.
27 SR_PRIV void hmo_queue_logic_data(struct dev_context *devc,
28 size_t group, GByteArray *pod_data);
29 SR_PRIV void hmo_send_logic_packet(struct sr_dev_inst *sdi,
30 struct dev_context *devc);
31 SR_PRIV void hmo_cleanup_logic_data(struct dev_context *devc);
33 static const char *hameg_scpi_dialect[] = {
34 [SCPI_CMD_GET_DIG_DATA] = ":FORM UINT,8;:POD%d:DATA?",
35 [SCPI_CMD_GET_TIMEBASE] = ":TIM:SCAL?",
36 [SCPI_CMD_SET_TIMEBASE] = ":TIM:SCAL %s",
37 [SCPI_CMD_GET_HORIZONTAL_DIV] = ":TIM:DIV?",
38 [SCPI_CMD_GET_COUPLING] = ":CHAN%d:COUP?",
39 [SCPI_CMD_SET_COUPLING] = ":CHAN%d:COUP %s",
40 [SCPI_CMD_GET_SAMPLE_RATE] = ":ACQ:SRAT?",
41 [SCPI_CMD_GET_ANALOG_DATA] = ":FORM:BORD %s;" \
42 ":FORM REAL,32;:CHAN%d:DATA?",
43 [SCPI_CMD_GET_VERTICAL_SCALE] = ":CHAN%d:SCAL?",
44 [SCPI_CMD_SET_VERTICAL_SCALE] = ":CHAN%d:SCAL %s",
45 [SCPI_CMD_GET_DIG_POD_STATE] = ":POD%d:STAT?",
46 [SCPI_CMD_SET_DIG_POD_STATE] = ":POD%d:STAT %d",
47 [SCPI_CMD_GET_TRIGGER_SLOPE] = ":TRIG:A:EDGE:SLOP?",
48 [SCPI_CMD_SET_TRIGGER_SLOPE] = ":TRIG:A:TYPE EDGE;:TRIG:A:EDGE:SLOP %s",
49 [SCPI_CMD_GET_TRIGGER_PATTERN] = ":TRIG:A:PATT:SOUR?",
50 [SCPI_CMD_SET_TRIGGER_PATTERN] = ":TRIG:A:TYPE LOGIC;" \
51 ":TRIG:A:PATT:FUNC AND;" \
52 ":TRIG:A:PATT:COND \"TRUE\";" \
53 ":TRIG:A:PATT:MODE OFF;" \
54 ":TRIG:A:PATT:SOUR \"%s\"",
55 [SCPI_CMD_GET_TRIGGER_SOURCE] = ":TRIG:A:SOUR?",
56 [SCPI_CMD_SET_TRIGGER_SOURCE] = ":TRIG:A:SOUR %s",
57 [SCPI_CMD_GET_DIG_CHAN_STATE] = ":LOG%d:STAT?",
58 [SCPI_CMD_SET_DIG_CHAN_STATE] = ":LOG%d:STAT %d",
59 [SCPI_CMD_GET_VERTICAL_OFFSET] = ":CHAN%d:POS?",
60 [SCPI_CMD_GET_HORIZ_TRIGGERPOS] = ":TIM:POS?",
61 [SCPI_CMD_SET_HORIZ_TRIGGERPOS] = ":TIM:POS %s",
62 [SCPI_CMD_GET_ANALOG_CHAN_STATE] = ":CHAN%d:STAT?",
63 [SCPI_CMD_SET_ANALOG_CHAN_STATE] = ":CHAN%d:STAT %d",
64 [SCPI_CMD_GET_PROBE_UNIT] = ":PROB%d:SET:ATT:UNIT?",
65 [SCPI_CMD_GET_DIG_POD_THRESHOLD] = ":POD%d:THR?",
66 [SCPI_CMD_SET_DIG_POD_THRESHOLD] = ":POD%d:THR %s",
67 [SCPI_CMD_GET_DIG_POD_USER_THRESHOLD] = ":POD%d:THR:UDL%d?",
68 [SCPI_CMD_SET_DIG_POD_USER_THRESHOLD] = ":POD%d:THR:UDL%d %s",
71 static const char *rohde_schwarz_log_not_pod_scpi_dialect[] = {
72 [SCPI_CMD_GET_DIG_DATA] = ":FORM UINT,8;:LOG%d:DATA?",
73 [SCPI_CMD_GET_TIMEBASE] = ":TIM:SCAL?",
74 [SCPI_CMD_SET_TIMEBASE] = ":TIM:SCAL %s",
75 [SCPI_CMD_GET_HORIZONTAL_DIV] = ":TIM:DIV?",
76 [SCPI_CMD_GET_COUPLING] = ":CHAN%d:COUP?",
77 [SCPI_CMD_SET_COUPLING] = ":CHAN%d:COUP %s",
78 [SCPI_CMD_GET_SAMPLE_RATE] = ":ACQ:SRAT?",
79 [SCPI_CMD_GET_ANALOG_DATA] = ":FORM:BORD %s;" \
80 ":FORM REAL,32;:CHAN%d:DATA?",
81 [SCPI_CMD_GET_VERTICAL_SCALE] = ":CHAN%d:SCAL?",
82 [SCPI_CMD_SET_VERTICAL_SCALE] = ":CHAN%d:SCAL %s",
83 [SCPI_CMD_GET_DIG_POD_STATE] = ":LOG%d:STAT?",
84 [SCPI_CMD_SET_DIG_POD_STATE] = ":LOG%d:STAT %d",
85 [SCPI_CMD_GET_TRIGGER_SLOPE] = ":TRIG:A:EDGE:SLOP?",
86 [SCPI_CMD_SET_TRIGGER_SLOPE] = ":TRIG:A:TYPE EDGE;:TRIG:A:EDGE:SLOP %s",
87 [SCPI_CMD_GET_TRIGGER_PATTERN] = ":TRIG:A:PATT:SOUR?",
88 [SCPI_CMD_SET_TRIGGER_PATTERN] = ":TRIG:A:TYPE LOGIC;" \
89 ":TRIG:A:PATT:FUNC AND;" \
90 ":TRIG:A:PATT:COND \"TRUE\";" \
91 ":TRIG:A:PATT:MODE OFF;" \
92 ":TRIG:A:PATT:SOUR \"%s\"",
93 [SCPI_CMD_GET_TRIGGER_SOURCE] = ":TRIG:A:SOUR?",
94 [SCPI_CMD_SET_TRIGGER_SOURCE] = ":TRIG:A:SOUR %s",
95 [SCPI_CMD_GET_DIG_CHAN_STATE] = ":LOG%d:STAT?",
96 [SCPI_CMD_SET_DIG_CHAN_STATE] = ":LOG%d:STAT %d",
97 [SCPI_CMD_GET_VERTICAL_OFFSET] = ":CHAN%d:POS?", /* Might not be supported on RTB200x... */
98 [SCPI_CMD_GET_HORIZ_TRIGGERPOS] = ":TIM:POS?",
99 [SCPI_CMD_SET_HORIZ_TRIGGERPOS] = ":TIM:POS %s",
100 [SCPI_CMD_GET_ANALOG_CHAN_STATE] = ":CHAN%d:STAT?",
101 [SCPI_CMD_SET_ANALOG_CHAN_STATE] = ":CHAN%d:STAT %d",
102 [SCPI_CMD_GET_PROBE_UNIT] = ":PROB%d:SET:ATT:UNIT?",
103 [SCPI_CMD_GET_DIG_POD_THRESHOLD] = ":DIG%d:TECH?",
104 [SCPI_CMD_SET_DIG_POD_THRESHOLD] = ":DIG%d:TECH %s",
105 [SCPI_CMD_GET_DIG_POD_USER_THRESHOLD] = ":DIG%d:THR?",
106 [SCPI_CMD_SET_DIG_POD_USER_THRESHOLD] = ":DIG%d:THR %s",
109 static const uint32_t devopts[] = {
110 SR_CONF_OSCILLOSCOPE,
111 SR_CONF_LIMIT_SAMPLES | SR_CONF_SET,
112 SR_CONF_LIMIT_FRAMES | SR_CONF_SET,
113 SR_CONF_SAMPLERATE | SR_CONF_GET,
114 SR_CONF_TIMEBASE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
115 SR_CONF_NUM_HDIV | SR_CONF_GET,
116 SR_CONF_HORIZ_TRIGGERPOS | SR_CONF_GET | SR_CONF_SET,
117 SR_CONF_TRIGGER_SOURCE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
118 SR_CONF_TRIGGER_SLOPE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
119 SR_CONF_TRIGGER_PATTERN | SR_CONF_GET | SR_CONF_SET,
122 static const uint32_t devopts_cg_analog[] = {
123 SR_CONF_NUM_VDIV | SR_CONF_GET,
124 SR_CONF_VDIV | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
125 SR_CONF_COUPLING | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
128 static const uint32_t devopts_cg_digital[] = {
129 SR_CONF_LOGIC_THRESHOLD | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
130 SR_CONF_LOGIC_THRESHOLD_CUSTOM | SR_CONF_GET | SR_CONF_SET,
133 static const char *coupling_options[] = {
134 "AC", // AC with 50 Ohm termination (152x, 202x, 30xx, 1202)
135 "ACL", // AC with 1 MOhm termination
136 "DC", // DC with 50 Ohm termination
137 "DCL", // DC with 1 MOhm termination
141 static const char *coupling_options_rtb200x[] = {
142 "ACL", // AC with 1 MOhm termination
143 "DCL", // DC with 1 MOhm termination
147 static const char *coupling_options_rtm300x[] = {
148 "ACL", // AC with 1 MOhm termination
149 "DC", // DC with 50 Ohm termination
150 "DCL", // DC with 1 MOhm termination
154 static const char *scope_trigger_slopes[] = {
160 /* Predefined logic thresholds. */
161 static const char *logic_threshold[] = {
166 "USER2", // overwritten by logic_threshold_custom, use USER1 for permanent setting
169 static const char *logic_threshold_rtb200x_rtm300x[] = {
173 "MAN", // overwritten by logic_threshold_custom
176 /* RTC1002, HMO Compact2 and HMO1002/HMO1202 */
177 static const char *an2_dig8_trigger_sources[] = {
179 "LINE", "EXT", "PATT", "BUS1", "BUS2",
180 "D0", "D1", "D2", "D3", "D4", "D5", "D6", "D7",
184 static const char *an2_dig16_trigger_sources[] = {
186 "LINE", "EXT", "PATT", "BUS1", "BUS2",
187 "D0", "D1", "D2", "D3", "D4", "D5", "D6", "D7",
188 "D8", "D9", "D10", "D11", "D12", "D13", "D14", "D15",
191 /* RTB2002 and RTM3002 */
192 static const char *an2_dig16_sbus_trigger_sources[] = {
194 "LINE", "EXT", "PATT", "SBUS1", "SBUS2",
195 "D0", "D1", "D2", "D3", "D4", "D5", "D6", "D7",
196 "D8", "D9", "D10", "D11", "D12", "D13", "D14", "D15",
200 static const char *an4_dig8_trigger_sources[] = {
201 "CH1", "CH2", "CH3", "CH4",
202 "LINE", "EXT", "PATT", "BUS1", "BUS2",
203 "D0", "D1", "D2", "D3", "D4", "D5", "D6", "D7",
206 /* HMO3xx4 and HMO2524 */
207 static const char *an4_dig16_trigger_sources[] = {
208 "CH1", "CH2", "CH3", "CH4",
209 "LINE", "EXT", "PATT", "BUS1", "BUS2",
210 "D0", "D1", "D2", "D3", "D4", "D5", "D6", "D7",
211 "D8", "D9", "D10", "D11", "D12", "D13", "D14", "D15",
214 /* RTB2004, RTM3004 and RTA4004 */
215 static const char *an4_dig16_sbus_trigger_sources[] = {
216 "CH1", "CH2", "CH3", "CH4",
217 "LINE", "EXT", "PATT", "SBUS1", "SBUS2",
218 "D0", "D1", "D2", "D3", "D4", "D5", "D6", "D7",
219 "D8", "D9", "D10", "D11", "D12", "D13", "D14", "D15",
222 static const uint64_t timebases[][2] = {
262 /* HMO Compact series (HMO722/724/1022/1024/1522/1524/2022/2024) do
263 * not support 1 ns timebase setting.
265 static const uint64_t timebases_hmo_compact[][2] = {
304 static const uint64_t vdivs[][2] = {
322 static const char *scope_analog_channel_names[] = {
323 "CH1", "CH2", "CH3", "CH4",
326 static const char *scope_digital_channel_names[] = {
327 "D0", "D1", "D2", "D3", "D4", "D5", "D6", "D7",
328 "D8", "D9", "D10", "D11", "D12", "D13", "D14", "D15",
331 static struct scope_config scope_models[] = {
333 /* HMO Compact2: HMO722/1022/1522/2022 support only 8 digital channels. */
334 .name = {"HMO722", "HMO1022", "HMO1522", "HMO2022", NULL},
335 .analog_channels = 2,
336 .digital_channels = 8,
338 .analog_names = &scope_analog_channel_names,
339 .digital_names = &scope_digital_channel_names,
342 .num_devopts = ARRAY_SIZE(devopts),
344 .devopts_cg_analog = &devopts_cg_analog,
345 .num_devopts_cg_analog = ARRAY_SIZE(devopts_cg_analog),
347 .devopts_cg_digital = &devopts_cg_digital,
348 .num_devopts_cg_digital = ARRAY_SIZE(devopts_cg_digital),
350 .coupling_options = &coupling_options,
351 .num_coupling_options = ARRAY_SIZE(coupling_options),
353 .logic_threshold = &logic_threshold,
354 .num_logic_threshold = ARRAY_SIZE(logic_threshold),
355 .logic_threshold_for_pod = TRUE,
357 .trigger_sources = &an2_dig8_trigger_sources,
358 .num_trigger_sources = ARRAY_SIZE(an2_dig8_trigger_sources),
360 .trigger_slopes = &scope_trigger_slopes,
361 .num_trigger_slopes = ARRAY_SIZE(scope_trigger_slopes),
363 .timebases = &timebases_hmo_compact,
364 .num_timebases = ARRAY_SIZE(timebases_hmo_compact),
367 .num_vdivs = ARRAY_SIZE(vdivs),
371 .scpi_dialect = &hameg_scpi_dialect,
374 /* RTC1002 and HMO1002/HMO1202 support only 8 digital channels. */
375 .name = {"RTC1002", "HMO1002", "HMO1202", NULL},
376 .analog_channels = 2,
377 .digital_channels = 8,
379 .analog_names = &scope_analog_channel_names,
380 .digital_names = &scope_digital_channel_names,
383 .num_devopts = ARRAY_SIZE(devopts),
385 .devopts_cg_analog = &devopts_cg_analog,
386 .num_devopts_cg_analog = ARRAY_SIZE(devopts_cg_analog),
388 .devopts_cg_digital = &devopts_cg_digital,
389 .num_devopts_cg_digital = ARRAY_SIZE(devopts_cg_digital),
391 .coupling_options = &coupling_options,
392 .num_coupling_options = ARRAY_SIZE(coupling_options),
394 .logic_threshold = &logic_threshold,
395 .num_logic_threshold = ARRAY_SIZE(logic_threshold),
396 .logic_threshold_for_pod = TRUE,
398 .trigger_sources = &an2_dig8_trigger_sources,
399 .num_trigger_sources = ARRAY_SIZE(an2_dig8_trigger_sources),
401 .trigger_slopes = &scope_trigger_slopes,
402 .num_trigger_slopes = ARRAY_SIZE(scope_trigger_slopes),
404 .timebases = &timebases,
405 .num_timebases = ARRAY_SIZE(timebases),
408 .num_vdivs = ARRAY_SIZE(vdivs),
412 .scpi_dialect = &hameg_scpi_dialect,
415 /* HMO3032/3042/3052/3522 support 16 digital channels. */
416 .name = {"HMO3032", "HMO3042", "HMO3052", "HMO3522", NULL},
417 .analog_channels = 2,
418 .digital_channels = 16,
420 .analog_names = &scope_analog_channel_names,
421 .digital_names = &scope_digital_channel_names,
424 .num_devopts = ARRAY_SIZE(devopts),
426 .devopts_cg_analog = &devopts_cg_analog,
427 .num_devopts_cg_analog = ARRAY_SIZE(devopts_cg_analog),
429 .devopts_cg_digital = &devopts_cg_digital,
430 .num_devopts_cg_digital = ARRAY_SIZE(devopts_cg_digital),
432 .coupling_options = &coupling_options,
433 .num_coupling_options = ARRAY_SIZE(coupling_options),
435 .logic_threshold = &logic_threshold,
436 .num_logic_threshold = ARRAY_SIZE(logic_threshold),
437 .logic_threshold_for_pod = TRUE,
439 .trigger_sources = &an2_dig16_trigger_sources,
440 .num_trigger_sources = ARRAY_SIZE(an2_dig16_trigger_sources),
442 .trigger_slopes = &scope_trigger_slopes,
443 .num_trigger_slopes = ARRAY_SIZE(scope_trigger_slopes),
445 .timebases = &timebases,
446 .num_timebases = ARRAY_SIZE(timebases),
449 .num_vdivs = ARRAY_SIZE(vdivs),
453 .scpi_dialect = &hameg_scpi_dialect,
456 /* HMO Compact4: HMO724/1024/1524/2024 support only 8 digital channels. */
457 .name = {"HMO724", "HMO1024", "HMO1524", "HMO2024", NULL},
458 .analog_channels = 4,
459 .digital_channels = 8,
461 .analog_names = &scope_analog_channel_names,
462 .digital_names = &scope_digital_channel_names,
465 .num_devopts = ARRAY_SIZE(devopts),
467 .devopts_cg_analog = &devopts_cg_analog,
468 .num_devopts_cg_analog = ARRAY_SIZE(devopts_cg_analog),
470 .devopts_cg_digital = &devopts_cg_digital,
471 .num_devopts_cg_digital = ARRAY_SIZE(devopts_cg_digital),
473 .coupling_options = &coupling_options,
474 .num_coupling_options = ARRAY_SIZE(coupling_options),
476 .logic_threshold = &logic_threshold,
477 .num_logic_threshold = ARRAY_SIZE(logic_threshold),
478 .logic_threshold_for_pod = TRUE,
480 .trigger_sources = &an4_dig8_trigger_sources,
481 .num_trigger_sources = ARRAY_SIZE(an4_dig8_trigger_sources),
483 .trigger_slopes = &scope_trigger_slopes,
484 .num_trigger_slopes = ARRAY_SIZE(scope_trigger_slopes),
486 .timebases = &timebases_hmo_compact,
487 .num_timebases = ARRAY_SIZE(timebases_hmo_compact),
490 .num_vdivs = ARRAY_SIZE(vdivs),
494 .scpi_dialect = &hameg_scpi_dialect,
497 .name = {"HMO2524", "HMO3034", "HMO3044", "HMO3054", "HMO3524", NULL},
498 .analog_channels = 4,
499 .digital_channels = 16,
501 .analog_names = &scope_analog_channel_names,
502 .digital_names = &scope_digital_channel_names,
505 .num_devopts = ARRAY_SIZE(devopts),
507 .devopts_cg_analog = &devopts_cg_analog,
508 .num_devopts_cg_analog = ARRAY_SIZE(devopts_cg_analog),
510 .devopts_cg_digital = &devopts_cg_digital,
511 .num_devopts_cg_digital = ARRAY_SIZE(devopts_cg_digital),
513 .coupling_options = &coupling_options,
514 .num_coupling_options = ARRAY_SIZE(coupling_options),
516 .logic_threshold = &logic_threshold,
517 .num_logic_threshold = ARRAY_SIZE(logic_threshold),
518 .logic_threshold_for_pod = TRUE,
520 .trigger_sources = &an4_dig16_trigger_sources,
521 .num_trigger_sources = ARRAY_SIZE(an4_dig16_trigger_sources),
523 .trigger_slopes = &scope_trigger_slopes,
524 .num_trigger_slopes = ARRAY_SIZE(scope_trigger_slopes),
526 .timebases = &timebases,
527 .num_timebases = ARRAY_SIZE(timebases),
530 .num_vdivs = ARRAY_SIZE(vdivs),
534 .scpi_dialect = &hameg_scpi_dialect,
537 .name = {"RTB2002", NULL},
538 .analog_channels = 2,
539 .digital_channels = 16,
541 .analog_names = &scope_analog_channel_names,
542 .digital_names = &scope_digital_channel_names,
545 .num_devopts = ARRAY_SIZE(devopts),
547 .devopts_cg_analog = &devopts_cg_analog,
548 .num_devopts_cg_analog = ARRAY_SIZE(devopts_cg_analog),
550 .devopts_cg_digital = &devopts_cg_digital,
551 .num_devopts_cg_digital = ARRAY_SIZE(devopts_cg_digital),
553 .coupling_options = &coupling_options_rtb200x,
554 .num_coupling_options = ARRAY_SIZE(coupling_options_rtb200x),
556 .logic_threshold = &logic_threshold_rtb200x_rtm300x,
557 .num_logic_threshold = ARRAY_SIZE(logic_threshold_rtb200x_rtm300x),
558 .logic_threshold_for_pod = FALSE,
560 .trigger_sources = &an2_dig16_sbus_trigger_sources,
561 .num_trigger_sources = ARRAY_SIZE(an2_dig16_sbus_trigger_sources),
563 .trigger_slopes = &scope_trigger_slopes,
564 .num_trigger_slopes = ARRAY_SIZE(scope_trigger_slopes),
566 .timebases = &timebases,
567 .num_timebases = ARRAY_SIZE(timebases),
570 .num_vdivs = ARRAY_SIZE(vdivs),
574 .scpi_dialect = &rohde_schwarz_log_not_pod_scpi_dialect,
577 .name = {"RTB2004", NULL},
578 .analog_channels = 4,
579 .digital_channels = 16,
581 .analog_names = &scope_analog_channel_names,
582 .digital_names = &scope_digital_channel_names,
585 .num_devopts = ARRAY_SIZE(devopts),
587 .devopts_cg_analog = &devopts_cg_analog,
588 .num_devopts_cg_analog = ARRAY_SIZE(devopts_cg_analog),
590 .devopts_cg_digital = &devopts_cg_digital,
591 .num_devopts_cg_digital = ARRAY_SIZE(devopts_cg_digital),
593 .coupling_options = &coupling_options_rtb200x,
594 .num_coupling_options = ARRAY_SIZE(coupling_options_rtb200x),
596 .logic_threshold = &logic_threshold_rtb200x_rtm300x,
597 .num_logic_threshold = ARRAY_SIZE(logic_threshold_rtb200x_rtm300x),
598 .logic_threshold_for_pod = FALSE,
600 .trigger_sources = &an4_dig16_sbus_trigger_sources,
601 .num_trigger_sources = ARRAY_SIZE(an4_dig16_sbus_trigger_sources),
603 .trigger_slopes = &scope_trigger_slopes,
604 .num_trigger_slopes = ARRAY_SIZE(scope_trigger_slopes),
606 .timebases = &timebases,
607 .num_timebases = ARRAY_SIZE(timebases),
610 .num_vdivs = ARRAY_SIZE(vdivs),
614 .scpi_dialect = &rohde_schwarz_log_not_pod_scpi_dialect,
617 .name = {"RTM3002", NULL},
618 .analog_channels = 2,
619 .digital_channels = 16,
621 .analog_names = &scope_analog_channel_names,
622 .digital_names = &scope_digital_channel_names,
625 .num_devopts = ARRAY_SIZE(devopts),
627 .devopts_cg_analog = &devopts_cg_analog,
628 .num_devopts_cg_analog = ARRAY_SIZE(devopts_cg_analog),
630 .devopts_cg_digital = &devopts_cg_digital,
631 .num_devopts_cg_digital = ARRAY_SIZE(devopts_cg_digital),
633 .coupling_options = &coupling_options_rtm300x,
634 .num_coupling_options = ARRAY_SIZE(coupling_options_rtm300x),
636 .logic_threshold = &logic_threshold_rtb200x_rtm300x,
637 .num_logic_threshold = ARRAY_SIZE(logic_threshold_rtb200x_rtm300x),
638 .logic_threshold_for_pod = FALSE,
640 .trigger_sources = &an2_dig16_sbus_trigger_sources,
641 .num_trigger_sources = ARRAY_SIZE(an2_dig16_sbus_trigger_sources),
643 .trigger_slopes = &scope_trigger_slopes,
644 .num_trigger_slopes = ARRAY_SIZE(scope_trigger_slopes),
646 .timebases = &timebases,
647 .num_timebases = ARRAY_SIZE(timebases),
650 .num_vdivs = ARRAY_SIZE(vdivs),
654 .scpi_dialect = &rohde_schwarz_log_not_pod_scpi_dialect,
657 .name = {"RTM3004", NULL},
658 .analog_channels = 4,
659 .digital_channels = 16,
661 .analog_names = &scope_analog_channel_names,
662 .digital_names = &scope_digital_channel_names,
665 .num_devopts = ARRAY_SIZE(devopts),
667 .devopts_cg_analog = &devopts_cg_analog,
668 .num_devopts_cg_analog = ARRAY_SIZE(devopts_cg_analog),
670 .devopts_cg_digital = &devopts_cg_digital,
671 .num_devopts_cg_digital = ARRAY_SIZE(devopts_cg_digital),
673 .coupling_options = &coupling_options_rtm300x,
674 .num_coupling_options = ARRAY_SIZE(coupling_options_rtm300x),
676 .logic_threshold = &logic_threshold_rtb200x_rtm300x,
677 .num_logic_threshold = ARRAY_SIZE(logic_threshold_rtb200x_rtm300x),
678 .logic_threshold_for_pod = FALSE,
680 .trigger_sources = &an4_dig16_sbus_trigger_sources,
681 .num_trigger_sources = ARRAY_SIZE(an4_dig16_sbus_trigger_sources),
683 .trigger_slopes = &scope_trigger_slopes,
684 .num_trigger_slopes = ARRAY_SIZE(scope_trigger_slopes),
686 .timebases = &timebases,
687 .num_timebases = ARRAY_SIZE(timebases),
690 .num_vdivs = ARRAY_SIZE(vdivs),
694 .scpi_dialect = &rohde_schwarz_log_not_pod_scpi_dialect,
697 .name = {"RTA4004", NULL},
698 .analog_channels = 4,
699 .digital_channels = 16,
701 .analog_names = &scope_analog_channel_names,
702 .digital_names = &scope_digital_channel_names,
705 .num_devopts = ARRAY_SIZE(devopts),
707 .devopts_cg_analog = &devopts_cg_analog,
708 .num_devopts_cg_analog = ARRAY_SIZE(devopts_cg_analog),
710 .devopts_cg_digital = &devopts_cg_digital,
711 .num_devopts_cg_digital = ARRAY_SIZE(devopts_cg_digital),
713 .coupling_options = &coupling_options_rtm300x,
714 .num_coupling_options = ARRAY_SIZE(coupling_options_rtm300x),
716 .logic_threshold = &logic_threshold_rtb200x_rtm300x,
717 .num_logic_threshold = ARRAY_SIZE(logic_threshold_rtb200x_rtm300x),
718 .logic_threshold_for_pod = FALSE,
720 .trigger_sources = &an4_dig16_sbus_trigger_sources,
721 .num_trigger_sources = ARRAY_SIZE(an4_dig16_sbus_trigger_sources),
723 .trigger_slopes = &scope_trigger_slopes,
724 .num_trigger_slopes = ARRAY_SIZE(scope_trigger_slopes),
726 .timebases = &timebases,
727 .num_timebases = ARRAY_SIZE(timebases),
730 .num_vdivs = ARRAY_SIZE(vdivs),
734 .scpi_dialect = &rohde_schwarz_log_not_pod_scpi_dialect,
738 static void scope_state_dump(const struct scope_config *config,
739 struct scope_state *state)
744 for (i = 0; i < config->analog_channels; i++) {
745 tmp = sr_voltage_string((*config->vdivs)[state->analog_channels[i].vdiv][0],
746 (*config->vdivs)[state->analog_channels[i].vdiv][1]);
747 sr_info("State of analog channel %d -> %s : %s (coupling) %s (vdiv) %2.2e (offset)",
748 i + 1, state->analog_channels[i].state ? "On" : "Off",
749 (*config->coupling_options)[state->analog_channels[i].coupling],
750 tmp, state->analog_channels[i].vertical_offset);
753 for (i = 0; i < config->digital_channels; i++) {
754 sr_info("State of digital channel %d -> %s", i,
755 state->digital_channels[i] ? "On" : "Off");
758 for (i = 0; i < config->digital_pods; i++) {
759 if (!strncmp("USER", (*config->logic_threshold)[state->digital_pods[i].threshold], 4) ||
760 !strcmp("MAN", (*config->logic_threshold)[state->digital_pods[i].threshold]))
761 sr_info("State of digital POD %d -> %s : %E (threshold)", i + 1,
762 state->digital_pods[i].state ? "On" : "Off",
763 state->digital_pods[i].user_threshold);
765 sr_info("State of digital POD %d -> %s : %s (threshold)", i + 1,
766 state->digital_pods[i].state ? "On" : "Off",
767 (*config->logic_threshold)[state->digital_pods[i].threshold]);
770 tmp = sr_period_string((*config->timebases)[state->timebase][0],
771 (*config->timebases)[state->timebase][1]);
772 sr_info("Current timebase: %s", tmp);
775 tmp = sr_samplerate_string(state->sample_rate);
776 sr_info("Current samplerate: %s", tmp);
779 if (!strcmp("PATT", (*config->trigger_sources)[state->trigger_source]))
780 sr_info("Current trigger: %s (pattern), %.2f (offset)",
781 state->trigger_pattern,
782 state->horiz_triggerpos);
783 else // Edge (slope) trigger
784 sr_info("Current trigger: %s (source), %s (slope) %.2f (offset)",
785 (*config->trigger_sources)[state->trigger_source],
786 (*config->trigger_slopes)[state->trigger_slope],
787 state->horiz_triggerpos);
790 static int scope_state_get_array_option(struct sr_scpi_dev_inst *scpi,
791 const char *command, const char *(*array)[], unsigned int n, int *result)
796 if (sr_scpi_get_string(scpi, command, &tmp) != SR_OK)
799 if ((idx = std_str_idx_s(tmp, *array, n)) < 0) {
812 * This function takes a value of the form "2.000E-03" and returns the index
813 * of an array where a matching pair was found.
815 * @param value The string to be parsed.
816 * @param array The array of s/f pairs.
817 * @param array_len The number of pairs in the array.
818 * @param result The index at which a matching pair was found.
820 * @return SR_ERR on any parsing error, SR_OK otherwise.
822 static int array_float_get(gchar *value, const uint64_t array[][2],
823 int array_len, unsigned int *result)
825 struct sr_rational rval;
826 struct sr_rational aval;
828 if (sr_parse_rational(value, &rval) != SR_OK)
831 for (int i = 0; i < array_len; i++) {
832 sr_rational_set(&aval, array[i][0], array[i][1]);
833 if (sr_rational_eq(&rval, &aval)) {
842 static struct sr_channel *get_channel_by_index_and_type(GSList *channel_lhead,
845 while (channel_lhead) {
846 struct sr_channel *ch = channel_lhead->data;
847 if (ch->index == index && ch->type == type)
850 channel_lhead = channel_lhead->next;
856 static int analog_channel_state_get(struct sr_dev_inst *sdi,
857 const struct scope_config *config,
858 struct scope_state *state)
861 char command[MAX_COMMAND_SIZE];
863 struct sr_channel *ch;
864 struct sr_scpi_dev_inst *scpi = sdi->conn;
866 for (i = 0; i < config->analog_channels; i++) {
867 g_snprintf(command, sizeof(command),
868 (*config->scpi_dialect)[SCPI_CMD_GET_ANALOG_CHAN_STATE],
871 if (sr_scpi_get_bool(scpi, command,
872 &state->analog_channels[i].state) != SR_OK)
875 ch = get_channel_by_index_and_type(sdi->channels, i, SR_CHANNEL_ANALOG);
877 ch->enabled = state->analog_channels[i].state;
879 g_snprintf(command, sizeof(command),
880 (*config->scpi_dialect)[SCPI_CMD_GET_VERTICAL_SCALE],
883 if (sr_scpi_get_string(scpi, command, &tmp_str) != SR_OK)
886 if (array_float_get(tmp_str, ARRAY_AND_SIZE(vdivs), &j) != SR_OK) {
888 sr_err("Could not determine array index for vertical div scale.");
893 state->analog_channels[i].vdiv = j;
895 g_snprintf(command, sizeof(command),
896 (*config->scpi_dialect)[SCPI_CMD_GET_VERTICAL_OFFSET],
899 if (sr_scpi_get_float(scpi, command,
900 &state->analog_channels[i].vertical_offset) != SR_OK)
903 g_snprintf(command, sizeof(command),
904 (*config->scpi_dialect)[SCPI_CMD_GET_COUPLING],
907 if (scope_state_get_array_option(scpi, command, config->coupling_options,
908 config->num_coupling_options,
909 &state->analog_channels[i].coupling) != SR_OK)
912 g_snprintf(command, sizeof(command),
913 (*config->scpi_dialect)[SCPI_CMD_GET_PROBE_UNIT],
916 if (sr_scpi_get_string(scpi, command, &tmp_str) != SR_OK)
919 if (tmp_str[0] == 'A')
920 state->analog_channels[i].probe_unit = 'A';
922 state->analog_channels[i].probe_unit = 'V';
929 static int digital_channel_state_get(struct sr_dev_inst *sdi,
930 const struct scope_config *config,
931 struct scope_state *state)
935 static char *logic_threshold_short[] = {};
936 char command[MAX_COMMAND_SIZE];
937 struct sr_channel *ch;
938 struct sr_scpi_dev_inst *scpi = sdi->conn;
940 for (i = 0; i < config->digital_channels; i++) {
941 g_snprintf(command, sizeof(command),
942 (*config->scpi_dialect)[SCPI_CMD_GET_DIG_CHAN_STATE],
945 if (sr_scpi_get_bool(scpi, command,
946 &state->digital_channels[i]) != SR_OK)
949 ch = get_channel_by_index_and_type(sdi->channels, i, SR_CHANNEL_LOGIC);
951 ch->enabled = state->digital_channels[i];
954 /* According to the SCPI standard, on models that support multiple
955 * user-defined logic threshold settings the response to the command
956 * SCPI_CMD_GET_DIG_POD_THRESHOLD might return "USER" instead of
959 * This makes more difficult to validate the response when the logic
960 * threshold is set to "USER1" and therefore we need to prevent device
961 * opening failures in such configuration case...
963 for (i = 0; i < config->num_logic_threshold; i++) {
964 logic_threshold_short[i] = g_strdup((*config->logic_threshold)[i]);
965 if (!strcmp("USER1", (*config->logic_threshold)[i]))
966 g_strlcpy(logic_threshold_short[i],
967 (*config->logic_threshold)[i], strlen((*config->logic_threshold)[i]));
970 for (i = 0; i < config->digital_pods; i++) {
971 g_snprintf(command, sizeof(command),
972 (*config->scpi_dialect)[SCPI_CMD_GET_DIG_POD_STATE],
975 if (sr_scpi_get_bool(scpi, command,
976 &state->digital_pods[i].state) != SR_OK)
979 /* Check if the threshold command is based on the POD or digital channel index. */
980 if (config->logic_threshold_for_pod)
983 idx = i * DIGITAL_CHANNELS_PER_POD;
985 g_snprintf(command, sizeof(command),
986 (*config->scpi_dialect)[SCPI_CMD_GET_DIG_POD_THRESHOLD],
989 /* Check for both standard and shortened responses. */
990 if (scope_state_get_array_option(scpi, command, config->logic_threshold,
991 config->num_logic_threshold,
992 &state->digital_pods[i].threshold) != SR_OK)
993 if (scope_state_get_array_option(scpi, command, (const char * (*)[]) &logic_threshold_short,
994 config->num_logic_threshold,
995 &state->digital_pods[i].threshold) != SR_OK)
998 /* If used-defined or custom threshold is active, get the level. */
999 if (!strcmp("USER1", (*config->logic_threshold)[state->digital_pods[i].threshold]))
1000 g_snprintf(command, sizeof(command),
1001 (*config->scpi_dialect)[SCPI_CMD_GET_DIG_POD_USER_THRESHOLD],
1002 idx, 1); /* USER1 logic threshold setting. */
1003 else if (!strcmp("USER2", (*config->logic_threshold)[state->digital_pods[i].threshold]))
1004 g_snprintf(command, sizeof(command),
1005 (*config->scpi_dialect)[SCPI_CMD_GET_DIG_POD_USER_THRESHOLD],
1006 idx, 2); /* USER2 for custom logic_threshold setting. */
1007 else if (!strcmp("USER", (*config->logic_threshold)[state->digital_pods[i].threshold]) ||
1008 !strcmp("MAN", (*config->logic_threshold)[state->digital_pods[i].threshold]))
1009 g_snprintf(command, sizeof(command),
1010 (*config->scpi_dialect)[SCPI_CMD_GET_DIG_POD_USER_THRESHOLD],
1011 idx); /* USER or MAN for custom logic_threshold setting. */
1012 if (!strcmp("USER1", (*config->logic_threshold)[state->digital_pods[i].threshold]) ||
1013 !strcmp("USER2", (*config->logic_threshold)[state->digital_pods[i].threshold]) ||
1014 !strcmp("USER", (*config->logic_threshold)[state->digital_pods[i].threshold]) ||
1015 !strcmp("MAN", (*config->logic_threshold)[state->digital_pods[i].threshold]))
1016 if (sr_scpi_get_float(scpi, command,
1017 &state->digital_pods[i].user_threshold) != SR_OK)
1024 for (i = 0; i < config->num_logic_threshold; i++)
1025 g_free(logic_threshold_short[i]);
1030 SR_PRIV int hmo_update_sample_rate(const struct sr_dev_inst *sdi)
1032 struct dev_context *devc;
1033 struct scope_state *state;
1034 const struct scope_config *config;
1038 config = devc->model_config;
1039 state = devc->model_state;
1041 if (sr_scpi_get_float(sdi->conn,
1042 (*config->scpi_dialect)[SCPI_CMD_GET_SAMPLE_RATE],
1043 &tmp_float) != SR_OK)
1046 state->sample_rate = tmp_float;
1051 SR_PRIV int hmo_scope_state_get(struct sr_dev_inst *sdi)
1053 struct dev_context *devc;
1054 struct scope_state *state;
1055 const struct scope_config *config;
1061 config = devc->model_config;
1062 state = devc->model_state;
1064 sr_info("Fetching scope state");
1066 if (analog_channel_state_get(sdi, config, state) != SR_OK)
1069 if (digital_channel_state_get(sdi, config, state) != SR_OK)
1072 if (sr_scpi_get_string(sdi->conn,
1073 (*config->scpi_dialect)[SCPI_CMD_GET_TIMEBASE],
1077 if (array_float_get(tmp_str, ARRAY_AND_SIZE(timebases), &i) != SR_OK) {
1079 sr_err("Could not determine array index for time base.");
1084 state->timebase = i;
1086 /* Determine the number of horizontal (x) divisions. */
1087 if (sr_scpi_get_int(sdi->conn,
1088 (*config->scpi_dialect)[SCPI_CMD_GET_HORIZONTAL_DIV],
1089 (int *)&config->num_xdivs) != SR_OK)
1092 if (sr_scpi_get_float(sdi->conn,
1093 (*config->scpi_dialect)[SCPI_CMD_GET_HORIZ_TRIGGERPOS],
1094 &tmp_float) != SR_OK)
1096 state->horiz_triggerpos = tmp_float /
1097 (((double) (*config->timebases)[state->timebase][0] /
1098 (*config->timebases)[state->timebase][1]) * config->num_xdivs);
1099 state->horiz_triggerpos -= 0.5;
1100 state->horiz_triggerpos *= -1;
1102 if (scope_state_get_array_option(sdi->conn,
1103 (*config->scpi_dialect)[SCPI_CMD_GET_TRIGGER_SOURCE],
1104 config->trigger_sources, config->num_trigger_sources,
1105 &state->trigger_source) != SR_OK)
1108 if (scope_state_get_array_option(sdi->conn,
1109 (*config->scpi_dialect)[SCPI_CMD_GET_TRIGGER_SLOPE],
1110 config->trigger_slopes, config->num_trigger_slopes,
1111 &state->trigger_slope) != SR_OK)
1114 if (sr_scpi_get_string(sdi->conn,
1115 (*config->scpi_dialect)[SCPI_CMD_GET_TRIGGER_PATTERN],
1118 strncpy(state->trigger_pattern,
1119 sr_scpi_unquote_string(tmp_str),
1120 MAX_ANALOG_CHANNEL_COUNT + MAX_DIGITAL_CHANNEL_COUNT);
1123 if (hmo_update_sample_rate(sdi) != SR_OK)
1126 sr_info("Fetching finished.");
1128 scope_state_dump(config, state);
1133 static struct scope_state *scope_state_new(const struct scope_config *config)
1135 struct scope_state *state;
1137 state = g_malloc0(sizeof(struct scope_state));
1138 state->analog_channels = g_malloc0_n(config->analog_channels,
1139 sizeof(struct analog_channel_state));
1140 state->digital_channels = g_malloc0_n(
1141 config->digital_channels, sizeof(gboolean));
1142 state->digital_pods = g_malloc0_n(config->digital_pods,
1143 sizeof(struct digital_pod_state));
1148 SR_PRIV void hmo_scope_state_free(struct scope_state *state)
1150 g_free(state->analog_channels);
1151 g_free(state->digital_channels);
1152 g_free(state->digital_pods);
1156 SR_PRIV int hmo_init_device(struct sr_dev_inst *sdi)
1159 unsigned int i, j, group;
1160 struct sr_channel *ch;
1161 struct dev_context *devc;
1167 /* Find the exact model. */
1168 for (i = 0; i < ARRAY_SIZE(scope_models); i++) {
1169 for (j = 0; scope_models[i].name[j]; j++) {
1170 if (!strcmp(sdi->model, scope_models[i].name[j])) {
1175 if (model_index != -1)
1179 if (model_index == -1) {
1180 sr_dbg("Unsupported device.");
1184 /* Configure the number of PODs given the number of digital channels. */
1185 scope_models[model_index].digital_pods = scope_models[model_index].digital_channels / DIGITAL_CHANNELS_PER_POD;
1187 devc->analog_groups = g_malloc0(sizeof(struct sr_channel_group*) *
1188 scope_models[model_index].analog_channels);
1189 devc->digital_groups = g_malloc0(sizeof(struct sr_channel_group*) *
1190 scope_models[model_index].digital_pods);
1191 if (!devc->analog_groups || !devc->digital_groups) {
1192 g_free(devc->analog_groups);
1193 g_free(devc->digital_groups);
1194 return SR_ERR_MALLOC;
1197 /* Add analog channels. */
1198 for (i = 0; i < scope_models[model_index].analog_channels; i++) {
1199 ch = sr_channel_new(sdi, i, SR_CHANNEL_ANALOG, TRUE,
1200 (*scope_models[model_index].analog_names)[i]);
1202 devc->analog_groups[i] = g_malloc0(sizeof(struct sr_channel_group));
1204 devc->analog_groups[i]->name = g_strdup(
1205 (char *)(*scope_models[model_index].analog_names)[i]);
1206 devc->analog_groups[i]->channels = g_slist_append(NULL, ch);
1208 sdi->channel_groups = g_slist_append(sdi->channel_groups,
1209 devc->analog_groups[i]);
1212 /* Add digital channel groups. */
1214 for (i = 0; i < scope_models[model_index].digital_pods; i++) {
1215 devc->digital_groups[i] = g_malloc0(sizeof(struct sr_channel_group));
1216 if (!devc->digital_groups[i]) {
1217 ret = SR_ERR_MALLOC;
1220 devc->digital_groups[i]->name = g_strdup_printf("POD%d", i + 1);
1221 sdi->channel_groups = g_slist_append(sdi->channel_groups,
1222 devc->digital_groups[i]);
1227 /* Add digital channels. */
1228 for (i = 0; i < scope_models[model_index].digital_channels; i++) {
1229 ch = sr_channel_new(sdi, i, SR_CHANNEL_LOGIC, TRUE,
1230 (*scope_models[model_index].digital_names)[i]);
1232 group = i / DIGITAL_CHANNELS_PER_POD;
1233 devc->digital_groups[group]->channels = g_slist_append(
1234 devc->digital_groups[group]->channels, ch);
1237 devc->model_config = &scope_models[model_index];
1238 devc->samples_limit = 0;
1239 devc->frame_limit = 0;
1241 if (!(devc->model_state = scope_state_new(devc->model_config)))
1242 return SR_ERR_MALLOC;
1247 /* Queue data of one channel group, for later submission. */
1248 SR_PRIV void hmo_queue_logic_data(struct dev_context *devc,
1249 size_t group, GByteArray *pod_data)
1253 uint8_t *logic_data;
1254 size_t idx, logic_step;
1257 * Upon first invocation, allocate the array which can hold the
1258 * combined logic data for all channels. Assume that each channel
1259 * will yield an identical number of samples per receive call.
1261 * As a poor man's safety measure: (Silently) skip processing
1262 * for unexpected sample counts, and ignore samples for
1263 * unexpected channel groups. Don't bother with complicated
1264 * resize logic, considering that many models only support one
1265 * pod, and the most capable supported models have two pods of
1266 * identical size. We haven't yet seen any "odd" configuration.
1268 if (!devc->logic_data) {
1269 size = pod_data->len * devc->pod_count;
1270 store = g_byte_array_sized_new(size);
1271 memset(store->data, 0, size);
1272 store = g_byte_array_set_size(store, size);
1273 devc->logic_data = store;
1275 store = devc->logic_data;
1276 size = store->len / devc->pod_count;
1277 if (group >= devc->pod_count)
1282 * Fold the data of the most recently received channel group into
1283 * the storage, where data resides for all channels combined.
1285 logic_data = store->data;
1286 logic_data += group;
1287 logic_step = devc->pod_count;
1288 for (idx = 0; idx < pod_data->len; idx++) {
1289 *logic_data = pod_data->data[idx];
1290 logic_data += logic_step;
1293 /* Truncate acquisition if a smaller number of samples has been requested. */
1294 if (devc->samples_limit > 0 && devc->logic_data->len > devc->samples_limit * devc->pod_count)
1295 devc->logic_data->len = devc->samples_limit * devc->pod_count;
1298 /* Submit data for all channels, after the individual groups got collected. */
1299 SR_PRIV void hmo_send_logic_packet(struct sr_dev_inst *sdi,
1300 struct dev_context *devc)
1302 struct sr_datafeed_packet packet;
1303 struct sr_datafeed_logic logic;
1305 if (!devc->logic_data)
1308 logic.data = devc->logic_data->data;
1309 logic.length = devc->logic_data->len;
1310 logic.unitsize = devc->pod_count;
1312 packet.type = SR_DF_LOGIC;
1313 packet.payload = &logic;
1315 sr_session_send(sdi, &packet);
1318 /* Undo previous resource allocation. */
1319 SR_PRIV void hmo_cleanup_logic_data(struct dev_context *devc)
1322 if (devc->logic_data) {
1323 g_byte_array_free(devc->logic_data, TRUE);
1324 devc->logic_data = NULL;
1327 * Keep 'pod_count'! It's required when more frames will be
1328 * received, and does not harm when kept after acquisition.
1332 SR_PRIV int hmo_receive_data(int fd, int revents, void *cb_data)
1334 struct sr_channel *ch;
1335 struct sr_dev_inst *sdi;
1336 struct dev_context *devc;
1337 struct scope_state *state;
1338 struct sr_datafeed_packet packet;
1340 struct sr_datafeed_analog analog;
1341 struct sr_analog_encoding encoding;
1342 struct sr_analog_meaning meaning;
1343 struct sr_analog_spec spec;
1344 struct sr_datafeed_logic logic;
1352 if (!(sdi = cb_data))
1355 if (!(devc = sdi->priv))
1358 /* Although this is correct in general, the USBTMC libusb implementation
1359 * currently does not generate an event prior to the first read. Often
1360 * it is ok to start reading just after the 50ms timeout. See bug #785.
1361 if (revents != G_IO_IN)
1365 ch = devc->current_channel->data;
1366 state = devc->model_state;
1369 * Send "frame begin" packet upon reception of data for the
1370 * first enabled channel.
1372 if (devc->current_channel == devc->enabled_channels) {
1373 packet.type = SR_DF_FRAME_BEGIN;
1374 sr_session_send(sdi, &packet);
1378 * Pass on the received data of the channel(s).
1381 case SR_CHANNEL_ANALOG:
1382 if (sr_scpi_get_block(sdi->conn, NULL, &data) != SR_OK) {
1384 g_byte_array_free(data, TRUE);
1388 packet.type = SR_DF_ANALOG;
1390 analog.data = data->data;
1391 analog.num_samples = data->len / sizeof(float);
1392 /* Truncate acquisition if a smaller number of samples has been requested. */
1393 if (devc->samples_limit > 0 && analog.num_samples > devc->samples_limit)
1394 analog.num_samples = devc->samples_limit;
1395 analog.encoding = &encoding;
1396 analog.meaning = &meaning;
1397 analog.spec = &spec;
1399 encoding.unitsize = sizeof(float);
1400 encoding.is_signed = TRUE;
1401 encoding.is_float = TRUE;
1402 #ifdef WORDS_BIGENDIAN
1403 encoding.is_bigendian = TRUE;
1405 encoding.is_bigendian = FALSE;
1407 /* TODO: Use proper 'digits' value for this device (and its modes). */
1408 encoding.digits = 2;
1409 encoding.is_digits_decimal = FALSE;
1410 encoding.scale.p = 1;
1411 encoding.scale.q = 1;
1412 encoding.offset.p = 0;
1413 encoding.offset.q = 1;
1414 if (state->analog_channels[ch->index].probe_unit == 'V') {
1415 meaning.mq = SR_MQ_VOLTAGE;
1416 meaning.unit = SR_UNIT_VOLT;
1418 meaning.mq = SR_MQ_CURRENT;
1419 meaning.unit = SR_UNIT_AMPERE;
1421 meaning.mqflags = 0;
1422 meaning.channels = g_slist_append(NULL, ch);
1423 /* TODO: Use proper 'digits' value for this device (and its modes). */
1424 spec.spec_digits = 2;
1425 packet.payload = &analog;
1426 sr_session_send(sdi, &packet);
1427 devc->num_samples = data->len / sizeof(float);
1428 g_slist_free(meaning.channels);
1429 g_byte_array_free(data, TRUE);
1432 case SR_CHANNEL_LOGIC:
1433 if (sr_scpi_get_block(sdi->conn, NULL, &data) != SR_OK) {
1435 g_byte_array_free(data, TRUE);
1440 * If only data from the first pod is involved in the
1441 * acquisition, then the raw input bytes can get passed
1442 * forward for performance reasons. When the second pod
1443 * is involved (either alone, or in combination with the
1444 * first pod), then the received bytes need to be put
1445 * into memory in such a layout that all channel groups
1446 * get combined, and a unitsize larger than a single byte
1447 * applies. The "queue" logic transparently copes with
1448 * any such configuration. This works around the lack
1449 * of support for "meaning" to logic data, which is used
1450 * above for analog data.
1452 if (devc->pod_count == 1) {
1453 packet.type = SR_DF_LOGIC;
1454 logic.data = data->data;
1455 logic.length = data->len;
1456 /* Truncate acquisition if a smaller number of samples has been requested. */
1457 if (devc->samples_limit > 0 && logic.length > devc->samples_limit)
1458 logic.length = devc->samples_limit;
1460 packet.payload = &logic;
1461 sr_session_send(sdi, &packet);
1463 group = ch->index / DIGITAL_CHANNELS_PER_POD;
1464 hmo_queue_logic_data(devc, group, data);
1467 devc->num_samples = data->len / devc->pod_count;
1468 g_byte_array_free(data, TRUE);
1472 sr_err("Invalid channel type.");
1477 * Advance to the next enabled channel. When data for all enabled
1478 * channels was received, then flush potentially queued logic data,
1479 * and send the "frame end" packet.
1481 if (devc->current_channel->next) {
1482 devc->current_channel = devc->current_channel->next;
1483 hmo_request_data(sdi);
1486 hmo_send_logic_packet(sdi, devc);
1489 * Release the logic data storage after each frame. This copes
1490 * with sample counts that differ in length per frame. -- Is
1491 * this a real constraint when acquiring multiple frames with
1492 * identical device settings?
1494 hmo_cleanup_logic_data(devc);
1496 packet.type = SR_DF_FRAME_END;
1497 sr_session_send(sdi, &packet);
1500 * End of frame was reached. Stop acquisition after the specified
1501 * number of frames or after the specified number of samples, or
1502 * continue reception by starting over at the first enabled channel.
1504 if (++devc->num_frames >= devc->frame_limit || devc->num_samples >= devc->samples_limit) {
1505 sr_dev_acquisition_stop(sdi);
1506 hmo_cleanup_logic_data(devc);
1508 devc->current_channel = devc->enabled_channels;
1509 hmo_request_data(sdi);