]> sigrok.org Git - libsigrok.git/commitdiff
hameg-hmo: Add SR_CONF_TRIGGER_PATTERN support.
authorGuido Trentalancia <redacted>
Fri, 16 Nov 2018 17:47:55 +0000 (18:47 +0100)
committerUwe Hermann <redacted>
Thu, 25 Jul 2019 22:11:07 +0000 (00:11 +0200)
Introduce support for the Pattern Trigger functionality, sometimes also
called Logic Trigger.

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 a60e53bd17f995f7059a291919645feaaa7f9881..ed6fd42471f4029fa7c8a43b101e31f7d2bf29ed 100644 (file)
@@ -770,6 +770,9 @@ enum sr_configkey {
        /** The device supports setting trigger slope. */
        SR_CONF_TRIGGER_SLOPE,
 
+       /** The device supports setting a pattern for the logic trigger. */
+       SR_CONF_TRIGGER_PATTERN,
+
        /** The device supports averaging. */
        SR_CONF_AVERAGING,
 
index 0070b61569800e3132bbc8ae4e816eb1dac13696..617c78d96838c0434ff0ce479912aec9790be0c0 100644 (file)
@@ -200,6 +200,9 @@ static int config_get(uint32_t key, GVariant **data,
        case SR_CONF_TRIGGER_SLOPE:
                *data = g_variant_new_string((*model->trigger_slopes)[state->trigger_slope]);
                break;
+       case SR_CONF_TRIGGER_PATTERN:
+               *data = g_variant_new_string(state->trigger_pattern);
+               break;
        case SR_CONF_HORIZ_TRIGGERPOS:
                *data = g_variant_new_double(state->horiz_triggerpos);
                break;
@@ -250,7 +253,7 @@ static int config_set(uint32_t key, GVariant *data,
        const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
 {
        int ret, cg_type, idx, j;
-       char command[MAX_COMMAND_SIZE], float_str[30];
+       char command[MAX_COMMAND_SIZE], float_str[30], *tmp_str;
        struct dev_context *devc;
        const struct scope_config *model;
        struct scope_state *state;
@@ -341,6 +344,21 @@ static int config_set(uint32_t key, GVariant *data,
                           (*model->trigger_slopes)[idx]);
                ret = sr_scpi_send(sdi->conn, command);
                break;
+       case SR_CONF_TRIGGER_PATTERN:
+               tmp_str = (char *)g_variant_get_string(data, 0);
+               idx = strlen(tmp_str);
+               if (idx == 0 || idx > model->analog_channels + model->digital_channels)
+                       return SR_ERR_ARG;
+               g_snprintf(command, sizeof(command),
+                          (*model->scpi_dialect)[SCPI_CMD_SET_TRIGGER_PATTERN],
+                          tmp_str);
+               if (sr_scpi_send(sdi->conn, command) != SR_OK ||
+                   sr_scpi_get_opc(sdi->conn) != SR_OK)
+                       return SR_ERR;
+               g_free(state->trigger_pattern);
+               state->trigger_pattern = g_strdup(tmp_str);
+               ret = SR_OK;
+               break;
        case SR_CONF_COUPLING:
                if (!cg)
                        return SR_ERR_CHANNEL_GROUP;
index 933432de2c0d58170ec868a43e9f8831623fe2cb..a69b34f65b455a5b2ac906824b6760b6805e5131 100644 (file)
@@ -46,6 +46,12 @@ static const char *hameg_scpi_dialect[] = {
        [SCPI_CMD_SET_DIG_POD_STATE]          = ":POD%d:STAT %d",
        [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?",
+       [SCPI_CMD_SET_TRIGGER_PATTERN]        = ":TRIG:A:TYPE LOGIC;" \
+                                               ":TRIG:A:PATT:FUNC AND;" \
+                                               ":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_DIG_CHAN_STATE]         = ":LOG%d:STAT?",
@@ -72,6 +78,7 @@ static const uint32_t devopts[] = {
        SR_CONF_HORIZ_TRIGGERPOS | SR_CONF_GET | SR_CONF_SET,
        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,
 };
 
 static const uint32_t devopts_cg_analog[] = {
@@ -415,10 +422,15 @@ static void scope_state_dump(const struct scope_config *config,
        sr_info("Current samplerate: %s", tmp);
        g_free(tmp);
 
-       sr_info("Current trigger: %s (source), %s (slope) %.2f (offset)",
-               (*config->trigger_sources)[state->trigger_source],
-               (*config->trigger_slopes)[state->trigger_slope],
-               state->horiz_triggerpos);
+       if (!strcmp("PATT", (*config->trigger_sources)[state->trigger_source]))
+               sr_info("Current trigger: %s (pattern), %.2f (offset)",
+                       state->trigger_pattern,
+                       state->horiz_triggerpos);
+       else // Edge (slope) trigger
+               sr_info("Current trigger: %s (source), %s (slope) %.2f (offset)",
+                       (*config->trigger_sources)[state->trigger_source],
+                       (*config->trigger_slopes)[state->trigger_slope],
+                       state->horiz_triggerpos);
 }
 
 static int scope_state_get_array_option(struct sr_scpi_dev_inst *scpi,
@@ -773,6 +785,11 @@ SR_PRIV int hmo_scope_state_get(struct sr_dev_inst *sdi)
                        &state->trigger_slope) != SR_OK)
                return SR_ERR;
 
+       if (sr_scpi_get_string(sdi->conn,
+                              (*config->scpi_dialect)[SCPI_CMD_GET_TRIGGER_PATTERN],
+                              &state->trigger_pattern) != SR_OK)
+               return SR_ERR;
+
        if (hmo_update_sample_rate(sdi) != SR_OK)
                return SR_ERR;
 
index da48ce9a65ee484198a051823282dfadf474ee49..a9f69c682eb1ee6591ad1045b3e4bf25aa76b45a 100644 (file)
@@ -29,7 +29,7 @@
 #define LOG_PREFIX "hameg-hmo"
 
 #define MAX_INSTRUMENT_VERSIONS 10
-#define MAX_COMMAND_SIZE 48
+#define MAX_COMMAND_SIZE 128
 #define MAX_ANALOG_CHANNEL_COUNT 4
 #define MAX_DIGITAL_CHANNEL_COUNT 16
 #define MAX_DIGITAL_GROUP_COUNT        2
@@ -103,6 +103,8 @@ struct scope_state {
 
        int trigger_source;
        int trigger_slope;
+       char *trigger_pattern;
+
        uint64_t sample_rate;
 };
 
index d5c92313b9901cf8be578ab433b792ffc79d63bb..27ca060d9d8f2c0f91e450888f807c309f6ebb23 100644 (file)
@@ -83,6 +83,8 @@ static struct sr_key_info sr_key_info_config[] = {
                "Run length encoding", 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_AVERAGING, SR_T_BOOL, "averaging",
                "Averaging", NULL},
        {SR_CONF_AVG_SAMPLES, SR_T_UINT64, "avg_samples",
index bd79d7840d190382506c0897c01cea3d30c16010..e551ba6b5aad17e1d70dfd9ea777674533c2f120 100644 (file)
@@ -39,6 +39,8 @@ enum {
        SCPI_CMD_SET_VERTICAL_DIV,
        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_COUPLING,