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] = {
337 * It feels a little hacky to use a single table yet use different item
338 * count values here. But it simplifies maintenance, reduces redundancy
339 * by avoiding several vdivs[] table versions of mostly identical content,
340 * still references which declare models' capabilities remain readable.
342 #define VDIVS_COUNT_UPTO_10V (ARRAY_SIZE(vdivs) - 2)
343 #define VDIVS_COUNT_UPTO_50V (ARRAY_SIZE(vdivs))
345 static const char *scope_analog_channel_names[] = {
346 "CH1", "CH2", "CH3", "CH4",
349 static const char *scope_digital_channel_names[] = {
350 "D0", "D1", "D2", "D3", "D4", "D5", "D6", "D7",
351 "D8", "D9", "D10", "D11", "D12", "D13", "D14", "D15",
354 static struct scope_config scope_models[] = {
356 /* HMO Compact2: HMO722/1022/1522/2022 support only 8 digital channels. */
357 .name = {"HMO722", "HMO1022", "HMO1522", "HMO2022", NULL},
358 .analog_channels = 2,
359 .digital_channels = 8,
361 .analog_names = &scope_analog_channel_names,
362 .digital_names = &scope_digital_channel_names,
365 .num_devopts = ARRAY_SIZE(devopts),
367 .devopts_cg_analog = &devopts_cg_analog,
368 .num_devopts_cg_analog = ARRAY_SIZE(devopts_cg_analog),
370 .devopts_cg_digital = &devopts_cg_digital,
371 .num_devopts_cg_digital = ARRAY_SIZE(devopts_cg_digital),
373 .coupling_options = &coupling_options,
374 .num_coupling_options = ARRAY_SIZE(coupling_options),
376 .logic_threshold = &logic_threshold,
377 .num_logic_threshold = ARRAY_SIZE(logic_threshold),
378 .logic_threshold_for_pod = TRUE,
380 .trigger_sources = &an2_dig8_trigger_sources,
381 .num_trigger_sources = ARRAY_SIZE(an2_dig8_trigger_sources),
383 .trigger_slopes = &scope_trigger_slopes,
384 .num_trigger_slopes = ARRAY_SIZE(scope_trigger_slopes),
386 .timebases = &timebases_hmo_compact,
387 .num_timebases = ARRAY_SIZE(timebases_hmo_compact),
390 .num_vdivs = VDIVS_COUNT_UPTO_10V,
394 .scpi_dialect = &hameg_scpi_dialect,
397 /* RTC1002 and HMO1002/HMO1202 support only 8 digital channels. */
398 .name = {"RTC1002", "HMO1002", "HMO1202", NULL},
399 .analog_channels = 2,
400 .digital_channels = 8,
402 .analog_names = &scope_analog_channel_names,
403 .digital_names = &scope_digital_channel_names,
406 .num_devopts = ARRAY_SIZE(devopts),
408 .devopts_cg_analog = &devopts_cg_analog,
409 .num_devopts_cg_analog = ARRAY_SIZE(devopts_cg_analog),
411 .devopts_cg_digital = &devopts_cg_digital,
412 .num_devopts_cg_digital = ARRAY_SIZE(devopts_cg_digital),
414 .coupling_options = &coupling_options,
415 .num_coupling_options = ARRAY_SIZE(coupling_options),
417 .logic_threshold = &logic_threshold,
418 .num_logic_threshold = ARRAY_SIZE(logic_threshold),
419 .logic_threshold_for_pod = TRUE,
421 .trigger_sources = &an2_dig8_trigger_sources,
422 .num_trigger_sources = ARRAY_SIZE(an2_dig8_trigger_sources),
424 .trigger_slopes = &scope_trigger_slopes,
425 .num_trigger_slopes = ARRAY_SIZE(scope_trigger_slopes),
427 .timebases = &timebases,
428 .num_timebases = ARRAY_SIZE(timebases),
431 .num_vdivs = VDIVS_COUNT_UPTO_10V,
435 .scpi_dialect = &hameg_scpi_dialect,
438 /* HMO3032/3042/3052/3522 support 16 digital channels. */
439 .name = {"HMO3032", "HMO3042", "HMO3052", "HMO3522", NULL},
440 .analog_channels = 2,
441 .digital_channels = 16,
443 .analog_names = &scope_analog_channel_names,
444 .digital_names = &scope_digital_channel_names,
447 .num_devopts = ARRAY_SIZE(devopts),
449 .devopts_cg_analog = &devopts_cg_analog,
450 .num_devopts_cg_analog = ARRAY_SIZE(devopts_cg_analog),
452 .devopts_cg_digital = &devopts_cg_digital,
453 .num_devopts_cg_digital = ARRAY_SIZE(devopts_cg_digital),
455 .coupling_options = &coupling_options,
456 .num_coupling_options = ARRAY_SIZE(coupling_options),
458 .logic_threshold = &logic_threshold,
459 .num_logic_threshold = ARRAY_SIZE(logic_threshold),
460 .logic_threshold_for_pod = TRUE,
462 .trigger_sources = &an2_dig16_trigger_sources,
463 .num_trigger_sources = ARRAY_SIZE(an2_dig16_trigger_sources),
465 .trigger_slopes = &scope_trigger_slopes,
466 .num_trigger_slopes = ARRAY_SIZE(scope_trigger_slopes),
468 .timebases = &timebases,
469 .num_timebases = ARRAY_SIZE(timebases),
472 .num_vdivs = VDIVS_COUNT_UPTO_10V,
476 .scpi_dialect = &hameg_scpi_dialect,
479 /* HMO Compact4: HMO724/1024/1524/2024 support only 8 digital channels. */
480 .name = {"HMO724", "HMO1024", "HMO1524", "HMO2024", NULL},
481 .analog_channels = 4,
482 .digital_channels = 8,
484 .analog_names = &scope_analog_channel_names,
485 .digital_names = &scope_digital_channel_names,
488 .num_devopts = ARRAY_SIZE(devopts),
490 .devopts_cg_analog = &devopts_cg_analog,
491 .num_devopts_cg_analog = ARRAY_SIZE(devopts_cg_analog),
493 .devopts_cg_digital = &devopts_cg_digital,
494 .num_devopts_cg_digital = ARRAY_SIZE(devopts_cg_digital),
496 .coupling_options = &coupling_options,
497 .num_coupling_options = ARRAY_SIZE(coupling_options),
499 .logic_threshold = &logic_threshold,
500 .num_logic_threshold = ARRAY_SIZE(logic_threshold),
501 .logic_threshold_for_pod = TRUE,
503 .trigger_sources = &an4_dig8_trigger_sources,
504 .num_trigger_sources = ARRAY_SIZE(an4_dig8_trigger_sources),
506 .trigger_slopes = &scope_trigger_slopes,
507 .num_trigger_slopes = ARRAY_SIZE(scope_trigger_slopes),
509 .timebases = &timebases_hmo_compact,
510 .num_timebases = ARRAY_SIZE(timebases_hmo_compact),
513 .num_vdivs = VDIVS_COUNT_UPTO_10V,
517 .scpi_dialect = &hameg_scpi_dialect,
520 .name = {"HMO2524", "HMO3034", "HMO3044", "HMO3054", "HMO3524", NULL},
521 .analog_channels = 4,
522 .digital_channels = 16,
524 .analog_names = &scope_analog_channel_names,
525 .digital_names = &scope_digital_channel_names,
528 .num_devopts = ARRAY_SIZE(devopts),
530 .devopts_cg_analog = &devopts_cg_analog,
531 .num_devopts_cg_analog = ARRAY_SIZE(devopts_cg_analog),
533 .devopts_cg_digital = &devopts_cg_digital,
534 .num_devopts_cg_digital = ARRAY_SIZE(devopts_cg_digital),
536 .coupling_options = &coupling_options,
537 .num_coupling_options = ARRAY_SIZE(coupling_options),
539 .logic_threshold = &logic_threshold,
540 .num_logic_threshold = ARRAY_SIZE(logic_threshold),
541 .logic_threshold_for_pod = TRUE,
543 .trigger_sources = &an4_dig16_trigger_sources,
544 .num_trigger_sources = ARRAY_SIZE(an4_dig16_trigger_sources),
546 .trigger_slopes = &scope_trigger_slopes,
547 .num_trigger_slopes = ARRAY_SIZE(scope_trigger_slopes),
549 .timebases = &timebases,
550 .num_timebases = ARRAY_SIZE(timebases),
553 .num_vdivs = VDIVS_COUNT_UPTO_10V,
557 .scpi_dialect = &hameg_scpi_dialect,
560 .name = {"RTB2002", NULL},
561 .analog_channels = 2,
562 .digital_channels = 16,
564 .analog_names = &scope_analog_channel_names,
565 .digital_names = &scope_digital_channel_names,
568 .num_devopts = ARRAY_SIZE(devopts),
570 .devopts_cg_analog = &devopts_cg_analog,
571 .num_devopts_cg_analog = ARRAY_SIZE(devopts_cg_analog),
573 .devopts_cg_digital = &devopts_cg_digital,
574 .num_devopts_cg_digital = ARRAY_SIZE(devopts_cg_digital),
576 .coupling_options = &coupling_options_rtb200x,
577 .num_coupling_options = ARRAY_SIZE(coupling_options_rtb200x),
579 .logic_threshold = &logic_threshold_rtb200x_rtm300x,
580 .num_logic_threshold = ARRAY_SIZE(logic_threshold_rtb200x_rtm300x),
581 .logic_threshold_for_pod = FALSE,
583 .trigger_sources = &an2_dig16_sbus_trigger_sources,
584 .num_trigger_sources = ARRAY_SIZE(an2_dig16_sbus_trigger_sources),
586 .trigger_slopes = &scope_trigger_slopes,
587 .num_trigger_slopes = ARRAY_SIZE(scope_trigger_slopes),
589 .timebases = &timebases,
590 .num_timebases = ARRAY_SIZE(timebases),
593 .num_vdivs = VDIVS_COUNT_UPTO_50V,
597 .scpi_dialect = &rohde_schwarz_log_not_pod_scpi_dialect,
600 .name = {"RTB2004", NULL},
601 .analog_channels = 4,
602 .digital_channels = 16,
604 .analog_names = &scope_analog_channel_names,
605 .digital_names = &scope_digital_channel_names,
608 .num_devopts = ARRAY_SIZE(devopts),
610 .devopts_cg_analog = &devopts_cg_analog,
611 .num_devopts_cg_analog = ARRAY_SIZE(devopts_cg_analog),
613 .devopts_cg_digital = &devopts_cg_digital,
614 .num_devopts_cg_digital = ARRAY_SIZE(devopts_cg_digital),
616 .coupling_options = &coupling_options_rtb200x,
617 .num_coupling_options = ARRAY_SIZE(coupling_options_rtb200x),
619 .logic_threshold = &logic_threshold_rtb200x_rtm300x,
620 .num_logic_threshold = ARRAY_SIZE(logic_threshold_rtb200x_rtm300x),
621 .logic_threshold_for_pod = FALSE,
623 .trigger_sources = &an4_dig16_sbus_trigger_sources,
624 .num_trigger_sources = ARRAY_SIZE(an4_dig16_sbus_trigger_sources),
626 .trigger_slopes = &scope_trigger_slopes,
627 .num_trigger_slopes = ARRAY_SIZE(scope_trigger_slopes),
629 .timebases = &timebases,
630 .num_timebases = ARRAY_SIZE(timebases),
633 .num_vdivs = VDIVS_COUNT_UPTO_50V,
637 .scpi_dialect = &rohde_schwarz_log_not_pod_scpi_dialect,
640 .name = {"RTM3002", NULL},
641 .analog_channels = 2,
642 .digital_channels = 16,
644 .analog_names = &scope_analog_channel_names,
645 .digital_names = &scope_digital_channel_names,
648 .num_devopts = ARRAY_SIZE(devopts),
650 .devopts_cg_analog = &devopts_cg_analog,
651 .num_devopts_cg_analog = ARRAY_SIZE(devopts_cg_analog),
653 .devopts_cg_digital = &devopts_cg_digital,
654 .num_devopts_cg_digital = ARRAY_SIZE(devopts_cg_digital),
656 .coupling_options = &coupling_options_rtm300x,
657 .num_coupling_options = ARRAY_SIZE(coupling_options_rtm300x),
659 .logic_threshold = &logic_threshold_rtb200x_rtm300x,
660 .num_logic_threshold = ARRAY_SIZE(logic_threshold_rtb200x_rtm300x),
661 .logic_threshold_for_pod = FALSE,
663 .trigger_sources = &an2_dig16_sbus_trigger_sources,
664 .num_trigger_sources = ARRAY_SIZE(an2_dig16_sbus_trigger_sources),
666 .trigger_slopes = &scope_trigger_slopes,
667 .num_trigger_slopes = ARRAY_SIZE(scope_trigger_slopes),
669 .timebases = &timebases,
670 .num_timebases = ARRAY_SIZE(timebases),
673 .num_vdivs = VDIVS_COUNT_UPTO_10V,
677 .scpi_dialect = &rohde_schwarz_log_not_pod_scpi_dialect,
680 .name = {"RTM3004", NULL},
681 .analog_channels = 4,
682 .digital_channels = 16,
684 .analog_names = &scope_analog_channel_names,
685 .digital_names = &scope_digital_channel_names,
688 .num_devopts = ARRAY_SIZE(devopts),
690 .devopts_cg_analog = &devopts_cg_analog,
691 .num_devopts_cg_analog = ARRAY_SIZE(devopts_cg_analog),
693 .devopts_cg_digital = &devopts_cg_digital,
694 .num_devopts_cg_digital = ARRAY_SIZE(devopts_cg_digital),
696 .coupling_options = &coupling_options_rtm300x,
697 .num_coupling_options = ARRAY_SIZE(coupling_options_rtm300x),
699 .logic_threshold = &logic_threshold_rtb200x_rtm300x,
700 .num_logic_threshold = ARRAY_SIZE(logic_threshold_rtb200x_rtm300x),
701 .logic_threshold_for_pod = FALSE,
703 .trigger_sources = &an4_dig16_sbus_trigger_sources,
704 .num_trigger_sources = ARRAY_SIZE(an4_dig16_sbus_trigger_sources),
706 .trigger_slopes = &scope_trigger_slopes,
707 .num_trigger_slopes = ARRAY_SIZE(scope_trigger_slopes),
709 .timebases = &timebases,
710 .num_timebases = ARRAY_SIZE(timebases),
713 .num_vdivs = VDIVS_COUNT_UPTO_10V,
717 .scpi_dialect = &rohde_schwarz_log_not_pod_scpi_dialect,
720 .name = {"RTA4004", NULL},
721 .analog_channels = 4,
722 .digital_channels = 16,
724 .analog_names = &scope_analog_channel_names,
725 .digital_names = &scope_digital_channel_names,
728 .num_devopts = ARRAY_SIZE(devopts),
730 .devopts_cg_analog = &devopts_cg_analog,
731 .num_devopts_cg_analog = ARRAY_SIZE(devopts_cg_analog),
733 .devopts_cg_digital = &devopts_cg_digital,
734 .num_devopts_cg_digital = ARRAY_SIZE(devopts_cg_digital),
736 .coupling_options = &coupling_options_rtm300x,
737 .num_coupling_options = ARRAY_SIZE(coupling_options_rtm300x),
739 .logic_threshold = &logic_threshold_rtb200x_rtm300x,
740 .num_logic_threshold = ARRAY_SIZE(logic_threshold_rtb200x_rtm300x),
741 .logic_threshold_for_pod = FALSE,
743 .trigger_sources = &an4_dig16_sbus_trigger_sources,
744 .num_trigger_sources = ARRAY_SIZE(an4_dig16_sbus_trigger_sources),
746 .trigger_slopes = &scope_trigger_slopes,
747 .num_trigger_slopes = ARRAY_SIZE(scope_trigger_slopes),
749 .timebases = &timebases,
750 .num_timebases = ARRAY_SIZE(timebases),
753 .num_vdivs = VDIVS_COUNT_UPTO_10V,
757 .scpi_dialect = &rohde_schwarz_log_not_pod_scpi_dialect,
761 static void scope_state_dump(const struct scope_config *config,
762 struct scope_state *state)
767 for (i = 0; i < config->analog_channels; i++) {
768 tmp = sr_voltage_string((*config->vdivs)[state->analog_channels[i].vdiv][0],
769 (*config->vdivs)[state->analog_channels[i].vdiv][1]);
770 sr_info("State of analog channel %d -> %s : %s (coupling) %s (vdiv) %2.2e (offset)",
771 i + 1, state->analog_channels[i].state ? "On" : "Off",
772 (*config->coupling_options)[state->analog_channels[i].coupling],
773 tmp, state->analog_channels[i].vertical_offset);
776 for (i = 0; i < config->digital_channels; i++) {
777 sr_info("State of digital channel %d -> %s", i,
778 state->digital_channels[i] ? "On" : "Off");
781 for (i = 0; i < config->digital_pods; i++) {
782 if (!strncmp("USER", (*config->logic_threshold)[state->digital_pods[i].threshold], 4) ||
783 !strcmp("MAN", (*config->logic_threshold)[state->digital_pods[i].threshold]))
784 sr_info("State of digital POD %d -> %s : %E (threshold)", i + 1,
785 state->digital_pods[i].state ? "On" : "Off",
786 state->digital_pods[i].user_threshold);
788 sr_info("State of digital POD %d -> %s : %s (threshold)", i + 1,
789 state->digital_pods[i].state ? "On" : "Off",
790 (*config->logic_threshold)[state->digital_pods[i].threshold]);
793 tmp = sr_period_string((*config->timebases)[state->timebase][0],
794 (*config->timebases)[state->timebase][1]);
795 sr_info("Current timebase: %s", tmp);
798 tmp = sr_samplerate_string(state->sample_rate);
799 sr_info("Current samplerate: %s", tmp);
802 if (!strcmp("PATT", (*config->trigger_sources)[state->trigger_source]))
803 sr_info("Current trigger: %s (pattern), %.2f (offset)",
804 state->trigger_pattern,
805 state->horiz_triggerpos);
806 else // Edge (slope) trigger
807 sr_info("Current trigger: %s (source), %s (slope) %.2f (offset)",
808 (*config->trigger_sources)[state->trigger_source],
809 (*config->trigger_slopes)[state->trigger_slope],
810 state->horiz_triggerpos);
813 static int scope_state_get_array_option(struct sr_scpi_dev_inst *scpi,
814 const char *command, const char *(*array)[], unsigned int n, int *result)
819 if (sr_scpi_get_string(scpi, command, &tmp) != SR_OK)
822 if ((idx = std_str_idx_s(tmp, *array, n)) < 0) {
835 * This function takes a value of the form "2.000E-03" and returns the index
836 * of an array where a matching pair was found.
838 * @param value The string to be parsed.
839 * @param array The array of s/f pairs.
840 * @param array_len The number of pairs in the array.
841 * @param result The index at which a matching pair was found.
843 * @return SR_ERR on any parsing error, SR_OK otherwise.
845 static int array_float_get(gchar *value, const uint64_t array[][2],
846 int array_len, unsigned int *result)
848 struct sr_rational rval;
849 struct sr_rational aval;
851 if (sr_parse_rational(value, &rval) != SR_OK)
854 for (int i = 0; i < array_len; i++) {
855 sr_rational_set(&aval, array[i][0], array[i][1]);
856 if (sr_rational_eq(&rval, &aval)) {
865 static struct sr_channel *get_channel_by_index_and_type(GSList *channel_lhead,
868 while (channel_lhead) {
869 struct sr_channel *ch = channel_lhead->data;
870 if (ch->index == index && ch->type == type)
873 channel_lhead = channel_lhead->next;
879 static int analog_channel_state_get(struct sr_dev_inst *sdi,
880 const struct scope_config *config,
881 struct scope_state *state)
884 char command[MAX_COMMAND_SIZE];
886 struct sr_channel *ch;
887 struct sr_scpi_dev_inst *scpi = sdi->conn;
889 for (i = 0; i < config->analog_channels; i++) {
890 g_snprintf(command, sizeof(command),
891 (*config->scpi_dialect)[SCPI_CMD_GET_ANALOG_CHAN_STATE],
894 if (sr_scpi_get_bool(scpi, command,
895 &state->analog_channels[i].state) != SR_OK)
898 ch = get_channel_by_index_and_type(sdi->channels, i, SR_CHANNEL_ANALOG);
900 ch->enabled = state->analog_channels[i].state;
902 g_snprintf(command, sizeof(command),
903 (*config->scpi_dialect)[SCPI_CMD_GET_VERTICAL_SCALE],
906 if (sr_scpi_get_string(scpi, command, &tmp_str) != SR_OK)
909 if (array_float_get(tmp_str, *(config->vdivs), config->num_vdivs, &j) != SR_OK) {
911 sr_err("Could not determine array index for vertical div scale.");
916 state->analog_channels[i].vdiv = j;
918 g_snprintf(command, sizeof(command),
919 (*config->scpi_dialect)[SCPI_CMD_GET_VERTICAL_OFFSET],
922 if (sr_scpi_get_float(scpi, command,
923 &state->analog_channels[i].vertical_offset) != SR_OK)
926 g_snprintf(command, sizeof(command),
927 (*config->scpi_dialect)[SCPI_CMD_GET_COUPLING],
930 if (scope_state_get_array_option(scpi, command, config->coupling_options,
931 config->num_coupling_options,
932 &state->analog_channels[i].coupling) != SR_OK)
935 g_snprintf(command, sizeof(command),
936 (*config->scpi_dialect)[SCPI_CMD_GET_PROBE_UNIT],
939 if (sr_scpi_get_string(scpi, command, &tmp_str) != SR_OK)
942 if (tmp_str[0] == 'A')
943 state->analog_channels[i].probe_unit = 'A';
945 state->analog_channels[i].probe_unit = 'V';
952 static int digital_channel_state_get(struct sr_dev_inst *sdi,
953 const struct scope_config *config,
954 struct scope_state *state)
958 char *logic_threshold_short[MAX_NUM_LOGIC_THRESHOLD_ENTRIES];
959 char command[MAX_COMMAND_SIZE];
960 struct sr_channel *ch;
961 struct sr_scpi_dev_inst *scpi = sdi->conn;
963 for (i = 0; i < config->digital_channels; i++) {
964 g_snprintf(command, sizeof(command),
965 (*config->scpi_dialect)[SCPI_CMD_GET_DIG_CHAN_STATE],
968 if (sr_scpi_get_bool(scpi, command,
969 &state->digital_channels[i]) != SR_OK)
972 ch = get_channel_by_index_and_type(sdi->channels, i, SR_CHANNEL_LOGIC);
974 ch->enabled = state->digital_channels[i];
977 /* According to the SCPI standard, on models that support multiple
978 * user-defined logic threshold settings the response to the command
979 * SCPI_CMD_GET_DIG_POD_THRESHOLD might return "USER" instead of
982 * This makes more difficult to validate the response when the logic
983 * threshold is set to "USER1" and therefore we need to prevent device
984 * opening failures in such configuration case...
986 for (i = 0; i < config->num_logic_threshold; i++) {
987 logic_threshold_short[i] = g_strdup((*config->logic_threshold)[i]);
988 if (!strcmp("USER1", (*config->logic_threshold)[i]))
989 g_strlcpy(logic_threshold_short[i],
990 (*config->logic_threshold)[i], strlen((*config->logic_threshold)[i]));
993 for (i = 0; i < config->digital_pods; i++) {
994 g_snprintf(command, sizeof(command),
995 (*config->scpi_dialect)[SCPI_CMD_GET_DIG_POD_STATE],
998 if (sr_scpi_get_bool(scpi, command,
999 &state->digital_pods[i].state) != SR_OK)
1002 /* Check if the threshold command is based on the POD or digital channel index. */
1003 if (config->logic_threshold_for_pod)
1006 idx = i * DIGITAL_CHANNELS_PER_POD;
1008 g_snprintf(command, sizeof(command),
1009 (*config->scpi_dialect)[SCPI_CMD_GET_DIG_POD_THRESHOLD],
1012 /* Check for both standard and shortened responses. */
1013 if (scope_state_get_array_option(scpi, command, config->logic_threshold,
1014 config->num_logic_threshold,
1015 &state->digital_pods[i].threshold) != SR_OK)
1016 if (scope_state_get_array_option(scpi, command, (const char * (*)[]) &logic_threshold_short,
1017 config->num_logic_threshold,
1018 &state->digital_pods[i].threshold) != SR_OK)
1021 /* If used-defined or custom threshold is active, get the level. */
1022 if (!strcmp("USER1", (*config->logic_threshold)[state->digital_pods[i].threshold]))
1023 g_snprintf(command, sizeof(command),
1024 (*config->scpi_dialect)[SCPI_CMD_GET_DIG_POD_USER_THRESHOLD],
1025 idx, 1); /* USER1 logic threshold setting. */
1026 else if (!strcmp("USER2", (*config->logic_threshold)[state->digital_pods[i].threshold]))
1027 g_snprintf(command, sizeof(command),
1028 (*config->scpi_dialect)[SCPI_CMD_GET_DIG_POD_USER_THRESHOLD],
1029 idx, 2); /* USER2 for custom logic_threshold setting. */
1030 else if (!strcmp("USER", (*config->logic_threshold)[state->digital_pods[i].threshold]) ||
1031 !strcmp("MAN", (*config->logic_threshold)[state->digital_pods[i].threshold]))
1032 g_snprintf(command, sizeof(command),
1033 (*config->scpi_dialect)[SCPI_CMD_GET_DIG_POD_USER_THRESHOLD],
1034 idx); /* USER or MAN for custom logic_threshold setting. */
1035 if (!strcmp("USER1", (*config->logic_threshold)[state->digital_pods[i].threshold]) ||
1036 !strcmp("USER2", (*config->logic_threshold)[state->digital_pods[i].threshold]) ||
1037 !strcmp("USER", (*config->logic_threshold)[state->digital_pods[i].threshold]) ||
1038 !strcmp("MAN", (*config->logic_threshold)[state->digital_pods[i].threshold]))
1039 if (sr_scpi_get_float(scpi, command,
1040 &state->digital_pods[i].user_threshold) != SR_OK)
1047 for (i = 0; i < config->num_logic_threshold; i++)
1048 g_free(logic_threshold_short[i]);
1053 SR_PRIV int hmo_update_sample_rate(const struct sr_dev_inst *sdi)
1055 struct dev_context *devc;
1056 struct scope_state *state;
1057 const struct scope_config *config;
1061 config = devc->model_config;
1062 state = devc->model_state;
1064 if (sr_scpi_get_float(sdi->conn,
1065 (*config->scpi_dialect)[SCPI_CMD_GET_SAMPLE_RATE],
1066 &tmp_float) != SR_OK)
1069 state->sample_rate = tmp_float;
1074 SR_PRIV int hmo_scope_state_get(struct sr_dev_inst *sdi)
1076 struct dev_context *devc;
1077 struct scope_state *state;
1078 const struct scope_config *config;
1084 config = devc->model_config;
1085 state = devc->model_state;
1087 sr_info("Fetching scope state");
1089 if (analog_channel_state_get(sdi, config, state) != SR_OK)
1092 if (digital_channel_state_get(sdi, config, state) != SR_OK)
1095 if (sr_scpi_get_string(sdi->conn,
1096 (*config->scpi_dialect)[SCPI_CMD_GET_TIMEBASE],
1100 if (array_float_get(tmp_str, ARRAY_AND_SIZE(timebases), &i) != SR_OK) {
1102 sr_err("Could not determine array index for time base.");
1107 state->timebase = i;
1109 /* Determine the number of horizontal (x) divisions. */
1110 if (sr_scpi_get_int(sdi->conn,
1111 (*config->scpi_dialect)[SCPI_CMD_GET_HORIZONTAL_DIV],
1112 (int *)&config->num_xdivs) != SR_OK)
1115 if (sr_scpi_get_float(sdi->conn,
1116 (*config->scpi_dialect)[SCPI_CMD_GET_HORIZ_TRIGGERPOS],
1117 &tmp_float) != SR_OK)
1119 state->horiz_triggerpos = tmp_float /
1120 (((double) (*config->timebases)[state->timebase][0] /
1121 (*config->timebases)[state->timebase][1]) * config->num_xdivs);
1122 state->horiz_triggerpos -= 0.5;
1123 state->horiz_triggerpos *= -1;
1125 if (scope_state_get_array_option(sdi->conn,
1126 (*config->scpi_dialect)[SCPI_CMD_GET_TRIGGER_SOURCE],
1127 config->trigger_sources, config->num_trigger_sources,
1128 &state->trigger_source) != SR_OK)
1131 if (scope_state_get_array_option(sdi->conn,
1132 (*config->scpi_dialect)[SCPI_CMD_GET_TRIGGER_SLOPE],
1133 config->trigger_slopes, config->num_trigger_slopes,
1134 &state->trigger_slope) != SR_OK)
1137 if (sr_scpi_get_string(sdi->conn,
1138 (*config->scpi_dialect)[SCPI_CMD_GET_TRIGGER_PATTERN],
1141 strncpy(state->trigger_pattern,
1142 sr_scpi_unquote_string(tmp_str),
1143 MAX_ANALOG_CHANNEL_COUNT + MAX_DIGITAL_CHANNEL_COUNT);
1146 if (sr_scpi_get_string(sdi->conn,
1147 (*config->scpi_dialect)[SCPI_CMD_GET_HIGH_RESOLUTION],
1150 if (!strcmp("OFF", tmp_str))
1151 state->high_resolution = FALSE;
1153 state->high_resolution = TRUE;
1156 if (sr_scpi_get_string(sdi->conn,
1157 (*config->scpi_dialect)[SCPI_CMD_GET_PEAK_DETECTION],
1160 if (!strcmp("OFF", tmp_str))
1161 state->peak_detection = FALSE;
1163 state->peak_detection = TRUE;
1166 if (hmo_update_sample_rate(sdi) != SR_OK)
1169 sr_info("Fetching finished.");
1171 scope_state_dump(config, state);
1176 static struct scope_state *scope_state_new(const struct scope_config *config)
1178 struct scope_state *state;
1180 state = g_malloc0(sizeof(struct scope_state));
1181 state->analog_channels = g_malloc0_n(config->analog_channels,
1182 sizeof(struct analog_channel_state));
1183 state->digital_channels = g_malloc0_n(
1184 config->digital_channels, sizeof(gboolean));
1185 state->digital_pods = g_malloc0_n(config->digital_pods,
1186 sizeof(struct digital_pod_state));
1191 SR_PRIV void hmo_scope_state_free(struct scope_state *state)
1193 g_free(state->analog_channels);
1194 g_free(state->digital_channels);
1195 g_free(state->digital_pods);
1199 SR_PRIV int hmo_init_device(struct sr_dev_inst *sdi)
1202 unsigned int i, j, group;
1203 struct sr_channel *ch;
1204 struct dev_context *devc;
1205 const char *cg_name;
1211 /* Find the exact model. */
1212 for (i = 0; i < ARRAY_SIZE(scope_models); i++) {
1213 for (j = 0; scope_models[i].name[j]; j++) {
1214 if (!strcmp(sdi->model, scope_models[i].name[j])) {
1219 if (model_index != -1)
1223 if (model_index == -1) {
1224 sr_dbg("Unsupported device.");
1228 /* Configure the number of PODs given the number of digital channels. */
1229 scope_models[model_index].digital_pods = scope_models[model_index].digital_channels / DIGITAL_CHANNELS_PER_POD;
1231 devc->analog_groups = g_malloc0(sizeof(struct sr_channel_group*) *
1232 scope_models[model_index].analog_channels);
1233 devc->digital_groups = g_malloc0(sizeof(struct sr_channel_group*) *
1234 scope_models[model_index].digital_pods);
1235 if (!devc->analog_groups || !devc->digital_groups) {
1236 g_free(devc->analog_groups);
1237 g_free(devc->digital_groups);
1238 return SR_ERR_MALLOC;
1241 /* Add analog channels. */
1242 for (i = 0; i < scope_models[model_index].analog_channels; i++) {
1243 ch = sr_channel_new(sdi, i, SR_CHANNEL_ANALOG, TRUE,
1244 (*scope_models[model_index].analog_names)[i]);
1246 cg_name = (*scope_models[model_index].analog_names)[i];
1247 devc->analog_groups[i] = sr_channel_group_new(sdi, cg_name, NULL);
1248 devc->analog_groups[i]->channels = g_slist_append(NULL, ch);
1251 /* Add digital channel groups. */
1253 for (i = 0; i < scope_models[model_index].digital_pods; i++) {
1254 devc->digital_groups[i] = sr_channel_group_new(sdi, NULL, NULL);
1255 if (!devc->digital_groups[i]) {
1256 ret = SR_ERR_MALLOC;
1259 devc->digital_groups[i]->name = g_strdup_printf("POD%d", i + 1);
1264 /* Add digital channels. */
1265 for (i = 0; i < scope_models[model_index].digital_channels; i++) {
1266 ch = sr_channel_new(sdi, i, SR_CHANNEL_LOGIC, TRUE,
1267 (*scope_models[model_index].digital_names)[i]);
1269 group = i / DIGITAL_CHANNELS_PER_POD;
1270 devc->digital_groups[group]->channels = g_slist_append(
1271 devc->digital_groups[group]->channels, ch);
1274 devc->model_config = &scope_models[model_index];
1275 devc->samples_limit = 0;
1276 devc->frame_limit = 0;
1278 if (!(devc->model_state = scope_state_new(devc->model_config)))
1279 return SR_ERR_MALLOC;
1284 /* Queue data of one channel group, for later submission. */
1285 SR_PRIV void hmo_queue_logic_data(struct dev_context *devc,
1286 size_t group, GByteArray *pod_data)
1290 uint8_t *logic_data;
1291 size_t idx, logic_step;
1294 * Upon first invocation, allocate the array which can hold the
1295 * combined logic data for all channels. Assume that each channel
1296 * will yield an identical number of samples per receive call.
1298 * As a poor man's safety measure: (Silently) skip processing
1299 * for unexpected sample counts, and ignore samples for
1300 * unexpected channel groups. Don't bother with complicated
1301 * resize logic, considering that many models only support one
1302 * pod, and the most capable supported models have two pods of
1303 * identical size. We haven't yet seen any "odd" configuration.
1305 if (!devc->logic_data) {
1306 size = pod_data->len * devc->pod_count;
1307 store = g_byte_array_sized_new(size);
1308 memset(store->data, 0, size);
1309 store = g_byte_array_set_size(store, size);
1310 devc->logic_data = store;
1312 store = devc->logic_data;
1313 size = store->len / devc->pod_count;
1314 if (group >= devc->pod_count)
1319 * Fold the data of the most recently received channel group into
1320 * the storage, where data resides for all channels combined.
1322 logic_data = store->data;
1323 logic_data += group;
1324 logic_step = devc->pod_count;
1325 for (idx = 0; idx < pod_data->len; idx++) {
1326 *logic_data = pod_data->data[idx];
1327 logic_data += logic_step;
1330 /* Truncate acquisition if a smaller number of samples has been requested. */
1331 if (devc->samples_limit > 0 && devc->logic_data->len > devc->samples_limit * devc->pod_count)
1332 devc->logic_data->len = devc->samples_limit * devc->pod_count;
1335 /* Submit data for all channels, after the individual groups got collected. */
1336 SR_PRIV void hmo_send_logic_packet(struct sr_dev_inst *sdi,
1337 struct dev_context *devc)
1339 struct sr_datafeed_packet packet;
1340 struct sr_datafeed_logic logic;
1342 if (!devc->logic_data)
1345 logic.data = devc->logic_data->data;
1346 logic.length = devc->logic_data->len;
1347 logic.unitsize = devc->pod_count;
1349 packet.type = SR_DF_LOGIC;
1350 packet.payload = &logic;
1352 sr_session_send(sdi, &packet);
1355 /* Undo previous resource allocation. */
1356 SR_PRIV void hmo_cleanup_logic_data(struct dev_context *devc)
1359 if (devc->logic_data) {
1360 g_byte_array_free(devc->logic_data, TRUE);
1361 devc->logic_data = NULL;
1364 * Keep 'pod_count'! It's required when more frames will be
1365 * received, and does not harm when kept after acquisition.
1369 SR_PRIV int hmo_receive_data(int fd, int revents, void *cb_data)
1371 struct sr_channel *ch;
1372 struct sr_dev_inst *sdi;
1373 struct dev_context *devc;
1374 struct scope_state *state;
1375 struct sr_datafeed_packet packet;
1377 struct sr_datafeed_analog analog;
1378 struct sr_analog_encoding encoding;
1379 struct sr_analog_meaning meaning;
1380 struct sr_analog_spec spec;
1381 struct sr_datafeed_logic logic;
1387 if (!(sdi = cb_data))
1390 if (!(devc = sdi->priv))
1393 /* Although this is correct in general, the USBTMC libusb implementation
1394 * currently does not generate an event prior to the first read. Often
1395 * it is ok to start reading just after the 50ms timeout. See bug #785.
1396 if (revents != G_IO_IN)
1400 ch = devc->current_channel->data;
1401 state = devc->model_state;
1404 * Send "frame begin" packet upon reception of data for the
1405 * first enabled channel.
1407 if (devc->current_channel == devc->enabled_channels)
1408 std_session_send_df_frame_begin(sdi);
1411 * Pass on the received data of the channel(s).
1414 case SR_CHANNEL_ANALOG:
1416 if (sr_scpi_get_block(sdi->conn, NULL, &data) != SR_OK) {
1418 g_byte_array_free(data, TRUE);
1422 packet.type = SR_DF_ANALOG;
1424 analog.data = data->data;
1425 analog.num_samples = data->len / sizeof(float);
1426 /* Truncate acquisition if a smaller number of samples has been requested. */
1427 if (devc->samples_limit > 0 && analog.num_samples > devc->samples_limit)
1428 analog.num_samples = devc->samples_limit;
1429 /* TODO: Use proper 'digits' value for this device (and its modes). */
1430 sr_analog_init(&analog, &encoding, &meaning, &spec, 2);
1431 encoding.is_signed = TRUE;
1432 if (state->analog_channels[ch->index].probe_unit == 'V') {
1433 meaning.mq = SR_MQ_VOLTAGE;
1434 meaning.unit = SR_UNIT_VOLT;
1436 meaning.mq = SR_MQ_CURRENT;
1437 meaning.unit = SR_UNIT_AMPERE;
1439 meaning.channels = g_slist_append(NULL, ch);
1440 packet.payload = &analog;
1441 sr_session_send(sdi, &packet);
1442 devc->num_samples = data->len / sizeof(float);
1443 g_slist_free(meaning.channels);
1444 g_byte_array_free(data, TRUE);
1447 case SR_CHANNEL_LOGIC:
1449 if (sr_scpi_get_block(sdi->conn, NULL, &data) != SR_OK) {
1451 g_byte_array_free(data, TRUE);
1456 * If only data from the first pod is involved in the
1457 * acquisition, then the raw input bytes can get passed
1458 * forward for performance reasons. When the second pod
1459 * is involved (either alone, or in combination with the
1460 * first pod), then the received bytes need to be put
1461 * into memory in such a layout that all channel groups
1462 * get combined, and a unitsize larger than a single byte
1463 * applies. The "queue" logic transparently copes with
1464 * any such configuration. This works around the lack
1465 * of support for "meaning" to logic data, which is used
1466 * above for analog data.
1468 if (devc->pod_count == 1) {
1469 packet.type = SR_DF_LOGIC;
1470 logic.data = data->data;
1471 logic.length = data->len;
1472 /* Truncate acquisition if a smaller number of samples has been requested. */
1473 if (devc->samples_limit > 0 && logic.length > devc->samples_limit)
1474 logic.length = devc->samples_limit;
1476 packet.payload = &logic;
1477 sr_session_send(sdi, &packet);
1479 group = ch->index / DIGITAL_CHANNELS_PER_POD;
1480 hmo_queue_logic_data(devc, group, data);
1483 devc->num_samples = data->len / devc->pod_count;
1484 g_byte_array_free(data, TRUE);
1488 sr_err("Invalid channel type.");
1493 * Advance to the next enabled channel. When data for all enabled
1494 * channels was received, then flush potentially queued logic data,
1495 * and send the "frame end" packet.
1497 if (devc->current_channel->next) {
1498 devc->current_channel = devc->current_channel->next;
1499 hmo_request_data(sdi);
1502 hmo_send_logic_packet(sdi, devc);
1505 * Release the logic data storage after each frame. This copes
1506 * with sample counts that differ in length per frame. -- Is
1507 * this a real constraint when acquiring multiple frames with
1508 * identical device settings?
1510 hmo_cleanup_logic_data(devc);
1512 std_session_send_df_frame_end(sdi);
1515 * End of frame was reached. Stop acquisition after the specified
1516 * number of frames or after the specified number of samples, or
1517 * continue reception by starting over at the first enabled channel.
1519 if (++devc->num_frames >= devc->frame_limit || devc->num_samples >= devc->samples_limit) {
1520 sr_dev_acquisition_stop(sdi);
1521 hmo_cleanup_logic_data(devc);
1523 devc->current_channel = devc->enabled_channels;
1524 hmo_request_data(sdi);