rigol-ds: Unify code for counting expected incoming bytes.

This commit is contained in:
Martin Ling 2013-12-27 18:56:59 +01:00 committed by Bert Vermeulen
parent 677f85d00b
commit f80a0bf232
1 changed files with 17 additions and 19 deletions

View File

@ -405,7 +405,7 @@ SR_PRIV int rigol_ds_receive(int fd, int revents, void *cb_data)
struct sr_datafeed_analog analog; struct sr_datafeed_analog analog;
struct sr_datafeed_logic logic; struct sr_datafeed_logic logic;
double vdiv, offset; double vdiv, offset;
int len, i, waveform_size, vref; int len, i, vref;
struct sr_probe *probe; struct sr_probe *probe;
(void)fd; (void)fd;
@ -448,8 +448,12 @@ SR_PRIV int rigol_ds_receive(int fd, int revents, void *cb_data)
default: default:
sr_err("BUG: Unknown event target encountered"); sr_err("BUG: Unknown event target encountered");
} }
}
probe = devc->channel;
if (devc->num_block_bytes == 0) { if (devc->num_block_bytes == 0) {
if (devc->model->protocol == PROTOCOL_IEEE488_2) {
sr_dbg("New block header expected"); sr_dbg("New block header expected");
if (sr_scpi_send(sdi->conn, ":WAV:DATA?") != SR_OK) if (sr_scpi_send(sdi->conn, ":WAV:DATA?") != SR_OK)
return TRUE; return TRUE;
@ -469,24 +473,20 @@ SR_PRIV int rigol_ds_receive(int fd, int revents, void *cb_data)
return TRUE; return TRUE;
} }
devc->num_block_bytes = len; devc->num_block_bytes = len;
devc->num_block_read = 0;
}
}
probe = devc->channel;
if (devc->model->protocol == PROTOCOL_IEEE488_2) {
len = devc->num_block_bytes - devc->num_block_read;
len = sr_scpi_read(scpi, (char *)devc->buffer,
len < ACQ_BUFFER_SIZE ? len : ACQ_BUFFER_SIZE);
} else { } else {
waveform_size = probe->type == SR_PROBE_ANALOG ? devc->num_block_bytes = probe->type == SR_PROBE_ANALOG ?
(devc->model->series == RIGOL_VS5000 ? (devc->model->series == RIGOL_VS5000 ?
VS5000_ANALOG_LIVE_WAVEFORM_SIZE : VS5000_ANALOG_LIVE_WAVEFORM_SIZE :
DS1000_ANALOG_LIVE_WAVEFORM_SIZE) : DS1000_ANALOG_LIVE_WAVEFORM_SIZE) :
DIGITAL_WAVEFORM_SIZE; DIGITAL_WAVEFORM_SIZE;
len = sr_scpi_read(scpi, (char *)devc->buffer,
waveform_size - devc->num_frame_samples);
} }
devc->num_block_read = 0;
}
len = devc->num_block_bytes - devc->num_block_read;
len = sr_scpi_read(scpi, (char *)devc->buffer,
len < ACQ_BUFFER_SIZE ? len : ACQ_BUFFER_SIZE);
sr_dbg("Received %d bytes.", len); sr_dbg("Received %d bytes.", len);
if (len == -1) if (len == -1)
return TRUE; return TRUE;
@ -556,9 +556,7 @@ SR_PRIV int rigol_ds_receive(int fd, int revents, void *cb_data)
/* End of the frame. */ /* End of the frame. */
packet.type = SR_DF_FRAME_END; packet.type = SR_DF_FRAME_END;
sr_session_send(sdi, &packet); sr_session_send(sdi, &packet);
if (devc->model->protocol == PROTOCOL_LEGACY) if (devc->model->protocol == PROTOCOL_IEEE488_2) {
devc->num_frame_samples = 0;
else {
/* Signal end of data download to scope */ /* Signal end of data download to scope */
if (devc->data_source != DATA_SOURCE_LIVE) if (devc->data_source != DATA_SOURCE_LIVE)
/* /*