X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fscpi-pps%2Fapi.c;h=e2afad3bead0f9ce016e8910ebf4b27404c78314;hb=700d6b64d578ce10e57f6a2289e37a5564eccf1c;hp=58e14f6e08abdaf9cf8848efad9fc0a0a6611401;hpb=91ef511db2370904f8765a13e315fbddaf5ffe07;p=libsigrok.git diff --git a/src/hardware/scpi-pps/api.c b/src/hardware/scpi-pps/api.c index 58e14f6e..e2afad3b 100644 --- a/src/hardware/scpi-pps/api.c +++ b/src/hardware/scpi-pps/api.c @@ -17,6 +17,7 @@ * along with this program. If not, see . */ +#include #include #include #include "scpi.h" @@ -74,7 +75,7 @@ static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi) device = NULL; for (i = 0; i < num_pps_profiles; i++) { vendor = sr_vendor_alias(hw_info->manufacturer); - if (strcasecmp(vendor, pps_profiles[i].vendor)) + if (g_ascii_strcasecmp(vendor, pps_profiles[i].vendor)) continue; model_re = g_regex_new(pps_profiles[i].model, 0, 0, NULL); if (g_regex_match(model_re, hw_info->model, 0, &model_mi)) @@ -90,7 +91,6 @@ static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi) } sdi = g_malloc0(sizeof(struct sr_dev_inst)); - sdi->status = SR_ST_INACTIVE; sdi->vendor = g_strdup(vendor); sdi->model = g_strdup(hw_info->model); sdi->version = g_strdup(hw_info->firmware_version); @@ -167,7 +167,6 @@ static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi) hw_info = NULL; scpi_cmd(sdi, devc->device->commands, SCPI_CMD_LOCAL); - sr_scpi_close(scpi); return sdi; } @@ -182,11 +181,6 @@ static GSList *dev_list(const struct sr_dev_driver *di) return ((struct drv_context *)(di->context))->instances; } -static int dev_clear(const struct sr_dev_driver *di) -{ - return std_dev_clear(di, NULL); -} - static int dev_open(struct sr_dev_inst *sdi) { struct dev_context *devc; @@ -204,7 +198,6 @@ static int dev_open(struct sr_dev_inst *sdi) devc = sdi->priv; scpi_cmd(sdi, devc->device->commands, SCPI_CMD_REMOTE); - devc = sdi->priv; devc->beeper_was_set = FALSE; if (scpi_cmd_resp(sdi, devc->device->commands, &beeper, G_VARIANT_TYPE_BOOLEAN, SCPI_CMD_BEEPER) == SR_OK) { @@ -249,7 +242,7 @@ static void clear_helper(void *priv) g_free(devc); } -static int cleanup(const struct sr_dev_driver *di) +static int dev_clear(const struct sr_dev_driver *di) { return std_dev_clear(di, clear_helper); } @@ -261,7 +254,7 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s const GVariantType *gvtype; unsigned int i; int cmd, ret; - char *s; + const char *s; if (!sdi) return SR_ERR_ARG; @@ -364,19 +357,20 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s * return VOLT/CURR. We always return a GVariant string in * the Rigol notation. */ - if ((ret = sr_scpi_get_string(sdi->conn, NULL, &s)) != SR_OK) - return ret; - if (!strcmp(s, "CV") || !strcmp(s, "VOLT")) { + s = g_variant_get_string(*data, NULL); + if (!strcmp(s, "VOLT")) { + g_variant_unref(*data); *data = g_variant_new_string("CV"); - } else if (!strcmp(s, "CC") || !strcmp(s, "CURR")) { + } else if (!strcmp(s, "CURR")) { + g_variant_unref(*data); *data = g_variant_new_string("CC"); - } else if (!strcmp(s, "UR")) { - *data = g_variant_new_string("UR"); - } else { + } + + s = g_variant_get_string(*data, NULL); + if (strcmp(s, "CV") && strcmp(s, "CC") && strcmp(s, "UR")) { sr_dbg("Unknown response to SCPI_CMD_GET_OUTPUT_REGULATION: %s", s); ret = SR_ERR_DATA; } - g_free(s); } return ret; @@ -400,7 +394,7 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd select_channel(sdi, cg->channels->data); devc = sdi->priv; - ret = SR_OK; + switch (key) { case SR_CONF_ENABLED: if (g_variant_get_boolean(data)) @@ -576,7 +570,7 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst * return ret; } -static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) +static int dev_acquisition_start(const struct sr_dev_inst *sdi) { struct dev_context *devc; struct sr_scpi_dev_inst *scpi; @@ -589,7 +583,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) devc = sdi->priv; scpi = sdi->conn; - devc->cb_data = cb_data; if ((ret = sr_scpi_source_add(sdi->session, scpi, G_IO_IN, 10, scpi_pps_receive_data, (void *)sdi)) != SR_OK) @@ -597,7 +590,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) std_session_send_df_header(sdi, LOG_PREFIX); /* Prime the pipe with the first channel's fetch. */ - ch = next_enabled_channel(sdi, NULL); + ch = sr_next_enabled_channel(sdi, NULL); pch = ch->priv; if ((ret = select_channel(sdi, ch)) < 0) return ret; @@ -616,14 +609,11 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) return SR_OK; } -static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data) +static int dev_acquisition_stop(struct sr_dev_inst *sdi) { - struct sr_datafeed_packet packet; struct sr_scpi_dev_inst *scpi; float f; - (void)cb_data; - if (sdi->status != SR_ST_ACTIVE) return SR_ERR_DEV_CLOSED; @@ -637,8 +627,7 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data) sr_scpi_get_float(scpi, NULL, &f); sr_scpi_source_remove(sdi->session, scpi); - packet.type = SR_DF_END; - sr_session_send(sdi, &packet); + std_session_send_df_end(sdi, LOG_PREFIX); return SR_OK; } @@ -648,7 +637,7 @@ SR_PRIV struct sr_dev_driver scpi_pps_driver_info = { .longname = "SCPI PPS", .api_version = 1, .init = init, - .cleanup = cleanup, + .cleanup = std_cleanup, .scan = scan, .dev_list = dev_list, .dev_clear = dev_clear,