siglent-sds: Fix, USB connection problem partially solved, bug #1130

This commit is contained in:
marchelh 2018-03-04 13:27:19 +01:00 committed by Uwe Hermann
parent 5e7ac9f9ec
commit 7e776c70b0
3 changed files with 84 additions and 94 deletions

View File

@ -857,6 +857,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
// devc->analog_frame_size = devc->model->series->buffer_samples; // devc->analog_frame_size = devc->model->series->buffer_samples;
// devc->digital_frame_size = devc->model->series->buffer_samples; // devc->digital_frame_size = devc->model->series->buffer_samples;
siglent_sds_get_dev_cfg_horizontal(sdi);
switch (devc->model->series->protocol) { switch (devc->model->series->protocol) {
case SPO_MODEL: case SPO_MODEL:
if (siglent_sds_config_set(sdi, "WFSU SP,0,TYPE,1") != SR_OK) if (siglent_sds_config_set(sdi, "WFSU SP,0,TYPE,1") != SR_OK)

View File

@ -257,12 +257,11 @@ static int siglent_sds_read_header(struct sr_dev_inst *sdi)
char *buf = (char *)devc->buffer; char *buf = (char *)devc->buffer;
int ret, desc_length; int ret, desc_length;
int block_offset = 15; /* Offset for descriptor block. */ int block_offset = 15; /* Offset for descriptor block. */
long dataLength = 0; long data_length = 0;
/* Read header from device. */ /* Read header from device. */
ret = sr_scpi_read_data(scpi, buf + devc->num_header_bytes, ret = sr_scpi_read_data(scpi, buf, SIGLENT_HEADER_SIZE);
devc->model->series->buffer_samples); if (ret < SIGLENT_HEADER_SIZE) {
if (ret < 346) {
sr_err("Read error while reading data header."); sr_err("Read error while reading data header.");
return SR_ERR; return SR_ERR;
} }
@ -272,10 +271,10 @@ static int siglent_sds_read_header(struct sr_dev_inst *sdi)
/* Parse WaveDescriptor header. */ /* Parse WaveDescriptor header. */
memcpy(&desc_length, buf + 36, 4); /* Descriptor block length */ memcpy(&desc_length, buf + 36, 4); /* Descriptor block length */
memcpy(&dataLength, buf + 60, 4); /* Data block length */ memcpy(&data_length, buf + 60, 4); /* Data block length */
devc->block_header_size = desc_length + 15; devc->block_header_size = desc_length + 15;
ret = dataLength; devc->num_samples = data_length;
sr_dbg("Received data block header: '%s' -> block length %d.", buf, ret); sr_dbg("Received data block header: '%s' -> block length %d.", buf, ret);
@ -295,8 +294,6 @@ SR_PRIV int siglent_sds_receive(int fd, int revents, void *cb_data)
struct sr_datafeed_logic logic; struct sr_datafeed_logic logic;
int len, i; int len, i;
struct sr_channel *ch; struct sr_channel *ch;
gsize expected_data_bytes = 0;
char *memsize;
(void)fd; (void)fd;
@ -311,10 +308,6 @@ SR_PRIV int siglent_sds_receive(int fd, int revents, void *cb_data)
if (!(revents == G_IO_IN || revents == 0)) if (!(revents == G_IO_IN || revents == 0))
return TRUE; return TRUE;
memsize = NULL;
if (sr_scpi_get_string(sdi->conn, "MSIZ?", &memsize) != SR_OK)
return SR_ERR;
switch (devc->wait_event) { switch (devc->wait_event) {
case WAIT_NONE: case WAIT_NONE:
break; break;
@ -338,18 +331,19 @@ SR_PRIV int siglent_sds_receive(int fd, int revents, void *cb_data)
sr_err("BUG: Unknown event target encountered."); sr_err("BUG: Unknown event target encountered.");
break; break;
} }
ch = devc->channel_entry->data; ch = devc->channel_entry->data;
len = 0;
if (devc->num_block_bytes == 0) { if (devc->num_block_bytes == 0) {
if (g_ascii_strcasecmp(memsize, "14M") == 0) { if (devc->samplerate >= 14000000) {
sr_err("Device memory depth is set to 14Mpts, so please be patient."); sr_err("Device memory depth is set to 14Mpts, so please be patient.");
g_usleep(4900000); /* Sleep for large memory set. */ g_usleep(4900000); /* Sleep for large memory set. */
} }
if (sr_scpi_read_begin(scpi) != SR_OK)
return TRUE;
sr_dbg("New block header expected."); sr_dbg("New block header expected.");
len = siglent_sds_read_header(sdi); len = siglent_sds_read_header(sdi);
expected_data_bytes = len;
if (len == 0) if (len == 0)
/* Still reading the header. */ /* Still reading the header. */
return TRUE; return TRUE;
@ -360,24 +354,10 @@ SR_PRIV int siglent_sds_receive(int fd, int revents, void *cb_data)
sdi->driver->dev_acquisition_stop(sdi); sdi->driver->dev_acquisition_stop(sdi);
return TRUE; return TRUE;
} }
devc->num_block_bytes = 0;
if (devc->data_source == DATA_SOURCE_SCREEN
&& (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;
devc->num_block_read = 0; devc->num_block_read = 0;
} }
len = devc->num_block_bytes - devc->num_block_read;
if (len > ACQ_BUFFER_SIZE)
len = ACQ_BUFFER_SIZE;
/* Offset the data block buffer past the IEEE header and description header. */
devc->buffer += devc->block_header_size;
if (len == -1) { if (len == -1) {
sr_err("Read error, aborting capture."); sr_err("Read error, aborting capture.");
packet.type = SR_DF_FRAME_END; packet.type = SR_DF_FRAME_END;
@ -386,10 +366,23 @@ SR_PRIV int siglent_sds_receive(int fd, int revents, void *cb_data)
return TRUE; return TRUE;
} }
sr_dbg("Received %d bytes.", len); while (devc->num_block_bytes < devc->num_samples) {
len = sr_scpi_read_data(scpi, (char *)devc->buffer, devc->num_samples);
devc->num_block_read += len; if (len == -1) {
sr_err("Read error, aborting capture.");
packet.type = SR_DF_FRAME_END;
sr_session_send(sdi, &packet);
sdi->driver->dev_acquisition_stop(sdi);
return TRUE;
}
devc->num_block_read += 1;
devc->num_block_bytes += len;
if (devc->num_block_bytes >= devc->num_samples ) {
/* Offset the data block buffer past the IEEE header and description header. */
devc->buffer += devc->block_header_size;
len = devc->num_samples;
}
sr_dbg("Received block: %i, %d bytes.", devc->num_block_read, len);
if (ch->type == SR_CHANNEL_ANALOG) { if (ch->type == SR_CHANNEL_ANALOG) {
float vdiv = devc->vdiv[ch->index]; float vdiv = devc->vdiv[ch->index];
float offset = devc->vert_offset[ch->index]; float offset = devc->vert_offset[ch->index];
@ -429,13 +422,10 @@ SR_PRIV int siglent_sds_receive(int fd, int revents, void *cb_data)
sr_session_send(sdi, &packet); sr_session_send(sdi, &packet);
} }
if (devc->num_block_read == devc->num_block_bytes) { if (devc->num_samples == devc->num_block_bytes) {
sr_dbg("Block has been completed."); sr_dbg("Transfer has been completed.");
sr_dbg("Preparing for possible next block.");
devc->num_header_bytes = 0; devc->num_header_bytes = 0;
devc->num_block_bytes = 0; devc->num_block_bytes = 0;
if (devc->data_source != DATA_SOURCE_SCREEN)
siglent_sds_set_wait_event(devc, WAIT_BLOCK);
if (!sr_scpi_read_complete(scpi)) { if (!sr_scpi_read_complete(scpi)) {
sr_err("Read should have been completed."); sr_err("Read should have been completed.");
packet.type = SR_DF_FRAME_END; packet.type = SR_DF_FRAME_END;
@ -446,13 +436,10 @@ SR_PRIV int siglent_sds_receive(int fd, int revents, void *cb_data)
devc->num_block_read = 0; devc->num_block_read = 0;
} else { } else {
sr_dbg("%" PRIu64 " of %" PRIu64 " block bytes read.", sr_dbg("%" PRIu64 " of %" PRIu64 " block bytes read.",
devc->num_block_read, devc->num_block_bytes); devc->num_block_bytes, devc->num_samples);
} }
devc->num_channel_bytes += len;
if (devc->num_channel_bytes < expected_data_bytes) {
/* Don't have the full data for this channel yet, re-run. */
return TRUE;
} }
if (devc->channel_entry->next) { if (devc->channel_entry->next) {
/* We got the frame for this channel, now get the next channel. */ /* We got the frame for this channel, now get the next channel. */
devc->channel_entry = devc->channel_entry->next; devc->channel_entry = devc->channel_entry->next;

View File

@ -32,6 +32,8 @@
//#define ACQ_BUFFER_SIZE (6000000) //#define ACQ_BUFFER_SIZE (6000000)
#define ACQ_BUFFER_SIZE (18000000) #define ACQ_BUFFER_SIZE (18000000)
#define SIGLENT_HEADER_SIZE 351
/* Maximum number of samples to retrieve at once. */ /* Maximum number of samples to retrieve at once. */
#define ACQ_BLOCK_SIZE (30 * 1000) #define ACQ_BLOCK_SIZE (30 * 1000)
@ -135,10 +137,10 @@ struct dev_context {
uint64_t num_channel_bytes; uint64_t num_channel_bytes;
/* Number of bytes of block header read. */ /* Number of bytes of block header read. */
uint64_t num_header_bytes; uint64_t num_header_bytes;
/* Number of bytes in current data block, if 0 block header expected. */ /* Number of data blocks bytes already read. */
uint64_t num_block_bytes; uint64_t num_block_bytes;
/* Number of data block bytes already read. */ /* Number of data blocks read. */
uint64_t num_block_read; int num_block_read;
/* What to wait for in *_receive. */ /* What to wait for in *_receive. */
enum wait_events wait_event; enum wait_events wait_event;
/* Trigger/block copying/stop waiting status. */ /* Trigger/block copying/stop waiting status. */