]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/siglent-sds/protocol.c
input/protocoldata: improve use of feed queue API
[libsigrok.git] / src / hardware / siglent-sds / protocol.c
index 69c07db5c9e2151907a5043e59af8cdccf05d5c1..919df9b27c30830ff16ff3f41c73b918abebc1a5 100644 (file)
@@ -75,6 +75,7 @@ static int siglent_sds_event_wait(const struct sr_dev_inst *sdi)
                        if (sr_scpi_get_string(sdi->conn, ":INR?", &buf) != SR_OK)
                                return SR_ERR;
                        sr_atoi(buf, &out);
+                       g_free(buf);
                        g_usleep(s);
                } while (out == 0);
 
@@ -100,6 +101,7 @@ static int siglent_sds_event_wait(const struct sr_dev_inst *sdi)
                        if (sr_scpi_get_string(sdi->conn, ":INR?", &buf) != SR_OK)
                                return SR_ERR;
                        sr_atoi(buf, &out);
+                       g_free(buf);
                        g_usleep(s);
                /* XXX
                 * Now this loop condition looks suspicious! A bitwise
@@ -168,6 +170,7 @@ SR_PRIV int siglent_sds_capture_start(const struct sr_dev_inst *sdi)
                        if (sr_scpi_get_string(sdi->conn, ":INR?", &buf) != SR_OK)
                                return SR_ERR;
                        sr_atoi(buf, &out);
+                       g_free(buf);
                        if (out == DEVICE_STATE_TRIG_RDY) {
                                siglent_sds_set_wait_event(devc, WAIT_TRIGGER);
                        } else if (out == DEVICE_STATE_DATA_TRIG_RDY) {
@@ -217,6 +220,7 @@ SR_PRIV int siglent_sds_capture_start(const struct sr_dev_inst *sdi)
                        if (sr_scpi_get_string(sdi->conn, ":INR?", &buf) != SR_OK)
                                return SR_ERR;
                        sr_atoi(buf, &out);
+                       g_free(buf);
                        if (out == DEVICE_STATE_TRIG_RDY) {
                                siglent_sds_set_wait_event(devc, WAIT_TRIGGER);
                        } else if (out == DEVICE_STATE_DATA_TRIG_RDY) {
@@ -348,7 +352,7 @@ static int siglent_sds_get_digital(const struct sr_dev_inst *sdi, struct sr_chan
        gboolean low_channels; /* Lower channels enabled */
        gboolean high_channels; /* Higher channels enabled */
        int len, channel_index;
-       long samples_index;
+       uint64_t samples_index;
 
        len = 0;
        channel_index = 0;
@@ -414,7 +418,7 @@ static int siglent_sds_get_digital(const struct sr_dev_inst *sdi, struct sr_chan
                                }
 
                                /* Storing the converted temp values from the the scope into the buffers. */
-                               for (long index = 0; index < tmp_samplebuf->len; index++) {
+                               for (uint64_t index = 0; index < tmp_samplebuf->len; index++) {
                                        uint8_t value = g_array_index(tmp_samplebuf, uint8_t, index);
                                        if (ch->index < 8)
                                                g_array_append_val(data_low_channels, value);
@@ -561,7 +565,7 @@ SR_PRIV int siglent_sds_receive(int fd, int revents, void *cb_data)
                                        devc->buffer += devc->block_header_size;
                                        len = devc->num_samples;
                                } else {
-                                       sr_dbg("Requesting: %li bytes.", devc->num_samples - devc->num_block_bytes);
+                                       sr_dbg("Requesting: %" PRIu64 " bytes.", devc->num_samples - devc->num_block_bytes);
                                        len = sr_scpi_read_data(scpi, (char *)devc->buffer, devc->num_samples-devc->num_block_bytes);
                                        if (len == -1) {
                                                sr_err("Read error, aborting capture.");
@@ -760,6 +764,8 @@ SR_PRIV int siglent_sds_get_dev_cfg(const struct sr_dev_inst *sdi)
        /* Coupling. */
        for (i = 0; i < devc->model->analog_channels; i++) {
                cmd = g_strdup_printf("C%d:CPL?", i + 1);
+               g_free(devc->coupling[i]);
+               devc->coupling[i] = NULL;
                res = sr_scpi_get_string(sdi->conn, cmd, &devc->coupling[i]);
                g_free(cmd);
                if (res != SR_OK)
@@ -776,7 +782,7 @@ SR_PRIV int siglent_sds_get_dev_cfg(const struct sr_dev_inst *sdi)
        if (sr_scpi_get_string(sdi->conn, "TRSE?", &response) != SR_OK)
                return SR_ERR;
        tokens = g_strsplit(response, ",", 0);
-       for (num_tokens = 0; tokens[num_tokens] != NULL; num_tokens++);
+       num_tokens = g_strv_length(tokens);
        if (num_tokens < 4) {
                sr_dbg("IDN response not according to spec: %80.s.", response);
                g_strfreev(tokens);
@@ -813,6 +819,8 @@ SR_PRIV int siglent_sds_get_dev_cfg(const struct sr_dev_inst *sdi)
 
        /* Trigger slope. */
        cmd = g_strdup_printf("%s:TRSL?", devc->trigger_source);
+       g_free(devc->trigger_slope);
+       devc->trigger_slope = NULL;
        res = sr_scpi_get_string(sdi->conn, cmd, &devc->trigger_slope);
        g_free(cmd);
        if (res != SR_OK)
@@ -886,12 +894,15 @@ SR_PRIV int siglent_sds_get_dev_cfg_horizontal(const struct sr_dev_inst *sdi)
                g_free(cmd);
                samplerate_scope = 0;
                fvalue = 0;
-               if (res != SR_OK)
+               if (res != SR_OK) {
+                       g_free(sample_points_string);
                        return SR_ERR;
+               }
                if (g_strstr_len(sample_points_string, -1, "Mpts") != NULL) {
                        sample_points_string[strlen(sample_points_string) - 4] = '\0';
                        if (sr_atof_ascii(sample_points_string, &fvalue) != SR_OK) {
                                sr_dbg("Invalid float converted from scope response.");
+                               g_free(sample_points_string);
                                return SR_ERR;
                        }
                        samplerate_scope = fvalue * 1000000;
@@ -899,6 +910,7 @@ SR_PRIV int siglent_sds_get_dev_cfg_horizontal(const struct sr_dev_inst *sdi)
                        sample_points_string[strlen(sample_points_string) - 4] = '\0';
                        if (sr_atof_ascii(sample_points_string, &fvalue) != SR_OK) {
                                sr_dbg("Invalid float converted from scope response.");
+                               g_free(sample_points_string);
                                return SR_ERR;
                        }
                        samplerate_scope = fvalue * 10000;
@@ -930,7 +942,7 @@ SR_PRIV int siglent_sds_get_dev_cfg_horizontal(const struct sr_dev_inst *sdi)
        sr_dbg("Current timebase: %g.", devc->timebase);
        devc->samplerate = devc->memory_depth_analog / (devc->timebase * devc->model->series->num_horizontal_divs);
        sr_dbg("Current samplerate: %0f.", devc->samplerate);
-       sr_dbg("Current memory depth: %lu.", devc->memory_depth_analog);
+       sr_dbg("Current memory depth: %" PRIu64 ".", devc->memory_depth_analog);
 
        return SR_OK;
 }