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; break;
case WAIT_FOR_TRANSFER_OF_BEGIN_TRANSMISSION_COMPLETE: 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] == '#') if (devc->rcv_buffer[0] == '#')
devc->state = WAIT_FOR_TRANSFER_OF_DATA_SIZE_DIGIT_COMPLETE; devc->state = WAIT_FOR_TRANSFER_OF_DATA_SIZE_DIGIT_COMPLETE;
}
break; break;
case WAIT_FOR_TRANSFER_OF_DATA_SIZE_DIGIT_COMPLETE: 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' && if (devc->rcv_buffer[0] != '4' &&
devc->rcv_buffer[0] != '5' && devc->rcv_buffer[0] != '5' &&
devc->rcv_buffer[0] != '6') { 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->data_size_digits = devc->rcv_buffer[0] - '0';
devc->state = WAIT_FOR_TRANSFER_OF_DATA_SIZE_COMPLETE; devc->state = WAIT_FOR_TRANSFER_OF_DATA_SIZE_COMPLETE;
} }
}
break; break;
case WAIT_FOR_TRANSFER_OF_DATA_SIZE_COMPLETE: 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; devc->rcv_buffer[devc->data_size_digits] = 0;
if (sr_atoi(devc->rcv_buffer, &devc->data_size) != SR_OK) { if (sr_atoi(devc->rcv_buffer, &devc->data_size) != SR_OK) {
sr_err("Could not parse data size '%s'", devc->rcv_buffer); 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; return TRUE;
} else } else
devc->state = WAIT_FOR_TRANSFER_OF_SAMPLE_RATE_COMPLETE; devc->state = WAIT_FOR_TRANSFER_OF_SAMPLE_RATE_COMPLETE;
}
break; break;
case WAIT_FOR_TRANSFER_OF_SAMPLE_RATE_COMPLETE: 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 * Contrary to the documentation, this field is
* transfered with most significant byte first! * 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; devc->df_started = TRUE;
} }
}
break; break;
case WAIT_FOR_TRANSFER_OF_CHANNEL_INDICATOR_COMPLETE: case WAIT_FOR_TRANSFER_OF_CHANNEL_INDICATOR_COMPLETE:
if (read_data(sdi, scpi, devc, 1) == SR_OK) 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; devc->state = WAIT_FOR_TRANSFER_OF_CHANNEL_DATA_COMPLETE;
break; break;
case WAIT_FOR_TRANSFER_OF_CHANNEL_DATA_COMPLETE: 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. */ /* Fetch data needed for conversion from device. */
snprintf(command, sizeof(command), ":CHAN%d:SCAL?", snprintf(command, sizeof(command), ":CHAN%d:SCAL?",
devc->cur_acq_channel + 1); 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++; devc->cur_acq_channel++;
return TRUE; return TRUE;
} }
}
break; break;
} }

View File

