]> sigrok.org Git - libsigrok.git/blame_incremental - src/hardware/hameg-hmo/api.c
Reorganize project tree.
[libsigrok.git] / src / hardware / hameg-hmo / api.c
... / ...
CommitLineData
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
25SR_PRIV struct sr_dev_driver hameg_hmo_driver_info;
26static struct sr_dev_driver *di = &hameg_hmo_driver_info;
27
28static const char *manufacturers[] = {
29 "HAMEG",
30};
31
32static const int32_t hwopts[] = {
33 SR_CONF_CONN,
34 SR_CONF_SERIALCOMM,
35};
36
37enum {
38 CG_INVALID = -1,
39 CG_NONE,
40 CG_ANALOG,
41 CG_DIGITAL,
42};
43
44static int init(struct sr_context *sr_ctx)
45{
46 return std_init(sr_ctx, di, LOG_PREFIX);
47}
48
49static 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
60static 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
103fail:
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
114static GSList *scan(GSList *options)
115{
116 return sr_scpi_scan(di->priv, options, hmo_probe_serial_device);
117}
118
119static GSList *dev_list(void)
120{
121 return ((struct drv_context *)(di->priv))->instances;
122}
123
124static 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].channels);
137
138 for (i = 0; i < model->digital_pods; ++i) {
139 g_slist_free(devc->digital_groups[i].channels);
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
149static int dev_clear(void)
150{
151 return std_dev_clear(di, clear_helper);
152}
153
154static 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
167static 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
179static int cleanup(void)
180{
181 dev_clear();
182
183 return SR_OK;
184}
185
186static int check_channel_group(struct dev_context *devc,
187 const struct sr_channel_group *cg)
188{
189 unsigned int i;
190 struct scope_config *model;
191
192 model = devc->model_config;
193
194 if (!cg)
195 return CG_NONE;
196
197 for (i = 0; i < model->analog_channels; ++i)
198 if (cg == &devc->analog_groups[i])
199 return CG_ANALOG;
200
201 for (i = 0; i < model->digital_pods; ++i)
202 if (cg == &devc->digital_groups[i])
203 return CG_DIGITAL;
204
205 sr_err("Invalid channel group specified.");
206
207 return CG_INVALID;
208}
209
210static int config_get(int key, GVariant **data, const struct sr_dev_inst *sdi,
211 const struct sr_channel_group *cg)
212{
213 int ret, cg_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 ((cg_type = check_channel_group(devc, cg)) == CG_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_TIMEBASE:
235 *data = g_variant_new("(tt)", (*model->timebases)[state->timebase][0],
236 (*model->timebases)[state->timebase][1]);
237 ret = SR_OK;
238 break;
239 case SR_CONF_NUM_VDIV:
240 if (cg_type == CG_NONE) {
241 sr_err("No channel group specified.");
242 return SR_ERR_CHANNEL_GROUP;
243 } else if (cg_type == CG_ANALOG) {
244 for (i = 0; i < model->analog_channels; ++i) {
245 if (cg != &devc->analog_groups[i])
246 continue;
247 *data = g_variant_new_int32(model->num_ydivs);
248 ret = SR_OK;
249 break;
250 }
251
252 } else {
253 ret = SR_ERR_NA;
254 }
255 break;
256 case SR_CONF_VDIV:
257 if (cg_type == CG_NONE) {
258 sr_err("No channel group specified.");
259 return SR_ERR_CHANNEL_GROUP;
260 } else if (cg_type == CG_ANALOG) {
261 for (i = 0; i < model->analog_channels; ++i) {
262 if (cg != &devc->analog_groups[i])
263 continue;
264 *data = g_variant_new("(tt)",
265 (*model->vdivs)[state->analog_channels[i].vdiv][0],
266 (*model->vdivs)[state->analog_channels[i].vdiv][1]);
267 ret = SR_OK;
268 break;
269 }
270
271 } else {
272 ret = SR_ERR_NA;
273 }
274 break;
275 case SR_CONF_TRIGGER_SOURCE:
276 *data = g_variant_new_string((*model->trigger_sources)[state->trigger_source]);
277 ret = SR_OK;
278 break;
279 case SR_CONF_TRIGGER_SLOPE:
280 *data = g_variant_new_string((*model->trigger_slopes)[state->trigger_slope]);
281 ret = SR_OK;
282 break;
283 case SR_CONF_HORIZ_TRIGGERPOS:
284 *data = g_variant_new_double(state->horiz_triggerpos);
285 ret = SR_OK;
286 break;
287 case SR_CONF_COUPLING:
288 if (cg_type == CG_NONE) {
289 sr_err("No channel group specified.");
290 return SR_ERR_CHANNEL_GROUP;
291 } else if (cg_type == CG_ANALOG) {
292 for (i = 0; i < model->analog_channels; ++i) {
293 if (cg != &devc->analog_groups[i])
294 continue;
295 *data = g_variant_new_string((*model->coupling_options)[state->analog_channels[i].coupling]);
296 ret = SR_OK;
297 break;
298 }
299
300 } else {
301 ret = SR_ERR_NA;
302 }
303 break;
304 case SR_CONF_SAMPLERATE:
305 *data = g_variant_new_uint64(state->sample_rate);
306 ret = SR_OK;
307 break;
308 default:
309 ret = SR_ERR_NA;
310 }
311
312 return ret;
313}
314
315static GVariant *build_tuples(const uint64_t (*array)[][2], unsigned int n)
316{
317 unsigned int i;
318 GVariant *rational[2];
319 GVariantBuilder gvb;
320
321 g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
322
323 for (i = 0; i < n; i++) {
324 rational[0] = g_variant_new_uint64((*array)[i][0]);
325 rational[1] = g_variant_new_uint64((*array)[i][1]);
326
327 /* FIXME: Valgrind reports a memory leak here. */
328 g_variant_builder_add_value(&gvb, g_variant_new_tuple(rational, 2));
329 }
330
331 return g_variant_builder_end(&gvb);
332}
333
334static int config_set(int key, GVariant *data, const struct sr_dev_inst *sdi,
335 const struct sr_channel_group *cg)
336{
337 int ret, cg_type;
338 unsigned int i, j;
339 char command[MAX_COMMAND_SIZE], float_str[30];
340 struct dev_context *devc;
341 struct scope_config *model;
342 struct scope_state *state;
343 const char *tmp;
344 uint64_t p, q;
345 double tmp_d;
346 gboolean update_sample_rate;
347
348 if (!sdi || !(devc = sdi->priv))
349 return SR_ERR_ARG;
350
351 if ((cg_type = check_channel_group(devc, cg)) == CG_INVALID)
352 return SR_ERR;
353
354 model = devc->model_config;
355 state = devc->model_state;
356 update_sample_rate = FALSE;
357
358 ret = SR_ERR_NA;
359
360 switch (key) {
361 case SR_CONF_LIMIT_FRAMES:
362 devc->frame_limit = g_variant_get_uint64(data);
363 ret = SR_OK;
364 break;
365 case SR_CONF_TRIGGER_SOURCE:
366 tmp = g_variant_get_string(data, NULL);
367 for (i = 0; (*model->trigger_sources)[i]; i++) {
368 if (g_strcmp0(tmp, (*model->trigger_sources)[i]) != 0)
369 continue;
370 state->trigger_source = i;
371 g_snprintf(command, sizeof(command),
372 (*model->scpi_dialect)[SCPI_CMD_SET_TRIGGER_SOURCE],
373 (*model->trigger_sources)[i]);
374
375 ret = sr_scpi_send(sdi->conn, command);
376 break;
377 }
378 break;
379 case SR_CONF_VDIV:
380 if (cg_type == CG_NONE) {
381 sr_err("No channel group specified.");
382 return SR_ERR_CHANNEL_GROUP;
383 }
384
385 g_variant_get(data, "(tt)", &p, &q);
386
387 for (i = 0; i < model->num_vdivs; i++) {
388 if (p != (*model->vdivs)[i][0] ||
389 q != (*model->vdivs)[i][1])
390 continue;
391 for (j = 1; j <= model->analog_channels; ++j) {
392 if (cg != &devc->analog_groups[j - 1])
393 continue;
394 state->analog_channels[j - 1].vdiv = i;
395 g_ascii_formatd(float_str, sizeof(float_str), "%E", (float) p / q);
396 g_snprintf(command, sizeof(command),
397 (*model->scpi_dialect)[SCPI_CMD_SET_VERTICAL_DIV],
398 j, float_str);
399
400 if (sr_scpi_send(sdi->conn, command) != SR_OK ||
401 sr_scpi_get_opc(sdi->conn) != SR_OK)
402 return SR_ERR;
403
404 break;
405 }
406
407 ret = SR_OK;
408 break;
409 }
410 break;
411 case SR_CONF_TIMEBASE:
412 g_variant_get(data, "(tt)", &p, &q);
413
414 for (i = 0; i < model->num_timebases; i++) {
415 if (p != (*model->timebases)[i][0] ||
416 q != (*model->timebases)[i][1])
417 continue;
418 state->timebase = i;
419 g_ascii_formatd(float_str, sizeof(float_str), "%E", (float) p / q);
420 g_snprintf(command, sizeof(command),
421 (*model->scpi_dialect)[SCPI_CMD_SET_TIMEBASE],
422 float_str);
423
424 ret = sr_scpi_send(sdi->conn, command);
425 update_sample_rate = TRUE;
426 break;
427 }
428 break;
429 case SR_CONF_HORIZ_TRIGGERPOS:
430 tmp_d = g_variant_get_double(data);
431
432 if (tmp_d < 0.0 || tmp_d > 1.0)
433 return SR_ERR;
434
435 state->horiz_triggerpos = tmp_d;
436 tmp_d = -(tmp_d - 0.5) *
437 ((double) (*model->timebases)[state->timebase][0] /
438 (*model->timebases)[state->timebase][1])
439 * model->num_xdivs;
440
441 g_ascii_formatd(float_str, sizeof(float_str), "%E", tmp_d);
442 g_snprintf(command, sizeof(command),
443 (*model->scpi_dialect)[SCPI_CMD_SET_HORIZ_TRIGGERPOS],
444 float_str);
445
446 ret = sr_scpi_send(sdi->conn, command);
447 break;
448 case SR_CONF_TRIGGER_SLOPE:
449 tmp = g_variant_get_string(data, NULL);
450
451 if (!tmp || !(tmp[0] == 'f' || tmp[0] == 'r'))
452 return SR_ERR_ARG;
453
454 state->trigger_slope = (tmp[0] == 'r') ? 0 : 1;
455
456 g_snprintf(command, sizeof(command),
457 (*model->scpi_dialect)[SCPI_CMD_SET_TRIGGER_SLOPE],
458 (state->trigger_slope == 0) ? "POS" : "NEG");
459
460 ret = sr_scpi_send(sdi->conn, command);
461 break;
462 case SR_CONF_COUPLING:
463 if (cg_type == CG_NONE) {
464 sr_err("No channel group specified.");
465 return SR_ERR_CHANNEL_GROUP;
466 }
467
468 tmp = g_variant_get_string(data, NULL);
469
470 for (i = 0; (*model->coupling_options)[i]; i++) {
471 if (strcmp(tmp, (*model->coupling_options)[i]) != 0)
472 continue;
473 for (j = 1; j <= model->analog_channels; ++j) {
474 if (cg != &devc->analog_groups[j - 1])
475 continue;
476 state->analog_channels[j-1].coupling = i;
477
478 g_snprintf(command, sizeof(command),
479 (*model->scpi_dialect)[SCPI_CMD_SET_COUPLING],
480 j, tmp);
481
482 if (sr_scpi_send(sdi->conn, command) != SR_OK ||
483 sr_scpi_get_opc(sdi->conn) != SR_OK)
484 return SR_ERR;
485 break;
486 }
487
488 ret = SR_OK;
489 break;
490 }
491 break;
492 default:
493 ret = SR_ERR_NA;
494 break;
495 }
496
497 if (ret == SR_OK)
498 ret = sr_scpi_get_opc(sdi->conn);
499
500 if (ret == SR_OK && update_sample_rate)
501 ret = hmo_update_sample_rate(sdi);
502
503 return ret;
504}
505
506static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi,
507 const struct sr_channel_group *cg)
508{
509 int cg_type;
510 struct dev_context *devc;
511 struct scope_config *model;
512
513 if (!sdi || !(devc = sdi->priv))
514 return SR_ERR_ARG;
515
516 if ((cg_type = check_channel_group(devc, cg)) == CG_INVALID)
517 return SR_ERR;
518
519 model = devc->model_config;
520
521 switch (key) {
522 case SR_CONF_DEVICE_OPTIONS:
523 if (cg_type == CG_NONE) {
524 *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32,
525 model->hw_caps, model->num_hwcaps,
526 sizeof(int32_t));
527 } else if (cg_type == CG_ANALOG) {
528 *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32,
529 model->analog_hwcaps, model->num_analog_hwcaps,
530 sizeof(int32_t));
531 } else {
532 *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32,
533 NULL, 0, sizeof(int32_t));
534 }
535 break;
536 case SR_CONF_COUPLING:
537 if (cg_type == CG_NONE)
538 return SR_ERR_CHANNEL_GROUP;
539 *data = g_variant_new_strv(*model->coupling_options,
540 g_strv_length((char **)*model->coupling_options));
541 break;
542 case SR_CONF_TRIGGER_SOURCE:
543 *data = g_variant_new_strv(*model->trigger_sources,
544 g_strv_length((char **)*model->trigger_sources));
545 break;
546 case SR_CONF_TRIGGER_SLOPE:
547 *data = g_variant_new_strv(*model->trigger_slopes,
548 g_strv_length((char **)*model->trigger_slopes));
549 break;
550 case SR_CONF_TIMEBASE:
551 *data = build_tuples(model->timebases, model->num_timebases);
552 break;
553 case SR_CONF_VDIV:
554 if (cg_type == CG_NONE)
555 return SR_ERR_CHANNEL_GROUP;
556 *data = build_tuples(model->vdivs, model->num_vdivs);
557 break;
558 default:
559 return SR_ERR_NA;
560 }
561
562 return SR_OK;
563}
564
565SR_PRIV int hmo_request_data(const struct sr_dev_inst *sdi)
566{
567 char command[MAX_COMMAND_SIZE];
568 struct sr_channel *ch;
569 struct dev_context *devc;
570 struct scope_config *model;
571
572 devc = sdi->priv;
573 model = devc->model_config;
574
575 ch = devc->current_channel->data;
576
577 switch (ch->type) {
578 case SR_CHANNEL_ANALOG:
579 g_snprintf(command, sizeof(command),
580 (*model->scpi_dialect)[SCPI_CMD_GET_ANALOG_DATA],
581 ch->index + 1);
582 break;
583 case SR_CHANNEL_LOGIC:
584 g_snprintf(command, sizeof(command),
585 (*model->scpi_dialect)[SCPI_CMD_GET_DIG_DATA],
586 ch->index < 8 ? 1 : 2);
587 break;
588 default:
589 sr_err("Invalid channel type.");
590 break;
591 }
592
593 return sr_scpi_send(sdi->conn, command);
594}
595
596static int hmo_check_channels(GSList *channels)
597{
598 GSList *l;
599 struct sr_channel *ch;
600 gboolean enabled_pod1, enabled_pod2, enabled_chan3, enabled_chan4;
601
602 enabled_pod1 = enabled_pod2 = enabled_chan3 = enabled_chan4 = FALSE;
603
604 for (l = channels; l; l = l->next) {
605 ch = l->data;
606 switch (ch->type) {
607 case SR_CHANNEL_ANALOG:
608 if (ch->index == 2)
609 enabled_chan3 = TRUE;
610 else if (ch->index == 3)
611 enabled_chan4 = TRUE;
612 break;
613 case SR_CHANNEL_LOGIC:
614 if (ch->index < 8)
615 enabled_pod1 = TRUE;
616 else
617 enabled_pod2 = TRUE;
618 break;
619 default:
620 return SR_ERR;
621 }
622 }
623
624 if ((enabled_pod1 && enabled_chan3) ||
625 (enabled_pod2 && enabled_chan4))
626 return SR_ERR;
627
628 return SR_OK;
629}
630
631static int hmo_setup_channels(const struct sr_dev_inst *sdi)
632{
633 GSList *l;
634 unsigned int i;
635 gboolean *pod_enabled, setup_changed;
636 char command[MAX_COMMAND_SIZE];
637 struct scope_state *state;
638 struct scope_config *model;
639 struct sr_channel *ch;
640 struct dev_context *devc;
641 struct sr_scpi_dev_inst *scpi;
642
643 devc = sdi->priv;
644 scpi = sdi->conn;
645 state = devc->model_state;
646 model = devc->model_config;
647 setup_changed = FALSE;
648
649 pod_enabled = g_try_malloc0(sizeof(gboolean) * model->digital_pods);
650
651 for (l = sdi->channels; l; l = l->next) {
652 ch = l->data;
653 switch (ch->type) {
654 case SR_CHANNEL_ANALOG:
655 if (ch->enabled == state->analog_channels[ch->index].state)
656 break;
657 g_snprintf(command, sizeof(command),
658 (*model->scpi_dialect)[SCPI_CMD_SET_ANALOG_CHAN_STATE],
659 ch->index + 1, ch->enabled);
660
661 if (sr_scpi_send(scpi, command) != SR_OK)
662 return SR_ERR;
663 state->analog_channels[ch->index].state = ch->enabled;
664 setup_changed = TRUE;
665 break;
666 case SR_CHANNEL_LOGIC:
667 /*
668 * A digital POD needs to be enabled for every group of
669 * 8 channels.
670 */
671 if (ch->enabled)
672 pod_enabled[ch->index < 8 ? 0 : 1] = TRUE;
673
674 if (ch->enabled == state->digital_channels[ch->index])
675 break;
676 g_snprintf(command, sizeof(command),
677 (*model->scpi_dialect)[SCPI_CMD_SET_DIG_CHAN_STATE],
678 ch->index, ch->enabled);
679
680 if (sr_scpi_send(scpi, command) != SR_OK)
681 return SR_ERR;
682
683 state->digital_channels[ch->index] = ch->enabled;
684 setup_changed = TRUE;
685 break;
686 default:
687 return SR_ERR;
688 }
689 }
690
691 for (i = 1; i <= model->digital_pods; ++i) {
692 if (state->digital_pods[i - 1] == pod_enabled[i - 1])
693 continue;
694 g_snprintf(command, sizeof(command),
695 (*model->scpi_dialect)[SCPI_CMD_SET_DIG_POD_STATE],
696 i, pod_enabled[i - 1]);
697 if (sr_scpi_send(scpi, command) != SR_OK)
698 return SR_ERR;
699 state->digital_pods[i - 1] = pod_enabled[i - 1];
700 setup_changed = TRUE;
701 }
702
703 g_free(pod_enabled);
704
705 if (setup_changed && hmo_update_sample_rate(sdi) != SR_OK)
706 return SR_ERR;
707
708 return SR_OK;
709}
710
711static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
712{
713 GSList *l;
714 gboolean digital_added;
715 struct sr_channel *ch;
716 struct dev_context *devc;
717 struct sr_scpi_dev_inst *scpi;
718
719 if (sdi->status != SR_ST_ACTIVE)
720 return SR_ERR_DEV_CLOSED;
721
722 scpi = sdi->conn;
723 devc = sdi->priv;
724 digital_added = FALSE;
725
726 for (l = sdi->channels; l; l = l->next) {
727 ch = l->data;
728 if (!ch->enabled)
729 continue;
730 /* Only add a single digital channel. */
731 if (ch->type != SR_CHANNEL_LOGIC || !digital_added) {
732 devc->enabled_channels = g_slist_append(
733 devc->enabled_channels, ch);
734 if (ch->type == SR_CHANNEL_LOGIC)
735 digital_added = TRUE;
736 }
737 }
738
739 if (!devc->enabled_channels)
740 return SR_ERR;
741
742 if (hmo_check_channels(devc->enabled_channels) != SR_OK) {
743 sr_err("Invalid channel configuration specified!");
744 return SR_ERR_NA;
745 }
746
747 if (hmo_setup_channels(sdi) != SR_OK) {
748 sr_err("Failed to setup channel configuration!");
749 return SR_ERR;
750 }
751
752 sr_scpi_source_add(sdi->session, scpi, G_IO_IN, 50,
753 hmo_receive_data, (void *)sdi);
754
755 /* Send header packet to the session bus. */
756 std_session_send_df_header(cb_data, LOG_PREFIX);
757
758 devc->current_channel = devc->enabled_channels;
759
760 return hmo_request_data(sdi);
761}
762
763static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
764{
765 struct dev_context *devc;
766 struct sr_scpi_dev_inst *scpi;
767 struct sr_datafeed_packet packet;
768
769 (void)cb_data;
770
771 packet.type = SR_DF_END;
772 packet.payload = NULL;
773 sr_session_send(sdi, &packet);
774
775 if (sdi->status != SR_ST_ACTIVE)
776 return SR_ERR_DEV_CLOSED;
777
778 devc = sdi->priv;
779
780 devc->num_frames = 0;
781 g_slist_free(devc->enabled_channels);
782 devc->enabled_channels = NULL;
783 scpi = sdi->conn;
784 sr_scpi_source_remove(sdi->session, scpi);
785
786 return SR_OK;
787}
788
789SR_PRIV struct sr_dev_driver hameg_hmo_driver_info = {
790 .name = "hameg-hmo",
791 .longname = "Hameg HMO",
792 .api_version = 1,
793 .init = init,
794 .cleanup = cleanup,
795 .scan = scan,
796 .dev_list = dev_list,
797 .dev_clear = dev_clear,
798 .config_get = config_get,
799 .config_set = config_set,
800 .config_list = config_list,
801 .dev_open = dev_open,
802 .dev_close = dev_close,
803 .dev_acquisition_start = dev_acquisition_start,
804 .dev_acquisition_stop = dev_acquisition_stop,
805 .priv = NULL,
806};