]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/hameg-hmo/protocol.c
hameg-hmo: Fix the upper limit for the vertical scale.
[libsigrok.git] / src / hardware / hameg-hmo / protocol.c
index b85b51d316bec75c401f46a9daf9663f82bb40ed..f787dcc0cf0982c2e2fa457e004ddcfd22777222 100644 (file)
@@ -37,7 +37,6 @@ static const char *hameg_scpi_dialect[] = {
        [SCPI_CMD_GET_COUPLING]               = ":CHAN%d:COUP?",
        [SCPI_CMD_SET_COUPLING]               = ":CHAN%d:COUP %s",
        [SCPI_CMD_GET_SAMPLE_RATE]            = ":ACQ:SRAT?",
-       [SCPI_CMD_GET_SAMPLE_RATE_LIVE]       = ":%s:DATA:POINTS?",
        [SCPI_CMD_GET_ANALOG_DATA]            = ":FORM:BORD %s;" \
                                                ":FORM REAL,32;:CHAN%d:DATA?",
        [SCPI_CMD_GET_VERTICAL_DIV]           = ":CHAN%d:SCAL?",
@@ -45,7 +44,13 @@ static const char *hameg_scpi_dialect[] = {
        [SCPI_CMD_GET_DIG_POD_STATE]          = ":POD%d:STAT?",
        [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:EDGE:SLOP %s",
+       [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?",
@@ -64,14 +69,15 @@ static const char *hameg_scpi_dialect[] = {
 
 static const uint32_t devopts[] = {
        SR_CONF_OSCILLOSCOPE,
-       SR_CONF_LIMIT_SAMPLES | SR_CONF_GET | SR_CONF_SET,
-       SR_CONF_LIMIT_FRAMES | SR_CONF_GET | SR_CONF_SET,
+       SR_CONF_LIMIT_SAMPLES | SR_CONF_SET,
+       SR_CONF_LIMIT_FRAMES | SR_CONF_SET,
        SR_CONF_SAMPLERATE | SR_CONF_GET,
        SR_CONF_TIMEBASE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
        SR_CONF_NUM_HDIV | SR_CONF_GET,
        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[] = {
@@ -108,14 +114,14 @@ static const char *logic_threshold[] = {
        "USER2", // overwritten by logic_threshold_custom, use USER1 for permanent setting
 };
 
-/* RTC1002 and HMO compact2 */
+/* RTC1002, HMO Compact2 and HMO1002/HMO1202 */
 static const char *an2_dig8_trigger_sources[] = {
        "CH1", "CH2",
        "LINE", "EXT", "PATT", "BUS1", "BUS2",
        "D0", "D1", "D2", "D3", "D4", "D5", "D6", "D7",
 };
 
-/* HMO xxx2 */
+/* HMO3xx2 */
 static const char *an2_dig16_trigger_sources[] = {
        "CH1", "CH2",
        "LINE", "EXT", "PATT", "BUS1", "BUS2",
@@ -123,14 +129,14 @@ static const char *an2_dig16_trigger_sources[] = {
        "D8", "D9", "D10", "D11", "D12", "D13", "D14", "D15",
 };
 
-/* HMO compact4 */
+/* HMO Compact4 */
 static const char *an4_dig8_trigger_sources[] = {
        "CH1", "CH2", "CH3", "CH4",
        "LINE", "EXT", "PATT", "BUS1", "BUS2",
        "D0", "D1", "D2", "D3", "D4", "D5", "D6", "D7",
 };
 
-/* HMO xxx4 */
+/* HMO3xx4 and HMO2524 */
 static const char *an4_dig16_trigger_sources[] = {
        "CH1", "CH2", "CH3", "CH4",
        "LINE", "EXT", "PATT", "BUS1", "BUS2",
@@ -193,8 +199,6 @@ static const uint64_t vdivs[][2] = {
        { 2, 1 },
        { 5, 1 },
        { 10, 1 },
-       { 20, 1 },
-       { 50, 1 },
 };
 
 static const char *scope_analog_channel_names[] = {
@@ -208,8 +212,8 @@ static const char *scope_digital_channel_names[] = {
 
 static const struct scope_config scope_models[] = {
        {
-               /* RTC1002 and HMO722/1002/1022/1522/2022 support only 8 digital channels. */
-               .name = {"RTC1002", "HMO722", "HMO1002", "HMO1022", "HMO1522", "HMO2022", NULL},
+               /* RTC1002 and HMO722/1002/1022/1202/1522/2022 support only 8 digital channels. */
+               .name = {"RTC1002", "HMO722", "HMO1002", "HMO1022", "HMO1202", "HMO1522", "HMO2022", NULL},
                .analog_channels = 2,
                .digital_channels = 8,
                .digital_pods = 1,
@@ -397,11 +401,11 @@ static void scope_state_dump(const struct scope_config *config,
 
        for (i = 0; i < config->digital_pods; i++) {
                if (strncmp("USER", (*config->logic_threshold)[state->digital_pods[i].threshold], 4))
-                       sr_info("State of digital POD %d -> %s : %s (threshold)", i,
+                       sr_info("State of digital POD %d -> %s : %s (threshold)", i + 1,
                                state->digital_pods[i].state ? "On" : "Off",
                                (*config->logic_threshold)[state->digital_pods[i].threshold]);
                else // user-defined or custom logic threshold
-                       sr_info("State of digital POD %d -> %s : %E (threshold)", i,
+                       sr_info("State of digital POD %d -> %s : %E (threshold)", i + 1,
                                state->digital_pods[i].state ? "On" : "Off",
                                state->digital_pods[i].user_threshold);
        }
@@ -415,10 +419,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,
@@ -427,10 +436,8 @@ static int scope_state_get_array_option(struct sr_scpi_dev_inst *scpi,
        char *tmp;
        int idx;
 
-       if (sr_scpi_get_string(scpi, command, &tmp) != SR_OK) {
-               g_free(tmp);
+       if (sr_scpi_get_string(scpi, command, &tmp) != SR_OK)
                return SR_ERR;
-       }
 
        if ((idx = std_str_idx_s(tmp, *array, n)) < 0) {
                g_free(tmp);
@@ -655,58 +662,18 @@ SR_PRIV int hmo_update_sample_rate(const struct sr_dev_inst *sdi)
        struct dev_context *devc;
        struct scope_state *state;
        const struct scope_config *config;
-       int tmp;
-       unsigned int i;
        float tmp_float;
-       gboolean channel_found;
-       char tmp_str[MAX_COMMAND_SIZE];
-       char chan_name[20];
 
        devc = sdi->priv;
        config = devc->model_config;
        state = devc->model_state;
-       channel_found = FALSE;
-
-       for (i = 0; i < config->analog_channels; i++) {
-               if (!state->analog_channels[i].state)
-                       continue;
-               g_snprintf(chan_name, sizeof(chan_name), "CHAN%d", i + 1);
-               g_snprintf(tmp_str, sizeof(tmp_str),
-                          (*config->scpi_dialect)[SCPI_CMD_GET_SAMPLE_RATE_LIVE],
-                          chan_name);
-               channel_found = TRUE;
-               break;
-       }
-
-       if (!channel_found) {
-               for (i = 0; i < config->digital_pods; i++) {
-                       if (!state->digital_pods[i].state)
-                               continue;
-                       g_snprintf(chan_name, sizeof(chan_name), "POD%d", i);
-                       g_snprintf(tmp_str, sizeof(tmp_str),
-                                  (*config->scpi_dialect)[SCPI_CMD_GET_SAMPLE_RATE_LIVE],
-                                  chan_name);
-                       channel_found = TRUE;
-                       break;
-               }
-       }
 
-       /* No channel is active, ask the instrument for the sample rate
-        * in single shot mode */
-       if (!channel_found) {
-               if (sr_scpi_get_float(sdi->conn,
-                                     (*config->scpi_dialect)[SCPI_CMD_GET_SAMPLE_RATE],
-                                     &tmp_float) != SR_OK)
-                       return SR_ERR;
+       if (sr_scpi_get_float(sdi->conn,
+                             (*config->scpi_dialect)[SCPI_CMD_GET_SAMPLE_RATE],
+                             &tmp_float) != SR_OK)
+               return SR_ERR;
 
-               state->sample_rate = tmp_float;
-       } else {
-               if (sr_scpi_get_int(sdi->conn, tmp_str, &tmp) != SR_OK)
-                       return SR_ERR;
-               state->sample_rate = tmp / (((float) (*config->timebases)[state->timebase][0] /
-                                            (*config->timebases)[state->timebase][1]) *
-                                           config->num_xdivs);
-       }
+       state->sample_rate = tmp_float;
 
        return SR_OK;
 }
@@ -773,6 +740,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;
 
@@ -867,7 +839,7 @@ SR_PRIV int hmo_init_device(struct sr_dev_inst *sdi)
                        ret = SR_ERR_MALLOC;
                        break;
                }
-               devc->digital_groups[i]->name = g_strdup_printf("POD%d", i);
+               devc->digital_groups[i]->name = g_strdup_printf("POD%d", i + 1);
                sdi->channel_groups = g_slist_append(sdi->channel_groups,
                                   devc->digital_groups[i]);
        }