]> sigrok.org Git - libsigrok.git/commitdiff
rigol-dg: Reduce unnecessary conversions between waveform and string repr
authorRalf <redacted>
Fri, 23 Oct 2020 14:57:31 +0000 (16:57 +0200)
committerSoeren Apel <redacted>
Sat, 28 Sep 2024 22:00:02 +0000 (00:00 +0200)
src/hardware/rigol-dg/api.c
src/hardware/rigol-dg/protocol.c
src/hardware/rigol-dg/protocol.h

index 537d6188437af4c25d3c0066186457277d08ff88..f57246fc5ee5d0764c2c060f5dcceb5c758a800c 100644 (file)
@@ -583,9 +583,7 @@ static int config_get(uint32_t key, GVariant **data,
                case SR_CONF_PATTERN_MODE:
                        if ((ret = rigol_dg_get_channel_state(sdi, cg)) == SR_OK) {
                                *data = g_variant_new_string(
-                                        rigol_dg_waveform_to_string(
-                                                &devc->device->channels[ch->index],
-                                                ch_status->wf));
+                                       ch_status->wf_spec->user_name);
                        }
                        break;
                case SR_CONF_OUTPUT_FREQUENCY:
@@ -642,7 +640,7 @@ static int config_set(uint32_t key, GVariant *data,
        const struct sr_key_info *kinfo;
        int ret;
        uint32_t cmd;
-       const char *mode, *mode_name, *new_mode;
+       const char *mode, *new_mode;
        unsigned int i;
 
        if (!data || !sdi)
@@ -689,12 +687,11 @@ static int config_set(uint32_t key, GVariant *data,
                        new_mode = NULL;
                        mode = g_variant_get_string(data, NULL);
                        for (i = 0; i < ch_spec->num_waveforms; i++) {
-                               mode_name = rigol_dg_waveform_to_string(
-                                               &devc->device->channels[ch->index],
-                                               ch_spec->waveforms[i].waveform);
-                               if (g_ascii_strncasecmp(mode, mode_name,
-                                               strlen(mode_name)) == 0)
+                               if (g_ascii_strcasecmp(mode,
+                                               ch_spec->waveforms[i].user_name) == 0) {
                                        new_mode = ch_spec->waveforms[i].scpi_name;
+                                       break;
+                               }
                        }
                        if (new_mode)
                                ret = sr_scpi_cmd(sdi, devc->cmdset,
@@ -806,9 +803,7 @@ static int config_list(uint32_t key, GVariant **data,
                        b = g_variant_builder_new(G_VARIANT_TYPE("as"));
                        for (i = 0; i < ch_spec->num_waveforms; i++) {
                                g_variant_builder_add(b, "s",
-                                       rigol_dg_waveform_to_string(
-                                               &devc->device->channels[ch->index],
-                                               ch_spec->waveforms[i].waveform));
+                                       ch_spec->waveforms[i].user_name);
                        }
                        *data = g_variant_new("as", b);
                        g_variant_builder_unref(b);
index 0b26bc599d5ddd2a0d80af5a1baa61e30ec9404d..5e19b57dc618596acd24f1509f5b5e9df412c3b7 100644 (file)
 #include "scpi.h"
 #include "protocol.h"
 
-SR_PRIV const char *rigol_dg_waveform_to_string(const struct channel_spec *ch,
-               enum waveform_type type)
-{
-       unsigned int i;
-
-       for (i = 0; i < ch->num_waveforms; i++) {
-               if (ch->waveforms[i].waveform == type) {
-                       return ch->waveforms[i].user_name;
-               }
-       }
-
-       return "Unknown";
-}
-
 SR_PRIV int rigol_dg_string_to_waveform(
                const struct channel_spec *ch, const char *s, enum waveform_type *wf)
 {
index 3e48e751e94a42be2165800b7e0cb88ceb55b8fe..b4e25ae5d853c6bd10cc60040e209fa1373d662a 100644 (file)
@@ -133,8 +133,6 @@ struct dev_context {
        uint32_t quirks;
 };
 
-SR_PRIV const char *rigol_dg_waveform_to_string(const struct channel_spec *ch,
-               enum waveform_type type);
 SR_PRIV int rigol_dg_string_to_waveform(
                const struct channel_spec *ch, const char *s, enum waveform_type *wf);
 SR_PRIV const struct waveform_spec *rigol_dg_get_waveform_spec(