X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Frohde-schwarz-sme-0x%2Fapi.c;h=6a719e878015dd5b45baa793478f8f93e620f89f;hb=fdf0744fa4b40adab32e8f10d84df784284c67cc;hp=59675c0cf1618b143b05537a1bc4872f5887ca9e;hpb=a28b3df111ce6b942d0904b7647b959a48f2b479;p=libsigrok.git diff --git a/src/hardware/rohde-schwarz-sme-0x/api.c b/src/hardware/rohde-schwarz-sme-0x/api.c index 59675c0c..6a719e87 100644 --- a/src/hardware/rohde-schwarz-sme-0x/api.c +++ b/src/hardware/rohde-schwarz-sme-0x/api.c @@ -26,59 +26,60 @@ SR_PRIV struct sr_dev_driver rohde_schwarz_sme_0x_driver_info; -static const char * manufacturer = "Rohde&Schwarz"; - -static const struct rs_device_model device_models[] = {{ - .model_str = "SME02", - .freq_max = SR_GHZ(1.5), - .freq_min = SR_KHZ(5), - .power_max = 16, - .power_min = -144 -}, { - .model_str = "SME03E", - .freq_max = SR_GHZ(2.2), - .freq_min = SR_KHZ(5), - .power_max = 16, - .power_min = -144 -}, { - .model_str = "SME03A", - .freq_max = SR_GHZ(3), - .freq_min = SR_KHZ(5), - .power_max = 16, - .power_min = -144 -}, { - .model_str = "SME03", - .freq_max = SR_GHZ(3), - .freq_min = SR_KHZ(5), - .power_max = 16, - .power_min = -144 -}, { - .model_str = "SME06", - .freq_max = SR_GHZ(1.5), - .freq_min = SR_KHZ(5), - .power_max = 16, - .power_min = -144 -}}; +static const char *manufacturer = "Rohde&Schwarz"; + +static const struct rs_device_model device_models[] = { + { + .model_str = "SME02", + .freq_max = SR_GHZ(1.5), + .freq_min = SR_KHZ(5), + .power_max = 16, + .power_min = -144, + }, + { + .model_str = "SME03E", + .freq_max = SR_GHZ(2.2), + .freq_min = SR_KHZ(5), + .power_max = 16, + .power_min = -144, + }, + { + .model_str = "SME03A", + .freq_max = SR_GHZ(3), + .freq_min = SR_KHZ(5), + .power_max = 16, + .power_min = -144, + }, + { + .model_str = "SME03", + .freq_max = SR_GHZ(3), + .freq_min = SR_KHZ(5), + .power_max = 16, + .power_min = -144, + }, + { + .model_str = "SME06", + .freq_max = SR_GHZ(1.5), + .freq_min = SR_KHZ(5), + .power_max = 16, + .power_min = -144, + } +}; static const uint32_t scanopts[] = { SR_CONF_CONN, SR_CONF_SERIALCOMM, }; +static const uint32_t drvopts[] = { + SR_CONF_SIGNAL_GENERATOR, +}; + static const uint32_t devopts[] = { SR_CONF_OUTPUT_FREQUENCY | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, SR_CONF_AMPLITUDE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, }; -static int check_manufacturer(const char *str) -{ - if (!strcmp(str, manufacturer)) { - return SR_OK; - } - - return SR_ERR; -} - static int rs_init_device(struct sr_dev_inst *sdi) { struct dev_context *devc; @@ -96,14 +97,15 @@ static int rs_init_device(struct sr_dev_inst *sdi) } if (!model_found) { - sr_dbg("Device %s %s is not supported by this driver", manufacturer, sdi->model); + sr_dbg("Device %s %s is not supported by this driver.", + manufacturer, sdi->model); return SR_ERR_NA; } return SR_OK; } -static struct sr_dev_inst *rs_probe_serial_device(struct sr_scpi_dev_inst *scpi) +static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi) { struct sr_dev_inst *sdi; struct dev_context *devc; @@ -115,13 +117,11 @@ static struct sr_dev_inst *rs_probe_serial_device(struct sr_scpi_dev_inst *scpi) rs_sme0x_mode_remote(scpi); - if (sr_scpi_get_hw_id(scpi, &hw_info) != SR_OK) { + if (sr_scpi_get_hw_id(scpi, &hw_info) != SR_OK) goto fail; - } - if (check_manufacturer(hw_info->manufacturer) != SR_OK) { + if (strcmp(hw_info->manufacturer, manufacturer) != 0) goto fail; - } sdi = g_malloc0(sizeof(struct sr_dev_inst)); sdi->vendor = g_strdup(hw_info->manufacturer); @@ -138,57 +138,31 @@ static struct sr_dev_inst *rs_probe_serial_device(struct sr_scpi_dev_inst *scpi) devc = g_malloc0(sizeof(struct dev_context)); sdi->priv = devc; - if (rs_init_device(sdi) != SR_OK) { + if (rs_init_device(sdi) != SR_OK) goto fail; - } return sdi; fail: - if (hw_info) { - sr_scpi_hw_info_free(hw_info); - } - - if (sdi) { - sr_dev_inst_free(sdi); - } - + sr_scpi_hw_info_free(hw_info); + sr_dev_inst_free(sdi); g_free(devc); return NULL; } static GSList *scan(struct sr_dev_driver *di, GSList *options) { - return sr_scpi_scan(di->context, options, rs_probe_serial_device); -} - -static int dev_clear(const struct sr_dev_driver *di) -{ - return std_dev_clear(di, NULL); + return sr_scpi_scan(di->context, options, probe_device); } static int dev_open(struct sr_dev_inst *sdi) { - if (sdi->status != SR_ST_ACTIVE && sr_scpi_open(sdi->conn) != SR_OK) { - return SR_ERR; - } - - sdi->status = SR_ST_ACTIVE; - - return SR_OK; + return sr_scpi_open(sdi->conn); } 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; - - return SR_OK; + return sr_scpi_close(sdi->conn); } static int config_get(uint32_t key, GVariant **data, @@ -221,13 +195,8 @@ static int config_set(uint32_t key, GVariant *data, (void)cg; - if (!sdi) { + if (!sdi) return SR_ERR_ARG; - } - - if (sdi->status != SR_ST_ACTIVE) { - return SR_ERR_DEV_CLOSED; - } switch (key) { case SR_CONF_OUTPUT_FREQUENCY: @@ -248,30 +217,7 @@ static int config_set(uint32_t key, GVariant *data, static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { - (void)sdi; - (void)cg; - - switch (key) { - case SR_CONF_SCAN_OPTIONS: - *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t)); - break; - case SR_CONF_DEVICE_OPTIONS: - *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, devopts, ARRAY_SIZE(devopts), sizeof(uint32_t)); - break; - default: - return SR_ERR_NA; - } - - return SR_OK; -} - -static int dev_acquisition_start(const struct sr_dev_inst *sdi) -{ - if (sdi->status != SR_ST_ACTIVE) { - return SR_ERR_DEV_CLOSED; - } - - return SR_OK; + return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts); } SR_PRIV struct sr_dev_driver rohde_schwarz_sme_0x_driver_info = { @@ -282,13 +228,13 @@ SR_PRIV struct sr_dev_driver rohde_schwarz_sme_0x_driver_info = { .cleanup = std_cleanup, .scan = scan, .dev_list = std_dev_list, - .dev_clear = dev_clear, + .dev_clear = std_dev_clear, .config_get = config_get, .config_set = config_set, .config_list = config_list, .dev_open = dev_open, .dev_close = dev_close, - .dev_acquisition_start = dev_acquisition_start, + .dev_acquisition_start = std_dummy_dev_acquisition_start, .dev_acquisition_stop = std_serial_dev_acquisition_stop, .context = NULL, };