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_GET | 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 /* This might need updates whenever logic_threshold* above change. */
187 #define MAX_NUM_LOGIC_THRESHOLD_ENTRIES ARRAY_SIZE(logic_threshold)
189 /* RTC1002, HMO Compact2 and HMO1002/HMO1202 */
190 static const char *an2_dig8_trigger_sources[] = {
192 "LINE", "EXT", "PATT", "BUS1", "BUS2",
193 "D0", "D1", "D2", "D3", "D4", "D5", "D6", "D7",
197 static const char *an2_dig16_trigger_sources[] = {
199 "LINE", "EXT", "PATT", "BUS1", "BUS2",
200 "D0", "D1", "D2", "D3", "D4", "D5", "D6", "D7",
201 "D8", "D9", "D10", "D11", "D12", "D13", "D14", "D15",
204 /* RTB2002 and RTM3002 */
205 static const char *an2_dig16_sbus_trigger_sources[] = {
207 "LINE", "EXT", "PATT", "SBUS1", "SBUS2",
208 "D0", "D1", "D2", "D3", "D4", "D5", "D6", "D7",
209 "D8", "D9", "D10", "D11", "D12", "D13", "D14", "D15",
213 static const char *an4_dig8_trigger_sources[] = {
214 "CH1", "CH2", "CH3", "CH4",
215 "LINE", "EXT", "PATT", "BUS1", "BUS2",
216 "D0", "D1", "D2", "D3", "D4", "D5", "D6", "D7",
219 /* HMO3xx4 and HMO2524 */
220 static const char *an4_dig16_trigger_sources[] = {
221 "CH1", "CH2", "CH3", "CH4",
222 "LINE", "EXT", "PATT", "BUS1", "BUS2",
223 "D0", "D1", "D2", "D3", "D4", "D5", "D6", "D7",
224 "D8", "D9", "D10", "D11", "D12", "D13", "D14", "D15",
227 /* RTB2004, RTM3004 and RTA4004 */
228 static const char *an4_dig16_sbus_trigger_sources[] = {
229 "CH1", "CH2", "CH3", "CH4",
230 "LINE", "EXT", "PATT", "SBUS1", "SBUS2",
231 "D0", "D1", "D2", "D3", "D4", "D5", "D6", "D7",
232 "D8", "D9", "D10", "D11", "D12", "D13", "D14", "D15",
235 static const uint64_t timebases[][2] = {
275 /* HMO Compact series (HMO722/724/1022/1024/1522/1524/2022/2024) do
276 * not support 1 ns timebase setting.
278 static const uint64_t timebases_hmo_compact[][2] = {
317 static const uint64_t vdivs[][2] = {
335 static const char *scope_analog_channel_names[] = {
336 "CH1", "CH2", "CH3", "CH4",
339 static const char *scope_digital_channel_names[] = {
340 "D0", "D1", "D2", "D3", "D4", "D5", "D6", "D7",
341 "D8", "D9", "D10", "D11", "D12", "D13", "D14", "D15",
344 static struct scope_config scope_models[] = {
346 /* HMO Compact2: HMO722/1022/1522/2022 support only 8 digital channels. */
347 .name = {"HMO722", "HMO1022", "HMO1522", "HMO2022", NULL},
348 .analog_channels = 2,
349 .digital_channels = 8,
351 .analog_names = &scope_analog_channel_names,
352 .digital_names = &scope_digital_channel_names,
355 .num_devopts = ARRAY_SIZE(devopts),
357 .devopts_cg_analog = &devopts_cg_analog,
358 .num_devopts_cg_analog = ARRAY_SIZE(devopts_cg_analog),
360 .devopts_cg_digital = &devopts_cg_digital,
361 .num_devopts_cg_digital = ARRAY_SIZE(devopts_cg_digital),
363 .coupling_options = &coupling_options,
364 .num_coupling_options = ARRAY_SIZE(coupling_options),
366 .logic_threshold = &logic_threshold,
367 .num_logic_threshold = ARRAY_SIZE(logic_threshold),
368 .logic_threshold_for_pod = TRUE,
370 .trigger_sources = &an2_dig8_trigger_sources,
371 .num_trigger_sources = ARRAY_SIZE(an2_dig8_trigger_sources),
373 .trigger_slopes = &scope_trigger_slopes,
374 .num_trigger_slopes = ARRAY_SIZE(scope_trigger_slopes),
376 .timebases = &timebases_hmo_compact,
377 .num_timebases = ARRAY_SIZE(timebases_hmo_compact),
380 .num_vdivs = ARRAY_SIZE(vdivs),
384 .scpi_dialect = &hameg_scpi_dialect,
387 /* RTC1002 and HMO1002/HMO1202 support only 8 digital channels. */
388 .name = {"RTC1002", "HMO1002", "HMO1202", NULL},
389 .analog_channels = 2,
390 .digital_channels = 8,
392 .analog_names = &scope_analog_channel_names,
393 .digital_names = &scope_digital_channel_names,
396 .num_devopts = ARRAY_SIZE(devopts),
398 .devopts_cg_analog = &devopts_cg_analog,
399 .num_devopts_cg_analog = ARRAY_SIZE(devopts_cg_analog),
401 .devopts_cg_digital = &devopts_cg_digital,
402 .num_devopts_cg_digital = ARRAY_SIZE(devopts_cg_digital),
404 .coupling_options = &coupling_options,
405 .num_coupling_options = ARRAY_SIZE(coupling_options),
407 .logic_threshold = &logic_threshold,
408 .num_logic_threshold = ARRAY_SIZE(logic_threshold),
409 .logic_threshold_for_pod = TRUE,
411 .trigger_sources = &an2_dig8_trigger_sources,
412 .num_trigger_sources = ARRAY_SIZE(an2_dig8_trigger_sources),
414 .trigger_slopes = &scope_trigger_slopes,
415 .num_trigger_slopes = ARRAY_SIZE(scope_trigger_slopes),
417 .timebases = &timebases,
418 .num_timebases = ARRAY_SIZE(timebases),
421 .num_vdivs = ARRAY_SIZE(vdivs),
425 .scpi_dialect = &hameg_scpi_dialect,
428 /* HMO3032/3042/3052/3522 support 16 digital channels. */
429 .name = {"HMO3032", "HMO3042", "HMO3052", "HMO3522", NULL},
430 .analog_channels = 2,
431 .digital_channels = 16,
433 .analog_names = &scope_analog_channel_names,
434 .digital_names = &scope_digital_channel_names,
437 .num_devopts = ARRAY_SIZE(devopts),
439 .devopts_cg_analog = &devopts_cg_analog,
440 .num_devopts_cg_analog = ARRAY_SIZE(devopts_cg_analog),
442 .devopts_cg_digital = &devopts_cg_digital,
443 .num_devopts_cg_digital = ARRAY_SIZE(devopts_cg_digital),
445 .coupling_options = &coupling_options,
446 .num_coupling_options = ARRAY_SIZE(coupling_options),
448 .logic_threshold = &logic_threshold,
449 .num_logic_threshold = ARRAY_SIZE(logic_threshold),
450 .logic_threshold_for_pod = TRUE,
452 .trigger_sources = &an2_dig16_trigger_sources,
453 .num_trigger_sources = ARRAY_SIZE(an2_dig16_trigger_sources),
455 .trigger_slopes = &scope_trigger_slopes,
456 .num_trigger_slopes = ARRAY_SIZE(scope_trigger_slopes),
458 .timebases = &timebases,
459 .num_timebases = ARRAY_SIZE(timebases),
462 .num_vdivs = ARRAY_SIZE(vdivs),
466 .scpi_dialect = &hameg_scpi_dialect,
469 /* HMO Compact4: HMO724/1024/1524/2024 support only 8 digital channels. */
470 .name = {"HMO724", "HMO1024", "HMO1524", "HMO2024", NULL},
471 .analog_channels = 4,
472 .digital_channels = 8,
474 .analog_names = &scope_analog_channel_names,
475 .digital_names = &scope_digital_channel_names,
478 .num_devopts = ARRAY_SIZE(devopts),
480 .devopts_cg_analog = &devopts_cg_analog,
481 .num_devopts_cg_analog = ARRAY_SIZE(devopts_cg_analog),
483 .devopts_cg_digital = &devopts_cg_digital,
484 .num_devopts_cg_digital = ARRAY_SIZE(devopts_cg_digital),
486 .coupling_options = &coupling_options,
487 .num_coupling_options = ARRAY_SIZE(coupling_options),
489 .logic_threshold = &logic_threshold,
490 .num_logic_threshold = ARRAY_SIZE(logic_threshold),
491 .logic_threshold_for_pod = TRUE,
493 .trigger_sources = &an4_dig8_trigger_sources,
494 .num_trigger_sources = ARRAY_SIZE(an4_dig8_trigger_sources),
496 .trigger_slopes = &scope_trigger_slopes,
497 .num_trigger_slopes = ARRAY_SIZE(scope_trigger_slopes),
499 .timebases = &timebases_hmo_compact,
500 .num_timebases = ARRAY_SIZE(timebases_hmo_compact),
503 .num_vdivs = ARRAY_SIZE(vdivs),
507 .scpi_dialect = &hameg_scpi_dialect,
510 .name = {"HMO2524", "HMO3034", "HMO3044", "HMO3054", "HMO3524", NULL},
511 .analog_channels = 4,
512 .digital_channels = 16,
514 .analog_names = &scope_analog_channel_names,
515 .digital_names = &scope_digital_channel_names,
518 .num_devopts = ARRAY_SIZE(devopts),
520 .devopts_cg_analog = &devopts_cg_analog,
521 .num_devopts_cg_analog = ARRAY_SIZE(devopts_cg_analog),
523 .devopts_cg_digital = &devopts_cg_digital,
524 .num_devopts_cg_digital = ARRAY_SIZE(devopts_cg_digital),
526 .coupling_options = &coupling_options,
527 .num_coupling_options = ARRAY_SIZE(coupling_options),
529 .logic_threshold = &logic_threshold,
530 .num_logic_threshold = ARRAY_SIZE(logic_threshold),
531 .logic_threshold_for_pod = TRUE,
533 .trigger_sources = &an4_dig16_trigger_sources,
534 .num_trigger_sources = ARRAY_SIZE(an4_dig16_trigger_sources),
536 .trigger_slopes = &scope_trigger_slopes,
537 .num_trigger_slopes = ARRAY_SIZE(scope_trigger_slopes),
539 .timebases = &timebases,
540 .num_timebases = ARRAY_SIZE(timebases),
543 .num_vdivs = ARRAY_SIZE(vdivs),
547 .scpi_dialect = &hameg_scpi_dialect,
550 .name = {"RTB2002", NULL},
551 .analog_channels = 2,
552 .digital_channels = 16,
554 .analog_names = &scope_analog_channel_names,
555 .digital_names = &scope_digital_channel_names,
558 .num_devopts = ARRAY_SIZE(devopts),
560 .devopts_cg_analog = &devopts_cg_analog,
561 .num_devopts_cg_analog = ARRAY_SIZE(devopts_cg_analog),
563 .devopts_cg_digital = &devopts_cg_digital,
564 .num_devopts_cg_digital = ARRAY_SIZE(devopts_cg_digital),
566 .coupling_options = &coupling_options_rtb200x,
567 .num_coupling_options = ARRAY_SIZE(coupling_options_rtb200x),
569 .logic_threshold = &logic_threshold_rtb200x_rtm300x,
570 .num_logic_threshold = ARRAY_SIZE(logic_threshold_rtb200x_rtm300x),
571 .logic_threshold_for_pod = FALSE,
573 .trigger_sources = &an2_dig16_sbus_trigger_sources,
574 .num_trigger_sources = ARRAY_SIZE(an2_dig16_sbus_trigger_sources),
576 .trigger_slopes = &scope_trigger_slopes,
577 .num_trigger_slopes = ARRAY_SIZE(scope_trigger_slopes),
579 .timebases = &timebases,
580 .num_timebases = ARRAY_SIZE(timebases),
583 .num_vdivs = ARRAY_SIZE(vdivs),
587 .scpi_dialect = &rohde_schwarz_log_not_pod_scpi_dialect,
590 .name = {"RTB2004", NULL},
591 .analog_channels = 4,
592 .digital_channels = 16,
594 .analog_names = &scope_analog_channel_names,
595 .digital_names = &scope_digital_channel_names,
598 .num_devopts = ARRAY_SIZE(devopts),
600 .devopts_cg_analog = &devopts_cg_analog,
601 .num_devopts_cg_analog = ARRAY_SIZE(devopts_cg_analog),
603 .devopts_cg_digital = &devopts_cg_digital,
604 .num_devopts_cg_digital = ARRAY_SIZE(devopts_cg_digital),
606 .coupling_options = &coupling_options_rtb200x,
607 .num_coupling_options = ARRAY_SIZE(coupling_options_rtb200x),
609 .logic_threshold = &logic_threshold_rtb200x_rtm300x,
610 .num_logic_threshold = ARRAY_SIZE(logic_threshold_rtb200x_rtm300x),
611 .logic_threshold_for_pod = FALSE,
613 .trigger_sources = &an4_dig16_sbus_trigger_sources,
614 .num_trigger_sources = ARRAY_SIZE(an4_dig16_sbus_trigger_sources),
616 .trigger_slopes = &scope_trigger_slopes,
617 .num_trigger_slopes = ARRAY_SIZE(scope_trigger_slopes),
619 .timebases = &timebases,
620 .num_timebases = ARRAY_SIZE(timebases),
623 .num_vdivs = ARRAY_SIZE(vdivs),
627 .scpi_dialect = &rohde_schwarz_log_not_pod_scpi_dialect,
630 .name = {"RTM3002", NULL},
631 .analog_channels = 2,
632 .digital_channels = 16,
634 .analog_names = &scope_analog_channel_names,
635 .digital_names = &scope_digital_channel_names,
638 .num_devopts = ARRAY_SIZE(devopts),
640 .devopts_cg_analog = &devopts_cg_analog,
641 .num_devopts_cg_analog = ARRAY_SIZE(devopts_cg_analog),
643 .devopts_cg_digital = &devopts_cg_digital,
644 .num_devopts_cg_digital = ARRAY_SIZE(devopts_cg_digital),
646 .coupling_options = &coupling_options_rtm300x,
647 .num_coupling_options = ARRAY_SIZE(coupling_options_rtm300x),
649 .logic_threshold = &logic_threshold_rtb200x_rtm300x,
650 .num_logic_threshold = ARRAY_SIZE(logic_threshold_rtb200x_rtm300x),
651 .logic_threshold_for_pod = FALSE,
653 .trigger_sources = &an2_dig16_sbus_trigger_sources,
654 .num_trigger_sources = ARRAY_SIZE(an2_dig16_sbus_trigger_sources),
656 .trigger_slopes = &scope_trigger_slopes,
657 .num_trigger_slopes = ARRAY_SIZE(scope_trigger_slopes),
659 .timebases = &timebases,
660 .num_timebases = ARRAY_SIZE(timebases),
663 .num_vdivs = ARRAY_SIZE(vdivs),
667 .scpi_dialect = &rohde_schwarz_log_not_pod_scpi_dialect,
670 .name = {"RTM3004", NULL},
671 .analog_channels = 4,
672 .digital_channels = 16,
674 .analog_names = &scope_analog_channel_names,
675 .digital_names = &scope_digital_channel_names,
678 .num_devopts = ARRAY_SIZE(devopts),
680 .devopts_cg_analog = &devopts_cg_analog,
681 .num_devopts_cg_analog = ARRAY_SIZE(devopts_cg_analog),
683 .devopts_cg_digital = &devopts_cg_digital,
684 .num_devopts_cg_digital = ARRAY_SIZE(devopts_cg_digital),
686 .coupling_options = &coupling_options_rtm300x,
687 .num_coupling_options = ARRAY_SIZE(coupling_options_rtm300x),
689 .logic_threshold = &logic_threshold_rtb200x_rtm300x,
690 .num_logic_threshold = ARRAY_SIZE(logic_threshold_rtb200x_rtm300x),
691 .logic_threshold_for_pod = FALSE,
693 .trigger_sources = &an4_dig16_sbus_trigger_sources,
694 .num_trigger_sources = ARRAY_SIZE(an4_dig16_sbus_trigger_sources),
696 .trigger_slopes = &scope_trigger_slopes,
697 .num_trigger_slopes = ARRAY_SIZE(scope_trigger_slopes),
699 .timebases = &timebases,
700 .num_timebases = ARRAY_SIZE(timebases),
703 .num_vdivs = ARRAY_SIZE(vdivs),
707 .scpi_dialect = &rohde_schwarz_log_not_pod_scpi_dialect,
710 .name = {"RTA4004", NULL},
711 .analog_channels = 4,
712 .digital_channels = 16,
714 .analog_names = &scope_analog_channel_names,
715 .digital_names = &scope_digital_channel_names,
718 .num_devopts = ARRAY_SIZE(devopts),
720 .devopts_cg_analog = &devopts_cg_analog,
721 .num_devopts_cg_analog = ARRAY_SIZE(devopts_cg_analog),
723 .devopts_cg_digital = &devopts_cg_digital,
724 .num_devopts_cg_digital = ARRAY_SIZE(devopts_cg_digital),
726 .coupling_options = &coupling_options_rtm300x,
727 .num_coupling_options = ARRAY_SIZE(coupling_options_rtm300x),
729 .logic_threshold = &logic_threshold_rtb200x_rtm300x,
730 .num_logic_threshold = ARRAY_SIZE(logic_threshold_rtb200x_rtm300x),
731 .logic_threshold_for_pod = FALSE,
733 .trigger_sources = &an4_dig16_sbus_trigger_sources,
734 .num_trigger_sources = ARRAY_SIZE(an4_dig16_sbus_trigger_sources),
736 .trigger_slopes = &scope_trigger_slopes,
737 .num_trigger_slopes = ARRAY_SIZE(scope_trigger_slopes),
739 .timebases = &timebases,
740 .num_timebases = ARRAY_SIZE(timebases),
743 .num_vdivs = ARRAY_SIZE(vdivs),
747 .scpi_dialect = &rohde_schwarz_log_not_pod_scpi_dialect,
751 static void scope_state_dump(const struct scope_config *config,
752 struct scope_state *state)
757 for (i = 0; i < config->analog_channels; i++) {
758 tmp = sr_voltage_string((*config->vdivs)[state->analog_channels[i].vdiv][0],
759 (*config->vdivs)[state->analog_channels[i].vdiv][1]);
760 sr_info("State of analog channel %d -> %s : %s (coupling) %s (vdiv) %2.2e (offset)",
761 i + 1, state->analog_channels[i].state ? "On" : "Off",
762 (*config->coupling_options)[state->analog_channels[i].coupling],
763 tmp, state->analog_channels[i].vertical_offset);
766 for (i = 0; i < config->digital_channels; i++) {
767 sr_info("State of digital channel %d -> %s", i,
768 state->digital_channels[i] ? "On" : "Off");
771 for (i = 0; i < config->digital_pods; i++) {
772 if (!strncmp("USER", (*config->logic_threshold)[state->digital_pods[i].threshold], 4) ||
773 !strcmp("MAN", (*config->logic_threshold)[state->digital_pods[i].threshold]))
774 sr_info("State of digital POD %d -> %s : %E (threshold)", i + 1,
775 state->digital_pods[i].state ? "On" : "Off",
776 state->digital_pods[i].user_threshold);
778 sr_info("State of digital POD %d -> %s : %s (threshold)", i + 1,
779 state->digital_pods[i].state ? "On" : "Off",
780 (*config->logic_threshold)[state->digital_pods[i].threshold]);
783 tmp = sr_period_string((*config->timebases)[state->timebase][0],
784 (*config->timebases)[state->timebase][1]);
785 sr_info("Current timebase: %s", tmp);
788 tmp = sr_samplerate_string(state->sample_rate);
789 sr_info("Current samplerate: %s", tmp);
792 if (!strcmp("PATT", (*config->trigger_sources)[state->trigger_source]))
793 sr_info("Current trigger: %s (pattern), %.2f (offset)",
794 state->trigger_pattern,
795 state->horiz_triggerpos);
796 else // Edge (slope) trigger
797 sr_info("Current trigger: %s (source), %s (slope) %.2f (offset)",
798 (*config->trigger_sources)[state->trigger_source],
799 (*config->trigger_slopes)[state->trigger_slope],
800 state->horiz_triggerpos);
803 static int scope_state_get_array_option(struct sr_scpi_dev_inst *scpi,
804 const char *command, const char *(*array)[], unsigned int n, int *result)
809 if (sr_scpi_get_string(scpi, command, &tmp) != SR_OK)
812 if ((idx = std_str_idx_s(tmp, *array, n)) < 0) {
825 * This function takes a value of the form "2.000E-03" and returns the index
826 * of an array where a matching pair was found.
828 * @param value The string to be parsed.
829 * @param array The array of s/f pairs.
830 * @param array_len The number of pairs in the array.
831 * @param result The index at which a matching pair was found.
833 * @return SR_ERR on any parsing error, SR_OK otherwise.
835 static int array_float_get(gchar *value, const uint64_t array[][2],
836 int array_len, unsigned int *result)
838 struct sr_rational rval;
839 struct sr_rational aval;
841 if (sr_parse_rational(value, &rval) != SR_OK)
844 for (int i = 0; i < array_len; i++) {
845 sr_rational_set(&aval, array[i][0], array[i][1]);
846 if (sr_rational_eq(&rval, &aval)) {
855 static struct sr_channel *get_channel_by_index_and_type(GSList *channel_lhead,
858 while (channel_lhead) {
859 struct sr_channel *ch = channel_lhead->data;
860 if (ch->index == index && ch->type == type)
863 channel_lhead = channel_lhead->next;
869 static int analog_channel_state_get(struct sr_dev_inst *sdi,
870 const struct scope_config *config,
871 struct scope_state *state)
874 char command[MAX_COMMAND_SIZE];
876 struct sr_channel *ch;
877 struct sr_scpi_dev_inst *scpi = sdi->conn;
879 for (i = 0; i < config->analog_channels; i++) {
880 g_snprintf(command, sizeof(command),
881 (*config->scpi_dialect)[SCPI_CMD_GET_ANALOG_CHAN_STATE],
884 if (sr_scpi_get_bool(scpi, command,
885 &state->analog_channels[i].state) != SR_OK)
888 ch = get_channel_by_index_and_type(sdi->channels, i, SR_CHANNEL_ANALOG);
890 ch->enabled = state->analog_channels[i].state;
892 g_snprintf(command, sizeof(command),
893 (*config->scpi_dialect)[SCPI_CMD_GET_VERTICAL_SCALE],
896 if (sr_scpi_get_string(scpi, command, &tmp_str) != SR_OK)
899 if (array_float_get(tmp_str, ARRAY_AND_SIZE(vdivs), &j) != SR_OK) {
901 sr_err("Could not determine array index for vertical div scale.");
906 state->analog_channels[i].vdiv = j;
908 g_snprintf(command, sizeof(command),
909 (*config->scpi_dialect)[SCPI_CMD_GET_VERTICAL_OFFSET],
912 if (sr_scpi_get_float(scpi, command,
913 &state->analog_channels[i].vertical_offset) != SR_OK)
916 g_snprintf(command, sizeof(command),
917 (*config->scpi_dialect)[SCPI_CMD_GET_COUPLING],
920 if (scope_state_get_array_option(scpi, command, config->coupling_options,
921 config->num_coupling_options,
922 &state->analog_channels[i].coupling) != SR_OK)
925 g_snprintf(command, sizeof(command),
926 (*config->scpi_dialect)[SCPI_CMD_GET_PROBE_UNIT],
929 if (sr_scpi_get_string(scpi, command, &tmp_str) != SR_OK)
932 if (tmp_str[0] == 'A')
933 state->analog_channels[i].probe_unit = 'A';
935 state->analog_channels[i].probe_unit = 'V';
942 static int digital_channel_state_get(struct sr_dev_inst *sdi,
943 const struct scope_config *config,
944 struct scope_state *state)
948 char *logic_threshold_short[MAX_NUM_LOGIC_THRESHOLD_ENTRIES];
949 char command[MAX_COMMAND_SIZE];
950 struct sr_channel *ch;
951 struct sr_scpi_dev_inst *scpi = sdi->conn;
953 for (i = 0; i < config->digital_channels; i++) {
954 g_snprintf(command, sizeof(command),
955 (*config->scpi_dialect)[SCPI_CMD_GET_DIG_CHAN_STATE],
958 if (sr_scpi_get_bool(scpi, command,
959 &state->digital_channels[i]) != SR_OK)
962 ch = get_channel_by_index_and_type(sdi->channels, i, SR_CHANNEL_LOGIC);
964 ch->enabled = state->digital_channels[i];
967 /* According to the SCPI standard, on models that support multiple
968 * user-defined logic threshold settings the response to the command
969 * SCPI_CMD_GET_DIG_POD_THRESHOLD might return "USER" instead of
972 * This makes more difficult to validate the response when the logic
973 * threshold is set to "USER1" and therefore we need to prevent device
974 * opening failures in such configuration case...
976 for (i = 0; i < config->num_logic_threshold; i++) {
977 logic_threshold_short[i] = g_strdup((*config->logic_threshold)[i]);
978 if (!strcmp("USER1", (*config->logic_threshold)[i]))
979 g_strlcpy(logic_threshold_short[i],
980 (*config->logic_threshold)[i], strlen((*config->logic_threshold)[i]));
983 for (i = 0; i < config->digital_pods; i++) {
984 g_snprintf(command, sizeof(command),
985 (*config->scpi_dialect)[SCPI_CMD_GET_DIG_POD_STATE],
988 if (sr_scpi_get_bool(scpi, command,
989 &state->digital_pods[i].state) != SR_OK)
992 /* Check if the threshold command is based on the POD or digital channel index. */
993 if (config->logic_threshold_for_pod)
996 idx = i * DIGITAL_CHANNELS_PER_POD;
998 g_snprintf(command, sizeof(command),
999 (*config->scpi_dialect)[SCPI_CMD_GET_DIG_POD_THRESHOLD],
1002 /* Check for both standard and shortened responses. */
1003 if (scope_state_get_array_option(scpi, command, config->logic_threshold,
1004 config->num_logic_threshold,
1005 &state->digital_pods[i].threshold) != SR_OK)
1006 if (scope_state_get_array_option(scpi, command, (const char * (*)[]) &logic_threshold_short,
1007 config->num_logic_threshold,
1008 &state->digital_pods[i].threshold) != SR_OK)
1011 /* If used-defined or custom threshold is active, get the level. */
1012 if (!strcmp("USER1", (*config->logic_threshold)[state->digital_pods[i].threshold]))
1013 g_snprintf(command, sizeof(command),
1014 (*config->scpi_dialect)[SCPI_CMD_GET_DIG_POD_USER_THRESHOLD],
1015 idx, 1); /* USER1 logic threshold setting. */
1016 else if (!strcmp("USER2", (*config->logic_threshold)[state->digital_pods[i].threshold]))
1017 g_snprintf(command, sizeof(command),
1018 (*config->scpi_dialect)[SCPI_CMD_GET_DIG_POD_USER_THRESHOLD],
1019 idx, 2); /* USER2 for custom logic_threshold setting. */
1020 else if (!strcmp("USER", (*config->logic_threshold)[state->digital_pods[i].threshold]) ||
1021 !strcmp("MAN", (*config->logic_threshold)[state->digital_pods[i].threshold]))
1022 g_snprintf(command, sizeof(command),
1023 (*config->scpi_dialect)[SCPI_CMD_GET_DIG_POD_USER_THRESHOLD],
1024 idx); /* USER or MAN for custom logic_threshold setting. */
1025 if (!strcmp("USER1", (*config->logic_threshold)[state->digital_pods[i].threshold]) ||
1026 !strcmp("USER2", (*config->logic_threshold)[state->digital_pods[i].threshold]) ||
1027 !strcmp("USER", (*config->logic_threshold)[state->digital_pods[i].threshold]) ||
1028 !strcmp("MAN", (*config->logic_threshold)[state->digital_pods[i].threshold]))
1029 if (sr_scpi_get_float(scpi, command,
1030 &state->digital_pods[i].user_threshold) != SR_OK)
1037 for (i = 0; i < config->num_logic_threshold; i++)
1038 g_free(logic_threshold_short[i]);
1043 SR_PRIV int hmo_update_sample_rate(const struct sr_dev_inst *sdi)
1045 struct dev_context *devc;
1046 struct scope_state *state;
1047 const struct scope_config *config;
1051 config = devc->model_config;
1052 state = devc->model_state;
1054 if (sr_scpi_get_float(sdi->conn,
1055 (*config->scpi_dialect)[SCPI_CMD_GET_SAMPLE_RATE],
1056 &tmp_float) != SR_OK)
1059 state->sample_rate = tmp_float;
1064 SR_PRIV int hmo_scope_state_get(struct sr_dev_inst *sdi)
1066 struct dev_context *devc;
1067 struct scope_state *state;
1068 const struct scope_config *config;
1074 config = devc->model_config;
1075 state = devc->model_state;
1077 sr_info("Fetching scope state");
1079 if (analog_channel_state_get(sdi, config, state) != SR_OK)
1082 if (digital_channel_state_get(sdi, config, state) != SR_OK)
1085 if (sr_scpi_get_string(sdi->conn,
1086 (*config->scpi_dialect)[SCPI_CMD_GET_TIMEBASE],
1090 if (array_float_get(tmp_str, ARRAY_AND_SIZE(timebases), &i) != SR_OK) {
1092 sr_err("Could not determine array index for time base.");
1097 state->timebase = i;
1099 /* Determine the number of horizontal (x) divisions. */
1100 if (sr_scpi_get_int(sdi->conn,
1101 (*config->scpi_dialect)[SCPI_CMD_GET_HORIZONTAL_DIV],
1102 (int *)&config->num_xdivs) != SR_OK)
1105 if (sr_scpi_get_float(sdi->conn,
1106 (*config->scpi_dialect)[SCPI_CMD_GET_HORIZ_TRIGGERPOS],
1107 &tmp_float) != SR_OK)
1109 state->horiz_triggerpos = tmp_float /
1110 (((double) (*config->timebases)[state->timebase][0] /
1111 (*config->timebases)[state->timebase][1]) * config->num_xdivs);
1112 state->horiz_triggerpos -= 0.5;
1113 state->horiz_triggerpos *= -1;
1115 if (scope_state_get_array_option(sdi->conn,
1116 (*config->scpi_dialect)[SCPI_CMD_GET_TRIGGER_SOURCE],
1117 config->trigger_sources, config->num_trigger_sources,
1118 &state->trigger_source) != SR_OK)
1121 if (scope_state_get_array_option(sdi->conn,
1122 (*config->scpi_dialect)[SCPI_CMD_GET_TRIGGER_SLOPE],
1123 config->trigger_slopes, config->num_trigger_slopes,
1124 &state->trigger_slope) != SR_OK)
1127 if (sr_scpi_get_string(sdi->conn,
1128 (*config->scpi_dialect)[SCPI_CMD_GET_TRIGGER_PATTERN],
1131 strncpy(state->trigger_pattern,
1132 sr_scpi_unquote_string(tmp_str),
1133 MAX_ANALOG_CHANNEL_COUNT + MAX_DIGITAL_CHANNEL_COUNT);
1136 if (sr_scpi_get_string(sdi->conn,
1137 (*config->scpi_dialect)[SCPI_CMD_GET_HIGH_RESOLUTION],
1140 if (!strcmp("OFF", tmp_str))
1141 state->high_resolution = FALSE;
1143 state->high_resolution = TRUE;
1146 if (sr_scpi_get_string(sdi->conn,
1147 (*config->scpi_dialect)[SCPI_CMD_GET_PEAK_DETECTION],
1150 if (!strcmp("OFF", tmp_str))
1151 state->peak_detection = FALSE;
1153 state->peak_detection = TRUE;
1156 if (hmo_update_sample_rate(sdi) != SR_OK)
1159 sr_info("Fetching finished.");
1161 scope_state_dump(config, state);
1166 static struct scope_state *scope_state_new(const struct scope_config *config)
1168 struct scope_state *state;
1170 state = g_malloc0(sizeof(struct scope_state));
1171 state->analog_channels = g_malloc0_n(config->analog_channels,
1172 sizeof(struct analog_channel_state));
1173 state->digital_channels = g_malloc0_n(
1174 config->digital_channels, sizeof(gboolean));
1175 state->digital_pods = g_malloc0_n(config->digital_pods,
1176 sizeof(struct digital_pod_state));
1181 SR_PRIV void hmo_scope_state_free(struct scope_state *state)
1183 g_free(state->analog_channels);
1184 g_free(state->digital_channels);
1185 g_free(state->digital_pods);
1189 SR_PRIV int hmo_init_device(struct sr_dev_inst *sdi)
1192 unsigned int i, j, group;
1193 struct sr_channel *ch;
1194 struct dev_context *devc;
1200 /* Find the exact model. */
1201 for (i = 0; i < ARRAY_SIZE(scope_models); i++) {
1202 for (j = 0; scope_models[i].name[j]; j++) {
1203 if (!strcmp(sdi->model, scope_models[i].name[j])) {
1208 if (model_index != -1)
1212 if (model_index == -1) {
1213 sr_dbg("Unsupported device.");
1217 /* Configure the number of PODs given the number of digital channels. */
1218 scope_models[model_index].digital_pods = scope_models[model_index].digital_channels / DIGITAL_CHANNELS_PER_POD;
1220 devc->analog_groups = g_malloc0(sizeof(struct sr_channel_group*) *
1221 scope_models[model_index].analog_channels);
1222 devc->digital_groups = g_malloc0(sizeof(struct sr_channel_group*) *
1223 scope_models[model_index].digital_pods);
1224 if (!devc->analog_groups || !devc->digital_groups) {
1225 g_free(devc->analog_groups);
1226 g_free(devc->digital_groups);
1227 return SR_ERR_MALLOC;
1230 /* Add analog channels. */
1231 for (i = 0; i < scope_models[model_index].analog_channels; i++) {
1232 ch = sr_channel_new(sdi, i, SR_CHANNEL_ANALOG, TRUE,
1233 (*scope_models[model_index].analog_names)[i]);
1235 devc->analog_groups[i] = g_malloc0(sizeof(struct sr_channel_group));
1237 devc->analog_groups[i]->name = g_strdup(
1238 (char *)(*scope_models[model_index].analog_names)[i]);
1239 devc->analog_groups[i]->channels = g_slist_append(NULL, ch);
1241 sdi->channel_groups = g_slist_append(sdi->channel_groups,
1242 devc->analog_groups[i]);
1245 /* Add digital channel groups. */
1247 for (i = 0; i < scope_models[model_index].digital_pods; i++) {
1248 devc->digital_groups[i] = g_malloc0(sizeof(struct sr_channel_group));
1249 if (!devc->digital_groups[i]) {
1250 ret = SR_ERR_MALLOC;
1253 devc->digital_groups[i]->name = g_strdup_printf("POD%d", i + 1);
1254 sdi->channel_groups = g_slist_append(sdi->channel_groups,
1255 devc->digital_groups[i]);
1260 /* Add digital channels. */
1261 for (i = 0; i < scope_models[model_index].digital_channels; i++) {
1262 ch = sr_channel_new(sdi, i, SR_CHANNEL_LOGIC, TRUE,
1263 (*scope_models[model_index].digital_names)[i]);
1265 group = i / DIGITAL_CHANNELS_PER_POD;
1266 devc->digital_groups[group]->channels = g_slist_append(
1267 devc->digital_groups[group]->channels, ch);
1270 devc->model_config = &scope_models[model_index];
1271 devc->samples_limit = 0;
1272 devc->frame_limit = 0;
1274 if (!(devc->model_state = scope_state_new(devc->model_config)))
1275 return SR_ERR_MALLOC;
1280 /* Queue data of one channel group, for later submission. */
1281 SR_PRIV void hmo_queue_logic_data(struct dev_context *devc,
1282 size_t group, GByteArray *pod_data)
1286 uint8_t *logic_data;
1287 size_t idx, logic_step;
1290 * Upon first invocation, allocate the array which can hold the
1291 * combined logic data for all channels. Assume that each channel
1292 * will yield an identical number of samples per receive call.
1294 * As a poor man's safety measure: (Silently) skip processing
1295 * for unexpected sample counts, and ignore samples for
1296 * unexpected channel groups. Don't bother with complicated
1297 * resize logic, considering that many models only support one
1298 * pod, and the most capable supported models have two pods of
1299 * identical size. We haven't yet seen any "odd" configuration.
1301 if (!devc->logic_data) {
1302 size = pod_data->len * devc->pod_count;
1303 store = g_byte_array_sized_new(size);
1304 memset(store->data, 0, size);
1305 store = g_byte_array_set_size(store, size);
1306 devc->logic_data = store;
1308 store = devc->logic_data;
1309 size = store->len / devc->pod_count;
1310 if (group >= devc->pod_count)
1315 * Fold the data of the most recently received channel group into
1316 * the storage, where data resides for all channels combined.
1318 logic_data = store->data;
1319 logic_data += group;
1320 logic_step = devc->pod_count;
1321 for (idx = 0; idx < pod_data->len; idx++) {
1322 *logic_data = pod_data->data[idx];
1323 logic_data += logic_step;
1326 /* Truncate acquisition if a smaller number of samples has been requested. */
1327 if (devc->samples_limit > 0 && devc->logic_data->len > devc->samples_limit * devc->pod_count)
1328 devc->logic_data->len = devc->samples_limit * devc->pod_count;
1331 /* Submit data for all channels, after the individual groups got collected. */
1332 SR_PRIV void hmo_send_logic_packet(struct sr_dev_inst *sdi,
1333 struct dev_context *devc)
1335 struct sr_datafeed_packet packet;
1336 struct sr_datafeed_logic logic;
1338 if (!devc->logic_data)
1341 logic.data = devc->logic_data->data;
1342 logic.length = devc->logic_data->len;
1343 logic.unitsize = devc->pod_count;
1345 packet.type = SR_DF_LOGIC;
1346 packet.payload = &logic;
1348 sr_session_send(sdi, &packet);
1351 /* Undo previous resource allocation. */
1352 SR_PRIV void hmo_cleanup_logic_data(struct dev_context *devc)
1355 if (devc->logic_data) {
1356 g_byte_array_free(devc->logic_data, TRUE);
1357 devc->logic_data = NULL;
1360 * Keep 'pod_count'! It's required when more frames will be
1361 * received, and does not harm when kept after acquisition.
1365 SR_PRIV int hmo_receive_data(int fd, int revents, void *cb_data)
1367 struct sr_channel *ch;
1368 struct sr_dev_inst *sdi;
1369 struct dev_context *devc;
1370 struct scope_state *state;
1371 struct sr_datafeed_packet packet;
1373 struct sr_datafeed_analog analog;
1374 struct sr_analog_encoding encoding;
1375 struct sr_analog_meaning meaning;
1376 struct sr_analog_spec spec;
1377 struct sr_datafeed_logic logic;
1385 if (!(sdi = cb_data))
1388 if (!(devc = sdi->priv))
1391 /* Although this is correct in general, the USBTMC libusb implementation
1392 * currently does not generate an event prior to the first read. Often
1393 * it is ok to start reading just after the 50ms timeout. See bug #785.
1394 if (revents != G_IO_IN)
1398 ch = devc->current_channel->data;
1399 state = devc->model_state;
1402 * Send "frame begin" packet upon reception of data for the
1403 * first enabled channel.
1405 if (devc->current_channel == devc->enabled_channels)
1406 std_session_send_df_frame_begin(sdi);
1409 * Pass on the received data of the channel(s).
1412 case SR_CHANNEL_ANALOG:
1413 if (sr_scpi_get_block(sdi->conn, NULL, &data) != SR_OK) {
1415 g_byte_array_free(data, TRUE);
1419 packet.type = SR_DF_ANALOG;
1421 analog.data = data->data;
1422 analog.num_samples = data->len / sizeof(float);
1423 /* Truncate acquisition if a smaller number of samples has been requested. */
1424 if (devc->samples_limit > 0 && analog.num_samples > devc->samples_limit)
1425 analog.num_samples = devc->samples_limit;
1426 /* TODO: Use proper 'digits' value for this device (and its modes). */
1427 sr_analog_init(&analog, &encoding, &meaning, &spec, 2);
1428 encoding.is_signed = TRUE;
1429 if (state->analog_channels[ch->index].probe_unit == 'V') {
1430 meaning.mq = SR_MQ_VOLTAGE;
1431 meaning.unit = SR_UNIT_VOLT;
1433 meaning.mq = SR_MQ_CURRENT;
1434 meaning.unit = SR_UNIT_AMPERE;
1436 meaning.channels = g_slist_append(NULL, ch);
1437 packet.payload = &analog;
1438 sr_session_send(sdi, &packet);
1439 devc->num_samples = data->len / sizeof(float);
1440 g_slist_free(meaning.channels);
1441 g_byte_array_free(data, TRUE);
1444 case SR_CHANNEL_LOGIC:
1445 if (sr_scpi_get_block(sdi->conn, NULL, &data) != SR_OK) {
1447 g_byte_array_free(data, TRUE);
1452 * If only data from the first pod is involved in the
1453 * acquisition, then the raw input bytes can get passed
1454 * forward for performance reasons. When the second pod
1455 * is involved (either alone, or in combination with the
1456 * first pod), then the received bytes need to be put
1457 * into memory in such a layout that all channel groups
1458 * get combined, and a unitsize larger than a single byte
1459 * applies. The "queue" logic transparently copes with
1460 * any such configuration. This works around the lack
1461 * of support for "meaning" to logic data, which is used
1462 * above for analog data.
1464 if (devc->pod_count == 1) {
1465 packet.type = SR_DF_LOGIC;
1466 logic.data = data->data;
1467 logic.length = data->len;
1468 /* Truncate acquisition if a smaller number of samples has been requested. */
1469 if (devc->samples_limit > 0 && logic.length > devc->samples_limit)
1470 logic.length = devc->samples_limit;
1472 packet.payload = &logic;
1473 sr_session_send(sdi, &packet);
1475 group = ch->index / DIGITAL_CHANNELS_PER_POD;
1476 hmo_queue_logic_data(devc, group, data);
1479 devc->num_samples = data->len / devc->pod_count;
1480 g_byte_array_free(data, TRUE);
1484 sr_err("Invalid channel type.");
1489 * Advance to the next enabled channel. When data for all enabled
1490 * channels was received, then flush potentially queued logic data,
1491 * and send the "frame end" packet.
1493 if (devc->current_channel->next) {
1494 devc->current_channel = devc->current_channel->next;
1495 hmo_request_data(sdi);
1498 hmo_send_logic_packet(sdi, devc);
1501 * Release the logic data storage after each frame. This copes
1502 * with sample counts that differ in length per frame. -- Is
1503 * this a real constraint when acquiring multiple frames with
1504 * identical device settings?
1506 hmo_cleanup_logic_data(devc);
1508 std_session_send_df_frame_end(sdi);
1511 * End of frame was reached. Stop acquisition after the specified
1512 * number of frames or after the specified number of samples, or
1513 * continue reception by starting over at the first enabled channel.
1515 if (++devc->num_frames >= devc->frame_limit || devc->num_samples >= devc->samples_limit) {
1516 sr_dev_acquisition_stop(sdi);
1517 hmo_cleanup_logic_data(devc);
1519 devc->current_channel = devc->enabled_channels;
1520 hmo_request_data(sdi);