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