]>
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 | ||
373e92a4 | 65 | static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi) |
8ab929d6 SA |
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 | { |
373e92a4 | 120 | return sr_scpi_scan(di->context, options, probe_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 | 164 | { |
329733d9 | 165 | const struct scope_config *model; |
8ab929d6 SA |
166 | |
167 | model = devc->model_config; | |
168 | ||
169 | if (!cg) | |
170 | return CG_NONE; | |
171 | ||
fcd6a8bd UH |
172 | if (std_cg_idx(cg, devc->analog_groups, model->analog_channels) >= 0) |
173 | return CG_ANALOG; | |
8ab929d6 | 174 | |
fcd6a8bd UH |
175 | if (std_cg_idx(cg, devc->digital_groups, model->pods) >= 0) |
176 | return CG_DIGITAL; | |
8ab929d6 SA |
177 | |
178 | sr_err("Invalid channel group specified."); | |
fcd6a8bd | 179 | |
8ab929d6 SA |
180 | return CG_INVALID; |
181 | } | |
182 | ||
dd7a72ea UH |
183 | static int config_get(uint32_t key, GVariant **data, |
184 | const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) | |
8ab929d6 | 185 | { |
fcd6a8bd | 186 | int ret, cg_type, idx; |
8ab929d6 | 187 | struct dev_context *devc; |
329733d9 | 188 | const struct scope_config *model; |
8ab929d6 SA |
189 | struct scope_state *state; |
190 | ||
709468ba | 191 | if (!sdi) |
8ab929d6 SA |
192 | return SR_ERR_ARG; |
193 | ||
709468ba UH |
194 | devc = sdi->priv; |
195 | ||
8ab929d6 SA |
196 | if ((cg_type = check_channel_group(devc, cg)) == CG_INVALID) |
197 | return SR_ERR; | |
198 | ||
8ab929d6 SA |
199 | model = devc->model_config; |
200 | state = devc->model_state; | |
201 | ||
202 | switch (key) { | |
bf622e6d | 203 | case SR_CONF_NUM_HDIV: |
8ab929d6 SA |
204 | *data = g_variant_new_int32(model->num_xdivs); |
205 | ret = SR_OK; | |
206 | break; | |
207 | case SR_CONF_TIMEBASE: | |
208 | *data = g_variant_new("(tt)", | |
f3c60fb6 SA |
209 | dlm_timebases[state->timebase][0], |
210 | dlm_timebases[state->timebase][1]); | |
8ab929d6 SA |
211 | ret = SR_OK; |
212 | break; | |
213 | case SR_CONF_NUM_VDIV: | |
214 | if (cg_type == CG_NONE) { | |
8ab929d6 SA |
215 | return SR_ERR_CHANNEL_GROUP; |
216 | } else if (cg_type == CG_ANALOG) { | |
217 | *data = g_variant_new_int32(model->num_ydivs); | |
218 | ret = SR_OK; | |
219 | break; | |
220 | } else { | |
221 | ret = SR_ERR_NA; | |
222 | } | |
223 | break; | |
224 | case SR_CONF_VDIV: | |
225 | ret = SR_ERR_NA; | |
226 | if (cg_type == CG_NONE) { | |
8ab929d6 SA |
227 | return SR_ERR_CHANNEL_GROUP; |
228 | } else if (cg_type != CG_ANALOG) | |
229 | break; | |
fcd6a8bd UH |
230 | if ((idx = std_cg_idx(cg, devc->analog_groups, model->analog_channels)) < 0) |
231 | return SR_ERR_ARG; | |
232 | *data = g_variant_new("(tt)", | |
233 | dlm_vdivs[state->analog_states[idx].vdiv][0], | |
234 | dlm_vdivs[state->analog_states[idx].vdiv][1]); | |
235 | ret = SR_OK; | |
8ab929d6 SA |
236 | break; |
237 | case SR_CONF_TRIGGER_SOURCE: | |
238 | *data = g_variant_new_string((*model->trigger_sources)[state->trigger_source]); | |
239 | ret = SR_OK; | |
240 | break; | |
241 | case SR_CONF_TRIGGER_SLOPE: | |
f3c60fb6 | 242 | *data = g_variant_new_string(dlm_trigger_slopes[state->trigger_slope]); |
8ab929d6 SA |
243 | ret = SR_OK; |
244 | break; | |
245 | case SR_CONF_HORIZ_TRIGGERPOS: | |
246 | *data = g_variant_new_double(state->horiz_triggerpos); | |
247 | ret = SR_OK; | |
248 | break; | |
249 | case SR_CONF_COUPLING: | |
250 | ret = SR_ERR_NA; | |
251 | if (cg_type == CG_NONE) { | |
8ab929d6 SA |
252 | return SR_ERR_CHANNEL_GROUP; |
253 | } else if (cg_type != CG_ANALOG) | |
254 | break; | |
fcd6a8bd UH |
255 | if ((idx = std_cg_idx(cg, devc->analog_groups, model->analog_channels)) < 0) |
256 | return SR_ERR_ARG; | |
257 | *data = g_variant_new_string((*model->coupling_options)[state->analog_states[idx].coupling]); | |
258 | ret = SR_OK; | |
8ab929d6 SA |
259 | break; |
260 | case SR_CONF_SAMPLERATE: | |
261 | *data = g_variant_new_uint64(state->sample_rate); | |
262 | ret = SR_OK; | |
263 | break; | |
264 | default: | |
265 | ret = SR_ERR_NA; | |
266 | } | |
267 | ||
268 | return ret; | |
269 | } | |
270 | ||
dd7a72ea UH |
271 | static int config_set(uint32_t key, GVariant *data, |
272 | const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) | |
8ab929d6 | 273 | { |
fcd6a8bd | 274 | int ret, cg_type, idx, j; |
8ab929d6 SA |
275 | char float_str[30]; |
276 | struct dev_context *devc; | |
329733d9 | 277 | const struct scope_config *model; |
8ab929d6 | 278 | struct scope_state *state; |
8ab929d6 SA |
279 | double tmp_d; |
280 | gboolean update_sample_rate; | |
281 | ||
282 | if (!sdi || !(devc = sdi->priv)) | |
283 | return SR_ERR_ARG; | |
284 | ||
285 | if ((cg_type = check_channel_group(devc, cg)) == CG_INVALID) | |
286 | return SR_ERR; | |
287 | ||
288 | model = devc->model_config; | |
289 | state = devc->model_state; | |
290 | update_sample_rate = FALSE; | |
291 | ||
292 | ret = SR_ERR_NA; | |
293 | ||
294 | switch (key) { | |
295 | case SR_CONF_LIMIT_FRAMES: | |
296 | devc->frame_limit = g_variant_get_uint64(data); | |
297 | ret = SR_OK; | |
298 | break; | |
299 | case SR_CONF_TRIGGER_SOURCE: | |
bd633efa UH |
300 | if ((idx = std_str_idx(data, *model->trigger_sources, model->num_trigger_sources)) < 0) |
301 | return SR_ERR_ARG; | |
302 | state->trigger_source = idx; | |
303 | /* TODO: A and B trigger support possible? */ | |
304 | ret = dlm_trigger_source_set(sdi->conn, (*model->trigger_sources)[idx]); | |
8ab929d6 SA |
305 | break; |
306 | case SR_CONF_VDIV: | |
87dc5410 | 307 | if (cg_type == CG_NONE) |
8ab929d6 | 308 | return SR_ERR_CHANNEL_GROUP; |
697fb6dd UH |
309 | if ((idx = std_u64_tuple_idx(data, ARRAY_AND_SIZE(dlm_vdivs))) < 0) |
310 | return SR_ERR_ARG; | |
fcd6a8bd UH |
311 | if ((j = std_cg_idx(cg, devc->analog_groups, model->analog_channels)) < 0) |
312 | return SR_ERR_ARG; | |
313 | state->analog_states[j].vdiv = idx; | |
314 | g_ascii_formatd(float_str, sizeof(float_str), | |
315 | "%E", (float) dlm_vdivs[idx][0] / dlm_vdivs[idx][1]); | |
316 | if (dlm_analog_chan_vdiv_set(sdi->conn, j + 1, float_str) != SR_OK || | |
317 | sr_scpi_get_opc(sdi->conn) != SR_OK) | |
318 | return SR_ERR; | |
697fb6dd | 319 | ret = SR_OK; |
8ab929d6 SA |
320 | break; |
321 | case SR_CONF_TIMEBASE: | |
697fb6dd UH |
322 | if ((idx = std_u64_tuple_idx(data, ARRAY_AND_SIZE(dlm_timebases))) < 0) |
323 | return SR_ERR_ARG; | |
324 | state->timebase = idx; | |
325 | g_ascii_formatd(float_str, sizeof(float_str), | |
326 | "%E", (float) dlm_timebases[idx][0] / dlm_timebases[idx][1]); | |
327 | ret = dlm_timebase_set(sdi->conn, float_str); | |
328 | update_sample_rate = TRUE; | |
8ab929d6 SA |
329 | break; |
330 | case SR_CONF_HORIZ_TRIGGERPOS: | |
331 | tmp_d = g_variant_get_double(data); | |
332 | ||
333 | /* TODO: Check if the calculation makes sense for the DLM. */ | |
334 | if (tmp_d < 0.0 || tmp_d > 1.0) | |
335 | return SR_ERR; | |
336 | ||
337 | state->horiz_triggerpos = tmp_d; | |
338 | tmp_d = -(tmp_d - 0.5) * | |
f3c60fb6 SA |
339 | ((double) dlm_timebases[state->timebase][0] / |
340 | dlm_timebases[state->timebase][1]) | |
ac10a927 | 341 | * model->num_xdivs; |
8ab929d6 SA |
342 | |
343 | g_ascii_formatd(float_str, sizeof(float_str), "%E", tmp_d); | |
344 | ret = dlm_horiz_trigger_pos_set(sdi->conn, float_str); | |
345 | break; | |
346 | case SR_CONF_TRIGGER_SLOPE: | |
bd633efa | 347 | if ((idx = std_str_idx(data, ARRAY_AND_SIZE(dlm_trigger_slopes))) < 0) |
8ab929d6 | 348 | return SR_ERR_ARG; |
8ab929d6 | 349 | /* Note: See dlm_trigger_slopes[] in protocol.c. */ |
bd633efa | 350 | state->trigger_slope = idx; |
8ab929d6 SA |
351 | ret = dlm_trigger_slope_set(sdi->conn, state->trigger_slope); |
352 | break; | |
353 | case SR_CONF_COUPLING: | |
87dc5410 | 354 | if (cg_type == CG_NONE) |
8ab929d6 | 355 | return SR_ERR_CHANNEL_GROUP; |
bd633efa UH |
356 | if ((idx = std_str_idx(data, *model->coupling_options, model->num_coupling_options)) < 0) |
357 | return SR_ERR_ARG; | |
fcd6a8bd UH |
358 | if ((j = std_cg_idx(cg, devc->analog_groups, model->analog_channels)) < 0) |
359 | return SR_ERR_ARG; | |
360 | state->analog_states[j].coupling = idx; | |
361 | if (dlm_analog_chan_coupl_set(sdi->conn, j + 1, (*model->coupling_options)[idx]) != SR_OK || | |
362 | sr_scpi_get_opc(sdi->conn) != SR_OK) | |
363 | return SR_ERR; | |
bd633efa | 364 | ret = SR_OK; |
8ab929d6 SA |
365 | break; |
366 | default: | |
367 | ret = SR_ERR_NA; | |
368 | break; | |
369 | } | |
370 | ||
371 | if (ret == SR_OK) | |
372 | ret = sr_scpi_get_opc(sdi->conn); | |
373 | ||
374 | if (ret == SR_OK && update_sample_rate) | |
375 | ret = dlm_sample_rate_query(sdi); | |
376 | ||
377 | return ret; | |
378 | } | |
379 | ||
c65a021c | 380 | static int config_channel_set(const struct sr_dev_inst *sdi, |
dd7a72ea | 381 | struct sr_channel *ch, unsigned int changes) |
c65a021c | 382 | { |
a9308652 | 383 | /* Currently we only handle SR_CHANNEL_SET_ENABLED. */ |
c65a021c SA |
384 | if (changes != SR_CHANNEL_SET_ENABLED) |
385 | return SR_ERR_NA; | |
386 | ||
387 | return dlm_channel_state_set(sdi, ch->index, ch->enabled); | |
388 | } | |
389 | ||
dd7a72ea UH |
390 | static int config_list(uint32_t key, GVariant **data, |
391 | const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) | |
8ab929d6 | 392 | { |
cf0280fa | 393 | int cg_type = CG_NONE; |
e66d1892 UH |
394 | struct dev_context *devc; |
395 | const struct scope_config *model; | |
f3c60fb6 | 396 | |
e66d1892 UH |
397 | devc = (sdi) ? sdi->priv : NULL; |
398 | model = (devc) ? devc->model_config : NULL; | |
f3c60fb6 | 399 | |
f3c60fb6 SA |
400 | if (!cg) { |
401 | switch (key) { | |
e66d1892 | 402 | case SR_CONF_SCAN_OPTIONS: |
f3c60fb6 | 403 | case SR_CONF_DEVICE_OPTIONS: |
4b25cbff | 404 | return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts); |
f3c60fb6 | 405 | case SR_CONF_TIMEBASE: |
58ffcf97 | 406 | *data = std_gvar_tuple_array(ARRAY_AND_SIZE(dlm_timebases)); |
f3c60fb6 SA |
407 | return SR_OK; |
408 | case SR_CONF_TRIGGER_SOURCE: | |
409 | if (!model) | |
410 | return SR_ERR_ARG; | |
692716f5 | 411 | *data = g_variant_new_strv(*model->trigger_sources, model->num_trigger_sources); |
f3c60fb6 SA |
412 | return SR_OK; |
413 | case SR_CONF_TRIGGER_SLOPE: | |
692716f5 | 414 | *data = g_variant_new_strv(ARRAY_AND_SIZE(dlm_trigger_slopes)); |
f3c60fb6 SA |
415 | return SR_OK; |
416 | case SR_CONF_NUM_HDIV: | |
49f49cb5 | 417 | *data = g_variant_new_uint32(model->num_xdivs); |
f3c60fb6 SA |
418 | return SR_OK; |
419 | default: | |
420 | return SR_ERR_NA; | |
421 | } | |
422 | } | |
423 | ||
424 | if ((cg_type = check_channel_group(devc, cg)) == CG_INVALID) | |
425 | return SR_ERR; | |
426 | ||
8ab929d6 | 427 | switch (key) { |
8ab929d6 | 428 | case SR_CONF_DEVICE_OPTIONS: |
105df674 | 429 | if (cg_type == CG_ANALOG) |
53012da6 | 430 | *data = std_gvar_array_u32(ARRAY_AND_SIZE(devopts_cg_analog)); |
105df674 | 431 | else if (cg_type == CG_DIGITAL) |
53012da6 | 432 | *data = std_gvar_array_u32(ARRAY_AND_SIZE(devopts_cg_digital)); |
105df674 UH |
433 | else |
434 | *data = std_gvar_array_u32(NULL, 0); | |
8ab929d6 SA |
435 | break; |
436 | case SR_CONF_COUPLING: | |
437 | if (cg_type == CG_NONE) | |
438 | return SR_ERR_CHANNEL_GROUP; | |
692716f5 | 439 | *data = g_variant_new_strv(*model->coupling_options, model->num_coupling_options); |
8ab929d6 | 440 | break; |
8ab929d6 SA |
441 | case SR_CONF_VDIV: |
442 | if (cg_type == CG_NONE) | |
443 | return SR_ERR_CHANNEL_GROUP; | |
58ffcf97 | 444 | *data = std_gvar_tuple_array(ARRAY_AND_SIZE(dlm_vdivs)); |
8ab929d6 SA |
445 | break; |
446 | default: | |
447 | return SR_ERR_NA; | |
448 | } | |
449 | ||
450 | return SR_OK; | |
451 | } | |
452 | ||
453 | static int dlm_check_channels(GSList *channels) | |
454 | { | |
455 | GSList *l; | |
456 | struct sr_channel *ch; | |
457 | gboolean enabled_pod1, enabled_chan4; | |
458 | ||
459 | enabled_pod1 = enabled_chan4 = FALSE; | |
460 | ||
461 | /* Note: On the DLM2000, CH4 and Logic are shared. */ | |
462 | /* TODO Handle non-DLM2000 models. */ | |
463 | for (l = channels; l; l = l->next) { | |
464 | ch = l->data; | |
465 | switch (ch->type) { | |
466 | case SR_CHANNEL_ANALOG: | |
467 | if (ch->index == 3) | |
468 | enabled_chan4 = TRUE; | |
469 | break; | |
470 | case SR_CHANNEL_LOGIC: | |
471 | enabled_pod1 = TRUE; | |
472 | break; | |
473 | default: | |
474 | return SR_ERR; | |
475 | } | |
476 | } | |
477 | ||
478 | if (enabled_pod1 && enabled_chan4) | |
479 | return SR_ERR; | |
480 | ||
481 | return SR_OK; | |
482 | } | |
483 | ||
695dc859 | 484 | static int dev_acquisition_start(const struct sr_dev_inst *sdi) |
8ab929d6 SA |
485 | { |
486 | GSList *l; | |
487 | gboolean digital_added; | |
488 | struct sr_channel *ch; | |
489 | struct dev_context *devc; | |
490 | struct sr_scpi_dev_inst *scpi; | |
491 | ||
8ab929d6 SA |
492 | scpi = sdi->conn; |
493 | devc = sdi->priv; | |
494 | digital_added = FALSE; | |
495 | ||
496 | g_slist_free(devc->enabled_channels); | |
497 | devc->enabled_channels = NULL; | |
498 | ||
499 | for (l = sdi->channels; l; l = l->next) { | |
500 | ch = l->data; | |
501 | if (!ch->enabled) | |
502 | continue; | |
503 | /* Only add a single digital channel. */ | |
504 | if (ch->type != SR_CHANNEL_LOGIC || !digital_added) { | |
505 | devc->enabled_channels = g_slist_append( | |
ac10a927 SA |
506 | devc->enabled_channels, ch); |
507 | if (ch->type == SR_CHANNEL_LOGIC) | |
508 | digital_added = TRUE; | |
8ab929d6 SA |
509 | } |
510 | } | |
511 | ||
512 | if (!devc->enabled_channels) | |
513 | return SR_ERR; | |
514 | ||
515 | if (dlm_check_channels(devc->enabled_channels) != SR_OK) { | |
516 | sr_err("Invalid channel configuration specified!"); | |
517 | return SR_ERR_NA; | |
518 | } | |
519 | ||
af3487ec SA |
520 | /* Request data for the first enabled channel. */ |
521 | devc->current_channel = devc->enabled_channels; | |
522 | dlm_channel_data_request(sdi); | |
523 | ||
0028d5a1 | 524 | sr_scpi_source_add(sdi->session, scpi, G_IO_IN, 5, |
8ab929d6 SA |
525 | dlm_data_receive, (void *)sdi); |
526 | ||
527 | return SR_OK; | |
528 | } | |
529 | ||
695dc859 | 530 | static int dev_acquisition_stop(struct sr_dev_inst *sdi) |
8ab929d6 SA |
531 | { |
532 | struct dev_context *devc; | |
8ab929d6 | 533 | |
bee2b016 | 534 | std_session_send_df_end(sdi); |
8ab929d6 | 535 | |
8ab929d6 SA |
536 | devc = sdi->priv; |
537 | ||
538 | devc->num_frames = 0; | |
539 | g_slist_free(devc->enabled_channels); | |
540 | devc->enabled_channels = NULL; | |
af3487ec SA |
541 | |
542 | sr_scpi_source_remove(sdi->session, sdi->conn); | |
8ab929d6 SA |
543 | |
544 | return SR_OK; | |
545 | } | |
10763937 | 546 | |
dd5c48a6 | 547 | static struct sr_dev_driver yokogawa_dlm_driver_info = { |
10763937 | 548 | .name = "yokogawa-dlm", |
ac10a927 | 549 | .longname = "Yokogawa DL/DLM", |
10763937 | 550 | .api_version = 1, |
c2fdcc25 | 551 | .init = std_init, |
700d6b64 | 552 | .cleanup = std_cleanup, |
8ab929d6 | 553 | .scan = scan, |
c01bf34c | 554 | .dev_list = std_dev_list, |
8ab929d6 SA |
555 | .dev_clear = dev_clear, |
556 | .config_get = config_get, | |
557 | .config_set = config_set, | |
c65a021c | 558 | .config_channel_set = config_channel_set, |
8ab929d6 SA |
559 | .config_list = config_list, |
560 | .dev_open = dev_open, | |
561 | .dev_close = dev_close, | |
562 | .dev_acquisition_start = dev_acquisition_start, | |
563 | .dev_acquisition_stop = dev_acquisition_stop, | |
41812aca | 564 | .context = NULL, |
10763937 | 565 | }; |
dd5c48a6 | 566 | SR_REGISTER_DEV_DRIVER(yokogawa_dlm_driver_info); |