X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=hardware%2Frigol-ds%2Fprotocol.c;h=97cb353c6ca597d1b9fe19b7e94396a0c043d7e8;hb=3f239f0803b9fbc073dd7abe9fc7b2a0c606fbb6;hp=de91e0709a877db19e230e54c8239216f5f19f25;hpb=aff00e40880184c9f9d4a934d83af0cf052ed70c;p=libsigrok.git diff --git a/hardware/rigol-ds/protocol.c b/hardware/rigol-ds/protocol.c index de91e070..97cb353c 100644 --- a/hardware/rigol-ds/protocol.c +++ b/hardware/rigol-ds/protocol.c @@ -207,19 +207,19 @@ static int rigol_ds_stop_wait(const struct sr_dev_inst *sdi) static int rigol_ds_check_stop(const struct sr_dev_inst *sdi) { struct dev_context *devc; - struct sr_probe *probe; + struct sr_channel *ch; int tmp; if (!(devc = sdi->priv)) return SR_ERR; - probe = devc->channel_entry->data; + ch = devc->channel_entry->data; if (devc->model->series->protocol <= PROTOCOL_V2) return SR_OK; if (rigol_ds_config_set(sdi, ":WAV:SOUR CHAN%d", - probe->index + 1) != SR_OK) + ch->index + 1) != SR_OK) return SR_ERR; /* Check that the number of samples will be accepted */ if (rigol_ds_config_set(sdi, ":WAV:POIN %d", devc->analog_frame_size) != SR_OK) @@ -261,29 +261,32 @@ static int rigol_ds_block_wait(const struct sr_dev_inst *sdi) if (!(devc = sdi->priv)) return SR_ERR; - start = time(NULL); + if (devc->model->series->protocol >= PROTOCOL_V3) { - do { - if (time(NULL) - start >= 3) { - sr_dbg("Timeout waiting for data block"); - return SR_ERR_TIMEOUT; - } + start = time(NULL); - /* - * The scope copies data really slowly from sample - * memory to its output buffer, so try not to bother - * it too much with SCPI requests but don't wait too - * long for short sample frame sizes. - */ - g_usleep(devc->analog_frame_size < 15000 ? 100000 : 1000000); + do { + if (time(NULL) - start >= 3) { + sr_dbg("Timeout waiting for data block"); + return SR_ERR_TIMEOUT; + } - /* "READ,nnnn" (still working) or "IDLE,nnnn" (finished) */ - if (sr_scpi_get_string(sdi->conn, ":WAV:STAT?", &buf) != SR_OK) - return SR_ERR; + /* + * The scope copies data really slowly from sample + * memory to its output buffer, so try not to bother + * it too much with SCPI requests but don't wait too + * long for short sample frame sizes. + */ + g_usleep(devc->analog_frame_size < 15000 ? 100000 : 1000000); - if (parse_int(buf + 5, &len) != SR_OK) - return SR_ERR; - } while (buf[0] == 'R' && len < 1000000); + /* "READ,nnnn" (still working) or "IDLE,nnnn" (finished) */ + if (sr_scpi_get_string(sdi->conn, ":WAV:STAT?", &buf) != SR_OK) + return SR_ERR; + + if (parse_int(buf + 5, &len) != SR_OK) + return SR_ERR; + } while (buf[0] == 'R' && len < 1000000); + } rigol_ds_set_wait_event(devc, WAIT_NONE); @@ -373,28 +376,28 @@ SR_PRIV int rigol_ds_capture_start(const struct sr_dev_inst *sdi) SR_PRIV int rigol_ds_channel_start(const struct sr_dev_inst *sdi) { struct dev_context *devc; - struct sr_probe *probe; + struct sr_channel *ch; if (!(devc = sdi->priv)) return SR_ERR; - probe = devc->channel_entry->data; + ch = devc->channel_entry->data; - sr_dbg("Starting reading data from channel %d", probe->index + 1); + sr_dbg("Starting reading data from channel %d", ch->index + 1); if (devc->model->series->protocol <= PROTOCOL_V2) { - if (probe->type == SR_PROBE_LOGIC) { + if (ch->type == SR_CHANNEL_LOGIC) { if (sr_scpi_send(sdi->conn, ":WAV:DATA? DIG") != SR_OK) return SR_ERR; } else { if (sr_scpi_send(sdi->conn, ":WAV:DATA? CHAN%d", - probe->index + 1) != SR_OK) + ch->index + 1) != SR_OK) return SR_ERR; } rigol_ds_set_wait_event(devc, WAIT_NONE); } else { if (rigol_ds_config_set(sdi, ":WAV:SOUR CHAN%d", - probe->index + 1) != SR_OK) + ch->index + 1) != SR_OK) return SR_ERR; if (devc->data_source != DATA_SOURCE_LIVE) { if (rigol_ds_config_set(sdi, ":WAV:RES") != SR_OK) @@ -419,18 +422,18 @@ static int rigol_ds_read_header(struct sr_dev_inst *sdi) struct sr_scpi_dev_inst *scpi = sdi->conn; struct dev_context *devc = sdi->priv; char *buf = (char *) devc->buffer; - int len; - int tmp; + size_t header_length; + int ret; /* Try to read the hashsign and length digit. */ if (devc->num_header_bytes < 2) { - tmp = sr_scpi_read_data(scpi, buf + devc->num_header_bytes, + ret = sr_scpi_read_data(scpi, buf + devc->num_header_bytes, 2 - devc->num_header_bytes); - if (tmp < 0) { + if (ret < 0) { sr_err("Read error while reading data header."); return SR_ERR; } - devc->num_header_bytes += tmp; + devc->num_header_bytes += ret; } if (devc->num_header_bytes < 2) @@ -441,33 +444,33 @@ static int rigol_ds_read_header(struct sr_dev_inst *sdi) return SR_ERR; } - len = buf[1] - '0'; + header_length = 2 + buf[1] - '0'; /* Try to read the length. */ - if (devc->num_header_bytes < 2 + len) { - tmp = sr_scpi_read_data(scpi, buf + devc->num_header_bytes, - 2 + len - devc->num_header_bytes); - if (tmp < 0) { + if (devc->num_header_bytes < header_length) { + ret = sr_scpi_read_data(scpi, buf + devc->num_header_bytes, + header_length - devc->num_header_bytes); + if (ret < 0) { sr_err("Read error while reading data header."); return SR_ERR; } - devc->num_header_bytes += tmp; + devc->num_header_bytes += ret; } - if (devc->num_header_bytes < 2 + len) + if (devc->num_header_bytes < header_length) return 0; /* Read the data length. */ - buf[2 + len] = '\0'; + buf[header_length] = '\0'; - if (parse_int(buf + 2, &len) != SR_OK) { + if (parse_int(buf + 2, &ret) != SR_OK) { sr_err("Received invalid data block length '%s'.", buf + 2); return -1; } - sr_dbg("Received data block header: '%s' -> block length %d", buf, len); + sr_dbg("Received data block header: '%s' -> block length %d", buf, ret); - return len; + return ret; } SR_PRIV int rigol_ds_receive(int fd, int revents, void *cb_data) @@ -480,7 +483,7 @@ SR_PRIV int rigol_ds_receive(int fd, int revents, void *cb_data) struct sr_datafeed_logic logic; double vdiv, offset; int len, i, vref; - struct sr_probe *probe; + struct sr_channel *ch; gsize expected_data_bytes; (void)fd; @@ -502,7 +505,7 @@ SR_PRIV int rigol_ds_receive(int fd, int revents, void *cb_data) return TRUE; if (rigol_ds_channel_start(sdi) != SR_OK) return TRUE; - break; + return TRUE; case WAIT_BLOCK: if (rigol_ds_block_wait(sdi) != SR_OK) return TRUE; @@ -519,9 +522,9 @@ SR_PRIV int rigol_ds_receive(int fd, int revents, void *cb_data) sr_err("BUG: Unknown event target encountered"); } - probe = devc->channel_entry->data; + ch = devc->channel_entry->data; - expected_data_bytes = probe->type == SR_PROBE_ANALOG ? + expected_data_bytes = ch->type == SR_CHANNEL_ANALOG ? devc->analog_frame_size : devc->digital_frame_size; if (devc->num_block_bytes == 0) { @@ -583,17 +586,17 @@ SR_PRIV int rigol_ds_receive(int fd, int revents, void *cb_data) devc->num_block_read += len; - if (probe->type == SR_PROBE_ANALOG) { - vref = devc->vert_reference[probe->index]; - vdiv = devc->vdiv[probe->index] / 25.6; - offset = devc->vert_offset[probe->index]; + 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.probes = g_slist_append(NULL, probe); + analog.channels = g_slist_append(NULL, ch); analog.num_samples = len; analog.data = devc->data; analog.mq = SR_MQ_VOLTAGE; @@ -602,7 +605,7 @@ SR_PRIV int rigol_ds_receive(int fd, int revents, void *cb_data) packet.type = SR_DF_ANALOG; packet.payload = &analog; sr_session_send(cb_data, &packet); - g_slist_free(analog.probes); + g_slist_free(analog.channels); } else { logic.length = len; logic.unitsize = 2; @@ -655,7 +658,7 @@ SR_PRIV int rigol_ds_receive(int fd, int revents, void *cb_data) rigol_ds_config_set(sdi, ":WAV:END"); } - if (probe->type == SR_PROBE_ANALOG + if (ch->type == SR_CHANNEL_ANALOG && devc->channel_entry->next != NULL) { /* We got the frame for this analog channel, but * there's another analog channel. */ @@ -663,10 +666,10 @@ SR_PRIV int rigol_ds_receive(int fd, int revents, void *cb_data) rigol_ds_channel_start(sdi); } else { /* Done with all analog channels in this frame. */ - if (devc->enabled_digital_probes - && devc->channel_entry != devc->enabled_digital_probes) { + if (devc->enabled_digital_channels + && devc->channel_entry != devc->enabled_digital_channels) { /* Now we need to get the digital data. */ - devc->channel_entry = devc->enabled_digital_probes; + devc->channel_entry = devc->enabled_digital_channels; rigol_ds_channel_start(sdi); } else { /* Done with this frame. */ @@ -678,10 +681,10 @@ SR_PRIV int rigol_ds_receive(int fd, int revents, void *cb_data) sdi->driver->dev_acquisition_stop(sdi, cb_data); } else { /* Get the next frame, starting with the first analog channel. */ - if (devc->enabled_analog_probes) - devc->channel_entry = devc->enabled_analog_probes; + if (devc->enabled_analog_channels) + devc->channel_entry = devc->enabled_analog_channels; else - devc->channel_entry = devc->enabled_digital_probes; + devc->channel_entry = devc->enabled_digital_channels; rigol_ds_capture_start(sdi);