From: marchelh Date: Mon, 5 Mar 2018 16:10:56 +0000 (+0100) Subject: siglent-sds: Fixed samplerate and memory depth calculation X-Git-Url: https://sigrok.org/gitweb/?a=commitdiff_plain;h=e5b41b8d7e60cac101fe4a1657da2f54597ff6a1;hp=7e776c70b0bf1522efac7913e6e90aec0ff588f6;p=libsigrok.git siglent-sds: Fixed samplerate and memory depth calculation --- diff --git a/src/hardware/siglent-sds/protocol.c b/src/hardware/siglent-sds/protocol.c index a463710d..251eb5d0 100644 --- a/src/hardware/siglent-sds/protocol.c +++ b/src/hardware/siglent-sds/protocol.c @@ -335,8 +335,7 @@ SR_PRIV int siglent_sds_receive(int fd, int revents, void *cb_data) len = 0; if (devc->num_block_bytes == 0) { - - if (devc->samplerate >= 14000000) { + if (devc->memory_depth >= 14000000) { sr_err("Device memory depth is set to 14Mpts, so please be patient."); g_usleep(4900000); /* Sleep for large memory set. */ } @@ -662,44 +661,39 @@ SR_PRIV int siglent_sds_get_dev_cfg_horizontal(const struct sr_dev_inst *sdi) int res; char *sample_points_string; float samplerate_scope, fvalue; - char *first, *concat; devc = sdi->priv; cmd = g_strdup_printf("SANU? C1"); res = sr_scpi_get_string(sdi->conn, cmd, &sample_points_string); g_free(cmd); + samplerate_scope = 0; + fvalue = 0; if (res != SR_OK) return SR_ERR; - if (g_strstr_len(sample_points_string, -1, "Mpts") != NULL) { - sample_points_string[strlen(sample_points_string) - 4] = '\0'; - if (g_strstr_len(sample_points_string, -1, ".") != NULL) { - first = strtok(sample_points_string, "."); - concat = strcat(first, strtok(NULL, ".")); - if (sr_atof_ascii(concat, &fvalue) != SR_OK || fvalue == 0.0) { - sr_dbg("Invalid float converted from scope response."); - return SR_ERR; - } - } else { - if (sr_atof_ascii(sample_points_string, &fvalue) != SR_OK || fvalue == 0.0) { - sr_dbg("Invalid float converted from scope response."); - 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."); + return SR_ERR; } - samplerate_scope = fvalue * 100000; - } else { - sample_points_string[strlen(sample_points_string) - 4] = '\0'; - if (sr_atof_ascii(sample_points_string, &fvalue) != SR_OK || fvalue == 0.0) { + samplerate_scope = fvalue * 1000000; + } else if (g_strstr_len(sample_points_string, -1, "Kpts") != 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."); return SR_ERR; } - samplerate_scope = fvalue * 1000; + samplerate_scope = fvalue * 10000; + } else { + samplerate_scope = fvalue; } + g_free(sample_points_string); /* Get the timebase. */ if (sr_scpi_get_float(sdi->conn, ":TDIV?", &devc->timebase) != SR_OK) return SR_ERR; sr_dbg("Current timebase: %g.", devc->timebase); devc->samplerate = samplerate_scope / (devc->timebase * devc->model->series->num_horizontal_divs); - + devc->memory_depth = samplerate_scope; return SR_OK; } diff --git a/src/hardware/siglent-sds/protocol.h b/src/hardware/siglent-sds/protocol.h index ea956e59..b0c926ed 100644 --- a/src/hardware/siglent-sds/protocol.h +++ b/src/hardware/siglent-sds/protocol.h @@ -109,6 +109,7 @@ struct dev_context { uint64_t analog_frame_size; uint64_t digital_frame_size; uint64_t num_samples; + uint64_t memory_depth; long block_header_size; float samplerate;