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);
269 static int config_set(uint32_t key, GVariant *data,
270 const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
272 int ret, cg_type, idx, i, j;
273 char command[MAX_COMMAND_SIZE], command2[MAX_COMMAND_SIZE];
274 char float_str[30], *tmp_str;
275 struct dev_context *devc;
276 const struct scope_config *model;
277 struct scope_state *state;
278 double tmp_d, tmp_d2;
279 gboolean update_sample_rate, tmp_bool;
286 if ((cg_type = check_channel_group(devc, cg)) == CG_INVALID)
289 model = devc->model_config;
290 state = devc->model_state;
291 update_sample_rate = FALSE;
294 case SR_CONF_LIMIT_SAMPLES:
295 devc->samples_limit = g_variant_get_uint64(data);
298 case SR_CONF_LIMIT_FRAMES:
299 devc->frame_limit = g_variant_get_uint64(data);
304 return SR_ERR_CHANNEL_GROUP;
305 if ((idx = std_u64_tuple_idx(data, *model->vdivs, model->num_vdivs)) < 0)
307 if ((j = std_cg_idx(cg, devc->analog_groups, model->analog_channels)) < 0)
309 g_ascii_formatd(float_str, sizeof(float_str), "%E",
310 (float) (*model->vdivs)[idx][0] / (*model->vdivs)[idx][1]);
311 g_snprintf(command, sizeof(command),
312 (*model->scpi_dialect)[SCPI_CMD_SET_VERTICAL_SCALE],
314 if (sr_scpi_send(sdi->conn, command) != SR_OK ||
315 sr_scpi_get_opc(sdi->conn) != SR_OK)
317 state->analog_channels[j].vdiv = idx;
320 case SR_CONF_TIMEBASE:
321 if ((idx = std_u64_tuple_idx(data, *model->timebases, model->num_timebases)) < 0)
323 g_ascii_formatd(float_str, sizeof(float_str), "%E",
324 (float) (*model->timebases)[idx][0] / (*model->timebases)[idx][1]);
325 g_snprintf(command, sizeof(command),
326 (*model->scpi_dialect)[SCPI_CMD_SET_TIMEBASE],
328 if (sr_scpi_send(sdi->conn, command) != SR_OK ||
329 sr_scpi_get_opc(sdi->conn) != SR_OK)
331 state->timebase = idx;
333 update_sample_rate = TRUE;
335 case SR_CONF_HORIZ_TRIGGERPOS:
336 tmp_d = g_variant_get_double(data);
337 if (tmp_d < 0.0 || tmp_d > 1.0)
339 tmp_d2 = -(tmp_d - 0.5) *
340 ((double) (*model->timebases)[state->timebase][0] /
341 (*model->timebases)[state->timebase][1])
343 g_ascii_formatd(float_str, sizeof(float_str), "%E", tmp_d2);
344 g_snprintf(command, sizeof(command),
345 (*model->scpi_dialect)[SCPI_CMD_SET_HORIZ_TRIGGERPOS],
347 if (sr_scpi_send(sdi->conn, command) != SR_OK ||
348 sr_scpi_get_opc(sdi->conn) != SR_OK)
350 state->horiz_triggerpos = tmp_d;
353 case SR_CONF_TRIGGER_SOURCE:
354 if ((idx = std_str_idx(data, *model->trigger_sources, model->num_trigger_sources)) < 0)
356 g_snprintf(command, sizeof(command),
357 (*model->scpi_dialect)[SCPI_CMD_SET_TRIGGER_SOURCE],
358 (*model->trigger_sources)[idx]);
359 if (sr_scpi_send(sdi->conn, command) != SR_OK ||
360 sr_scpi_get_opc(sdi->conn) != SR_OK)
362 state->trigger_source = idx;
365 case SR_CONF_TRIGGER_SLOPE:
366 if ((idx = std_str_idx(data, *model->trigger_slopes, model->num_trigger_slopes)) < 0)
368 g_snprintf(command, sizeof(command),
369 (*model->scpi_dialect)[SCPI_CMD_SET_TRIGGER_SLOPE],
370 (*model->trigger_slopes)[idx]);
371 if (sr_scpi_send(sdi->conn, command) != SR_OK ||
372 sr_scpi_get_opc(sdi->conn) != SR_OK)
374 state->trigger_slope = idx;
377 case SR_CONF_TRIGGER_PATTERN:
378 tmp_str = (char *)g_variant_get_string(data, 0);
379 idx = strlen(tmp_str);
380 if (idx == 0 || idx > model->analog_channels + model->digital_channels)
382 g_snprintf(command, sizeof(command),
383 (*model->scpi_dialect)[SCPI_CMD_SET_TRIGGER_PATTERN],
385 if (sr_scpi_send(sdi->conn, command) != SR_OK ||
386 sr_scpi_get_opc(sdi->conn) != SR_OK)
388 strncpy(state->trigger_pattern,
390 MAX_ANALOG_CHANNEL_COUNT + MAX_DIGITAL_CHANNEL_COUNT);
393 case SR_CONF_HIGH_RESOLUTION:
394 tmp_bool = g_variant_get_boolean(data);
395 g_snprintf(command, sizeof(command),
396 (*model->scpi_dialect)[SCPI_CMD_SET_HIGH_RESOLUTION],
397 tmp_bool ? "AUTO" : "OFF");
398 if (sr_scpi_send(sdi->conn, command) != SR_OK ||
399 sr_scpi_get_opc(sdi->conn) != SR_OK)
401 /* High Resolution mode automatically switches off Peak Detection. */
403 g_snprintf(command, sizeof(command),
404 (*model->scpi_dialect)[SCPI_CMD_SET_PEAK_DETECTION],
406 if (sr_scpi_send(sdi->conn, command) != SR_OK ||
407 sr_scpi_get_opc(sdi->conn) != SR_OK)
409 state->peak_detection = FALSE;
411 state->high_resolution = tmp_bool;
414 case SR_CONF_PEAK_DETECTION:
415 tmp_bool = g_variant_get_boolean(data);
416 g_snprintf(command, sizeof(command),
417 (*model->scpi_dialect)[SCPI_CMD_SET_PEAK_DETECTION],
418 tmp_bool ? "AUTO" : "OFF");
419 if (sr_scpi_send(sdi->conn, command) != SR_OK ||
420 sr_scpi_get_opc(sdi->conn) != SR_OK)
422 /* Peak Detection automatically switches off High Resolution mode. */
424 g_snprintf(command, sizeof(command),
425 (*model->scpi_dialect)[SCPI_CMD_SET_HIGH_RESOLUTION],
427 if (sr_scpi_send(sdi->conn, command) != SR_OK ||
428 sr_scpi_get_opc(sdi->conn) != SR_OK)
430 state->high_resolution = FALSE;
432 state->peak_detection = tmp_bool;
435 case SR_CONF_COUPLING:
437 return SR_ERR_CHANNEL_GROUP;
438 if ((idx = std_str_idx(data, *model->coupling_options, model->num_coupling_options)) < 0)
440 if ((j = std_cg_idx(cg, devc->analog_groups, model->analog_channels)) < 0)
442 g_snprintf(command, sizeof(command),
443 (*model->scpi_dialect)[SCPI_CMD_SET_COUPLING],
444 j + 1, (*model->coupling_options)[idx]);
445 if (sr_scpi_send(sdi->conn, command) != SR_OK ||
446 sr_scpi_get_opc(sdi->conn) != SR_OK)
448 state->analog_channels[j].coupling = idx;
451 case SR_CONF_LOGIC_THRESHOLD:
453 return SR_ERR_CHANNEL_GROUP;
454 if (cg_type != CG_DIGITAL)
458 if ((idx = std_str_idx(data, *model->logic_threshold, model->num_logic_threshold)) < 0)
460 if ((j = std_cg_idx(cg, devc->digital_groups, model->digital_pods)) < 0)
462 /* Check if the threshold command is based on the POD or digital channel index. */
463 if (model->logic_threshold_for_pod)
466 i = j * DIGITAL_CHANNELS_PER_POD;
467 g_snprintf(command, sizeof(command),
468 (*model->scpi_dialect)[SCPI_CMD_SET_DIG_POD_THRESHOLD],
469 i, (*model->logic_threshold)[idx]);
470 if (sr_scpi_send(sdi->conn, command) != SR_OK ||
471 sr_scpi_get_opc(sdi->conn) != SR_OK)
473 state->digital_pods[j].threshold = idx;
476 case SR_CONF_LOGIC_THRESHOLD_CUSTOM:
478 return SR_ERR_CHANNEL_GROUP;
479 if (cg_type != CG_DIGITAL)
483 if ((j = std_cg_idx(cg, devc->digital_groups, model->digital_pods)) < 0)
485 tmp_d = g_variant_get_double(data);
486 if (tmp_d < -2.0 || tmp_d > 8.0)
488 g_ascii_formatd(float_str, sizeof(float_str), "%E", tmp_d);
489 /* Check if the threshold command is based on the POD or digital channel index. */
490 if (model->logic_threshold_for_pod)
493 idx = j * DIGITAL_CHANNELS_PER_POD;
494 /* Try to support different dialects exhaustively. */
495 for (i = 0; i < model->num_logic_threshold; i++) {
496 if (!strcmp("USER2", (*model->logic_threshold)[i])) {
497 g_snprintf(command, sizeof(command),
498 (*model->scpi_dialect)[SCPI_CMD_SET_DIG_POD_USER_THRESHOLD],
499 idx, 2, float_str); /* USER2 */
500 g_snprintf(command2, sizeof(command2),
501 (*model->scpi_dialect)[SCPI_CMD_SET_DIG_POD_THRESHOLD],
505 if (!strcmp("USER", (*model->logic_threshold)[i])) {
506 g_snprintf(command, sizeof(command),
507 (*model->scpi_dialect)[SCPI_CMD_SET_DIG_POD_USER_THRESHOLD],
509 g_snprintf(command2, sizeof(command2),
510 (*model->scpi_dialect)[SCPI_CMD_SET_DIG_POD_THRESHOLD],
514 if (!strcmp("MAN", (*model->logic_threshold)[i])) {
515 g_snprintf(command, sizeof(command),
516 (*model->scpi_dialect)[SCPI_CMD_SET_DIG_POD_USER_THRESHOLD],
518 g_snprintf(command2, sizeof(command2),
519 (*model->scpi_dialect)[SCPI_CMD_SET_DIG_POD_THRESHOLD],
524 if (sr_scpi_send(sdi->conn, command) != SR_OK ||
525 sr_scpi_get_opc(sdi->conn) != SR_OK)
527 if (sr_scpi_send(sdi->conn, command2) != SR_OK ||
528 sr_scpi_get_opc(sdi->conn) != SR_OK)
530 state->digital_pods[j].user_threshold = tmp_d;
538 if (ret == SR_OK && update_sample_rate)
539 ret = hmo_update_sample_rate(sdi);
544 static int config_list(uint32_t key, GVariant **data,
545 const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
547 int cg_type = CG_NONE;
548 struct dev_context *devc = NULL;
549 const struct scope_config *model = NULL;
553 if ((cg_type = check_channel_group(devc, cg)) == CG_INVALID)
556 model = devc->model_config;
560 case SR_CONF_SCAN_OPTIONS:
561 *data = std_gvar_array_u32(ARRAY_AND_SIZE(scanopts));
563 case SR_CONF_DEVICE_OPTIONS:
566 *data = std_gvar_array_u32(*model->devopts, model->num_devopts);
568 *data = std_gvar_array_u32(ARRAY_AND_SIZE(drvopts));
569 } else if (cg_type == CG_ANALOG) {
570 *data = std_gvar_array_u32(*model->devopts_cg_analog, model->num_devopts_cg_analog);
571 } else if (cg_type == CG_DIGITAL) {
572 *data = std_gvar_array_u32(*model->devopts_cg_digital, model->num_devopts_cg_digital);
574 *data = std_gvar_array_u32(NULL, 0);
577 case SR_CONF_COUPLING:
579 return SR_ERR_CHANNEL_GROUP;
582 *data = g_variant_new_strv(*model->coupling_options, model->num_coupling_options);
584 case SR_CONF_TRIGGER_SOURCE:
587 *data = g_variant_new_strv(*model->trigger_sources, model->num_trigger_sources);
589 case SR_CONF_TRIGGER_SLOPE:
592 *data = g_variant_new_strv(*model->trigger_slopes, model->num_trigger_slopes);
594 case SR_CONF_TIMEBASE:
597 *data = std_gvar_tuple_array(*model->timebases, model->num_timebases);
601 return SR_ERR_CHANNEL_GROUP;
604 *data = std_gvar_tuple_array(*model->vdivs, model->num_vdivs);
606 case SR_CONF_LOGIC_THRESHOLD:
608 return SR_ERR_CHANNEL_GROUP;
611 *data = g_variant_new_strv(*model->logic_threshold, model->num_logic_threshold);
620 SR_PRIV int hmo_request_data(const struct sr_dev_inst *sdi)
622 char command[MAX_COMMAND_SIZE];
623 struct sr_channel *ch;
624 struct dev_context *devc;
625 const struct scope_config *model;
628 model = devc->model_config;
630 ch = devc->current_channel->data;
633 case SR_CHANNEL_ANALOG:
634 g_snprintf(command, sizeof(command),
635 (*model->scpi_dialect)[SCPI_CMD_GET_ANALOG_DATA],
636 #ifdef WORDS_BIGENDIAN
643 case SR_CHANNEL_LOGIC:
644 g_snprintf(command, sizeof(command),
645 (*model->scpi_dialect)[SCPI_CMD_GET_DIG_DATA],
646 ch->index / DIGITAL_CHANNELS_PER_POD + 1);
649 sr_err("Invalid channel type.");
653 return sr_scpi_send(sdi->conn, command);
656 static int hmo_check_channels(GSList *channels)
659 struct sr_channel *ch;
660 gboolean enabled_chan[MAX_ANALOG_CHANNEL_COUNT];
661 gboolean enabled_pod[MAX_DIGITAL_GROUP_COUNT];
664 /* Preset "not enabled" for all channels / pods. */
665 for (idx = 0; idx < ARRAY_SIZE(enabled_chan); idx++)
666 enabled_chan[idx] = FALSE;
667 for (idx = 0; idx < ARRAY_SIZE(enabled_pod); idx++)
668 enabled_pod[idx] = FALSE;
671 * Determine which channels / pods are required for the caller's
672 * specified configuration.
674 for (l = channels; l; l = l->next) {
677 case SR_CHANNEL_ANALOG:
679 if (idx < ARRAY_SIZE(enabled_chan))
680 enabled_chan[idx] = TRUE;
682 case SR_CHANNEL_LOGIC:
683 idx = ch->index / DIGITAL_CHANNELS_PER_POD;
684 if (idx < ARRAY_SIZE(enabled_pod))
685 enabled_pod[idx] = TRUE;
693 * Check for resource conflicts. Some channels can be either
694 * analog or digital, but never both at the same time.
696 * Note that the constraints might depend on the specific model.
697 * These tests might need some adjustment when support for more
698 * models gets added to the driver.
700 if (enabled_pod[0] && enabled_chan[2])
702 if (enabled_pod[1] && enabled_chan[3])
707 static int hmo_setup_channels(const struct sr_dev_inst *sdi)
711 gboolean *pod_enabled, setup_changed;
712 char command[MAX_COMMAND_SIZE];
713 struct scope_state *state;
714 const struct scope_config *model;
715 struct sr_channel *ch;
716 struct dev_context *devc;
717 struct sr_scpi_dev_inst *scpi;
722 state = devc->model_state;
723 model = devc->model_config;
724 setup_changed = FALSE;
726 pod_enabled = g_try_malloc0(sizeof(gboolean) * model->digital_pods);
728 for (l = sdi->channels; l; l = l->next) {
731 case SR_CHANNEL_ANALOG:
732 if (ch->enabled == state->analog_channels[ch->index].state)
734 g_snprintf(command, sizeof(command),
735 (*model->scpi_dialect)[SCPI_CMD_SET_ANALOG_CHAN_STATE],
736 ch->index + 1, ch->enabled);
738 if (sr_scpi_send(scpi, command) != SR_OK) {
742 state->analog_channels[ch->index].state = ch->enabled;
743 setup_changed = TRUE;
745 case SR_CHANNEL_LOGIC:
747 * A digital POD needs to be enabled for every group of
748 * DIGITAL_CHANNELS_PER_POD channels.
751 pod_enabled[ch->index / DIGITAL_CHANNELS_PER_POD] = TRUE;
753 if (ch->enabled == state->digital_channels[ch->index])
755 g_snprintf(command, sizeof(command),
756 (*model->scpi_dialect)[SCPI_CMD_SET_DIG_CHAN_STATE],
757 ch->index, ch->enabled);
759 if (sr_scpi_send(scpi, command) != SR_OK) {
764 state->digital_channels[ch->index] = ch->enabled;
765 setup_changed = TRUE;
774 for (i = 0; i < model->digital_pods; i++) {
775 if (state->digital_pods[i].state == pod_enabled[i])
777 g_snprintf(command, sizeof(command),
778 (*model->scpi_dialect)[SCPI_CMD_SET_DIG_POD_STATE],
779 i + 1, pod_enabled[i]);
780 if (sr_scpi_send(scpi, command) != SR_OK) {
784 state->digital_pods[i].state = pod_enabled[i];
785 setup_changed = TRUE;
791 if (setup_changed && hmo_update_sample_rate(sdi) != SR_OK)
797 static int dev_acquisition_start(const struct sr_dev_inst *sdi)
800 gboolean digital_added[MAX_DIGITAL_GROUP_COUNT];
801 size_t group, pod_count;
802 struct sr_channel *ch;
803 struct dev_context *devc;
804 struct sr_scpi_dev_inst *scpi;
810 devc->num_samples = 0;
811 devc->num_frames = 0;
813 /* Preset empty results. */
814 for (group = 0; group < ARRAY_SIZE(digital_added); group++)
815 digital_added[group] = FALSE;
816 g_slist_free(devc->enabled_channels);
817 devc->enabled_channels = NULL;
820 * Contruct the list of enabled channels. Determine the highest
821 * number of digital pods involved in the acquisition.
824 for (l = sdi->channels; l; l = l->next) {
828 /* Only add a single digital channel per group (pod). */
829 group = ch->index / DIGITAL_CHANNELS_PER_POD;
830 if (ch->type != SR_CHANNEL_LOGIC || !digital_added[group]) {
831 devc->enabled_channels = g_slist_append(
832 devc->enabled_channels, ch);
833 if (ch->type == SR_CHANNEL_LOGIC) {
834 digital_added[group] = TRUE;
835 if (pod_count < group + 1)
836 pod_count = group + 1;
840 if (!devc->enabled_channels)
842 devc->pod_count = pod_count;
843 devc->logic_data = NULL;
846 * Check constraints. Some channels can be either analog or
847 * digital, but not both at the same time.
849 if (hmo_check_channels(devc->enabled_channels) != SR_OK) {
850 sr_err("Invalid channel configuration specified!");
856 * Configure the analog and digital channels and the
857 * corresponding digital pods.
859 if (hmo_setup_channels(sdi) != SR_OK) {
860 sr_err("Failed to setup channel configuration!");
866 * Start acquisition on the first enabled channel. The
867 * receive routine will continue driving the acquisition.
869 sr_scpi_source_add(sdi->session, scpi, G_IO_IN, 50,
870 hmo_receive_data, (void *)sdi);
872 std_session_send_df_header(sdi);
874 devc->current_channel = devc->enabled_channels;
876 return hmo_request_data(sdi);
879 g_slist_free(devc->enabled_channels);
880 devc->enabled_channels = NULL;
884 static int dev_acquisition_stop(struct sr_dev_inst *sdi)
886 struct dev_context *devc;
887 struct sr_scpi_dev_inst *scpi;
889 std_session_send_df_end(sdi);
893 devc->num_samples = 0;
894 devc->num_frames = 0;
895 g_slist_free(devc->enabled_channels);
896 devc->enabled_channels = NULL;
898 sr_scpi_source_remove(sdi->session, scpi);
903 static struct sr_dev_driver hameg_hmo_driver_info = {
905 .longname = "Hameg HMO",
908 .cleanup = std_cleanup,
910 .dev_list = std_dev_list,
911 .dev_clear = dev_clear,
912 .config_get = config_get,
913 .config_set = config_set,
914 .config_list = config_list,
915 .dev_open = dev_open,
916 .dev_close = dev_close,
917 .dev_acquisition_start = dev_acquisition_start,
918 .dev_acquisition_stop = dev_acquisition_stop,
921 SR_REGISTER_DEV_DRIVER(hameg_hmo_driver_info);