X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fhameg-hmo%2Fprotocol.c;h=1306338200699532af3a7e5eda3686b75322f730;hb=3782e57129fa661a773be337c9f548708f593eb0;hp=ec1b64f0e607c385241ae74150d117ccbe618383;hpb=8662130615d7a59883c303914f94377032101cb9;p=libsigrok.git diff --git a/src/hardware/hameg-hmo/protocol.c b/src/hardware/hameg-hmo/protocol.c index ec1b64f0..13063382 100644 --- a/src/hardware/hameg-hmo/protocol.c +++ b/src/hardware/hameg-hmo/protocol.c @@ -57,7 +57,7 @@ static const char *hameg_scpi_dialect[] = { [SCPI_CMD_GET_PROBE_UNIT] = ":PROB%d:SET:ATT:UNIT?", }; -static const uint32_t hmo_devopts[] = { +static const uint32_t devopts[] = { SR_CONF_OSCILLOSCOPE, SR_CONF_LIMIT_FRAMES | SR_CONF_GET | SR_CONF_SET, SR_CONF_SAMPLERATE | SR_CONF_GET, @@ -68,98 +68,46 @@ static const uint32_t hmo_devopts[] = { SR_CONF_TRIGGER_SLOPE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, }; -static const uint32_t hmo_analog_devopts[] = { +static const uint32_t devopts_cg_analog[] = { SR_CONF_NUM_VDIV | SR_CONF_GET, SR_CONF_VDIV | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, SR_CONF_COUPLING | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, }; -static const char *hmo_coupling_options[] = { +static const char *coupling_options[] = { "AC", // AC with 50 Ohm termination (152x, 202x, 30xx, 1202) "ACL", // AC with 1 MOhm termination "DC", // DC with 50 Ohm termination "DCL", // DC with 1 MOhm termination "GND", - NULL, }; static const char *scope_trigger_slopes[] = { "POS", "NEG", "EITH", - NULL, }; -static const char *hmo_compact2_trigger_sources[] = { - "CH1", - "CH2", - "LINE", - "EXT", - "PATT", - "BUS1", - "BUS2", - "D0", - "D1", - "D2", - "D3", - "D4", - "D5", - "D6", - "D7", - NULL, +static const char *compact2_trigger_sources[] = { + "CH1", "CH2", + "LINE", "EXT", "PATT", "BUS1", "BUS2", + "D0", "D1", "D2", "D3", "D4", "D5", "D6", "D7", }; -static const char *hmo_compact4_trigger_sources[] = { - "CH1", - "CH2", - "CH3", - "CH4", - "LINE", - "EXT", - "PATT", - "BUS1", - "BUS2", - "D0", - "D1", - "D2", - "D3", - "D4", - "D5", - "D6", - "D7", - NULL, +static const char *compact4_trigger_sources[] = { + "CH1", "CH2", "CH3", "CH4", + "LINE", "EXT", "PATT", "BUS1", "BUS2", + "D0", "D1", "D2", "D3", "D4", "D5", "D6", "D7", }; -static const char *hmo_compact4_dig16_trigger_sources[] = { - "CH1", - "CH2", - "CH3", - "CH4", - "LINE", - "EXT", - "PATT", - "BUS1", - "BUS2", - "D0", - "D1", - "D2", - "D3", - "D4", - "D5", - "D6", - "D7", - "D8", - "D9", - "D10", - "D11", - "D12", - "D13", - "D14", - "D15", - NULL, +static const char *compact4_dig16_trigger_sources[] = { + "CH1", "CH2", "CH3", "CH4", + "LINE", "EXT", "PATT", "BUS1", "BUS2", + "D0", "D1", "D2", "D3", "D4", "D5", "D6", "D7", + "D8", "D9", "D10", "D11", "D12", "D13", "D14", "D15", }; -static const uint64_t hmo_timebases[][2] = { +static const uint64_t timebases[][2] = { /* nanoseconds */ { 2, 1000000000 }, { 5, 1000000000 }, @@ -198,7 +146,7 @@ static const uint64_t hmo_timebases[][2] = { { 50, 1 }, }; -static const uint64_t hmo_vdivs[][2] = { +static const uint64_t vdivs[][2] = { /* millivolts */ { 1, 1000 }, { 2, 1000 }, @@ -219,29 +167,12 @@ static const uint64_t hmo_vdivs[][2] = { }; static const char *scope_analog_channel_names[] = { - "CH1", - "CH2", - "CH3", - "CH4", + "CH1", "CH2", "CH3", "CH4", }; static const char *scope_digital_channel_names[] = { - "D0", - "D1", - "D2", - "D3", - "D4", - "D5", - "D6", - "D7", - "D8", - "D9", - "D10", - "D11", - "D12", - "D13", - "D14", - "D15", + "D0", "D1", "D2", "D3", "D4", "D5", "D6", "D7", + "D8", "D9", "D10", "D11", "D12", "D13", "D14", "D15", }; static const struct scope_config scope_models[] = { @@ -256,21 +187,26 @@ static const struct scope_config scope_models[] = { .analog_names = &scope_analog_channel_names, .digital_names = &scope_digital_channel_names, - .devopts = &hmo_devopts, - .num_devopts = ARRAY_SIZE(hmo_devopts), + .devopts = &devopts, + .num_devopts = ARRAY_SIZE(devopts), - .analog_devopts = &hmo_analog_devopts, - .num_analog_devopts = ARRAY_SIZE(hmo_analog_devopts), + .devopts_cg_analog = &devopts_cg_analog, + .num_devopts_cg_analog = ARRAY_SIZE(devopts_cg_analog), + + .coupling_options = &coupling_options, + .num_coupling_options = ARRAY_SIZE(coupling_options), + + .trigger_sources = &compact2_trigger_sources, + .num_trigger_sources = ARRAY_SIZE(compact2_trigger_sources), - .coupling_options = &hmo_coupling_options, - .trigger_sources = &hmo_compact2_trigger_sources, .trigger_slopes = &scope_trigger_slopes, + .num_trigger_slopes = ARRAY_SIZE(scope_trigger_slopes), - .timebases = &hmo_timebases, - .num_timebases = ARRAY_SIZE(hmo_timebases), + .timebases = &timebases, + .num_timebases = ARRAY_SIZE(timebases), - .vdivs = &hmo_vdivs, - .num_vdivs = ARRAY_SIZE(hmo_vdivs), + .vdivs = &vdivs, + .num_vdivs = ARRAY_SIZE(vdivs), .num_xdivs = 12, .num_ydivs = 8, @@ -286,21 +222,26 @@ static const struct scope_config scope_models[] = { .analog_names = &scope_analog_channel_names, .digital_names = &scope_digital_channel_names, - .devopts = &hmo_devopts, - .num_devopts = ARRAY_SIZE(hmo_devopts), + .devopts = &devopts, + .num_devopts = ARRAY_SIZE(devopts), + + .devopts_cg_analog = &devopts_cg_analog, + .num_devopts_cg_analog = ARRAY_SIZE(devopts_cg_analog), + + .coupling_options = &coupling_options, + .num_coupling_options = ARRAY_SIZE(coupling_options), - .analog_devopts = &hmo_analog_devopts, - .num_analog_devopts = ARRAY_SIZE(hmo_analog_devopts), + .trigger_sources = &compact4_trigger_sources, + .num_trigger_sources = ARRAY_SIZE(compact4_trigger_sources), - .coupling_options = &hmo_coupling_options, - .trigger_sources = &hmo_compact4_trigger_sources, .trigger_slopes = &scope_trigger_slopes, + .num_trigger_slopes = ARRAY_SIZE(scope_trigger_slopes), - .timebases = &hmo_timebases, - .num_timebases = ARRAY_SIZE(hmo_timebases), + .timebases = &timebases, + .num_timebases = ARRAY_SIZE(timebases), - .vdivs = &hmo_vdivs, - .num_vdivs = ARRAY_SIZE(hmo_vdivs), + .vdivs = &vdivs, + .num_vdivs = ARRAY_SIZE(vdivs), .num_xdivs = 12, .num_ydivs = 8, @@ -308,7 +249,7 @@ static const struct scope_config scope_models[] = { .scpi_dialect = &hameg_scpi_dialect, }, { - .name = {"HMO2524", "HMO3034", "HMO3044", "HMO3054", NULL}, + .name = {"HMO2524", "HMO3034", "HMO3044", "HMO3054", "HMO3524", NULL}, .analog_channels = 4, .digital_channels = 16, .digital_pods = 2, @@ -316,21 +257,26 @@ static const struct scope_config scope_models[] = { .analog_names = &scope_analog_channel_names, .digital_names = &scope_digital_channel_names, - .devopts = &hmo_devopts, - .num_devopts = ARRAY_SIZE(hmo_devopts), + .devopts = &devopts, + .num_devopts = ARRAY_SIZE(devopts), - .analog_devopts = &hmo_analog_devopts, - .num_analog_devopts = ARRAY_SIZE(hmo_analog_devopts), + .devopts_cg_analog = &devopts_cg_analog, + .num_devopts_cg_analog = ARRAY_SIZE(devopts_cg_analog), + + .coupling_options = &coupling_options, + .num_coupling_options = ARRAY_SIZE(coupling_options), + + .trigger_sources = &compact4_dig16_trigger_sources, + .num_trigger_sources = ARRAY_SIZE(compact4_dig16_trigger_sources), - .coupling_options = &hmo_coupling_options, - .trigger_sources = &hmo_compact4_dig16_trigger_sources, .trigger_slopes = &scope_trigger_slopes, + .num_trigger_slopes = ARRAY_SIZE(scope_trigger_slopes), - .timebases = &hmo_timebases, - .num_timebases = ARRAY_SIZE(hmo_timebases), + .timebases = &timebases, + .num_timebases = ARRAY_SIZE(timebases), - .vdivs = &hmo_vdivs, - .num_vdivs = ARRAY_SIZE(hmo_vdivs), + .vdivs = &vdivs, + .num_vdivs = ARRAY_SIZE(vdivs), .num_xdivs = 12, .num_ydivs = 8, @@ -380,30 +326,25 @@ static void scope_state_dump(const struct scope_config *config, } static int scope_state_get_array_option(struct sr_scpi_dev_inst *scpi, - const char *command, const char *(*array)[], int *result) + const char *command, const char *(*array)[], unsigned int n, int *result) { char *tmp; - unsigned int i; + int idx; if (sr_scpi_get_string(scpi, command, &tmp) != SR_OK) { g_free(tmp); return SR_ERR; } - for (i = 0; (*array)[i]; i++) { - if (!g_strcmp0(tmp, (*array)[i])) { - *result = i; - g_free(tmp); - tmp = NULL; - break; - } - } - - if (tmp) { + if ((idx = std_str_idx_s(tmp, *array, n)) < 0) { g_free(tmp); - return SR_ERR; + return SR_ERR_ARG; } + *result = idx; + + g_free(tmp); + return SR_OK; } @@ -462,8 +403,7 @@ static int analog_channel_state_get(struct sr_scpi_dev_inst *scpi, if (sr_scpi_get_string(scpi, command, &tmp_str) != SR_OK) return SR_ERR; - if (array_float_get(tmp_str, hmo_vdivs, ARRAY_SIZE(hmo_vdivs), - &j) != SR_OK) { + if (array_float_get(tmp_str, ARRAY_AND_SIZE(vdivs), &j) != SR_OK) { g_free(tmp_str); sr_err("Could not determine array index for vertical div scale."); return SR_ERR; @@ -485,6 +425,7 @@ static int analog_channel_state_get(struct sr_scpi_dev_inst *scpi, i + 1); if (scope_state_get_array_option(scpi, command, config->coupling_options, + config->num_coupling_options, &state->analog_channels[i].coupling) != SR_OK) return SR_ERR; @@ -554,8 +495,21 @@ SR_PRIV int hmo_update_sample_rate(const struct sr_dev_inst *sdi) channel_found = FALSE; for (i = 0; i < config->analog_channels; i++) { - if (state->analog_channels[i].state) { - g_snprintf(chan_name, sizeof(chan_name), "CHAN%d", i + 1); + 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]) + 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); @@ -564,19 +518,6 @@ SR_PRIV int hmo_update_sample_rate(const struct sr_dev_inst *sdi) } } - if (!channel_found) { - for (i = 0; i < config->digital_pods; i++) { - if (state->digital_pods[i]) { - 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) { @@ -628,8 +569,7 @@ SR_PRIV int hmo_scope_state_get(struct sr_dev_inst *sdi) &tmp_str) != SR_OK) return SR_ERR; - if (array_float_get(tmp_str, hmo_timebases, ARRAY_SIZE(hmo_timebases), - &i) != SR_OK) { + if (array_float_get(tmp_str, ARRAY_AND_SIZE(timebases), &i) != SR_OK) { g_free(tmp_str); sr_err("Could not determine array index for time base."); return SR_ERR; @@ -650,12 +590,14 @@ SR_PRIV int hmo_scope_state_get(struct sr_dev_inst *sdi) if (scope_state_get_array_option(sdi->conn, (*config->scpi_dialect)[SCPI_CMD_GET_TRIGGER_SOURCE], - config->trigger_sources, &state->trigger_source) != SR_OK) + config->trigger_sources, config->num_trigger_sources, + &state->trigger_source) != SR_OK) return SR_ERR; if (scope_state_get_array_option(sdi->conn, - (*config->scpi_dialect)[SCPI_CMD_GET_TRIGGER_SLOPE], - config->trigger_slopes, &state->trigger_slope) != SR_OK) + (*config->scpi_dialect)[SCPI_CMD_GET_TRIGGER_SLOPE], + config->trigger_slopes, config->num_trigger_slopes, + &state->trigger_slope) != SR_OK) return SR_ERR; if (hmo_update_sample_rate(sdi) != SR_OK) @@ -1018,7 +960,7 @@ SR_PRIV int hmo_receive_data(int fd, int revents, void *cb_data) * the first enabled channel. */ if (++devc->num_frames == devc->frame_limit) { - sdi->driver->dev_acquisition_stop(sdi); + sr_dev_acquisition_stop(sdi); hmo_cleanup_logic_data(devc); } else { devc->current_channel = devc->enabled_channels;