2 * This file is part of the libsigrok project.
4 * Copyright (C) 2013 poljar (Damir Jelić) <poljarinho@gmail.com>
5 * Copyright (C) 2018 Guido Trentalancia <guido@trentalancia.com>
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
26 static struct sr_dev_driver hameg_hmo_driver_info;
28 static const char *manufacturers[] = {
33 static const uint32_t scanopts[] = {
38 static const uint32_t drvopts[] = {
40 SR_CONF_LOGIC_ANALYZER,
50 static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi)
52 struct sr_dev_inst *sdi;
53 struct dev_context *devc;
54 struct sr_scpi_hw_info *hw_info;
60 if (sr_scpi_get_hw_id(scpi, &hw_info) != SR_OK) {
61 sr_info("Couldn't get IDN response.");
65 if (std_str_idx_s(hw_info->manufacturer, ARRAY_AND_SIZE(manufacturers)) < 0)
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;
77 sr_scpi_hw_info_free(hw_info);
80 devc = g_malloc0(sizeof(struct dev_context));
84 if (hmo_init_device(sdi) != SR_OK)
90 sr_scpi_hw_info_free(hw_info);
91 sr_dev_inst_free(sdi);
97 static GSList *scan(struct sr_dev_driver *di, GSList *options)
99 return sr_scpi_scan(di->context, options, probe_device);
102 static void clear_helper(struct dev_context *devc)
104 hmo_scope_state_free(devc->model_state);
105 g_free(devc->analog_groups);
106 g_free(devc->digital_groups);
109 static int dev_clear(const struct sr_dev_driver *di)
111 return std_dev_clear_with_callback(di, (std_dev_clear_callback)clear_helper);
114 static int dev_open(struct sr_dev_inst *sdi)
116 if (sr_scpi_open(sdi->conn) != SR_OK)
119 if (hmo_scope_state_get(sdi) != SR_OK)
125 static int dev_close(struct sr_dev_inst *sdi)
127 return sr_scpi_close(sdi->conn);
130 static int check_channel_group(struct dev_context *devc,
131 const struct sr_channel_group *cg)
133 const struct scope_config *model;
135 model = devc->model_config;
140 if (std_cg_idx(cg, devc->analog_groups, model->analog_channels) >= 0)
143 if (std_cg_idx(cg, devc->digital_groups, model->digital_pods) >= 0)
146 sr_err("Invalid channel group specified.");
151 static int config_get(uint32_t key, GVariant **data,
152 const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
155 struct dev_context *devc;
156 const struct scope_config *model;
157 struct scope_state *state;
164 if ((cg_type = check_channel_group(devc, cg)) == CG_INVALID)
167 model = devc->model_config;
168 state = devc->model_state;
171 case SR_CONF_NUM_HDIV:
172 *data = g_variant_new_int32(model->num_xdivs);
174 case SR_CONF_TIMEBASE:
175 *data = g_variant_new("(tt)", (*model->timebases)[state->timebase][0],
176 (*model->timebases)[state->timebase][1]);
178 case SR_CONF_NUM_VDIV:
180 return SR_ERR_CHANNEL_GROUP;
181 if (cg_type != CG_ANALOG)
183 if (std_cg_idx(cg, devc->analog_groups, model->analog_channels) < 0)
185 *data = g_variant_new_int32(model->num_ydivs);
189 return SR_ERR_CHANNEL_GROUP;
190 if (cg_type != CG_ANALOG)
192 if ((idx = std_cg_idx(cg, devc->analog_groups, model->analog_channels)) < 0)
194 *data = g_variant_new("(tt)",
195 (*model->vdivs)[state->analog_channels[idx].vdiv][0],
196 (*model->vdivs)[state->analog_channels[idx].vdiv][1]);
198 case SR_CONF_TRIGGER_SOURCE:
199 *data = g_variant_new_string((*model->trigger_sources)[state->trigger_source]);
201 case SR_CONF_TRIGGER_SLOPE:
202 *data = g_variant_new_string((*model->trigger_slopes)[state->trigger_slope]);
204 case SR_CONF_TRIGGER_PATTERN:
205 *data = g_variant_new_string(state->trigger_pattern);
207 case SR_CONF_HIGH_RESOLUTION:
208 *data = g_variant_new_boolean(state->high_resolution);
210 case SR_CONF_PEAK_DETECTION:
211 *data = g_variant_new_boolean(state->peak_detection);
213 case SR_CONF_HORIZ_TRIGGERPOS:
214 *data = g_variant_new_double(state->horiz_triggerpos);
216 case SR_CONF_COUPLING:
218 return SR_ERR_CHANNEL_GROUP;
219 if (cg_type != CG_ANALOG)
221 if ((idx = std_cg_idx(cg, devc->analog_groups, model->analog_channels)) < 0)
223 *data = g_variant_new_string((*model->coupling_options)[state->analog_channels[idx].coupling]);
225 case SR_CONF_SAMPLERATE:
226 *data = g_variant_new_uint64(state->sample_rate);
228 case SR_CONF_LOGIC_THRESHOLD:
230 return SR_ERR_CHANNEL_GROUP;
231 if (cg_type != CG_DIGITAL)
235 if ((idx = std_cg_idx(cg, devc->digital_groups, model->digital_pods)) < 0)
237 *data = g_variant_new_string((*model->logic_threshold)[state->digital_pods[idx].threshold]);
239 case SR_CONF_LOGIC_THRESHOLD_CUSTOM:
241 return SR_ERR_CHANNEL_GROUP;
242 if (cg_type != CG_DIGITAL)
246 if ((idx = std_cg_idx(cg, devc->digital_groups, model->digital_pods)) < 0)
248 /* Check if the oscilloscope is currently in custom threshold mode. */
249 for (i = 0; i < model->num_logic_threshold; i++) {
250 if (!strcmp("USER2", (*model->logic_threshold)[i]))
251 if (strcmp("USER2", (*model->logic_threshold)[state->digital_pods[idx].threshold]))
253 if (!strcmp("USER", (*model->logic_threshold)[i]))
254 if (strcmp("USER", (*model->logic_threshold)[state->digital_pods[idx].threshold]))
256 if (!strcmp("MAN", (*model->logic_threshold)[i]))
257 if (strcmp("MAN", (*model->logic_threshold)[state->digital_pods[idx].threshold]))
260 *data = g_variant_new_double(state->digital_pods[idx].user_threshold);
262 case SR_CONF_LIMIT_FRAMES:
263 *data = g_variant_new_uint64(devc->frame_limit);
272 static int config_set(uint32_t key, GVariant *data,
273 const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
275 int ret, cg_type, idx, i, j;
276 char command[MAX_COMMAND_SIZE], command2[MAX_COMMAND_SIZE];
277 char float_str[30], *tmp_str;
278 struct dev_context *devc;
279 const struct scope_config *model;
280 struct scope_state *state;
281 double tmp_d, tmp_d2;
282 gboolean update_sample_rate, tmp_bool;
289 if ((cg_type = check_channel_group(devc, cg)) == CG_INVALID)
292 model = devc->model_config;
293 state = devc->model_state;
294 update_sample_rate = FALSE;
297 case SR_CONF_LIMIT_SAMPLES:
298 devc->samples_limit = g_variant_get_uint64(data);
301 case SR_CONF_LIMIT_FRAMES:
302 devc->frame_limit = g_variant_get_uint64(data);
307 return SR_ERR_CHANNEL_GROUP;
308 if ((idx = std_u64_tuple_idx(data, *model->vdivs, model->num_vdivs)) < 0)
310 if ((j = std_cg_idx(cg, devc->analog_groups, model->analog_channels)) < 0)
312 g_ascii_formatd(float_str, sizeof(float_str), "%E",
313 (float) (*model->vdivs)[idx][0] / (*model->vdivs)[idx][1]);
314 g_snprintf(command, sizeof(command),
315 (*model->scpi_dialect)[SCPI_CMD_SET_VERTICAL_SCALE],
317 if (sr_scpi_send(sdi->conn, command) != SR_OK ||
318 sr_scpi_get_opc(sdi->conn) != SR_OK)
320 state->analog_channels[j].vdiv = idx;
323 case SR_CONF_TIMEBASE:
324 if ((idx = std_u64_tuple_idx(data, *model->timebases, model->num_timebases)) < 0)
326 g_ascii_formatd(float_str, sizeof(float_str), "%E",
327 (float) (*model->timebases)[idx][0] / (*model->timebases)[idx][1]);
328 g_snprintf(command, sizeof(command),
329 (*model->scpi_dialect)[SCPI_CMD_SET_TIMEBASE],
331 if (sr_scpi_send(sdi->conn, command) != SR_OK ||
332 sr_scpi_get_opc(sdi->conn) != SR_OK)
334 state->timebase = idx;
336 update_sample_rate = TRUE;
338 case SR_CONF_HORIZ_TRIGGERPOS:
339 tmp_d = g_variant_get_double(data);
340 if (tmp_d < 0.0 || tmp_d > 1.0)
342 tmp_d2 = -(tmp_d - 0.5) *
343 ((double) (*model->timebases)[state->timebase][0] /
344 (*model->timebases)[state->timebase][1])
346 g_ascii_formatd(float_str, sizeof(float_str), "%E", tmp_d2);
347 g_snprintf(command, sizeof(command),
348 (*model->scpi_dialect)[SCPI_CMD_SET_HORIZ_TRIGGERPOS],
350 if (sr_scpi_send(sdi->conn, command) != SR_OK ||
351 sr_scpi_get_opc(sdi->conn) != SR_OK)
353 state->horiz_triggerpos = tmp_d;
356 case SR_CONF_TRIGGER_SOURCE:
357 if ((idx = std_str_idx(data, *model->trigger_sources, model->num_trigger_sources)) < 0)
359 g_snprintf(command, sizeof(command),
360 (*model->scpi_dialect)[SCPI_CMD_SET_TRIGGER_SOURCE],
361 (*model->trigger_sources)[idx]);
362 if (sr_scpi_send(sdi->conn, command) != SR_OK ||
363 sr_scpi_get_opc(sdi->conn) != SR_OK)
365 state->trigger_source = idx;
368 case SR_CONF_TRIGGER_SLOPE:
369 if ((idx = std_str_idx(data, *model->trigger_slopes, model->num_trigger_slopes)) < 0)
371 g_snprintf(command, sizeof(command),
372 (*model->scpi_dialect)[SCPI_CMD_SET_TRIGGER_SLOPE],
373 (*model->trigger_slopes)[idx]);
374 if (sr_scpi_send(sdi->conn, command) != SR_OK ||
375 sr_scpi_get_opc(sdi->conn) != SR_OK)
377 state->trigger_slope = idx;
380 case SR_CONF_TRIGGER_PATTERN:
381 tmp_str = (char *)g_variant_get_string(data, 0);
382 idx = strlen(tmp_str);
383 if (idx == 0 || idx > model->analog_channels + model->digital_channels)
385 g_snprintf(command, sizeof(command),
386 (*model->scpi_dialect)[SCPI_CMD_SET_TRIGGER_PATTERN],
388 if (sr_scpi_send(sdi->conn, command) != SR_OK ||
389 sr_scpi_get_opc(sdi->conn) != SR_OK)
391 strncpy(state->trigger_pattern,
393 MAX_ANALOG_CHANNEL_COUNT + MAX_DIGITAL_CHANNEL_COUNT);
396 case SR_CONF_HIGH_RESOLUTION:
397 tmp_bool = g_variant_get_boolean(data);
398 g_snprintf(command, sizeof(command),
399 (*model->scpi_dialect)[SCPI_CMD_SET_HIGH_RESOLUTION],
400 tmp_bool ? "AUTO" : "OFF");
401 if (sr_scpi_send(sdi->conn, command) != SR_OK ||
402 sr_scpi_get_opc(sdi->conn) != SR_OK)
404 /* High Resolution mode automatically switches off Peak Detection. */
406 g_snprintf(command, sizeof(command),
407 (*model->scpi_dialect)[SCPI_CMD_SET_PEAK_DETECTION],
409 if (sr_scpi_send(sdi->conn, command) != SR_OK ||
410 sr_scpi_get_opc(sdi->conn) != SR_OK)
412 state->peak_detection = FALSE;
414 state->high_resolution = tmp_bool;
417 case SR_CONF_PEAK_DETECTION:
418 tmp_bool = g_variant_get_boolean(data);
419 g_snprintf(command, sizeof(command),
420 (*model->scpi_dialect)[SCPI_CMD_SET_PEAK_DETECTION],
421 tmp_bool ? "AUTO" : "OFF");
422 if (sr_scpi_send(sdi->conn, command) != SR_OK ||
423 sr_scpi_get_opc(sdi->conn) != SR_OK)
425 /* Peak Detection automatically switches off High Resolution mode. */
427 g_snprintf(command, sizeof(command),
428 (*model->scpi_dialect)[SCPI_CMD_SET_HIGH_RESOLUTION],
430 if (sr_scpi_send(sdi->conn, command) != SR_OK ||
431 sr_scpi_get_opc(sdi->conn) != SR_OK)
433 state->high_resolution = FALSE;
435 state->peak_detection = tmp_bool;
438 case SR_CONF_COUPLING:
440 return SR_ERR_CHANNEL_GROUP;
441 if ((idx = std_str_idx(data, *model->coupling_options, model->num_coupling_options)) < 0)
443 if ((j = std_cg_idx(cg, devc->analog_groups, model->analog_channels)) < 0)
445 g_snprintf(command, sizeof(command),
446 (*model->scpi_dialect)[SCPI_CMD_SET_COUPLING],
447 j + 1, (*model->coupling_options)[idx]);
448 if (sr_scpi_send(sdi->conn, command) != SR_OK ||
449 sr_scpi_get_opc(sdi->conn) != SR_OK)
451 state->analog_channels[j].coupling = idx;
454 case SR_CONF_LOGIC_THRESHOLD:
456 return SR_ERR_CHANNEL_GROUP;
457 if (cg_type != CG_DIGITAL)
461 if ((idx = std_str_idx(data, *model->logic_threshold, model->num_logic_threshold)) < 0)
463 if ((j = std_cg_idx(cg, devc->digital_groups, model->digital_pods)) < 0)
465 /* Check if the threshold command is based on the POD or digital channel index. */
466 if (model->logic_threshold_for_pod)
469 i = j * DIGITAL_CHANNELS_PER_POD;
470 g_snprintf(command, sizeof(command),
471 (*model->scpi_dialect)[SCPI_CMD_SET_DIG_POD_THRESHOLD],
472 i, (*model->logic_threshold)[idx]);
473 if (sr_scpi_send(sdi->conn, command) != SR_OK ||
474 sr_scpi_get_opc(sdi->conn) != SR_OK)
476 state->digital_pods[j].threshold = idx;
479 case SR_CONF_LOGIC_THRESHOLD_CUSTOM:
481 return SR_ERR_CHANNEL_GROUP;
482 if (cg_type != CG_DIGITAL)
486 if ((j = std_cg_idx(cg, devc->digital_groups, model->digital_pods)) < 0)
488 tmp_d = g_variant_get_double(data);
489 if (tmp_d < -2.0 || tmp_d > 8.0)
491 g_ascii_formatd(float_str, sizeof(float_str), "%E", tmp_d);
492 /* Check if the threshold command is based on the POD or digital channel index. */
493 if (model->logic_threshold_for_pod)
496 idx = j * DIGITAL_CHANNELS_PER_POD;
497 /* Try to support different dialects exhaustively. */
498 for (i = 0; i < model->num_logic_threshold; i++) {
499 if (!strcmp("USER2", (*model->logic_threshold)[i])) {
500 g_snprintf(command, sizeof(command),
501 (*model->scpi_dialect)[SCPI_CMD_SET_DIG_POD_USER_THRESHOLD],
502 idx, 2, float_str); /* USER2 */
503 g_snprintf(command2, sizeof(command2),
504 (*model->scpi_dialect)[SCPI_CMD_SET_DIG_POD_THRESHOLD],
508 if (!strcmp("USER", (*model->logic_threshold)[i])) {
509 g_snprintf(command, sizeof(command),
510 (*model->scpi_dialect)[SCPI_CMD_SET_DIG_POD_USER_THRESHOLD],
512 g_snprintf(command2, sizeof(command2),
513 (*model->scpi_dialect)[SCPI_CMD_SET_DIG_POD_THRESHOLD],
517 if (!strcmp("MAN", (*model->logic_threshold)[i])) {
518 g_snprintf(command, sizeof(command),
519 (*model->scpi_dialect)[SCPI_CMD_SET_DIG_POD_USER_THRESHOLD],
521 g_snprintf(command2, sizeof(command2),
522 (*model->scpi_dialect)[SCPI_CMD_SET_DIG_POD_THRESHOLD],
527 if (sr_scpi_send(sdi->conn, command) != SR_OK ||
528 sr_scpi_get_opc(sdi->conn) != SR_OK)
530 if (sr_scpi_send(sdi->conn, command2) != SR_OK ||
531 sr_scpi_get_opc(sdi->conn) != SR_OK)
533 state->digital_pods[j].user_threshold = tmp_d;
541 if (ret == SR_OK && update_sample_rate)
542 ret = hmo_update_sample_rate(sdi);
547 static int config_list(uint32_t key, GVariant **data,
548 const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
550 int cg_type = CG_NONE;
551 struct dev_context *devc = NULL;
552 const struct scope_config *model = NULL;
556 if ((cg_type = check_channel_group(devc, cg)) == CG_INVALID)
559 model = devc->model_config;
563 case SR_CONF_SCAN_OPTIONS:
564 *data = std_gvar_array_u32(ARRAY_AND_SIZE(scanopts));
566 case SR_CONF_DEVICE_OPTIONS:
569 *data = std_gvar_array_u32(*model->devopts, model->num_devopts);
571 *data = std_gvar_array_u32(ARRAY_AND_SIZE(drvopts));
572 } else if (cg_type == CG_ANALOG) {
573 *data = std_gvar_array_u32(*model->devopts_cg_analog, model->num_devopts_cg_analog);
574 } else if (cg_type == CG_DIGITAL) {
575 *data = std_gvar_array_u32(*model->devopts_cg_digital, model->num_devopts_cg_digital);
577 *data = std_gvar_array_u32(NULL, 0);
580 case SR_CONF_COUPLING:
582 return SR_ERR_CHANNEL_GROUP;
585 *data = g_variant_new_strv(*model->coupling_options, model->num_coupling_options);
587 case SR_CONF_TRIGGER_SOURCE:
590 *data = g_variant_new_strv(*model->trigger_sources, model->num_trigger_sources);
592 case SR_CONF_TRIGGER_SLOPE:
595 *data = g_variant_new_strv(*model->trigger_slopes, model->num_trigger_slopes);
597 case SR_CONF_TIMEBASE:
600 *data = std_gvar_tuple_array(*model->timebases, model->num_timebases);
604 return SR_ERR_CHANNEL_GROUP;
607 *data = std_gvar_tuple_array(*model->vdivs, model->num_vdivs);
609 case SR_CONF_LOGIC_THRESHOLD:
611 return SR_ERR_CHANNEL_GROUP;
614 *data = g_variant_new_strv(*model->logic_threshold, model->num_logic_threshold);
623 SR_PRIV int hmo_request_data(const struct sr_dev_inst *sdi)
625 char command[MAX_COMMAND_SIZE];
626 struct sr_channel *ch;
627 struct dev_context *devc;
628 const struct scope_config *model;
631 model = devc->model_config;
633 ch = devc->current_channel->data;
636 case SR_CHANNEL_ANALOG:
637 g_snprintf(command, sizeof(command),
638 (*model->scpi_dialect)[SCPI_CMD_GET_ANALOG_DATA],
639 #ifdef WORDS_BIGENDIAN
646 case SR_CHANNEL_LOGIC:
647 g_snprintf(command, sizeof(command),
648 (*model->scpi_dialect)[SCPI_CMD_GET_DIG_DATA],
649 ch->index / DIGITAL_CHANNELS_PER_POD + 1);
652 sr_err("Invalid channel type.");
656 return sr_scpi_send(sdi->conn, command);
659 static int hmo_check_channels(GSList *channels)
662 struct sr_channel *ch;
663 gboolean enabled_chan[MAX_ANALOG_CHANNEL_COUNT];
664 gboolean enabled_pod[MAX_DIGITAL_GROUP_COUNT];
667 /* Preset "not enabled" for all channels / pods. */
668 for (idx = 0; idx < ARRAY_SIZE(enabled_chan); idx++)
669 enabled_chan[idx] = FALSE;
670 for (idx = 0; idx < ARRAY_SIZE(enabled_pod); idx++)
671 enabled_pod[idx] = FALSE;
674 * Determine which channels / pods are required for the caller's
675 * specified configuration.
677 for (l = channels; l; l = l->next) {
680 case SR_CHANNEL_ANALOG:
682 if (idx < ARRAY_SIZE(enabled_chan))
683 enabled_chan[idx] = TRUE;
685 case SR_CHANNEL_LOGIC:
686 idx = ch->index / DIGITAL_CHANNELS_PER_POD;
687 if (idx < ARRAY_SIZE(enabled_pod))
688 enabled_pod[idx] = TRUE;
696 * Check for resource conflicts. Some channels can be either
697 * analog or digital, but never both at the same time.
699 * Note that the constraints might depend on the specific model.
700 * These tests might need some adjustment when support for more
701 * models gets added to the driver.
703 if (enabled_pod[0] && enabled_chan[2])
705 if (enabled_pod[1] && enabled_chan[3])
710 static int hmo_setup_channels(const struct sr_dev_inst *sdi)
714 gboolean *pod_enabled, setup_changed;
715 char command[MAX_COMMAND_SIZE];
716 struct scope_state *state;
717 const struct scope_config *model;
718 struct sr_channel *ch;
719 struct dev_context *devc;
720 struct sr_scpi_dev_inst *scpi;
725 state = devc->model_state;
726 model = devc->model_config;
727 setup_changed = FALSE;
729 pod_enabled = g_try_malloc0(sizeof(gboolean) * model->digital_pods);
731 for (l = sdi->channels; l; l = l->next) {
734 case SR_CHANNEL_ANALOG:
735 if (ch->enabled == state->analog_channels[ch->index].state)
737 g_snprintf(command, sizeof(command),
738 (*model->scpi_dialect)[SCPI_CMD_SET_ANALOG_CHAN_STATE],
739 ch->index + 1, ch->enabled);
741 if (sr_scpi_send(scpi, command) != SR_OK) {
745 state->analog_channels[ch->index].state = ch->enabled;
746 setup_changed = TRUE;
748 case SR_CHANNEL_LOGIC:
750 * A digital POD needs to be enabled for every group of
751 * DIGITAL_CHANNELS_PER_POD channels.
754 pod_enabled[ch->index / DIGITAL_CHANNELS_PER_POD] = TRUE;
756 if (ch->enabled == state->digital_channels[ch->index])
758 g_snprintf(command, sizeof(command),
759 (*model->scpi_dialect)[SCPI_CMD_SET_DIG_CHAN_STATE],
760 ch->index, ch->enabled);
762 if (sr_scpi_send(scpi, command) != SR_OK) {
767 state->digital_channels[ch->index] = ch->enabled;
768 setup_changed = TRUE;
777 for (i = 0; i < model->digital_pods; i++) {
778 if (state->digital_pods[i].state == pod_enabled[i])
780 g_snprintf(command, sizeof(command),
781 (*model->scpi_dialect)[SCPI_CMD_SET_DIG_POD_STATE],
782 i + 1, pod_enabled[i]);
783 if (sr_scpi_send(scpi, command) != SR_OK) {
787 state->digital_pods[i].state = pod_enabled[i];
788 setup_changed = TRUE;
794 if (setup_changed && hmo_update_sample_rate(sdi) != SR_OK)
800 static int dev_acquisition_start(const struct sr_dev_inst *sdi)
803 gboolean digital_added[MAX_DIGITAL_GROUP_COUNT];
804 size_t group, pod_count;
805 struct sr_channel *ch;
806 struct dev_context *devc;
807 struct sr_scpi_dev_inst *scpi;
813 devc->num_samples = 0;
814 devc->num_frames = 0;
816 /* Preset empty results. */
817 for (group = 0; group < ARRAY_SIZE(digital_added); group++)
818 digital_added[group] = FALSE;
819 g_slist_free(devc->enabled_channels);
820 devc->enabled_channels = NULL;
823 * Contruct the list of enabled channels. Determine the highest
824 * number of digital pods involved in the acquisition.
827 for (l = sdi->channels; l; l = l->next) {
831 /* Only add a single digital channel per group (pod). */
832 group = ch->index / DIGITAL_CHANNELS_PER_POD;
833 if (ch->type != SR_CHANNEL_LOGIC || !digital_added[group]) {
834 devc->enabled_channels = g_slist_append(
835 devc->enabled_channels, ch);
836 if (ch->type == SR_CHANNEL_LOGIC) {
837 digital_added[group] = TRUE;
838 if (pod_count < group + 1)
839 pod_count = group + 1;
843 if (!devc->enabled_channels)
845 devc->pod_count = pod_count;
846 devc->logic_data = NULL;
849 * Check constraints. Some channels can be either analog or
850 * digital, but not both at the same time.
852 if (hmo_check_channels(devc->enabled_channels) != SR_OK) {
853 sr_err("Invalid channel configuration specified!");
859 * Configure the analog and digital channels and the
860 * corresponding digital pods.
862 if (hmo_setup_channels(sdi) != SR_OK) {
863 sr_err("Failed to setup channel configuration!");
869 * Start acquisition on the first enabled channel. The
870 * receive routine will continue driving the acquisition.
872 sr_scpi_source_add(sdi->session, scpi, G_IO_IN, 50,
873 hmo_receive_data, (void *)sdi);
875 std_session_send_df_header(sdi);
877 devc->current_channel = devc->enabled_channels;
879 return hmo_request_data(sdi);
882 g_slist_free(devc->enabled_channels);
883 devc->enabled_channels = NULL;
887 static int dev_acquisition_stop(struct sr_dev_inst *sdi)
889 struct dev_context *devc;
890 struct sr_scpi_dev_inst *scpi;
892 std_session_send_df_end(sdi);
896 devc->num_samples = 0;
897 devc->num_frames = 0;
898 g_slist_free(devc->enabled_channels);
899 devc->enabled_channels = NULL;
901 sr_scpi_source_remove(sdi->session, scpi);
906 static struct sr_dev_driver hameg_hmo_driver_info = {
908 .longname = "Hameg HMO",
911 .cleanup = std_cleanup,
913 .dev_list = std_dev_list,
914 .dev_clear = dev_clear,
915 .config_get = config_get,
916 .config_set = config_set,
917 .config_list = config_list,
918 .dev_open = dev_open,
919 .dev_close = dev_close,
920 .dev_acquisition_start = dev_acquisition_start,
921 .dev_acquisition_stop = dev_acquisition_stop,
924 SR_REGISTER_DEV_DRIVER(hameg_hmo_driver_info);