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