]> sigrok.org Git - libsigrok.git/blob - src/hardware/hameg-hmo/api.c
hameg-hmo: fix potential memory leak
[libsigrok.git] / src / 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 <config.h>
21 #include <stdlib.h>
22 #include "scpi.h"
23 #include "protocol.h"
24
25 #define SERIALCOMM "115200/8n1/flow=1"
26
27 static struct sr_dev_driver hameg_hmo_driver_info;
28
29 static const char *manufacturers[] = {
30         "HAMEG",
31         "Rohde&Schwarz",
32 };
33
34 static const uint32_t scanopts[] = {
35         SR_CONF_CONN,
36         SR_CONF_SERIALCOMM,
37 };
38
39 static const uint32_t drvopts[] = {
40         SR_CONF_OSCILLOSCOPE,
41 };
42
43 enum {
44         CG_INVALID = -1,
45         CG_NONE,
46         CG_ANALOG,
47         CG_DIGITAL,
48 };
49
50 static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi)
51 {
52         struct sr_dev_inst *sdi;
53         struct dev_context *devc;
54         struct sr_scpi_hw_info *hw_info;
55
56         sdi = NULL;
57         devc = NULL;
58         hw_info = NULL;
59
60         if (sr_scpi_get_hw_id(scpi, &hw_info) != SR_OK) {
61                 sr_info("Couldn't get IDN response.");
62                 goto fail;
63         }
64
65         if (std_str_idx_s(hw_info->manufacturer, ARRAY_AND_SIZE(manufacturers)) < 0)
66                 goto fail;
67
68         sdi = g_malloc0(sizeof(struct sr_dev_inst));
69         sdi->vendor = g_strdup(hw_info->manufacturer);
70         sdi->model = g_strdup(hw_info->model);
71         sdi->version = g_strdup(hw_info->firmware_version);
72         sdi->serial_num = g_strdup(hw_info->serial_number);
73         sdi->driver = &hameg_hmo_driver_info;
74         sdi->inst_type = SR_INST_SCPI;
75         sdi->conn = scpi;
76
77         sr_scpi_hw_info_free(hw_info);
78         hw_info = NULL;
79
80         devc = g_malloc0(sizeof(struct dev_context));
81
82         sdi->priv = devc;
83
84         if (hmo_init_device(sdi) != SR_OK)
85                 goto fail;
86
87         return sdi;
88
89 fail:
90         sr_scpi_hw_info_free(hw_info);
91         sr_dev_inst_free(sdi);
92         g_free(devc);
93
94         return NULL;
95 }
96
97 static GSList *scan(struct sr_dev_driver *di, GSList *options)
98 {
99         return sr_scpi_scan(di->context, options, probe_device);
100 }
101
102 static void clear_helper(struct dev_context *devc)
103 {
104         hmo_scope_state_free(devc->model_state);
105         g_free(devc->analog_groups);
106         g_free(devc->digital_groups);
107 }
108
109 static int dev_clear(const struct sr_dev_driver *di)
110 {
111         return std_dev_clear_with_callback(di, (std_dev_clear_callback)clear_helper);
112 }
113
114 static int dev_open(struct sr_dev_inst *sdi)
115 {
116         if (sr_scpi_open(sdi->conn) != SR_OK)
117                 return SR_ERR;
118
119         if (hmo_scope_state_get(sdi) != SR_OK)
120                 return SR_ERR;
121
122         return SR_OK;
123 }
124
125 static int dev_close(struct sr_dev_inst *sdi)
126 {
127         return sr_scpi_close(sdi->conn);
128 }
129
130 static int check_channel_group(struct dev_context *devc,
131                              const struct sr_channel_group *cg)
132 {
133         const struct scope_config *model;
134
135         model = devc->model_config;
136
137         if (!cg)
138                 return CG_NONE;
139
140         if (std_cg_idx(cg, devc->analog_groups, model->analog_channels) >= 0)
141                 return CG_ANALOG;
142
143         if (std_cg_idx(cg, devc->digital_groups, model->digital_pods) >= 0)
144                 return CG_DIGITAL;
145
146         sr_err("Invalid channel group specified.");
147
148         return CG_INVALID;
149 }
150
151 static int config_get(uint32_t key, GVariant **data,
152         const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
153 {
154         int cg_type, idx;
155         struct dev_context *devc;
156         const struct scope_config *model;
157         struct scope_state *state;
158
159         if (!sdi)
160                 return SR_ERR_ARG;
161
162         devc = sdi->priv;
163
164         if ((cg_type = check_channel_group(devc, cg)) == CG_INVALID)
165                 return SR_ERR;
166
167         model = devc->model_config;
168         state = devc->model_state;
169
170         switch (key) {
171         case SR_CONF_NUM_HDIV:
172                 *data = g_variant_new_int32(model->num_xdivs);
173                 break;
174         case SR_CONF_TIMEBASE:
175                 *data = g_variant_new("(tt)", (*model->timebases)[state->timebase][0],
176                                       (*model->timebases)[state->timebase][1]);
177                 break;
178         case SR_CONF_NUM_VDIV:
179                 if (!cg)
180                         return SR_ERR_CHANNEL_GROUP;
181                 if (cg_type != CG_ANALOG)
182                         return SR_ERR_NA;
183                 if (std_cg_idx(cg, devc->analog_groups, model->analog_channels) < 0)
184                         return SR_ERR_ARG;
185                 *data = g_variant_new_int32(model->num_ydivs);
186                 break;
187         case SR_CONF_VDIV:
188                 if (!cg)
189                         return SR_ERR_CHANNEL_GROUP;
190                 if (cg_type != CG_ANALOG)
191                         return SR_ERR_NA;
192                 if ((idx = std_cg_idx(cg, devc->analog_groups, model->analog_channels)) < 0)
193                         return SR_ERR_ARG;
194                 *data = g_variant_new("(tt)",
195                                       (*model->vdivs)[state->analog_channels[idx].vdiv][0],
196                                       (*model->vdivs)[state->analog_channels[idx].vdiv][1]);
197                 break;
198         case SR_CONF_TRIGGER_SOURCE:
199                 *data = g_variant_new_string((*model->trigger_sources)[state->trigger_source]);
200                 break;
201         case SR_CONF_TRIGGER_SLOPE:
202                 *data = g_variant_new_string((*model->trigger_slopes)[state->trigger_slope]);
203                 break;
204         case SR_CONF_HORIZ_TRIGGERPOS:
205                 *data = g_variant_new_double(state->horiz_triggerpos);
206                 break;
207         case SR_CONF_COUPLING:
208                 if (!cg)
209                         return SR_ERR_CHANNEL_GROUP;
210                 if (cg_type != CG_ANALOG)
211                         return SR_ERR_NA;
212                 if ((idx = std_cg_idx(cg, devc->analog_groups, model->analog_channels)) < 0)
213                         return SR_ERR_ARG;
214                 *data = g_variant_new_string((*model->coupling_options)[state->analog_channels[idx].coupling]);
215                 break;
216         case SR_CONF_SAMPLERATE:
217                 *data = g_variant_new_uint64(state->sample_rate);
218                 break;
219         default:
220                 return SR_ERR_NA;
221         }
222
223         return SR_OK;
224 }
225
226 static int config_set(uint32_t key, GVariant *data,
227         const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
228 {
229         int ret, cg_type, idx, j;
230         char command[MAX_COMMAND_SIZE], float_str[30];
231         struct dev_context *devc;
232         const struct scope_config *model;
233         struct scope_state *state;
234         double tmp_d;
235         gboolean update_sample_rate;
236
237         if (!sdi)
238                 return SR_ERR_ARG;
239
240         devc = sdi->priv;
241
242         if ((cg_type = check_channel_group(devc, cg)) == CG_INVALID)
243                 return SR_ERR;
244
245         model = devc->model_config;
246         state = devc->model_state;
247         update_sample_rate = FALSE;
248
249         switch (key) {
250         case SR_CONF_LIMIT_FRAMES:
251                 devc->frame_limit = g_variant_get_uint64(data);
252                 ret = SR_OK;
253                 break;
254         case SR_CONF_TRIGGER_SOURCE:
255                 if ((idx = std_str_idx(data, *model->trigger_sources, model->num_trigger_sources)) < 0)
256                         return SR_ERR_ARG;
257                 state->trigger_source = idx;
258                 g_snprintf(command, sizeof(command),
259                            (*model->scpi_dialect)[SCPI_CMD_SET_TRIGGER_SOURCE],
260                            (*model->trigger_sources)[idx]);
261                 ret = sr_scpi_send(sdi->conn, command);
262                 break;
263         case SR_CONF_VDIV:
264                 if (!cg)
265                         return SR_ERR_CHANNEL_GROUP;
266                 if ((idx = std_u64_tuple_idx(data, *model->vdivs, model->num_vdivs)) < 0)
267                         return SR_ERR_ARG;
268                 if ((j = std_cg_idx(cg, devc->analog_groups, model->analog_channels)) < 0)
269                         return SR_ERR_ARG;
270                 state->analog_channels[j].vdiv = idx;
271                 g_ascii_formatd(float_str, sizeof(float_str), "%E",
272                         (float) (*model->vdivs)[idx][0] / (*model->vdivs)[idx][1]);
273                 g_snprintf(command, sizeof(command),
274                            (*model->scpi_dialect)[SCPI_CMD_SET_VERTICAL_DIV],
275                            j + 1, float_str);
276                 if (sr_scpi_send(sdi->conn, command) != SR_OK ||
277                     sr_scpi_get_opc(sdi->conn) != SR_OK)
278                         return SR_ERR;
279                 ret = SR_OK;
280                 break;
281         case SR_CONF_TIMEBASE:
282                 if ((idx = std_u64_tuple_idx(data, *model->timebases, model->num_timebases)) < 0)
283                         return SR_ERR_ARG;
284                 state->timebase = idx;
285                 g_ascii_formatd(float_str, sizeof(float_str), "%E",
286                         (float) (*model->timebases)[idx][0] / (*model->timebases)[idx][1]);
287                 g_snprintf(command, sizeof(command),
288                            (*model->scpi_dialect)[SCPI_CMD_SET_TIMEBASE],
289                            float_str);
290                 ret = sr_scpi_send(sdi->conn, command);
291                 update_sample_rate = TRUE;
292                 break;
293         case SR_CONF_HORIZ_TRIGGERPOS:
294                 tmp_d = g_variant_get_double(data);
295                 if (tmp_d < 0.0 || tmp_d > 1.0)
296                         return SR_ERR;
297                 state->horiz_triggerpos = tmp_d;
298                 tmp_d = -(tmp_d - 0.5) *
299                         ((double) (*model->timebases)[state->timebase][0] /
300                         (*model->timebases)[state->timebase][1])
301                          * model->num_xdivs;
302                 g_ascii_formatd(float_str, sizeof(float_str), "%E", tmp_d);
303                 g_snprintf(command, sizeof(command),
304                            (*model->scpi_dialect)[SCPI_CMD_SET_HORIZ_TRIGGERPOS],
305                            float_str);
306                 ret = sr_scpi_send(sdi->conn, command);
307                 break;
308         case SR_CONF_TRIGGER_SLOPE:
309                 if ((idx = std_str_idx(data, *model->trigger_slopes, model->num_trigger_slopes)) < 0)
310                         return SR_ERR_ARG;
311                 state->trigger_slope = idx;
312                 g_snprintf(command, sizeof(command),
313                            (*model->scpi_dialect)[SCPI_CMD_SET_TRIGGER_SLOPE],
314                            (*model->trigger_slopes)[idx]);
315                 ret = sr_scpi_send(sdi->conn, command);
316                 break;
317         case SR_CONF_COUPLING:
318                 if (!cg)
319                         return SR_ERR_CHANNEL_GROUP;
320                 if ((idx = std_str_idx(data, *model->coupling_options, model->num_coupling_options)) < 0)
321                         return SR_ERR_ARG;
322                 if ((j = std_cg_idx(cg, devc->analog_groups, model->analog_channels)) < 0)
323                         return SR_ERR_ARG;
324                 state->analog_channels[j].coupling = idx;
325                 g_snprintf(command, sizeof(command),
326                            (*model->scpi_dialect)[SCPI_CMD_SET_COUPLING],
327                            j + 1, (*model->coupling_options)[idx]);
328                 if (sr_scpi_send(sdi->conn, command) != SR_OK ||
329                     sr_scpi_get_opc(sdi->conn) != SR_OK)
330                         return SR_ERR;
331                 ret = SR_OK;
332                 break;
333         default:
334                 ret = SR_ERR_NA;
335                 break;
336         }
337
338         if (ret == SR_OK)
339                 ret = sr_scpi_get_opc(sdi->conn);
340
341         if (ret == SR_OK && update_sample_rate)
342                 ret = hmo_update_sample_rate(sdi);
343
344         return ret;
345 }
346
347 static int config_list(uint32_t key, GVariant **data,
348         const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
349 {
350         int cg_type = CG_NONE;
351         struct dev_context *devc = NULL;
352         const struct scope_config *model = NULL;
353
354         if (sdi) {
355                 devc = sdi->priv;
356                 if ((cg_type = check_channel_group(devc, cg)) == CG_INVALID)
357                         return SR_ERR;
358
359                 model = devc->model_config;
360         }
361
362         switch (key) {
363         case SR_CONF_SCAN_OPTIONS:
364                 *data = std_gvar_array_u32(ARRAY_AND_SIZE(scanopts));
365                 break;
366         case SR_CONF_DEVICE_OPTIONS:
367                 if (!cg) {
368                         if (model)
369                                 *data = std_gvar_array_u32((const uint32_t *)model->devopts, model->num_devopts);
370                         else
371                                 *data = std_gvar_array_u32(ARRAY_AND_SIZE(drvopts));
372                 } else if (cg_type == CG_ANALOG) {
373                         *data = std_gvar_array_u32((const uint32_t *)model->devopts_cg_analog, model->num_devopts_cg_analog);
374                 } else {
375                         *data = std_gvar_array_u32(NULL, 0);
376                 }
377                 break;
378         case SR_CONF_COUPLING:
379                 if (!cg)
380                         return SR_ERR_CHANNEL_GROUP;
381                 if (!model)
382                         return SR_ERR_ARG;
383                 *data = g_variant_new_strv(*model->coupling_options, model->num_coupling_options);
384                 break;
385         case SR_CONF_TRIGGER_SOURCE:
386                 if (!model)
387                         return SR_ERR_ARG;
388                 *data = g_variant_new_strv(*model->trigger_sources, model->num_trigger_sources);
389                 break;
390         case SR_CONF_TRIGGER_SLOPE:
391                 if (!model)
392                         return SR_ERR_ARG;
393                 *data = g_variant_new_strv(*model->trigger_slopes, model->num_trigger_slopes);
394                 break;
395         case SR_CONF_TIMEBASE:
396                 if (!model)
397                         return SR_ERR_ARG;
398                 *data = std_gvar_tuple_array(*model->timebases, model->num_timebases);
399                 break;
400         case SR_CONF_VDIV:
401                 if (!cg)
402                         return SR_ERR_CHANNEL_GROUP;
403                 if (!model)
404                         return SR_ERR_ARG;
405                 *data = std_gvar_tuple_array(*model->vdivs, model->num_vdivs);
406                 break;
407         default:
408                 return SR_ERR_NA;
409         }
410
411         return SR_OK;
412 }
413
414 SR_PRIV int hmo_request_data(const struct sr_dev_inst *sdi)
415 {
416         char command[MAX_COMMAND_SIZE];
417         struct sr_channel *ch;
418         struct dev_context *devc;
419         const struct scope_config *model;
420
421         devc = sdi->priv;
422         model = devc->model_config;
423
424         ch = devc->current_channel->data;
425
426         switch (ch->type) {
427         case SR_CHANNEL_ANALOG:
428                 g_snprintf(command, sizeof(command),
429                            (*model->scpi_dialect)[SCPI_CMD_GET_ANALOG_DATA],
430 #ifdef WORDS_BIGENDIAN
431                            "MSBF",
432 #else
433                            "LSBF",
434 #endif
435                            ch->index + 1);
436                 break;
437         case SR_CHANNEL_LOGIC:
438                 g_snprintf(command, sizeof(command),
439                            (*model->scpi_dialect)[SCPI_CMD_GET_DIG_DATA],
440                            ch->index < 8 ? 1 : 2);
441                 break;
442         default:
443                 sr_err("Invalid channel type.");
444                 break;
445         }
446
447         return sr_scpi_send(sdi->conn, command);
448 }
449
450 static int hmo_check_channels(GSList *channels)
451 {
452         GSList *l;
453         struct sr_channel *ch;
454         gboolean enabled_chan[MAX_ANALOG_CHANNEL_COUNT];
455         gboolean enabled_pod[MAX_DIGITAL_GROUP_COUNT];
456         size_t idx;
457
458         /* Preset "not enabled" for all channels / pods. */
459         for (idx = 0; idx < ARRAY_SIZE(enabled_chan); idx++)
460                 enabled_chan[idx] = FALSE;
461         for (idx = 0; idx < ARRAY_SIZE(enabled_pod); idx++)
462                 enabled_pod[idx] = FALSE;
463
464         /*
465          * Determine which channels / pods are required for the caller's
466          * specified configuration.
467          */
468         for (l = channels; l; l = l->next) {
469                 ch = l->data;
470                 switch (ch->type) {
471                 case SR_CHANNEL_ANALOG:
472                         idx = ch->index;
473                         if (idx < ARRAY_SIZE(enabled_chan))
474                                 enabled_chan[idx] = TRUE;
475                         break;
476                 case SR_CHANNEL_LOGIC:
477                         idx = ch->index / 8;
478                         if (idx < ARRAY_SIZE(enabled_pod))
479                                 enabled_pod[idx] = TRUE;
480                         break;
481                 default:
482                         return SR_ERR;
483                 }
484         }
485
486         /*
487          * Check for resource conflicts. Some channels can be either
488          * analog or digital, but never both at the same time.
489          *
490          * Note that the constraints might depend on the specific model.
491          * These tests might need some adjustment when support for more
492          * models gets added to the driver.
493          */
494         if (enabled_pod[0] && enabled_chan[2])
495                 return SR_ERR;
496         if (enabled_pod[1] && enabled_chan[3])
497                 return SR_ERR;
498         return SR_OK;
499 }
500
501 static int hmo_setup_channels(const struct sr_dev_inst *sdi)
502 {
503         GSList *l;
504         unsigned int i;
505         gboolean *pod_enabled, setup_changed;
506         char command[MAX_COMMAND_SIZE];
507         struct scope_state *state;
508         const struct scope_config *model;
509         struct sr_channel *ch;
510         struct dev_context *devc;
511         struct sr_scpi_dev_inst *scpi;
512         int ret;
513
514         devc = sdi->priv;
515         scpi = sdi->conn;
516         state = devc->model_state;
517         model = devc->model_config;
518         setup_changed = FALSE;
519
520         pod_enabled = g_try_malloc0(sizeof(gboolean) * model->digital_pods);
521
522         for (l = sdi->channels; l; l = l->next) {
523                 ch = l->data;
524                 switch (ch->type) {
525                 case SR_CHANNEL_ANALOG:
526                         if (ch->enabled == state->analog_channels[ch->index].state)
527                                 break;
528                         g_snprintf(command, sizeof(command),
529                                    (*model->scpi_dialect)[SCPI_CMD_SET_ANALOG_CHAN_STATE],
530                                    ch->index + 1, ch->enabled);
531
532                         if (sr_scpi_send(scpi, command) != SR_OK)
533                                 return SR_ERR;
534                         state->analog_channels[ch->index].state = ch->enabled;
535                         setup_changed = TRUE;
536                         break;
537                 case SR_CHANNEL_LOGIC:
538                         /*
539                          * A digital POD needs to be enabled for every group of
540                          * 8 channels.
541                          */
542                         if (ch->enabled)
543                                 pod_enabled[ch->index < 8 ? 0 : 1] = TRUE;
544
545                         if (ch->enabled == state->digital_channels[ch->index])
546                                 break;
547                         g_snprintf(command, sizeof(command),
548                                    (*model->scpi_dialect)[SCPI_CMD_SET_DIG_CHAN_STATE],
549                                    ch->index, ch->enabled);
550
551                         if (sr_scpi_send(scpi, command) != SR_OK)
552                                 return SR_ERR;
553
554                         state->digital_channels[ch->index] = ch->enabled;
555                         setup_changed = TRUE;
556                         break;
557                 default:
558                         g_free(pod_enabled);
559                         return SR_ERR;
560                 }
561         }
562
563         ret = SR_OK;
564         for (i = 0; i < model->digital_pods; i++) {
565                 if (state->digital_pods[i] == pod_enabled[i])
566                         continue;
567                 g_snprintf(command, sizeof(command),
568                            (*model->scpi_dialect)[SCPI_CMD_SET_DIG_POD_STATE],
569                            i + 1, pod_enabled[i]);
570                 if (sr_scpi_send(scpi, command) != SR_OK) {
571                         ret = SR_ERR;
572                         break;
573                 }
574                 state->digital_pods[i] = pod_enabled[i];
575                 setup_changed = TRUE;
576         }
577         g_free(pod_enabled);
578         if (ret != SR_OK)
579                 return ret;
580
581         if (setup_changed && hmo_update_sample_rate(sdi) != SR_OK)
582                 return SR_ERR;
583
584         return SR_OK;
585 }
586
587 static int dev_acquisition_start(const struct sr_dev_inst *sdi)
588 {
589         GSList *l;
590         gboolean digital_added[MAX_DIGITAL_GROUP_COUNT];
591         size_t group, pod_count;
592         struct sr_channel *ch;
593         struct dev_context *devc;
594         struct sr_scpi_dev_inst *scpi;
595         int ret;
596
597         scpi = sdi->conn;
598         devc = sdi->priv;
599
600         /* Preset empty results. */
601         for (group = 0; group < ARRAY_SIZE(digital_added); group++)
602                 digital_added[group] = FALSE;
603         g_slist_free(devc->enabled_channels);
604         devc->enabled_channels = NULL;
605
606         /*
607          * Contruct the list of enabled channels. Determine the highest
608          * number of digital pods involved in the acquisition.
609          */
610         pod_count = 0;
611         for (l = sdi->channels; l; l = l->next) {
612                 ch = l->data;
613                 if (!ch->enabled)
614                         continue;
615                 /* Only add a single digital channel per group (pod). */
616                 group = ch->index / 8;
617                 if (ch->type != SR_CHANNEL_LOGIC || !digital_added[group]) {
618                         devc->enabled_channels = g_slist_append(
619                                         devc->enabled_channels, ch);
620                         if (ch->type == SR_CHANNEL_LOGIC) {
621                                 digital_added[group] = TRUE;
622                                 if (pod_count < group + 1)
623                                         pod_count = group + 1;
624                         }
625                 }
626         }
627         if (!devc->enabled_channels)
628                 return SR_ERR;
629         devc->pod_count = pod_count;
630         devc->logic_data = NULL;
631
632         /*
633          * Check constraints. Some channels can be either analog or
634          * digital, but not both at the same time.
635          */
636         if (hmo_check_channels(devc->enabled_channels) != SR_OK) {
637                 sr_err("Invalid channel configuration specified!");
638                 ret = SR_ERR_NA;
639                 goto free_enabled;
640         }
641
642         /*
643          * Configure the analog and digital channels and the
644          * corresponding digital pods.
645          */
646         if (hmo_setup_channels(sdi) != SR_OK) {
647                 sr_err("Failed to setup channel configuration!");
648                 ret = SR_ERR;
649                 goto free_enabled;
650         }
651
652         /*
653          * Start acquisition on the first enabled channel. The
654          * receive routine will continue driving the acquisition.
655          */
656         sr_scpi_source_add(sdi->session, scpi, G_IO_IN, 50,
657                         hmo_receive_data, (void *)sdi);
658
659         std_session_send_df_header(sdi);
660
661         devc->current_channel = devc->enabled_channels;
662
663         return hmo_request_data(sdi);
664
665 free_enabled:
666         g_slist_free(devc->enabled_channels);
667         devc->enabled_channels = NULL;
668         return ret;
669 }
670
671 static int dev_acquisition_stop(struct sr_dev_inst *sdi)
672 {
673         struct dev_context *devc;
674         struct sr_scpi_dev_inst *scpi;
675
676         std_session_send_df_end(sdi);
677
678         devc = sdi->priv;
679
680         devc->num_frames = 0;
681         g_slist_free(devc->enabled_channels);
682         devc->enabled_channels = NULL;
683         scpi = sdi->conn;
684         sr_scpi_source_remove(sdi->session, scpi);
685
686         return SR_OK;
687 }
688
689 static struct sr_dev_driver hameg_hmo_driver_info = {
690         .name = "hameg-hmo",
691         .longname = "Hameg HMO",
692         .api_version = 1,
693         .init = std_init,
694         .cleanup = std_cleanup,
695         .scan = scan,
696         .dev_list = std_dev_list,
697         .dev_clear = dev_clear,
698         .config_get = config_get,
699         .config_set = config_set,
700         .config_list = config_list,
701         .dev_open = dev_open,
702         .dev_close = dev_close,
703         .dev_acquisition_start = dev_acquisition_start,
704         .dev_acquisition_stop = dev_acquisition_stop,
705         .context = NULL,
706 };
707 SR_REGISTER_DEV_DRIVER(hameg_hmo_driver_info);