]>
Commit | Line | Data |
---|---|---|
7c198f96 ML |
1 | /* |
2 | * This file is part of the libsigrok project. | |
3 | * | |
4 | * Copyright (C) 2015 Martin Lederhilger <martin.lederhilger@gmx.at> | |
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 | ||
b11afbb1 | 20 | #include <string.h> |
7c198f96 ML |
21 | #include "protocol.h" |
22 | ||
b11afbb1 ML |
23 | static const uint32_t scanopts[] = { |
24 | SR_CONF_CONN, | |
25 | SR_CONF_SERIALCOMM, | |
26 | }; | |
27 | ||
28 | static const uint32_t devopts[] = { | |
29 | SR_CONF_OSCILLOSCOPE, | |
30 | SR_CONF_LIMIT_FRAMES | SR_CONF_SET, | |
31 | SR_CONF_SAMPLERATE | SR_CONF_GET, | |
32 | }; | |
33 | ||
dd5c48a6 | 34 | static struct sr_dev_driver gwinstek_gds_800_driver_info; |
7c198f96 | 35 | |
b11afbb1 | 36 | static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi) |
7c198f96 | 37 | { |
b11afbb1 ML |
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; | |
42 | ||
43 | if (sr_scpi_get_hw_id(scpi, &hw_info) != SR_OK) { | |
44 | sr_info("Couldn't get IDN response."); | |
45 | return NULL; | |
46 | } | |
7c198f96 | 47 | |
b11afbb1 ML |
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); | |
51 | return NULL; | |
52 | } | |
7c198f96 | 53 | |
b11afbb1 | 54 | sdi = g_malloc0(sizeof(struct sr_dev_inst)); |
b11afbb1 ML |
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); | |
58 | sdi->conn = scpi; | |
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); | |
62 | sdi->channels = NULL; | |
63 | sdi->channel_groups = NULL; | |
64 | ||
65 | sr_scpi_hw_info_free(hw_info); | |
66 | ||
67 | devc = g_malloc0(sizeof(struct dev_context)); | |
68 | devc->frame_limit = 1; | |
d9251a2c UH |
69 | devc->sample_rate = 0.0; |
70 | devc->df_started = FALSE; | |
b11afbb1 ML |
71 | sdi->priv = devc; |
72 | ||
73 | sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "CH1"); | |
74 | sr_channel_new(sdi, 1, SR_CHANNEL_ANALOG, TRUE, "CH2"); | |
75 | ||
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)); | |
80 | cg->priv = NULL; | |
81 | sdi->channel_groups = g_slist_append(NULL, cg); | |
82 | ||
83 | return sdi; | |
84 | } | |
7c198f96 | 85 | |
b11afbb1 ML |
86 | static GSList *scan(struct sr_dev_driver *di, GSList *options) |
87 | { | |
88 | return sr_scpi_scan(di->context, options, probe_device); | |
7c198f96 ML |
89 | } |
90 | ||
7c198f96 ML |
91 | static int dev_open(struct sr_dev_inst *sdi) |
92 | { | |
b11afbb1 ML |
93 | int ret; |
94 | struct sr_scpi_dev_inst *scpi = sdi->conn; | |
7c198f96 | 95 | |
b11afbb1 ML |
96 | if ((ret = sr_scpi_open(scpi)) < 0) { |
97 | sr_err("Failed to open SCPI device: %s.", sr_strerror(ret)); | |
98 | return SR_ERR; | |
99 | } | |
7c198f96 | 100 | |
7c198f96 ML |
101 | return SR_OK; |
102 | } | |
103 | ||
104 | static int dev_close(struct sr_dev_inst *sdi) | |
105 | { | |
b11afbb1 | 106 | struct sr_scpi_dev_inst *scpi; |
7c198f96 | 107 | |
b11afbb1 ML |
108 | scpi = sdi->conn; |
109 | if (scpi) { | |
110 | if (sr_scpi_close(scpi) < 0) | |
111 | return SR_ERR; | |
112 | sdi->status = SR_ST_INACTIVE; | |
113 | } | |
7c198f96 ML |
114 | |
115 | return SR_OK; | |
116 | } | |
117 | ||
7c198f96 ML |
118 | static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, |
119 | const struct sr_channel_group *cg) | |
120 | { | |
b11afbb1 | 121 | struct dev_context *devc; |
7c198f96 | 122 | |
7c198f96 ML |
123 | (void)cg; |
124 | ||
709468ba | 125 | if (!sdi) |
b11afbb1 ML |
126 | return SR_ERR_ARG; |
127 | ||
709468ba UH |
128 | devc = sdi->priv; |
129 | ||
7c198f96 | 130 | switch (key) { |
b11afbb1 ML |
131 | case SR_CONF_SAMPLERATE: |
132 | *data = g_variant_new_uint64(devc->sample_rate); | |
133 | break; | |
7c198f96 ML |
134 | default: |
135 | return SR_ERR_NA; | |
136 | } | |
137 | ||
b11afbb1 | 138 | return SR_OK; |
7c198f96 ML |
139 | } |
140 | ||
141 | static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi, | |
142 | const struct sr_channel_group *cg) | |
143 | { | |
b11afbb1 | 144 | struct dev_context *devc; |
7c198f96 | 145 | |
7c198f96 ML |
146 | (void)cg; |
147 | ||
b0baddef | 148 | if (!sdi) |
b11afbb1 ML |
149 | return SR_ERR_ARG; |
150 | ||
b0baddef UH |
151 | devc = sdi->priv; |
152 | ||
7c198f96 | 153 | switch (key) { |
b11afbb1 ML |
154 | case SR_CONF_LIMIT_FRAMES: |
155 | devc->frame_limit = g_variant_get_uint64(data); | |
156 | break; | |
7c198f96 | 157 | default: |
b11afbb1 | 158 | return SR_ERR_NA; |
7c198f96 ML |
159 | } |
160 | ||
b11afbb1 | 161 | return SR_OK; |
7c198f96 ML |
162 | } |
163 | ||
164 | static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, | |
165 | const struct sr_channel_group *cg) | |
166 | { | |
7c198f96 | 167 | (void)sdi; |
7c198f96 ML |
168 | (void)cg; |
169 | ||
7c198f96 | 170 | switch (key) { |
b11afbb1 ML |
171 | case SR_CONF_SCAN_OPTIONS: |
172 | *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, | |
173 | scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t)); | |
174 | return SR_OK; | |
175 | case SR_CONF_DEVICE_OPTIONS: | |
176 | *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, | |
177 | devopts, ARRAY_SIZE(devopts), sizeof(uint32_t)); | |
178 | return SR_OK; | |
7c198f96 ML |
179 | default: |
180 | return SR_ERR_NA; | |
181 | } | |
182 | ||
b11afbb1 | 183 | return SR_OK; |
7c198f96 ML |
184 | } |
185 | ||
695dc859 | 186 | static int dev_acquisition_start(const struct sr_dev_inst *sdi) |
7c198f96 | 187 | { |
b11afbb1 ML |
188 | struct sr_scpi_dev_inst *scpi; |
189 | struct dev_context *devc; | |
190 | ||
b11afbb1 ML |
191 | scpi = sdi->conn; |
192 | devc = sdi->priv; | |
193 | ||
b11afbb1 ML |
194 | devc->state = START_ACQUISITION; |
195 | devc->cur_acq_frame = 0; | |
196 | ||
197 | sr_scpi_source_add(sdi->session, scpi, G_IO_IN, 50, | |
198 | gwinstek_gds_800_receive_data, (void *)sdi); | |
7c198f96 ML |
199 | |
200 | return SR_OK; | |
201 | } | |
202 | ||
695dc859 | 203 | static int dev_acquisition_stop(struct sr_dev_inst *sdi) |
7c198f96 | 204 | { |
b11afbb1 ML |
205 | struct sr_scpi_dev_inst *scpi; |
206 | struct dev_context *devc; | |
207 | struct sr_datafeed_packet packet; | |
208 | ||
b11afbb1 ML |
209 | scpi = sdi->conn; |
210 | devc = sdi->priv; | |
211 | ||
b11afbb1 ML |
212 | if (devc->df_started) { |
213 | packet.type = SR_DF_FRAME_END; | |
214 | sr_session_send(sdi, &packet); | |
215 | ||
bee2b016 | 216 | std_session_send_df_end(sdi); |
b11afbb1 ML |
217 | |
218 | devc->df_started = FALSE; | |
219 | } | |
7c198f96 | 220 | |
b11afbb1 | 221 | sr_scpi_source_remove(sdi->session, scpi); |
7c198f96 ML |
222 | |
223 | return SR_OK; | |
224 | } | |
225 | ||
dd5c48a6 | 226 | static struct sr_dev_driver gwinstek_gds_800_driver_info = { |
7c198f96 | 227 | .name = "gwinstek-gds-800", |
b11afbb1 | 228 | .longname = "GW Instek GDS-800 series", |
7c198f96 | 229 | .api_version = 1, |
c2fdcc25 | 230 | .init = std_init, |
700d6b64 | 231 | .cleanup = std_cleanup, |
7c198f96 | 232 | .scan = scan, |
c01bf34c | 233 | .dev_list = std_dev_list, |
7c198f96 ML |
234 | .config_get = config_get, |
235 | .config_set = config_set, | |
236 | .config_list = config_list, | |
237 | .dev_open = dev_open, | |
238 | .dev_close = dev_close, | |
239 | .dev_acquisition_start = dev_acquisition_start, | |
240 | .dev_acquisition_stop = dev_acquisition_stop, | |
241 | .context = NULL, | |
242 | }; | |
dd5c48a6 | 243 | SR_REGISTER_DEV_DRIVER(gwinstek_gds_800_driver_info); |