]> sigrok.org Git - libsigrok.git/blob - hardware/hameg-hmo/api.c
hameg-hmo: use the new scpi scan API
[libsigrok.git] / hardware / hameg-hmo / api.c
1 /*
2  * This file is part of the libsigrok project.
3  *
4  * Copyright (C) 2013 poljar (Damir Jelić) <poljarinho@gmail.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
20 #include <stdlib.h>
21 #include "protocol.h"
22
23 #define SERIALCOMM "115200/8n1/flow=1"
24
25 SR_PRIV struct sr_dev_driver hameg_hmo_driver_info;
26 static struct sr_dev_driver *di = &hameg_hmo_driver_info;
27
28 static const char *manufacturers[] = {
29         "HAMEG",
30 };
31
32 static const int32_t hwopts[] = {
33         SR_CONF_CONN,
34         SR_CONF_SERIALCOMM,
35 };
36
37 enum {
38         PG_INVALID = -1,
39         PG_NONE,
40         PG_ANALOG,
41         PG_DIGITAL,
42 };
43
44 static int init(struct sr_context *sr_ctx)
45 {
46         return std_init(sr_ctx, di, LOG_PREFIX);
47 }
48
49 static int check_manufacturer(const char *manufacturer)
50 {
51         unsigned int i;
52
53         for (i = 0; i < ARRAY_SIZE(manufacturers); ++i)
54                 if (!strcmp(manufacturer, manufacturers[i]))
55                         return SR_OK;
56
57         return SR_ERR;
58 }
59
60 static struct sr_dev_inst *hmo_probe_serial_device(struct sr_scpi_dev_inst *scpi)
61 {
62         struct sr_dev_inst *sdi;
63         struct dev_context *devc;
64         struct sr_scpi_hw_info *hw_info;
65
66         sdi = NULL;
67         devc = NULL;
68         hw_info = NULL;
69
70         if (sr_scpi_get_hw_id(scpi, &hw_info) != SR_OK) {
71                 sr_info("Couldn't get IDN response.");
72                 goto fail;
73         }
74
75         if (check_manufacturer(hw_info->manufacturer) != SR_OK)
76                 goto fail;
77
78         if (!(sdi = sr_dev_inst_new(0, SR_ST_ACTIVE,
79                                     hw_info->manufacturer, hw_info->model,
80                                     hw_info->firmware_version))) {
81                 goto fail;
82         }
83         sr_scpi_hw_info_free(hw_info);
84         hw_info = NULL;
85
86         if (!(devc = g_try_malloc0(sizeof(struct dev_context))))
87                 goto fail;
88
89         sdi->driver = di;
90         sdi->priv = devc;
91         sdi->inst_type = SR_INST_SCPI;
92         sdi->conn = scpi;
93
94         if (hmo_init_device(sdi) != SR_OK)
95                 goto fail;
96
97         sr_scpi_close(sdi->conn);
98
99         sdi->status = SR_ST_INACTIVE;
100
101         return sdi;
102
103 fail:
104         if (hw_info)
105                 sr_scpi_hw_info_free(hw_info);
106         if (sdi)
107                 sr_dev_inst_free(sdi);
108         if (devc)
109                 g_free(devc);
110
111         return NULL;
112 }
113
114 static GSList *scan(GSList *options)
115 {
116         return sr_scpi_scan(di->priv, options, hmo_probe_serial_device);
117 }
118
119 static GSList *dev_list(void)
120 {
121         return ((struct drv_context *)(di->priv))->instances;
122 }
123
124 static void clear_helper(void *priv)
125 {
126         unsigned int i;
127         struct dev_context *devc;
128         struct scope_config *model;
129
130         devc = priv;
131         model = devc->model_config;
132
133         hmo_scope_state_free(devc->model_state);
134
135         for (i = 0; i < model->analog_channels; ++i)
136                 g_slist_free(devc->analog_groups[i].probes);
137
138         for (i = 0; i < model->digital_pods; ++i) {
139                 g_slist_free(devc->digital_groups[i].probes);
140                 g_free(devc->digital_groups[i].name);
141         }
142
143         g_free(devc->analog_groups);
144         g_free(devc->digital_groups);
145
146         g_free(devc);
147 }
148
149 static int dev_clear(void)
150 {
151         return std_dev_clear(di, clear_helper);
152 }
153
154 static int dev_open(struct sr_dev_inst *sdi)
155 {
156         if (sdi->status != SR_ST_ACTIVE && sr_scpi_open(sdi->conn) != SR_OK)
157                 return SR_ERR;
158
159         if (hmo_scope_state_get(sdi) != SR_OK)
160                 return SR_ERR;
161
162         sdi->status = SR_ST_ACTIVE;
163
164         return SR_OK;
165 }
166
167 static int dev_close(struct sr_dev_inst *sdi)
168 {
169         if (sdi->status == SR_ST_INACTIVE)
170                 return SR_OK;
171
172         sr_scpi_close(sdi->conn);
173
174         sdi->status = SR_ST_INACTIVE;
175
176         return SR_OK;
177 }
178
179 static int cleanup(void)
180 {
181         dev_clear();
182
183         return SR_OK;
184 }
185
186 static int check_probe_group(struct dev_context *devc,
187                              const struct sr_probe_group *probe_group)
188 {
189         unsigned int i;
190         struct scope_config *model;
191
192         model = devc->model_config;
193
194         if (!probe_group)
195                 return PG_NONE;
196
197         for (i = 0; i < model->analog_channels; ++i)
198                 if (probe_group == &devc->analog_groups[i])
199                         return PG_ANALOG;
200
201         for (i = 0; i < model->digital_pods; ++i)
202                 if (probe_group == &devc->digital_groups[i])
203                         return PG_DIGITAL;
204
205         sr_err("Invalid probe group specified.");
206
207         return PG_INVALID;
208 }
209
210 static int config_get(int key, GVariant **data, const struct sr_dev_inst *sdi,
211                       const struct sr_probe_group *probe_group)
212 {
213         int ret, pg_type;
214         unsigned int i;
215         struct dev_context *devc;
216         struct scope_config *model;
217         struct scope_state *state;
218
219         if (!sdi || !(devc = sdi->priv))
220                 return SR_ERR_ARG;
221
222         if ((pg_type = check_probe_group(devc, probe_group)) == PG_INVALID)
223                 return SR_ERR;
224
225         ret = SR_ERR_NA;
226         model = devc->model_config;
227         state = devc->model_state;
228
229         switch (key) {
230         case SR_CONF_NUM_TIMEBASE:
231                 *data = g_variant_new_int32(model->num_xdivs);
232                 ret = SR_OK;
233                 break;
234         case SR_CONF_NUM_VDIV:
235                 if (pg_type == PG_NONE) {
236                         sr_err("No probe group specified.");
237                         return SR_ERR_PROBE_GROUP;
238                 } else if (pg_type == PG_ANALOG) {
239                         for (i = 0; i < model->analog_channels; ++i) {
240                                 if (probe_group != &devc->analog_groups[i])
241                                         continue;
242                                 *data = g_variant_new_int32(model->num_ydivs);
243                                 ret = SR_OK;
244                                 break;
245                         }
246
247                 } else {
248                         ret = SR_ERR_NA;
249                 }
250                 break;
251         case SR_CONF_TRIGGER_SOURCE:
252                 *data = g_variant_new_string((*model->trigger_sources)[state->trigger_source]);
253                 ret = SR_OK;
254                 break;
255         case SR_CONF_COUPLING:
256                 if (pg_type == PG_NONE) {
257                         sr_err("No probe group specified.");
258                         return SR_ERR_PROBE_GROUP;
259                 } else if (pg_type == PG_ANALOG) {
260                         for (i = 0; i < model->analog_channels; ++i) {
261                                 if (probe_group != &devc->analog_groups[i])
262                                         continue;
263                                 *data = g_variant_new_string((*model->coupling_options)[state->analog_channels[i].coupling]);
264                                 ret = SR_OK;
265                                 break;
266                         }
267
268                 } else {
269                         ret = SR_ERR_NA;
270                 }
271                 break;
272         case SR_CONF_SAMPLERATE:
273                 *data = g_variant_new_uint64(state->sample_rate);
274                 ret = SR_OK;
275                 break;
276         default:
277                 ret = SR_ERR_NA;
278         }
279
280         return ret;
281 }
282
283 static GVariant *build_tuples(const uint64_t (*array)[][2], unsigned int n)
284 {
285         unsigned int i;
286         GVariant *rational[2];
287         GVariantBuilder gvb;
288
289         g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
290
291         for (i = 0; i < n; i++) {
292                 rational[0] = g_variant_new_uint64((*array)[i][0]);
293                 rational[1] = g_variant_new_uint64((*array)[i][1]);
294
295                 /* FIXME: Valgrind reports a memory leak here. */
296                 g_variant_builder_add_value(&gvb, g_variant_new_tuple(rational, 2));
297         }
298
299         return g_variant_builder_end(&gvb);
300 }
301
302 static int config_set(int key, GVariant *data, const struct sr_dev_inst *sdi,
303                       const struct sr_probe_group *probe_group)
304 {
305         int ret, pg_type;
306         unsigned int i, j;
307         char command[MAX_COMMAND_SIZE], float_str[30];
308         struct dev_context *devc;
309         struct scope_config *model;
310         struct scope_state *state;
311         const char *tmp;
312         uint64_t p, q;
313         double tmp_d;
314         gboolean update_sample_rate;
315
316         if (!sdi || !(devc = sdi->priv))
317                 return SR_ERR_ARG;
318
319         if ((pg_type = check_probe_group(devc, probe_group)) == PG_INVALID)
320                 return SR_ERR;
321
322         model = devc->model_config;
323         state = devc->model_state;
324         update_sample_rate = FALSE;
325
326         ret = SR_ERR_NA;
327
328         switch (key) {
329         case SR_CONF_LIMIT_FRAMES:
330                 devc->frame_limit = g_variant_get_uint64(data);
331                 ret = SR_OK;
332                 break;
333         case SR_CONF_TRIGGER_SOURCE:
334                 tmp = g_variant_get_string(data, NULL);
335                 for (i = 0; (*model->trigger_sources)[i]; i++) {
336                         if (g_strcmp0(tmp, (*model->trigger_sources)[i]) != 0)
337                                 continue;
338                         state->trigger_source = i;
339                         g_snprintf(command, sizeof(command),
340                                    (*model->scpi_dialect)[SCPI_CMD_SET_TRIGGER_SOURCE],
341                                    (*model->trigger_sources)[i]);
342
343                         ret = sr_scpi_send(sdi->conn, command);
344                         break;
345                 }
346                 break;
347         case SR_CONF_VDIV:
348                 if (pg_type == PG_NONE) {
349                         sr_err("No probe group specified.");
350                         return SR_ERR_PROBE_GROUP;
351                 }
352
353                 g_variant_get(data, "(tt)", &p, &q);
354
355                 for (i = 0; i < model->num_vdivs; i++) {
356                         if (p != (*model->vdivs)[i][0] ||
357                             q != (*model->vdivs)[i][1])
358                                 continue;
359                         for (j = 1; j <= model->analog_channels; ++j) {
360                                 if (probe_group != &devc->analog_groups[j - 1])
361                                         continue;
362                                 state->analog_channels[j - 1].vdiv = i;
363                                 g_ascii_formatd(float_str, sizeof(float_str), "%E", (float) p / q);
364                                 g_snprintf(command, sizeof(command),
365                                            (*model->scpi_dialect)[SCPI_CMD_SET_VERTICAL_DIV],
366                                            j, float_str);
367
368                                 if (sr_scpi_send(sdi->conn, command) != SR_OK ||
369                                     sr_scpi_get_opc(sdi->conn) != SR_OK)
370                                         return SR_ERR;
371
372                                 break;
373                         }
374
375                         ret = SR_OK;
376                         break;
377                 }
378                 break;
379         case SR_CONF_TIMEBASE:
380                 g_variant_get(data, "(tt)", &p, &q);
381
382                 for (i = 0; i < model->num_timebases; i++) {
383                         if (p != (*model->timebases)[i][0] ||
384                             q != (*model->timebases)[i][1])
385                                 continue;
386                         state->timebase = i;
387                         g_ascii_formatd(float_str, sizeof(float_str), "%E", (float) p / q);
388                         g_snprintf(command, sizeof(command),
389                                    (*model->scpi_dialect)[SCPI_CMD_SET_TIMEBASE],
390                                    float_str);
391
392                         ret = sr_scpi_send(sdi->conn, command);
393                         update_sample_rate = TRUE;
394                         break;
395                 }
396                 break;
397         case SR_CONF_HORIZ_TRIGGERPOS:
398                 tmp_d = g_variant_get_double(data);
399
400                 if (tmp_d < 0.0 || tmp_d > 1.0)
401                         return SR_ERR;
402
403                 state->horiz_triggerpos = -(tmp_d - 0.5) * state->timebase * model->num_xdivs;
404                 g_snprintf(command, sizeof(command),
405                            (*model->scpi_dialect)[SCPI_CMD_SET_HORIZ_TRIGGERPOS],
406                            state->horiz_triggerpos);
407
408                 ret = sr_scpi_send(sdi->conn, command);
409                 break;
410         case SR_CONF_TRIGGER_SLOPE:
411                 tmp = g_variant_get_string(data, NULL);
412
413                 if (!tmp || !(tmp[0] == 'f' || tmp[0] == 'r'))
414                         return SR_ERR_ARG;
415
416                 state->trigger_slope = (tmp[0] == 'r') ? 0 : 1;
417
418                 g_snprintf(command, sizeof(command),
419                            (*model->scpi_dialect)[SCPI_CMD_SET_TRIGGER_SLOPE],
420                            (state->trigger_slope == 0) ? "POS" : "NEG");
421
422                 ret = sr_scpi_send(sdi->conn, command);
423                 break;
424         case SR_CONF_COUPLING:
425                 if (pg_type == PG_NONE) {
426                         sr_err("No probe group specified.");
427                         return SR_ERR_PROBE_GROUP;
428                 }
429
430                 tmp = g_variant_get_string(data, NULL);
431
432                 for (i = 0; (*model->coupling_options)[i]; i++) {
433                         if (strcmp(tmp, (*model->coupling_options)[i]) != 0)
434                                 continue;
435                         for (j = 1; j <= model->analog_channels; ++j) {
436                                 if (probe_group != &devc->analog_groups[j - 1])
437                                         continue;
438                                 state->analog_channels[j-1].coupling = i;
439
440                                 g_snprintf(command, sizeof(command),
441                                            (*model->scpi_dialect)[SCPI_CMD_SET_COUPLING],
442                                            j, tmp);
443
444                                 if (sr_scpi_send(sdi->conn, command) != SR_OK ||
445                                     sr_scpi_get_opc(sdi->conn) != SR_OK)
446                                         return SR_ERR;
447                                 break;
448                         }
449
450                         ret = SR_OK;
451                         break;
452                 }
453                 break;
454         default:
455                 ret = SR_ERR_NA;
456                 break;
457         }
458
459         if (ret == SR_OK)
460                 ret = sr_scpi_get_opc(sdi->conn);
461
462         if (ret == SR_OK && update_sample_rate)
463                 ret = hmo_update_sample_rate(sdi);
464
465         return ret;
466 }
467
468 static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi,
469                        const struct sr_probe_group *probe_group)
470 {
471         int pg_type;
472         struct dev_context *devc;
473         struct scope_config *model;
474
475         if (!sdi || !(devc = sdi->priv))
476                 return SR_ERR_ARG;
477
478         if ((pg_type = check_probe_group(devc, probe_group)) == PG_INVALID)
479                 return SR_ERR;
480
481         model = devc->model_config;
482
483         switch (key) {
484         case SR_CONF_DEVICE_OPTIONS:
485                 if (pg_type == PG_NONE) {
486                         *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32,
487                                 model->hw_caps, model->num_hwcaps,
488                                 sizeof(int32_t));
489                 } else if (pg_type == PG_ANALOG) {
490                         *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32,
491                                 model->analog_hwcaps, model->num_analog_hwcaps,
492                                 sizeof(int32_t));
493                 } else {
494                         *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32,
495                                 NULL, 0, sizeof(int32_t));
496                 }
497                 break;
498         case SR_CONF_COUPLING:
499                 if (pg_type == PG_NONE)
500                         return SR_ERR_PROBE_GROUP;
501                 *data = g_variant_new_strv(*model->coupling_options,
502                            g_strv_length((char **)*model->coupling_options));
503                 break;
504         case SR_CONF_TRIGGER_SOURCE:
505                 *data = g_variant_new_strv(*model->trigger_sources,
506                            g_strv_length((char **)*model->trigger_sources));
507                 break;
508         case SR_CONF_TIMEBASE:
509                 *data = build_tuples(model->timebases, model->num_timebases);
510                 break;
511         case SR_CONF_VDIV:
512                 if (pg_type == PG_NONE)
513                         return SR_ERR_PROBE_GROUP;
514                 *data = build_tuples(model->vdivs, model->num_vdivs);
515                 break;
516         default:
517                 return SR_ERR_NA;
518         }
519
520         return SR_OK;
521 }
522
523 SR_PRIV int hmo_request_data(const struct sr_dev_inst *sdi)
524 {
525         char command[MAX_COMMAND_SIZE];
526         struct sr_probe *probe;
527         struct dev_context *devc;
528         struct scope_config *model;
529
530         devc = sdi->priv;
531         model = devc->model_config;
532
533         probe = devc->current_probe->data;
534
535         switch (probe->type) {
536         case SR_PROBE_ANALOG:
537                 g_snprintf(command, sizeof(command),
538                            (*model->scpi_dialect)[SCPI_CMD_GET_ANALOG_DATA],
539                            probe->index + 1);
540                 break;
541         case SR_PROBE_LOGIC:
542                 g_snprintf(command, sizeof(command),
543                            (*model->scpi_dialect)[SCPI_CMD_GET_DIG_DATA],
544                            probe->index < 8 ? 1 : 2);
545                 break;
546         default:
547                 sr_err("Invalid probe type.");
548                 break;
549         }
550
551         return sr_scpi_send(sdi->conn, command);
552 }
553
554 static int hmo_check_probes(GSList *probes)
555 {
556         GSList *l;
557         struct sr_probe *probe;
558         gboolean enabled_pod1, enabled_pod2, enabled_chan3, enabled_chan4;
559
560         enabled_pod1 = enabled_pod2 = enabled_chan3 = enabled_chan4 = FALSE;
561
562         for (l = probes; l; l = l->next) {
563                 probe = l->data;
564                 switch (probe->type) {
565                 case SR_PROBE_ANALOG:
566                         if (probe->index == 2)
567                                 enabled_chan3 = TRUE;
568                         else if (probe->index == 3)
569                                 enabled_chan4 = TRUE;
570                         break;
571                 case SR_PROBE_LOGIC:
572                         if (probe->index < 8)
573                                 enabled_pod1 = TRUE;
574                         else
575                                 enabled_pod2 = TRUE;
576                         break;
577                 default:
578                         return SR_ERR;
579                 }
580         }
581
582         if ((enabled_pod1 && enabled_chan3) ||
583             (enabled_pod2 && enabled_chan4))
584                 return SR_ERR;
585
586         return SR_OK;
587 }
588
589 static int hmo_setup_probes(const struct sr_dev_inst *sdi)
590 {
591         GSList *l;
592         unsigned int i;
593         gboolean *pod_enabled, setup_changed;
594         char command[MAX_COMMAND_SIZE];
595         struct scope_state *state;
596         struct scope_config *model;
597         struct sr_probe *probe;
598         struct dev_context *devc;
599         struct sr_scpi_dev_inst *scpi;
600
601         devc = sdi->priv;
602         scpi = sdi->conn;
603         state = devc->model_state;
604         model = devc->model_config;
605         setup_changed = FALSE;
606
607         pod_enabled = g_try_malloc0(sizeof(gboolean) * model->digital_pods);
608
609         for (l = sdi->probes; l; l = l->next) {
610                 probe = l->data;
611                 switch (probe->type) {
612                 case SR_PROBE_ANALOG:
613                         if (probe->enabled == state->analog_channels[probe->index].state)
614                                 break;
615                         g_snprintf(command, sizeof(command),
616                                    (*model->scpi_dialect)[SCPI_CMD_SET_ANALOG_CHAN_STATE],
617                                    probe->index + 1, probe->enabled);
618
619                         if (sr_scpi_send(scpi, command) != SR_OK)
620                                 return SR_ERR;
621                         state->analog_channels[probe->index].state = probe->enabled;
622                         setup_changed = TRUE;
623                         break;
624                 case SR_PROBE_LOGIC:
625                         /*
626                          * A digital POD needs to be enabled for every group of
627                          * 8 probes.
628                          */
629                         if (probe->enabled)
630                                 pod_enabled[probe->index < 8 ? 0 : 1] = TRUE;
631
632                         if (probe->enabled == state->digital_channels[probe->index])
633                                 break;
634                         g_snprintf(command, sizeof(command),
635                                    (*model->scpi_dialect)[SCPI_CMD_SET_DIG_CHAN_STATE],
636                                    probe->index, probe->enabled);
637
638                         if (sr_scpi_send(scpi, command) != SR_OK)
639                                 return SR_ERR;
640
641                         state->digital_channels[probe->index] = probe->enabled;
642                         setup_changed = TRUE;
643                         break;
644                 default:
645                         return SR_ERR;
646                 }
647         }
648
649         for (i = 1; i <= model->digital_pods; ++i) {
650                 if (state->digital_pods[i - 1] == pod_enabled[i - 1])
651                         continue;
652                 g_snprintf(command, sizeof(command),
653                            (*model->scpi_dialect)[SCPI_CMD_SET_DIG_POD_STATE],
654                            i, pod_enabled[i - 1]);
655                 if (sr_scpi_send(scpi, command) != SR_OK)
656                         return SR_ERR;
657                 state->digital_pods[i - 1] = pod_enabled[i - 1];
658                 setup_changed = TRUE;
659         }
660
661         g_free(pod_enabled);
662
663         if (setup_changed && hmo_update_sample_rate(sdi) != SR_OK)
664                 return SR_ERR;
665
666         return SR_OK;
667 }
668
669 static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
670 {
671         GSList *l;
672         gboolean digital_added;
673         struct sr_probe *probe;
674         struct dev_context *devc;
675         struct sr_scpi_dev_inst *scpi;
676
677         if (sdi->status != SR_ST_ACTIVE)
678                 return SR_ERR_DEV_CLOSED;
679
680         scpi = sdi->conn;
681         devc = sdi->priv;
682         digital_added = FALSE;
683
684         for (l = sdi->probes; l; l = l->next) {
685                 probe = l->data;
686                 if (!probe->enabled)
687                         continue;
688                 /* Only add a single digital probe. */
689                 if (probe->type != SR_PROBE_LOGIC || !digital_added) {
690                         devc->enabled_probes = g_slist_append(
691                                         devc->enabled_probes, probe);
692                         if (probe->type == SR_PROBE_LOGIC)
693                                 digital_added = TRUE;
694                 }
695         }
696
697         if (!devc->enabled_probes)
698                 return SR_ERR;
699
700         if (hmo_check_probes(devc->enabled_probes) != SR_OK) {
701                 sr_err("Invalid probe configuration specified!");
702                 return SR_ERR_NA;
703         }
704
705         if (hmo_setup_probes(sdi) != SR_OK) {
706                 sr_err("Failed to setup probe configuration!");
707                 return SR_ERR;
708         }
709
710         sr_scpi_source_add(scpi, G_IO_IN, 50, hmo_receive_data, (void *)sdi);
711
712         /* Send header packet to the session bus. */
713         std_session_send_df_header(cb_data, LOG_PREFIX);
714
715         devc->current_probe = devc->enabled_probes;
716
717         return hmo_request_data(sdi);
718 }
719
720 static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
721 {
722         struct dev_context *devc;
723         struct sr_scpi_dev_inst *scpi;
724         struct sr_datafeed_packet packet;
725
726         (void)cb_data;
727
728         packet.type = SR_DF_END;
729         packet.payload = NULL;
730         sr_session_send(sdi, &packet);
731
732         if (sdi->status != SR_ST_ACTIVE)
733                 return SR_ERR_DEV_CLOSED;
734
735         devc = sdi->priv;
736
737         devc->num_frames = 0;
738         g_slist_free(devc->enabled_probes);
739         devc->enabled_probes = NULL;
740         scpi = sdi->conn;
741         sr_scpi_source_remove(scpi);
742
743         return SR_OK;
744 }
745
746 SR_PRIV struct sr_dev_driver hameg_hmo_driver_info = {
747         .name = "hameg-hmo",
748         .longname = "Hameg HMO",
749         .api_version = 1,
750         .init = init,
751         .cleanup = cleanup,
752         .scan = scan,
753         .dev_list = dev_list,
754         .dev_clear = dev_clear,
755         .config_get = config_get,
756         .config_set = config_set,
757         .config_list = config_list,
758         .dev_open = dev_open,
759         .dev_close = dev_close,
760         .dev_acquisition_start = dev_acquisition_start,
761         .dev_acquisition_stop = dev_acquisition_stop,
762         .priv = NULL,
763 };