]>
Commit | Line | Data |
---|---|---|
ca1a7cb5 BV |
1 | /* |
2 | * This file is part of the libsigrok project. | |
3 | * | |
4 | * Copyright (C) 2014 Bert Vermeulen <bert@biot.com> | |
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 | ||
9e45cd41 | 20 | #include <string.h> |
ca1a7cb5 BV |
21 | #include "protocol.h" |
22 | ||
23 | SR_PRIV struct sr_dev_driver scpi_pps_driver_info; | |
24 | static struct sr_dev_driver *di = &scpi_pps_driver_info; | |
d4eabea8 BV |
25 | extern unsigned int num_pps_profiles; |
26 | extern const struct scpi_pps pps_profiles[]; | |
9e45cd41 | 27 | |
584560f1 | 28 | static const uint32_t scanopts[] = { |
9e45cd41 BV |
29 | SR_CONF_CONN, |
30 | SR_CONF_SERIALCOMM, | |
31 | }; | |
ca1a7cb5 | 32 | |
01b0257a BV |
33 | static struct pps_channel_instance pci[] = { |
34 | { SR_MQ_VOLTAGE, SCPI_CMD_GET_MEAS_VOLTAGE, "V" }, | |
35 | { SR_MQ_CURRENT, SCPI_CMD_GET_MEAS_CURRENT, "I" }, | |
36 | { SR_MQ_POWER, SCPI_CMD_GET_MEAS_POWER, "P" }, | |
37 | }; | |
38 | ||
ca1a7cb5 BV |
39 | static int init(struct sr_context *sr_ctx) |
40 | { | |
41 | return std_init(sr_ctx, di, LOG_PREFIX); | |
42 | } | |
43 | ||
9e45cd41 | 44 | static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi) |
ca1a7cb5 | 45 | { |
9e45cd41 BV |
46 | struct dev_context *devc; |
47 | struct sr_dev_inst *sdi; | |
48 | struct sr_scpi_hw_info *hw_info; | |
49 | struct sr_channel_group *cg; | |
50 | struct sr_channel *ch; | |
51 | const struct scpi_pps *device; | |
01b0257a | 52 | struct pps_channel *pch; |
9e45cd41 BV |
53 | const struct channel_group_spec *cgs; |
54 | struct pps_channel_group *pcg; | |
58b77c41 BV |
55 | GRegex *model_re; |
56 | GMatchInfo *model_mi; | |
01b0257a | 57 | GSList *l; |
9e45cd41 | 58 | uint64_t mask; |
331f5654 | 59 | unsigned int ch_num, ch_idx, i, j; |
22c18b03 | 60 | const char *vendor; |
01b0257a | 61 | char ch_name[16]; |
9e45cd41 BV |
62 | |
63 | if (sr_scpi_get_hw_id(scpi, &hw_info) != SR_OK) { | |
64 | sr_info("Couldn't get IDN response."); | |
65 | return NULL; | |
66 | } | |
67 | ||
68 | device = NULL; | |
69 | for (i = 0; i < num_pps_profiles; i++) { | |
22c18b03 | 70 | vendor = get_vendor(hw_info->manufacturer); |
58b77c41 | 71 | if (strcasecmp(vendor, pps_profiles[i].vendor)) |
22c18b03 | 72 | continue; |
58b77c41 BV |
73 | model_re = g_regex_new(pps_profiles[i].model, 0, 0, NULL); |
74 | if (g_regex_match(model_re, hw_info->model, 0, &model_mi)) | |
9e45cd41 | 75 | device = &pps_profiles[i]; |
58b77c41 BV |
76 | g_match_info_unref(model_mi); |
77 | g_regex_unref(model_re); | |
78 | if (device) | |
9e45cd41 | 79 | break; |
9e45cd41 BV |
80 | } |
81 | if (!device) { | |
82 | sr_scpi_hw_info_free(hw_info); | |
83 | return NULL; | |
84 | } | |
85 | ||
aed4ad0b | 86 | sdi = sr_dev_inst_new(SR_ST_ACTIVE, vendor, hw_info->model, |
58b77c41 | 87 | hw_info->firmware_version); |
9e45cd41 BV |
88 | sdi->conn = scpi; |
89 | sdi->driver = di; | |
90 | sdi->inst_type = SR_INST_SCPI; | |
91 | devc = g_malloc0(sizeof(struct dev_context)); | |
92 | devc->device = device; | |
93 | sdi->priv = devc; | |
94 | ||
01b0257a BV |
95 | ch_idx = 0; |
96 | for (ch_num = 0; ch_num < device->num_channels; ch_num++) { | |
97 | /* Create one channel per measurable output unit. */ | |
01b0257a BV |
98 | for (i = 0; i < ARRAY_SIZE(pci); i++) { |
99 | if (!scpi_cmd_get(sdi, pci[i].command)) | |
100 | continue; | |
101 | g_snprintf(ch_name, 16, "%s%s", pci[i].prefix, | |
102 | device->channels[ch_num].name); | |
103 | ch = sr_channel_new(ch_idx++, SR_CHANNEL_ANALOG, TRUE, ch_name); | |
104 | pch = g_malloc0(sizeof(struct pps_channel)); | |
105 | pch->hw_output_idx = ch_num; | |
106 | pch->hwname = device->channels[ch_num].name; | |
107 | pch->mq = pci[i].mq; | |
108 | ch->priv = pch; | |
109 | sdi->channels = g_slist_append(sdi->channels, ch); | |
110 | } | |
9e45cd41 | 111 | } |
ca1a7cb5 | 112 | |
9e45cd41 BV |
113 | for (i = 0; i < device->num_channel_groups; i++) { |
114 | cgs = &device->channel_groups[i]; | |
115 | cg = g_malloc0(sizeof(struct sr_channel_group)); | |
116 | cg->name = g_strdup(cgs->name); | |
117 | for (j = 0, mask = 1; j < 64; j++, mask <<= 1) { | |
118 | if (cgs->channel_index_mask & mask) { | |
01b0257a BV |
119 | for (l = sdi->channels; l; l = l->next) { |
120 | ch = l->data; | |
121 | pch = ch->priv; | |
122 | if (pch->hw_output_idx == j) | |
123 | cg->channels = g_slist_append(cg->channels, ch); | |
124 | } | |
9e45cd41 BV |
125 | } |
126 | } | |
127 | pcg = g_malloc0(sizeof(struct pps_channel_group)); | |
128 | pcg->features = cgs->features; | |
129 | cg->priv = pcg; | |
130 | sdi->channel_groups = g_slist_append(sdi->channel_groups, cg); | |
131 | } | |
ca1a7cb5 | 132 | |
60475cd7 | 133 | scpi_cmd(sdi, SCPI_CMD_LOCAL); |
9e45cd41 | 134 | sr_scpi_close(scpi); |
ca1a7cb5 | 135 | |
9e45cd41 BV |
136 | return sdi; |
137 | } | |
ca1a7cb5 | 138 | |
9e45cd41 BV |
139 | static GSList *scan(GSList *options) |
140 | { | |
141 | return sr_scpi_scan(di->priv, options, probe_device); | |
ca1a7cb5 BV |
142 | } |
143 | ||
144 | static GSList *dev_list(void) | |
145 | { | |
146 | return ((struct drv_context *)(di->priv))->instances; | |
147 | } | |
148 | ||
149 | static int dev_clear(void) | |
150 | { | |
151 | return std_dev_clear(di, NULL); | |
152 | } | |
153 | ||
154 | static int dev_open(struct sr_dev_inst *sdi) | |
155 | { | |
ee2860ee | 156 | struct dev_context *devc; |
9e45cd41 | 157 | struct sr_scpi_dev_inst *scpi; |
ee2860ee | 158 | GVariant *beeper; |
9e45cd41 BV |
159 | |
160 | if (sdi->status != SR_ST_ACTIVE) | |
161 | return SR_ERR; | |
ca1a7cb5 | 162 | |
9e45cd41 BV |
163 | scpi = sdi->conn; |
164 | if (sr_scpi_open(scpi) < 0) | |
165 | return SR_ERR; | |
ca1a7cb5 BV |
166 | |
167 | sdi->status = SR_ST_ACTIVE; | |
168 | ||
60475cd7 | 169 | scpi_cmd(sdi, SCPI_CMD_REMOTE); |
ee2860ee BV |
170 | devc = sdi->priv; |
171 | devc->beeper_was_set = FALSE; | |
172 | if (scpi_cmd_resp(sdi, &beeper, G_VARIANT_TYPE_BOOLEAN, SCPI_CMD_BEEPER) == SR_OK) { | |
173 | if (g_variant_get_boolean(beeper)) { | |
174 | devc->beeper_was_set = TRUE; | |
175 | scpi_cmd(sdi, SCPI_CMD_BEEPER_DISABLE); | |
176 | } | |
177 | g_variant_unref(beeper); | |
178 | } | |
60475cd7 | 179 | |
ca1a7cb5 BV |
180 | return SR_OK; |
181 | } | |
182 | ||
183 | static int dev_close(struct sr_dev_inst *sdi) | |
184 | { | |
9e45cd41 | 185 | struct sr_scpi_dev_inst *scpi; |
ee2860ee | 186 | struct dev_context *devc; |
ca1a7cb5 | 187 | |
9e45cd41 BV |
188 | if (sdi->status != SR_ST_ACTIVE) |
189 | return SR_ERR_DEV_CLOSED; | |
ca1a7cb5 | 190 | |
ee2860ee | 191 | devc = sdi->priv; |
9e45cd41 BV |
192 | scpi = sdi->conn; |
193 | if (scpi) { | |
ee2860ee BV |
194 | if (devc->beeper_was_set) |
195 | scpi_cmd(sdi, SCPI_CMD_BEEPER_ENABLE); | |
60475cd7 | 196 | scpi_cmd(sdi, SCPI_CMD_LOCAL); |
9e45cd41 BV |
197 | sr_scpi_close(scpi); |
198 | sdi->status = SR_ST_INACTIVE; | |
199 | } | |
ca1a7cb5 BV |
200 | |
201 | return SR_OK; | |
202 | } | |
203 | ||
204 | static int cleanup(void) | |
205 | { | |
bf48cceb | 206 | return std_dev_clear(di, NULL); |
ca1a7cb5 BV |
207 | } |
208 | ||
584560f1 | 209 | static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, |
ca1a7cb5 BV |
210 | const struct sr_channel_group *cg) |
211 | { | |
9e45cd41 | 212 | struct dev_context *devc; |
478c8d92 BV |
213 | const GVariantType *gvtype; |
214 | unsigned int i; | |
215 | int cmd, ret; | |
60475cd7 | 216 | const char *s; |
ca1a7cb5 | 217 | |
9e45cd41 BV |
218 | if (!sdi) |
219 | return SR_ERR_ARG; | |
220 | ||
221 | devc = sdi->priv; | |
ca1a7cb5 | 222 | |
478c8d92 | 223 | if (cg) { |
9e45cd41 BV |
224 | /* |
225 | * These options only apply to channel groups with a single | |
226 | * channel -- they're per-channel settings for the device. | |
227 | */ | |
478c8d92 BV |
228 | |
229 | /* | |
230 | * Config keys are handled below depending on whether a channel | |
231 | * group was provided by the frontend. However some of these | |
232 | * take a CG on one PPS but not on others. Check the device's | |
233 | * profile for that here, and NULL out the channel group as needed. | |
234 | */ | |
235 | for (i = 0; i < devc->device->num_devopts; i++) { | |
236 | if (devc->device->devopts[i] == key) { | |
237 | cg = NULL; | |
238 | break; | |
239 | } | |
240 | } | |
478c8d92 | 241 | } |
9e45cd41 | 242 | |
478c8d92 BV |
243 | gvtype = NULL; |
244 | cmd = -1; | |
245 | switch (key) { | |
246 | case SR_CONF_OUTPUT_ENABLED: | |
247 | gvtype = G_VARIANT_TYPE_BOOLEAN; | |
248 | cmd = SCPI_CMD_GET_OUTPUT_ENABLED; | |
249 | break; | |
250 | case SR_CONF_OUTPUT_VOLTAGE: | |
251 | gvtype = G_VARIANT_TYPE_DOUBLE; | |
252 | cmd = SCPI_CMD_GET_MEAS_VOLTAGE; | |
253 | break; | |
ca95e90f | 254 | case SR_CONF_OUTPUT_VOLTAGE_TARGET: |
478c8d92 | 255 | gvtype = G_VARIANT_TYPE_DOUBLE; |
ca95e90f | 256 | cmd = SCPI_CMD_GET_VOLTAGE_TARGET; |
478c8d92 BV |
257 | break; |
258 | case SR_CONF_OUTPUT_CURRENT: | |
259 | gvtype = G_VARIANT_TYPE_DOUBLE; | |
260 | cmd = SCPI_CMD_GET_MEAS_CURRENT; | |
261 | break; | |
ca95e90f | 262 | case SR_CONF_OUTPUT_CURRENT_LIMIT: |
478c8d92 | 263 | gvtype = G_VARIANT_TYPE_DOUBLE; |
ca95e90f | 264 | cmd = SCPI_CMD_GET_CURRENT_LIMIT; |
478c8d92 BV |
265 | break; |
266 | case SR_CONF_OVER_VOLTAGE_PROTECTION_ENABLED: | |
267 | gvtype = G_VARIANT_TYPE_BOOLEAN; | |
268 | cmd = SCPI_CMD_GET_OVER_VOLTAGE_PROTECTION_ENABLED; | |
269 | break; | |
270 | case SR_CONF_OVER_VOLTAGE_PROTECTION_ACTIVE: | |
271 | gvtype = G_VARIANT_TYPE_BOOLEAN; | |
272 | cmd = SCPI_CMD_GET_OVER_VOLTAGE_PROTECTION_ACTIVE; | |
273 | break; | |
274 | case SR_CONF_OVER_VOLTAGE_PROTECTION_THRESHOLD: | |
275 | gvtype = G_VARIANT_TYPE_DOUBLE; | |
276 | cmd = SCPI_CMD_GET_OVER_VOLTAGE_PROTECTION_THRESHOLD; | |
277 | break; | |
278 | case SR_CONF_OVER_CURRENT_PROTECTION_ENABLED: | |
279 | gvtype = G_VARIANT_TYPE_BOOLEAN; | |
280 | cmd = SCPI_CMD_GET_OVER_CURRENT_PROTECTION_ENABLED; | |
281 | break; | |
282 | case SR_CONF_OVER_CURRENT_PROTECTION_ACTIVE: | |
283 | gvtype = G_VARIANT_TYPE_BOOLEAN; | |
284 | cmd = SCPI_CMD_GET_OVER_CURRENT_PROTECTION_ACTIVE; | |
285 | break; | |
286 | case SR_CONF_OVER_CURRENT_PROTECTION_THRESHOLD: | |
287 | gvtype = G_VARIANT_TYPE_DOUBLE; | |
288 | cmd = SCPI_CMD_GET_OVER_CURRENT_PROTECTION_THRESHOLD; | |
289 | break; | |
290 | case SR_CONF_OVER_TEMPERATURE_PROTECTION: | |
291 | gvtype = G_VARIANT_TYPE_BOOLEAN; | |
292 | cmd = SCPI_CMD_GET_OVER_TEMPERATURE_PROTECTION; | |
293 | break; | |
60475cd7 BV |
294 | case SR_CONF_OUTPUT_REGULATION: |
295 | gvtype = G_VARIANT_TYPE_STRING; | |
296 | cmd = SCPI_CMD_GET_OUTPUT_REGULATION; | |
478c8d92 BV |
297 | } |
298 | if (gvtype) { | |
299 | if (cg) | |
60475cd7 BV |
300 | select_channel(sdi, cg->channels->data); |
301 | ret = scpi_cmd_resp(sdi, data, gvtype, cmd); | |
302 | ||
303 | if (gvtype == G_VARIANT_TYPE_STRING && ret == SR_OK) { | |
304 | /* Non-standard data type responses. */ | |
305 | switch (key) { | |
306 | case SCPI_CMD_GET_OUTPUT_REGULATION: | |
307 | /* | |
308 | * This is specific to the Rigol DP800 series. | |
309 | * We return the same string for now until more | |
310 | * models with this key are supported. Do a check | |
311 | * just for the hell of it. | |
312 | */ | |
313 | s = g_variant_get_string(*data, NULL); | |
314 | if (strcmp(s, "CC") && strcmp(s, "CV") && strcmp(s, "UR")) { | |
315 | sr_dbg("Unknown response to SCPI_CMD_GET_OUTPUT_REGULATION: %s", s); | |
316 | ret = SR_ERR_DATA; | |
9e45cd41 | 317 | } |
60475cd7 | 318 | break; |
9e45cd41 | 319 | } |
9e45cd41 | 320 | } |
478c8d92 BV |
321 | } else |
322 | ret = SR_ERR_NA; | |
ca1a7cb5 BV |
323 | |
324 | return ret; | |
325 | } | |
326 | ||
584560f1 | 327 | static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi, |
ca1a7cb5 BV |
328 | const struct sr_channel_group *cg) |
329 | { | |
9e45cd41 | 330 | double d; |
ca1a7cb5 | 331 | int ret; |
ca1a7cb5 | 332 | |
fdedbfcd BV |
333 | if (!sdi) |
334 | return SR_ERR_ARG; | |
335 | ||
ca1a7cb5 BV |
336 | if (sdi->status != SR_ST_ACTIVE) |
337 | return SR_ERR_DEV_CLOSED; | |
338 | ||
60475cd7 | 339 | if (cg) |
9e45cd41 | 340 | /* Channel group specified. */ |
60475cd7 BV |
341 | select_channel(sdi, cg->channels->data); |
342 | ||
343 | ret = SR_OK; | |
344 | switch (key) { | |
345 | case SR_CONF_OUTPUT_ENABLED: | |
346 | if (g_variant_get_boolean(data)) | |
347 | ret = scpi_cmd(sdi, SCPI_CMD_SET_OUTPUT_ENABLE); | |
348 | else | |
349 | ret = scpi_cmd(sdi, SCPI_CMD_SET_OUTPUT_DISABLE); | |
350 | break; | |
351 | case SR_CONF_OUTPUT_VOLTAGE_TARGET: | |
352 | d = g_variant_get_double(data); | |
353 | ret = scpi_cmd(sdi, SCPI_CMD_SET_VOLTAGE_TARGET, d); | |
354 | break; | |
355 | case SR_CONF_OUTPUT_CURRENT_LIMIT: | |
356 | d = g_variant_get_double(data); | |
357 | ret = scpi_cmd(sdi, SCPI_CMD_SET_CURRENT_LIMIT, d); | |
358 | break; | |
359 | case SR_CONF_OVER_VOLTAGE_PROTECTION_ENABLED: | |
360 | if (g_variant_get_boolean(data)) | |
361 | ret = scpi_cmd(sdi, SCPI_CMD_SET_OVER_VOLTAGE_PROTECTION_ENABLE); | |
362 | else | |
363 | ret = scpi_cmd(sdi, SCPI_CMD_SET_OVER_VOLTAGE_PROTECTION_DISABLE); | |
364 | break; | |
365 | case SR_CONF_OVER_VOLTAGE_PROTECTION_THRESHOLD: | |
366 | d = g_variant_get_double(data); | |
367 | ret = scpi_cmd(sdi, SCPI_CMD_SET_OVER_VOLTAGE_PROTECTION_THRESHOLD, d); | |
368 | break; | |
369 | case SR_CONF_OVER_CURRENT_PROTECTION_ENABLED: | |
370 | if (g_variant_get_boolean(data)) | |
371 | ret = scpi_cmd(sdi, SCPI_CMD_SET_OVER_CURRENT_PROTECTION_ENABLE); | |
372 | else | |
373 | ret = scpi_cmd(sdi, SCPI_CMD_SET_OVER_CURRENT_PROTECTION_DISABLE); | |
374 | break; | |
375 | case SR_CONF_OVER_CURRENT_PROTECTION_THRESHOLD: | |
376 | d = g_variant_get_double(data); | |
377 | ret = scpi_cmd(sdi, SCPI_CMD_SET_OVER_CURRENT_PROTECTION_THRESHOLD, d); | |
378 | break; | |
379 | case SR_CONF_OVER_TEMPERATURE_PROTECTION: | |
380 | if (g_variant_get_boolean(data)) | |
381 | ret = scpi_cmd(sdi, SCPI_CMD_SET_OVER_TEMPERATURE_PROTECTION_ENABLE); | |
382 | else | |
383 | ret = scpi_cmd(sdi, SCPI_CMD_SET_OVER_TEMPERATURE_PROTECTION_DISABLE); | |
384 | break; | |
385 | default: | |
386 | ret = SR_ERR_NA; | |
ca1a7cb5 BV |
387 | } |
388 | ||
389 | return ret; | |
390 | } | |
391 | ||
584560f1 | 392 | static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, |
ca1a7cb5 BV |
393 | const struct sr_channel_group *cg) |
394 | { | |
9e45cd41 BV |
395 | struct dev_context *devc; |
396 | struct sr_channel *ch; | |
397 | struct channel_spec *ch_spec; | |
398 | GVariant *gvar; | |
399 | GVariantBuilder gvb; | |
400 | int ret, i; | |
401 | const char *s[16]; | |
402 | ||
403 | /* Always available, even without sdi. */ | |
404 | if (key == SR_CONF_SCAN_OPTIONS) { | |
584560f1 BV |
405 | *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, |
406 | scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t)); | |
9e45cd41 BV |
407 | return SR_OK; |
408 | } | |
ca1a7cb5 | 409 | |
9e45cd41 BV |
410 | if (!sdi) |
411 | return SR_ERR_ARG; | |
412 | devc = sdi->priv; | |
ca1a7cb5 BV |
413 | |
414 | ret = SR_OK; | |
9e45cd41 BV |
415 | if (!cg) { |
416 | /* No channel group: global options. */ | |
417 | switch (key) { | |
418 | case SR_CONF_DEVICE_OPTIONS: | |
584560f1 | 419 | *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, |
9e45cd41 | 420 | devc->device->devopts, devc->device->num_devopts, |
584560f1 | 421 | sizeof(uint32_t)); |
9e45cd41 BV |
422 | break; |
423 | case SR_CONF_OUTPUT_CHANNEL_CONFIG: | |
478c8d92 | 424 | /* Not used. */ |
9e45cd41 BV |
425 | i = 0; |
426 | if (devc->device->features & PPS_INDEPENDENT) | |
427 | s[i++] = "Independent"; | |
428 | if (devc->device->features & PPS_SERIES) | |
429 | s[i++] = "Series"; | |
430 | if (devc->device->features & PPS_PARALLEL) | |
431 | s[i++] = "Parallel"; | |
432 | if (i == 0) { | |
433 | /* | |
434 | * Shouldn't happen: independent-only devices | |
435 | * shouldn't advertise this option at all. | |
436 | */ | |
437 | return SR_ERR_NA; | |
438 | } | |
439 | *data = g_variant_new_strv(s, i); | |
440 | break; | |
441 | default: | |
442 | return SR_ERR_NA; | |
443 | } | |
444 | } else { | |
445 | /* Channel group specified. */ | |
9e45cd41 BV |
446 | /* |
447 | * Per-channel-group options depending on a channel are actually | |
448 | * done with the first channel. Channel groups in PPS can have | |
449 | * more than one channel, but they will typically be of equal | |
01b0257a | 450 | * specification for use in series or parallel mode. |
9e45cd41 | 451 | */ |
9e45cd41 BV |
452 | ch = cg->channels->data; |
453 | ||
454 | switch (key) { | |
455 | case SR_CONF_DEVICE_OPTIONS: | |
584560f1 | 456 | *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, |
9e45cd41 | 457 | devc->device->devopts_cg, devc->device->num_devopts_cg, |
584560f1 | 458 | sizeof(uint32_t)); |
9e45cd41 | 459 | break; |
ca95e90f | 460 | case SR_CONF_OUTPUT_VOLTAGE_TARGET: |
9e45cd41 BV |
461 | ch_spec = &(devc->device->channels[ch->index]); |
462 | g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY); | |
463 | /* Min, max, write resolution. */ | |
464 | for (i = 0; i < 3; i++) { | |
465 | gvar = g_variant_new_double(ch_spec->voltage[i]); | |
466 | g_variant_builder_add_value(&gvb, gvar); | |
467 | } | |
468 | *data = g_variant_builder_end(&gvb); | |
469 | break; | |
ca95e90f | 470 | case SR_CONF_OUTPUT_CURRENT_LIMIT: |
9e45cd41 BV |
471 | g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY); |
472 | /* Min, max, step. */ | |
473 | for (i = 0; i < 3; i++) { | |
474 | ch_spec = &(devc->device->channels[ch->index]); | |
475 | gvar = g_variant_new_double(ch_spec->current[i]); | |
476 | g_variant_builder_add_value(&gvb, gvar); | |
477 | } | |
478 | *data = g_variant_builder_end(&gvb); | |
479 | break; | |
480 | default: | |
481 | return SR_ERR_NA; | |
482 | } | |
ca1a7cb5 BV |
483 | } |
484 | ||
485 | return ret; | |
486 | } | |
487 | ||
488 | static int dev_acquisition_start(const struct sr_dev_inst *sdi, | |
9e45cd41 | 489 | void *cb_data) |
ca1a7cb5 | 490 | { |
9e45cd41 BV |
491 | struct dev_context *devc; |
492 | struct sr_scpi_dev_inst *scpi; | |
493 | struct sr_channel *ch; | |
01b0257a BV |
494 | struct pps_channel *pch; |
495 | int cmd, ret; | |
ca1a7cb5 BV |
496 | |
497 | if (sdi->status != SR_ST_ACTIVE) | |
498 | return SR_ERR_DEV_CLOSED; | |
499 | ||
9e45cd41 BV |
500 | devc = sdi->priv; |
501 | scpi = sdi->conn; | |
502 | devc->cb_data = cb_data; | |
503 | ||
01b0257a | 504 | if ((ret = sr_scpi_source_add(sdi->session, scpi, G_IO_IN, 10, |
9e45cd41 BV |
505 | scpi_pps_receive_data, (void *)sdi)) != SR_OK) |
506 | return ret; | |
507 | std_session_send_df_header(sdi, LOG_PREFIX); | |
508 | ||
01b0257a | 509 | /* Prime the pipe with the first channel's fetch. */ |
9e45cd41 | 510 | ch = sdi->channels->data; |
01b0257a | 511 | pch = ch->priv; |
60475cd7 | 512 | select_channel(sdi, ch); |
01b0257a BV |
513 | if (pch->mq == SR_MQ_VOLTAGE) |
514 | cmd = SCPI_CMD_GET_MEAS_VOLTAGE; | |
515 | else if (pch->mq == SR_MQ_CURRENT) | |
516 | cmd = SCPI_CMD_GET_MEAS_CURRENT; | |
517 | else if (pch->mq == SR_MQ_POWER) | |
518 | cmd = SCPI_CMD_GET_MEAS_POWER; | |
519 | else | |
520 | return SR_ERR; | |
521 | scpi_cmd(sdi, cmd, pch->hwname); | |
ca1a7cb5 BV |
522 | |
523 | return SR_OK; | |
524 | } | |
525 | ||
526 | static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data) | |
527 | { | |
bf48cceb | 528 | struct sr_datafeed_packet packet; |
9e45cd41 BV |
529 | struct sr_scpi_dev_inst *scpi; |
530 | float f; | |
531 | ||
ca1a7cb5 BV |
532 | (void)cb_data; |
533 | ||
534 | if (sdi->status != SR_ST_ACTIVE) | |
535 | return SR_ERR_DEV_CLOSED; | |
536 | ||
9e45cd41 BV |
537 | scpi = sdi->conn; |
538 | ||
539 | /* | |
540 | * A requested value is certainly on the way. Retrieve it now, | |
541 | * to avoid leaving the device in a state where it's not expecting | |
542 | * commands. | |
543 | */ | |
544 | sr_scpi_get_float(scpi, NULL, &f); | |
545 | sr_scpi_source_remove(sdi->session, scpi); | |
546 | ||
bf48cceb BV |
547 | packet.type = SR_DF_END; |
548 | sr_session_send(sdi, &packet); | |
549 | ||
ca1a7cb5 BV |
550 | return SR_OK; |
551 | } | |
552 | ||
553 | SR_PRIV struct sr_dev_driver scpi_pps_driver_info = { | |
554 | .name = "scpi-pps", | |
555 | .longname = "SCPI PPS", | |
556 | .api_version = 1, | |
557 | .init = init, | |
558 | .cleanup = cleanup, | |
559 | .scan = scan, | |
560 | .dev_list = dev_list, | |
561 | .dev_clear = dev_clear, | |
562 | .config_get = config_get, | |
563 | .config_set = config_set, | |
564 | .config_list = config_list, | |
565 | .dev_open = dev_open, | |
566 | .dev_close = dev_close, | |
567 | .dev_acquisition_start = dev_acquisition_start, | |
568 | .dev_acquisition_stop = dev_acquisition_stop, | |
569 | .priv = NULL, | |
570 | }; |