From: Uwe Hermann Date: Fri, 4 Aug 2017 21:24:15 +0000 (+0200) Subject: drivers: Reduce unnecessarily high indentation in some places. X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=3782e57129fa661a773be337c9f548708f593eb0;p=libsigrok.git drivers: Reduce unnecessarily high indentation in some places. --- diff --git a/src/hardware/gwinstek-gds-800/protocol.c b/src/hardware/gwinstek-gds-800/protocol.c index 962bfe05..ce9e8d41 100644 --- a/src/hardware/gwinstek-gds-800/protocol.c +++ b/src/hardware/gwinstek-gds-800/protocol.c @@ -158,55 +158,55 @@ SR_PRIV int gwinstek_gds_800_receive_data(int fd, int revents, void *cb_data) } break; case WAIT_FOR_TRANSFER_OF_BEGIN_TRANSMISSION_COMPLETE: - if (read_data(sdi, scpi, devc, 1) == SR_OK) { - if (devc->rcv_buffer[0] == '#') - devc->state = WAIT_FOR_TRANSFER_OF_DATA_SIZE_DIGIT_COMPLETE; - } + if (read_data(sdi, scpi, devc, 1) < 0) + break; + if (devc->rcv_buffer[0] == '#') + devc->state = WAIT_FOR_TRANSFER_OF_DATA_SIZE_DIGIT_COMPLETE; break; case WAIT_FOR_TRANSFER_OF_DATA_SIZE_DIGIT_COMPLETE: - if (read_data(sdi, scpi, devc, 1) == SR_OK) { - if (devc->rcv_buffer[0] != '4' && - devc->rcv_buffer[0] != '5' && - devc->rcv_buffer[0] != '6') { - sr_err("Data size digits is not 4, 5 or 6 but " - "'%c'.", devc->rcv_buffer[0]); - sr_dev_acquisition_stop(sdi); - return TRUE; - } else { - devc->data_size_digits = devc->rcv_buffer[0] - '0'; - devc->state = WAIT_FOR_TRANSFER_OF_DATA_SIZE_COMPLETE; - } + if (read_data(sdi, scpi, devc, 1) < 0) + break; + if (devc->rcv_buffer[0] != '4' && + devc->rcv_buffer[0] != '5' && + devc->rcv_buffer[0] != '6') { + sr_err("Data size digits is not 4, 5 or 6 but " + "'%c'.", devc->rcv_buffer[0]); + sr_dev_acquisition_stop(sdi); + return TRUE; + } else { + devc->data_size_digits = devc->rcv_buffer[0] - '0'; + devc->state = WAIT_FOR_TRANSFER_OF_DATA_SIZE_COMPLETE; } break; case WAIT_FOR_TRANSFER_OF_DATA_SIZE_COMPLETE: - if (read_data(sdi, scpi, devc, devc->data_size_digits) == SR_OK) { - devc->rcv_buffer[devc->data_size_digits] = 0; - if (sr_atoi(devc->rcv_buffer, &devc->data_size) != SR_OK) { - sr_err("Could not parse data size '%s'", devc->rcv_buffer); - sr_dev_acquisition_stop(sdi); - return TRUE; - } else - devc->state = WAIT_FOR_TRANSFER_OF_SAMPLE_RATE_COMPLETE; - } + if (read_data(sdi, scpi, devc, devc->data_size_digits) < 0) + break; + devc->rcv_buffer[devc->data_size_digits] = 0; + if (sr_atoi(devc->rcv_buffer, &devc->data_size) != SR_OK) { + sr_err("Could not parse data size '%s'", devc->rcv_buffer); + sr_dev_acquisition_stop(sdi); + return TRUE; + } else + devc->state = WAIT_FOR_TRANSFER_OF_SAMPLE_RATE_COMPLETE; break; case WAIT_FOR_TRANSFER_OF_SAMPLE_RATE_COMPLETE: - if (read_data(sdi, scpi, devc, sizeof(float)) == SR_OK) { - /* - * Contrary to the documentation, this field is - * transfered with most significant byte first! - */ - sample_rate = RB32(devc->rcv_buffer); - memcpy(&devc->sample_rate, &sample_rate, sizeof(float)); - devc->state = WAIT_FOR_TRANSFER_OF_CHANNEL_INDICATOR_COMPLETE; + if (read_data(sdi, scpi, devc, sizeof(float)) < 0) + break; + /* + * Contrary to the documentation, this field is + * transfered with most significant byte first! + */ + sample_rate = RB32(devc->rcv_buffer); + memcpy(&devc->sample_rate, &sample_rate, sizeof(float)); + devc->state = WAIT_FOR_TRANSFER_OF_CHANNEL_INDICATOR_COMPLETE; - if (!devc->df_started) { - std_session_send_df_header(sdi); + if (!devc->df_started) { + std_session_send_df_header(sdi); - packet.type = SR_DF_FRAME_BEGIN; - sr_session_send(sdi, &packet); + packet.type = SR_DF_FRAME_BEGIN; + sr_session_send(sdi, &packet); - devc->df_started = TRUE; - } + devc->df_started = TRUE; } break; case WAIT_FOR_TRANSFER_OF_CHANNEL_INDICATOR_COMPLETE: @@ -218,72 +218,73 @@ SR_PRIV int gwinstek_gds_800_receive_data(int fd, int revents, void *cb_data) devc->state = WAIT_FOR_TRANSFER_OF_CHANNEL_DATA_COMPLETE; break; case WAIT_FOR_TRANSFER_OF_CHANNEL_DATA_COMPLETE: - if (read_data(sdi, scpi, devc, devc->data_size - 8) == SR_OK) { - /* Fetch data needed for conversion from device. */ - snprintf(command, sizeof(command), ":CHAN%d:SCAL?", - devc->cur_acq_channel + 1); - if (sr_scpi_get_string(scpi, command, &response) != SR_OK) { - sr_err("Failed to get volts per division."); - sr_dev_acquisition_stop(sdi); - return TRUE; - } - volts_per_division = g_ascii_strtod(response, &end_ptr); - if (!strcmp(end_ptr, "mV")) - volts_per_division *= 1.e-3; - g_free(response); + if (read_data(sdi, scpi, devc, devc->data_size - 8) < 0) + break; - num_samples = (devc->data_size - 8) / 2; - sr_spew("Received %d number of samples from channel " - "%d.", num_samples, devc->cur_acq_channel + 1); + /* Fetch data needed for conversion from device. */ + snprintf(command, sizeof(command), ":CHAN%d:SCAL?", + devc->cur_acq_channel + 1); + if (sr_scpi_get_string(scpi, command, &response) != SR_OK) { + sr_err("Failed to get volts per division."); + sr_dev_acquisition_stop(sdi); + return TRUE; + } + volts_per_division = g_ascii_strtod(response, &end_ptr); + if (!strcmp(end_ptr, "mV")) + volts_per_division *= 1.e-3; + g_free(response); - float vbit = volts_per_division * VERTICAL_DIVISIONS / 256.0; - float vbitlog = log10f(vbit); - int digits = -(int)vbitlog + (vbitlog < 0.0); + num_samples = (devc->data_size - 8) / 2; + sr_spew("Received %d number of samples from channel " + "%d.", num_samples, devc->cur_acq_channel + 1); - /* Convert data. */ - for (i = 0; i < num_samples; i++) - samples[i] = ((float) ((int16_t) (RB16(&devc->rcv_buffer[i*2])))) * vbit; + float vbit = volts_per_division * VERTICAL_DIVISIONS / 256.0; + float vbitlog = log10f(vbit); + int digits = -(int)vbitlog + (vbitlog < 0.0); - /* Fill frame. */ - sr_analog_init(&analog, &encoding, &meaning, &spec, digits); - analog.meaning->channels = g_slist_append(NULL, g_slist_nth_data(sdi->channels, devc->cur_acq_channel)); - analog.num_samples = num_samples; - analog.data = samples; - analog.meaning->mq = SR_MQ_VOLTAGE; - analog.meaning->unit = SR_UNIT_VOLT; - analog.meaning->mqflags = 0; - packet.type = SR_DF_ANALOG; - packet.payload = &analog; - sr_session_send(sdi, &packet); - g_slist_free(analog.meaning->channels); + /* Convert data. */ + for (i = 0; i < num_samples; i++) + samples[i] = ((float) ((int16_t) (RB16(&devc->rcv_buffer[i*2])))) * vbit; - /* All channels acquired. */ - if (devc->cur_acq_channel == ANALOG_CHANNELS - 1) { - sr_spew("All channels acquired."); + /* Fill frame. */ + sr_analog_init(&analog, &encoding, &meaning, &spec, digits); + analog.meaning->channels = g_slist_append(NULL, g_slist_nth_data(sdi->channels, devc->cur_acq_channel)); + analog.num_samples = num_samples; + analog.data = samples; + analog.meaning->mq = SR_MQ_VOLTAGE; + analog.meaning->unit = SR_UNIT_VOLT; + analog.meaning->mqflags = 0; + packet.type = SR_DF_ANALOG; + packet.payload = &analog; + sr_session_send(sdi, &packet); + g_slist_free(analog.meaning->channels); - if (devc->cur_acq_frame == devc->frame_limit - 1) { - /* All frames acquired. */ - sr_spew("All frames acquired."); - sr_dev_acquisition_stop(sdi); - return TRUE; - } else { - /* Start acquiring next frame. */ - if (devc->df_started) { - packet.type = SR_DF_FRAME_END; - sr_session_send(sdi, &packet); + /* All channels acquired. */ + if (devc->cur_acq_channel == ANALOG_CHANNELS - 1) { + sr_spew("All channels acquired."); - packet.type = SR_DF_FRAME_BEGIN; - sr_session_send(sdi, &packet); - } - devc->cur_acq_frame++; - devc->state = START_ACQUISITION; - } - } else { - /* Start acquiring next channel. */ - devc->state = START_TRANSFER_OF_CHANNEL_DATA; - devc->cur_acq_channel++; + if (devc->cur_acq_frame == devc->frame_limit - 1) { + /* All frames acquired. */ + sr_spew("All frames acquired."); + sr_dev_acquisition_stop(sdi); return TRUE; + } else { + /* Start acquiring next frame. */ + if (devc->df_started) { + packet.type = SR_DF_FRAME_END; + sr_session_send(sdi, &packet); + + packet.type = SR_DF_FRAME_BEGIN; + sr_session_send(sdi, &packet); + } + devc->cur_acq_frame++; + devc->state = START_ACQUISITION; } + } else { + /* Start acquiring next channel. */ + devc->state = START_TRANSFER_OF_CHANNEL_DATA; + devc->cur_acq_channel++; + return TRUE; } break; } diff --git a/src/hardware/hameg-hmo/api.c b/src/hardware/hameg-hmo/api.c index 0abc722c..44841e85 100644 --- a/src/hardware/hameg-hmo/api.c +++ b/src/hardware/hameg-hmo/api.c @@ -176,28 +176,24 @@ static int config_get(uint32_t key, GVariant **data, (*model->timebases)[state->timebase][1]); break; case SR_CONF_NUM_VDIV: - if (!cg) { + if (!cg) return SR_ERR_CHANNEL_GROUP; - } else if (cg_type == CG_ANALOG) { - if (std_cg_idx(cg, devc->analog_groups, model->analog_channels) < 0) - return SR_ERR_ARG; - *data = g_variant_new_int32(model->num_ydivs); - } else { + if (cg_type != CG_ANALOG) return SR_ERR_NA; - } + if (std_cg_idx(cg, devc->analog_groups, model->analog_channels) < 0) + return SR_ERR_ARG; + *data = g_variant_new_int32(model->num_ydivs); break; case SR_CONF_VDIV: - if (!cg) { + if (!cg) return SR_ERR_CHANNEL_GROUP; - } else if (cg_type == CG_ANALOG) { - if ((idx = std_cg_idx(cg, devc->analog_groups, model->analog_channels)) < 0) - return SR_ERR_ARG; - *data = g_variant_new("(tt)", - (*model->vdivs)[state->analog_channels[idx].vdiv][0], - (*model->vdivs)[state->analog_channels[idx].vdiv][1]); - } else { + if (cg_type != CG_ANALOG) return SR_ERR_NA; - } + if ((idx = std_cg_idx(cg, devc->analog_groups, model->analog_channels)) < 0) + return SR_ERR_ARG; + *data = g_variant_new("(tt)", + (*model->vdivs)[state->analog_channels[idx].vdiv][0], + (*model->vdivs)[state->analog_channels[idx].vdiv][1]); break; case SR_CONF_TRIGGER_SOURCE: *data = g_variant_new_string((*model->trigger_sources)[state->trigger_source]); @@ -209,15 +205,13 @@ static int config_get(uint32_t key, GVariant **data, *data = g_variant_new_double(state->horiz_triggerpos); break; case SR_CONF_COUPLING: - if (!cg) { + if (!cg) return SR_ERR_CHANNEL_GROUP; - } else if (cg_type == CG_ANALOG) { - if ((idx = std_cg_idx(cg, devc->analog_groups, model->analog_channels)) < 0) - return SR_ERR_ARG; - *data = g_variant_new_string((*model->coupling_options)[state->analog_channels[idx].coupling]); - } else { + if (cg_type != CG_ANALOG) return SR_ERR_NA; - } + if ((idx = std_cg_idx(cg, devc->analog_groups, model->analog_channels)) < 0) + return SR_ERR_ARG; + *data = g_variant_new_string((*model->coupling_options)[state->analog_channels[idx].coupling]); break; case SR_CONF_SAMPLERATE: *data = g_variant_new_uint64(state->sample_rate); diff --git a/src/hardware/hameg-hmo/protocol.c b/src/hardware/hameg-hmo/protocol.c index 0c4d57f3..13063382 100644 --- a/src/hardware/hameg-hmo/protocol.c +++ b/src/hardware/hameg-hmo/protocol.c @@ -495,8 +495,21 @@ SR_PRIV int hmo_update_sample_rate(const struct sr_dev_inst *sdi) channel_found = FALSE; for (i = 0; i < config->analog_channels; i++) { - if (state->analog_channels[i].state) { - g_snprintf(chan_name, sizeof(chan_name), "CHAN%d", i + 1); + if (!state->analog_channels[i].state) + continue; + g_snprintf(chan_name, sizeof(chan_name), "CHAN%d", i + 1); + g_snprintf(tmp_str, sizeof(tmp_str), + (*config->scpi_dialect)[SCPI_CMD_GET_SAMPLE_RATE_LIVE], + chan_name); + channel_found = TRUE; + break; + } + + if (!channel_found) { + for (i = 0; i < config->digital_pods; i++) { + if (!state->digital_pods[i]) + continue; + g_snprintf(chan_name, sizeof(chan_name), "POD%d", i); g_snprintf(tmp_str, sizeof(tmp_str), (*config->scpi_dialect)[SCPI_CMD_GET_SAMPLE_RATE_LIVE], chan_name); @@ -505,19 +518,6 @@ SR_PRIV int hmo_update_sample_rate(const struct sr_dev_inst *sdi) } } - if (!channel_found) { - for (i = 0; i < config->digital_pods; i++) { - if (state->digital_pods[i]) { - g_snprintf(chan_name, sizeof(chan_name), "POD%d", i); - g_snprintf(tmp_str, sizeof(tmp_str), - (*config->scpi_dialect)[SCPI_CMD_GET_SAMPLE_RATE_LIVE], - chan_name); - channel_found = TRUE; - break; - } - } - } - /* No channel is active, ask the instrument for the sample rate * in single shot mode */ if (!channel_found) { diff --git a/src/hardware/hung-chang-dso-2100/api.c b/src/hardware/hung-chang-dso-2100/api.c index a16eb899..e0806070 100644 --- a/src/hardware/hung-chang-dso-2100/api.c +++ b/src/hardware/hung-chang-dso-2100/api.c @@ -312,35 +312,29 @@ static int config_get(uint32_t key, GVariant **data, case SR_CONF_TRIGGER_SLOPE: if (devc->edge >= ARRAY_SIZE(trigger_slopes)) return SR_ERR; - else - *data = g_variant_new_string(trigger_slopes[devc->edge]); + *data = g_variant_new_string(trigger_slopes[devc->edge]); break; case SR_CONF_BUFFERSIZE: *data = g_variant_new_uint64(buffersizes[devc->last_step]); break; case SR_CONF_VDIV: - if (!cg) { + if (!cg) return SR_ERR_CHANNEL_GROUP; - } else { - if ((idx = std_u8_idx_s(devc->cctl[ch] & 0x33, ARRAY_AND_SIZE(vdivs_map))) < 0) - return SR_ERR_BUG; - *data = g_variant_new("(tt)", vdivs[idx][0], vdivs[idx][1]); - } + if ((idx = std_u8_idx_s(devc->cctl[ch] & 0x33, ARRAY_AND_SIZE(vdivs_map))) < 0) + return SR_ERR_BUG; + *data = g_variant_new("(tt)", vdivs[idx][0], vdivs[idx][1]); break; case SR_CONF_COUPLING: - if (!cg) { + if (!cg) return SR_ERR_CHANNEL_GROUP; - } else { - if ((idx = std_u8_idx_s(devc->cctl[ch] & 0x0C, ARRAY_AND_SIZE(coupling_map))) < 0) - return SR_ERR_BUG; - *data = g_variant_new_string(coupling[idx]); - } + if ((idx = std_u8_idx_s(devc->cctl[ch] & 0x0C, ARRAY_AND_SIZE(coupling_map))) < 0) + return SR_ERR_BUG; + *data = g_variant_new_string(coupling[idx]); break; case SR_CONF_PROBE_FACTOR: if (!cg) return SR_ERR_CHANNEL_GROUP; - else - *data = g_variant_new_uint64(devc->probe[ch]); + *data = g_variant_new_uint64(devc->probe[ch]); break; default: return SR_ERR_NA; @@ -384,35 +378,28 @@ static int config_set(uint32_t key, GVariant *data, devc->last_step = idx; break; case SR_CONF_VDIV: - if (!cg) { + if (!cg) return SR_ERR_CHANNEL_GROUP; - } else if (!g_variant_is_of_type(data, G_VARIANT_TYPE("(tt)"))) { + if (!g_variant_is_of_type(data, G_VARIANT_TYPE("(tt)"))) return SR_ERR_ARG; - } else { - if ((idx = std_u64_tuple_idx(data, ARRAY_AND_SIZE(vdivs))) < 0) - return SR_ERR_ARG; - devc->cctl[ch] = (devc->cctl[ch] & 0xCC) | vdivs_map[idx]; - } + if ((idx = std_u64_tuple_idx(data, ARRAY_AND_SIZE(vdivs))) < 0) + return SR_ERR_ARG; + devc->cctl[ch] = (devc->cctl[ch] & 0xCC) | vdivs_map[idx]; break; case SR_CONF_COUPLING: - if (!cg) { + if (!cg) return SR_ERR_CHANNEL_GROUP; - } else { - if ((idx = std_str_idx(data, ARRAY_AND_SIZE(coupling))) < 0) - return SR_ERR_ARG; - devc->cctl[ch] = (devc->cctl[ch] & 0xF3) | coupling_map[idx]; - } + if ((idx = std_str_idx(data, ARRAY_AND_SIZE(coupling))) < 0) + return SR_ERR_ARG; + devc->cctl[ch] = (devc->cctl[ch] & 0xF3) | coupling_map[idx]; break; case SR_CONF_PROBE_FACTOR: - if (!cg) { + if (!cg) return SR_ERR_CHANNEL_GROUP; - } else { - u = g_variant_get_uint64(data); - if (!u) - return SR_ERR_ARG; - else - devc->probe[ch] = u; - } + u = g_variant_get_uint64(data); + if (!u) + return SR_ERR_ARG; + devc->probe[ch] = u; break; default: return SR_ERR_NA; @@ -427,17 +414,19 @@ static int config_channel_set(const struct sr_dev_inst *sdi, struct dev_context *devc = sdi->priv; uint8_t v; - if (changes & SR_CHANNEL_SET_ENABLED) { - if (ch->enabled) { - v = devc->channel | (1 << ch->index); - if (v & (v - 1)) - return SR_ERR; - devc->channel = v; - devc->enabled_channel->data = ch; - } else { - devc->channel &= ~(1 << ch->index); - } + if (!(changes & SR_CHANNEL_SET_ENABLED)) + return SR_OK; + + if (ch->enabled) { + v = devc->channel | (1 << ch->index); + if (v & (v - 1)) + return SR_ERR; + devc->channel = v; + devc->enabled_channel->data = ch; + } else { + devc->channel &= ~(1 << ch->index); } + return SR_OK; } diff --git a/src/hardware/lascar-el-usb/protocol.c b/src/hardware/lascar-el-usb/protocol.c index bda67b33..44f4be82 100644 --- a/src/hardware/lascar-el-usb/protocol.c +++ b/src/hardware/lascar-el-usb/protocol.c @@ -298,51 +298,53 @@ static struct sr_dev_inst *lascar_identify(unsigned char *config) modelid = config[0]; sdi = NULL; - if (modelid) { - profile = NULL; - for (i = 0; profiles[i].modelid; i++) { - if (profiles[i].modelid == modelid) { - profile = &profiles[i]; - break; - } - } - if (!profile) { - sr_dbg("unknown EL-USB modelid %d", modelid); - return NULL; - } - i = config[52] | (config[53] << 8); - memcpy(firmware, config + 0x30, 4); - firmware[4] = '\0'; - sr_dbg("found %s with firmware version %s serial %d", - profile->modelname, firmware, i); + if (!modelid) + return sdi; - if (profile->logformat == LOG_UNSUPPORTED) { - sr_dbg("unsupported EL-USB logformat for %s", profile->modelname); - return NULL; + profile = NULL; + for (i = 0; profiles[i].modelid; i++) { + if (profiles[i].modelid == modelid) { + profile = &profiles[i]; + break; } + } + if (!profile) { + sr_dbg("unknown EL-USB modelid %d", modelid); + return NULL; + } - sdi = g_malloc0(sizeof(struct sr_dev_inst)); - sdi->status = SR_ST_INACTIVE; - sdi->vendor = g_strdup("Lascar"); - sdi->model = g_strdup(profile->modelname); - sdi->version = g_strdup(firmware); - - if (profile->logformat == LOG_TEMP_RH) { - /* Model this as two channels: temperature and humidity. */ - sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "Temp"); - sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "Hum"); - } else if (profile->logformat == LOG_CO) { - sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "CO"); - } else { - sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "P1"); - } + i = config[52] | (config[53] << 8); + memcpy(firmware, config + 0x30, 4); + firmware[4] = '\0'; + sr_dbg("found %s with firmware version %s serial %d", + profile->modelname, firmware, i); - devc = g_malloc0(sizeof(struct dev_context)); - sdi->priv = devc; - devc->profile = profile; + if (profile->logformat == LOG_UNSUPPORTED) { + sr_dbg("unsupported EL-USB logformat for %s", profile->modelname); + return NULL; } + sdi = g_malloc0(sizeof(struct sr_dev_inst)); + sdi->status = SR_ST_INACTIVE; + sdi->vendor = g_strdup("Lascar"); + sdi->model = g_strdup(profile->modelname); + sdi->version = g_strdup(firmware); + + if (profile->logformat == LOG_TEMP_RH) { + /* Model this as two channels: temperature and humidity. */ + sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "Temp"); + sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "Hum"); + } else if (profile->logformat == LOG_CO) { + sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "CO"); + } else { + sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "P1"); + } + + devc = g_malloc0(sizeof(struct dev_context)); + sdi->priv = devc; + devc->profile = profile; + return sdi; } diff --git a/src/hardware/saleae-logic16/protocol.c b/src/hardware/saleae-logic16/protocol.c index 28a4c52f..a3dc0900 100644 --- a/src/hardware/saleae-logic16/protocol.c +++ b/src/hardware/saleae-logic16/protocol.c @@ -913,47 +913,51 @@ SR_PRIV void LIBUSB_CALL logic16_receive_transfer(struct libusb_transfer *transf new_samples = convert_sample_data(devc, devc->convbuffer, devc->convbuffer_size, transfer->buffer, transfer->actual_length); - if (new_samples > 0) { - if (devc->trigger_fired) { - /* Send the incoming transfer to the session bus. */ + if (new_samples <= 0) { + resubmit_transfer(transfer); + return; + } + + /* At least one new sample. */ + if (devc->trigger_fired) { + /* Send the incoming transfer to the session bus. */ + packet.type = SR_DF_LOGIC; + packet.payload = &logic; + if (devc->limit_samples && + new_samples > devc->limit_samples - devc->sent_samples) + new_samples = devc->limit_samples - devc->sent_samples; + logic.length = new_samples * 2; + logic.unitsize = 2; + logic.data = devc->convbuffer; + sr_session_send(sdi, &packet); + devc->sent_samples += new_samples; + } else { + trigger_offset = soft_trigger_logic_check(devc->stl, + devc->convbuffer, new_samples * 2, &pre_trigger_samples); + if (trigger_offset > -1) { + devc->sent_samples += pre_trigger_samples; packet.type = SR_DF_LOGIC; packet.payload = &logic; + num_samples = new_samples - trigger_offset; if (devc->limit_samples && - new_samples > devc->limit_samples - devc->sent_samples) - new_samples = devc->limit_samples - devc->sent_samples; - logic.length = new_samples * 2; + num_samples > devc->limit_samples - devc->sent_samples) + num_samples = devc->limit_samples - devc->sent_samples; + logic.length = num_samples * 2; logic.unitsize = 2; - logic.data = devc->convbuffer; + logic.data = devc->convbuffer + trigger_offset * 2; sr_session_send(sdi, &packet); - devc->sent_samples += new_samples; - } else { - trigger_offset = soft_trigger_logic_check(devc->stl, - devc->convbuffer, new_samples * 2, &pre_trigger_samples); - if (trigger_offset > -1) { - devc->sent_samples += pre_trigger_samples; - packet.type = SR_DF_LOGIC; - packet.payload = &logic; - num_samples = new_samples - trigger_offset; - if (devc->limit_samples && - num_samples > devc->limit_samples - devc->sent_samples) - num_samples = devc->limit_samples - devc->sent_samples; - logic.length = num_samples * 2; - logic.unitsize = 2; - logic.data = devc->convbuffer + trigger_offset * 2; - sr_session_send(sdi, &packet); - devc->sent_samples += num_samples; - - devc->trigger_fired = TRUE; - } - } + devc->sent_samples += num_samples; - if (devc->limit_samples && - (uint64_t)devc->sent_samples >= devc->limit_samples) { - devc->sent_samples = -2; - free_transfer(transfer); - return; + devc->trigger_fired = TRUE; } } + if (devc->limit_samples && + (uint64_t)devc->sent_samples >= devc->limit_samples) { + devc->sent_samples = -2; + free_transfer(transfer); + return; + } + resubmit_transfer(transfer); } diff --git a/src/hardware/yokogawa-dlm/api.c b/src/hardware/yokogawa-dlm/api.c index 16983653..9d566076 100644 --- a/src/hardware/yokogawa-dlm/api.c +++ b/src/hardware/yokogawa-dlm/api.c @@ -211,22 +211,18 @@ static int config_get(uint32_t key, GVariant **data, ret = SR_OK; break; case SR_CONF_NUM_VDIV: - if (!cg) { + if (!cg) return SR_ERR_CHANNEL_GROUP; - } else if (cg_type == CG_ANALOG) { - *data = g_variant_new_int32(model->num_ydivs); - ret = SR_OK; - break; - } else { - ret = SR_ERR_NA; - } + if (cg_type != CG_ANALOG) + return SR_ERR_NA; + *data = g_variant_new_int32(model->num_ydivs); + ret = SR_OK; break; case SR_CONF_VDIV: - ret = SR_ERR_NA; - if (!cg) { + if (!cg) return SR_ERR_CHANNEL_GROUP; - } else if (cg_type != CG_ANALOG) - break; + if (cg_type != CG_ANALOG) + return SR_ERR_NA; if ((idx = std_cg_idx(cg, devc->analog_groups, model->analog_channels)) < 0) return SR_ERR_ARG; *data = g_variant_new("(tt)", @@ -247,11 +243,10 @@ static int config_get(uint32_t key, GVariant **data, ret = SR_OK; break; case SR_CONF_COUPLING: - ret = SR_ERR_NA; - if (!cg) { + if (!cg) return SR_ERR_CHANNEL_GROUP; - } else if (cg_type != CG_ANALOG) - break; + if (cg_type != CG_ANALOG) + return SR_ERR_NA; if ((idx = std_cg_idx(cg, devc->analog_groups, model->analog_channels)) < 0) return SR_ERR_ARG; *data = g_variant_new_string((*model->coupling_options)[state->analog_states[idx].coupling]);