2 * This file is part of the libsigrok project.
4 * Copyright (C) 2015 Martin Lederhilger <martin.lederhilger@gmx.at>
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/>.
23 static const uint32_t scanopts[] = {
28 static const uint32_t devopts[] = {
30 SR_CONF_LIMIT_FRAMES | SR_CONF_SET,
31 SR_CONF_SAMPLERATE | SR_CONF_GET,
34 static struct sr_dev_driver gwinstek_gds_800_driver_info;
36 static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi)
38 struct dev_context *devc;
39 struct sr_dev_inst *sdi;
40 struct sr_scpi_hw_info *hw_info;
41 struct sr_channel_group *cg;
43 if (sr_scpi_get_hw_id(scpi, &hw_info) != SR_OK) {
44 sr_info("Couldn't get IDN response.");
48 if (strcmp(hw_info->manufacturer, "GW") != 0 ||
49 strncmp(hw_info->model, "GDS-8", 5) != 0) {
50 sr_scpi_hw_info_free(hw_info);
54 sdi = g_malloc0(sizeof(struct sr_dev_inst));
55 sdi->vendor = g_strdup(hw_info->manufacturer);
56 sdi->model = g_strdup(hw_info->model);
57 sdi->version = g_strdup(hw_info->firmware_version);
59 sdi->driver = &gwinstek_gds_800_driver_info;
60 sdi->inst_type = SR_INST_SCPI;
61 sdi->serial_num = g_strdup(hw_info->serial_number);
63 sdi->channel_groups = NULL;
65 sr_scpi_hw_info_free(hw_info);
67 devc = g_malloc0(sizeof(struct dev_context));
68 devc->frame_limit = 1;
69 devc->sample_rate = 0.0;
70 devc->df_started = FALSE;
73 sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "CH1");
74 sr_channel_new(sdi, 1, SR_CHANNEL_ANALOG, TRUE, "CH2");
76 cg = g_malloc0(sizeof(struct sr_channel_group));
77 cg->name = g_strdup("");
78 cg->channels = g_slist_append(cg->channels, g_slist_nth_data(sdi->channels, 0));
79 cg->channels = g_slist_append(cg->channels, g_slist_nth_data(sdi->channels, 1));
81 sdi->channel_groups = g_slist_append(NULL, cg);
86 static GSList *scan(struct sr_dev_driver *di, GSList *options)
88 return sr_scpi_scan(di->context, options, probe_device);
91 static int dev_open(struct sr_dev_inst *sdi)
94 struct sr_scpi_dev_inst *scpi = sdi->conn;
96 if ((ret = sr_scpi_open(scpi)) < 0) {
97 sr_err("Failed to open SCPI device: %s.", sr_strerror(ret));
104 static int dev_close(struct sr_dev_inst *sdi)
106 struct sr_scpi_dev_inst *scpi;
113 return sr_scpi_close(scpi);
116 static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
117 const struct sr_channel_group *cg)
119 struct dev_context *devc;
129 case SR_CONF_SAMPLERATE:
130 *data = g_variant_new_uint64(devc->sample_rate);
139 static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi,
140 const struct sr_channel_group *cg)
142 struct dev_context *devc;
152 case SR_CONF_LIMIT_FRAMES:
153 devc->frame_limit = g_variant_get_uint64(data);
162 static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
163 const struct sr_channel_group *cg)
169 case SR_CONF_SCAN_OPTIONS:
170 *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
171 scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
173 case SR_CONF_DEVICE_OPTIONS:
174 *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
175 devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
184 static int dev_acquisition_start(const struct sr_dev_inst *sdi)
186 struct sr_scpi_dev_inst *scpi;
187 struct dev_context *devc;
192 devc->state = START_ACQUISITION;
193 devc->cur_acq_frame = 0;
195 sr_scpi_source_add(sdi->session, scpi, G_IO_IN, 50,
196 gwinstek_gds_800_receive_data, (void *)sdi);
201 static int dev_acquisition_stop(struct sr_dev_inst *sdi)
203 struct sr_scpi_dev_inst *scpi;
204 struct dev_context *devc;
205 struct sr_datafeed_packet packet;
210 if (devc->df_started) {
211 packet.type = SR_DF_FRAME_END;
212 sr_session_send(sdi, &packet);
214 std_session_send_df_end(sdi);
216 devc->df_started = FALSE;
219 sr_scpi_source_remove(sdi->session, scpi);
224 static struct sr_dev_driver gwinstek_gds_800_driver_info = {
225 .name = "gwinstek-gds-800",
226 .longname = "GW Instek GDS-800 series",
229 .cleanup = std_cleanup,
231 .dev_list = std_dev_list,
232 .dev_clear = std_dev_clear,
233 .config_get = config_get,
234 .config_set = config_set,
235 .config_list = config_list,
236 .dev_open = dev_open,
237 .dev_close = dev_close,
238 .dev_acquisition_start = dev_acquisition_start,
239 .dev_acquisition_stop = dev_acquisition_stop,
242 SR_REGISTER_DEV_DRIVER(gwinstek_gds_800_driver_info);