]> sigrok.org Git - libsigrok.git/commitdiff
hameg-hmo: Add SR_CONF_HIGH_RESOLUTION and SR_CONF_PEAK_DETECTION.
authorGuido Trentalancia <redacted>
Wed, 21 Nov 2018 13:48:56 +0000 (14:48 +0100)
committerUwe Hermann <redacted>
Thu, 25 Jul 2019 23:43:19 +0000 (01:43 +0200)
Implement High Resolution mode and Peak Detection settings.

Beautify the code by reordering the Trigger Source settings
definitions.

include/libsigrok/libsigrok.h
src/hardware/hameg-hmo/api.c
src/hardware/hameg-hmo/protocol.c
src/hardware/hameg-hmo/protocol.h
src/hwdriver.c
src/scpi.h

index ed6fd42471f4029fa7c8a43b101e31f7d2bf29ed..63dc483be20d528e19c9cc86037469e23c73c128 100644 (file)
@@ -767,12 +767,21 @@ enum sr_configkey {
        /** The device supports run-length encoding (RLE). */
        SR_CONF_RLE,
 
+       /** Trigger source. */
+       SR_CONF_TRIGGER_SOURCE,
+
        /** The device supports setting trigger slope. */
        SR_CONF_TRIGGER_SLOPE,
 
        /** The device supports setting a pattern for the logic trigger. */
        SR_CONF_TRIGGER_PATTERN,
 
+       /** High resolution mode. */
+       SR_CONF_HIGH_RESOLUTION,
+
+       /** Peak detection. */
+       SR_CONF_PEAK_DETECTION,
+
        /** The device supports averaging. */
        SR_CONF_AVERAGING,
 
@@ -782,9 +791,6 @@ enum sr_configkey {
         */
        SR_CONF_AVG_SAMPLES,
 
-       /** Trigger source. */
-       SR_CONF_TRIGGER_SOURCE,
-
        /** Horizontal trigger position. */
        SR_CONF_HORIZ_TRIGGERPOS,
 
index e5808fb362735ce9a20ceeb92afdc56e2c183cc6..bbbaaaa716f11234ae8f3fa901e705902c70290f 100644 (file)
@@ -204,6 +204,12 @@ static int config_get(uint32_t key, GVariant **data,
        case SR_CONF_TRIGGER_PATTERN:
                *data = g_variant_new_string(state->trigger_pattern);
                break;
+       case SR_CONF_HIGH_RESOLUTION:
+               *data = g_variant_new_boolean(state->high_resolution);
+               break;
+       case SR_CONF_PEAK_DETECTION:
+               *data = g_variant_new_boolean(state->peak_detection);
+               break;
        case SR_CONF_HORIZ_TRIGGERPOS:
                *data = g_variant_new_double(state->horiz_triggerpos);
                break;
@@ -270,7 +276,7 @@ static int config_set(uint32_t key, GVariant *data,
        const struct scope_config *model;
        struct scope_state *state;
        double tmp_d, tmp_d2;
-       gboolean update_sample_rate;
+       gboolean update_sample_rate, tmp_bool;
 
        if (!sdi)
                return SR_ERR_ARG;
@@ -293,18 +299,6 @@ static int config_set(uint32_t key, GVariant *data,
                devc->frame_limit = g_variant_get_uint64(data);
                ret = SR_OK;
                break;
-       case SR_CONF_TRIGGER_SOURCE:
-               if ((idx = std_str_idx(data, *model->trigger_sources, model->num_trigger_sources)) < 0)
-                       return SR_ERR_ARG;
-               g_snprintf(command, sizeof(command),
-                          (*model->scpi_dialect)[SCPI_CMD_SET_TRIGGER_SOURCE],
-                          (*model->trigger_sources)[idx]);
-               if (sr_scpi_send(sdi->conn, command) != SR_OK ||
-                   sr_scpi_get_opc(sdi->conn) != SR_OK)
-                       return SR_ERR;
-               state->trigger_source = idx;
-               ret = SR_OK;
-               break;
        case SR_CONF_VDIV:
                if (!cg)
                        return SR_ERR_CHANNEL_GROUP;
@@ -356,6 +350,18 @@ static int config_set(uint32_t key, GVariant *data,
                state->horiz_triggerpos = tmp_d;
                ret = SR_OK;
                break;
+       case SR_CONF_TRIGGER_SOURCE:
+               if ((idx = std_str_idx(data, *model->trigger_sources, model->num_trigger_sources)) < 0)
+                       return SR_ERR_ARG;
+               g_snprintf(command, sizeof(command),
+                          (*model->scpi_dialect)[SCPI_CMD_SET_TRIGGER_SOURCE],
+                          (*model->trigger_sources)[idx]);
+               if (sr_scpi_send(sdi->conn, command) != SR_OK ||
+                   sr_scpi_get_opc(sdi->conn) != SR_OK)
+                       return SR_ERR;
+               state->trigger_source = idx;
+               ret = SR_OK;
+               break;
        case SR_CONF_TRIGGER_SLOPE:
                if ((idx = std_str_idx(data, *model->trigger_slopes, model->num_trigger_slopes)) < 0)
                        return SR_ERR_ARG;
@@ -384,6 +390,48 @@ static int config_set(uint32_t key, GVariant *data,
                        MAX_ANALOG_CHANNEL_COUNT + MAX_DIGITAL_CHANNEL_COUNT);
                ret = SR_OK;
                break;
+       case SR_CONF_HIGH_RESOLUTION:
+               tmp_bool = g_variant_get_boolean(data);
+               g_snprintf(command, sizeof(command),
+                          (*model->scpi_dialect)[SCPI_CMD_SET_HIGH_RESOLUTION],
+                          tmp_bool ? "AUTO" : "OFF");
+               if (sr_scpi_send(sdi->conn, command) != SR_OK ||
+                   sr_scpi_get_opc(sdi->conn) != SR_OK)
+                       return SR_ERR;
+               /* High Resolution mode automatically switches off Peak Detection. */
+               if (tmp_bool) {
+                       g_snprintf(command, sizeof(command),
+                                  (*model->scpi_dialect)[SCPI_CMD_SET_PEAK_DETECTION],
+                                  "OFF");
+                       if (sr_scpi_send(sdi->conn, command) != SR_OK ||
+                                        sr_scpi_get_opc(sdi->conn) != SR_OK)
+                               return SR_ERR;
+                       state->peak_detection = FALSE;
+               }
+               state->high_resolution = tmp_bool;
+               ret = SR_OK;
+               break;
+       case SR_CONF_PEAK_DETECTION:
+               tmp_bool = g_variant_get_boolean(data);
+               g_snprintf(command, sizeof(command),
+                          (*model->scpi_dialect)[SCPI_CMD_SET_PEAK_DETECTION],
+                          tmp_bool ? "AUTO" : "OFF");
+               if (sr_scpi_send(sdi->conn, command) != SR_OK ||
+                   sr_scpi_get_opc(sdi->conn) != SR_OK)
+                       return SR_ERR;
+               /* Peak Detection automatically switches off High Resolution mode. */
+               if (tmp_bool) {
+                       g_snprintf(command, sizeof(command),
+                                  (*model->scpi_dialect)[SCPI_CMD_SET_HIGH_RESOLUTION],
+                                  "OFF");
+                       if (sr_scpi_send(sdi->conn, command) != SR_OK ||
+                                        sr_scpi_get_opc(sdi->conn) != SR_OK)
+                               return SR_ERR;
+                       state->high_resolution = FALSE;
+               }
+               state->peak_detection = tmp_bool;
+               ret = SR_OK;
+               break;
        case SR_CONF_COUPLING:
                if (!cg)
                        return SR_ERR_CHANNEL_GROUP;
index 167c1a4fe5e9960d4f1a0df91e76c20ef9209857..b0875eb588e2bae2928608aeee6a0af08c38e7c7 100644 (file)
@@ -44,6 +44,8 @@ static const char *hameg_scpi_dialect[] = {
        [SCPI_CMD_SET_VERTICAL_SCALE]         = ":CHAN%d:SCAL %s",
        [SCPI_CMD_GET_DIG_POD_STATE]          = ":POD%d:STAT?",
        [SCPI_CMD_SET_DIG_POD_STATE]          = ":POD%d:STAT %d",
+       [SCPI_CMD_GET_TRIGGER_SOURCE]         = ":TRIG:A:SOUR?",
+       [SCPI_CMD_SET_TRIGGER_SOURCE]         = ":TRIG:A:SOUR %s",
        [SCPI_CMD_GET_TRIGGER_SLOPE]          = ":TRIG:A:EDGE:SLOP?",
        [SCPI_CMD_SET_TRIGGER_SLOPE]          = ":TRIG:A:TYPE EDGE;:TRIG:A:EDGE:SLOP %s",
        [SCPI_CMD_GET_TRIGGER_PATTERN]        = ":TRIG:A:PATT:SOUR?",
@@ -52,8 +54,10 @@ static const char *hameg_scpi_dialect[] = {
                                                ":TRIG:A:PATT:COND \"TRUE\";" \
                                                ":TRIG:A:PATT:MODE OFF;" \
                                                ":TRIG:A:PATT:SOUR \"%s\"",
-       [SCPI_CMD_GET_TRIGGER_SOURCE]         = ":TRIG:A:SOUR?",
-       [SCPI_CMD_SET_TRIGGER_SOURCE]         = ":TRIG:A:SOUR %s",
+       [SCPI_CMD_GET_HIGH_RESOLUTION]        = ":ACQ:HRES?",
+       [SCPI_CMD_SET_HIGH_RESOLUTION]        = ":ACQ:HRES %s",
+       [SCPI_CMD_GET_PEAK_DETECTION]         = ":ACQ:PEAK?",
+       [SCPI_CMD_SET_PEAK_DETECTION]         = ":ACQ:PEAK %s",
        [SCPI_CMD_GET_DIG_CHAN_STATE]         = ":LOG%d:STAT?",
        [SCPI_CMD_SET_DIG_CHAN_STATE]         = ":LOG%d:STAT %d",
        [SCPI_CMD_GET_VERTICAL_OFFSET]        = ":CHAN%d:POS?",
@@ -82,6 +86,8 @@ static const char *rohde_schwarz_log_not_pod_scpi_dialect[] = {
        [SCPI_CMD_SET_VERTICAL_SCALE]         = ":CHAN%d:SCAL %s",
        [SCPI_CMD_GET_DIG_POD_STATE]          = ":LOG%d:STAT?",
        [SCPI_CMD_SET_DIG_POD_STATE]          = ":LOG%d:STAT %d",
+       [SCPI_CMD_GET_TRIGGER_SOURCE]         = ":TRIG:A:SOUR?",
+       [SCPI_CMD_SET_TRIGGER_SOURCE]         = ":TRIG:A:SOUR %s",
        [SCPI_CMD_GET_TRIGGER_SLOPE]          = ":TRIG:A:EDGE:SLOP?",
        [SCPI_CMD_SET_TRIGGER_SLOPE]          = ":TRIG:A:TYPE EDGE;:TRIG:A:EDGE:SLOP %s",
        [SCPI_CMD_GET_TRIGGER_PATTERN]        = ":TRIG:A:PATT:SOUR?",
@@ -90,8 +96,10 @@ static const char *rohde_schwarz_log_not_pod_scpi_dialect[] = {
                                                ":TRIG:A:PATT:COND \"TRUE\";" \
                                                ":TRIG:A:PATT:MODE OFF;" \
                                                ":TRIG:A:PATT:SOUR \"%s\"",
-       [SCPI_CMD_GET_TRIGGER_SOURCE]         = ":TRIG:A:SOUR?",
-       [SCPI_CMD_SET_TRIGGER_SOURCE]         = ":TRIG:A:SOUR %s",
+       [SCPI_CMD_GET_HIGH_RESOLUTION]        = ":ACQ:HRES?",
+       [SCPI_CMD_SET_HIGH_RESOLUTION]        = ":ACQ:HRES %s",
+       [SCPI_CMD_GET_PEAK_DETECTION]         = ":ACQ:PEAK?",
+       [SCPI_CMD_SET_PEAK_DETECTION]         = ":ACQ:PEAK %s",
        [SCPI_CMD_GET_DIG_CHAN_STATE]         = ":LOG%d:STAT?",
        [SCPI_CMD_SET_DIG_CHAN_STATE]         = ":LOG%d:STAT %d",
        [SCPI_CMD_GET_VERTICAL_OFFSET]        = ":CHAN%d:POS?", /* Might not be supported on RTB200x... */
@@ -117,6 +125,8 @@ static const uint32_t devopts[] = {
        SR_CONF_TRIGGER_SOURCE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
        SR_CONF_TRIGGER_SLOPE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
        SR_CONF_TRIGGER_PATTERN | SR_CONF_GET | SR_CONF_SET,
+       SR_CONF_HIGH_RESOLUTION | SR_CONF_GET | SR_CONF_SET,
+       SR_CONF_PEAK_DETECTION | SR_CONF_GET | SR_CONF_SET,
 };
 
 static const uint32_t devopts_cg_analog[] = {
@@ -1120,6 +1130,26 @@ SR_PRIV int hmo_scope_state_get(struct sr_dev_inst *sdi)
                MAX_ANALOG_CHANNEL_COUNT + MAX_DIGITAL_CHANNEL_COUNT);
        g_free(tmp_str);
 
+       if (sr_scpi_get_string(sdi->conn,
+                            (*config->scpi_dialect)[SCPI_CMD_GET_HIGH_RESOLUTION],
+                            &tmp_str) != SR_OK)
+               return SR_ERR;
+       if (!strcmp("OFF", tmp_str))
+               state->high_resolution = FALSE;
+       else
+               state->high_resolution = TRUE;
+       g_free(tmp_str);
+
+       if (sr_scpi_get_string(sdi->conn,
+                            (*config->scpi_dialect)[SCPI_CMD_GET_PEAK_DETECTION],
+                            &tmp_str) != SR_OK)
+               return SR_ERR;
+       if (!strcmp("OFF", tmp_str))
+               state->peak_detection = FALSE;
+       else
+               state->peak_detection = TRUE;
+       g_free(tmp_str);
+
        if (hmo_update_sample_rate(sdi) != SR_OK)
                return SR_ERR;
 
index 975ea7e342e311b3c3234e03f29323d5bc997b1a..2749fb8e7e0c27565d4898dd0ceea2d2984c39b3 100644 (file)
@@ -108,6 +108,9 @@ struct scope_state {
        int trigger_slope;
        char trigger_pattern[MAX_ANALOG_CHANNEL_COUNT + MAX_DIGITAL_CHANNEL_COUNT];
 
+       gboolean high_resolution;
+       gboolean peak_detection;
+
        uint64_t sample_rate;
 };
 
index 27ca060d9d8f2c0f91e450888f807c309f6ebb23..342abeb9ef780f4d7b3040de8555dc03cc5a1478 100644 (file)
@@ -81,16 +81,20 @@ static struct sr_key_info sr_key_info_config[] = {
                "Pattern", NULL},
        {SR_CONF_RLE, SR_T_BOOL, "rle",
                "Run length encoding", NULL},
+       {SR_CONF_TRIGGER_SOURCE, SR_T_STRING, "triggersource",
+               "Trigger source", NULL},
        {SR_CONF_TRIGGER_SLOPE, SR_T_STRING, "triggerslope",
                "Trigger slope", NULL},
        {SR_CONF_TRIGGER_PATTERN, SR_T_STRING, "triggerpattern",
                "Trigger pattern", NULL},
+       {SR_CONF_HIGH_RESOLUTION, SR_T_BOOL, "highresolution",
+               "High resolution", NULL},
+       {SR_CONF_PEAK_DETECTION, SR_T_BOOL, "peakdetection",
+               "Peak detection", NULL},
        {SR_CONF_AVERAGING, SR_T_BOOL, "averaging",
                "Averaging", NULL},
        {SR_CONF_AVG_SAMPLES, SR_T_UINT64, "avg_samples",
                "Number of samples to average over", NULL},
-       {SR_CONF_TRIGGER_SOURCE, SR_T_STRING, "triggersource",
-               "Trigger source", NULL},
        {SR_CONF_HORIZ_TRIGGERPOS, SR_T_FLOAT, "horiz_triggerpos",
                "Horizontal trigger position", NULL},
        {SR_CONF_BUFFERSIZE, SR_T_UINT64, "buffersize",
index 7d9a39bb75d8cd91e8891cfe53931fb024f2407c..e8bb33f49583c0248f91c36976feb233a9a9aa95 100644 (file)
@@ -38,12 +38,16 @@ enum {
        SCPI_CMD_GET_HORIZONTAL_DIV,
        SCPI_CMD_GET_VERTICAL_SCALE,
        SCPI_CMD_SET_VERTICAL_SCALE,
+       SCPI_CMD_GET_TRIGGER_SOURCE,
+       SCPI_CMD_SET_TRIGGER_SOURCE,
        SCPI_CMD_GET_TRIGGER_SLOPE,
        SCPI_CMD_SET_TRIGGER_SLOPE,
        SCPI_CMD_GET_TRIGGER_PATTERN,
        SCPI_CMD_SET_TRIGGER_PATTERN,
-       SCPI_CMD_GET_TRIGGER_SOURCE,
-       SCPI_CMD_SET_TRIGGER_SOURCE,
+       SCPI_CMD_GET_HIGH_RESOLUTION,
+       SCPI_CMD_SET_HIGH_RESOLUTION,
+       SCPI_CMD_GET_PEAK_DETECTION,
+       SCPI_CMD_SET_PEAK_DETECTION,
        SCPI_CMD_GET_COUPLING,
        SCPI_CMD_SET_COUPLING,
        SCPI_CMD_GET_HORIZ_TRIGGERPOS,