X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Flecroy-xstream%2Fapi.c;h=075fff76fb9816d11e5a2ceab2ba83f33167a606;hb=6402c379161ec138e451901c411817a55846a75b;hp=ed3603a28d907e216515abdfd472f736f4ae96be;hpb=ea257cdc23d0489fd589d0f17e3838db28189a79;p=libsigrok.git diff --git a/src/hardware/lecroy-xstream/api.c b/src/hardware/lecroy-xstream/api.c index ed3603a2..075fff76 100644 --- a/src/hardware/lecroy-xstream/api.c +++ b/src/hardware/lecroy-xstream/api.c @@ -32,6 +32,26 @@ static const uint32_t scanopts[] = { SR_CONF_CONN, }; +static const uint32_t drvopts[] = { + SR_CONF_OSCILLOSCOPE, +}; + +static const uint32_t devopts[] = { + SR_CONF_LIMIT_FRAMES | SR_CONF_GET | SR_CONF_SET, + SR_CONF_SAMPLERATE | SR_CONF_GET, + SR_CONF_TIMEBASE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, + SR_CONF_NUM_HDIV | SR_CONF_GET, + SR_CONF_HORIZ_TRIGGERPOS | SR_CONF_GET | SR_CONF_SET, + SR_CONF_TRIGGER_SOURCE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, + SR_CONF_TRIGGER_SLOPE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, +}; + +static const uint32_t analog_devopts[] = { + SR_CONF_NUM_VDIV | SR_CONF_GET, + SR_CONF_VDIV | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, + SR_CONF_COUPLING | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, +}; + static int check_manufacturer(const char *manufacturer) { unsigned int i; @@ -84,8 +104,7 @@ static struct sr_dev_inst *probe_serial_device(struct sr_scpi_dev_inst *scpi) fail: sr_scpi_hw_info_free(hw_info); - if (sdi) - sr_dev_inst_free(sdi); + sr_dev_inst_free(sdi); g_free(devc); return NULL; @@ -116,7 +135,7 @@ static int dev_clear(const struct sr_dev_driver *di) static int dev_open(struct sr_dev_inst *sdi) { - if (sdi->status != SR_ST_ACTIVE && sr_scpi_open(sdi->conn) != SR_OK) + if (sr_scpi_open(sdi->conn) != SR_OK) return SR_ERR; if (lecroy_xstream_state_get(sdi) != SR_OK) @@ -129,9 +148,6 @@ static int dev_open(struct sr_dev_inst *sdi) static int dev_close(struct sr_dev_inst *sdi) { - if (sdi->status == SR_ST_INACTIVE) - return SR_OK; - sr_scpi_close(sdi->conn); sdi->status = SR_ST_INACTIVE; @@ -402,24 +418,38 @@ static int config_list(uint32_t key, GVariant **data, (void)cg; - if (sdi) { - devc = sdi->priv; - model = devc->model_config; + /* SR_CONF_SCAN_OPTIONS is always valid, regardless of sdi or channel group. */ + if (key == SR_CONF_SCAN_OPTIONS) { + *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, + scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t)); + return SR_OK; } - switch (key) { - case SR_CONF_SCAN_OPTIONS: + /* If sdi is NULL, nothing except SR_CONF_DEVICE_OPTIONS can be provided. */ + if (key == SR_CONF_DEVICE_OPTIONS && !sdi) { *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, - scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t)); - break; + drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t)); + return SR_OK; + } + + /* Every other option requires a valid device instance. */ + if (!sdi) + return SR_ERR_ARG; + + devc = sdi->priv; + model = devc->model_config; + + switch (key) { case SR_CONF_DEVICE_OPTIONS: if (!cg) { + /* If cg is NULL, only the SR_CONF_DEVICE_OPTIONS that are not + * specific to a channel group must be returned. */ *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, - model->devopts, model->num_devopts, sizeof(uint32_t)); - break; + devopts, ARRAY_SIZE(devopts), sizeof(uint32_t)); + return SR_OK; } *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, - model->analog_devopts, model->num_analog_devopts, + analog_devopts, ARRAY_SIZE(analog_devopts), sizeof(uint32_t)); break; case SR_CONF_COUPLING: @@ -472,7 +502,7 @@ SR_PRIV int lecroy_xstream_request_data(const struct sr_dev_inst *sdi) return sr_scpi_send(sdi->conn, command); } -static int lecroy_setup_channels(const struct sr_dev_inst *sdi) +static int setup_channels(const struct sr_dev_inst *sdi) { GSList *l; gboolean setup_changed; @@ -520,9 +550,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) int ret; struct sr_scpi_dev_inst *scpi; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - devc = sdi->priv; scpi = sdi->conn; /* Preset empty results. */ @@ -550,7 +577,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) * Configure the analog channels and the * corresponding digital pods. */ - if (lecroy_setup_channels(sdi) != SR_OK) { + if (setup_channels(sdi) != SR_OK) { sr_err("Failed to setup channel configuration!"); ret = SR_ERR; goto free_enabled; @@ -583,9 +610,6 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi) std_session_send_df_end(sdi); - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - devc = sdi->priv; devc->num_frames = 0;