2 * This file is part of the libsigrok project.
4 * Copyright (C) 2013 poljar (Damir Jelić) <poljarinho@gmail.com>
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.
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.
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/>.
26 SR_PRIV void hmo_queue_logic_data(struct dev_context *devc,
27 size_t group, GByteArray *pod_data);
28 SR_PRIV void hmo_send_logic_packet(struct sr_dev_inst *sdi,
29 struct dev_context *devc);
30 SR_PRIV void hmo_cleanup_logic_data(struct dev_context *devc);
32 static const char *hameg_scpi_dialect[] = {
33 [SCPI_CMD_GET_DIG_DATA] = ":FORM UINT,8;:POD%d:DATA?",
34 [SCPI_CMD_GET_TIMEBASE] = ":TIM:SCAL?",
35 [SCPI_CMD_SET_TIMEBASE] = ":TIM:SCAL %s",
36 [SCPI_CMD_GET_COUPLING] = ":CHAN%d:COUP?",
37 [SCPI_CMD_SET_COUPLING] = ":CHAN%d:COUP %s",
38 [SCPI_CMD_GET_SAMPLE_RATE] = ":ACQ:SRAT?",
39 [SCPI_CMD_GET_SAMPLE_RATE_LIVE] = ":%s:DATA:POINTS?",
40 [SCPI_CMD_GET_ANALOG_DATA] = ":FORM:BORD %s;" \
41 ":FORM REAL,32;:CHAN%d:DATA?",
42 [SCPI_CMD_GET_VERTICAL_DIV] = ":CHAN%d:SCAL?",
43 [SCPI_CMD_SET_VERTICAL_DIV] = ":CHAN%d:SCAL %s",
44 [SCPI_CMD_GET_DIG_POD_STATE] = ":POD%d:STAT?",
45 [SCPI_CMD_SET_DIG_POD_STATE] = ":POD%d:STAT %d",
46 [SCPI_CMD_GET_TRIGGER_SLOPE] = ":TRIG:A:EDGE:SLOP?",
47 [SCPI_CMD_SET_TRIGGER_SLOPE] = ":TRIG:A:EDGE:SLOP %s",
48 [SCPI_CMD_GET_TRIGGER_SOURCE] = ":TRIG:A:SOUR?",
49 [SCPI_CMD_SET_TRIGGER_SOURCE] = ":TRIG:A:SOUR %s",
50 [SCPI_CMD_GET_DIG_CHAN_STATE] = ":LOG%d:STAT?",
51 [SCPI_CMD_SET_DIG_CHAN_STATE] = ":LOG%d:STAT %d",
52 [SCPI_CMD_GET_VERTICAL_OFFSET] = ":CHAN%d:POS?",
53 [SCPI_CMD_GET_HORIZ_TRIGGERPOS] = ":TIM:POS?",
54 [SCPI_CMD_SET_HORIZ_TRIGGERPOS] = ":TIM:POS %s",
55 [SCPI_CMD_GET_ANALOG_CHAN_STATE] = ":CHAN%d:STAT?",
56 [SCPI_CMD_SET_ANALOG_CHAN_STATE] = ":CHAN%d:STAT %d",
57 [SCPI_CMD_GET_PROBE_UNIT] = ":PROB%d:SET:ATT:UNIT?",
60 static const uint32_t hmo_devopts[] = {
62 SR_CONF_LIMIT_FRAMES | SR_CONF_GET | SR_CONF_SET,
63 SR_CONF_TRIGGER_SOURCE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
64 SR_CONF_TIMEBASE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
65 SR_CONF_NUM_HDIV | SR_CONF_GET,
66 SR_CONF_TRIGGER_SLOPE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
67 SR_CONF_HORIZ_TRIGGERPOS | SR_CONF_GET | SR_CONF_SET,
68 SR_CONF_SAMPLERATE | SR_CONF_GET,
71 static const uint32_t hmo_analog_devopts[] = {
72 SR_CONF_NUM_VDIV | SR_CONF_GET,
73 SR_CONF_COUPLING | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
74 SR_CONF_VDIV | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
77 static const char *hmo_coupling_options[] = {
78 "AC", // AC with 50 Ohm termination (152x, 202x, 30xx, 1202)
79 "ACL", // AC with 1 MOhm termination
80 "DC", // DC with 50 Ohm termination
81 "DCL", // DC with 1 MOhm termination
86 static const char *scope_trigger_slopes[] = {
93 static const char *hmo_compact2_trigger_sources[] = {
112 static const char *hmo_compact4_trigger_sources[] = {
133 static const char *hmo_compact4_dig16_trigger_sources[] = {
162 static const uint64_t hmo_timebases[][2] = {
201 static const uint64_t hmo_vdivs[][2] = {
221 static const char *scope_analog_channel_names[] = {
228 static const char *scope_digital_channel_names[] = {
247 static const struct scope_config scope_models[] = {
249 /* HMO2522/3032/3042/3052 support 16 digital channels but they're not supported yet. */
250 .name = {"HMO1002", "HMO722", "HMO1022", "HMO1522", "HMO2022", "HMO2522",
251 "HMO3032", "HMO3042", "HMO3052", NULL},
252 .analog_channels = 2,
253 .digital_channels = 8,
256 .analog_names = &scope_analog_channel_names,
257 .digital_names = &scope_digital_channel_names,
259 .devopts = &hmo_devopts,
260 .num_devopts = ARRAY_SIZE(hmo_devopts),
262 .analog_devopts = &hmo_analog_devopts,
263 .num_analog_devopts = ARRAY_SIZE(hmo_analog_devopts),
265 .coupling_options = &hmo_coupling_options,
266 .trigger_sources = &hmo_compact2_trigger_sources,
267 .trigger_slopes = &scope_trigger_slopes,
269 .timebases = &hmo_timebases,
270 .num_timebases = ARRAY_SIZE(hmo_timebases),
273 .num_vdivs = ARRAY_SIZE(hmo_vdivs),
278 .scpi_dialect = &hameg_scpi_dialect,
281 .name = {"HMO724", "HMO1024", "HMO1524", "HMO2024", NULL},
282 .analog_channels = 4,
283 .digital_channels = 8,
286 .analog_names = &scope_analog_channel_names,
287 .digital_names = &scope_digital_channel_names,
289 .devopts = &hmo_devopts,
290 .num_devopts = ARRAY_SIZE(hmo_devopts),
292 .analog_devopts = &hmo_analog_devopts,
293 .num_analog_devopts = ARRAY_SIZE(hmo_analog_devopts),
295 .coupling_options = &hmo_coupling_options,
296 .trigger_sources = &hmo_compact4_trigger_sources,
297 .trigger_slopes = &scope_trigger_slopes,
299 .timebases = &hmo_timebases,
300 .num_timebases = ARRAY_SIZE(hmo_timebases),
303 .num_vdivs = ARRAY_SIZE(hmo_vdivs),
308 .scpi_dialect = &hameg_scpi_dialect,
311 .name = {"HMO2524", "HMO3034", "HMO3044", "HMO3054", NULL},
312 .analog_channels = 4,
313 .digital_channels = 16,
316 .analog_names = &scope_analog_channel_names,
317 .digital_names = &scope_digital_channel_names,
319 .devopts = &hmo_devopts,
320 .num_devopts = ARRAY_SIZE(hmo_devopts),
322 .analog_devopts = &hmo_analog_devopts,
323 .num_analog_devopts = ARRAY_SIZE(hmo_analog_devopts),
325 .coupling_options = &hmo_coupling_options,
326 .trigger_sources = &hmo_compact4_dig16_trigger_sources,
327 .trigger_slopes = &scope_trigger_slopes,
329 .timebases = &hmo_timebases,
330 .num_timebases = ARRAY_SIZE(hmo_timebases),
333 .num_vdivs = ARRAY_SIZE(hmo_vdivs),
338 .scpi_dialect = &hameg_scpi_dialect,
342 static void scope_state_dump(const struct scope_config *config,
343 struct scope_state *state)
348 for (i = 0; i < config->analog_channels; i++) {
349 tmp = sr_voltage_string((*config->vdivs)[state->analog_channels[i].vdiv][0],
350 (*config->vdivs)[state->analog_channels[i].vdiv][1]);
351 sr_info("State of analog channel %d -> %s : %s (coupling) %s (vdiv) %2.2e (offset)",
352 i + 1, state->analog_channels[i].state ? "On" : "Off",
353 (*config->coupling_options)[state->analog_channels[i].coupling],
354 tmp, state->analog_channels[i].vertical_offset);
357 for (i = 0; i < config->digital_channels; i++) {
358 sr_info("State of digital channel %d -> %s", i,
359 state->digital_channels[i] ? "On" : "Off");
362 for (i = 0; i < config->digital_pods; i++) {
363 sr_info("State of digital POD %d -> %s", i,
364 state->digital_pods[i] ? "On" : "Off");
367 tmp = sr_period_string((*config->timebases)[state->timebase][0] *
368 (*config->timebases)[state->timebase][1]);
369 sr_info("Current timebase: %s", tmp);
372 tmp = sr_samplerate_string(state->sample_rate);
373 sr_info("Current samplerate: %s", tmp);
376 sr_info("Current trigger: %s (source), %s (slope) %.2f (offset)",
377 (*config->trigger_sources)[state->trigger_source],
378 (*config->trigger_slopes)[state->trigger_slope],
379 state->horiz_triggerpos);
382 static int scope_state_get_array_option(struct sr_scpi_dev_inst *scpi,
383 const char *command, const char *(*array)[], int *result)
388 if (sr_scpi_get_string(scpi, command, &tmp) != SR_OK) {
393 for (i = 0; (*array)[i]; i++) {
394 if (!g_strcmp0(tmp, (*array)[i])) {
411 * This function takes a value of the form "2.000E-03" and returns the index
412 * of an array where a matching pair was found.
414 * @param value The string to be parsed.
415 * @param array The array of s/f pairs.
416 * @param array_len The number of pairs in the array.
417 * @param result The index at which a matching pair was found.
419 * @return SR_ERR on any parsing error, SR_OK otherwise.
421 static int array_float_get(gchar *value, const uint64_t array[][2],
422 int array_len, unsigned int *result)
424 struct sr_rational rval;
425 struct sr_rational aval;
427 if (sr_parse_rational(value, &rval) != SR_OK)
430 for (int i = 0; i < array_len; i++) {
431 sr_rational_set(&aval, array[i][0], array[i][1]);
432 if (sr_rational_eq(&rval, &aval)) {
441 static int analog_channel_state_get(struct sr_scpi_dev_inst *scpi,
442 const struct scope_config *config,
443 struct scope_state *state)
446 char command[MAX_COMMAND_SIZE];
449 for (i = 0; i < config->analog_channels; i++) {
450 g_snprintf(command, sizeof(command),
451 (*config->scpi_dialect)[SCPI_CMD_GET_ANALOG_CHAN_STATE],
454 if (sr_scpi_get_bool(scpi, command,
455 &state->analog_channels[i].state) != SR_OK)
458 g_snprintf(command, sizeof(command),
459 (*config->scpi_dialect)[SCPI_CMD_GET_VERTICAL_DIV],
462 if (sr_scpi_get_string(scpi, command, &tmp_str) != SR_OK)
465 if (array_float_get(tmp_str, hmo_vdivs, ARRAY_SIZE(hmo_vdivs),
468 sr_err("Could not determine array index for vertical div scale.");
473 state->analog_channels[i].vdiv = j;
475 g_snprintf(command, sizeof(command),
476 (*config->scpi_dialect)[SCPI_CMD_GET_VERTICAL_OFFSET],
479 if (sr_scpi_get_float(scpi, command,
480 &state->analog_channels[i].vertical_offset) != SR_OK)
483 g_snprintf(command, sizeof(command),
484 (*config->scpi_dialect)[SCPI_CMD_GET_COUPLING],
487 if (scope_state_get_array_option(scpi, command, config->coupling_options,
488 &state->analog_channels[i].coupling) != SR_OK)
491 g_snprintf(command, sizeof(command),
492 (*config->scpi_dialect)[SCPI_CMD_GET_PROBE_UNIT],
495 if (sr_scpi_get_string(scpi, command, &tmp_str) != SR_OK)
498 if (tmp_str[0] == 'A')
499 state->analog_channels[i].probe_unit = 'A';
501 state->analog_channels[i].probe_unit = 'V';
508 static int digital_channel_state_get(struct sr_scpi_dev_inst *scpi,
509 const struct scope_config *config,
510 struct scope_state *state)
513 char command[MAX_COMMAND_SIZE];
515 for (i = 0; i < config->digital_channels; i++) {
516 g_snprintf(command, sizeof(command),
517 (*config->scpi_dialect)[SCPI_CMD_GET_DIG_CHAN_STATE],
520 if (sr_scpi_get_bool(scpi, command,
521 &state->digital_channels[i]) != SR_OK)
525 for (i = 0; i < config->digital_pods; i++) {
526 g_snprintf(command, sizeof(command),
527 (*config->scpi_dialect)[SCPI_CMD_GET_DIG_POD_STATE],
530 if (sr_scpi_get_bool(scpi, command,
531 &state->digital_pods[i]) != SR_OK)
538 SR_PRIV int hmo_update_sample_rate(const struct sr_dev_inst *sdi)
540 struct dev_context *devc;
541 struct scope_state *state;
542 const struct scope_config *config;
547 gboolean channel_found;
548 char tmp_str[MAX_COMMAND_SIZE];
552 config = devc->model_config;
553 state = devc->model_state;
554 channel_found = FALSE;
556 for (i = 0; i < config->analog_channels; i++) {
557 if (state->analog_channels[i].state) {
558 g_snprintf(chan_name, sizeof(chan_name), "CHAN%d", i + 1);
559 g_snprintf(tmp_str, sizeof(tmp_str),
560 (*config->scpi_dialect)[SCPI_CMD_GET_SAMPLE_RATE_LIVE],
562 channel_found = TRUE;
567 if (!channel_found) {
568 for (i = 0; i < config->digital_pods; i++) {
569 if (state->digital_pods[i]) {
570 g_snprintf(chan_name, sizeof(chan_name), "POD%d", i);
571 g_snprintf(tmp_str, sizeof(tmp_str),
572 (*config->scpi_dialect)[SCPI_CMD_GET_SAMPLE_RATE_LIVE],
574 channel_found = TRUE;
580 /* No channel is active, ask the instrument for the sample rate
581 * in single shot mode */
582 if (!channel_found) {
583 if (sr_scpi_get_float(sdi->conn,
584 (*config->scpi_dialect)[SCPI_CMD_GET_SAMPLE_RATE],
585 &tmp_float) != SR_OK)
588 state->sample_rate = tmp_float;
590 if (sr_scpi_get_int(sdi->conn, tmp_str, &tmp) != SR_OK)
592 state->sample_rate = tmp / (((float) (*config->timebases)[state->timebase][0] /
593 (*config->timebases)[state->timebase][1]) *
600 SR_PRIV int hmo_scope_state_get(struct sr_dev_inst *sdi)
602 struct dev_context *devc;
603 struct scope_state *state;
604 const struct scope_config *config;
610 config = devc->model_config;
611 state = devc->model_state;
613 sr_info("Fetching scope state");
615 if (analog_channel_state_get(sdi->conn, config, state) != SR_OK)
618 if (digital_channel_state_get(sdi->conn, config, state) != SR_OK)
621 if (sr_scpi_get_float(sdi->conn,
622 (*config->scpi_dialect)[SCPI_CMD_GET_TIMEBASE],
623 &tmp_float) != SR_OK)
626 if (sr_scpi_get_string(sdi->conn,
627 (*config->scpi_dialect)[SCPI_CMD_GET_TIMEBASE],
631 if (array_float_get(tmp_str, hmo_timebases, ARRAY_SIZE(hmo_timebases),
634 sr_err("Could not determine array index for time base.");
641 if (sr_scpi_get_float(sdi->conn,
642 (*config->scpi_dialect)[SCPI_CMD_GET_HORIZ_TRIGGERPOS],
643 &tmp_float) != SR_OK)
645 state->horiz_triggerpos = tmp_float /
646 (((double) (*config->timebases)[state->timebase][0] /
647 (*config->timebases)[state->timebase][1]) * config->num_xdivs);
648 state->horiz_triggerpos -= 0.5;
649 state->horiz_triggerpos *= -1;
651 if (scope_state_get_array_option(sdi->conn,
652 (*config->scpi_dialect)[SCPI_CMD_GET_TRIGGER_SOURCE],
653 config->trigger_sources, &state->trigger_source) != SR_OK)
656 if (scope_state_get_array_option(sdi->conn,
657 (*config->scpi_dialect)[SCPI_CMD_GET_TRIGGER_SLOPE],
658 config->trigger_slopes, &state->trigger_slope) != SR_OK)
661 if (hmo_update_sample_rate(sdi) != SR_OK)
664 sr_info("Fetching finished.");
666 scope_state_dump(config, state);
671 static struct scope_state *scope_state_new(const struct scope_config *config)
673 struct scope_state *state;
675 state = g_malloc0(sizeof(struct scope_state));
676 state->analog_channels = g_malloc0_n(config->analog_channels,
677 sizeof(struct analog_channel_state));
678 state->digital_channels = g_malloc0_n(
679 config->digital_channels, sizeof(gboolean));
680 state->digital_pods = g_malloc0_n(config->digital_pods,
686 SR_PRIV void hmo_scope_state_free(struct scope_state *state)
688 g_free(state->analog_channels);
689 g_free(state->digital_channels);
690 g_free(state->digital_pods);
694 SR_PRIV int hmo_init_device(struct sr_dev_inst *sdi)
698 unsigned int i, j, group;
699 struct sr_channel *ch;
700 struct dev_context *devc;
705 /* Find the exact model. */
706 for (i = 0; i < ARRAY_SIZE(scope_models); i++) {
707 for (j = 0; scope_models[i].name[j]; j++) {
708 if (!strcmp(sdi->model, scope_models[i].name[j])) {
713 if (model_index != -1)
717 if (model_index == -1) {
718 sr_dbg("Unsupported HMO device.");
722 devc->analog_groups = g_malloc0(sizeof(struct sr_channel_group*) *
723 scope_models[model_index].analog_channels);
725 devc->digital_groups = g_malloc0(sizeof(struct sr_channel_group*) *
726 scope_models[model_index].digital_pods);
728 /* Add analog channels. */
729 for (i = 0; i < scope_models[model_index].analog_channels; i++) {
730 ch = sr_channel_new(sdi, i, SR_CHANNEL_ANALOG, TRUE,
731 (*scope_models[model_index].analog_names)[i]);
733 devc->analog_groups[i] = g_malloc0(sizeof(struct sr_channel_group));
735 devc->analog_groups[i]->name = g_strdup(
736 (char *)(*scope_models[model_index].analog_names)[i]);
737 devc->analog_groups[i]->channels = g_slist_append(NULL, ch);
739 sdi->channel_groups = g_slist_append(sdi->channel_groups,
740 devc->analog_groups[i]);
743 /* Add digital channel groups. */
744 for (i = 0; i < scope_models[model_index].digital_pods; i++) {
745 g_snprintf(tmp, 25, "POD%d", i);
747 devc->digital_groups[i] = g_malloc0(sizeof(struct sr_channel_group));
749 devc->digital_groups[i]->name = g_strdup(tmp);
750 sdi->channel_groups = g_slist_append(sdi->channel_groups,
751 devc->digital_groups[i]);
754 /* Add digital channels. */
755 for (i = 0; i < scope_models[model_index].digital_channels; i++) {
756 ch = sr_channel_new(sdi, i, SR_CHANNEL_LOGIC, TRUE,
757 (*scope_models[model_index].digital_names)[i]);
760 devc->digital_groups[group]->channels = g_slist_append(
761 devc->digital_groups[group]->channels, ch);
764 devc->model_config = &scope_models[model_index];
765 devc->frame_limit = 0;
767 if (!(devc->model_state = scope_state_new(devc->model_config)))
768 return SR_ERR_MALLOC;
773 /* Queue data of one channel group, for later submission. */
774 SR_PRIV void hmo_queue_logic_data(struct dev_context *devc,
775 size_t group, GByteArray *pod_data)
780 size_t idx, logic_step;
783 * Upon first invocation, allocate the array which can hold the
784 * combined logic data for all channels. Assume that each channel
785 * will yield an identical number of samples per receive call.
787 * As a poor man's safety measure: (Silently) skip processing
788 * for unexpected sample counts, and ignore samples for
789 * unexpected channel groups. Don't bother with complicated
790 * resize logic, considering that many models only support one
791 * pod, and the most capable supported models have two pods of
792 * identical size. We haven't yet seen any "odd" configuration.
794 if (!devc->logic_data) {
795 size = pod_data->len * devc->pod_count;
796 store = g_byte_array_sized_new(size);
797 memset(store->data, 0, size);
798 store = g_byte_array_set_size(store, size);
799 devc->logic_data = store;
801 store = devc->logic_data;
802 size = store->len / devc->pod_count;
803 if (size != pod_data->len)
805 if (group >= devc->pod_count)
810 * Fold the data of the most recently received channel group into
811 * the storage, where data resides for all channels combined.
813 logic_data = store->data;
815 logic_step = devc->pod_count;
816 for (idx = 0; idx < pod_data->len; idx++) {
817 *logic_data = pod_data->data[idx];
818 logic_data += logic_step;
822 /* Submit data for all channels, after the individual groups got collected. */
823 SR_PRIV void hmo_send_logic_packet(struct sr_dev_inst *sdi,
824 struct dev_context *devc)
826 struct sr_datafeed_packet packet;
827 struct sr_datafeed_logic logic;
829 if (!devc->logic_data)
832 logic.data = devc->logic_data->data;
833 logic.length = devc->logic_data->len;
834 logic.unitsize = devc->pod_count;
836 packet.type = SR_DF_LOGIC;
837 packet.payload = &logic;
839 sr_session_send(sdi, &packet);
842 /* Undo previous resource allocation. */
843 SR_PRIV void hmo_cleanup_logic_data(struct dev_context *devc)
846 if (devc->logic_data) {
847 g_byte_array_free(devc->logic_data, TRUE);
848 devc->logic_data = NULL;
851 * Keep 'pod_count'! It's required when more frames will be
852 * received, and does not harm when kept after acquisition.
856 SR_PRIV int hmo_receive_data(int fd, int revents, void *cb_data)
858 struct sr_channel *ch;
859 struct sr_dev_inst *sdi;
860 struct dev_context *devc;
861 struct scope_state *state;
862 struct sr_datafeed_packet packet;
864 struct sr_datafeed_analog analog;
865 struct sr_analog_encoding encoding;
866 struct sr_analog_meaning meaning;
867 struct sr_analog_spec spec;
868 struct sr_datafeed_logic logic;
876 if (!(sdi = cb_data))
879 if (!(devc = sdi->priv))
882 /* Although this is correct in general, the USBTMC libusb implementation
883 * currently does not generate an event prior to the first read. Often
884 * it is ok to start reading just after the 50ms timeout. See bug #785.
885 if (revents != G_IO_IN)
889 ch = devc->current_channel->data;
890 state = devc->model_state;
893 * Send "frame begin" packet upon reception of data for the
894 * first enabled channel.
896 if (devc->current_channel == devc->enabled_channels) {
897 packet.type = SR_DF_FRAME_BEGIN;
898 sr_session_send(sdi, &packet);
902 * Pass on the received data of the channel(s).
905 case SR_CHANNEL_ANALOG:
906 if (sr_scpi_get_block(sdi->conn, NULL, &data) != SR_OK) {
908 g_byte_array_free(data, TRUE);
913 packet.type = SR_DF_ANALOG;
915 analog.data = data->data;
916 analog.num_samples = data->len / sizeof(float);
917 analog.encoding = &encoding;
918 analog.meaning = &meaning;
921 encoding.unitsize = sizeof(float);
922 encoding.is_signed = TRUE;
923 encoding.is_float = TRUE;
924 #ifdef WORDS_BIGENDIAN
925 encoding.is_bigendian = TRUE;
927 encoding.is_bigendian = FALSE;
929 /* TODO: Use proper 'digits' value for this device (and its modes). */
931 encoding.is_digits_decimal = FALSE;
932 encoding.scale.p = 1;
933 encoding.scale.q = 1;
934 encoding.offset.p = 0;
935 encoding.offset.q = 1;
936 if (state->analog_channels[ch->index].probe_unit == 'V') {
937 meaning.mq = SR_MQ_VOLTAGE;
938 meaning.unit = SR_UNIT_VOLT;
940 meaning.mq = SR_MQ_CURRENT;
941 meaning.unit = SR_UNIT_AMPERE;
944 meaning.channels = g_slist_append(NULL, ch);
945 /* TODO: Use proper 'digits' value for this device (and its modes). */
946 spec.spec_digits = 2;
947 packet.payload = &analog;
948 sr_session_send(sdi, &packet);
949 g_slist_free(meaning.channels);
950 g_byte_array_free(data, TRUE);
953 case SR_CHANNEL_LOGIC:
954 if (sr_scpi_get_block(sdi->conn, NULL, &data) != SR_OK) {
960 * If only data from the first pod is involved in the
961 * acquisition, then the raw input bytes can get passed
962 * forward for performance reasons. When the second pod
963 * is involved (either alone, or in combination with the
964 * first pod), then the received bytes need to be put
965 * into memory in such a layout that all channel groups
966 * get combined, and a unitsize larger than a single byte
967 * applies. The "queue" logic transparently copes with
968 * any such configuration. This works around the lack
969 * of support for "meaning" to logic data, which is used
970 * above for analog data.
972 if (devc->pod_count == 1) {
973 packet.type = SR_DF_LOGIC;
974 logic.data = data->data;
975 logic.length = data->len;
977 packet.payload = &logic;
978 sr_session_send(sdi, &packet);
980 group = ch->index / 8;
981 hmo_queue_logic_data(devc, group, data);
984 g_byte_array_free(data, TRUE);
988 sr_err("Invalid channel type.");
993 * Advance to the next enabled channel. When data for all enabled
994 * channels was received, then flush potentially queued logic data,
995 * and send the "frame end" packet.
997 if (devc->current_channel->next) {
998 devc->current_channel = devc->current_channel->next;
999 hmo_request_data(sdi);
1002 hmo_send_logic_packet(sdi, devc);
1005 * Release the logic data storage after each frame. This copes
1006 * with sample counts that differ in length per frame. -- Is
1007 * this a real constraint when acquiring multiple frames with
1008 * identical device settings?
1010 hmo_cleanup_logic_data(devc);
1012 packet.type = SR_DF_FRAME_END;
1013 sr_session_send(sdi, &packet);
1016 * End of frame was reached. Stop acquisition after the specified
1017 * number of frames, or continue reception by starting over at
1018 * the first enabled channel.
1020 if (++devc->num_frames == devc->frame_limit) {
1021 sdi->driver->dev_acquisition_stop(sdi);
1022 hmo_cleanup_logic_data(devc);
1024 devc->current_channel = devc->enabled_channels;
1025 hmo_request_data(sdi);