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