2 * This file is part of the libsigrok project.
4 * Copyright (C) 2018 mhooijboer <marchelh@gmail.com>
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.
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.
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/>.
28 #include <libsigrok/libsigrok.h>
29 #include "libsigrok-internal.h"
33 static const uint32_t scanopts[] = {
38 static const uint32_t devopts[] = {
40 SR_CONF_LOGIC_ANALYZER,
41 SR_CONF_TIMEBASE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
42 SR_CONF_TRIGGER_SOURCE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
43 SR_CONF_TRIGGER_SLOPE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
44 SR_CONF_TRIGGER_LEVEL | SR_CONF_GET | SR_CONF_SET,
45 SR_CONF_HORIZ_TRIGGERPOS | SR_CONF_GET | SR_CONF_SET,
46 SR_CONF_NUM_HDIV | SR_CONF_GET | SR_CONF_LIST,
47 SR_CONF_SAMPLERATE | SR_CONF_GET,
48 SR_CONF_LIMIT_FRAMES | SR_CONF_GET | SR_CONF_SET,
49 SR_CONF_DATA_SOURCE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
50 SR_CONF_AVERAGING | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
51 SR_CONF_AVG_SAMPLES | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
54 static const uint32_t analog_devopts[] = {
55 SR_CONF_NUM_VDIV | SR_CONF_GET,
56 SR_CONF_VDIV | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
57 SR_CONF_TIMEBASE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
58 SR_CONF_COUPLING | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
59 SR_CONF_PROBE_FACTOR | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
60 SR_CONF_DATA_SOURCE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
63 static const uint64_t timebases[][2] = {
104 static const uint64_t vdivs[][2] = {
127 static const char *trigger_sources[] = {
128 "CH1", "CH2", "Ext", "Ext /5", "AC Line",
129 "D0", "D1", "D2", "D3", "D4", "D5", "D6", "D7",
130 "D8", "D9", "D10", "D11", "D12", "D13", "D14", "D15",
133 static const char *trigger_slopes[] = {
137 static const char *coupling[] = {
145 static const uint64_t probe_factor[] = {
146 1, 2, 5, 10, 20, 50, 100, 200, 500, 1000, 2000, 5000, 10000,
149 /* Do not change the order of entries. */
150 static const char *data_sources[] = {
169 /* short name, full name */
170 static const struct siglent_sds_vendor supported_vendors[] = {
171 [SIGLENT] = {"Siglent", "Siglent Technologies"},
174 #define VENDOR(x) &supported_vendors[x]
175 /* vendor, series, protocol, max timebase, min vdiv, number of horizontal divs,
176 * number of vertical divs, live waveform samples, memory buffer samples */
177 static const struct siglent_sds_series supported_series[] = {
178 [SDS1000CML] = {VENDOR(SIGLENT), "SDS1000CML", NON_SPO_MODEL,
179 { 50, 1 }, { 2, 1000 }, 18, 8, 1400363},
180 [SDS1000CNL] = {VENDOR(SIGLENT), "SDS1000CNL", NON_SPO_MODEL,
181 { 50, 1 }, { 2, 1000 }, 18, 8, 1400363},
182 [SDS1000DL] = {VENDOR(SIGLENT), "SDS1000DL", NON_SPO_MODEL,
183 { 50, 1 }, { 2, 1000 }, 18, 8, 1400363},
184 [SDS1000X] = {VENDOR(SIGLENT), "SDS1000X", SPO_MODEL,
185 { 50, 1 }, { 500, 100000 }, 14, 8, 14000363},
186 [SDS1000XP] = {VENDOR(SIGLENT), "SDS1000X+", SPO_MODEL,
187 { 50, 1 }, { 500, 100000 }, 14, 8, 14000363},
188 [SDS1000XE] = {VENDOR(SIGLENT), "SDS1000XE", SPO_MODEL,
189 { 50, 1 }, { 500, 100000 }, 14, 8, 14000363},
190 [SDS2000X] = {VENDOR(SIGLENT), "SDS2000X", SPO_MODEL,
191 { 50, 1 }, { 500, 100000 }, 14, 8, 14000363},
194 #define SERIES(x) &supported_series[x]
195 /* series, model, min timebase, analog channels, digital */
196 static const struct siglent_sds_model supported_models[] = {
197 { SERIES(SDS1000CML), "SDS1152CML", { 20, 1000000000 }, 2, false, 0 },
198 { SERIES(SDS1000CML), "SDS1102CML", { 10, 1000000000 }, 2, false, 0 },
199 { SERIES(SDS1000CML), "SDS1072CML", { 5, 1000000000 }, 2, false, 0 },
200 { SERIES(SDS1000CNL), "SDS1202CNL", { 20, 1000000000 }, 2, false, 0 },
201 { SERIES(SDS1000CNL), "SDS1102CNL", { 10, 1000000000 }, 2, false, 0 },
202 { SERIES(SDS1000CNL), "SDS1072CNL", { 5, 1000000000 }, 2, false, 0 },
203 { SERIES(SDS1000DL), "SDS1202DL", { 20, 1000000000 }, 2, false, 0 },
204 { SERIES(SDS1000DL), "SDS1102DL", { 10, 1000000000 }, 2, false, 0 },
205 { SERIES(SDS1000DL), "SDS1022DL", { 5, 1000000000 }, 2, false, 0 },
206 { SERIES(SDS1000DL), "SDS1052DL", { 5, 1000000000 }, 2, false, 0 },
207 { SERIES(SDS1000DL), "SDS1052DL+", { 5, 1000000000 }, 2, false, 0 },
208 { SERIES(SDS1000X), "SDS1102X", { 2, 1000000000 }, 2, false, 0 },
209 { SERIES(SDS1000XP), "SDS1102X+", { 2, 1000000000 }, 2, false, 0 },
210 { SERIES(SDS1000X), "SDS1202X", { 2, 1000000000 }, 2, false, 0 },
211 { SERIES(SDS1000XP), "SDS1202X+", { 2, 1000000000 }, 2, false, 0 },
212 { SERIES(SDS1000XE), "SDS1202X-E", { 1, 1000000000 }, 2, false, 0 },
213 { SERIES(SDS1000XE), "SDS1104X-E", { 1, 1000000000 }, 4, true, 16 },
214 { SERIES(SDS1000XE), "SDS1204X-E", { 1, 1000000000 }, 4, true, 16 },
215 { SERIES(SDS2000X), "SDS2072X", { 2, 1000000000 }, 2, false, 0 },
216 { SERIES(SDS2000X), "SDS2074X", { 2, 1000000000 }, 4, false, 0 },
217 { SERIES(SDS2000X), "SDS2102X", { 2, 1000000000 }, 2, false, 0 },
218 { SERIES(SDS2000X), "SDS2104X", { 2, 1000000000 }, 4, false, 0 },
219 { SERIES(SDS2000X), "SDS2202X", { 2, 1000000000 }, 2, false, 0 },
220 { SERIES(SDS2000X), "SDS2204X", { 2, 1000000000 }, 4, false, 0 },
221 { SERIES(SDS2000X), "SDS2302X", { 2, 1000000000 }, 2, false, 0 },
222 { SERIES(SDS2000X), "SDS2304X", { 2, 1000000000 }, 4, false, 0 },
225 SR_PRIV struct sr_dev_driver siglent_sds_driver_info;
227 static void clear_helper(void *priv)
229 struct dev_context *devc;
234 g_free(devc->analog_groups);
235 g_free(devc->enabled_channels);
238 static int dev_clear(const struct sr_dev_driver *di)
240 return std_dev_clear_with_callback(di, clear_helper);
243 static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi)
245 struct dev_context *devc;
246 struct sr_dev_inst *sdi;
247 struct sr_scpi_hw_info *hw_info;
248 struct sr_channel *ch;
250 const struct siglent_sds_model *model;
253 sr_dbg("Setting Communication Headers to off.");
254 if (sr_scpi_send(scpi, "CHDR OFF") != SR_OK)
257 if (sr_scpi_get_hw_id(scpi, &hw_info) != SR_OK) {
258 sr_info("Couldn't get IDN response, retrying.");
261 if (sr_scpi_get_hw_id(scpi, &hw_info) != SR_OK) {
262 sr_info("Couldn't get IDN response.");
268 for (i = 0; i < ARRAY_SIZE(supported_models); i++) {
269 if (!strcmp(hw_info->model, supported_models[i].name)) {
270 model = &supported_models[i];
276 sr_scpi_hw_info_free(hw_info);
280 sdi = g_malloc0(sizeof(struct sr_dev_inst));
281 sdi->vendor = g_strdup(model->series->vendor->name);
282 sdi->model = g_strdup(model->name);
283 sdi->version = g_strdup(hw_info->firmware_version);
285 sdi->driver = &siglent_sds_driver_info;
286 sdi->inst_type = SR_INST_SCPI;
287 sdi->serial_num = g_strdup(hw_info->serial_number);
288 devc = g_malloc0(sizeof(struct dev_context));
289 devc->limit_frames = 1;
292 sr_scpi_hw_info_free(hw_info);
294 devc->analog_groups = g_malloc0(sizeof(struct sr_channel_group *) *
295 model->analog_channels);
297 for (i = 0; i < model->analog_channels; i++) {
298 channel_name = g_strdup_printf("CH%d", i + 1);
299 ch = sr_channel_new(sdi, i, SR_CHANNEL_ANALOG, TRUE, channel_name);
301 devc->analog_groups[i] = g_malloc0(sizeof(struct sr_channel_group));
303 devc->analog_groups[i]->name = channel_name;
304 devc->analog_groups[i]->channels = g_slist_append(NULL, ch);
305 sdi->channel_groups = g_slist_append(sdi->channel_groups,
306 devc->analog_groups[i]);
309 if (devc->model->has_digital) {
310 devc->digital_group = g_malloc0(sizeof(struct sr_channel_group));
312 for (i = 0; i < ARRAY_SIZE(devc->digital_channels); i++) {
313 channel_name = g_strdup_printf("D%d", i);
314 ch = sr_channel_new(sdi, i, SR_CHANNEL_LOGIC, TRUE, channel_name);
315 g_free(channel_name);
316 devc->digital_group->channels = g_slist_append(
317 devc->digital_group->channels, ch);
319 devc->digital_group->name = g_strdup("LA");
320 sdi->channel_groups = g_slist_append(sdi->channel_groups,
321 devc->digital_group);
324 for (i = 0; i < ARRAY_SIZE(timebases); i++) {
325 if (!memcmp(&devc->model->min_timebase, &timebases[i], sizeof(uint64_t[2])))
326 devc->timebases = &timebases[i];
328 if (!memcmp(&devc->model->series->max_timebase, &timebases[i], sizeof(uint64_t[2])))
329 devc->num_timebases = &timebases[i] - devc->timebases + 1;
332 for (i = 0; i < ARRAY_SIZE(vdivs); i++) {
333 devc->vdivs = &vdivs[i];
334 if (!memcmp(&devc->model->series->min_vdiv,
335 &vdivs[i], sizeof(uint64_t[2]))) {
336 devc->vdivs = &vdivs[i];
337 devc->num_vdivs = ARRAY_SIZE(vdivs) - i;
342 devc->buffer = g_malloc(devc->model->series->buffer_samples);
343 sr_dbg("Setting device context buffer size: %i.", devc->model->series->buffer_samples);
344 devc->data = g_malloc(devc->model->series->buffer_samples * sizeof(float));
346 devc->data_source = DATA_SOURCE_SCREEN;
353 static GSList *scan(struct sr_dev_driver *di, GSList *options)
355 /* TODO: Implement RPC call for LXI device discovery. */
356 return sr_scpi_scan(di->context, options, probe_device);
359 static int dev_open(struct sr_dev_inst *sdi)
362 struct sr_scpi_dev_inst *scpi = sdi->conn;
364 if ((ret = sr_scpi_open(scpi)) < 0) {
365 sr_err("Failed to open SCPI device: %s.", sr_strerror(ret));
369 if ((ret = siglent_sds_get_dev_cfg(sdi)) < 0) {
370 sr_err("Failed to get device config: %s.", sr_strerror(ret));
377 static int dev_close(struct sr_dev_inst *sdi)
379 return sr_scpi_close(sdi->conn);
382 static int config_get(uint32_t key, GVariant **data,
383 const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
385 struct dev_context *devc;
386 struct sr_channel *ch;
388 int analog_channel = -1;
389 float smallest_diff = INFINITY;
398 /* If a channel group is specified, it must be a valid one. */
399 if (cg && !g_slist_find(sdi->channel_groups, cg)) {
400 sr_err("Invalid channel group specified.");
405 ch = g_slist_nth_data(cg->channels, 0);
408 if (ch->type == SR_CHANNEL_ANALOG) {
409 if (ch->name[2] < '1' || ch->name[2] > '4')
411 analog_channel = ch->name[2] - '1';
416 case SR_CONF_NUM_HDIV:
417 *data = g_variant_new_int32(devc->model->series->num_horizontal_divs);
419 case SR_CONF_NUM_VDIV:
420 *data = g_variant_new_int32(devc->num_vdivs);
422 case SR_CONF_LIMIT_FRAMES:
423 *data = g_variant_new_uint64(devc->limit_frames);
425 case SR_CONF_DATA_SOURCE:
426 if (devc->data_source == DATA_SOURCE_SCREEN)
427 *data = g_variant_new_string("Screen");
428 else if (devc->data_source == DATA_SOURCE_HISTORY)
429 *data = g_variant_new_string("History");
431 case SR_CONF_SAMPLERATE:
432 siglent_sds_get_dev_cfg_horizontal(sdi);
433 *data = g_variant_new_uint64(devc->samplerate);
435 case SR_CONF_TRIGGER_SOURCE:
436 if (!strcmp(devc->trigger_source, "ACL"))
438 else if (!strcmp(devc->trigger_source, "CHAN1"))
440 else if (!strcmp(devc->trigger_source, "CHAN2"))
443 tmp_str = devc->trigger_source;
444 *data = g_variant_new_string(tmp_str);
446 case SR_CONF_TRIGGER_SLOPE:
447 if (!strncmp(devc->trigger_slope, "POS", 3)) {
449 } else if (!strncmp(devc->trigger_slope, "NEG", 3)) {
452 sr_dbg("Unknown trigger slope: '%s'.", devc->trigger_slope);
455 *data = g_variant_new_string(tmp_str);
457 case SR_CONF_TRIGGER_LEVEL:
458 *data = g_variant_new_double(devc->trigger_level);
460 case SR_CONF_HORIZ_TRIGGERPOS:
461 *data = g_variant_new_double(devc->horiz_triggerpos);
463 case SR_CONF_TIMEBASE:
464 for (i = 0; i < devc->num_timebases; i++) {
467 tb = (float)devc->timebases[i][0] / devc->timebases[i][1];
468 diff = fabs(devc->timebase - tb);
469 if (diff < smallest_diff) {
470 smallest_diff = diff;
475 sr_dbg("Negative timebase index: %d.", idx);
478 *data = g_variant_new("(tt)", devc->timebases[idx][0],
479 devc->timebases[idx][1]);
482 if (analog_channel < 0) {
483 sr_dbg("Negative analog channel: %d.", analog_channel);
486 for (i = 0; i < ARRAY_SIZE(vdivs); i++) {
489 vdiv = (float)vdivs[i][0] / vdivs[i][1];
490 diff = fabsf(devc->vdiv[analog_channel] - vdiv);
491 if (diff < smallest_diff) {
492 smallest_diff = diff;
497 sr_dbg("Negative vdiv index: %d.", idx);
500 *data = g_variant_new("(tt)", vdivs[idx][0], vdivs[idx][1]);
502 case SR_CONF_COUPLING:
503 if (analog_channel < 0) {
504 sr_dbg("Negative analog channel: %d.", analog_channel);
507 *data = g_variant_new_string(devc->coupling[analog_channel]);
509 case SR_CONF_PROBE_FACTOR:
510 if (analog_channel < 0) {
511 sr_dbg("Negative analog channel: %d.", analog_channel);
514 *data = g_variant_new_uint64(devc->attenuation[analog_channel]);
523 static int config_set(uint32_t key, GVariant *data,
524 const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
526 struct dev_context *devc;
536 /* If a channel group is specified, it must be a valid one. */
537 if (cg && !g_slist_find(sdi->channel_groups, cg)) {
538 sr_err("Invalid channel group specified.");
544 case SR_CONF_LIMIT_FRAMES:
545 devc->limit_frames = g_variant_get_uint64(data);
547 case SR_CONF_TRIGGER_SLOPE:
548 if ((idx = std_str_idx(data, ARRAY_AND_SIZE(trigger_slopes))) < 0)
550 g_free(devc->trigger_slope);
551 devc->trigger_slope = g_strdup((trigger_slopes[idx][0] == 'r') ? "POS" : "NEG");
552 ret = siglent_sds_config_set(sdi, "%s:TRSL %s",
553 devc->trigger_source, devc->trigger_slope);
555 case SR_CONF_HORIZ_TRIGGERPOS:
556 t_dbl = g_variant_get_double(data);
557 if (t_dbl < 0.0 || t_dbl > 1.0) {
558 sr_err("Invalid horiz. trigger position: %g.", t_dbl);
561 devc->horiz_triggerpos = t_dbl;
562 /* We have the trigger offset as a percentage of the frame, but
563 * need to express this in seconds. */
564 t_dbl = -(devc->horiz_triggerpos - 0.5) * devc->timebase * devc->num_timebases;
565 g_ascii_formatd(buffer, sizeof(buffer), "%.6f", t_dbl);
566 ret = siglent_sds_config_set(sdi, ":TIM:OFFS %s", buffer);
568 case SR_CONF_TRIGGER_LEVEL:
569 t_dbl = g_variant_get_double(data);
570 g_ascii_formatd(buffer, sizeof(buffer), "%.3f", t_dbl);
571 ret = siglent_sds_config_set(sdi, ":TRIG:EDGE:LEV %s", buffer);
573 devc->trigger_level = t_dbl;
575 case SR_CONF_TIMEBASE:
576 g_variant_get(data, "(tt)", &p, &q);
577 for (i = 0; i < devc->num_timebases; i++) {
579 if (devc->timebases[i][0] == p && devc->timebases[i][1] == q) {
581 devc->timebase = (float) p / q;
584 cmd = g_strdup_printf("%" PRIu64 "S", p);
587 cmd = g_strdup_printf("%" PRIu64 "MS", p);
590 cmd = g_strdup_printf("%" PRIu64 "US", p);
593 cmd = g_strdup_printf("%" PRIu64 "NS", p);
596 sr_dbg("Setting device timebase: TDIV %s.", cmd);
597 ret = siglent_sds_config_set(sdi, "TDIV %s", cmd);
601 if (i == devc->num_timebases) {
602 sr_err("Invalid timebase index: %d.", i);
606 case SR_CONF_TRIGGER_SOURCE:
607 tmp_str = g_variant_get_string(data, NULL);
608 for (i = 0; i < ARRAY_SIZE(trigger_sources); i++) {
609 if (!strcmp(trigger_sources[i], tmp_str)) {
610 g_free(devc->trigger_source);
611 devc->trigger_source = g_strdup(trigger_sources[i]);
612 if (!strcmp(devc->trigger_source, "AC Line"))
614 else if (!strcmp(devc->trigger_source, "CH1"))
616 else if (!strcmp(devc->trigger_source, "CH2"))
618 else if (!strcmp(devc->trigger_source, "CH3"))
620 else if (!strcmp(devc->trigger_source, "CH4"))
622 else if (!strcmp(devc->trigger_source, "Ext"))
624 else if (!strcmp(devc->trigger_source, "Ext /5"))
627 tmp_str = (char *) devc->trigger_source;
628 ret = siglent_sds_config_set(sdi, "TRSE EDGE,SR,%s,OFF", tmp_str);
632 if (i == ARRAY_SIZE(trigger_sources)) {
633 sr_err("Invalid trigger source index: %d.", i);
639 return SR_ERR_CHANNEL_GROUP;
640 g_variant_get(data, "(tt)", &p, &q);
641 for (i = 0; i < devc->model->analog_channels; i++) {
643 if (cg == devc->analog_groups[i]) {
644 for (j = 0; j < ARRAY_SIZE(vdivs); j++) {
645 if (vdivs[j][0] != p || vdivs[j][1] != q)
650 cmd = g_strdup_printf("%" PRIu64 "V", p);
653 cmd = g_strdup_printf("%" PRIu64 "MV", p);
656 cmd = g_strdup_printf("%" PRIu64 "UV", p);
659 return siglent_sds_config_set(sdi, "C%d:VDIV %s", i + 1, cmd);
661 sr_err("Invalid vdiv index: %d.", j);
665 sr_dbg("Didn't set vdiv, unknown channel(group).");
667 case SR_CONF_COUPLING:
669 return SR_ERR_CHANNEL_GROUP;
670 tmp_str = g_variant_get_string(data, NULL);
671 for (i = 0; i < devc->model->analog_channels; i++) {
673 if (cg == devc->analog_groups[i]) {
674 for (j = 0; j < ARRAY_SIZE(coupling); j++) {
675 if (!strcmp(tmp_str, coupling[j])) {
676 g_free(devc->coupling[i]);
677 devc->coupling[i] = g_strdup(coupling[j]);
678 strncpy(cmd, devc->coupling[i], 3);
680 return siglent_sds_config_set(sdi, "C%d:CPL %s", i + 1, cmd);
683 sr_err("Invalid coupling index: %d.", j);
687 sr_dbg("Didn't set coupling, unknown channel(group).");
689 case SR_CONF_PROBE_FACTOR:
691 return SR_ERR_CHANNEL_GROUP;
692 p = g_variant_get_uint64(data);
693 for (i = 0; i < devc->model->analog_channels; i++) {
694 if (cg == devc->analog_groups[i]) {
695 for (j = 0; j < ARRAY_SIZE(probe_factor); j++) {
696 if (p == probe_factor[j]) {
697 devc->attenuation[i] = p;
698 ret = siglent_sds_config_set(sdi, "C%d:ATTN %" PRIu64, i + 1, p);
700 siglent_sds_get_dev_cfg_vertical(sdi);
704 sr_err("Invalid probe factor: %" PRIu64 ".", p);
708 sr_dbg("Didn't set probe factor, unknown channel(group).");
710 case SR_CONF_DATA_SOURCE:
711 tmp_str = g_variant_get_string(data, NULL);
712 if (!strcmp(tmp_str, "Display"))
713 devc->data_source = DATA_SOURCE_SCREEN;
714 else if (devc->model->series->protocol >= SPO_MODEL
715 && !strcmp(tmp_str, "History"))
716 devc->data_source = DATA_SOURCE_HISTORY;
718 sr_err("Unknown data source: '%s'.", tmp_str);
722 case SR_CONF_SAMPLERATE:
723 siglent_sds_get_dev_cfg_horizontal(sdi);
724 data = g_variant_new_uint64(devc->samplerate);
733 static int config_list(uint32_t key, GVariant **data,
734 const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
736 GVariant *tuple, *rational[2];
739 struct dev_context *devc = NULL;
741 if (key == SR_CONF_SCAN_OPTIONS) {
742 *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
743 scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
745 } else if (key == SR_CONF_DEVICE_OPTIONS && !cg) {
746 *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
747 devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
751 /* Every other option requires a valid device instance. */
756 /* If a channel group is specified, it must be a valid one. */
757 if (cg && !g_slist_find(sdi->channel_groups, cg)) {
758 sr_err("Invalid channel group specified.");
763 case SR_CONF_DEVICE_OPTIONS:
765 return SR_ERR_CHANNEL_GROUP;
766 if (cg == devc->digital_group) {
767 *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
768 NULL, 0, sizeof(uint32_t));
771 for (i = 0; i < devc->model->analog_channels; i++) {
772 if (cg == devc->analog_groups[i]) {
773 *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
774 analog_devopts, ARRAY_SIZE(analog_devopts), sizeof(uint32_t));
781 case SR_CONF_COUPLING:
783 return SR_ERR_CHANNEL_GROUP;
784 *data = g_variant_new_strv(coupling, ARRAY_SIZE(coupling));
786 case SR_CONF_PROBE_FACTOR:
788 return SR_ERR_CHANNEL_GROUP;
789 *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT64,
790 probe_factor, ARRAY_SIZE(probe_factor), sizeof(uint64_t));
794 /* Can't know this until we have the exact model. */
797 return SR_ERR_CHANNEL_GROUP;
798 g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
799 for (i = 0; i < devc->num_vdivs; i++) {
800 rational[0] = g_variant_new_uint64(devc->vdivs[i][0]);
801 rational[1] = g_variant_new_uint64(devc->vdivs[i][1]);
802 tuple = g_variant_new_tuple(rational, 2);
803 g_variant_builder_add_value(&gvb, tuple);
805 *data = g_variant_builder_end(&gvb);
807 case SR_CONF_TIMEBASE:
809 /* Can't know this until we have the exact model. */
811 if (devc->num_timebases <= 0)
813 g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
814 for (i = 0; i < devc->num_timebases; i++) {
815 rational[0] = g_variant_new_uint64(devc->timebases[i][0]);
816 rational[1] = g_variant_new_uint64(devc->timebases[i][1]);
817 tuple = g_variant_new_tuple(rational, 2);
818 g_variant_builder_add_value(&gvb, tuple);
820 *data = g_variant_builder_end(&gvb);
822 case SR_CONF_TRIGGER_SOURCE:
824 /* Can't know this until we have the exact model. */
826 *data = g_variant_new_strv(trigger_sources,
827 devc->model->has_digital ? ARRAY_SIZE(trigger_sources) : 5);
829 case SR_CONF_TRIGGER_SLOPE:
830 *data = g_variant_new_strv(trigger_slopes, ARRAY_SIZE(trigger_slopes));
832 case SR_CONF_DATA_SOURCE:
834 /* Can't know this until we have the exact model. */
836 switch (devc->model->series->protocol) {
837 /* TODO: Check what must be done here for the data source buffer sizes. */
839 *data = g_variant_new_strv(data_sources, ARRAY_SIZE(data_sources) - 1);
842 *data = g_variant_new_strv(data_sources, ARRAY_SIZE(data_sources));
846 case SR_CONF_NUM_HDIV:
847 *data = g_variant_new_int32(devc->model->series->num_horizontal_divs);
849 case SR_CONF_AVERAGING:
850 /* TODO: Implement averaging. */
859 static int dev_acquisition_start(const struct sr_dev_inst *sdi)
861 struct sr_scpi_dev_inst *scpi;
862 struct dev_context *devc;
863 struct sr_channel *ch;
864 struct sr_datafeed_packet packet;
865 gboolean some_digital;
871 devc->num_frames = 0;
872 some_digital = FALSE;
875 * Check if there are any logic channels enabled, if so then enable
876 * the MSO, otherwise skip the digital channel setup. Enable and
877 * disable channels on the device is very slow and it is faster when
878 * checked in a small loop without the actual actions.
880 for (d = sdi->channels; d; d = d->next) {
882 if (ch->type == SR_CHANNEL_LOGIC && ch->enabled)
886 for (l = sdi->channels; l; l = l->next) {
888 if (ch->type == SR_CHANNEL_ANALOG) {
890 devc->enabled_channels = g_slist_append(
891 devc->enabled_channels, ch);
892 if (ch->enabled != devc->analog_channels[ch->index]) {
893 /* Enabled channel is currently disabled, or vice versa. */
894 if (siglent_sds_config_set(sdi, "C%d:TRA %s", ch->index + 1,
895 ch->enabled ? "ON" : "OFF") != SR_OK)
897 devc->analog_channels[ch->index] = ch->enabled;
899 } else if (ch->type == SR_CHANNEL_LOGIC && some_digital) {
901 /* Turn on LA module if currently off and digital channels are enabled. */
902 if (!devc->la_enabled) {
903 if (siglent_sds_config_set(sdi, "DGST ON") != SR_OK)
906 devc->la_enabled = TRUE;
908 devc->enabled_channels = g_slist_append(
909 devc->enabled_channels, ch);
911 /* Enabled channel is currently disabled, or vice versa. */
912 if (siglent_sds_config_set(sdi, "D%d:DGCH %s", ch->index,
913 ch->enabled ? "ON" : "OFF") != SR_OK)
915 /* Slowing the command sequence down to let the device handle it. */
917 devc->digital_channels[ch->index] = ch->enabled;
920 if (!devc->enabled_channels)
922 /* Turn off LA module if on and no digital channels selected. */
923 if (devc->la_enabled && !some_digital)
924 if (siglent_sds_config_set(sdi, "DGST OFF") != SR_OK) {
925 devc->la_enabled = FALSE;
930 // devc->analog_frame_size = devc->model->series->buffer_samples;
931 // devc->digital_frame_size = devc->model->series->buffer_samples;
933 switch (devc->model->series->protocol) {
935 if (siglent_sds_config_set(sdi, "WFSU SP,0,TYPE,1") != SR_OK)
937 if (siglent_sds_config_set(sdi, "ACQW SAMPLING") != SR_OK)
941 /* TODO: Implement CML/CNL/DL models. */
942 if (siglent_sds_config_set(sdi, "WFSU SP,0,TYPE,1") != SR_OK)
944 if (siglent_sds_config_set(sdi, "ACQW SAMPLING") != SR_OK)
951 sr_scpi_source_add(sdi->session, scpi, G_IO_IN, 50,
952 siglent_sds_receive, (void *) sdi);
954 std_session_send_df_header(sdi);
956 devc->channel_entry = devc->enabled_channels;
958 if (siglent_sds_capture_start(sdi) != SR_OK)
961 /* Start of first frame. */
962 packet.type = SR_DF_FRAME_BEGIN;
963 sr_session_send(sdi, &packet);
968 static int dev_acquisition_stop(struct sr_dev_inst *sdi)
970 struct dev_context *devc;
971 struct sr_scpi_dev_inst *scpi;
975 std_session_send_df_end(sdi);
977 g_slist_free(devc->enabled_channels);
978 devc->enabled_channels = NULL;
980 sr_scpi_source_remove(sdi->session, scpi);
985 SR_PRIV struct sr_dev_driver siglent_sds_driver_info = {
986 .name = "siglent-sds",
987 .longname = "Siglent SDS1000/SDS2000",
990 .cleanup = std_cleanup,
992 .dev_list = std_dev_list,
993 .dev_clear = dev_clear,
994 .config_get = config_get,
995 .config_set = config_set,
996 .config_list = config_list,
997 .dev_open = dev_open,
998 .dev_close = dev_close,
999 .dev_acquisition_start = dev_acquisition_start,
1000 .dev_acquisition_stop = dev_acquisition_stop,
1004 SR_REGISTER_DEV_DRIVER(siglent_sds_driver_info);