X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=hardware%2Frigol-ds%2Fapi.c;h=872531f694159b3c0d57d9ad7f2b5df584efd7de;hb=43cd4637285833706f8a404ca027bcf0ee75b9ae;hp=c23805c6acd1c24a0782bc4018af978ab2656cf5;hpb=91aea754aaed0f0f2a6fc4b2b875f0d0b7c01f8e;p=libsigrok.git diff --git a/hardware/rigol-ds/api.c b/hardware/rigol-ds/api.c index c23805c6..872531f6 100644 --- a/hardware/rigol-ds/api.c +++ b/hardware/rigol-ds/api.c @@ -143,6 +143,11 @@ static const char *trigger_sources[] = { "D15", }; +static const char *trigger_slopes[] = { + "r", + "f", +}; + static const char *coupling[] = { "AC", "DC", @@ -260,17 +265,20 @@ static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi) struct dev_context *devc; struct sr_dev_inst *sdi; struct sr_scpi_hw_info *hw_info; - struct sr_channel *probe; + struct sr_channel *ch; long n[3]; unsigned int i; const struct rigol_ds_model *model = NULL; gchar *channel_name, **version; if (sr_scpi_get_hw_id(scpi, &hw_info) != SR_OK) { - sr_info("Couldn't get IDN response."); + sr_info("Couldn't get IDN response, retrying."); sr_scpi_close(scpi); - sr_scpi_free(scpi); - return NULL; + sr_scpi_open(scpi); + if (sr_scpi_get_hw_id(scpi, &hw_info) != SR_OK) { + sr_info("Couldn't get IDN response."); + return NULL; + } } for (i = 0; i < ARRAY_SIZE(supported_models); i++) { @@ -287,13 +295,9 @@ static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi) model->name, hw_info->firmware_version))) { sr_scpi_hw_info_free(hw_info); - sr_scpi_close(scpi); - sr_scpi_free(scpi); return NULL; } - sr_scpi_close(scpi); - sdi->conn = scpi; sdi->driver = di; @@ -335,10 +339,10 @@ static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi) for (i = 0; i < model->analog_channels; i++) { if (!(channel_name = g_strdup_printf("CH%d", i + 1))) return NULL; - probe = sr_probe_new(i, SR_PROBE_ANALOG, TRUE, channel_name); - sdi->probes = g_slist_append(sdi->probes, probe); + ch = sr_channel_new(i, SR_CHANNEL_ANALOG, TRUE, channel_name); + sdi->channels = g_slist_append(sdi->channels, ch); devc->analog_groups[i].name = channel_name; - devc->analog_groups[i].channels = g_slist_append(NULL, probe); + devc->analog_groups[i].channels = g_slist_append(NULL, ch); sdi->channel_groups = g_slist_append(sdi->channel_groups, &devc->analog_groups[i]); } @@ -347,13 +351,13 @@ static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi) for (i = 0; i < 16; i++) { if (!(channel_name = g_strdup_printf("D%d", i))) return NULL; - probe = sr_probe_new(i, SR_PROBE_LOGIC, TRUE, channel_name); + ch = sr_channel_new(i, SR_CHANNEL_LOGIC, TRUE, channel_name); g_free(channel_name); - if (!probe) + if (!ch) return NULL; - sdi->probes = g_slist_append(sdi->probes, probe); + sdi->channels = g_slist_append(sdi->channels, ch); devc->digital_group.channels = g_slist_append( - devc->digital_group.channels, probe); + devc->digital_group.channels, ch); } devc->digital_group.name = "LA"; sdi->channel_groups = g_slist_append(sdi->channel_groups, @@ -439,24 +443,24 @@ static int cleanup(void) static int analog_frame_size(const struct sr_dev_inst *sdi) { struct dev_context *devc = sdi->priv; - struct sr_channel *probe; - int analog_probes = 0; + struct sr_channel *ch; + int analog_channels = 0; GSList *l; - for (l = sdi->probes; l; l = l->next) { - probe = l->data; - if (probe->type == SR_PROBE_ANALOG && probe->enabled) - analog_probes++; + for (l = sdi->channels; l; l = l->next) { + ch = l->data; + if (ch->type == SR_CHANNEL_ANALOG && ch->enabled) + analog_channels++; } - if (analog_probes == 0) + if (analog_channels == 0) return 0; switch (devc->data_source) { case DATA_SOURCE_LIVE: return devc->model->series->live_samples; case DATA_SOURCE_MEMORY: - return devc->model->series->buffer_samples / analog_probes; + return devc->model->series->buffer_samples / analog_channels; default: return 0; } @@ -480,7 +484,7 @@ static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { struct dev_context *devc; - struct sr_channel *probe; + struct sr_channel *ch; const char *tmp_str; uint64_t samplerate; int analog_channel = -1; @@ -498,13 +502,13 @@ static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi, } if (cg) { - probe = g_slist_nth_data(cg->channels, 0); - if (!probe) + ch = g_slist_nth_data(cg->channels, 0); + if (!ch) return SR_ERR; - if (probe->type == SR_PROBE_ANALOG) { - if (probe->name[2] < '1' || probe->name[2] > '4') + if (ch->type == SR_CHANNEL_ANALOG) { + if (ch->name[2] < '1' || ch->name[2] > '4') return SR_ERR; - analog_channel = probe->name[2] - '1'; + analog_channel = ch->name[2] - '1'; } } @@ -546,6 +550,15 @@ static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi, tmp_str = devc->trigger_source; *data = g_variant_new_string(tmp_str); break; + case SR_CONF_TRIGGER_SLOPE: + if (!strcmp(devc->trigger_slope, "POS")) + tmp_str = "r"; + else if (!strcmp(devc->trigger_slope, "NEG")) + tmp_str = "f"; + else + return SR_ERR_NA; + *data = g_variant_new_string(tmp_str); + break; case SR_CONF_TIMEBASE: for (i = 0; i < devc->num_timebases; i++) { float tb = (float)devc->timebases[i][0] / devc->timebases[i][1]; @@ -838,6 +851,9 @@ static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi, *data = g_variant_new_strv(trigger_sources, devc->model->has_digital ? ARRAY_SIZE(trigger_sources) : 4); break; + case SR_CONF_TRIGGER_SLOPE: + *data = g_variant_new_strv(trigger_slopes, ARRAY_SIZE(trigger_slopes)); + break; case SR_CONF_DATA_SOURCE: if (!devc) /* Can't know this until we have the exact model. */ @@ -865,7 +881,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) { struct sr_scpi_dev_inst *scpi; struct dev_context *devc; - struct sr_channel *probe; + struct sr_channel *ch; struct sr_datafeed_packet packet; GSList *l; @@ -877,24 +893,24 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) devc->num_frames = 0; - for (l = sdi->probes; l; l = l->next) { - probe = l->data; - sr_dbg("handling probe %s", probe->name); - if (probe->type == SR_PROBE_ANALOG) { - if (probe->enabled) - devc->enabled_analog_probes = g_slist_append( - devc->enabled_analog_probes, probe); - if (probe->enabled != devc->analog_channels[probe->index]) { + for (l = sdi->channels; l; l = l->next) { + ch = l->data; + sr_dbg("handling channel %s", ch->name); + if (ch->type == SR_CHANNEL_ANALOG) { + if (ch->enabled) + devc->enabled_analog_channels = g_slist_append( + devc->enabled_analog_channels, ch); + if (ch->enabled != devc->analog_channels[ch->index]) { /* Enabled channel is currently disabled, or vice versa. */ - if (rigol_ds_config_set(sdi, ":CHAN%d:DISP %s", probe->index + 1, - probe->enabled ? "ON" : "OFF") != SR_OK) + if (rigol_ds_config_set(sdi, ":CHAN%d:DISP %s", ch->index + 1, + ch->enabled ? "ON" : "OFF") != SR_OK) return SR_ERR; - devc->analog_channels[probe->index] = probe->enabled; + devc->analog_channels[ch->index] = ch->enabled; } - } else if (probe->type == SR_PROBE_LOGIC) { - if (probe->enabled) { - devc->enabled_digital_probes = g_slist_append( - devc->enabled_digital_probes, probe); + } else if (ch->type == SR_CHANNEL_LOGIC) { + if (ch->enabled) { + devc->enabled_digital_channels = g_slist_append( + devc->enabled_digital_channels, ch); /* Turn on LA module if currently off. */ if (!devc->la_enabled) { if (rigol_ds_config_set(sdi, ":LA:DISP ON") != SR_OK) @@ -902,21 +918,21 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) devc->la_enabled = TRUE; } } - if (probe->enabled != devc->digital_channels[probe->index]) { + if (ch->enabled != devc->digital_channels[ch->index]) { /* Enabled channel is currently disabled, or vice versa. */ - if (rigol_ds_config_set(sdi, ":DIG%d:TURN %s", probe->index, - probe->enabled ? "ON" : "OFF") != SR_OK) + if (rigol_ds_config_set(sdi, ":DIG%d:TURN %s", ch->index, + ch->enabled ? "ON" : "OFF") != SR_OK) return SR_ERR; - devc->digital_channels[probe->index] = probe->enabled; + devc->digital_channels[ch->index] = ch->enabled; } } } - if (!devc->enabled_analog_probes && !devc->enabled_digital_probes) + if (!devc->enabled_analog_channels && !devc->enabled_digital_channels) return SR_ERR; - /* Turn off LA module if on and no digital probes selected. */ - if (devc->la_enabled && !devc->enabled_digital_probes) + /* Turn off LA module if on and no digital channels selected. */ + if (devc->la_enabled && !devc->enabled_digital_channels) if (rigol_ds_config_set(sdi, ":LA:DISP OFF") != SR_OK) return SR_ERR; @@ -931,7 +947,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) switch (devc->model->series->protocol) { case PROTOCOL_V2: - if (rigol_ds_config_set(sdi, ":ACQ:MDEP LONG") != SR_OK) + if (rigol_ds_config_set(sdi, ":ACQ:MEMD LONG") != SR_OK) return SR_ERR; break; case PROTOCOL_V3: @@ -954,15 +970,16 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) if (rigol_ds_config_set(sdi, ":RUN") != SR_OK) return SR_ERR; - sr_scpi_source_add(scpi, G_IO_IN, 50, rigol_ds_receive, (void *)sdi); + sr_scpi_source_add(sdi->session, scpi, G_IO_IN, 50, + rigol_ds_receive, (void *)sdi); /* Send header packet to the session bus. */ std_session_send_df_header(cb_data, LOG_PREFIX); - 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; if (rigol_ds_capture_start(sdi) != SR_OK) return SR_ERR; @@ -993,12 +1010,12 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data) packet.type = SR_DF_END; sr_session_send(sdi, &packet); - g_slist_free(devc->enabled_analog_probes); - g_slist_free(devc->enabled_digital_probes); - devc->enabled_analog_probes = NULL; - devc->enabled_digital_probes = NULL; + g_slist_free(devc->enabled_analog_channels); + g_slist_free(devc->enabled_digital_channels); + devc->enabled_analog_channels = NULL; + devc->enabled_digital_channels = NULL; scpi = sdi->conn; - sr_scpi_source_remove(scpi); + sr_scpi_source_remove(sdi->session, scpi); return SR_OK; }