X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fhameg-hmo%2Fprotocol.c;h=0a60127faa662d6523ee25339d0af4cc164e227e;hb=19c9b176485e6033f024216a56058e507d47b2fc;hp=437b5f37dfef445d2502379132a2e7590f3c9dc8;hpb=4b25cbffa17c9b8c9c30f98ffe6918a15b664b2a;p=libsigrok.git diff --git a/src/hardware/hameg-hmo/protocol.c b/src/hardware/hameg-hmo/protocol.c index 437b5f37..0a60127f 100644 --- a/src/hardware/hameg-hmo/protocol.c +++ b/src/hardware/hameg-hmo/protocol.c @@ -68,7 +68,7 @@ static const uint32_t devopts[] = { SR_CONF_TRIGGER_SLOPE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, }; -static const uint32_t 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, @@ -80,83 +80,31 @@ static const char *coupling_options[] = { "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 *compact2_trigger_sources[] = { - "CH1", - "CH2", - "LINE", - "EXT", - "PATT", - "BUS1", - "BUS2", - "D0", - "D1", - "D2", - "D3", - "D4", - "D5", - "D6", - "D7", - NULL, + "CH1", "CH2", + "LINE", "EXT", "PATT", "BUS1", "BUS2", + "D0", "D1", "D2", "D3", "D4", "D5", "D6", "D7", }; static const char *compact4_trigger_sources[] = { - "CH1", - "CH2", - "CH3", - "CH4", - "LINE", - "EXT", - "PATT", - "BUS1", - "BUS2", - "D0", - "D1", - "D2", - "D3", - "D4", - "D5", - "D6", - "D7", - NULL, + "CH1", "CH2", "CH3", "CH4", + "LINE", "EXT", "PATT", "BUS1", "BUS2", + "D0", "D1", "D2", "D3", "D4", "D5", "D6", "D7", }; 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", - NULL, + "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 timebases[][2] = { @@ -219,29 +167,12 @@ static const uint64_t 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[] = { @@ -259,12 +190,17 @@ static const struct scope_config scope_models[] = { .devopts = &devopts, .num_devopts = ARRAY_SIZE(devopts), - .analog_devopts = &analog_devopts, - .num_analog_devopts = ARRAY_SIZE(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), + .trigger_slopes = &scope_trigger_slopes, + .num_trigger_slopes = ARRAY_SIZE(scope_trigger_slopes), .timebases = &timebases, .num_timebases = ARRAY_SIZE(timebases), @@ -289,12 +225,17 @@ static const struct scope_config scope_models[] = { .devopts = &devopts, .num_devopts = ARRAY_SIZE(devopts), - .analog_devopts = &analog_devopts, - .num_analog_devopts = ARRAY_SIZE(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_trigger_sources, + .num_trigger_sources = ARRAY_SIZE(compact4_trigger_sources), + .trigger_slopes = &scope_trigger_slopes, + .num_trigger_slopes = ARRAY_SIZE(scope_trigger_slopes), .timebases = &timebases, .num_timebases = ARRAY_SIZE(timebases), @@ -319,12 +260,17 @@ static const struct scope_config scope_models[] = { .devopts = &devopts, .num_devopts = ARRAY_SIZE(devopts), - .analog_devopts = &analog_devopts, - .num_analog_devopts = ARRAY_SIZE(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), + .trigger_slopes = &scope_trigger_slopes, + .num_trigger_slopes = ARRAY_SIZE(scope_trigger_slopes), .timebases = &timebases, .num_timebases = ARRAY_SIZE(timebases), @@ -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,7 +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, vdivs, ARRAY_SIZE(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; @@ -484,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; @@ -539,7 +481,6 @@ 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; @@ -553,8 +494,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); @@ -563,19 +517,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) { @@ -627,7 +568,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, timebases, ARRAY_SIZE(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; @@ -648,12 +589,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) @@ -691,7 +634,6 @@ SR_PRIV void hmo_scope_state_free(struct scope_state *state) SR_PRIV int hmo_init_device(struct sr_dev_inst *sdi) { - char tmp[25]; int model_index; unsigned int i, j, group; struct sr_channel *ch; @@ -740,11 +682,8 @@ SR_PRIV int hmo_init_device(struct sr_dev_inst *sdi) /* Add digital channel groups. */ for (i = 0; i < scope_models[model_index].digital_pods; i++) { - g_snprintf(tmp, 25, "POD%d", i); - devc->digital_groups[i] = g_malloc0(sizeof(struct sr_channel_group)); - - devc->digital_groups[i]->name = g_strdup(tmp); + devc->digital_groups[i]->name = g_strdup_printf("POD%d", i); sdi->channel_groups = g_slist_append(sdi->channel_groups, devc->digital_groups[i]); }