X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=hardware%2Frigol-ds%2Fapi.c;h=57bfd033a8587a34dc286cb94521d83502aedc46;hb=3f239f0803b9fbc073dd7abe9fc7b2a0c606fbb6;hp=76c2efc7c811d91fd6c9b9944845d0afc39719b5;hpb=ca9b9f4834f106ba8387cf962a216425e0476de5;p=libsigrok.git diff --git a/hardware/rigol-ds/api.c b/hardware/rigol-ds/api.c index 76c2efc7..57bfd033 100644 --- a/hardware/rigol-ds/api.c +++ b/hardware/rigol-ds/api.c @@ -240,9 +240,9 @@ static void clear_helper(void *priv) g_free(devc->coupling[1]); g_free(devc->trigger_source); g_free(devc->trigger_slope); - g_slist_free(devc->analog_groups[0].probes); - g_slist_free(devc->analog_groups[1].probes); - g_slist_free(devc->digital_group.probes); + g_slist_free(devc->analog_groups[0].channels); + g_slist_free(devc->analog_groups[1].channels); + g_slist_free(devc->digital_group.channels); } static int dev_clear(void) @@ -255,34 +255,22 @@ static int init(struct sr_context *sr_ctx) return std_init(sr_ctx, di, LOG_PREFIX); } -static int probe_port(const char *resource, const char *serialcomm, GSList **devices) +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_dev_inst *scpi; struct sr_scpi_hw_info *hw_info; - struct sr_probe *probe; + struct sr_channel *ch; long n[3]; unsigned int i; const struct rigol_ds_model *model = NULL; gchar *channel_name, **version; - *devices = NULL; - - if (!(scpi = scpi_dev_inst_new(resource, serialcomm))) - return SR_ERR; - - if (sr_scpi_open(scpi) != SR_OK) { - sr_info("Couldn't open SCPI device."); - sr_scpi_free(scpi); - return SR_ERR; - }; - if (sr_scpi_get_hw_id(scpi, &hw_info) != SR_OK) { sr_info("Couldn't get IDN response."); sr_scpi_close(scpi); sr_scpi_free(scpi); - return SR_ERR; + return NULL; } for (i = 0; i < ARRAY_SIZE(supported_models); i++) { @@ -301,7 +289,7 @@ static int probe_port(const char *resource, const char *serialcomm, GSList **dev sr_scpi_hw_info_free(hw_info); sr_scpi_close(scpi); sr_scpi_free(scpi); - return SR_ERR_NA; + return NULL; } sr_scpi_close(scpi); @@ -312,7 +300,7 @@ static int probe_port(const char *resource, const char *serialcomm, GSList **dev sdi->inst_type = SR_INST_SCPI; if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) - return SR_ERR_MALLOC; + return NULL; devc->limit_frames = 0; devc->model = model; @@ -346,29 +334,29 @@ static int probe_port(const char *resource, const char *serialcomm, GSList **dev for (i = 0; i < model->analog_channels; i++) { if (!(channel_name = g_strdup_printf("CH%d", i + 1))) - return SR_ERR_MALLOC; - probe = sr_probe_new(i, SR_PROBE_ANALOG, TRUE, channel_name); - sdi->probes = g_slist_append(sdi->probes, probe); + return NULL; + 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].probes = g_slist_append(NULL, probe); - sdi->probe_groups = g_slist_append(sdi->probe_groups, + devc->analog_groups[i].channels = g_slist_append(NULL, ch); + sdi->channel_groups = g_slist_append(sdi->channel_groups, &devc->analog_groups[i]); } if (devc->model->has_digital) { for (i = 0; i < 16; i++) { if (!(channel_name = g_strdup_printf("D%d", i))) - return SR_ERR_MALLOC; - probe = sr_probe_new(i, SR_PROBE_LOGIC, TRUE, channel_name); + return NULL; + ch = sr_channel_new(i, SR_CHANNEL_LOGIC, TRUE, channel_name); g_free(channel_name); - if (!probe) - return SR_ERR_MALLOC; - sdi->probes = g_slist_append(sdi->probes, probe); - devc->digital_group.probes = g_slist_append( - devc->digital_group.probes, probe); + if (!ch) + return NULL; + sdi->channels = g_slist_append(sdi->channels, ch); + devc->digital_group.channels = g_slist_append( + devc->digital_group.channels, ch); } devc->digital_group.name = "LA"; - sdi->probe_groups = g_slist_append(sdi->probe_groups, + sdi->channel_groups = g_slist_append(sdi->channel_groups, &devc->digital_group); } @@ -384,77 +372,20 @@ static int probe_port(const char *resource, const char *serialcomm, GSList **dev devc->vdivs = &vdivs[i]; if (!(devc->buffer = g_try_malloc(ACQ_BUFFER_SIZE))) - return SR_ERR_MALLOC; + return NULL; if (!(devc->data = g_try_malloc(ACQ_BUFFER_SIZE * sizeof(float)))) - return SR_ERR_MALLOC; + return NULL; devc->data_source = DATA_SOURCE_LIVE; sdi->priv = devc; - *devices = g_slist_append(NULL, sdi); - - return SR_OK; + return sdi; } static GSList *scan(GSList *options) { - struct drv_context *drvc; - struct sr_config *src; - GSList *l, *devices; - GDir *dir; - int ret; - const gchar *dev_name; - gchar *port = NULL; - gchar *serialcomm = NULL; - - drvc = di->priv; - - for (l = options; l; l = l->next) { - src = l->data; - switch (src->key) { - case SR_CONF_CONN: - port = (char *)g_variant_get_string(src->data, NULL); - break; - case SR_CONF_SERIALCOMM: - serialcomm = (char *)g_variant_get_string(src->data, NULL); - break; - } - } - - devices = NULL; - if (port) { - if (probe_port(port, serialcomm, &devices) == SR_ERR_MALLOC) { - g_free(port); - if (serialcomm) - g_free(serialcomm); - return NULL; - } - } else { - if (!(dir = g_dir_open("/sys/class/usbmisc/", 0, NULL))) - if (!(dir = g_dir_open("/sys/class/usb/", 0, NULL))) - return NULL; - while ((dev_name = g_dir_read_name(dir))) { - if (strncmp(dev_name, "usbtmc", 6)) - continue; - port = g_strconcat("/dev/", dev_name, NULL); - ret = probe_port(port, serialcomm, &devices); - g_free(port); - if (serialcomm) - g_free(serialcomm); - if (ret == SR_ERR_MALLOC) { - g_dir_close(dir); - return NULL; - } - } - g_dir_close(dir); - } - - /* Tack a copy of the newly found devices onto the driver list. */ - l = g_slist_copy(devices); - drvc->instances = g_slist_concat(drvc->instances, l); - - return devices; + return sr_scpi_scan(di->priv, options, probe_device); } static GSList *dev_list(void) @@ -482,10 +413,13 @@ static int dev_close(struct sr_dev_inst *sdi) struct sr_scpi_dev_inst *scpi; struct dev_context *devc; + if (sdi->status != SR_ST_ACTIVE) + return SR_ERR_DEV_CLOSED; + scpi = sdi->conn; devc = sdi->priv; - if (devc->model->series->protocol >= PROTOCOL_V2) + if (devc->model->series->protocol == PROTOCOL_V2) rigol_ds_config_set(sdi, ":KEY:LOCK DISABLE"); if (scpi) { @@ -505,24 +439,24 @@ static int cleanup(void) static int analog_frame_size(const struct sr_dev_inst *sdi) { struct dev_context *devc = sdi->priv; - struct sr_probe *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; } @@ -543,10 +477,10 @@ static int digital_frame_size(const struct sr_dev_inst *sdi) } static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi, - const struct sr_probe_group *probe_group) + const struct sr_channel_group *cg) { struct dev_context *devc; - struct sr_probe *probe; + struct sr_channel *ch; const char *tmp_str; uint64_t samplerate; int analog_channel = -1; @@ -557,20 +491,20 @@ static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi, if (!sdi || !(devc = sdi->priv)) return SR_ERR_ARG; - /* If a probe group is specified, it must be a valid one. */ - if (probe_group && !g_slist_find(sdi->probe_groups, probe_group)) { - sr_err("Invalid probe group specified."); + /* If a channel group is specified, it must be a valid one. */ + if (cg && !g_slist_find(sdi->channel_groups, cg)) { + sr_err("Invalid channel group specified."); return SR_ERR; } - if (probe_group) { - probe = g_slist_nth_data(probe_group->probes, 0); - if (!probe) + if (cg) { + 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'; } } @@ -654,7 +588,7 @@ static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi, } static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi, - const struct sr_probe_group *probe_group) + const struct sr_channel_group *cg) { struct dev_context *devc; uint64_t p, q; @@ -670,9 +604,9 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi, if (sdi->status != SR_ST_ACTIVE) return SR_ERR_DEV_CLOSED; - /* If a probe group is specified, it must be a valid one. */ - if (probe_group && !g_slist_find(sdi->probe_groups, probe_group)) { - sr_err("Invalid probe group specified."); + /* If a channel group is specified, it must be a valid one. */ + if (cg && !g_slist_find(sdi->channel_groups, cg)) { + sr_err("Invalid channel group specified."); return SR_ERR; } @@ -742,13 +676,13 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi, ret = SR_ERR_ARG; break; case SR_CONF_VDIV: - if (!probe_group) { - sr_err("No probe group specified."); - return SR_ERR_PROBE_GROUP; + if (!cg) { + sr_err("No channel group specified."); + return SR_ERR_CHANNEL_GROUP; } g_variant_get(data, "(tt)", &p, &q); for (i = 0; i < 2; i++) { - if (probe_group == &devc->analog_groups[i]) { + if (cg == &devc->analog_groups[i]) { for (j = 0; j < ARRAY_SIZE(vdivs); j++) { if (vdivs[j][0] != p || vdivs[j][1] != q) continue; @@ -763,13 +697,13 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi, } return SR_ERR_NA; case SR_CONF_COUPLING: - if (!probe_group) { - sr_err("No probe group specified."); - return SR_ERR_PROBE_GROUP; + if (!cg) { + sr_err("No channel group specified."); + return SR_ERR_CHANNEL_GROUP; } tmp_str = g_variant_get_string(data, NULL); for (i = 0; i < 2; i++) { - if (probe_group == &devc->analog_groups[i]) { + if (cg == &devc->analog_groups[i]) { for (j = 0; j < ARRAY_SIZE(coupling); j++) { if (!strcmp(tmp_str, coupling[j])) { g_free(devc->coupling[i]); @@ -804,7 +738,7 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi, } static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi, - const struct sr_probe_group *probe_group) + const struct sr_channel_group *cg) { GVariant *tuple, *rational[2]; GVariantBuilder gvb; @@ -818,7 +752,7 @@ static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi, *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32, hwopts, ARRAY_SIZE(hwopts), sizeof(int32_t)); return SR_OK; - } else if (key == SR_CONF_DEVICE_OPTIONS && probe_group == NULL) { + } else if (key == SR_CONF_DEVICE_OPTIONS && cg == NULL) { *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32, hwcaps, ARRAY_SIZE(hwcaps), sizeof(int32_t)); return SR_OK; @@ -828,28 +762,28 @@ static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi, if (!sdi || !(devc = sdi->priv)) return SR_ERR_ARG; - /* If a probe group is specified, it must be a valid one. */ - if (probe_group) { - if (probe_group != &devc->analog_groups[0] - && probe_group != &devc->analog_groups[1]) { - sr_err("Invalid probe group specified."); + /* If a channel group is specified, it must be a valid one. */ + if (cg) { + if (cg != &devc->analog_groups[0] + && cg != &devc->analog_groups[1]) { + sr_err("Invalid channel group specified."); return SR_ERR; } } switch (key) { case SR_CONF_DEVICE_OPTIONS: - if (!probe_group) { - sr_err("No probe group specified."); - return SR_ERR_PROBE_GROUP; + if (!cg) { + sr_err("No channel group specified."); + return SR_ERR_CHANNEL_GROUP; } - if (probe_group == &devc->digital_group) { + if (cg == &devc->digital_group) { *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32, NULL, 0, sizeof(int32_t)); return SR_OK; } else { for (i = 0; i < 2; i++) { - if (probe_group == &devc->analog_groups[i]) { + if (cg == &devc->analog_groups[i]) { *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32, analog_hwcaps, ARRAY_SIZE(analog_hwcaps), sizeof(int32_t)); return SR_OK; @@ -859,9 +793,9 @@ static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi, } break; case SR_CONF_COUPLING: - if (!probe_group) { - sr_err("No probe group specified."); - return SR_ERR_PROBE_GROUP; + if (!cg) { + sr_err("No channel group specified."); + return SR_ERR_CHANNEL_GROUP; } *data = g_variant_new_strv(coupling, ARRAY_SIZE(coupling)); break; @@ -869,9 +803,9 @@ static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi, if (!devc) /* Can't know this until we have the exact model. */ return SR_ERR_ARG; - if (!probe_group) { - sr_err("No probe group specified."); - return SR_ERR_PROBE_GROUP; + if (!cg) { + sr_err("No channel group specified."); + return SR_ERR_CHANNEL_GROUP; } g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY); for (i = 0; i < NUM_VDIV; i++) { @@ -931,7 +865,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_probe *probe; + struct sr_channel *ch; struct sr_datafeed_packet packet; GSList *l; @@ -943,24 +877,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) @@ -968,21 +902,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; @@ -1025,10 +959,10 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) /* 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; @@ -1059,10 +993,10 @@ 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);