]>
Commit | Line | Data |
---|---|---|
10763937 SA |
1 | /* |
2 | * This file is part of the libsigrok project. | |
3 | * | |
4 | * Copyright (C) 2014 abraxa (Soeren Apel) <soeren@apelpie.net> | |
5 | * Based on the Hameg HMO driver by poljar (Damir Jelić) <poljarinho@gmail.com> | |
6 | * | |
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. | |
11 | * | |
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. | |
16 | * | |
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/>. | |
19 | */ | |
20 | ||
6ec6c43b | 21 | #include <config.h> |
10763937 | 22 | #include <stdlib.h> |
5a1afc09 | 23 | #include "scpi.h" |
10763937 SA |
24 | #include "protocol.h" |
25 | ||
dd5c48a6 | 26 | static struct sr_dev_driver yokogawa_dlm_driver_info; |
8ab929d6 | 27 | |
329733d9 | 28 | static const char *MANUFACTURER_ID = "YOKOGAWA"; |
8ab929d6 | 29 | |
4b25cbff | 30 | static const uint32_t scanopts[] = { |
f3c60fb6 SA |
31 | SR_CONF_CONN, |
32 | }; | |
33 | ||
4b25cbff | 34 | static const uint32_t drvopts[] = { |
cf0280fa AJ |
35 | SR_CONF_LOGIC_ANALYZER, |
36 | SR_CONF_OSCILLOSCOPE, | |
37 | }; | |
38 | ||
4b25cbff | 39 | static const uint32_t devopts[] = { |
f3c60fb6 SA |
40 | SR_CONF_LIMIT_FRAMES | SR_CONF_GET | SR_CONF_SET, |
41 | SR_CONF_SAMPLERATE | SR_CONF_GET, | |
42 | SR_CONF_TIMEBASE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, | |
43 | SR_CONF_NUM_HDIV | SR_CONF_GET, | |
44 | SR_CONF_HORIZ_TRIGGERPOS | SR_CONF_GET | SR_CONF_SET, | |
f3c60fb6 | 45 | SR_CONF_TRIGGER_SOURCE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, |
86621306 | 46 | SR_CONF_TRIGGER_SLOPE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, |
f3c60fb6 SA |
47 | }; |
48 | ||
6b82c3e5 | 49 | static const uint32_t devopts_cg_analog[] = { |
f3c60fb6 | 50 | SR_CONF_NUM_VDIV | SR_CONF_GET, |
86621306 UH |
51 | SR_CONF_VDIV | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, |
52 | SR_CONF_COUPLING | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, | |
f3c60fb6 SA |
53 | }; |
54 | ||
6b82c3e5 | 55 | static const uint32_t devopts_cg_digital[] = { |
f3c60fb6 SA |
56 | }; |
57 | ||
8ab929d6 SA |
58 | enum { |
59 | CG_INVALID = -1, | |
60 | CG_NONE, | |
61 | CG_ANALOG, | |
62 | CG_DIGITAL, | |
63 | }; | |
64 | ||
8ab929d6 SA |
65 | static struct sr_dev_inst *probe_usbtmc_device(struct sr_scpi_dev_inst *scpi) |
66 | { | |
67 | struct sr_dev_inst *sdi; | |
68 | struct dev_context *devc; | |
69 | struct sr_scpi_hw_info *hw_info; | |
70 | char *model_name; | |
71 | int model_index; | |
72 | ||
73 | sdi = NULL; | |
74 | devc = NULL; | |
75 | hw_info = NULL; | |
76 | ||
77 | if (sr_scpi_get_hw_id(scpi, &hw_info) != SR_OK) { | |
78 | sr_info("Couldn't get IDN response."); | |
79 | goto fail; | |
80 | } | |
81 | ||
82 | if (strcmp(hw_info->manufacturer, MANUFACTURER_ID) != 0) | |
83 | goto fail; | |
84 | ||
85 | if (dlm_model_get(hw_info->model, &model_name, &model_index) != SR_OK) | |
86 | goto fail; | |
87 | ||
aac29cc1 | 88 | sdi = g_malloc0(sizeof(struct sr_dev_inst)); |
b15ff1c9 | 89 | sdi->vendor = g_strdup("Yokogawa"); |
0af636be UH |
90 | sdi->model = g_strdup(model_name); |
91 | sdi->version = g_strdup(hw_info->firmware_version); | |
8ab929d6 | 92 | |
d1314831 SA |
93 | sdi->serial_num = g_strdup(hw_info->serial_number); |
94 | ||
8ab929d6 SA |
95 | sr_scpi_hw_info_free(hw_info); |
96 | hw_info = NULL; | |
97 | ||
ac10a927 | 98 | devc = g_malloc0(sizeof(struct dev_context)); |
8ab929d6 | 99 | |
4f840ce9 | 100 | sdi->driver = &yokogawa_dlm_driver_info; |
8ab929d6 SA |
101 | sdi->priv = devc; |
102 | sdi->inst_type = SR_INST_SCPI; | |
103 | sdi->conn = scpi; | |
104 | ||
105 | if (dlm_device_init(sdi, model_index) != SR_OK) | |
106 | goto fail; | |
107 | ||
8ab929d6 SA |
108 | return sdi; |
109 | ||
110 | fail: | |
7b365c47 | 111 | sr_scpi_hw_info_free(hw_info); |
4bf93988 | 112 | sr_dev_inst_free(sdi); |
b1f83103 | 113 | g_free(devc); |
8ab929d6 SA |
114 | |
115 | return NULL; | |
116 | } | |
117 | ||
4f840ce9 | 118 | static GSList *scan(struct sr_dev_driver *di, GSList *options) |
8ab929d6 | 119 | { |
41812aca | 120 | return sr_scpi_scan(di->context, options, probe_usbtmc_device); |
8ab929d6 SA |
121 | } |
122 | ||
3553451f | 123 | static void clear_helper(struct dev_context *devc) |
8ab929d6 | 124 | { |
8ab929d6 | 125 | dlm_scope_state_destroy(devc->model_state); |
8ab929d6 SA |
126 | g_free(devc->analog_groups); |
127 | g_free(devc->digital_groups); | |
8ab929d6 SA |
128 | } |
129 | ||
4f840ce9 | 130 | static int dev_clear(const struct sr_dev_driver *di) |
8ab929d6 | 131 | { |
3553451f | 132 | return std_dev_clear_with_callback(di, (std_dev_clear_callback)clear_helper); |
8ab929d6 SA |
133 | } |
134 | ||
135 | static int dev_open(struct sr_dev_inst *sdi) | |
136 | { | |
6402c379 | 137 | if (sr_scpi_open(sdi->conn) != SR_OK) |
8ab929d6 SA |
138 | return SR_ERR; |
139 | ||
140 | if (dlm_scope_state_query(sdi) != SR_OK) | |
141 | return SR_ERR; | |
142 | ||
8ab929d6 SA |
143 | return SR_OK; |
144 | } | |
145 | ||
146 | static int dev_close(struct sr_dev_inst *sdi) | |
147 | { | |
f1ba6b4b | 148 | return sr_scpi_close(sdi->conn); |
8ab929d6 SA |
149 | } |
150 | ||
8ab929d6 SA |
151 | /** |
152 | * Check which category a given channel group belongs to. | |
153 | * | |
154 | * @param devc Our internal device context. | |
a9308652 | 155 | * @param cg The channel group to check. |
8ab929d6 | 156 | * |
a9308652 UH |
157 | * @retval CG_NONE cg is NULL |
158 | * @retval CG_ANALOG cg is an analog group | |
8ab929d6 SA |
159 | * @retval CG_DIGITAL cg is a digital group |
160 | * @retval CG_INVALID cg is something else | |
161 | */ | |
162 | static int check_channel_group(struct dev_context *devc, | |
ac10a927 | 163 | const struct sr_channel_group *cg) |
8ab929d6 SA |
164 | { |
165 | unsigned int i; | |
329733d9 | 166 | const struct scope_config *model; |
8ab929d6 SA |
167 | |
168 | model = devc->model_config; | |
169 | ||
170 | if (!cg) | |
171 | return CG_NONE; | |
172 | ||
a9308652 | 173 | for (i = 0; i < model->analog_channels; i++) |
8ab929d6 SA |
174 | if (cg == devc->analog_groups[i]) |
175 | return CG_ANALOG; | |
176 | ||
a9308652 | 177 | for (i = 0; i < model->pods; i++) |
8ab929d6 SA |
178 | if (cg == devc->digital_groups[i]) |
179 | return CG_DIGITAL; | |
180 | ||
181 | sr_err("Invalid channel group specified."); | |
182 | return CG_INVALID; | |
183 | } | |
184 | ||
dd7a72ea UH |
185 | static int config_get(uint32_t key, GVariant **data, |
186 | const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) | |
8ab929d6 SA |
187 | { |
188 | int ret, cg_type; | |
189 | unsigned int i; | |
190 | struct dev_context *devc; | |
329733d9 | 191 | const struct scope_config *model; |
8ab929d6 SA |
192 | struct scope_state *state; |
193 | ||
709468ba | 194 | if (!sdi) |
8ab929d6 SA |
195 | return SR_ERR_ARG; |
196 | ||
709468ba UH |
197 | devc = sdi->priv; |
198 | ||
8ab929d6 SA |
199 | if ((cg_type = check_channel_group(devc, cg)) == CG_INVALID) |
200 | return SR_ERR; | |
201 | ||
8ab929d6 SA |
202 | model = devc->model_config; |
203 | state = devc->model_state; | |
204 | ||
205 | switch (key) { | |
bf622e6d | 206 | case SR_CONF_NUM_HDIV: |
8ab929d6 SA |
207 | *data = g_variant_new_int32(model->num_xdivs); |
208 | ret = SR_OK; | |
209 | break; | |
210 | case SR_CONF_TIMEBASE: | |
211 | *data = g_variant_new("(tt)", | |
f3c60fb6 SA |
212 | dlm_timebases[state->timebase][0], |
213 | dlm_timebases[state->timebase][1]); | |
8ab929d6 SA |
214 | ret = SR_OK; |
215 | break; | |
216 | case SR_CONF_NUM_VDIV: | |
217 | if (cg_type == CG_NONE) { | |
8ab929d6 SA |
218 | return SR_ERR_CHANNEL_GROUP; |
219 | } else if (cg_type == CG_ANALOG) { | |
220 | *data = g_variant_new_int32(model->num_ydivs); | |
221 | ret = SR_OK; | |
222 | break; | |
223 | } else { | |
224 | ret = SR_ERR_NA; | |
225 | } | |
226 | break; | |
227 | case SR_CONF_VDIV: | |
228 | ret = SR_ERR_NA; | |
229 | if (cg_type == CG_NONE) { | |
8ab929d6 SA |
230 | return SR_ERR_CHANNEL_GROUP; |
231 | } else if (cg_type != CG_ANALOG) | |
232 | break; | |
233 | ||
a9308652 | 234 | for (i = 0; i < model->analog_channels; i++) { |
8ab929d6 SA |
235 | if (cg != devc->analog_groups[i]) |
236 | continue; | |
237 | *data = g_variant_new("(tt)", | |
f3c60fb6 SA |
238 | dlm_vdivs[state->analog_states[i].vdiv][0], |
239 | dlm_vdivs[state->analog_states[i].vdiv][1]); | |
8ab929d6 SA |
240 | ret = SR_OK; |
241 | break; | |
242 | } | |
243 | break; | |
244 | case SR_CONF_TRIGGER_SOURCE: | |
245 | *data = g_variant_new_string((*model->trigger_sources)[state->trigger_source]); | |
246 | ret = SR_OK; | |
247 | break; | |
248 | case SR_CONF_TRIGGER_SLOPE: | |
f3c60fb6 | 249 | *data = g_variant_new_string(dlm_trigger_slopes[state->trigger_slope]); |
8ab929d6 SA |
250 | ret = SR_OK; |
251 | break; | |
252 | case SR_CONF_HORIZ_TRIGGERPOS: | |
253 | *data = g_variant_new_double(state->horiz_triggerpos); | |
254 | ret = SR_OK; | |
255 | break; | |
256 | case SR_CONF_COUPLING: | |
257 | ret = SR_ERR_NA; | |
258 | if (cg_type == CG_NONE) { | |
8ab929d6 SA |
259 | return SR_ERR_CHANNEL_GROUP; |
260 | } else if (cg_type != CG_ANALOG) | |
261 | break; | |
262 | ||
a9308652 | 263 | for (i = 0; i < model->analog_channels; i++) { |
8ab929d6 SA |
264 | if (cg != devc->analog_groups[i]) |
265 | continue; | |
266 | *data = g_variant_new_string((*model->coupling_options)[state->analog_states[i].coupling]); | |
267 | ret = SR_OK; | |
268 | break; | |
269 | } | |
270 | break; | |
271 | case SR_CONF_SAMPLERATE: | |
272 | *data = g_variant_new_uint64(state->sample_rate); | |
273 | ret = SR_OK; | |
274 | break; | |
275 | default: | |
276 | ret = SR_ERR_NA; | |
277 | } | |
278 | ||
279 | return ret; | |
280 | } | |
281 | ||
dd7a72ea UH |
282 | static int config_set(uint32_t key, GVariant *data, |
283 | const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) | |
8ab929d6 SA |
284 | { |
285 | int ret, cg_type; | |
286 | unsigned int i, j; | |
287 | char float_str[30]; | |
288 | struct dev_context *devc; | |
329733d9 | 289 | const struct scope_config *model; |
8ab929d6 SA |
290 | struct scope_state *state; |
291 | const char *tmp; | |
292 | uint64_t p, q; | |
293 | double tmp_d; | |
294 | gboolean update_sample_rate; | |
295 | ||
296 | if (!sdi || !(devc = sdi->priv)) | |
297 | return SR_ERR_ARG; | |
298 | ||
299 | if ((cg_type = check_channel_group(devc, cg)) == CG_INVALID) | |
300 | return SR_ERR; | |
301 | ||
302 | model = devc->model_config; | |
303 | state = devc->model_state; | |
304 | update_sample_rate = FALSE; | |
305 | ||
306 | ret = SR_ERR_NA; | |
307 | ||
308 | switch (key) { | |
309 | case SR_CONF_LIMIT_FRAMES: | |
310 | devc->frame_limit = g_variant_get_uint64(data); | |
311 | ret = SR_OK; | |
312 | break; | |
313 | case SR_CONF_TRIGGER_SOURCE: | |
314 | tmp = g_variant_get_string(data, NULL); | |
315 | for (i = 0; (*model->trigger_sources)[i]; i++) { | |
316 | if (g_strcmp0(tmp, (*model->trigger_sources)[i]) != 0) | |
317 | continue; | |
318 | state->trigger_source = i; | |
319 | /* TODO: A and B trigger support possible? */ | |
320 | ret = dlm_trigger_source_set(sdi->conn, (*model->trigger_sources)[i]); | |
321 | break; | |
322 | } | |
323 | break; | |
324 | case SR_CONF_VDIV: | |
87dc5410 | 325 | if (cg_type == CG_NONE) |
8ab929d6 | 326 | return SR_ERR_CHANNEL_GROUP; |
8ab929d6 SA |
327 | |
328 | g_variant_get(data, "(tt)", &p, &q); | |
329 | ||
f3c60fb6 SA |
330 | for (i = 0; i < ARRAY_SIZE(dlm_vdivs); i++) { |
331 | if (p != dlm_vdivs[i][0] || | |
332 | q != dlm_vdivs[i][1]) | |
8ab929d6 | 333 | continue; |
a9308652 | 334 | for (j = 1; j <= model->analog_channels; j++) { |
8ab929d6 SA |
335 | if (cg != devc->analog_groups[j - 1]) |
336 | continue; | |
337 | state->analog_states[j - 1].vdiv = i; | |
338 | g_ascii_formatd(float_str, sizeof(float_str), | |
339 | "%E", (float) p / q); | |
340 | if (dlm_analog_chan_vdiv_set(sdi->conn, j, float_str) != SR_OK || | |
ac10a927 | 341 | sr_scpi_get_opc(sdi->conn) != SR_OK) |
8ab929d6 SA |
342 | return SR_ERR; |
343 | ||
344 | break; | |
345 | } | |
346 | ||
347 | ret = SR_OK; | |
348 | break; | |
349 | } | |
350 | break; | |
351 | case SR_CONF_TIMEBASE: | |
352 | g_variant_get(data, "(tt)", &p, &q); | |
353 | ||
f3c60fb6 SA |
354 | for (i = 0; i < ARRAY_SIZE(dlm_timebases); i++) { |
355 | if (p != dlm_timebases[i][0] || | |
356 | q != dlm_timebases[i][1]) | |
8ab929d6 SA |
357 | continue; |
358 | state->timebase = i; | |
359 | g_ascii_formatd(float_str, sizeof(float_str), | |
360 | "%E", (float) p / q); | |
361 | ret = dlm_timebase_set(sdi->conn, float_str); | |
362 | update_sample_rate = TRUE; | |
363 | break; | |
364 | } | |
365 | break; | |
366 | case SR_CONF_HORIZ_TRIGGERPOS: | |
367 | tmp_d = g_variant_get_double(data); | |
368 | ||
369 | /* TODO: Check if the calculation makes sense for the DLM. */ | |
370 | if (tmp_d < 0.0 || tmp_d > 1.0) | |
371 | return SR_ERR; | |
372 | ||
373 | state->horiz_triggerpos = tmp_d; | |
374 | tmp_d = -(tmp_d - 0.5) * | |
f3c60fb6 SA |
375 | ((double) dlm_timebases[state->timebase][0] / |
376 | dlm_timebases[state->timebase][1]) | |
ac10a927 | 377 | * model->num_xdivs; |
8ab929d6 SA |
378 | |
379 | g_ascii_formatd(float_str, sizeof(float_str), "%E", tmp_d); | |
380 | ret = dlm_horiz_trigger_pos_set(sdi->conn, float_str); | |
381 | break; | |
382 | case SR_CONF_TRIGGER_SLOPE: | |
383 | tmp = g_variant_get_string(data, NULL); | |
384 | ||
385 | if (!tmp || !(tmp[0] == 'f' || tmp[0] == 'r')) | |
386 | return SR_ERR_ARG; | |
387 | ||
388 | /* Note: See dlm_trigger_slopes[] in protocol.c. */ | |
389 | state->trigger_slope = (tmp[0] == 'r') ? | |
390 | SLOPE_POSITIVE : SLOPE_NEGATIVE; | |
391 | ||
392 | ret = dlm_trigger_slope_set(sdi->conn, state->trigger_slope); | |
393 | break; | |
394 | case SR_CONF_COUPLING: | |
87dc5410 | 395 | if (cg_type == CG_NONE) |
8ab929d6 | 396 | return SR_ERR_CHANNEL_GROUP; |
8ab929d6 SA |
397 | |
398 | tmp = g_variant_get_string(data, NULL); | |
399 | ||
400 | for (i = 0; (*model->coupling_options)[i]; i++) { | |
401 | if (strcmp(tmp, (*model->coupling_options)[i]) != 0) | |
402 | continue; | |
a9308652 | 403 | for (j = 1; j <= model->analog_channels; j++) { |
8ab929d6 SA |
404 | if (cg != devc->analog_groups[j - 1]) |
405 | continue; | |
406 | state->analog_states[j-1].coupling = i; | |
407 | ||
408 | if (dlm_analog_chan_coupl_set(sdi->conn, j, tmp) != SR_OK || | |
ac10a927 | 409 | sr_scpi_get_opc(sdi->conn) != SR_OK) |
8ab929d6 SA |
410 | return SR_ERR; |
411 | break; | |
412 | } | |
413 | ||
414 | ret = SR_OK; | |
415 | break; | |
416 | } | |
417 | break; | |
418 | default: | |
419 | ret = SR_ERR_NA; | |
420 | break; | |
421 | } | |
422 | ||
423 | if (ret == SR_OK) | |
424 | ret = sr_scpi_get_opc(sdi->conn); | |
425 | ||
426 | if (ret == SR_OK && update_sample_rate) | |
427 | ret = dlm_sample_rate_query(sdi); | |
428 | ||
429 | return ret; | |
430 | } | |
431 | ||
c65a021c | 432 | static int config_channel_set(const struct sr_dev_inst *sdi, |
dd7a72ea | 433 | struct sr_channel *ch, unsigned int changes) |
c65a021c | 434 | { |
a9308652 | 435 | /* Currently we only handle SR_CHANNEL_SET_ENABLED. */ |
c65a021c SA |
436 | if (changes != SR_CHANNEL_SET_ENABLED) |
437 | return SR_ERR_NA; | |
438 | ||
439 | return dlm_channel_state_set(sdi, ch->index, ch->enabled); | |
440 | } | |
441 | ||
dd7a72ea UH |
442 | static int config_list(uint32_t key, GVariant **data, |
443 | const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) | |
8ab929d6 | 444 | { |
cf0280fa | 445 | int cg_type = CG_NONE; |
e66d1892 UH |
446 | struct dev_context *devc; |
447 | const struct scope_config *model; | |
f3c60fb6 | 448 | |
e66d1892 UH |
449 | devc = (sdi) ? sdi->priv : NULL; |
450 | model = (devc) ? devc->model_config : NULL; | |
f3c60fb6 | 451 | |
f3c60fb6 SA |
452 | if (!cg) { |
453 | switch (key) { | |
e66d1892 | 454 | case SR_CONF_SCAN_OPTIONS: |
f3c60fb6 | 455 | case SR_CONF_DEVICE_OPTIONS: |
4b25cbff | 456 | return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts); |
f3c60fb6 | 457 | case SR_CONF_TIMEBASE: |
58ffcf97 | 458 | *data = std_gvar_tuple_array(ARRAY_AND_SIZE(dlm_timebases)); |
f3c60fb6 SA |
459 | return SR_OK; |
460 | case SR_CONF_TRIGGER_SOURCE: | |
461 | if (!model) | |
462 | return SR_ERR_ARG; | |
463 | *data = g_variant_new_strv(*model->trigger_sources, | |
464 | g_strv_length((char **)*model->trigger_sources)); | |
465 | return SR_OK; | |
466 | case SR_CONF_TRIGGER_SLOPE: | |
467 | *data = g_variant_new_strv(dlm_trigger_slopes, | |
468 | g_strv_length((char **)dlm_trigger_slopes)); | |
469 | return SR_OK; | |
470 | case SR_CONF_NUM_HDIV: | |
49f49cb5 | 471 | *data = g_variant_new_uint32(model->num_xdivs); |
f3c60fb6 SA |
472 | return SR_OK; |
473 | default: | |
474 | return SR_ERR_NA; | |
475 | } | |
476 | } | |
477 | ||
478 | if ((cg_type = check_channel_group(devc, cg)) == CG_INVALID) | |
479 | return SR_ERR; | |
480 | ||
8ab929d6 | 481 | switch (key) { |
8ab929d6 | 482 | case SR_CONF_DEVICE_OPTIONS: |
105df674 | 483 | if (cg_type == CG_ANALOG) |
53012da6 | 484 | *data = std_gvar_array_u32(ARRAY_AND_SIZE(devopts_cg_analog)); |
105df674 | 485 | else if (cg_type == CG_DIGITAL) |
53012da6 | 486 | *data = std_gvar_array_u32(ARRAY_AND_SIZE(devopts_cg_digital)); |
105df674 UH |
487 | else |
488 | *data = std_gvar_array_u32(NULL, 0); | |
8ab929d6 SA |
489 | break; |
490 | case SR_CONF_COUPLING: | |
491 | if (cg_type == CG_NONE) | |
492 | return SR_ERR_CHANNEL_GROUP; | |
493 | *data = g_variant_new_strv(*model->coupling_options, | |
ac10a927 | 494 | g_strv_length((char **)*model->coupling_options)); |
8ab929d6 | 495 | break; |
8ab929d6 SA |
496 | case SR_CONF_VDIV: |
497 | if (cg_type == CG_NONE) | |
498 | return SR_ERR_CHANNEL_GROUP; | |
58ffcf97 | 499 | *data = std_gvar_tuple_array(ARRAY_AND_SIZE(dlm_vdivs)); |
8ab929d6 SA |
500 | break; |
501 | default: | |
502 | return SR_ERR_NA; | |
503 | } | |
504 | ||
505 | return SR_OK; | |
506 | } | |
507 | ||
508 | static int dlm_check_channels(GSList *channels) | |
509 | { | |
510 | GSList *l; | |
511 | struct sr_channel *ch; | |
512 | gboolean enabled_pod1, enabled_chan4; | |
513 | ||
514 | enabled_pod1 = enabled_chan4 = FALSE; | |
515 | ||
516 | /* Note: On the DLM2000, CH4 and Logic are shared. */ | |
517 | /* TODO Handle non-DLM2000 models. */ | |
518 | for (l = channels; l; l = l->next) { | |
519 | ch = l->data; | |
520 | switch (ch->type) { | |
521 | case SR_CHANNEL_ANALOG: | |
522 | if (ch->index == 3) | |
523 | enabled_chan4 = TRUE; | |
524 | break; | |
525 | case SR_CHANNEL_LOGIC: | |
526 | enabled_pod1 = TRUE; | |
527 | break; | |
528 | default: | |
529 | return SR_ERR; | |
530 | } | |
531 | } | |
532 | ||
533 | if (enabled_pod1 && enabled_chan4) | |
534 | return SR_ERR; | |
535 | ||
536 | return SR_OK; | |
537 | } | |
538 | ||
695dc859 | 539 | static int dev_acquisition_start(const struct sr_dev_inst *sdi) |
8ab929d6 SA |
540 | { |
541 | GSList *l; | |
542 | gboolean digital_added; | |
543 | struct sr_channel *ch; | |
544 | struct dev_context *devc; | |
545 | struct sr_scpi_dev_inst *scpi; | |
546 | ||
8ab929d6 SA |
547 | scpi = sdi->conn; |
548 | devc = sdi->priv; | |
549 | digital_added = FALSE; | |
550 | ||
551 | g_slist_free(devc->enabled_channels); | |
552 | devc->enabled_channels = NULL; | |
553 | ||
554 | for (l = sdi->channels; l; l = l->next) { | |
555 | ch = l->data; | |
556 | if (!ch->enabled) | |
557 | continue; | |
558 | /* Only add a single digital channel. */ | |
559 | if (ch->type != SR_CHANNEL_LOGIC || !digital_added) { | |
560 | devc->enabled_channels = g_slist_append( | |
ac10a927 SA |
561 | devc->enabled_channels, ch); |
562 | if (ch->type == SR_CHANNEL_LOGIC) | |
563 | digital_added = TRUE; | |
8ab929d6 SA |
564 | } |
565 | } | |
566 | ||
567 | if (!devc->enabled_channels) | |
568 | return SR_ERR; | |
569 | ||
570 | if (dlm_check_channels(devc->enabled_channels) != SR_OK) { | |
571 | sr_err("Invalid channel configuration specified!"); | |
572 | return SR_ERR_NA; | |
573 | } | |
574 | ||
af3487ec SA |
575 | /* Request data for the first enabled channel. */ |
576 | devc->current_channel = devc->enabled_channels; | |
577 | dlm_channel_data_request(sdi); | |
578 | ||
0028d5a1 | 579 | sr_scpi_source_add(sdi->session, scpi, G_IO_IN, 5, |
8ab929d6 SA |
580 | dlm_data_receive, (void *)sdi); |
581 | ||
582 | return SR_OK; | |
583 | } | |
584 | ||
695dc859 | 585 | static int dev_acquisition_stop(struct sr_dev_inst *sdi) |
8ab929d6 SA |
586 | { |
587 | struct dev_context *devc; | |
8ab929d6 | 588 | |
bee2b016 | 589 | std_session_send_df_end(sdi); |
8ab929d6 | 590 | |
8ab929d6 SA |
591 | devc = sdi->priv; |
592 | ||
593 | devc->num_frames = 0; | |
594 | g_slist_free(devc->enabled_channels); | |
595 | devc->enabled_channels = NULL; | |
af3487ec SA |
596 | |
597 | sr_scpi_source_remove(sdi->session, sdi->conn); | |
8ab929d6 SA |
598 | |
599 | return SR_OK; | |
600 | } | |
10763937 | 601 | |
dd5c48a6 | 602 | static struct sr_dev_driver yokogawa_dlm_driver_info = { |
10763937 | 603 | .name = "yokogawa-dlm", |
ac10a927 | 604 | .longname = "Yokogawa DL/DLM", |
10763937 | 605 | .api_version = 1, |
c2fdcc25 | 606 | .init = std_init, |
700d6b64 | 607 | .cleanup = std_cleanup, |
8ab929d6 | 608 | .scan = scan, |
c01bf34c | 609 | .dev_list = std_dev_list, |
8ab929d6 SA |
610 | .dev_clear = dev_clear, |
611 | .config_get = config_get, | |
612 | .config_set = config_set, | |
c65a021c | 613 | .config_channel_set = config_channel_set, |
8ab929d6 SA |
614 | .config_list = config_list, |
615 | .dev_open = dev_open, | |
616 | .dev_close = dev_close, | |
617 | .dev_acquisition_start = dev_acquisition_start, | |
618 | .dev_acquisition_stop = dev_acquisition_stop, | |
41812aca | 619 | .context = NULL, |
10763937 | 620 | }; |
dd5c48a6 | 621 | SR_REGISTER_DEV_DRIVER(yokogawa_dlm_driver_info); |