]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/hameg-hmo/api.c
hameg-hmo: Use the host's endianess to read analog channel data via SCPI
[libsigrok.git] / src / hardware / hameg-hmo / api.c
index 1e60a34aba99696470967da10af091a49f85e9fe..ead97cd4cef46eb48c4a28007d0bf3783c1c79d4 100644 (file)
@@ -24,7 +24,7 @@
 
 #define SERIALCOMM "115200/8n1/flow=1"
 
-SR_PRIV struct sr_dev_driver hameg_hmo_driver_info;
+static struct sr_dev_driver hameg_hmo_driver_info;
 
 static const char *manufacturers[] = {
        "HAMEG",
@@ -47,11 +47,6 @@ enum {
        CG_DIGITAL,
 };
 
-static int init(struct sr_dev_driver *di, struct sr_context *sr_ctx)
-{
-       return std_init(di, sr_ctx);
-}
-
 static int check_manufacturer(const char *manufacturer)
 {
        unsigned int i;
@@ -194,9 +189,11 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s
        const struct scope_config *model;
        struct scope_state *state;
 
-       if (!sdi || !(devc = sdi->priv))
+       if (!sdi)
                return SR_ERR_ARG;
 
+       devc = sdi->priv;
+
        if ((cg_type = check_channel_group(devc, cg)) == CG_INVALID)
                return SR_ERR;
 
@@ -323,9 +320,11 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
        double tmp_d;
        gboolean update_sample_rate;
 
-       if (!sdi || !(devc = sdi->priv))
+       if (!sdi)
                return SR_ERR_ARG;
 
+       devc = sdi->priv;
+
        if ((cg_type = check_channel_group(devc, cg)) == CG_INVALID)
                return SR_ERR;
 
@@ -488,7 +487,8 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
        struct dev_context *devc = NULL;
        const struct scope_config *model = NULL;
 
-       if (sdi && (devc = sdi->priv)) {
+       if (sdi) {
+               devc = sdi->priv;
                if ((cg_type = check_channel_group(devc, cg)) == CG_INVALID)
                        return SR_ERR;
 
@@ -568,6 +568,11 @@ SR_PRIV int hmo_request_data(const struct sr_dev_inst *sdi)
        case SR_CHANNEL_ANALOG:
                g_snprintf(command, sizeof(command),
                           (*model->scpi_dialect)[SCPI_CMD_GET_ANALOG_DATA],
+#ifdef WORDS_BIGENDIAN
+                          "MSBF",
+#else
+                          "LSBF",
+#endif
                           ch->index + 1);
                break;
        case SR_CHANNEL_LOGIC:
@@ -705,6 +710,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
        struct sr_channel *ch;
        struct dev_context *devc;
        struct sr_scpi_dev_inst *scpi;
+       int ret;
 
        if (sdi->status != SR_ST_ACTIVE)
                return SR_ERR_DEV_CLOSED;
@@ -734,22 +740,29 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
 
        if (hmo_check_channels(devc->enabled_channels) != SR_OK) {
                sr_err("Invalid channel configuration specified!");
-               return SR_ERR_NA;
+               ret = SR_ERR_NA;
+               goto free_enabled;
        }
 
        if (hmo_setup_channels(sdi) != SR_OK) {
                sr_err("Failed to setup channel configuration!");
-               return SR_ERR;
+               ret = SR_ERR;
+               goto free_enabled;
        }
 
        sr_scpi_source_add(sdi->session, scpi, G_IO_IN, 50,
                        hmo_receive_data, (void *)sdi);
 
-       std_session_send_df_header(sdi, LOG_PREFIX);
+       std_session_send_df_header(sdi);
 
        devc->current_channel = devc->enabled_channels;
 
        return hmo_request_data(sdi);
+
+free_enabled:
+       g_slist_free(devc->enabled_channels);
+       devc->enabled_channels = NULL;
+       return ret;
 }
 
 static int dev_acquisition_stop(struct sr_dev_inst *sdi)
@@ -757,7 +770,7 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi)
        struct dev_context *devc;
        struct sr_scpi_dev_inst *scpi;
 
-       std_session_send_df_end(sdi, LOG_PREFIX);
+       std_session_send_df_end(sdi);
 
        if (sdi->status != SR_ST_ACTIVE)
                return SR_ERR_DEV_CLOSED;
@@ -773,11 +786,11 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi)
        return SR_OK;
 }
 
-SR_PRIV struct sr_dev_driver hameg_hmo_driver_info = {
+static struct sr_dev_driver hameg_hmo_driver_info = {
        .name = "hameg-hmo",
        .longname = "Hameg HMO",
        .api_version = 1,
-       .init = init,
+       .init = std_init,
        .cleanup = std_cleanup,
        .scan = scan,
        .dev_list = std_dev_list,
@@ -791,3 +804,4 @@ SR_PRIV struct sr_dev_driver hameg_hmo_driver_info = {
        .dev_acquisition_stop = dev_acquisition_stop,
        .context = NULL,
 };
+SR_REGISTER_DEV_DRIVER(hameg_hmo_driver_info);