]> sigrok.org Git - libsigrok.git/commitdiff
hameg-hmo: Change the way vdiv and timebase are saved.
authorpoljar (Damir Jelić) <redacted>
Thu, 16 Jan 2014 14:28:53 +0000 (15:28 +0100)
committerBert Vermeulen <redacted>
Thu, 16 Jan 2014 15:27:35 +0000 (16:27 +0100)
The current vertical division setting (per channel) and the timebase are stored
as a floating point number. This is suboptimal since clients expect us to send
this information to them in form of a rational number.

Store only the index of the current setting since all the supported settings are
already stored inside of an array.

hardware/hameg-hmo/api.c
hardware/hameg-hmo/protocol.c
hardware/hameg-hmo/protocol.h

index 9e1d6e1ff2c88cd26feb300fed864b53d2dd2f8e..33800c7345867024b467d7fbe9a7e2453720af19 100644 (file)
@@ -531,7 +531,7 @@ static int config_set(int key, GVariant *data, const struct sr_dev_inst *sdi,
                        for (j = 1; j <= model->analog_channels; ++j) {
                                if (probe_group != &devc->analog_groups[j - 1])
                                        continue;
-                               state->analog_channels[j - 1].vdiv = (float) p / q;
+                               state->analog_channels[j - 1].vdiv = i;
                                g_ascii_formatd(float_str, sizeof(float_str), "%E", (float) p / q);
                                g_snprintf(command, sizeof(command),
                                           (*model->scpi_dialect)[SCPI_CMD_SET_VERTICAL_DIV],
@@ -555,7 +555,7 @@ static int config_set(int key, GVariant *data, const struct sr_dev_inst *sdi,
                        if (p != (*model->timebases)[i][0] ||
                            q != (*model->timebases)[i][1])
                                continue;
-                       state->timebase = (float) p / q;
+                       state->timebase = i;
                        g_ascii_formatd(float_str, sizeof(float_str), "%E", (float) p / q);
                        g_snprintf(command, sizeof(command),
                                   (*model->scpi_dialect)[SCPI_CMD_SET_TIMEBASE],
index f3de763895e7cbf0c1b39f187b0c15bf5d2391bd..dd24270f0fd1b6ddc9d643954bc383425f8045d5 100644 (file)
@@ -257,12 +257,15 @@ static void scope_state_dump(struct scope_config *config,
                             struct scope_state *state)
 {
        unsigned int i;
+       char *tmp;
 
        for (i = 0; i < config->analog_channels; ++i) {
-               sr_info("State of analog channel %d -> %s : %s %.3eV %.3e offset", i + 1,
-                       state->analog_channels[i].state ? "On" : "Off",
+               tmp = sr_voltage_string((*config->vdivs)[state->analog_channels[i].vdiv][0],
+                                            (*config->vdivs)[state->analog_channels[i].vdiv][1]);
+               sr_info("State of analog channel  %d -> %s : %s (coupling) %s (vdiv) %2.2e (offset)",
+                       i + 1, state->analog_channels[i].state ? "On" : "Off",
                        (*config->coupling_options)[state->analog_channels[i].coupling],
-                       state->analog_channels[i].vdiv, state->analog_channels[i].vertical_offset);
+                       tmp, state->analog_channels[i].vertical_offset);
        }
 
        for (i = 0; i < config->digital_channels; ++i) {
@@ -275,8 +278,12 @@ static void scope_state_dump(struct scope_config *config,
                        state->digital_pods[i] ? "On" : "Off");
        }
 
-       sr_info("Current timebase: %.2es", state->timebase);
-       sr_info("Current trigger: %s (source), %s (slope) %.2e (offset)",
+       tmp = sr_period_string((*config->timebases)[state->timebase][0] *
+                              (*config->timebases)[state->timebase][1]);
+       sr_info("Current timebase: %s", tmp);
+       g_free(tmp);
+
+       sr_info("Current trigger: %s (source), %s (slope) %2.2e (offset)",
                (*config->trigger_sources)[state->trigger_source],
                (*config->trigger_slopes)[state->trigger_slope],
                state->horiz_triggerpos);
@@ -314,7 +321,8 @@ static int analog_channel_state_get(struct sr_scpi_dev_inst *scpi,
                                    struct scope_config *config,
                                    struct scope_state *state)
 {
-       unsigned int i;
+       unsigned int i, j;
+       float tmp_float;
        char command[MAX_COMMAND_SIZE];
 
        for (i = 0; i < config->analog_channels; ++i) {
@@ -330,8 +338,16 @@ static int analog_channel_state_get(struct sr_scpi_dev_inst *scpi,
                           (*config->scpi_dialect)[SCPI_CMD_GET_VERTICAL_DIV],
                           i + 1);
 
-               if (sr_scpi_get_float(scpi, command,
-                                    &state->analog_channels[i].vdiv) != SR_OK)
+               if (sr_scpi_get_float(scpi, command, &tmp_float) != SR_OK)
+                       return SR_ERR;
+               for (j = 0; j < config->num_vdivs; j++) {
+                       if (tmp_float == ((float) (*config->vdivs)[j][0] /
+                                         (*config->vdivs)[j][1])) {
+                               state->analog_channels[i].vdiv = j;
+                               break;
+                       }
+               }
+               if (i == config->num_vdivs)
                        return SR_ERR;
 
                g_snprintf(command, sizeof(command),
@@ -389,21 +405,34 @@ SR_PRIV int hmo_scope_state_get(struct sr_dev_inst *sdi)
        struct dev_context *devc;
        struct scope_state *state;
        struct scope_config *config;
+       float tmp_float;
+       unsigned int i;
 
        devc = sdi->priv;
        config = devc->model_config;
        state = devc->model_state;
 
+       sr_info("Fetching scope state");
+
        if (analog_channel_state_get(sdi->conn, config, state) != SR_OK)
                return SR_ERR;
 
        if (digital_channel_state_get(sdi->conn, config, state) != SR_OK)
                return SR_ERR;
 
-       /* TODO: Check if value is sensible. */
        if (sr_scpi_get_float(sdi->conn,
                        (*config->scpi_dialect)[SCPI_CMD_GET_TIMEBASE],
-                       &state->timebase) != SR_OK)
+                       &tmp_float) != SR_OK)
+               return SR_ERR;
+
+       for (i = 0; i < config->num_timebases; i++) {
+               if (tmp_float == ((float) (*config->timebases)[i][0] /
+                                 (*config->timebases)[i][1])) {
+                       state->timebase = i;
+                       break;
+               }
+       }
+       if (i == config->num_timebases)
                return SR_ERR;
 
        if (sr_scpi_get_float(sdi->conn,
@@ -421,6 +450,8 @@ SR_PRIV int hmo_scope_state_get(struct sr_dev_inst *sdi)
                config->trigger_slopes, &state->trigger_slope) != SR_OK)
                return SR_ERR;
 
+       sr_info("Fetching finished.");
+
        scope_state_dump(config, state);
 
        return SR_OK;
index ffc841283d24f152bd5ed83d2c03788a1f3f4933..18dde31f66b19dd2c746b6bdd13d8e6ee9398a8a 100644 (file)
@@ -69,7 +69,7 @@ struct scope_config {
 struct analog_channel_state {
        int coupling;
 
-       float vdiv;
+       int vdiv;
        float vertical_offset;
 
        gboolean state;
@@ -80,7 +80,7 @@ struct scope_state {
        gboolean *digital_channels;
        gboolean *digital_pods;
 
-       float timebase;
+       int timebase;
        float horiz_triggerpos;
 
        int trigger_source;