drivers: Reduce unnecessarily high indentation in some places.

This commit is contained in:
Uwe Hermann 2017-08-04 23:24:15 +02:00
parent 612336970d
commit 3782e57129
7 changed files with 261 additions and 276 deletions

View File

@ -158,13 +158,14 @@ 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 (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 (read_data(sdi, scpi, devc, 1) < 0)
break;
if (devc->rcv_buffer[0] != '4' &&
devc->rcv_buffer[0] != '5' &&
devc->rcv_buffer[0] != '6') {
@ -176,10 +177,10 @@ SR_PRIV int gwinstek_gds_800_receive_data(int fd, int revents, void *cb_data)
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) {
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);
@ -187,10 +188,10 @@ SR_PRIV int gwinstek_gds_800_receive_data(int fd, int revents, void *cb_data)
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) {
if (read_data(sdi, scpi, devc, sizeof(float)) < 0)
break;
/*
* Contrary to the documentation, this field is
* transfered with most significant byte first!
@ -207,7 +208,6 @@ SR_PRIV int gwinstek_gds_800_receive_data(int fd, int revents, void *cb_data)
devc->df_started = TRUE;
}
}
break;
case WAIT_FOR_TRANSFER_OF_CHANNEL_INDICATOR_COMPLETE:
if (read_data(sdi, scpi, devc, 1) == SR_OK)
@ -218,7 +218,9 @@ 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) {
if (read_data(sdi, scpi, devc, devc->data_size - 8) < 0)
break;
/* Fetch data needed for conversion from device. */
snprintf(command, sizeof(command), ":CHAN%d:SCAL?",
devc->cur_acq_channel + 1);
@ -284,7 +286,6 @@ SR_PRIV int gwinstek_gds_800_receive_data(int fd, int revents, void *cb_data)
devc->cur_acq_channel++;
return TRUE;
}
}
break;
}

View File

@ -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 (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);
} else {
return SR_ERR_NA;
}
break;
case SR_CONF_VDIV:
if (!cg) {
if (!cg)
return SR_ERR_CHANNEL_GROUP;
} else if (cg_type == CG_ANALOG) {
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]);
} else {
return SR_ERR_NA;
}
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 (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]);
} else {
return SR_ERR_NA;
}
break;
case SR_CONF_SAMPLERATE:
*data = g_variant_new_uint64(state->sample_rate);

View File

@ -495,7 +495,8 @@ 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) {
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],
@ -503,11 +504,11 @@ SR_PRIV int hmo_update_sample_rate(const struct sr_dev_inst *sdi)
channel_found = TRUE;
break;
}
}
if (!channel_found) {
for (i = 0; i < config->digital_pods; i++) {
if (state->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],
@ -516,7 +517,6 @@ SR_PRIV int hmo_update_sample_rate(const struct sr_dev_inst *sdi)
break;
}
}
}
/* No channel is active, ask the instrument for the sample rate
* in single shot mode */

View File

@ -312,34 +312,28 @@ 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]);
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]);
}
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]);
}
break;
case SR_CONF_PROBE_FACTOR:
if (!cg)
return SR_ERR_CHANNEL_GROUP;
else
*data = g_variant_new_uint64(devc->probe[ch]);
break;
default:
@ -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];
}
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];
}
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;
}
break;
default:
return SR_ERR_NA;
@ -427,7 +414,9 @@ 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 (!(changes & SR_CHANNEL_SET_ENABLED))
return SR_OK;
if (ch->enabled) {
v = devc->channel | (1 << ch->index);
if (v & (v - 1))
@ -437,7 +426,7 @@ static int config_channel_set(const struct sr_dev_inst *sdi,
} else {
devc->channel &= ~(1 << ch->index);
}
}
return SR_OK;
}

View File

@ -298,7 +298,10 @@ static struct sr_dev_inst *lascar_identify(unsigned char *config)
modelid = config[0];
sdi = NULL;
if (modelid) {
if (!modelid)
return sdi;
profile = NULL;
for (i = 0; profiles[i].modelid; i++) {
if (profiles[i].modelid == modelid) {
@ -341,7 +344,6 @@ static struct sr_dev_inst *lascar_identify(unsigned char *config)
devc = g_malloc0(sizeof(struct dev_context));
sdi->priv = devc;
devc->profile = profile;
}
return sdi;
}

View File

@ -913,7 +913,12 @@ 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 (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;
@ -953,7 +958,6 @@ SR_PRIV void LIBUSB_CALL logic16_receive_transfer(struct libusb_transfer *transf
free_transfer(transfer);
return;
}
}
resubmit_transfer(transfer);
}

View File

@ -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) {
if (cg_type != CG_ANALOG)
return SR_ERR_NA;
*data = g_variant_new_int32(model->num_ydivs);
ret = SR_OK;
break;
} else {
ret = SR_ERR_NA;
}
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]);