2 * This file is part of the libsigrok project.
4 * Copyright (C) 2014 abraxa (Soeren Apel) <soeren@apelpie.net>
5 * Based on the Hameg HMO driver by poljar (Damir Jelić) <poljarinho@gmail.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/>.
25 static const char *coupling_options[] = {
33 static const char *trigger_sources_2ch[] = {
41 /* TODO: Is BITx handled correctly or is Dx required? */
42 static const char *trigger_sources_4ch[] = {
60 /* Note: Values must correlate to the trigger_slopes values. */
61 const char *dlm_trigger_slopes[3] = {
67 const uint64_t dlm_timebases[36][2] = {
110 const uint64_t dlm_vdivs[17][2] = {
132 static const char *scope_analog_channel_names[] = {
139 static const char *scope_digital_channel_names_8[] = {
150 static const char *scope_digital_channel_names_32[] = {
185 static const struct scope_config scope_models[] = {
187 .model_id = {"710105", "710115", "710125", NULL},
188 .model_name = {"DLM2022", "DLM2032", "DLM2052", NULL},
189 .analog_channels = 2,
190 .digital_channels = 0,
193 .analog_names = &scope_analog_channel_names,
194 .digital_names = &scope_digital_channel_names_8,
196 .coupling_options = &coupling_options,
197 .trigger_sources = &trigger_sources_2ch,
203 .model_id = {"710110", "710120", "710130", NULL},
204 .model_name = {"DLM2024", "DLM2034", "DLM2054", NULL},
205 .analog_channels = 4,
206 .digital_channels = 8,
209 .analog_names = &scope_analog_channel_names,
210 .digital_names = &scope_digital_channel_names_8,
212 .coupling_options = &coupling_options,
213 .trigger_sources = &trigger_sources_4ch,
219 .model_id = {"701307", "701308", "701310", "701311",
220 "701312", "701313", NULL},
221 .model_name = {"DL9040", "DL9040L", "DL9140", "DL9140L",
222 "DL9240", "DL9240L", NULL},
223 .analog_channels = 4,
224 .digital_channels = 0,
227 .analog_names = &scope_analog_channel_names,
228 .digital_names = NULL,
230 .coupling_options = &coupling_options,
231 .trigger_sources = &trigger_sources_4ch,
237 .model_id = {"701320", "701321", NULL},
238 .model_name = {"DL9505L", "DL9510L", NULL},
239 .analog_channels = 4,
240 .digital_channels = 16,
243 .analog_names = &scope_analog_channel_names,
244 .digital_names = &scope_digital_channel_names_32,
246 .coupling_options = &coupling_options,
247 .trigger_sources = &trigger_sources_4ch,
253 .model_id = {"701330", "701331", NULL},
254 .model_name = {"DL9705L", "DL9710L", NULL},
255 .analog_channels = 4,
256 .digital_channels = 32,
259 .analog_names = &scope_analog_channel_names,
260 .digital_names = &scope_digital_channel_names_32,
262 .coupling_options = &coupling_options,
263 .trigger_sources = &trigger_sources_4ch,
271 * Prints out the state of the device as we currently know it.
273 * @param config This is the scope configuration.
274 * @param state The current scope state to print.
276 static void scope_state_dump(const struct scope_config *config,
277 struct scope_state *state)
282 for (i = 0; i < config->analog_channels; i++) {
283 tmp = sr_voltage_string(dlm_vdivs[state->analog_states[i].vdiv][0],
284 dlm_vdivs[state->analog_states[i].vdiv][1]);
285 sr_info("State of analog channel %d -> %s : %s (coupling) %s (vdiv) %2.2e (offset)",
286 i + 1, state->analog_states[i].state ? "On" : "Off",
287 (*config->coupling_options)[state->analog_states[i].coupling],
288 tmp, state->analog_states[i].vertical_offset);
291 for (i = 0; i < config->digital_channels; i++) {
292 sr_info("State of digital channel %d -> %s", i,
293 state->digital_states[i] ? "On" : "Off");
296 for (i = 0; i < config->pods; i++) {
297 sr_info("State of digital POD %d -> %s", i,
298 state->pod_states[i] ? "On" : "Off");
301 tmp = sr_period_string(dlm_timebases[state->timebase][0],
302 dlm_timebases[state->timebase][1]);
303 sr_info("Current timebase: %s", tmp);
306 tmp = sr_samplerate_string(state->sample_rate);
307 sr_info("Current samplerate: %s", tmp);
310 sr_info("Current samples per acquisition (i.e. frame): %d",
311 state->samples_per_frame);
313 sr_info("Current trigger: %s (source), %s (slope) %.2f (offset)",
314 (*config->trigger_sources)[state->trigger_source],
315 dlm_trigger_slopes[state->trigger_slope],
316 state->horiz_triggerpos);
320 * Searches through an array of strings and returns the index to the
321 * array where a given string is located.
323 * @param value The string to search for.
324 * @param array The array of strings.
325 * @param result The index at which value is located in array. -1 on error.
327 * @return SR_ERR when value couldn't be found, SR_OK otherwise.
329 static int array_option_get(char *value, const char *(*array)[],
336 for (i = 0; (*array)[i]; i++)
337 if (!g_strcmp0(value, (*array)[i])) {
349 * This function takes a value of the form "2.000E-03", converts it to a
350 * significand / factor pair and returns the index of an array where
351 * a matching pair was found.
353 * It's a bit convoluted because of floating-point issues. The value "10.00E-09"
354 * is parsed by g_ascii_strtod() as 0.000000009999999939, for example.
355 * Therefore it's easier to break the number up into two strings and handle
358 * @param value The string to be parsed.
359 * @param array The array of s/f pairs.
360 * @param array_len The number of pairs in the array.
361 * @param result The index at which a matching pair was found.
363 * @return SR_ERR on any parsing error, SR_OK otherwise.
365 static int array_float_get(gchar *value, const uint64_t array[][2],
366 int array_len, int *result)
373 gchar ss[10], es[10];
375 memset(ss, 0, sizeof(ss));
376 memset(es, 0, sizeof(es));
378 /* Get index of the separating 'E' character and break up the string. */
379 pos = strcspn(value, "E");
381 strncpy(ss, value, pos);
382 strncpy(es, &(value[pos+1]), 3);
384 if (sr_atof_ascii(ss, &s) != SR_OK)
386 if (sr_atoi(es, &e) != SR_OK)
389 /* Transform e.g. 10^-03 to 1000 as the array stores the inverse. */
393 * Adjust the significand/factor pair to make sure
394 * that f is a multiple of 1000.
396 while ((int)fmod(log10(f), 3) > 0) {
405 /* Truncate s to circumvent rounding errors. */
406 s_int = (unsigned int)s;
408 for (i = 0; i < array_len; i++) {
409 if ((s_int == array[i][0]) && (f == array[i][1])) {
419 * Obtains information about all analog channels from the oscilloscope.
420 * The internal state information is updated accordingly.
422 * @param sdi The device instance.
423 * @param config The device's device configuration.
424 * @param state The device's state information.
426 * @return SR_ERR on error, SR_OK otherwise.
428 static int analog_channel_state_get(const struct sr_dev_inst *sdi,
429 const struct scope_config *config,
430 struct scope_state *state)
432 struct sr_scpi_dev_inst *scpi;
435 struct sr_channel *ch;
440 for (i = 0; i < config->analog_channels; i++) {
442 if (dlm_analog_chan_state_get(scpi, i + 1,
443 &state->analog_states[i].state) != SR_OK)
446 for (l = sdi->channels; l; l = l->next) {
448 if (ch->index == i) {
449 ch->enabled = state->analog_states[i].state;
454 if (dlm_analog_chan_vdiv_get(scpi, i + 1, &response) != SR_OK)
457 if (array_float_get(response, ARRAY_AND_SIZE(dlm_vdivs),
464 state->analog_states[i].vdiv = j;
466 if (dlm_analog_chan_voffs_get(scpi, i + 1,
467 &state->analog_states[i].vertical_offset) != SR_OK)
470 if (dlm_analog_chan_wrange_get(scpi, i + 1,
471 &state->analog_states[i].waveform_range) != SR_OK)
474 if (dlm_analog_chan_woffs_get(scpi, i + 1,
475 &state->analog_states[i].waveform_offset) != SR_OK)
478 if (dlm_analog_chan_coupl_get(scpi, i + 1, &response) != SR_OK) {
483 if (array_option_get(response, config->coupling_options,
484 &state->analog_states[i].coupling) != SR_OK) {
495 * Obtains information about all digital channels from the oscilloscope.
496 * The internal state information is updated accordingly.
498 * @param sdi The device instance.
499 * @param config The device's device configuration.
500 * @param state The device's state information.
502 * @return SR_ERR on error, SR_OK otherwise.
504 static int digital_channel_state_get(const struct sr_dev_inst *sdi,
505 const struct scope_config *config,
506 struct scope_state *state)
508 struct sr_scpi_dev_inst *scpi;
511 struct sr_channel *ch;
515 if (!config->digital_channels) {
516 sr_warn("Tried obtaining digital channel states on a " \
517 "model without digital inputs.");
521 for (i = 0; i < config->digital_channels; i++) {
522 if (dlm_digital_chan_state_get(scpi, i + 1,
523 &state->digital_states[i]) != SR_OK) {
527 for (l = sdi->channels; l; l = l->next) {
529 if (ch->index == i + DLM_DIG_CHAN_INDEX_OFFS) {
530 ch->enabled = state->digital_states[i];
537 sr_warn("Tried obtaining pod states on a model without pods.");
541 for (i = 0; i < config->pods; i++) {
542 if (dlm_digital_pod_state_get(scpi, i + 'A',
543 &state->pod_states[i]) != SR_OK)
550 SR_PRIV int dlm_channel_state_set(const struct sr_dev_inst *sdi,
551 const int ch_index, gboolean ch_state)
554 struct sr_channel *ch;
555 struct dev_context *devc = NULL;
556 struct scope_state *state;
557 const struct scope_config *model = NULL;
558 struct sr_scpi_dev_inst *scpi;
560 gboolean *pod_enabled;
567 state = devc->model_state;
568 model = devc->model_config;
571 pod_enabled = g_malloc0(sizeof(gboolean) * model->pods);
573 for (l = sdi->channels; l; l = l->next) {
577 case SR_CHANNEL_ANALOG:
578 if (ch->index == ch_index) {
579 if (dlm_analog_chan_state_set(scpi, ch->index + 1, ch_state) != SR_OK) {
584 ch->enabled = ch_state;
585 state->analog_states[ch->index].state = ch_state;
590 case SR_CHANNEL_LOGIC:
591 i = ch->index - DLM_DIG_CHAN_INDEX_OFFS;
593 if (ch->index == ch_index) {
594 if (dlm_digital_chan_state_set(scpi, i + 1, ch_state) != SR_OK) {
599 ch->enabled = ch_state;
600 state->digital_states[i] = ch_state;
603 /* The corresponding pod has to be enabled also. */
604 pod_enabled[i / 8] |= ch->enabled;
606 /* Also check all other channels. Maybe we can disable a pod. */
607 pod_enabled[i / 8] |= ch->enabled;
615 for (i = 0; i < model->pods; i++) {
616 if (state->pod_states[i] == pod_enabled[i])
619 if (dlm_digital_pod_state_set(scpi, i + 1, pod_enabled[i]) != SR_OK) {
624 state->pod_states[i] = pod_enabled[i];
629 if ((result == SR_OK) && !chan_found)
636 * Obtains information about the sample rate from the oscilloscope.
637 * The internal state information is updated accordingly.
639 * @param sdi The device instance.
641 * @return SR_ERR on error, SR_OK otherwise.
643 SR_PRIV int dlm_sample_rate_query(const struct sr_dev_inst *sdi)
645 struct dev_context *devc;
646 struct scope_state *state;
650 state = devc->model_state;
653 * No need to find an active channel to query the sample rate:
654 * querying any channel will do, so we use channel 1 all the time.
656 if (dlm_analog_chan_srate_get(sdi->conn, 1, &tmp_float) != SR_OK)
659 state->sample_rate = tmp_float;
665 * Obtains information about the current device state from the oscilloscope,
666 * including all analog and digital channel configurations.
667 * The internal state information is updated accordingly.
669 * @param sdi The device instance.
671 * @return SR_ERR on error, SR_OK otherwise.
673 SR_PRIV int dlm_scope_state_query(struct sr_dev_inst *sdi)
675 struct dev_context *devc;
676 struct scope_state *state;
677 const struct scope_config *config;
683 config = devc->model_config;
684 state = devc->model_state;
686 if (analog_channel_state_get(sdi, config, state) != SR_OK)
689 if (digital_channel_state_get(sdi, config, state) != SR_OK)
692 if (dlm_timebase_get(sdi->conn, &response) != SR_OK)
695 if (array_float_get(response, ARRAY_AND_SIZE(dlm_timebases), &i) != SR_OK) {
703 if (dlm_horiz_trigger_pos_get(sdi->conn, &tmp_float) != SR_OK)
706 /* TODO: Check if the calculation makes sense for the DLM. */
707 state->horiz_triggerpos = tmp_float /
708 (((double)dlm_timebases[state->timebase][0] /
709 dlm_timebases[state->timebase][1]) * config->num_xdivs);
710 state->horiz_triggerpos -= 0.5;
711 state->horiz_triggerpos *= -1;
713 if (dlm_trigger_source_get(sdi->conn, &response) != SR_OK) {
718 if (array_option_get(response, config->trigger_sources,
719 &state->trigger_source) != SR_OK) {
726 if (dlm_trigger_slope_get(sdi->conn, &i) != SR_OK)
729 state->trigger_slope = i;
731 if (dlm_acq_length_get(sdi->conn, &state->samples_per_frame) != SR_OK) {
732 sr_err("Failed to query acquisition length.");
736 dlm_sample_rate_query(sdi);
738 scope_state_dump(config, state);
744 * Creates a new device state structure.
746 * @param config The device configuration to use.
748 * @return The newly allocated scope_state struct.
750 static struct scope_state *dlm_scope_state_new(const struct scope_config *config)
752 struct scope_state *state;
754 state = g_malloc0(sizeof(struct scope_state));
756 state->analog_states = g_malloc0(config->analog_channels *
757 sizeof(struct analog_channel_state));
759 state->digital_states = g_malloc0(config->digital_channels *
762 state->pod_states = g_malloc0(config->pods * sizeof(gboolean));
768 * Frees the memory that was allocated by a call to dlm_scope_state_new().
770 * @param state The device state structure whose memory is to be freed.
772 SR_PRIV void dlm_scope_state_destroy(struct scope_state *state)
774 g_free(state->analog_states);
775 g_free(state->digital_states);
776 g_free(state->pod_states);
780 SR_PRIV int dlm_model_get(char *model_id, char **model_name, int *model_index)
787 for (i = 0; i < ARRAY_SIZE(scope_models); i++) {
788 for (j = 0; scope_models[i].model_id[j]; j++) {
789 if (!strcmp(model_id, scope_models[i].model_id[j])) {
791 *model_name = (char *)scope_models[i].model_name[j];
795 if (*model_index != -1)
799 if (*model_index == -1) {
800 sr_err("Found unsupported DLM device with model identifier %s.",
809 * Attempts to initialize a DL/DLM device and prepares internal structures
810 * if a suitable device was found.
812 * @param sdi The device instance.
814 SR_PRIV int dlm_device_init(struct sr_dev_inst *sdi, int model_index)
818 struct sr_channel *ch;
819 struct dev_context *devc;
823 devc->analog_groups = g_malloc0(sizeof(struct sr_channel_group*) *
824 scope_models[model_index].analog_channels);
826 devc->digital_groups = g_malloc0(sizeof(struct sr_channel_group*) *
827 scope_models[model_index].pods);
829 /* Add analog channels, each in its own group. */
830 for (i = 0; i < scope_models[model_index].analog_channels; i++) {
831 ch = sr_channel_new(sdi, i, SR_CHANNEL_ANALOG, TRUE,
832 (*scope_models[model_index].analog_names)[i]);
834 devc->analog_groups[i] = g_malloc0(sizeof(struct sr_channel_group));
836 devc->analog_groups[i]->name = g_strdup(
837 (char *)(*scope_models[model_index].analog_names)[i]);
838 devc->analog_groups[i]->channels = g_slist_append(NULL, ch);
840 sdi->channel_groups = g_slist_append(sdi->channel_groups,
841 devc->analog_groups[i]);
844 /* Add digital channel groups. */
845 for (i = 0; i < scope_models[model_index].pods; i++) {
846 g_snprintf(tmp, sizeof(tmp), "POD%d", i);
848 devc->digital_groups[i] = g_malloc0(sizeof(struct sr_channel_group));
849 if (!devc->digital_groups[i])
850 return SR_ERR_MALLOC;
852 devc->digital_groups[i]->name = g_strdup(tmp);
853 sdi->channel_groups = g_slist_append(sdi->channel_groups,
854 devc->digital_groups[i]);
857 /* Add digital channels. */
858 for (i = 0; i < scope_models[model_index].digital_channels; i++) {
859 ch = sr_channel_new(sdi, DLM_DIG_CHAN_INDEX_OFFS + i,
860 SR_CHANNEL_LOGIC, TRUE,
861 (*scope_models[model_index].digital_names)[i]);
863 devc->digital_groups[i / 8]->channels = g_slist_append(
864 devc->digital_groups[i / 8]->channels, ch);
866 devc->model_config = &scope_models[model_index];
867 devc->frame_limit = 0;
869 if (!(devc->model_state = dlm_scope_state_new(devc->model_config)))
870 return SR_ERR_MALLOC;
872 /* Disable non-standard response behavior. */
873 if (dlm_response_headers_set(sdi->conn, FALSE) != SR_OK)
879 SR_PRIV int dlm_channel_data_request(const struct sr_dev_inst *sdi)
881 struct dev_context *devc;
882 struct sr_channel *ch;
886 ch = devc->current_channel->data;
889 case SR_CHANNEL_ANALOG:
890 result = dlm_analog_data_get(sdi->conn, ch->index + 1);
892 case SR_CHANNEL_LOGIC:
893 result = dlm_digital_data_get(sdi->conn);
896 sr_err("Invalid channel type encountered (%d).",
902 devc->data_pending = TRUE;
904 devc->data_pending = FALSE;
910 * Reads and removes the block data header from a given data input.
911 * Format is #ndddd... with n being the number of decimal digits d.
912 * The string dddd... contains the decimal-encoded length of the data.
913 * Example: #9000000013 would yield a length of 13 bytes.
915 * @param data The input data.
916 * @param len The determined input data length.
918 static int dlm_block_data_header_process(GArray *data, int *len)
923 if (g_array_index(data, gchar, 0) != '#')
926 n = (uint8_t)(g_array_index(data, gchar, 1) - '0');
928 for (i = 0; i < n; i++)
929 s[i] = g_array_index(data, gchar, 2 + i);
932 if (sr_atoi(s, len) != SR_OK)
935 g_array_remove_range(data, 0, 2 + n);
941 * Turns raw sample data into voltages and sends them off to the session bus.
943 * @param data The raw sample data.
944 * @ch_state Pointer to the state of the channel whose data we're processing.
945 * @sdi The device instance.
947 * @return SR_ERR when data is trucated, SR_OK otherwise.
949 static int dlm_analog_samples_send(GArray *data,
950 struct analog_channel_state *ch_state,
951 struct sr_dev_inst *sdi)
954 float voltage, range, offset;
956 struct dev_context *devc;
957 struct scope_state *model_state;
958 struct sr_channel *ch;
959 struct sr_datafeed_analog analog;
960 struct sr_analog_encoding encoding;
961 struct sr_analog_meaning meaning;
962 struct sr_analog_spec spec;
963 struct sr_datafeed_packet packet;
966 model_state = devc->model_state;
967 samples = model_state->samples_per_frame;
968 ch = devc->current_channel->data;
970 if (data->len < samples * sizeof(uint8_t)) {
971 sr_err("Truncated waveform data packet received.");
975 range = ch_state->waveform_range;
976 offset = ch_state->waveform_offset;
979 * Convert byte sample to voltage according to
980 * page 269 of the Communication Interface User's Manual.
982 float_data = g_array_new(FALSE, FALSE, sizeof(float));
983 for (i = 0; i < samples; i++) {
984 voltage = (float)g_array_index(data, int8_t, i);
985 voltage = (range * voltage /
986 DLM_DIVISION_FOR_BYTE_FORMAT) + offset;
987 g_array_append_val(float_data, voltage);
990 /* TODO: Use proper 'digits' value for this device (and its modes). */
991 sr_analog_init(&analog, &encoding, &meaning, &spec, 2);
992 analog.meaning->channels = g_slist_append(NULL, ch);
993 analog.num_samples = float_data->len;
994 analog.data = (float*)float_data->data;
995 analog.meaning->mq = SR_MQ_VOLTAGE;
996 analog.meaning->unit = SR_UNIT_VOLT;
997 analog.meaning->mqflags = 0;
998 packet.type = SR_DF_ANALOG;
999 packet.payload = &analog;
1000 sr_session_send(sdi, &packet);
1001 g_slist_free(analog.meaning->channels);
1003 g_array_free(float_data, TRUE);
1004 g_array_remove_range(data, 0, samples * sizeof(uint8_t));
1010 * Sends logic sample data off to the session bus.
1012 * @param data The raw sample data.
1013 * @ch_state Pointer to the state of the channel whose data we're processing.
1014 * @sdi The device instance.
1016 * @return SR_ERR when data is trucated, SR_OK otherwise.
1018 static int dlm_digital_samples_send(GArray *data,
1019 struct sr_dev_inst *sdi)
1021 struct dev_context *devc;
1022 struct scope_state *model_state;
1024 struct sr_datafeed_logic logic;
1025 struct sr_datafeed_packet packet;
1028 model_state = devc->model_state;
1029 samples = model_state->samples_per_frame;
1031 if (data->len < samples * sizeof(uint8_t)) {
1032 sr_err("Truncated waveform data packet received.");
1036 logic.length = samples;
1038 logic.data = data->data;
1039 packet.type = SR_DF_LOGIC;
1040 packet.payload = &logic;
1041 sr_session_send(sdi, &packet);
1043 g_array_remove_range(data, 0, samples * sizeof(uint8_t));
1049 * Attempts to query sample data from the oscilloscope in order to send it
1050 * to the session bus for further processing.
1052 * @param fd The file descriptor used as the event source.
1053 * @param revents The received events.
1054 * @param cb_data Callback data, in this case our device instance.
1056 * @return TRUE in case of success or a recoverable error,
1057 * FALSE when a fatal error was encountered.
1059 SR_PRIV int dlm_data_receive(int fd, int revents, void *cb_data)
1061 struct sr_dev_inst *sdi;
1062 struct scope_state *model_state;
1063 struct dev_context *devc;
1064 struct sr_channel *ch;
1065 struct sr_datafeed_packet packet;
1066 int chunk_len, num_bytes;
1067 static GArray *data = NULL;
1072 if (!(sdi = cb_data))
1075 if (!(devc = sdi->priv))
1078 if (!(model_state = (struct scope_state*)devc->model_state))
1081 /* Are we waiting for a response from the device? */
1082 if (!devc->data_pending)
1085 /* Check if a new query response is coming our way. */
1087 if (sr_scpi_read_begin(sdi->conn) == SR_OK)
1088 /* The 16 here accounts for the header and EOL. */
1089 data = g_array_sized_new(FALSE, FALSE, sizeof(uint8_t),
1090 16 + model_state->samples_per_frame);
1095 /* Store incoming data. */
1096 chunk_len = sr_scpi_read_data(sdi->conn, devc->receive_buffer,
1097 RECEIVE_BUFFER_SIZE);
1098 if (chunk_len < 0) {
1099 sr_err("Error while reading data: %d", chunk_len);
1102 g_array_append_vals(data, devc->receive_buffer, chunk_len);
1104 /* Read the entire query response before processing. */
1105 if (!sr_scpi_read_complete(sdi->conn))
1108 /* We finished reading and are no longer waiting for data. */
1109 devc->data_pending = FALSE;
1111 /* Signal the beginning of a new frame if this is the first channel. */
1112 if (devc->current_channel == devc->enabled_channels) {
1113 packet.type = SR_DF_FRAME_BEGIN;
1114 sr_session_send(sdi, &packet);
1117 if (dlm_block_data_header_process(data, &num_bytes) != SR_OK) {
1118 sr_err("Encountered malformed block data header.");
1122 if (num_bytes == 0) {
1123 sr_warn("Zero-length waveform data packet received. " \
1124 "Live mode not supported yet, stopping " \
1125 "acquisition and retrying.");
1126 /* Don't care about return value here. */
1127 dlm_acquisition_stop(sdi->conn);
1128 g_array_free(data, TRUE);
1129 dlm_channel_data_request(sdi);
1133 ch = devc->current_channel->data;
1135 case SR_CHANNEL_ANALOG:
1136 if (dlm_analog_samples_send(data,
1137 &model_state->analog_states[ch->index],
1141 case SR_CHANNEL_LOGIC:
1142 if (dlm_digital_samples_send(data, sdi) != SR_OK)
1146 sr_err("Invalid channel type encountered.");
1150 g_array_free(data, TRUE);
1154 * Signal the end of this frame if this was the last enabled channel
1155 * and set the next enabled channel. Then, request its data.
1157 if (!devc->current_channel->next) {
1158 packet.type = SR_DF_FRAME_END;
1159 sr_session_send(sdi, &packet);
1160 devc->current_channel = devc->enabled_channels;
1163 * As of now we only support importing the current acquisition
1164 * data so we're going to stop at this point.
1166 sr_dev_acquisition_stop(sdi);
1169 devc->current_channel = devc->current_channel->next;
1171 if (dlm_channel_data_request(sdi) != SR_OK) {
1172 sr_err("Failed to request acquisition data.");
1180 g_array_free(data, TRUE);