From: Guido Trentalancia Date: Fri, 16 Nov 2018 17:47:55 +0000 (+0100) Subject: hameg-hmo: Add SR_CONF_TRIGGER_PATTERN support. X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=4fa4db2c7983235fff5891127f5f4648a3762172;p=libsigrok.git hameg-hmo: Add SR_CONF_TRIGGER_PATTERN support. Introduce support for the Pattern Trigger functionality, sometimes also called Logic Trigger. --- diff --git a/include/libsigrok/libsigrok.h b/include/libsigrok/libsigrok.h index a60e53bd..ed6fd424 100644 --- a/include/libsigrok/libsigrok.h +++ b/include/libsigrok/libsigrok.h @@ -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, diff --git a/src/hardware/hameg-hmo/api.c b/src/hardware/hameg-hmo/api.c index 0070b615..617c78d9 100644 --- a/src/hardware/hameg-hmo/api.c +++ b/src/hardware/hameg-hmo/api.c @@ -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; diff --git a/src/hardware/hameg-hmo/protocol.c b/src/hardware/hameg-hmo/protocol.c index 933432de..a69b34f6 100644 --- a/src/hardware/hameg-hmo/protocol.c +++ b/src/hardware/hameg-hmo/protocol.c @@ -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; diff --git a/src/hardware/hameg-hmo/protocol.h b/src/hardware/hameg-hmo/protocol.h index da48ce9a..a9f69c68 100644 --- a/src/hardware/hameg-hmo/protocol.h +++ b/src/hardware/hameg-hmo/protocol.h @@ -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; }; diff --git a/src/hwdriver.c b/src/hwdriver.c index d5c92313..27ca060d 100644 --- a/src/hwdriver.c +++ b/src/hwdriver.c @@ -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", diff --git a/src/scpi.h b/src/scpi.h index bd79d784..e551ba6b 100644 --- a/src/scpi.h +++ b/src/scpi.h @@ -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,