]>
Commit | Line | Data |
---|---|---|
06a3e78a DJ |
1 | /* |
2 | * This file is part of the libsigrok project. | |
3 | * | |
4 | * Copyright (C) 2013 poljar (Damir Jelić) <poljarinho@gmail.com> | |
5 | * | |
6 | * This program is free software: you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License as published by | |
8 | * the Free Software Foundation, either version 3 of the License, or | |
9 | * (at your option) any later version. | |
10 | * | |
11 | * This program is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | * GNU General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License | |
17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
18 | */ | |
19 | ||
6ec6c43b | 20 | #include <config.h> |
650847e7 UH |
21 | #include <math.h> |
22 | #include <stdlib.h> | |
5a1afc09 | 23 | #include "scpi.h" |
06a3e78a DJ |
24 | #include "protocol.h" |
25 | ||
e06875b2 GS |
26 | SR_PRIV void hmo_queue_logic_data(struct dev_context *devc, |
27 | size_t group, GByteArray *pod_data); | |
28 | SR_PRIV void hmo_send_logic_packet(struct sr_dev_inst *sdi, | |
29 | struct dev_context *devc); | |
30 | SR_PRIV void hmo_cleanup_logic_data(struct dev_context *devc); | |
31 | ||
13f2b9d7 | 32 | static const char *hameg_scpi_dialect[] = { |
401b83a1 | 33 | [SCPI_CMD_GET_DIG_DATA] = ":FORM UINT,8;:POD%d:DATA?", |
13f2b9d7 | 34 | [SCPI_CMD_GET_TIMEBASE] = ":TIM:SCAL?", |
965b463d | 35 | [SCPI_CMD_SET_TIMEBASE] = ":TIM:SCAL %s", |
13f2b9d7 DJ |
36 | [SCPI_CMD_GET_COUPLING] = ":CHAN%d:COUP?", |
37 | [SCPI_CMD_SET_COUPLING] = ":CHAN%d:COUP %s", | |
14a2f74d DJ |
38 | [SCPI_CMD_GET_SAMPLE_RATE] = ":ACQ:SRAT?", |
39 | [SCPI_CMD_GET_SAMPLE_RATE_LIVE] = ":%s:DATA:POINTS?", | |
65a6794e GS |
40 | [SCPI_CMD_GET_ANALOG_DATA] = ":FORM:BORD %s;" \ |
41 | ":FORM REAL,32;:CHAN%d:DATA?", | |
13f2b9d7 | 42 | [SCPI_CMD_GET_VERTICAL_DIV] = ":CHAN%d:SCAL?", |
965b463d | 43 | [SCPI_CMD_SET_VERTICAL_DIV] = ":CHAN%d:SCAL %s", |
13f2b9d7 DJ |
44 | [SCPI_CMD_GET_DIG_POD_STATE] = ":POD%d:STAT?", |
45 | [SCPI_CMD_SET_DIG_POD_STATE] = ":POD%d:STAT %d", | |
46 | [SCPI_CMD_GET_TRIGGER_SLOPE] = ":TRIG:A:EDGE:SLOP?", | |
47 | [SCPI_CMD_SET_TRIGGER_SLOPE] = ":TRIG:A:EDGE:SLOP %s", | |
48 | [SCPI_CMD_GET_TRIGGER_SOURCE] = ":TRIG:A:SOUR?", | |
49 | [SCPI_CMD_SET_TRIGGER_SOURCE] = ":TRIG:A:SOUR %s", | |
50 | [SCPI_CMD_GET_DIG_CHAN_STATE] = ":LOG%d:STAT?", | |
51 | [SCPI_CMD_SET_DIG_CHAN_STATE] = ":LOG%d:STAT %d", | |
52 | [SCPI_CMD_GET_VERTICAL_OFFSET] = ":CHAN%d:POS?", | |
53 | [SCPI_CMD_GET_HORIZ_TRIGGERPOS] = ":TIM:POS?", | |
422a1c0d | 54 | [SCPI_CMD_SET_HORIZ_TRIGGERPOS] = ":TIM:POS %s", |
13f2b9d7 DJ |
55 | [SCPI_CMD_GET_ANALOG_CHAN_STATE] = ":CHAN%d:STAT?", |
56 | [SCPI_CMD_SET_ANALOG_CHAN_STATE] = ":CHAN%d:STAT %d", | |
448e81b1 | 57 | [SCPI_CMD_GET_PROBE_UNIT] = ":PROB%d:SET:ATT:UNIT?", |
13f2b9d7 DJ |
58 | }; |
59 | ||
4b25cbff | 60 | static const uint32_t devopts[] = { |
13f2b9d7 | 61 | SR_CONF_OSCILLOSCOPE, |
a1b61e6e | 62 | SR_CONF_LIMIT_FRAMES | SR_CONF_GET | SR_CONF_SET, |
86621306 | 63 | SR_CONF_SAMPLERATE | SR_CONF_GET, |
5827f61b | 64 | SR_CONF_TIMEBASE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, |
bf622e6d | 65 | SR_CONF_NUM_HDIV | SR_CONF_GET, |
5827f61b | 66 | SR_CONF_HORIZ_TRIGGERPOS | SR_CONF_GET | SR_CONF_SET, |
86621306 UH |
67 | SR_CONF_TRIGGER_SOURCE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, |
68 | SR_CONF_TRIGGER_SLOPE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, | |
13f2b9d7 DJ |
69 | }; |
70 | ||
6b82c3e5 | 71 | static const uint32_t devopts_cg_analog[] = { |
5827f61b | 72 | SR_CONF_NUM_VDIV | SR_CONF_GET, |
5827f61b | 73 | SR_CONF_VDIV | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, |
86621306 | 74 | SR_CONF_COUPLING | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, |
13f2b9d7 DJ |
75 | }; |
76 | ||
4b25cbff | 77 | static const char *coupling_options[] = { |
b05ab7d2 SB |
78 | "AC", // AC with 50 Ohm termination (152x, 202x, 30xx, 1202) |
79 | "ACL", // AC with 1 MOhm termination | |
80 | "DC", // DC with 50 Ohm termination | |
81 | "DCL", // DC with 1 MOhm termination | |
13f2b9d7 | 82 | "GND", |
13f2b9d7 DJ |
83 | }; |
84 | ||
85 | static const char *scope_trigger_slopes[] = { | |
86 | "POS", | |
87 | "NEG", | |
356f64f8 | 88 | "EITH", |
13f2b9d7 DJ |
89 | }; |
90 | ||
4b25cbff | 91 | static const char *compact2_trigger_sources[] = { |
f8195cb2 UH |
92 | "CH1", "CH2", |
93 | "LINE", "EXT", "PATT", "BUS1", "BUS2", | |
94 | "D0", "D1", "D2", "D3", "D4", "D5", "D6", "D7", | |
13f2b9d7 DJ |
95 | }; |
96 | ||
4b25cbff | 97 | static const char *compact4_trigger_sources[] = { |
f8195cb2 UH |
98 | "CH1", "CH2", "CH3", "CH4", |
99 | "LINE", "EXT", "PATT", "BUS1", "BUS2", | |
100 | "D0", "D1", "D2", "D3", "D4", "D5", "D6", "D7", | |
13f2b9d7 DJ |
101 | }; |
102 | ||
4b25cbff | 103 | static const char *compact4_dig16_trigger_sources[] = { |
f8195cb2 UH |
104 | "CH1", "CH2", "CH3", "CH4", |
105 | "LINE", "EXT", "PATT", "BUS1", "BUS2", | |
106 | "D0", "D1", "D2", "D3", "D4", "D5", "D6", "D7", | |
107 | "D8", "D9", "D10", "D11", "D12", "D13", "D14", "D15", | |
74413faf GS |
108 | }; |
109 | ||
4b25cbff | 110 | static const uint64_t timebases[][2] = { |
13f2b9d7 DJ |
111 | /* nanoseconds */ |
112 | { 2, 1000000000 }, | |
113 | { 5, 1000000000 }, | |
114 | { 10, 1000000000 }, | |
115 | { 20, 1000000000 }, | |
116 | { 50, 1000000000 }, | |
117 | { 100, 1000000000 }, | |
118 | { 200, 1000000000 }, | |
119 | { 500, 1000000000 }, | |
120 | /* microseconds */ | |
121 | { 1, 1000000 }, | |
122 | { 2, 1000000 }, | |
123 | { 5, 1000000 }, | |
124 | { 10, 1000000 }, | |
125 | { 20, 1000000 }, | |
126 | { 50, 1000000 }, | |
127 | { 100, 1000000 }, | |
128 | { 200, 1000000 }, | |
129 | { 500, 1000000 }, | |
130 | /* milliseconds */ | |
131 | { 1, 1000 }, | |
132 | { 2, 1000 }, | |
133 | { 5, 1000 }, | |
134 | { 10, 1000 }, | |
135 | { 20, 1000 }, | |
136 | { 50, 1000 }, | |
137 | { 100, 1000 }, | |
138 | { 200, 1000 }, | |
139 | { 500, 1000 }, | |
140 | /* seconds */ | |
141 | { 1, 1 }, | |
142 | { 2, 1 }, | |
143 | { 5, 1 }, | |
144 | { 10, 1 }, | |
145 | { 20, 1 }, | |
146 | { 50, 1 }, | |
147 | }; | |
148 | ||
4b25cbff | 149 | static const uint64_t vdivs[][2] = { |
13f2b9d7 DJ |
150 | /* millivolts */ |
151 | { 1, 1000 }, | |
152 | { 2, 1000 }, | |
153 | { 5, 1000 }, | |
154 | { 10, 1000 }, | |
155 | { 20, 1000 }, | |
156 | { 50, 1000 }, | |
157 | { 100, 1000 }, | |
158 | { 200, 1000 }, | |
159 | { 500, 1000 }, | |
160 | /* volts */ | |
161 | { 1, 1 }, | |
162 | { 2, 1 }, | |
163 | { 5, 1 }, | |
164 | { 10, 1 }, | |
fe227d17 SA |
165 | { 20, 1 }, |
166 | { 50, 1 }, | |
13f2b9d7 DJ |
167 | }; |
168 | ||
ba7dd8bb | 169 | static const char *scope_analog_channel_names[] = { |
f8195cb2 | 170 | "CH1", "CH2", "CH3", "CH4", |
13f2b9d7 DJ |
171 | }; |
172 | ||
ba7dd8bb | 173 | static const char *scope_digital_channel_names[] = { |
f8195cb2 UH |
174 | "D0", "D1", "D2", "D3", "D4", "D5", "D6", "D7", |
175 | "D8", "D9", "D10", "D11", "D12", "D13", "D14", "D15", | |
13f2b9d7 DJ |
176 | }; |
177 | ||
329733d9 | 178 | static const struct scope_config scope_models[] = { |
13f2b9d7 | 179 | { |
e786b194 | 180 | /* HMO2522/3032/3042/3052 support 16 digital channels but they're not supported yet. */ |
da1726cc | 181 | .name = {"HMO1002", "HMO722", "HMO1022", "HMO1522", "HMO2022", "HMO2522", |
e786b194 | 182 | "HMO3032", "HMO3042", "HMO3052", NULL}, |
13f2b9d7 DJ |
183 | .analog_channels = 2, |
184 | .digital_channels = 8, | |
185 | .digital_pods = 1, | |
186 | ||
ba7dd8bb UH |
187 | .analog_names = &scope_analog_channel_names, |
188 | .digital_names = &scope_digital_channel_names, | |
13f2b9d7 | 189 | |
4b25cbff UH |
190 | .devopts = &devopts, |
191 | .num_devopts = ARRAY_SIZE(devopts), | |
13f2b9d7 | 192 | |
6b82c3e5 UH |
193 | .devopts_cg_analog = &devopts_cg_analog, |
194 | .num_devopts_cg_analog = ARRAY_SIZE(devopts_cg_analog), | |
13f2b9d7 | 195 | |
4b25cbff | 196 | .coupling_options = &coupling_options, |
692716f5 UH |
197 | .num_coupling_options = ARRAY_SIZE(coupling_options), |
198 | ||
4b25cbff | 199 | .trigger_sources = &compact2_trigger_sources, |
692716f5 UH |
200 | .num_trigger_sources = ARRAY_SIZE(compact2_trigger_sources), |
201 | ||
13f2b9d7 | 202 | .trigger_slopes = &scope_trigger_slopes, |
692716f5 | 203 | .num_trigger_slopes = ARRAY_SIZE(scope_trigger_slopes), |
13f2b9d7 | 204 | |
4b25cbff UH |
205 | .timebases = &timebases, |
206 | .num_timebases = ARRAY_SIZE(timebases), | |
13f2b9d7 | 207 | |
4b25cbff UH |
208 | .vdivs = &vdivs, |
209 | .num_vdivs = ARRAY_SIZE(vdivs), | |
13f2b9d7 DJ |
210 | |
211 | .num_xdivs = 12, | |
212 | .num_ydivs = 8, | |
213 | ||
214 | .scpi_dialect = &hameg_scpi_dialect, | |
215 | }, | |
216 | { | |
74413faf | 217 | .name = {"HMO724", "HMO1024", "HMO1524", "HMO2024", NULL}, |
13f2b9d7 DJ |
218 | .analog_channels = 4, |
219 | .digital_channels = 8, | |
220 | .digital_pods = 1, | |
221 | ||
ba7dd8bb UH |
222 | .analog_names = &scope_analog_channel_names, |
223 | .digital_names = &scope_digital_channel_names, | |
13f2b9d7 | 224 | |
4b25cbff UH |
225 | .devopts = &devopts, |
226 | .num_devopts = ARRAY_SIZE(devopts), | |
13f2b9d7 | 227 | |
6b82c3e5 UH |
228 | .devopts_cg_analog = &devopts_cg_analog, |
229 | .num_devopts_cg_analog = ARRAY_SIZE(devopts_cg_analog), | |
13f2b9d7 | 230 | |
4b25cbff | 231 | .coupling_options = &coupling_options, |
692716f5 UH |
232 | .num_coupling_options = ARRAY_SIZE(coupling_options), |
233 | ||
4b25cbff | 234 | .trigger_sources = &compact4_trigger_sources, |
692716f5 UH |
235 | .num_trigger_sources = ARRAY_SIZE(compact4_trigger_sources), |
236 | ||
13f2b9d7 | 237 | .trigger_slopes = &scope_trigger_slopes, |
692716f5 | 238 | .num_trigger_slopes = ARRAY_SIZE(scope_trigger_slopes), |
13f2b9d7 | 239 | |
4b25cbff UH |
240 | .timebases = &timebases, |
241 | .num_timebases = ARRAY_SIZE(timebases), | |
13f2b9d7 | 242 | |
4b25cbff UH |
243 | .vdivs = &vdivs, |
244 | .num_vdivs = ARRAY_SIZE(vdivs), | |
13f2b9d7 DJ |
245 | |
246 | .num_xdivs = 12, | |
247 | .num_ydivs = 8, | |
248 | ||
74413faf GS |
249 | .scpi_dialect = &hameg_scpi_dialect, |
250 | }, | |
251 | { | |
bf8a02b6 | 252 | .name = {"HMO2524", "HMO3034", "HMO3044", "HMO3054", "HMO3524", NULL}, |
74413faf GS |
253 | .analog_channels = 4, |
254 | .digital_channels = 16, | |
255 | .digital_pods = 2, | |
256 | ||
257 | .analog_names = &scope_analog_channel_names, | |
258 | .digital_names = &scope_digital_channel_names, | |
259 | ||
4b25cbff UH |
260 | .devopts = &devopts, |
261 | .num_devopts = ARRAY_SIZE(devopts), | |
74413faf | 262 | |
6b82c3e5 UH |
263 | .devopts_cg_analog = &devopts_cg_analog, |
264 | .num_devopts_cg_analog = ARRAY_SIZE(devopts_cg_analog), | |
74413faf | 265 | |
4b25cbff | 266 | .coupling_options = &coupling_options, |
692716f5 UH |
267 | .num_coupling_options = ARRAY_SIZE(coupling_options), |
268 | ||
4b25cbff | 269 | .trigger_sources = &compact4_dig16_trigger_sources, |
692716f5 UH |
270 | .num_trigger_sources = ARRAY_SIZE(compact4_dig16_trigger_sources), |
271 | ||
74413faf | 272 | .trigger_slopes = &scope_trigger_slopes, |
692716f5 | 273 | .num_trigger_slopes = ARRAY_SIZE(scope_trigger_slopes), |
74413faf | 274 | |
4b25cbff UH |
275 | .timebases = &timebases, |
276 | .num_timebases = ARRAY_SIZE(timebases), | |
74413faf | 277 | |
4b25cbff UH |
278 | .vdivs = &vdivs, |
279 | .num_vdivs = ARRAY_SIZE(vdivs), | |
74413faf GS |
280 | |
281 | .num_xdivs = 12, | |
282 | .num_ydivs = 8, | |
283 | ||
13f2b9d7 DJ |
284 | .scpi_dialect = &hameg_scpi_dialect, |
285 | }, | |
286 | }; | |
287 | ||
329733d9 | 288 | static void scope_state_dump(const struct scope_config *config, |
13f2b9d7 DJ |
289 | struct scope_state *state) |
290 | { | |
291 | unsigned int i; | |
8de2dc3b | 292 | char *tmp; |
13f2b9d7 | 293 | |
0a1f7b09 | 294 | for (i = 0; i < config->analog_channels; i++) { |
8de2dc3b DJ |
295 | tmp = sr_voltage_string((*config->vdivs)[state->analog_channels[i].vdiv][0], |
296 | (*config->vdivs)[state->analog_channels[i].vdiv][1]); | |
d9251a2c | 297 | sr_info("State of analog channel %d -> %s : %s (coupling) %s (vdiv) %2.2e (offset)", |
8de2dc3b | 298 | i + 1, state->analog_channels[i].state ? "On" : "Off", |
13f2b9d7 | 299 | (*config->coupling_options)[state->analog_channels[i].coupling], |
8de2dc3b | 300 | tmp, state->analog_channels[i].vertical_offset); |
13f2b9d7 DJ |
301 | } |
302 | ||
0a1f7b09 | 303 | for (i = 0; i < config->digital_channels; i++) { |
13f2b9d7 DJ |
304 | sr_info("State of digital channel %d -> %s", i, |
305 | state->digital_channels[i] ? "On" : "Off"); | |
306 | } | |
307 | ||
0a1f7b09 | 308 | for (i = 0; i < config->digital_pods; i++) { |
13f2b9d7 DJ |
309 | sr_info("State of digital POD %d -> %s", i, |
310 | state->digital_pods[i] ? "On" : "Off"); | |
311 | } | |
312 | ||
6984cfb2 SA |
313 | tmp = sr_period_string((*config->timebases)[state->timebase][0], |
314 | (*config->timebases)[state->timebase][1]); | |
8de2dc3b DJ |
315 | sr_info("Current timebase: %s", tmp); |
316 | g_free(tmp); | |
317 | ||
14a2f74d DJ |
318 | tmp = sr_samplerate_string(state->sample_rate); |
319 | sr_info("Current samplerate: %s", tmp); | |
320 | g_free(tmp); | |
321 | ||
422a1c0d | 322 | sr_info("Current trigger: %s (source), %s (slope) %.2f (offset)", |
13f2b9d7 DJ |
323 | (*config->trigger_sources)[state->trigger_source], |
324 | (*config->trigger_slopes)[state->trigger_slope], | |
325 | state->horiz_triggerpos); | |
326 | } | |
327 | ||
23f43dff | 328 | static int scope_state_get_array_option(struct sr_scpi_dev_inst *scpi, |
692716f5 | 329 | const char *command, const char *(*array)[], unsigned int n, int *result) |
13f2b9d7 DJ |
330 | { |
331 | char *tmp; | |
bd633efa | 332 | int idx; |
13f2b9d7 | 333 | |
23f43dff | 334 | if (sr_scpi_get_string(scpi, command, &tmp) != SR_OK) { |
89280b1a | 335 | g_free(tmp); |
13f2b9d7 DJ |
336 | return SR_ERR; |
337 | } | |
338 | ||
bd633efa | 339 | if ((idx = std_str_idx_s(tmp, *array, n)) < 0) { |
13f2b9d7 | 340 | g_free(tmp); |
bd633efa | 341 | return SR_ERR_ARG; |
13f2b9d7 DJ |
342 | } |
343 | ||
bd633efa UH |
344 | *result = idx; |
345 | ||
346 | g_free(tmp); | |
347 | ||
13f2b9d7 DJ |
348 | return SR_OK; |
349 | } | |
350 | ||
8fff7519 | 351 | /** |
a53acd7d SB |
352 | * This function takes a value of the form "2.000E-03" and returns the index |
353 | * of an array where a matching pair was found. | |
8fff7519 SA |
354 | * |
355 | * @param value The string to be parsed. | |
356 | * @param array The array of s/f pairs. | |
357 | * @param array_len The number of pairs in the array. | |
358 | * @param result The index at which a matching pair was found. | |
359 | * | |
360 | * @return SR_ERR on any parsing error, SR_OK otherwise. | |
361 | */ | |
362 | static int array_float_get(gchar *value, const uint64_t array[][2], | |
650847e7 | 363 | int array_len, unsigned int *result) |
8fff7519 | 364 | { |
a53acd7d SB |
365 | struct sr_rational rval; |
366 | struct sr_rational aval; | |
8cccbac8 | 367 | |
a53acd7d | 368 | if (sr_parse_rational(value, &rval) != SR_OK) |
8fff7519 SA |
369 | return SR_ERR; |
370 | ||
a53acd7d SB |
371 | for (int i = 0; i < array_len; i++) { |
372 | sr_rational_set(&aval, array[i][0], array[i][1]); | |
373 | if (sr_rational_eq(&rval, &aval)) { | |
8fff7519 SA |
374 | *result = i; |
375 | return SR_OK; | |
376 | } | |
377 | } | |
378 | ||
379 | return SR_ERR; | |
380 | } | |
381 | ||
bd70ec4b SB |
382 | static struct sr_channel *get_channel_by_index_and_type(GSList *channel_lhead, |
383 | int index, int type) | |
384 | { | |
385 | while (channel_lhead) { | |
386 | struct sr_channel *ch = channel_lhead->data; | |
387 | if (ch->index == index && ch->type == type) | |
388 | return ch; | |
389 | ||
390 | channel_lhead = channel_lhead->next; | |
391 | } | |
392 | ||
393 | return 0; | |
394 | } | |
395 | ||
396 | static int analog_channel_state_get(struct sr_dev_inst *sdi, | |
329733d9 | 397 | const struct scope_config *config, |
13f2b9d7 DJ |
398 | struct scope_state *state) |
399 | { | |
8de2dc3b | 400 | unsigned int i, j; |
13f2b9d7 | 401 | char command[MAX_COMMAND_SIZE]; |
8fff7519 | 402 | char *tmp_str; |
bd70ec4b SB |
403 | struct sr_channel *ch; |
404 | struct sr_scpi_dev_inst *scpi = sdi->conn; | |
13f2b9d7 | 405 | |
0a1f7b09 | 406 | for (i = 0; i < config->analog_channels; i++) { |
13f2b9d7 DJ |
407 | g_snprintf(command, sizeof(command), |
408 | (*config->scpi_dialect)[SCPI_CMD_GET_ANALOG_CHAN_STATE], | |
409 | i + 1); | |
410 | ||
23f43dff | 411 | if (sr_scpi_get_bool(scpi, command, |
13f2b9d7 DJ |
412 | &state->analog_channels[i].state) != SR_OK) |
413 | return SR_ERR; | |
414 | ||
bd70ec4b SB |
415 | ch = get_channel_by_index_and_type(sdi->channels, i, SR_CHANNEL_ANALOG); |
416 | if (ch) | |
417 | ch->enabled = state->analog_channels[i].state; | |
418 | ||
13f2b9d7 DJ |
419 | g_snprintf(command, sizeof(command), |
420 | (*config->scpi_dialect)[SCPI_CMD_GET_VERTICAL_DIV], | |
421 | i + 1); | |
422 | ||
8fff7519 | 423 | if (sr_scpi_get_string(scpi, command, &tmp_str) != SR_OK) |
8de2dc3b | 424 | return SR_ERR; |
8fff7519 | 425 | |
53012da6 | 426 | if (array_float_get(tmp_str, ARRAY_AND_SIZE(vdivs), &j) != SR_OK) { |
8fff7519 | 427 | g_free(tmp_str); |
b4e31d2a | 428 | sr_err("Could not determine array index for vertical div scale."); |
13f2b9d7 | 429 | return SR_ERR; |
b4e31d2a | 430 | } |
13f2b9d7 | 431 | |
8fff7519 SA |
432 | g_free(tmp_str); |
433 | state->analog_channels[i].vdiv = j; | |
434 | ||
13f2b9d7 DJ |
435 | g_snprintf(command, sizeof(command), |
436 | (*config->scpi_dialect)[SCPI_CMD_GET_VERTICAL_OFFSET], | |
437 | i + 1); | |
438 | ||
23f43dff | 439 | if (sr_scpi_get_float(scpi, command, |
13f2b9d7 DJ |
440 | &state->analog_channels[i].vertical_offset) != SR_OK) |
441 | return SR_ERR; | |
442 | ||
443 | g_snprintf(command, sizeof(command), | |
444 | (*config->scpi_dialect)[SCPI_CMD_GET_COUPLING], | |
445 | i + 1); | |
446 | ||
23f43dff | 447 | if (scope_state_get_array_option(scpi, command, config->coupling_options, |
692716f5 | 448 | config->num_coupling_options, |
13f2b9d7 DJ |
449 | &state->analog_channels[i].coupling) != SR_OK) |
450 | return SR_ERR; | |
448e81b1 SB |
451 | |
452 | g_snprintf(command, sizeof(command), | |
453 | (*config->scpi_dialect)[SCPI_CMD_GET_PROBE_UNIT], | |
454 | i + 1); | |
455 | ||
456 | if (sr_scpi_get_string(scpi, command, &tmp_str) != SR_OK) | |
457 | return SR_ERR; | |
458 | ||
459 | if (tmp_str[0] == 'A') | |
460 | state->analog_channels[i].probe_unit = 'A'; | |
461 | else | |
462 | state->analog_channels[i].probe_unit = 'V'; | |
463 | g_free(tmp_str); | |
13f2b9d7 DJ |
464 | } |
465 | ||
466 | return SR_OK; | |
467 | } | |
468 | ||
bd70ec4b | 469 | static int digital_channel_state_get(struct sr_dev_inst *sdi, |
329733d9 | 470 | const struct scope_config *config, |
13f2b9d7 DJ |
471 | struct scope_state *state) |
472 | { | |
473 | unsigned int i; | |
474 | char command[MAX_COMMAND_SIZE]; | |
bd70ec4b SB |
475 | struct sr_channel *ch; |
476 | struct sr_scpi_dev_inst *scpi = sdi->conn; | |
13f2b9d7 | 477 | |
0a1f7b09 | 478 | for (i = 0; i < config->digital_channels; i++) { |
13f2b9d7 DJ |
479 | g_snprintf(command, sizeof(command), |
480 | (*config->scpi_dialect)[SCPI_CMD_GET_DIG_CHAN_STATE], | |
481 | i); | |
482 | ||
23f43dff | 483 | if (sr_scpi_get_bool(scpi, command, |
13f2b9d7 DJ |
484 | &state->digital_channels[i]) != SR_OK) |
485 | return SR_ERR; | |
bd70ec4b SB |
486 | |
487 | ch = get_channel_by_index_and_type(sdi->channels, i, SR_CHANNEL_LOGIC); | |
488 | if (ch) | |
489 | ch->enabled = state->digital_channels[i]; | |
13f2b9d7 DJ |
490 | } |
491 | ||
0a1f7b09 | 492 | for (i = 0; i < config->digital_pods; i++) { |
13f2b9d7 DJ |
493 | g_snprintf(command, sizeof(command), |
494 | (*config->scpi_dialect)[SCPI_CMD_GET_DIG_POD_STATE], | |
495 | i + 1); | |
496 | ||
23f43dff | 497 | if (sr_scpi_get_bool(scpi, command, |
13f2b9d7 DJ |
498 | &state->digital_pods[i]) != SR_OK) |
499 | return SR_ERR; | |
500 | } | |
501 | ||
502 | return SR_OK; | |
503 | } | |
504 | ||
14a2f74d DJ |
505 | SR_PRIV int hmo_update_sample_rate(const struct sr_dev_inst *sdi) |
506 | { | |
507 | struct dev_context *devc; | |
508 | struct scope_state *state; | |
329733d9 | 509 | const struct scope_config *config; |
14a2f74d DJ |
510 | int tmp; |
511 | unsigned int i; | |
512 | float tmp_float; | |
513 | gboolean channel_found; | |
514 | char tmp_str[MAX_COMMAND_SIZE]; | |
515 | char chan_name[20]; | |
516 | ||
517 | devc = sdi->priv; | |
518 | config = devc->model_config; | |
519 | state = devc->model_state; | |
520 | channel_found = FALSE; | |
521 | ||
0a1f7b09 | 522 | for (i = 0; i < config->analog_channels; i++) { |
3782e571 UH |
523 | if (!state->analog_channels[i].state) |
524 | continue; | |
525 | g_snprintf(chan_name, sizeof(chan_name), "CHAN%d", i + 1); | |
526 | g_snprintf(tmp_str, sizeof(tmp_str), | |
527 | (*config->scpi_dialect)[SCPI_CMD_GET_SAMPLE_RATE_LIVE], | |
528 | chan_name); | |
529 | channel_found = TRUE; | |
530 | break; | |
531 | } | |
532 | ||
533 | if (!channel_found) { | |
534 | for (i = 0; i < config->digital_pods; i++) { | |
535 | if (!state->digital_pods[i]) | |
536 | continue; | |
537 | g_snprintf(chan_name, sizeof(chan_name), "POD%d", i); | |
14a2f74d DJ |
538 | g_snprintf(tmp_str, sizeof(tmp_str), |
539 | (*config->scpi_dialect)[SCPI_CMD_GET_SAMPLE_RATE_LIVE], | |
540 | chan_name); | |
541 | channel_found = TRUE; | |
542 | break; | |
543 | } | |
544 | } | |
545 | ||
14a2f74d DJ |
546 | /* No channel is active, ask the instrument for the sample rate |
547 | * in single shot mode */ | |
548 | if (!channel_found) { | |
c06c24d2 DJ |
549 | if (sr_scpi_get_float(sdi->conn, |
550 | (*config->scpi_dialect)[SCPI_CMD_GET_SAMPLE_RATE], | |
551 | &tmp_float) != SR_OK) | |
14a2f74d | 552 | return SR_ERR; |
c06c24d2 | 553 | |
14a2f74d DJ |
554 | state->sample_rate = tmp_float; |
555 | } else { | |
556 | if (sr_scpi_get_int(sdi->conn, tmp_str, &tmp) != SR_OK) | |
557 | return SR_ERR; | |
558 | state->sample_rate = tmp / (((float) (*config->timebases)[state->timebase][0] / | |
559 | (*config->timebases)[state->timebase][1]) * | |
560 | config->num_xdivs); | |
561 | } | |
562 | ||
563 | return SR_OK; | |
564 | } | |
565 | ||
719eff68 | 566 | SR_PRIV int hmo_scope_state_get(struct sr_dev_inst *sdi) |
13f2b9d7 DJ |
567 | { |
568 | struct dev_context *devc; | |
569 | struct scope_state *state; | |
329733d9 | 570 | const struct scope_config *config; |
8de2dc3b DJ |
571 | float tmp_float; |
572 | unsigned int i; | |
8cccbac8 | 573 | char *tmp_str; |
13f2b9d7 DJ |
574 | |
575 | devc = sdi->priv; | |
576 | config = devc->model_config; | |
577 | state = devc->model_state; | |
578 | ||
8de2dc3b DJ |
579 | sr_info("Fetching scope state"); |
580 | ||
bd70ec4b | 581 | if (analog_channel_state_get(sdi, config, state) != SR_OK) |
13f2b9d7 DJ |
582 | return SR_ERR; |
583 | ||
bd70ec4b | 584 | if (digital_channel_state_get(sdi, config, state) != SR_OK) |
13f2b9d7 DJ |
585 | return SR_ERR; |
586 | ||
89280b1a UH |
587 | if (sr_scpi_get_float(sdi->conn, |
588 | (*config->scpi_dialect)[SCPI_CMD_GET_TIMEBASE], | |
8de2dc3b DJ |
589 | &tmp_float) != SR_OK) |
590 | return SR_ERR; | |
591 | ||
8cccbac8 SA |
592 | if (sr_scpi_get_string(sdi->conn, |
593 | (*config->scpi_dialect)[SCPI_CMD_GET_TIMEBASE], | |
594 | &tmp_str) != SR_OK) | |
595 | return SR_ERR; | |
596 | ||
53012da6 | 597 | if (array_float_get(tmp_str, ARRAY_AND_SIZE(timebases), &i) != SR_OK) { |
8cccbac8 | 598 | g_free(tmp_str); |
b4e31d2a | 599 | sr_err("Could not determine array index for time base."); |
13f2b9d7 | 600 | return SR_ERR; |
b4e31d2a | 601 | } |
e5b7eef7 | 602 | g_free(tmp_str); |
13f2b9d7 | 603 | |
8cccbac8 SA |
604 | state->timebase = i; |
605 | ||
89280b1a UH |
606 | if (sr_scpi_get_float(sdi->conn, |
607 | (*config->scpi_dialect)[SCPI_CMD_GET_HORIZ_TRIGGERPOS], | |
422a1c0d | 608 | &tmp_float) != SR_OK) |
13f2b9d7 | 609 | return SR_ERR; |
422a1c0d DJ |
610 | state->horiz_triggerpos = tmp_float / |
611 | (((double) (*config->timebases)[state->timebase][0] / | |
612 | (*config->timebases)[state->timebase][1]) * config->num_xdivs); | |
613 | state->horiz_triggerpos -= 0.5; | |
614 | state->horiz_triggerpos *= -1; | |
13f2b9d7 | 615 | |
89280b1a UH |
616 | if (scope_state_get_array_option(sdi->conn, |
617 | (*config->scpi_dialect)[SCPI_CMD_GET_TRIGGER_SOURCE], | |
692716f5 UH |
618 | config->trigger_sources, config->num_trigger_sources, |
619 | &state->trigger_source) != SR_OK) | |
13f2b9d7 DJ |
620 | return SR_ERR; |
621 | ||
89280b1a | 622 | if (scope_state_get_array_option(sdi->conn, |
692716f5 UH |
623 | (*config->scpi_dialect)[SCPI_CMD_GET_TRIGGER_SLOPE], |
624 | config->trigger_slopes, config->num_trigger_slopes, | |
625 | &state->trigger_slope) != SR_OK) | |
13f2b9d7 DJ |
626 | return SR_ERR; |
627 | ||
14a2f74d DJ |
628 | if (hmo_update_sample_rate(sdi) != SR_OK) |
629 | return SR_ERR; | |
630 | ||
8de2dc3b DJ |
631 | sr_info("Fetching finished."); |
632 | ||
13f2b9d7 DJ |
633 | scope_state_dump(config, state); |
634 | ||
635 | return SR_OK; | |
636 | } | |
637 | ||
329733d9 | 638 | static struct scope_state *scope_state_new(const struct scope_config *config) |
13f2b9d7 DJ |
639 | { |
640 | struct scope_state *state; | |
641 | ||
a95f142e UH |
642 | state = g_malloc0(sizeof(struct scope_state)); |
643 | state->analog_channels = g_malloc0_n(config->analog_channels, | |
644 | sizeof(struct analog_channel_state)); | |
645 | state->digital_channels = g_malloc0_n( | |
646 | config->digital_channels, sizeof(gboolean)); | |
647 | state->digital_pods = g_malloc0_n(config->digital_pods, | |
648 | sizeof(gboolean)); | |
13f2b9d7 DJ |
649 | |
650 | return state; | |
13f2b9d7 DJ |
651 | } |
652 | ||
719eff68 | 653 | SR_PRIV void hmo_scope_state_free(struct scope_state *state) |
13f2b9d7 DJ |
654 | { |
655 | g_free(state->analog_channels); | |
656 | g_free(state->digital_channels); | |
657 | g_free(state->digital_pods); | |
658 | g_free(state); | |
659 | } | |
660 | ||
661 | SR_PRIV int hmo_init_device(struct sr_dev_inst *sdi) | |
662 | { | |
13f2b9d7 | 663 | int model_index; |
2d224dba | 664 | unsigned int i, j, group; |
ba7dd8bb | 665 | struct sr_channel *ch; |
13f2b9d7 DJ |
666 | struct dev_context *devc; |
667 | ||
668 | devc = sdi->priv; | |
669 | model_index = -1; | |
670 | ||
89280b1a | 671 | /* Find the exact model. */ |
13f2b9d7 DJ |
672 | for (i = 0; i < ARRAY_SIZE(scope_models); i++) { |
673 | for (j = 0; scope_models[i].name[j]; j++) { | |
674 | if (!strcmp(sdi->model, scope_models[i].name[j])) { | |
675 | model_index = i; | |
676 | break; | |
677 | } | |
678 | } | |
679 | if (model_index != -1) | |
680 | break; | |
681 | } | |
682 | ||
683 | if (model_index == -1) { | |
89280b1a | 684 | sr_dbg("Unsupported HMO device."); |
13f2b9d7 DJ |
685 | return SR_ERR_NA; |
686 | } | |
687 | ||
562b7ae5 SA |
688 | devc->analog_groups = g_malloc0(sizeof(struct sr_channel_group*) * |
689 | scope_models[model_index].analog_channels); | |
13f2b9d7 | 690 | |
562b7ae5 SA |
691 | devc->digital_groups = g_malloc0(sizeof(struct sr_channel_group*) * |
692 | scope_models[model_index].digital_pods); | |
13f2b9d7 | 693 | |
89280b1a | 694 | /* Add analog channels. */ |
13f2b9d7 | 695 | for (i = 0; i < scope_models[model_index].analog_channels; i++) { |
5e23fcab | 696 | ch = sr_channel_new(sdi, i, SR_CHANNEL_ANALOG, TRUE, |
c368e6f3 | 697 | (*scope_models[model_index].analog_names)[i]); |
13f2b9d7 | 698 | |
562b7ae5 SA |
699 | devc->analog_groups[i] = g_malloc0(sizeof(struct sr_channel_group)); |
700 | ||
701 | devc->analog_groups[i]->name = g_strdup( | |
702 | (char *)(*scope_models[model_index].analog_names)[i]); | |
703 | devc->analog_groups[i]->channels = g_slist_append(NULL, ch); | |
13f2b9d7 | 704 | |
660e398f | 705 | sdi->channel_groups = g_slist_append(sdi->channel_groups, |
562b7ae5 | 706 | devc->analog_groups[i]); |
13f2b9d7 DJ |
707 | } |
708 | ||
660e398f | 709 | /* Add digital channel groups. */ |
0a1f7b09 | 710 | for (i = 0; i < scope_models[model_index].digital_pods; i++) { |
562b7ae5 | 711 | devc->digital_groups[i] = g_malloc0(sizeof(struct sr_channel_group)); |
d2391b54 | 712 | devc->digital_groups[i]->name = g_strdup_printf("POD%d", i); |
660e398f | 713 | sdi->channel_groups = g_slist_append(sdi->channel_groups, |
2d224dba | 714 | devc->digital_groups[i]); |
13f2b9d7 DJ |
715 | } |
716 | ||
89280b1a | 717 | /* Add digital channels. */ |
13f2b9d7 | 718 | for (i = 0; i < scope_models[model_index].digital_channels; i++) { |
5e23fcab | 719 | ch = sr_channel_new(sdi, i, SR_CHANNEL_LOGIC, TRUE, |
c368e6f3 | 720 | (*scope_models[model_index].digital_names)[i]); |
13f2b9d7 | 721 | |
2d224dba GS |
722 | group = i / 8; |
723 | devc->digital_groups[group]->channels = g_slist_append( | |
724 | devc->digital_groups[group]->channels, ch); | |
13f2b9d7 DJ |
725 | } |
726 | ||
727 | devc->model_config = &scope_models[model_index]; | |
728 | devc->frame_limit = 0; | |
729 | ||
730 | if (!(devc->model_state = scope_state_new(devc->model_config))) | |
731 | return SR_ERR_MALLOC; | |
732 | ||
733 | return SR_OK; | |
734 | } | |
735 | ||
e06875b2 GS |
736 | /* Queue data of one channel group, for later submission. */ |
737 | SR_PRIV void hmo_queue_logic_data(struct dev_context *devc, | |
738 | size_t group, GByteArray *pod_data) | |
739 | { | |
740 | size_t size; | |
741 | GByteArray *store; | |
742 | uint8_t *logic_data; | |
743 | size_t idx, logic_step; | |
744 | ||
745 | /* | |
746 | * Upon first invocation, allocate the array which can hold the | |
747 | * combined logic data for all channels. Assume that each channel | |
748 | * will yield an identical number of samples per receive call. | |
749 | * | |
750 | * As a poor man's safety measure: (Silently) skip processing | |
751 | * for unexpected sample counts, and ignore samples for | |
752 | * unexpected channel groups. Don't bother with complicated | |
753 | * resize logic, considering that many models only support one | |
754 | * pod, and the most capable supported models have two pods of | |
755 | * identical size. We haven't yet seen any "odd" configuration. | |
756 | */ | |
757 | if (!devc->logic_data) { | |
758 | size = pod_data->len * devc->pod_count; | |
759 | store = g_byte_array_sized_new(size); | |
760 | memset(store->data, 0, size); | |
761 | store = g_byte_array_set_size(store, size); | |
762 | devc->logic_data = store; | |
763 | } else { | |
764 | store = devc->logic_data; | |
765 | size = store->len / devc->pod_count; | |
766 | if (size != pod_data->len) | |
767 | return; | |
768 | if (group >= devc->pod_count) | |
769 | return; | |
770 | } | |
771 | ||
772 | /* | |
773 | * Fold the data of the most recently received channel group into | |
774 | * the storage, where data resides for all channels combined. | |
775 | */ | |
776 | logic_data = store->data; | |
777 | logic_data += group; | |
778 | logic_step = devc->pod_count; | |
779 | for (idx = 0; idx < pod_data->len; idx++) { | |
780 | *logic_data = pod_data->data[idx]; | |
781 | logic_data += logic_step; | |
782 | } | |
783 | } | |
784 | ||
785 | /* Submit data for all channels, after the individual groups got collected. */ | |
786 | SR_PRIV void hmo_send_logic_packet(struct sr_dev_inst *sdi, | |
787 | struct dev_context *devc) | |
788 | { | |
789 | struct sr_datafeed_packet packet; | |
790 | struct sr_datafeed_logic logic; | |
791 | ||
792 | if (!devc->logic_data) | |
793 | return; | |
794 | ||
795 | logic.data = devc->logic_data->data; | |
796 | logic.length = devc->logic_data->len; | |
797 | logic.unitsize = devc->pod_count; | |
798 | ||
799 | packet.type = SR_DF_LOGIC; | |
800 | packet.payload = &logic; | |
801 | ||
802 | sr_session_send(sdi, &packet); | |
803 | } | |
804 | ||
805 | /* Undo previous resource allocation. */ | |
806 | SR_PRIV void hmo_cleanup_logic_data(struct dev_context *devc) | |
807 | { | |
808 | ||
809 | if (devc->logic_data) { | |
810 | g_byte_array_free(devc->logic_data, TRUE); | |
811 | devc->logic_data = NULL; | |
812 | } | |
813 | /* | |
814 | * Keep 'pod_count'! It's required when more frames will be | |
815 | * received, and does not harm when kept after acquisition. | |
816 | */ | |
817 | } | |
818 | ||
719eff68 | 819 | SR_PRIV int hmo_receive_data(int fd, int revents, void *cb_data) |
06a3e78a | 820 | { |
ba7dd8bb | 821 | struct sr_channel *ch; |
13f2b9d7 | 822 | struct sr_dev_inst *sdi; |
06a3e78a | 823 | struct dev_context *devc; |
401b83a1 | 824 | struct scope_state *state; |
13f2b9d7 | 825 | struct sr_datafeed_packet packet; |
401b83a1 SB |
826 | GByteArray *data; |
827 | struct sr_datafeed_analog analog; | |
828 | struct sr_analog_encoding encoding; | |
829 | struct sr_analog_meaning meaning; | |
830 | struct sr_analog_spec spec; | |
89280b1a | 831 | struct sr_datafeed_logic logic; |
e06875b2 | 832 | size_t group; |
06a3e78a DJ |
833 | |
834 | (void)fd; | |
f0729866 | 835 | (void)revents; |
06a3e78a | 836 | |
f62f595b MK |
837 | data = NULL; |
838 | ||
06a3e78a DJ |
839 | if (!(sdi = cb_data)) |
840 | return TRUE; | |
841 | ||
842 | if (!(devc = sdi->priv)) | |
843 | return TRUE; | |
844 | ||
f4f273ce SB |
845 | /* Although this is correct in general, the USBTMC libusb implementation |
846 | * currently does not generate an event prior to the first read. Often | |
847 | * it is ok to start reading just after the 50ms timeout. See bug #785. | |
dc89faea UH |
848 | if (revents != G_IO_IN) |
849 | return TRUE; | |
f4f273ce | 850 | */ |
13f2b9d7 | 851 | |
dc89faea | 852 | ch = devc->current_channel->data; |
401b83a1 | 853 | state = devc->model_state; |
13f2b9d7 | 854 | |
b23eb1d4 GS |
855 | /* |
856 | * Send "frame begin" packet upon reception of data for the | |
857 | * first enabled channel. | |
858 | */ | |
859 | if (devc->current_channel == devc->enabled_channels) { | |
860 | packet.type = SR_DF_FRAME_BEGIN; | |
861 | sr_session_send(sdi, &packet); | |
862 | } | |
863 | ||
864 | /* | |
865 | * Pass on the received data of the channel(s). | |
866 | */ | |
dc89faea UH |
867 | switch (ch->type) { |
868 | case SR_CHANNEL_ANALOG: | |
401b83a1 | 869 | if (sr_scpi_get_block(sdi->conn, NULL, &data) != SR_OK) { |
dc89faea | 870 | if (data) |
401b83a1 | 871 | g_byte_array_free(data, TRUE); |
13f2b9d7 | 872 | |
dc89faea | 873 | return TRUE; |
13f2b9d7 DJ |
874 | } |
875 | ||
401b83a1 SB |
876 | packet.type = SR_DF_ANALOG; |
877 | ||
878 | analog.data = data->data; | |
879 | analog.num_samples = data->len / sizeof(float); | |
880 | analog.encoding = &encoding; | |
881 | analog.meaning = &meaning; | |
882 | analog.spec = &spec; | |
883 | ||
884 | encoding.unitsize = sizeof(float); | |
885 | encoding.is_signed = TRUE; | |
886 | encoding.is_float = TRUE; | |
65a6794e GS |
887 | #ifdef WORDS_BIGENDIAN |
888 | encoding.is_bigendian = TRUE; | |
889 | #else | |
d1ad8b10 | 890 | encoding.is_bigendian = FALSE; |
65a6794e | 891 | #endif |
7dcaddd3 UH |
892 | /* TODO: Use proper 'digits' value for this device (and its modes). */ |
893 | encoding.digits = 2; | |
401b83a1 SB |
894 | encoding.is_digits_decimal = FALSE; |
895 | encoding.scale.p = 1; | |
896 | encoding.scale.q = 1; | |
897 | encoding.offset.p = 0; | |
898 | encoding.offset.q = 1; | |
899 | if (state->analog_channels[ch->index].probe_unit == 'V') { | |
900 | meaning.mq = SR_MQ_VOLTAGE; | |
901 | meaning.unit = SR_UNIT_VOLT; | |
902 | } else { | |
903 | meaning.mq = SR_MQ_CURRENT; | |
904 | meaning.unit = SR_UNIT_AMPERE; | |
905 | } | |
906 | meaning.mqflags = 0; | |
907 | meaning.channels = g_slist_append(NULL, ch); | |
7dcaddd3 UH |
908 | /* TODO: Use proper 'digits' value for this device (and its modes). */ |
909 | spec.spec_digits = 2; | |
dc89faea | 910 | packet.payload = &analog; |
695dc859 | 911 | sr_session_send(sdi, &packet); |
401b83a1 SB |
912 | g_slist_free(meaning.channels); |
913 | g_byte_array_free(data, TRUE); | |
dc89faea UH |
914 | data = NULL; |
915 | break; | |
916 | case SR_CHANNEL_LOGIC: | |
401b83a1 | 917 | if (sr_scpi_get_block(sdi->conn, NULL, &data) != SR_OK) { |
dc89faea UH |
918 | g_free(data); |
919 | return TRUE; | |
13f2b9d7 | 920 | } |
dc89faea | 921 | |
e06875b2 GS |
922 | /* |
923 | * If only data from the first pod is involved in the | |
924 | * acquisition, then the raw input bytes can get passed | |
925 | * forward for performance reasons. When the second pod | |
926 | * is involved (either alone, or in combination with the | |
927 | * first pod), then the received bytes need to be put | |
928 | * into memory in such a layout that all channel groups | |
929 | * get combined, and a unitsize larger than a single byte | |
930 | * applies. The "queue" logic transparently copes with | |
931 | * any such configuration. This works around the lack | |
932 | * of support for "meaning" to logic data, which is used | |
933 | * above for analog data. | |
934 | */ | |
935 | if (devc->pod_count == 1) { | |
936 | packet.type = SR_DF_LOGIC; | |
937 | logic.data = data->data; | |
938 | logic.length = data->len; | |
939 | logic.unitsize = 1; | |
940 | packet.payload = &logic; | |
941 | sr_session_send(sdi, &packet); | |
942 | } else { | |
943 | group = ch->index / 8; | |
944 | hmo_queue_logic_data(devc, group, data); | |
945 | } | |
dc89faea | 946 | |
401b83a1 | 947 | g_byte_array_free(data, TRUE); |
dc89faea UH |
948 | data = NULL; |
949 | break; | |
950 | default: | |
951 | sr_err("Invalid channel type."); | |
952 | break; | |
953 | } | |
954 | ||
b23eb1d4 GS |
955 | /* |
956 | * Advance to the next enabled channel. When data for all enabled | |
e06875b2 GS |
957 | * channels was received, then flush potentially queued logic data, |
958 | * and send the "frame end" packet. | |
b23eb1d4 | 959 | */ |
dc89faea UH |
960 | if (devc->current_channel->next) { |
961 | devc->current_channel = devc->current_channel->next; | |
962 | hmo_request_data(sdi); | |
b23eb1d4 GS |
963 | return TRUE; |
964 | } | |
e06875b2 GS |
965 | hmo_send_logic_packet(sdi, devc); |
966 | ||
967 | /* | |
968 | * Release the logic data storage after each frame. This copes | |
969 | * with sample counts that differ in length per frame. -- Is | |
970 | * this a real constraint when acquiring multiple frames with | |
971 | * identical device settings? | |
972 | */ | |
973 | hmo_cleanup_logic_data(devc); | |
974 | ||
b23eb1d4 GS |
975 | packet.type = SR_DF_FRAME_END; |
976 | sr_session_send(sdi, &packet); | |
977 | ||
978 | /* | |
979 | * End of frame was reached. Stop acquisition after the specified | |
980 | * number of frames, or continue reception by starting over at | |
981 | * the first enabled channel. | |
982 | */ | |
983 | if (++devc->num_frames == devc->frame_limit) { | |
d2f7c417 | 984 | sr_dev_acquisition_stop(sdi); |
e06875b2 | 985 | hmo_cleanup_logic_data(devc); |
dc89faea UH |
986 | } else { |
987 | devc->current_channel = devc->enabled_channels; | |
988 | hmo_request_data(sdi); | |
06a3e78a DJ |
989 | } |
990 | ||
991 | return TRUE; | |
992 | } |