Reduce unnecessarily high indentation level in some places.

This commit is contained in:
Uwe Hermann 2015-03-28 19:36:47 +01:00
parent 2ea67fc9bf
commit dc89faeace
4 changed files with 274 additions and 269 deletions

View File

@ -660,69 +660,70 @@ SR_PRIV int hmo_receive_data(int fd, int revents, void *cb_data)
if (!(devc = sdi->priv))
return TRUE;
if (revents == G_IO_IN) {
ch = devc->current_channel->data;
if (revents != G_IO_IN)
return TRUE;
switch (ch->type) {
case SR_CHANNEL_ANALOG:
if (sr_scpi_get_floatv(sdi->conn, NULL, &data) != SR_OK) {
if (data)
g_array_free(data, TRUE);
ch = devc->current_channel->data;
return TRUE;
}
switch (ch->type) {
case SR_CHANNEL_ANALOG:
if (sr_scpi_get_floatv(sdi->conn, NULL, &data) != SR_OK) {
if (data)
g_array_free(data, TRUE);
packet.type = SR_DF_FRAME_BEGIN;
sr_session_send(sdi, &packet);
analog.channels = g_slist_append(NULL, ch);
analog.num_samples = data->len;
analog.data = (float *) data->data;
analog.mq = SR_MQ_VOLTAGE;
analog.unit = SR_UNIT_VOLT;
analog.mqflags = 0;
packet.type = SR_DF_ANALOG;
packet.payload = &analog;
sr_session_send(cb_data, &packet);
g_slist_free(analog.channels);
g_array_free(data, TRUE);
data = NULL;
break;
case SR_CHANNEL_LOGIC:
if (sr_scpi_get_uint8v(sdi->conn, NULL, &data) != SR_OK) {
g_free(data);
return TRUE;
}
packet.type = SR_DF_FRAME_BEGIN;
sr_session_send(sdi, &packet);
logic.length = data->len;
logic.unitsize = 1;
logic.data = data->data;
packet.type = SR_DF_LOGIC;
packet.payload = &logic;
sr_session_send(cb_data, &packet);
g_array_free(data, TRUE);
data = NULL;
break;
default:
sr_err("Invalid channel type.");
break;
return TRUE;
}
packet.type = SR_DF_FRAME_END;
packet.type = SR_DF_FRAME_BEGIN;
sr_session_send(sdi, &packet);
if (devc->current_channel->next) {
devc->current_channel = devc->current_channel->next;
hmo_request_data(sdi);
} else if (++devc->num_frames == devc->frame_limit) {
sdi->driver->dev_acquisition_stop(sdi, cb_data);
} else {
devc->current_channel = devc->enabled_channels;
hmo_request_data(sdi);
analog.channels = g_slist_append(NULL, ch);
analog.num_samples = data->len;
analog.data = (float *) data->data;
analog.mq = SR_MQ_VOLTAGE;
analog.unit = SR_UNIT_VOLT;
analog.mqflags = 0;
packet.type = SR_DF_ANALOG;
packet.payload = &analog;
sr_session_send(cb_data, &packet);
g_slist_free(analog.channels);
g_array_free(data, TRUE);
data = NULL;
break;
case SR_CHANNEL_LOGIC:
if (sr_scpi_get_uint8v(sdi->conn, NULL, &data) != SR_OK) {
g_free(data);
return TRUE;
}
packet.type = SR_DF_FRAME_BEGIN;
sr_session_send(sdi, &packet);
logic.length = data->len;
logic.unitsize = 1;
logic.data = data->data;
packet.type = SR_DF_LOGIC;
packet.payload = &logic;
sr_session_send(cb_data, &packet);
g_array_free(data, TRUE);
data = NULL;
break;
default:
sr_err("Invalid channel type.");
break;
}
packet.type = SR_DF_FRAME_END;
sr_session_send(sdi, &packet);
if (devc->current_channel->next) {
devc->current_channel = devc->current_channel->next;
hmo_request_data(sdi);
} else if (++devc->num_frames == devc->frame_limit) {
sdi->driver->dev_acquisition_stop(sdi, cb_data);
} else {
devc->current_channel = devc->enabled_channels;
hmo_request_data(sdi);
}
return TRUE;

View File

@ -188,50 +188,52 @@ SR_PRIV int motech_lps_30x_receive_data(int fd, int revents, void *cb_data)
sdi->driver->dev_acquisition_stop(sdi, cb_data);
}
/* Request next packet, if required. */
if ((sdi->status == SR_ST_ACTIVE) && (devc->acq_running)){
if (devc->acq_req_pending) {
gint64 elapsed_us = g_get_monotonic_time() - devc->req_sent_at;
if (elapsed_us > (REQ_TIMEOUT_MS * 1000)) {
sr_spew("Request timeout: req=%d t=%lldus", (int)devc->acq_req, elapsed_us);
devc->acq_req_pending = 0;
}
/* Only request the next packet if required. */
if (!((sdi->status == SR_ST_ACTIVE) && (devc->acq_running)))
return TRUE;
if (devc->acq_req_pending) {
gint64 elapsed_us = g_get_monotonic_time() - devc->req_sent_at;
if (elapsed_us > (REQ_TIMEOUT_MS * 1000)) {
sr_spew("Request timeout: req=%d t=%lldus", (int)devc->acq_req, elapsed_us);
devc->acq_req_pending = 0;
}
if (devc->acq_req_pending == 0) {
switch (devc->acq_req) {
case AQ_NONE: /* Fall through */
case AQ_STATUS:
devc->acq_req = AQ_U1;
lps_send_req(serial, "VOUT1");
break;
case AQ_U1:
devc->acq_req = AQ_I1;
lps_send_req(serial, "IOUT1");
break;
case AQ_I1:
if (devc->model->num_channels == 1) {
devc->acq_req = AQ_STATUS;
lps_send_req(serial, "STATUS");
} else {
devc->acq_req = AQ_U2;
lps_send_req(serial, "VOUT2");
}
break;
case AQ_U2:
devc->acq_req = AQ_I2;
lps_send_req(serial, "IOUT2");
break;
case AQ_I2:
}
if (devc->acq_req_pending == 0) {
switch (devc->acq_req) {
case AQ_NONE: /* Fall through */
case AQ_STATUS:
devc->acq_req = AQ_U1;
lps_send_req(serial, "VOUT1");
break;
case AQ_U1:
devc->acq_req = AQ_I1;
lps_send_req(serial, "IOUT1");
break;
case AQ_I1:
if (devc->model->num_channels == 1) {
devc->acq_req = AQ_STATUS;
lps_send_req(serial, "STATUS");
break;
default:
sr_err("Illegal devc->acq_req=%d", devc->acq_req);
return SR_ERR;
} else {
devc->acq_req = AQ_U2;
lps_send_req(serial, "VOUT2");
}
devc->req_sent_at = g_get_real_time();
devc->acq_req_pending = 1;
break;
case AQ_U2:
devc->acq_req = AQ_I2;
lps_send_req(serial, "IOUT2");
break;
case AQ_I2:
devc->acq_req = AQ_STATUS;
lps_send_req(serial, "STATUS");
break;
default:
sr_err("Illegal devc->acq_req=%d", devc->acq_req);
return SR_ERR;
}
devc->req_sent_at = g_get_real_time();
devc->acq_req_pending = 1;
}
return TRUE;

View File

@ -619,8 +619,9 @@ SR_PRIV int p_ols_receive_data(int fd, int revents, void *cb_data)
}
return TRUE;
} else {
do bytes_read = ftdi_read_data(devc->ftdic, devc->ftdi_buf, FTDI_BUF_SIZE);
while (bytes_read > 0);
do {
bytes_read = ftdi_read_data(devc->ftdic, devc->ftdi_buf, FTDI_BUF_SIZE);
} while (bytes_read > 0);
/*
* We've acquired all the samples we asked for -- we're done.

View File

@ -554,204 +554,205 @@ SR_PRIV int rigol_ds_receive(int fd, int revents, void *cb_data)
scpi = sdi->conn;
if (revents == G_IO_IN || revents == 0) {
switch (devc->wait_event) {
case WAIT_NONE:
break;
case WAIT_TRIGGER:
if (rigol_ds_trigger_wait(sdi) != SR_OK)
return TRUE;
if (rigol_ds_channel_start(sdi) != SR_OK)
return TRUE;
if (!(revents == G_IO_IN || revents == 0))
return TRUE;
switch (devc->wait_event) {
case WAIT_NONE:
break;
case WAIT_TRIGGER:
if (rigol_ds_trigger_wait(sdi) != SR_OK)
return TRUE;
case WAIT_BLOCK:
if (rigol_ds_block_wait(sdi) != SR_OK)
return TRUE;
break;
case WAIT_STOP:
if (rigol_ds_stop_wait(sdi) != SR_OK)
return TRUE;
if (rigol_ds_check_stop(sdi) != SR_OK)
return TRUE;
if (rigol_ds_channel_start(sdi) != SR_OK)
return TRUE;
if (rigol_ds_channel_start(sdi) != SR_OK)
return TRUE;
default:
sr_err("BUG: Unknown event target encountered");
break;
return TRUE;
case WAIT_BLOCK:
if (rigol_ds_block_wait(sdi) != SR_OK)
return TRUE;
break;
case WAIT_STOP:
if (rigol_ds_stop_wait(sdi) != SR_OK)
return TRUE;
if (rigol_ds_check_stop(sdi) != SR_OK)
return TRUE;
if (rigol_ds_channel_start(sdi) != SR_OK)
return TRUE;
return TRUE;
default:
sr_err("BUG: Unknown event target encountered");
break;
}
ch = devc->channel_entry->data;
expected_data_bytes = ch->type == SR_CHANNEL_ANALOG ?
devc->analog_frame_size : devc->digital_frame_size;
if (devc->num_block_bytes == 0) {
if (devc->model->series->protocol >= PROTOCOL_V4) {
if (sr_scpi_send(sdi->conn, ":WAV:START %d",
devc->num_channel_bytes + 1) != SR_OK)
return TRUE;
if (sr_scpi_send(sdi->conn, ":WAV:STOP %d",
MIN(devc->num_channel_bytes + ACQ_BLOCK_SIZE,
devc->analog_frame_size)) != SR_OK)
return TRUE;
}
ch = devc->channel_entry->data;
expected_data_bytes = ch->type == SR_CHANNEL_ANALOG ?
devc->analog_frame_size : devc->digital_frame_size;
if (devc->num_block_bytes == 0) {
if (devc->model->series->protocol >= PROTOCOL_V4) {
if (sr_scpi_send(sdi->conn, ":WAV:START %d",
devc->num_channel_bytes + 1) != SR_OK)
return TRUE;
if (sr_scpi_send(sdi->conn, ":WAV:STOP %d",
MIN(devc->num_channel_bytes + ACQ_BLOCK_SIZE,
devc->analog_frame_size)) != SR_OK)
return TRUE;
}
if (devc->model->series->protocol >= PROTOCOL_V3)
if (sr_scpi_send(sdi->conn, ":WAV:DATA?") != SR_OK)
return TRUE;
if (sr_scpi_read_begin(scpi) != SR_OK)
if (devc->model->series->protocol >= PROTOCOL_V3)
if (sr_scpi_send(sdi->conn, ":WAV:DATA?") != SR_OK)
return TRUE;
if (devc->format == FORMAT_IEEE488_2) {
sr_dbg("New block header expected");
len = rigol_ds_read_header(sdi);
if (len == 0)
/* Still reading the header. */
return TRUE;
if (len == -1) {
sr_err("Read error, aborting capture.");
packet.type = SR_DF_FRAME_END;
sr_session_send(cb_data, &packet);
sdi->driver->dev_acquisition_stop(sdi, cb_data);
return TRUE;
}
/* At slow timebases in live capture the DS2072
* sometimes returns "short" data blocks, with
* apparently no way to get the rest of the data.
* Discard these, the complete data block will
* appear eventually.
*/
if (devc->data_source == DATA_SOURCE_LIVE
&& (unsigned)len < expected_data_bytes) {
sr_dbg("Discarding short data block");
sr_scpi_read_data(scpi, (char *)devc->buffer, len + 1);
return TRUE;
}
devc->num_block_bytes = len;
} else {
devc->num_block_bytes = expected_data_bytes;
}
devc->num_block_read = 0;
}
len = devc->num_block_bytes - devc->num_block_read;
if (len > ACQ_BUFFER_SIZE)
len = ACQ_BUFFER_SIZE;
sr_dbg("Requesting read of %d bytes", len);
len = sr_scpi_read_data(scpi, (char *)devc->buffer, len);
if (len == -1) {
sr_err("Read error, aborting capture.");
packet.type = SR_DF_FRAME_END;
sr_session_send(cb_data, &packet);
sdi->driver->dev_acquisition_stop(sdi, cb_data);
if (sr_scpi_read_begin(scpi) != SR_OK)
return TRUE;
}
sr_dbg("Received %d bytes.", len);
devc->num_block_read += len;
if (ch->type == SR_CHANNEL_ANALOG) {
vref = devc->vert_reference[ch->index];
vdiv = devc->vdiv[ch->index] / 25.6;
offset = devc->vert_offset[ch->index];
if (devc->model->series->protocol >= PROTOCOL_V3)
for (i = 0; i < len; i++)
devc->data[i] = ((int)devc->buffer[i] - vref) * vdiv - offset;
else
for (i = 0; i < len; i++)
devc->data[i] = (128 - devc->buffer[i]) * vdiv - offset;
analog.channels = g_slist_append(NULL, ch);
analog.num_samples = len;
analog.data = devc->data;
analog.mq = SR_MQ_VOLTAGE;
analog.unit = SR_UNIT_VOLT;
analog.mqflags = 0;
packet.type = SR_DF_ANALOG;
packet.payload = &analog;
sr_session_send(cb_data, &packet);
g_slist_free(analog.channels);
} else {
logic.length = len;
// TODO: For the MSO1000Z series, we need a way to express that
// this data is in fact just for a single channel, with the valid
// data for that channel in the LSB of each byte.
logic.unitsize = devc->model->series->protocol == PROTOCOL_V4 ? 1 : 2;
logic.data = devc->buffer;
packet.type = SR_DF_LOGIC;
packet.payload = &logic;
sr_session_send(cb_data, &packet);
}
if (devc->num_block_read == devc->num_block_bytes) {
sr_dbg("Block has been completed");
if (devc->model->series->protocol >= PROTOCOL_V3) {
/* Discard the terminating linefeed */
sr_scpi_read_data(scpi, (char *)devc->buffer, 1);
}
if (devc->format == FORMAT_IEEE488_2) {
/* Prepare for possible next block */
devc->num_header_bytes = 0;
devc->num_block_bytes = 0;
if (devc->data_source != DATA_SOURCE_LIVE)
rigol_ds_set_wait_event(devc, WAIT_BLOCK);
}
if (!sr_scpi_read_complete(scpi)) {
sr_err("Read should have been completed");
if (devc->format == FORMAT_IEEE488_2) {
sr_dbg("New block header expected");
len = rigol_ds_read_header(sdi);
if (len == 0)
/* Still reading the header. */
return TRUE;
if (len == -1) {
sr_err("Read error, aborting capture.");
packet.type = SR_DF_FRAME_END;
sr_session_send(cb_data, &packet);
sdi->driver->dev_acquisition_stop(sdi, cb_data);
return TRUE;
}
devc->num_block_read = 0;
/* At slow timebases in live capture the DS2072
* sometimes returns "short" data blocks, with
* apparently no way to get the rest of the data.
* Discard these, the complete data block will
* appear eventually.
*/
if (devc->data_source == DATA_SOURCE_LIVE
&& (unsigned)len < expected_data_bytes) {
sr_dbg("Discarding short data block");
sr_scpi_read_data(scpi, (char *)devc->buffer, len + 1);
return TRUE;
}
devc->num_block_bytes = len;
} else {
sr_dbg("%d of %d block bytes read", devc->num_block_read, devc->num_block_bytes);
devc->num_block_bytes = expected_data_bytes;
}
devc->num_block_read = 0;
}
devc->num_channel_bytes += len;
len = devc->num_block_bytes - devc->num_block_read;
if (len > ACQ_BUFFER_SIZE)
len = ACQ_BUFFER_SIZE;
sr_dbg("Requesting read of %d bytes", len);
if (devc->num_channel_bytes < expected_data_bytes)
/* Don't have the full data for this channel yet, re-run. */
return TRUE;
len = sr_scpi_read_data(scpi, (char *)devc->buffer, len);
/* End of data for this channel. */
if (devc->model->series->protocol == PROTOCOL_V3) {
/* Signal end of data download to scope */
if (len == -1) {
sr_err("Read error, aborting capture.");
packet.type = SR_DF_FRAME_END;
sr_session_send(cb_data, &packet);
sdi->driver->dev_acquisition_stop(sdi, cb_data);
return TRUE;
}
sr_dbg("Received %d bytes.", len);
devc->num_block_read += len;
if (ch->type == SR_CHANNEL_ANALOG) {
vref = devc->vert_reference[ch->index];
vdiv = devc->vdiv[ch->index] / 25.6;
offset = devc->vert_offset[ch->index];
if (devc->model->series->protocol >= PROTOCOL_V3)
for (i = 0; i < len; i++)
devc->data[i] = ((int)devc->buffer[i] - vref) * vdiv - offset;
else
for (i = 0; i < len; i++)
devc->data[i] = (128 - devc->buffer[i]) * vdiv - offset;
analog.channels = g_slist_append(NULL, ch);
analog.num_samples = len;
analog.data = devc->data;
analog.mq = SR_MQ_VOLTAGE;
analog.unit = SR_UNIT_VOLT;
analog.mqflags = 0;
packet.type = SR_DF_ANALOG;
packet.payload = &analog;
sr_session_send(cb_data, &packet);
g_slist_free(analog.channels);
} else {
logic.length = len;
// TODO: For the MSO1000Z series, we need a way to express that
// this data is in fact just for a single channel, with the valid
// data for that channel in the LSB of each byte.
logic.unitsize = devc->model->series->protocol == PROTOCOL_V4 ? 1 : 2;
logic.data = devc->buffer;
packet.type = SR_DF_LOGIC;
packet.payload = &logic;
sr_session_send(cb_data, &packet);
}
if (devc->num_block_read == devc->num_block_bytes) {
sr_dbg("Block has been completed");
if (devc->model->series->protocol >= PROTOCOL_V3) {
/* Discard the terminating linefeed */
sr_scpi_read_data(scpi, (char *)devc->buffer, 1);
}
if (devc->format == FORMAT_IEEE488_2) {
/* Prepare for possible next block */
devc->num_header_bytes = 0;
devc->num_block_bytes = 0;
if (devc->data_source != DATA_SOURCE_LIVE)
/*
* This causes a query error, without it switching
* to the next channel causes an error. Fun with
* firmware...
*/
rigol_ds_config_set(sdi, ":WAV:END");
rigol_ds_set_wait_event(devc, WAIT_BLOCK);
}
if (devc->channel_entry->next) {
/* We got the frame for this channel, now get the next channel. */
devc->channel_entry = devc->channel_entry->next;
rigol_ds_channel_start(sdi);
} else {
/* Done with this frame. */
if (!sr_scpi_read_complete(scpi)) {
sr_err("Read should have been completed");
packet.type = SR_DF_FRAME_END;
sr_session_send(cb_data, &packet);
sdi->driver->dev_acquisition_stop(sdi, cb_data);
return TRUE;
}
devc->num_block_read = 0;
} else {
sr_dbg("%d of %d block bytes read", devc->num_block_read, devc->num_block_bytes);
}
if (++devc->num_frames == devc->limit_frames) {
/* Last frame, stop capture. */
sdi->driver->dev_acquisition_stop(sdi, cb_data);
} else {
/* Get the next frame, starting with the first channel. */
devc->channel_entry = devc->enabled_channels;
devc->num_channel_bytes += len;
rigol_ds_capture_start(sdi);
if (devc->num_channel_bytes < expected_data_bytes)
/* Don't have the full data for this channel yet, re-run. */
return TRUE;
/* Start of next frame. */
packet.type = SR_DF_FRAME_BEGIN;
sr_session_send(cb_data, &packet);
}
/* End of data for this channel. */
if (devc->model->series->protocol == PROTOCOL_V3) {
/* Signal end of data download to scope */
if (devc->data_source != DATA_SOURCE_LIVE)
/*
* This causes a query error, without it switching
* to the next channel causes an error. Fun with
* firmware...
*/
rigol_ds_config_set(sdi, ":WAV:END");
}
if (devc->channel_entry->next) {
/* We got the frame for this channel, now get the next channel. */
devc->channel_entry = devc->channel_entry->next;
rigol_ds_channel_start(sdi);
} else {
/* Done with this frame. */
packet.type = SR_DF_FRAME_END;
sr_session_send(cb_data, &packet);
if (++devc->num_frames == devc->limit_frames) {
/* Last frame, stop capture. */
sdi->driver->dev_acquisition_stop(sdi, cb_data);
} else {
/* Get the next frame, starting with the first channel. */
devc->channel_entry = devc->enabled_channels;
rigol_ds_capture_start(sdi);
/* Start of next frame. */
packet.type = SR_DF_FRAME_BEGIN;
sr_session_send(cb_data, &packet);
}
}