@ -176,28 +176,24 @@ static int config_get(uint32_t key, GVariant **data,
(*model->timebases)[state->timebase][1]); (*model->timebases)[state->timebase][1]);
break; break;
case SR_CONF_NUM_VDIV: case SR_CONF_NUM_VDIV:
if (!cg) { if (!cg)
return SR_ERR_CHANNEL_GROUP; 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) if (std_cg_idx(cg, devc->analog_groups, model->analog_channels) < 0)
return SR_ERR_ARG; return SR_ERR_ARG;
*data = g_variant_new_int32(model->num_ydivs); *data = g_variant_new_int32(model->num_ydivs);
} else {
return SR_ERR_NA;
}
break; break;
case SR_CONF_VDIV: case SR_CONF_VDIV:
if (!cg) { if (!cg)
return SR_ERR_CHANNEL_GROUP; 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) if ((idx = std_cg_idx(cg, devc->analog_groups, model->analog_channels)) < 0)
return SR_ERR_ARG; return SR_ERR_ARG;
*data = g_variant_new("(tt)", *data = g_variant_new("(tt)",
(*model->vdivs)[state->analog_channels[idx].vdiv][0], (*model->vdivs)[state->analog_channels[idx].vdiv][0],
(*model->vdivs)[state->analog_channels[idx].vdiv][1]); (*model->vdivs)[state->analog_channels[idx].vdiv][1]);
} else {
return SR_ERR_NA;
}
break; break;
case SR_CONF_TRIGGER_SOURCE: case SR_CONF_TRIGGER_SOURCE:
*data = g_variant_new_string((*model->trigger_sources)[state->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); *data = g_variant_new_double(state->horiz_triggerpos);
break; break;
case SR_CONF_COUPLING: case SR_CONF_COUPLING:
if (!cg) { if (!cg)
return SR_ERR_CHANNEL_GROUP; 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) if ((idx = std_cg_idx(cg, devc->analog_groups, model->analog_channels)) < 0)
return SR_ERR_ARG; return SR_ERR_ARG;
*data = g_variant_new_string((*model->coupling_options)[state->analog_channels[idx].coupling]); *data = g_variant_new_string((*model->coupling_options)[state->analog_channels[idx].coupling]);
} else {
return SR_ERR_NA;
}
break; break;
case SR_CONF_SAMPLERATE: case SR_CONF_SAMPLERATE:
*data = g_variant_new_uint64(state->sample_rate); *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; channel_found = FALSE;
for (i = 0; i < config->analog_channels; i++) { 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(chan_name, sizeof(chan_name), "CHAN%d", i + 1);
g_snprintf(tmp_str, sizeof(tmp_str), g_snprintf(tmp_str, sizeof(tmp_str),
(*config->scpi_dialect)[SCPI_CMD_GET_SAMPLE_RATE_LIVE], (*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; channel_found = TRUE;
break; break;
} }
}
if (!channel_found) { if (!channel_found) {
for (i = 0; i < config->digital_pods; i++) { 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(chan_name, sizeof(chan_name), "POD%d", i);
g_snprintf(tmp_str, sizeof(tmp_str), g_snprintf(tmp_str, sizeof(tmp_str),
(*config->scpi_dialect)[SCPI_CMD_GET_SAMPLE_RATE_LIVE], (*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; break;
} }
} }
}
/* No channel is active, ask the instrument for the sample rate /* No channel is active, ask the instrument for the sample rate
* in single shot mode */ * in single shot mode */

View File

@ -312,34 +312,28 @@ static int config_get(uint32_t key, GVariant **data,
case SR_CONF_TRIGGER_SLOPE: case SR_CONF_TRIGGER_SLOPE:
if (devc->edge >= ARRAY_SIZE(trigger_slopes)) if (devc->edge >= ARRAY_SIZE(trigger_slopes))
return SR_ERR; return SR_ERR;
else
*data = g_variant_new_string(trigger_slopes[devc->edge]); *data = g_variant_new_string(trigger_slopes[devc->edge]);
break; break;
case SR_CONF_BUFFERSIZE: case SR_CONF_BUFFERSIZE:
*data = g_variant_new_uint64(buffersizes[devc->last_step]); *data = g_variant_new_uint64(buffersizes[devc->last_step]);
break; break;
case SR_CONF_VDIV: case SR_CONF_VDIV:
if (!cg) { if (!cg)
return SR_ERR_CHANNEL_GROUP; return SR_ERR_CHANNEL_GROUP;
} else {
if ((idx = std_u8_idx_s(devc->cctl[ch] & 0x33, ARRAY_AND_SIZE(vdivs_map))) < 0) if ((idx = std_u8_idx_s(devc->cctl[ch] & 0x33, ARRAY_AND_SIZE(vdivs_map))) < 0)
return SR_ERR_BUG; return SR_ERR_BUG;
*data = g_variant_new("(tt)", vdivs[idx][0], vdivs[idx][1]); *data = g_variant_new("(tt)", vdivs[idx][0], vdivs[idx][1]);
}
break; break;
case SR_CONF_COUPLING: case SR_CONF_COUPLING:
if (!cg) { if (!cg)
return SR_ERR_CHANNEL_GROUP; return SR_ERR_CHANNEL_GROUP;
} else {
if ((idx = std_u8_idx_s(devc->cctl[ch] & 0x0C, ARRAY_AND_SIZE(coupling_map))) < 0) if ((idx = std_u8_idx_s(devc->cctl[ch] & 0x0C, ARRAY_AND_SIZE(coupling_map))) < 0)
return SR_ERR_BUG; return SR_ERR_BUG;
*data = g_variant_new_string(coupling[idx]); *data = g_variant_new_string(coupling[idx]);
}
break; break;
case SR_CONF_PROBE_FACTOR: case SR_CONF_PROBE_FACTOR:
if (!cg) if (!cg)
return SR_ERR_CHANNEL_GROUP; return SR_ERR_CHANNEL_GROUP;
else
*data = g_variant_new_uint64(devc->probe[ch]); *data = g_variant_new_uint64(devc->probe[ch]);
break; break;
default: default:
@ -384,35 +378,28 @@ static int config_set(uint32_t key, GVariant *data,
devc->last_step = idx; devc->last_step = idx;
break; break;
case SR_CONF_VDIV: case SR_CONF_VDIV:
if (!cg) { if (!cg)
return SR_ERR_CHANNEL_GROUP; 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; return SR_ERR_ARG;
} else {
if ((idx = std_u64_tuple_idx(data, ARRAY_AND_SIZE(vdivs))) < 0) if ((idx = std_u64_tuple_idx(data, ARRAY_AND_SIZE(vdivs))) < 0)
return SR_ERR_ARG; return SR_ERR_ARG;
devc->cctl[ch] = (devc->cctl[ch] & 0xCC) | vdivs_map[idx]; devc->cctl[ch] = (devc->cctl[ch] & 0xCC) | vdivs_map[idx];
}
break; break;
case SR_CONF_COUPLING: case SR_CONF_COUPLING:
if (!cg) { if (!cg)
return SR_ERR_CHANNEL_GROUP; return SR_ERR_CHANNEL_GROUP;
} else {
if ((idx = std_str_idx(data, ARRAY_AND_SIZE(coupling))) < 0) if ((idx = std_str_idx(data, ARRAY_AND_SIZE(coupling))) < 0)
return SR_ERR_ARG; return SR_ERR_ARG;
devc->cctl[ch] = (devc->cctl[ch] & 0xF3) | coupling_map[idx]; devc->cctl[ch] = (devc->cctl[ch] & 0xF3) | coupling_map[idx];
}
break; break;
case SR_CONF_PROBE_FACTOR: case SR_CONF_PROBE_FACTOR:
if (!cg) { if (!cg)
return SR_ERR_CHANNEL_GROUP; return SR_ERR_CHANNEL_GROUP;
} else {
u = g_variant_get_uint64(data); u = g_variant_get_uint64(data);
if (!u) if (!u)
return SR_ERR_ARG; return SR_ERR_ARG;
else
devc->probe[ch] = u; devc->probe[ch] = u;
}
break; break;
default: default:
return SR_ERR_NA; 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; struct dev_context *devc = sdi->priv;
uint8_t v; uint8_t v;
if (changes & SR_CHANNEL_SET_ENABLED) { if (!(changes & SR_CHANNEL_SET_ENABLED))
return SR_OK;
if (ch->enabled) { if (ch->enabled) {
v = devc->channel | (1 << ch->index); v = devc->channel | (1 << ch->index);
if (v & (v - 1)) if (v & (v - 1))
@ -437,7 +426,7 @@ static int config_channel_set(const struct sr_dev_inst *sdi,
} else { } else {
devc->channel &= ~(1 << ch->index); devc->channel &= ~(1 << ch->index);
} }
}
return SR_OK; return SR_OK;
} }

View File

@ -298,7 +298,10 @@ static struct sr_dev_inst *lascar_identify(unsigned char *config)
modelid = config[0]; modelid = config[0];
sdi = NULL; sdi = NULL;
if (modelid) {
if (!modelid)
return sdi;
profile = NULL; profile = NULL;
for (i = 0; profiles[i].modelid; i++) { for (i = 0; profiles[i].modelid; i++) {
if (profiles[i].modelid == modelid) { 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)); devc = g_malloc0(sizeof(struct dev_context));
sdi->priv = devc; sdi->priv = devc;
devc->profile = profile; devc->profile = profile;
}
return sdi; 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, new_samples = convert_sample_data(devc, devc->convbuffer,
devc->convbuffer_size, transfer->buffer, transfer->actual_length); 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) { if (devc->trigger_fired) {
/* Send the incoming transfer to the session bus. */ /* Send the incoming transfer to the session bus. */
packet.type = SR_DF_LOGIC; packet.type = SR_DF_LOGIC;
@ -953,7 +958,6 @@ SR_PRIV void LIBUSB_CALL logic16_receive_transfer(struct libusb_transfer *transf
free_transfer(transfer); free_transfer(transfer);
return; return;
} }
}
resubmit_transfer(transfer); resubmit_transfer(transfer);
} }

View File

@ -211,22 +211,18 @@ static int config_get(uint32_t key, GVariant **data,
ret = SR_OK; ret = SR_OK;
break; break;
case SR_CONF_NUM_VDIV: case SR_CONF_NUM_VDIV:
if (!cg) { if (!cg)
return SR_ERR_CHANNEL_GROUP; 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); *data = g_variant_new_int32(model->num_ydivs);
ret = SR_OK; ret = SR_OK;
break; break;
} else {
ret = SR_ERR_NA;
}
break;
case SR_CONF_VDIV: case SR_CONF_VDIV:
ret = SR_ERR_NA; if (!cg)
if (!cg) {
return SR_ERR_CHANNEL_GROUP; return SR_ERR_CHANNEL_GROUP;
} else if (cg_type != CG_ANALOG) if (cg_type != CG_ANALOG)
break; return SR_ERR_NA;
if ((idx = std_cg_idx(cg, devc->analog_groups, model->analog_channels)) < 0) if ((idx = std_cg_idx(cg, devc->analog_groups, model->analog_channels)) < 0)
return SR_ERR_ARG; return SR_ERR_ARG;
*data = g_variant_new("(tt)", *data = g_variant_new("(tt)",
@ -247,11 +243,10 @@ static int config_get(uint32_t key, GVariant **data,
ret = SR_OK; ret = SR_OK;
break; break;
case SR_CONF_COUPLING: case SR_CONF_COUPLING:
ret = SR_ERR_NA; if (!cg)
if (!cg) {
return SR_ERR_CHANNEL_GROUP; return SR_ERR_CHANNEL_GROUP;
} else if (cg_type != CG_ANALOG) if (cg_type != CG_ANALOG)
break; return SR_ERR_NA;
if ((idx = std_cg_idx(cg, devc->analog_groups, model->analog_channels)) < 0) if ((idx = std_cg_idx(cg, devc->analog_groups, model->analog_channels)) < 0)
return SR_ERR_ARG; return SR_ERR_ARG;
*data = g_variant_new_string((*model->coupling_options)[state->analog_states[idx].coupling]); *data = g_variant_new_string((*model->coupling_options)[state->analog_states[idx].coupling]);