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_SOURCE] = ":TRIG:A:SOUR?",
48 [SCPI_CMD_SET_TRIGGER_SOURCE] = ":TRIG:A:SOUR %s",
49 [SCPI_CMD_GET_TRIGGER_SLOPE] = ":TRIG:A:EDGE:SLOP?",
50 [SCPI_CMD_SET_TRIGGER_SLOPE] = ":TRIG:A:TYPE EDGE;:TRIG:A:EDGE:SLOP %s",
51 [SCPI_CMD_GET_TRIGGER_PATTERN] = ":TRIG:A:PATT:SOUR?",
52 [SCPI_CMD_SET_TRIGGER_PATTERN] = ":TRIG:A:TYPE LOGIC;" \
53 ":TRIG:A:PATT:FUNC AND;" \
54 ":TRIG:A:PATT:COND \"TRUE\";" \
55 ":TRIG:A:PATT:MODE OFF;" \
56 ":TRIG:A:PATT:SOUR \"%s\"",
57 [SCPI_CMD_GET_HIGH_RESOLUTION] = ":ACQ:HRES?",
58 [SCPI_CMD_SET_HIGH_RESOLUTION] = ":ACQ:HRES %s",
59 [SCPI_CMD_GET_PEAK_DETECTION] = ":ACQ:PEAK?",
60 [SCPI_CMD_SET_PEAK_DETECTION] = ":ACQ:PEAK %s",
61 [SCPI_CMD_GET_DIG_CHAN_STATE] = ":LOG%d:STAT?",
62 [SCPI_CMD_SET_DIG_CHAN_STATE] = ":LOG%d:STAT %d",
63 [SCPI_CMD_GET_VERTICAL_OFFSET] = ":CHAN%d:POS?",
64 [SCPI_CMD_GET_HORIZ_TRIGGERPOS] = ":TIM:POS?",
65 [SCPI_CMD_SET_HORIZ_TRIGGERPOS] = ":TIM:POS %s",
66 [SCPI_CMD_GET_ANALOG_CHAN_STATE] = ":CHAN%d:STAT?",
67 [SCPI_CMD_SET_ANALOG_CHAN_STATE] = ":CHAN%d:STAT %d",
68 [SCPI_CMD_GET_PROBE_UNIT] = ":PROB%d:SET:ATT:UNIT?",
69 [SCPI_CMD_GET_DIG_POD_THRESHOLD] = ":POD%d:THR?",
70 [SCPI_CMD_SET_DIG_POD_THRESHOLD] = ":POD%d:THR %s",
71 [SCPI_CMD_GET_DIG_POD_USER_THRESHOLD] = ":POD%d:THR:UDL%d?",
72 [SCPI_CMD_SET_DIG_POD_USER_THRESHOLD] = ":POD%d:THR:UDL%d %s",
75 static const char *rohde_schwarz_log_not_pod_scpi_dialect[] = {
76 [SCPI_CMD_GET_DIG_DATA] = ":FORM UINT,8;:LOG%d:DATA?",
77 [SCPI_CMD_GET_TIMEBASE] = ":TIM:SCAL?",
78 [SCPI_CMD_SET_TIMEBASE] = ":TIM:SCAL %s",
79 [SCPI_CMD_GET_HORIZONTAL_DIV] = ":TIM:DIV?",
80 [SCPI_CMD_GET_COUPLING] = ":CHAN%d:COUP?",
81 [SCPI_CMD_SET_COUPLING] = ":CHAN%d:COUP %s",
82 [SCPI_CMD_GET_SAMPLE_RATE] = ":ACQ:SRAT?",
83 [SCPI_CMD_GET_ANALOG_DATA] = ":FORM:BORD %s;" \
84 ":FORM REAL,32;:CHAN%d:DATA?",
85 [SCPI_CMD_GET_VERTICAL_SCALE] = ":CHAN%d:SCAL?",
86 [SCPI_CMD_SET_VERTICAL_SCALE] = ":CHAN%d:SCAL %s",
87 [SCPI_CMD_GET_DIG_POD_STATE] = ":LOG%d:STAT?",
88 [SCPI_CMD_SET_DIG_POD_STATE] = ":LOG%d:STAT %d",
89 [SCPI_CMD_GET_TRIGGER_SOURCE] = ":TRIG:A:SOUR?",
90 [SCPI_CMD_SET_TRIGGER_SOURCE] = ":TRIG:A:SOUR %s",
91 [SCPI_CMD_GET_TRIGGER_SLOPE] = ":TRIG:A:EDGE:SLOP?",
92 [SCPI_CMD_SET_TRIGGER_SLOPE] = ":TRIG:A:TYPE EDGE;:TRIG:A:EDGE:SLOP %s",
93 [SCPI_CMD_GET_TRIGGER_PATTERN] = ":TRIG:A:PATT:SOUR?",
94 [SCPI_CMD_SET_TRIGGER_PATTERN] = ":TRIG:A:TYPE LOGIC;" \
95 ":TRIG:A:PATT:FUNC AND;" \
96 ":TRIG:A:PATT:COND \"TRUE\";" \
97 ":TRIG:A:PATT:MODE OFF;" \
98 ":TRIG:A:PATT:SOUR \"%s\"",
99 [SCPI_CMD_GET_HIGH_RESOLUTION] = ":ACQ:HRES?",
100 [SCPI_CMD_SET_HIGH_RESOLUTION] = ":ACQ:HRES %s",
101 [SCPI_CMD_GET_PEAK_DETECTION] = ":ACQ:PEAK?",
102 [SCPI_CMD_SET_PEAK_DETECTION] = ":ACQ:PEAK %s",
103 [SCPI_CMD_GET_DIG_CHAN_STATE] = ":LOG%d:STAT?",
104 [SCPI_CMD_SET_DIG_CHAN_STATE] = ":LOG%d:STAT %d",
105 [SCPI_CMD_GET_VERTICAL_OFFSET] = ":CHAN%d:POS?", /* Might not be supported on RTB200x... */
106 [SCPI_CMD_GET_HORIZ_TRIGGERPOS] = ":TIM:POS?",
107 [SCPI_CMD_SET_HORIZ_TRIGGERPOS] = ":TIM:POS %s",
108 [SCPI_CMD_GET_ANALOG_CHAN_STATE] = ":CHAN%d:STAT?",
109 [SCPI_CMD_SET_ANALOG_CHAN_STATE] = ":CHAN%d:STAT %d",
110 [SCPI_CMD_GET_PROBE_UNIT] = ":PROB%d:SET:ATT:UNIT?",
111 [SCPI_CMD_GET_DIG_POD_THRESHOLD] = ":DIG%d:TECH?",
112 [SCPI_CMD_SET_DIG_POD_THRESHOLD] = ":DIG%d:TECH %s",
113 [SCPI_CMD_GET_DIG_POD_USER_THRESHOLD] = ":DIG%d:THR?",
114 [SCPI_CMD_SET_DIG_POD_USER_THRESHOLD] = ":DIG%d:THR %s",
117 static const uint32_t devopts[] = {
118 SR_CONF_OSCILLOSCOPE,
119 SR_CONF_LIMIT_SAMPLES | SR_CONF_SET,
120 SR_CONF_LIMIT_FRAMES | SR_CONF_SET,
121 SR_CONF_SAMPLERATE | SR_CONF_GET,
122 SR_CONF_TIMEBASE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
123 SR_CONF_NUM_HDIV | SR_CONF_GET,
124 SR_CONF_HORIZ_TRIGGERPOS | SR_CONF_GET | SR_CONF_SET,
125 SR_CONF_TRIGGER_SOURCE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
126 SR_CONF_TRIGGER_SLOPE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
127 SR_CONF_TRIGGER_PATTERN | SR_CONF_GET | SR_CONF_SET,
128 SR_CONF_HIGH_RESOLUTION | SR_CONF_GET | SR_CONF_SET,
129 SR_CONF_PEAK_DETECTION | SR_CONF_GET | SR_CONF_SET,
132 static const uint32_t devopts_cg_analog[] = {
133 SR_CONF_NUM_VDIV | SR_CONF_GET,
134 SR_CONF_VDIV | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
135 SR_CONF_COUPLING | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
138 static const uint32_t devopts_cg_digital[] = {
139 SR_CONF_LOGIC_THRESHOLD | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
140 SR_CONF_LOGIC_THRESHOLD_CUSTOM | SR_CONF_GET | SR_CONF_SET,
143 static const char *coupling_options[] = {
144 "AC", // AC with 50 Ohm termination (152x, 202x, 30xx, 1202)
145 "ACL", // AC with 1 MOhm termination
146 "DC", // DC with 50 Ohm termination
147 "DCL", // DC with 1 MOhm termination
151 static const char *coupling_options_rtb200x[] = {
152 "ACL", // AC with 1 MOhm termination
153 "DCL", // DC with 1 MOhm termination
157 static const char *coupling_options_rtm300x[] = {
158 "ACL", // AC with 1 MOhm termination
159 "DC", // DC with 50 Ohm termination
160 "DCL", // DC with 1 MOhm termination
164 static const char *scope_trigger_slopes[] = {
170 /* Predefined logic thresholds. */
171 static const char *logic_threshold[] = {
176 "USER2", // overwritten by logic_threshold_custom, use USER1 for permanent setting
179 static const char *logic_threshold_rtb200x_rtm300x[] = {
183 "MAN", // overwritten by logic_threshold_custom
186 /* RTC1002, HMO Compact2 and HMO1002/HMO1202 */
187 static const char *an2_dig8_trigger_sources[] = {
189 "LINE", "EXT", "PATT", "BUS1", "BUS2",
190 "D0", "D1", "D2", "D3", "D4", "D5", "D6", "D7",
194 static const char *an2_dig16_trigger_sources[] = {
196 "LINE", "EXT", "PATT", "BUS1", "BUS2",
197 "D0", "D1", "D2", "D3", "D4", "D5", "D6", "D7",
198 "D8", "D9", "D10", "D11", "D12", "D13", "D14", "D15",
201 /* RTB2002 and RTM3002 */
202 static const char *an2_dig16_sbus_trigger_sources[] = {
204 "LINE", "EXT", "PATT", "SBUS1", "SBUS2",
205 "D0", "D1", "D2", "D3", "D4", "D5", "D6", "D7",
206 "D8", "D9", "D10", "D11", "D12", "D13", "D14", "D15",
210 static const char *an4_dig8_trigger_sources[] = {
211 "CH1", "CH2", "CH3", "CH4",
212 "LINE", "EXT", "PATT", "BUS1", "BUS2",
213 "D0", "D1", "D2", "D3", "D4", "D5", "D6", "D7",
216 /* HMO3xx4 and HMO2524 */
217 static const char *an4_dig16_trigger_sources[] = {
218 "CH1", "CH2", "CH3", "CH4",
219 "LINE", "EXT", "PATT", "BUS1", "BUS2",
220 "D0", "D1", "D2", "D3", "D4", "D5", "D6", "D7",
221 "D8", "D9", "D10", "D11", "D12", "D13", "D14", "D15",
224 /* RTB2004, RTM3004 and RTA4004 */
225 static const char *an4_dig16_sbus_trigger_sources[] = {
226 "CH1", "CH2", "CH3", "CH4",
227 "LINE", "EXT", "PATT", "SBUS1", "SBUS2",
228 "D0", "D1", "D2", "D3", "D4", "D5", "D6", "D7",
229 "D8", "D9", "D10", "D11", "D12", "D13", "D14", "D15",
232 static const uint64_t timebases[][2] = {
272 /* HMO Compact series (HMO722/724/1022/1024/1522/1524/2022/2024) do
273 * not support 1 ns timebase setting.
275 static const uint64_t timebases_hmo_compact[][2] = {
314 static const uint64_t vdivs[][2] = {
332 static const char *scope_analog_channel_names[] = {
333 "CH1", "CH2", "CH3", "CH4",
336 static const char *scope_digital_channel_names[] = {
337 "D0", "D1", "D2", "D3", "D4", "D5", "D6", "D7",
338 "D8", "D9", "D10", "D11", "D12", "D13", "D14", "D15",
341 static struct scope_config scope_models[] = {
343 /* HMO Compact2: HMO722/1022/1522/2022 support only 8 digital channels. */
344 .name = {"HMO722", "HMO1022", "HMO1522", "HMO2022", NULL},
345 .analog_channels = 2,
346 .digital_channels = 8,
348 .analog_names = &scope_analog_channel_names,
349 .digital_names = &scope_digital_channel_names,
352 .num_devopts = ARRAY_SIZE(devopts),
354 .devopts_cg_analog = &devopts_cg_analog,
355 .num_devopts_cg_analog = ARRAY_SIZE(devopts_cg_analog),
357 .devopts_cg_digital = &devopts_cg_digital,
358 .num_devopts_cg_digital = ARRAY_SIZE(devopts_cg_digital),
360 .coupling_options = &coupling_options,
361 .num_coupling_options = ARRAY_SIZE(coupling_options),
363 .logic_threshold = &logic_threshold,
364 .num_logic_threshold = ARRAY_SIZE(logic_threshold),
365 .logic_threshold_for_pod = TRUE,
367 .trigger_sources = &an2_dig8_trigger_sources,
368 .num_trigger_sources = ARRAY_SIZE(an2_dig8_trigger_sources),
370 .trigger_slopes = &scope_trigger_slopes,
371 .num_trigger_slopes = ARRAY_SIZE(scope_trigger_slopes),
373 .timebases = &timebases_hmo_compact,
374 .num_timebases = ARRAY_SIZE(timebases_hmo_compact),
377 .num_vdivs = ARRAY_SIZE(vdivs),
381 .scpi_dialect = &hameg_scpi_dialect,
384 /* RTC1002 and HMO1002/HMO1202 support only 8 digital channels. */
385 .name = {"RTC1002", "HMO1002", "HMO1202", NULL},
386 .analog_channels = 2,
387 .digital_channels = 8,
389 .analog_names = &scope_analog_channel_names,
390 .digital_names = &scope_digital_channel_names,
393 .num_devopts = ARRAY_SIZE(devopts),
395 .devopts_cg_analog = &devopts_cg_analog,
396 .num_devopts_cg_analog = ARRAY_SIZE(devopts_cg_analog),
398 .devopts_cg_digital = &devopts_cg_digital,
399 .num_devopts_cg_digital = ARRAY_SIZE(devopts_cg_digital),
401 .coupling_options = &coupling_options,
402 .num_coupling_options = ARRAY_SIZE(coupling_options),
404 .logic_threshold = &logic_threshold,
405 .num_logic_threshold = ARRAY_SIZE(logic_threshold),
406 .logic_threshold_for_pod = TRUE,
408 .trigger_sources = &an2_dig8_trigger_sources,
409 .num_trigger_sources = ARRAY_SIZE(an2_dig8_trigger_sources),
411 .trigger_slopes = &scope_trigger_slopes,
412 .num_trigger_slopes = ARRAY_SIZE(scope_trigger_slopes),
414 .timebases = &timebases,
415 .num_timebases = ARRAY_SIZE(timebases),
418 .num_vdivs = ARRAY_SIZE(vdivs),
422 .scpi_dialect = &hameg_scpi_dialect,
425 /* HMO3032/3042/3052/3522 support 16 digital channels. */
426 .name = {"HMO3032", "HMO3042", "HMO3052", "HMO3522", NULL},
427 .analog_channels = 2,
428 .digital_channels = 16,
430 .analog_names = &scope_analog_channel_names,
431 .digital_names = &scope_digital_channel_names,
434 .num_devopts = ARRAY_SIZE(devopts),
436 .devopts_cg_analog = &devopts_cg_analog,
437 .num_devopts_cg_analog = ARRAY_SIZE(devopts_cg_analog),
439 .devopts_cg_digital = &devopts_cg_digital,
440 .num_devopts_cg_digital = ARRAY_SIZE(devopts_cg_digital),
442 .coupling_options = &coupling_options,
443 .num_coupling_options = ARRAY_SIZE(coupling_options),
445 .logic_threshold = &logic_threshold,
446 .num_logic_threshold = ARRAY_SIZE(logic_threshold),
447 .logic_threshold_for_pod = TRUE,
449 .trigger_sources = &an2_dig16_trigger_sources,
450 .num_trigger_sources = ARRAY_SIZE(an2_dig16_trigger_sources),
452 .trigger_slopes = &scope_trigger_slopes,
453 .num_trigger_slopes = ARRAY_SIZE(scope_trigger_slopes),
455 .timebases = &timebases,
456 .num_timebases = ARRAY_SIZE(timebases),
459 .num_vdivs = ARRAY_SIZE(vdivs),
463 .scpi_dialect = &hameg_scpi_dialect,
466 /* HMO Compact4: HMO724/1024/1524/2024 support only 8 digital channels. */
467 .name = {"HMO724", "HMO1024", "HMO1524", "HMO2024", NULL},
468 .analog_channels = 4,
469 .digital_channels = 8,
471 .analog_names = &scope_analog_channel_names,
472 .digital_names = &scope_digital_channel_names,
475 .num_devopts = ARRAY_SIZE(devopts),
477 .devopts_cg_analog = &devopts_cg_analog,
478 .num_devopts_cg_analog = ARRAY_SIZE(devopts_cg_analog),
480 .devopts_cg_digital = &devopts_cg_digital,
481 .num_devopts_cg_digital = ARRAY_SIZE(devopts_cg_digital),
483 .coupling_options = &coupling_options,
484 .num_coupling_options = ARRAY_SIZE(coupling_options),
486 .logic_threshold = &logic_threshold,
487 .num_logic_threshold = ARRAY_SIZE(logic_threshold),
488 .logic_threshold_for_pod = TRUE,
490 .trigger_sources = &an4_dig8_trigger_sources,
491 .num_trigger_sources = ARRAY_SIZE(an4_dig8_trigger_sources),
493 .trigger_slopes = &scope_trigger_slopes,
494 .num_trigger_slopes = ARRAY_SIZE(scope_trigger_slopes),
496 .timebases = &timebases_hmo_compact,
497 .num_timebases = ARRAY_SIZE(timebases_hmo_compact),
500 .num_vdivs = ARRAY_SIZE(vdivs),
504 .scpi_dialect = &hameg_scpi_dialect,
507 .name = {"HMO2524", "HMO3034", "HMO3044", "HMO3054", "HMO3524", NULL},
508 .analog_channels = 4,
509 .digital_channels = 16,
511 .analog_names = &scope_analog_channel_names,
512 .digital_names = &scope_digital_channel_names,
515 .num_devopts = ARRAY_SIZE(devopts),
517 .devopts_cg_analog = &devopts_cg_analog,
518 .num_devopts_cg_analog = ARRAY_SIZE(devopts_cg_analog),
520 .devopts_cg_digital = &devopts_cg_digital,
521 .num_devopts_cg_digital = ARRAY_SIZE(devopts_cg_digital),
523 .coupling_options = &coupling_options,
524 .num_coupling_options = ARRAY_SIZE(coupling_options),
526 .logic_threshold = &logic_threshold,
527 .num_logic_threshold = ARRAY_SIZE(logic_threshold),
528 .logic_threshold_for_pod = TRUE,
530 .trigger_sources = &an4_dig16_trigger_sources,
531 .num_trigger_sources = ARRAY_SIZE(an4_dig16_trigger_sources),
533 .trigger_slopes = &scope_trigger_slopes,
534 .num_trigger_slopes = ARRAY_SIZE(scope_trigger_slopes),
536 .timebases = &timebases,
537 .num_timebases = ARRAY_SIZE(timebases),
540 .num_vdivs = ARRAY_SIZE(vdivs),
544 .scpi_dialect = &hameg_scpi_dialect,
547 .name = {"RTB2002", NULL},
548 .analog_channels = 2,
549 .digital_channels = 16,
551 .analog_names = &scope_analog_channel_names,
552 .digital_names = &scope_digital_channel_names,
555 .num_devopts = ARRAY_SIZE(devopts),
557 .devopts_cg_analog = &devopts_cg_analog,
558 .num_devopts_cg_analog = ARRAY_SIZE(devopts_cg_analog),
560 .devopts_cg_digital = &devopts_cg_digital,
561 .num_devopts_cg_digital = ARRAY_SIZE(devopts_cg_digital),
563 .coupling_options = &coupling_options_rtb200x,
564 .num_coupling_options = ARRAY_SIZE(coupling_options_rtb200x),
566 .logic_threshold = &logic_threshold_rtb200x_rtm300x,
567 .num_logic_threshold = ARRAY_SIZE(logic_threshold_rtb200x_rtm300x),
568 .logic_threshold_for_pod = FALSE,
570 .trigger_sources = &an2_dig16_sbus_trigger_sources,
571 .num_trigger_sources = ARRAY_SIZE(an2_dig16_sbus_trigger_sources),
573 .trigger_slopes = &scope_trigger_slopes,
574 .num_trigger_slopes = ARRAY_SIZE(scope_trigger_slopes),
576 .timebases = &timebases,
577 .num_timebases = ARRAY_SIZE(timebases),
580 .num_vdivs = ARRAY_SIZE(vdivs),
584 .scpi_dialect = &rohde_schwarz_log_not_pod_scpi_dialect,
587 .name = {"RTB2004", NULL},
588 .analog_channels = 4,
589 .digital_channels = 16,
591 .analog_names = &scope_analog_channel_names,
592 .digital_names = &scope_digital_channel_names,
595 .num_devopts = ARRAY_SIZE(devopts),
597 .devopts_cg_analog = &devopts_cg_analog,
598 .num_devopts_cg_analog = ARRAY_SIZE(devopts_cg_analog),
600 .devopts_cg_digital = &devopts_cg_digital,
601 .num_devopts_cg_digital = ARRAY_SIZE(devopts_cg_digital),
603 .coupling_options = &coupling_options_rtb200x,
604 .num_coupling_options = ARRAY_SIZE(coupling_options_rtb200x),
606 .logic_threshold = &logic_threshold_rtb200x_rtm300x,
607 .num_logic_threshold = ARRAY_SIZE(logic_threshold_rtb200x_rtm300x),
608 .logic_threshold_for_pod = FALSE,
610 .trigger_sources = &an4_dig16_sbus_trigger_sources,
611 .num_trigger_sources = ARRAY_SIZE(an4_dig16_sbus_trigger_sources),
613 .trigger_slopes = &scope_trigger_slopes,
614 .num_trigger_slopes = ARRAY_SIZE(scope_trigger_slopes),
616 .timebases = &timebases,
617 .num_timebases = ARRAY_SIZE(timebases),
620 .num_vdivs = ARRAY_SIZE(vdivs),
624 .scpi_dialect = &rohde_schwarz_log_not_pod_scpi_dialect,
627 .name = {"RTM3002", NULL},
628 .analog_channels = 2,
629 .digital_channels = 16,
631 .analog_names = &scope_analog_channel_names,
632 .digital_names = &scope_digital_channel_names,
635 .num_devopts = ARRAY_SIZE(devopts),
637 .devopts_cg_analog = &devopts_cg_analog,
638 .num_devopts_cg_analog = ARRAY_SIZE(devopts_cg_analog),
640 .devopts_cg_digital = &devopts_cg_digital,
641 .num_devopts_cg_digital = ARRAY_SIZE(devopts_cg_digital),
643 .coupling_options = &coupling_options_rtm300x,
644 .num_coupling_options = ARRAY_SIZE(coupling_options_rtm300x),
646 .logic_threshold = &logic_threshold_rtb200x_rtm300x,
647 .num_logic_threshold = ARRAY_SIZE(logic_threshold_rtb200x_rtm300x),
648 .logic_threshold_for_pod = FALSE,
650 .trigger_sources = &an2_dig16_sbus_trigger_sources,
651 .num_trigger_sources = ARRAY_SIZE(an2_dig16_sbus_trigger_sources),
653 .trigger_slopes = &scope_trigger_slopes,
654 .num_trigger_slopes = ARRAY_SIZE(scope_trigger_slopes),
656 .timebases = &timebases,
657 .num_timebases = ARRAY_SIZE(timebases),
660 .num_vdivs = ARRAY_SIZE(vdivs),
664 .scpi_dialect = &rohde_schwarz_log_not_pod_scpi_dialect,
667 .name = {"RTM3004", NULL},
668 .analog_channels = 4,
669 .digital_channels = 16,
671 .analog_names = &scope_analog_channel_names,
672 .digital_names = &scope_digital_channel_names,
675 .num_devopts = ARRAY_SIZE(devopts),
677 .devopts_cg_analog = &devopts_cg_analog,
678 .num_devopts_cg_analog = ARRAY_SIZE(devopts_cg_analog),
680 .devopts_cg_digital = &devopts_cg_digital,
681 .num_devopts_cg_digital = ARRAY_SIZE(devopts_cg_digital),
683 .coupling_options = &coupling_options_rtm300x,
684 .num_coupling_options = ARRAY_SIZE(coupling_options_rtm300x),
686 .logic_threshold = &logic_threshold_rtb200x_rtm300x,
687 .num_logic_threshold = ARRAY_SIZE(logic_threshold_rtb200x_rtm300x),
688 .logic_threshold_for_pod = FALSE,
690 .trigger_sources = &an4_dig16_sbus_trigger_sources,
691 .num_trigger_sources = ARRAY_SIZE(an4_dig16_sbus_trigger_sources),
693 .trigger_slopes = &scope_trigger_slopes,
694 .num_trigger_slopes = ARRAY_SIZE(scope_trigger_slopes),
696 .timebases = &timebases,
697 .num_timebases = ARRAY_SIZE(timebases),
700 .num_vdivs = ARRAY_SIZE(vdivs),
704 .scpi_dialect = &rohde_schwarz_log_not_pod_scpi_dialect,
707 .name = {"RTA4004", NULL},
708 .analog_channels = 4,
709 .digital_channels = 16,
711 .analog_names = &scope_analog_channel_names,
712 .digital_names = &scope_digital_channel_names,
715 .num_devopts = ARRAY_SIZE(devopts),
717 .devopts_cg_analog = &devopts_cg_analog,
718 .num_devopts_cg_analog = ARRAY_SIZE(devopts_cg_analog),
720 .devopts_cg_digital = &devopts_cg_digital,
721 .num_devopts_cg_digital = ARRAY_SIZE(devopts_cg_digital),
723 .coupling_options = &coupling_options_rtm300x,
724 .num_coupling_options = ARRAY_SIZE(coupling_options_rtm300x),
726 .logic_threshold = &logic_threshold_rtb200x_rtm300x,
727 .num_logic_threshold = ARRAY_SIZE(logic_threshold_rtb200x_rtm300x),
728 .logic_threshold_for_pod = FALSE,
730 .trigger_sources = &an4_dig16_sbus_trigger_sources,
731 .num_trigger_sources = ARRAY_SIZE(an4_dig16_sbus_trigger_sources),
733 .trigger_slopes = &scope_trigger_slopes,
734 .num_trigger_slopes = ARRAY_SIZE(scope_trigger_slopes),
736 .timebases = &timebases,
737 .num_timebases = ARRAY_SIZE(timebases),
740 .num_vdivs = ARRAY_SIZE(vdivs),
744 .scpi_dialect = &rohde_schwarz_log_not_pod_scpi_dialect,
748 static void scope_state_dump(const struct scope_config *config,
749 struct scope_state *state)
754 for (i = 0; i < config->analog_channels; i++) {
755 tmp = sr_voltage_string((*config->vdivs)[state->analog_channels[i].vdiv][0],
756 (*config->vdivs)[state->analog_channels[i].vdiv][1]);
757 sr_info("State of analog channel %d -> %s : %s (coupling) %s (vdiv) %2.2e (offset)",
758 i + 1, state->analog_channels[i].state ? "On" : "Off",
759 (*config->coupling_options)[state->analog_channels[i].coupling],
760 tmp, state->analog_channels[i].vertical_offset);
763 for (i = 0; i < config->digital_channels; i++) {
764 sr_info("State of digital channel %d -> %s", i,
765 state->digital_channels[i] ? "On" : "Off");
768 for (i = 0; i < config->digital_pods; i++) {
769 if (!strncmp("USER", (*config->logic_threshold)[state->digital_pods[i].threshold], 4) ||
770 !strcmp("MAN", (*config->logic_threshold)[state->digital_pods[i].threshold]))
771 sr_info("State of digital POD %d -> %s : %E (threshold)", i + 1,
772 state->digital_pods[i].state ? "On" : "Off",
773 state->digital_pods[i].user_threshold);
775 sr_info("State of digital POD %d -> %s : %s (threshold)", i + 1,
776 state->digital_pods[i].state ? "On" : "Off",
777 (*config->logic_threshold)[state->digital_pods[i].threshold]);
780 tmp = sr_period_string((*config->timebases)[state->timebase][0],
781 (*config->timebases)[state->timebase][1]);
782 sr_info("Current timebase: %s", tmp);
785 tmp = sr_samplerate_string(state->sample_rate);
786 sr_info("Current samplerate: %s", tmp);
789 if (!strcmp("PATT", (*config->trigger_sources)[state->trigger_source]))
790 sr_info("Current trigger: %s (pattern), %.2f (offset)",
791 state->trigger_pattern,
792 state->horiz_triggerpos);
793 else // Edge (slope) trigger
794 sr_info("Current trigger: %s (source), %s (slope) %.2f (offset)",
795 (*config->trigger_sources)[state->trigger_source],
796 (*config->trigger_slopes)[state->trigger_slope],
797 state->horiz_triggerpos);
800 static int scope_state_get_array_option(struct sr_scpi_dev_inst *scpi,
801 const char *command, const char *(*array)[], unsigned int n, int *result)
806 if (sr_scpi_get_string(scpi, command, &tmp) != SR_OK)
809 if ((idx = std_str_idx_s(tmp, *array, n)) < 0) {
822 * This function takes a value of the form "2.000E-03" and returns the index
823 * of an array where a matching pair was found.
825 * @param value The string to be parsed.
826 * @param array The array of s/f pairs.
827 * @param array_len The number of pairs in the array.
828 * @param result The index at which a matching pair was found.
830 * @return SR_ERR on any parsing error, SR_OK otherwise.
832 static int array_float_get(gchar *value, const uint64_t array[][2],
833 int array_len, unsigned int *result)
835 struct sr_rational rval;
836 struct sr_rational aval;
838 if (sr_parse_rational(value, &rval) != SR_OK)
841 for (int i = 0; i < array_len; i++) {
842 sr_rational_set(&aval, array[i][0], array[i][1]);
843 if (sr_rational_eq(&rval, &aval)) {
852 static struct sr_channel *get_channel_by_index_and_type(GSList *channel_lhead,
855 while (channel_lhead) {
856 struct sr_channel *ch = channel_lhead->data;
857 if (ch->index == index && ch->type == type)
860 channel_lhead = channel_lhead->next;
866 static int analog_channel_state_get(struct sr_dev_inst *sdi,
867 const struct scope_config *config,
868 struct scope_state *state)
871 char command[MAX_COMMAND_SIZE];
873 struct sr_channel *ch;
874 struct sr_scpi_dev_inst *scpi = sdi->conn;
876 for (i = 0; i < config->analog_channels; i++) {
877 g_snprintf(command, sizeof(command),
878 (*config->scpi_dialect)[SCPI_CMD_GET_ANALOG_CHAN_STATE],
881 if (sr_scpi_get_bool(scpi, command,
882 &state->analog_channels[i].state) != SR_OK)
885 ch = get_channel_by_index_and_type(sdi->channels, i, SR_CHANNEL_ANALOG);
887 ch->enabled = state->analog_channels[i].state;
889 g_snprintf(command, sizeof(command),
890 (*config->scpi_dialect)[SCPI_CMD_GET_VERTICAL_SCALE],
893 if (sr_scpi_get_string(scpi, command, &tmp_str) != SR_OK)
896 if (array_float_get(tmp_str, ARRAY_AND_SIZE(vdivs), &j) != SR_OK) {
898 sr_err("Could not determine array index for vertical div scale.");
903 state->analog_channels[i].vdiv = j;
905 g_snprintf(command, sizeof(command),
906 (*config->scpi_dialect)[SCPI_CMD_GET_VERTICAL_OFFSET],
909 if (sr_scpi_get_float(scpi, command,
910 &state->analog_channels[i].vertical_offset) != SR_OK)
913 g_snprintf(command, sizeof(command),
914 (*config->scpi_dialect)[SCPI_CMD_GET_COUPLING],
917 if (scope_state_get_array_option(scpi, command, config->coupling_options,
918 config->num_coupling_options,
919 &state->analog_channels[i].coupling) != SR_OK)
922 g_snprintf(command, sizeof(command),
923 (*config->scpi_dialect)[SCPI_CMD_GET_PROBE_UNIT],
926 if (sr_scpi_get_string(scpi, command, &tmp_str) != SR_OK)
929 if (tmp_str[0] == 'A')
930 state->analog_channels[i].probe_unit = 'A';
932 state->analog_channels[i].probe_unit = 'V';
939 static int digital_channel_state_get(struct sr_dev_inst *sdi,
940 const struct scope_config *config,
941 struct scope_state *state)
945 static char *logic_threshold_short[] = {};
946 char command[MAX_COMMAND_SIZE];
947 struct sr_channel *ch;
948 struct sr_scpi_dev_inst *scpi = sdi->conn;
950 for (i = 0; i < config->digital_channels; i++) {
951 g_snprintf(command, sizeof(command),
952 (*config->scpi_dialect)[SCPI_CMD_GET_DIG_CHAN_STATE],
955 if (sr_scpi_get_bool(scpi, command,
956 &state->digital_channels[i]) != SR_OK)
959 ch = get_channel_by_index_and_type(sdi->channels, i, SR_CHANNEL_LOGIC);
961 ch->enabled = state->digital_channels[i];
964 /* According to the SCPI standard, on models that support multiple
965 * user-defined logic threshold settings the response to the command
966 * SCPI_CMD_GET_DIG_POD_THRESHOLD might return "USER" instead of
969 * This makes more difficult to validate the response when the logic
970 * threshold is set to "USER1" and therefore we need to prevent device
971 * opening failures in such configuration case...
973 for (i = 0; i < config->num_logic_threshold; i++) {
974 logic_threshold_short[i] = g_strdup((*config->logic_threshold)[i]);
975 if (!strcmp("USER1", (*config->logic_threshold)[i]))
976 g_strlcpy(logic_threshold_short[i],
977 (*config->logic_threshold)[i], strlen((*config->logic_threshold)[i]));
980 for (i = 0; i < config->digital_pods; i++) {
981 g_snprintf(command, sizeof(command),
982 (*config->scpi_dialect)[SCPI_CMD_GET_DIG_POD_STATE],
985 if (sr_scpi_get_bool(scpi, command,
986 &state->digital_pods[i].state) != SR_OK)
989 /* Check if the threshold command is based on the POD or digital channel index. */
990 if (config->logic_threshold_for_pod)
993 idx = i * DIGITAL_CHANNELS_PER_POD;
995 g_snprintf(command, sizeof(command),
996 (*config->scpi_dialect)[SCPI_CMD_GET_DIG_POD_THRESHOLD],
999 /* Check for both standard and shortened responses. */
1000 if (scope_state_get_array_option(scpi, command, config->logic_threshold,
1001 config->num_logic_threshold,
1002 &state->digital_pods[i].threshold) != SR_OK)
1003 if (scope_state_get_array_option(scpi, command, (const char * (*)[]) &logic_threshold_short,
1004 config->num_logic_threshold,
1005 &state->digital_pods[i].threshold) != SR_OK)
1008 /* If used-defined or custom threshold is active, get the level. */
1009 if (!strcmp("USER1", (*config->logic_threshold)[state->digital_pods[i].threshold]))
1010 g_snprintf(command, sizeof(command),
1011 (*config->scpi_dialect)[SCPI_CMD_GET_DIG_POD_USER_THRESHOLD],
1012 idx, 1); /* USER1 logic threshold setting. */
1013 else if (!strcmp("USER2", (*config->logic_threshold)[state->digital_pods[i].threshold]))
1014 g_snprintf(command, sizeof(command),
1015 (*config->scpi_dialect)[SCPI_CMD_GET_DIG_POD_USER_THRESHOLD],
1016 idx, 2); /* USER2 for custom logic_threshold setting. */
1017 else if (!strcmp("USER", (*config->logic_threshold)[state->digital_pods[i].threshold]) ||
1018 !strcmp("MAN", (*config->logic_threshold)[state->digital_pods[i].threshold]))
1019 g_snprintf(command, sizeof(command),
1020 (*config->scpi_dialect)[SCPI_CMD_GET_DIG_POD_USER_THRESHOLD],
1021 idx); /* USER or MAN for custom logic_threshold setting. */
1022 if (!strcmp("USER1", (*config->logic_threshold)[state->digital_pods[i].threshold]) ||
1023 !strcmp("USER2", (*config->logic_threshold)[state->digital_pods[i].threshold]) ||
1024 !strcmp("USER", (*config->logic_threshold)[state->digital_pods[i].threshold]) ||
1025 !strcmp("MAN", (*config->logic_threshold)[state->digital_pods[i].threshold]))
1026 if (sr_scpi_get_float(scpi, command,
1027 &state->digital_pods[i].user_threshold) != SR_OK)
1034 for (i = 0; i < config->num_logic_threshold; i++)
1035 g_free(logic_threshold_short[i]);
1040 SR_PRIV int hmo_update_sample_rate(const struct sr_dev_inst *sdi)
1042 struct dev_context *devc;
1043 struct scope_state *state;
1044 const struct scope_config *config;
1048 config = devc->model_config;
1049 state = devc->model_state;
1051 if (sr_scpi_get_float(sdi->conn,
1052 (*config->scpi_dialect)[SCPI_CMD_GET_SAMPLE_RATE],
1053 &tmp_float) != SR_OK)
1056 state->sample_rate = tmp_float;
1061 SR_PRIV int hmo_scope_state_get(struct sr_dev_inst *sdi)
1063 struct dev_context *devc;
1064 struct scope_state *state;
1065 const struct scope_config *config;
1071 config = devc->model_config;
1072 state = devc->model_state;
1074 sr_info("Fetching scope state");
1076 if (analog_channel_state_get(sdi, config, state) != SR_OK)
1079 if (digital_channel_state_get(sdi, config, state) != SR_OK)
1082 if (sr_scpi_get_string(sdi->conn,
1083 (*config->scpi_dialect)[SCPI_CMD_GET_TIMEBASE],
1087 if (array_float_get(tmp_str, ARRAY_AND_SIZE(timebases), &i) != SR_OK) {
1089 sr_err("Could not determine array index for time base.");
1094 state->timebase = i;
1096 /* Determine the number of horizontal (x) divisions. */
1097 if (sr_scpi_get_int(sdi->conn,
1098 (*config->scpi_dialect)[SCPI_CMD_GET_HORIZONTAL_DIV],
1099 (int *)&config->num_xdivs) != SR_OK)
1102 if (sr_scpi_get_float(sdi->conn,
1103 (*config->scpi_dialect)[SCPI_CMD_GET_HORIZ_TRIGGERPOS],
1104 &tmp_float) != SR_OK)
1106 state->horiz_triggerpos = tmp_float /
1107 (((double) (*config->timebases)[state->timebase][0] /
1108 (*config->timebases)[state->timebase][1]) * config->num_xdivs);
1109 state->horiz_triggerpos -= 0.5;
1110 state->horiz_triggerpos *= -1;
1112 if (scope_state_get_array_option(sdi->conn,
1113 (*config->scpi_dialect)[SCPI_CMD_GET_TRIGGER_SOURCE],
1114 config->trigger_sources, config->num_trigger_sources,
1115 &state->trigger_source) != SR_OK)
1118 if (scope_state_get_array_option(sdi->conn,
1119 (*config->scpi_dialect)[SCPI_CMD_GET_TRIGGER_SLOPE],
1120 config->trigger_slopes, config->num_trigger_slopes,
1121 &state->trigger_slope) != SR_OK)
1124 if (sr_scpi_get_string(sdi->conn,
1125 (*config->scpi_dialect)[SCPI_CMD_GET_TRIGGER_PATTERN],
1128 strncpy(state->trigger_pattern,
1129 sr_scpi_unquote_string(tmp_str),
1130 MAX_ANALOG_CHANNEL_COUNT + MAX_DIGITAL_CHANNEL_COUNT);
1133 if (sr_scpi_get_string(sdi->conn,
1134 (*config->scpi_dialect)[SCPI_CMD_GET_HIGH_RESOLUTION],
1137 if (!strcmp("OFF", tmp_str))
1138 state->high_resolution = FALSE;
1140 state->high_resolution = TRUE;
1143 if (sr_scpi_get_string(sdi->conn,
1144 (*config->scpi_dialect)[SCPI_CMD_GET_PEAK_DETECTION],
1147 if (!strcmp("OFF", tmp_str))
1148 state->peak_detection = FALSE;
1150 state->peak_detection = TRUE;
1153 if (hmo_update_sample_rate(sdi) != SR_OK)
1156 sr_info("Fetching finished.");
1158 scope_state_dump(config, state);
1163 static struct scope_state *scope_state_new(const struct scope_config *config)
1165 struct scope_state *state;
1167 state = g_malloc0(sizeof(struct scope_state));
1168 state->analog_channels = g_malloc0_n(config->analog_channels,
1169 sizeof(struct analog_channel_state));
1170 state->digital_channels = g_malloc0_n(
1171 config->digital_channels, sizeof(gboolean));
1172 state->digital_pods = g_malloc0_n(config->digital_pods,
1173 sizeof(struct digital_pod_state));
1178 SR_PRIV void hmo_scope_state_free(struct scope_state *state)
1180 g_free(state->analog_channels);
1181 g_free(state->digital_channels);
1182 g_free(state->digital_pods);
1186 SR_PRIV int hmo_init_device(struct sr_dev_inst *sdi)
1189 unsigned int i, j, group;
1190 struct sr_channel *ch;
1191 struct dev_context *devc;
1197 /* Find the exact model. */
1198 for (i = 0; i < ARRAY_SIZE(scope_models); i++) {
1199 for (j = 0; scope_models[i].name[j]; j++) {
1200 if (!strcmp(sdi->model, scope_models[i].name[j])) {
1205 if (model_index != -1)
1209 if (model_index == -1) {
1210 sr_dbg("Unsupported device.");
1214 /* Configure the number of PODs given the number of digital channels. */
1215 scope_models[model_index].digital_pods = scope_models[model_index].digital_channels / DIGITAL_CHANNELS_PER_POD;
1217 devc->analog_groups = g_malloc0(sizeof(struct sr_channel_group*) *
1218 scope_models[model_index].analog_channels);
1219 devc->digital_groups = g_malloc0(sizeof(struct sr_channel_group*) *
1220 scope_models[model_index].digital_pods);
1221 if (!devc->analog_groups || !devc->digital_groups) {
1222 g_free(devc->analog_groups);
1223 g_free(devc->digital_groups);
1224 return SR_ERR_MALLOC;
1227 /* Add analog channels. */
1228 for (i = 0; i < scope_models[model_index].analog_channels; i++) {
1229 ch = sr_channel_new(sdi, i, SR_CHANNEL_ANALOG, TRUE,
1230 (*scope_models[model_index].analog_names)[i]);
1232 devc->analog_groups[i] = g_malloc0(sizeof(struct sr_channel_group));
1234 devc->analog_groups[i]->name = g_strdup(
1235 (char *)(*scope_models[model_index].analog_names)[i]);
1236 devc->analog_groups[i]->channels = g_slist_append(NULL, ch);
1238 sdi->channel_groups = g_slist_append(sdi->channel_groups,
1239 devc->analog_groups[i]);
1242 /* Add digital channel groups. */
1244 for (i = 0; i < scope_models[model_index].digital_pods; i++) {
1245 devc->digital_groups[i] = g_malloc0(sizeof(struct sr_channel_group));
1246 if (!devc->digital_groups[i]) {
1247 ret = SR_ERR_MALLOC;
1250 devc->digital_groups[i]->name = g_strdup_printf("POD%d", i + 1);
1251 sdi->channel_groups = g_slist_append(sdi->channel_groups,
1252 devc->digital_groups[i]);
1257 /* Add digital channels. */
1258 for (i = 0; i < scope_models[model_index].digital_channels; i++) {
1259 ch = sr_channel_new(sdi, i, SR_CHANNEL_LOGIC, TRUE,
1260 (*scope_models[model_index].digital_names)[i]);
1262 group = i / DIGITAL_CHANNELS_PER_POD;
1263 devc->digital_groups[group]->channels = g_slist_append(
1264 devc->digital_groups[group]->channels, ch);
1267 devc->model_config = &scope_models[model_index];
1268 devc->samples_limit = 0;
1269 devc->frame_limit = 0;
1271 if (!(devc->model_state = scope_state_new(devc->model_config)))
1272 return SR_ERR_MALLOC;
1277 /* Queue data of one channel group, for later submission. */
1278 SR_PRIV void hmo_queue_logic_data(struct dev_context *devc,
1279 size_t group, GByteArray *pod_data)
1283 uint8_t *logic_data;
1284 size_t idx, logic_step;
1287 * Upon first invocation, allocate the array which can hold the
1288 * combined logic data for all channels. Assume that each channel
1289 * will yield an identical number of samples per receive call.
1291 * As a poor man's safety measure: (Silently) skip processing
1292 * for unexpected sample counts, and ignore samples for
1293 * unexpected channel groups. Don't bother with complicated
1294 * resize logic, considering that many models only support one
1295 * pod, and the most capable supported models have two pods of
1296 * identical size. We haven't yet seen any "odd" configuration.
1298 if (!devc->logic_data) {
1299 size = pod_data->len * devc->pod_count;
1300 store = g_byte_array_sized_new(size);
1301 memset(store->data, 0, size);
1302 store = g_byte_array_set_size(store, size);
1303 devc->logic_data = store;
1305 store = devc->logic_data;
1306 size = store->len / devc->pod_count;
1307 if (group >= devc->pod_count)
1312 * Fold the data of the most recently received channel group into
1313 * the storage, where data resides for all channels combined.
1315 logic_data = store->data;
1316 logic_data += group;
1317 logic_step = devc->pod_count;
1318 for (idx = 0; idx < pod_data->len; idx++) {
1319 *logic_data = pod_data->data[idx];
1320 logic_data += logic_step;
1323 /* Truncate acquisition if a smaller number of samples has been requested. */
1324 if (devc->samples_limit > 0 && devc->logic_data->len > devc->samples_limit * devc->pod_count)
1325 devc->logic_data->len = devc->samples_limit * devc->pod_count;
1328 /* Submit data for all channels, after the individual groups got collected. */
1329 SR_PRIV void hmo_send_logic_packet(struct sr_dev_inst *sdi,
1330 struct dev_context *devc)
1332 struct sr_datafeed_packet packet;
1333 struct sr_datafeed_logic logic;
1335 if (!devc->logic_data)
1338 logic.data = devc->logic_data->data;
1339 logic.length = devc->logic_data->len;
1340 logic.unitsize = devc->pod_count;
1342 packet.type = SR_DF_LOGIC;
1343 packet.payload = &logic;
1345 sr_session_send(sdi, &packet);
1348 /* Undo previous resource allocation. */
1349 SR_PRIV void hmo_cleanup_logic_data(struct dev_context *devc)
1352 if (devc->logic_data) {
1353 g_byte_array_free(devc->logic_data, TRUE);
1354 devc->logic_data = NULL;
1357 * Keep 'pod_count'! It's required when more frames will be
1358 * received, and does not harm when kept after acquisition.
1362 SR_PRIV int hmo_receive_data(int fd, int revents, void *cb_data)
1364 struct sr_channel *ch;
1365 struct sr_dev_inst *sdi;
1366 struct dev_context *devc;
1367 struct scope_state *state;
1368 struct sr_datafeed_packet packet;
1370 struct sr_datafeed_analog analog;
1371 struct sr_analog_encoding encoding;
1372 struct sr_analog_meaning meaning;
1373 struct sr_analog_spec spec;
1374 struct sr_datafeed_logic logic;
1382 if (!(sdi = cb_data))
1385 if (!(devc = sdi->priv))
1388 /* Although this is correct in general, the USBTMC libusb implementation
1389 * currently does not generate an event prior to the first read. Often
1390 * it is ok to start reading just after the 50ms timeout. See bug #785.
1391 if (revents != G_IO_IN)
1395 ch = devc->current_channel->data;
1396 state = devc->model_state;
1399 * Send "frame begin" packet upon reception of data for the
1400 * first enabled channel.
1402 if (devc->current_channel == devc->enabled_channels) {
1403 packet.type = SR_DF_FRAME_BEGIN;
1404 sr_session_send(sdi, &packet);
1408 * Pass on the received data of the channel(s).
1411 case SR_CHANNEL_ANALOG:
1412 if (sr_scpi_get_block(sdi->conn, NULL, &data) != SR_OK) {
1414 g_byte_array_free(data, TRUE);
1418 packet.type = SR_DF_ANALOG;
1420 analog.data = data->data;
1421 analog.num_samples = data->len / sizeof(float);
1422 /* Truncate acquisition if a smaller number of samples has been requested. */
1423 if (devc->samples_limit > 0 && analog.num_samples > devc->samples_limit)
1424 analog.num_samples = devc->samples_limit;
1425 analog.encoding = &encoding;
1426 analog.meaning = &meaning;
1427 analog.spec = &spec;
1429 encoding.unitsize = sizeof(float);
1430 encoding.is_signed = TRUE;
1431 encoding.is_float = TRUE;
1432 #ifdef WORDS_BIGENDIAN
1433 encoding.is_bigendian = TRUE;
1435 encoding.is_bigendian = FALSE;
1437 /* TODO: Use proper 'digits' value for this device (and its modes). */
1438 encoding.digits = 2;
1439 encoding.is_digits_decimal = FALSE;
1440 encoding.scale.p = 1;
1441 encoding.scale.q = 1;
1442 encoding.offset.p = 0;
1443 encoding.offset.q = 1;
1444 if (state->analog_channels[ch->index].probe_unit == 'V') {
1445 meaning.mq = SR_MQ_VOLTAGE;
1446 meaning.unit = SR_UNIT_VOLT;
1448 meaning.mq = SR_MQ_CURRENT;
1449 meaning.unit = SR_UNIT_AMPERE;
1451 meaning.mqflags = 0;
1452 meaning.channels = g_slist_append(NULL, ch);
1453 /* TODO: Use proper 'digits' value for this device (and its modes). */
1454 spec.spec_digits = 2;
1455 packet.payload = &analog;
1456 sr_session_send(sdi, &packet);
1457 devc->num_samples = data->len / sizeof(float);
1458 g_slist_free(meaning.channels);
1459 g_byte_array_free(data, TRUE);
1462 case SR_CHANNEL_LOGIC:
1463 if (sr_scpi_get_block(sdi->conn, NULL, &data) != SR_OK) {
1465 g_byte_array_free(data, TRUE);
1470 * If only data from the first pod is involved in the
1471 * acquisition, then the raw input bytes can get passed
1472 * forward for performance reasons. When the second pod
1473 * is involved (either alone, or in combination with the
1474 * first pod), then the received bytes need to be put
1475 * into memory in such a layout that all channel groups
1476 * get combined, and a unitsize larger than a single byte
1477 * applies. The "queue" logic transparently copes with
1478 * any such configuration. This works around the lack
1479 * of support for "meaning" to logic data, which is used
1480 * above for analog data.
1482 if (devc->pod_count == 1) {
1483 packet.type = SR_DF_LOGIC;
1484 logic.data = data->data;
1485 logic.length = data->len;
1486 /* Truncate acquisition if a smaller number of samples has been requested. */
1487 if (devc->samples_limit > 0 && logic.length > devc->samples_limit)
1488 logic.length = devc->samples_limit;
1490 packet.payload = &logic;
1491 sr_session_send(sdi, &packet);
1493 group = ch->index / DIGITAL_CHANNELS_PER_POD;
1494 hmo_queue_logic_data(devc, group, data);
1497 devc->num_samples = data->len / devc->pod_count;
1498 g_byte_array_free(data, TRUE);
1502 sr_err("Invalid channel type.");
1507 * Advance to the next enabled channel. When data for all enabled
1508 * channels was received, then flush potentially queued logic data,
1509 * and send the "frame end" packet.
1511 if (devc->current_channel->next) {
1512 devc->current_channel = devc->current_channel->next;
1513 hmo_request_data(sdi);
1516 hmo_send_logic_packet(sdi, devc);
1519 * Release the logic data storage after each frame. This copes
1520 * with sample counts that differ in length per frame. -- Is
1521 * this a real constraint when acquiring multiple frames with
1522 * identical device settings?
1524 hmo_cleanup_logic_data(devc);
1526 packet.type = SR_DF_FRAME_END;
1527 sr_session_send(sdi, &packet);
1530 * End of frame was reached. Stop acquisition after the specified
1531 * number of frames or after the specified number of samples, or
1532 * continue reception by starting over at the first enabled channel.
1534 if (++devc->num_frames >= devc->frame_limit || devc->num_samples >= devc->samples_limit) {
1535 sr_dev_acquisition_stop(sdi);
1536 hmo_cleanup_logic_data(devc);
1538 devc->current_channel = devc->enabled_channels;
1539 hmo_request_data(sdi);