This allows us to use the new array helpers in a few more places.
break;
case SR_CONF_TRIGGER_SOURCE:
tmp = g_variant_get_string(data, NULL);
- for (i = 0; (*model->trigger_sources)[i]; i++) {
+ for (i = 0; i < model->num_trigger_sources; i++) {
if (g_strcmp0(tmp, (*model->trigger_sources)[i]) != 0)
continue;
state->trigger_source = i;
break;
case SR_CONF_TRIGGER_SLOPE:
tmp = g_variant_get_string(data, NULL);
- for (i = 0; (*model->trigger_slopes)[i]; i++) {
+ for (i = 0; i < model->num_trigger_slopes; i++) {
if (g_strcmp0(tmp, (*model->trigger_slopes)[i]) != 0)
continue;
state->trigger_slope = i;
tmp = g_variant_get_string(data, NULL);
- for (i = 0; (*model->coupling_options)[i]; i++) {
+ for (i = 0; i < model->num_coupling_options; i++) {
if (strcmp(tmp, (*model->coupling_options)[i]) != 0)
continue;
for (j = 1; j <= model->analog_channels; j++) {
case SR_CONF_COUPLING:
if (cg_type == CG_NONE)
return SR_ERR_CHANNEL_GROUP;
- *data = g_variant_new_strv(*model->coupling_options,
- g_strv_length((char **)*model->coupling_options));
+ *data = g_variant_new_strv(*model->coupling_options, model->num_coupling_options);
break;
case SR_CONF_TRIGGER_SOURCE:
if (!model)
return SR_ERR_ARG;
- *data = g_variant_new_strv(*model->trigger_sources,
- g_strv_length((char **)*model->trigger_sources));
+ *data = g_variant_new_strv(*model->trigger_sources, model->num_trigger_sources);
break;
case SR_CONF_TRIGGER_SLOPE:
if (!model)
return SR_ERR_ARG;
- *data = g_variant_new_strv(*model->trigger_slopes,
- g_strv_length((char **)*model->trigger_slopes));
+ *data = g_variant_new_strv(*model->trigger_slopes, model->num_trigger_slopes);
break;
case SR_CONF_TIMEBASE:
if (!model)
"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,
};
static const char *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_dig16_trigger_sources[] = {
"LINE", "EXT", "PATT", "BUS1", "BUS2",
"D0", "D1", "D2", "D3", "D4", "D5", "D6", "D7",
"D8", "D9", "D10", "D11", "D12", "D13", "D14", "D15",
- NULL,
};
static const uint64_t timebases[][2] = {
.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),
.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),
.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),
}
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;
return SR_ERR;
}
- for (i = 0; (*array)[i]; i++) {
+ for (i = 0; i < n; i++) {
if (!g_strcmp0(tmp, (*array)[i])) {
*result = i;
g_free(tmp);
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;
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)
const uint8_t num_trigger_sources;
const char *(*trigger_slopes)[];
+ const uint8_t num_trigger_slopes;
const uint64_t (*timebases)[][2];
const uint8_t num_timebases;
break;
case SR_CONF_TRIGGER_SOURCE:
tmp = g_variant_get_string(data, NULL);
- for (i = 0; (*model->trigger_sources)[i]; i++) {
+ for (i = 0; i < model->num_trigger_sources; i++) {
if (g_strcmp0(tmp, (*model->trigger_sources)[i]) != 0)
continue;
state->trigger_source = i;
break;
case SR_CONF_TRIGGER_SLOPE:
tmp = g_variant_get_string(data, NULL);
- for (i = 0; (*model->trigger_slopes)[i]; i++) {
+ for (i = 0; i < model->num_trigger_slopes; i++) {
if (g_strcmp0(tmp, (*model->trigger_slopes)[i]) != 0)
continue;
state->trigger_slope = i;
case SR_CONF_COUPLING:
tmp = g_variant_get_string(data, NULL);
- for (i = 0; (*model->coupling_options)[i]; i++) {
+ for (i = 0; i < model->num_coupling_options; i++) {
if (strcmp(tmp, (*model->coupling_options)[i]) != 0)
continue;
for (j = 1; j <= model->analog_channels; j++) {
*data = std_gvar_array_u32(ARRAY_AND_SIZE(devopts_cg_analog));
break;
case SR_CONF_COUPLING:
- *data = g_variant_new_strv(*model->coupling_options,
- g_strv_length((char **)*model->coupling_options));
+ *data = g_variant_new_strv(*model->coupling_options, model->num_coupling_options);
break;
case SR_CONF_TRIGGER_SOURCE:
if (!model)
return SR_ERR_ARG;
- *data = g_variant_new_strv(*model->trigger_sources,
- g_strv_length((char **)*model->trigger_sources));
+ *data = g_variant_new_strv(*model->trigger_sources, model->num_trigger_sources);
break;
case SR_CONF_TRIGGER_SLOPE:
if (!model)
return SR_ERR_ARG;
- *data = g_variant_new_strv(*model->trigger_slopes,
- g_strv_length((char **)*model->trigger_slopes));
+ *data = g_variant_new_strv(*model->trigger_slopes, model->num_trigger_slopes);
break;
case SR_CONF_TIMEBASE:
if (!model)
"D1M", // DC with 1 MOhm termination
"GND",
"OVL",
- NULL,
};
static const char *scope_trigger_slopes[] = {
- "POS", "NEG", NULL,
+ "POS", "NEG",
};
static const char *trigger_sources[] = {
- "C1", "C2", "C3", "C4", "LINE", "EXT", NULL,
+ "C1", "C2", "C3", "C4", "LINE", "EXT",
};
static const struct sr_rational timebases[] = {
.analog_names = &scope_analog_channel_names,
.coupling_options = &coupling_options,
+ .num_coupling_options = ARRAY_SIZE(coupling_options),
+
.trigger_sources = &trigger_sources,
+ .num_trigger_sources = ARRAY_SIZE(trigger_sources),
+
.trigger_slopes = &scope_trigger_slopes,
+ .num_trigger_slopes = ARRAY_SIZE(scope_trigger_slopes),
.timebases = timebases,
.num_timebases = ARRAY_SIZE(timebases),
}
static int scope_state_get_array_option(const char *resp,
- const char *(*array)[], int *result)
+ const char *(*array)[], unsigned int n, int *result)
{
unsigned int i;
- for (i = 0; (*array)[i]; i++) {
+ for (i = 0; i < n; i++) {
if (!g_strcmp0(resp, (*array)[i])) {
*result = i;
return SR_OK;
if (scope_state_get_array_option(tmp_str, config->coupling_options,
+ config->num_coupling_options,
&state->analog_channels[i].coupling) != SR_OK)
return SR_ERR;
i++;
}
- if (!trig_source || scope_state_get_array_option(trig_source, config->trigger_sources, &state->trigger_source) != SR_OK)
+ if (!trig_source || scope_state_get_array_option(trig_source, config->trigger_sources, config->num_trigger_sources, &state->trigger_source) != SR_OK)
return SR_ERR;
g_snprintf(command, sizeof(command), "%s:TRIG_SLOPE?", trig_source);
return SR_ERR;
if (scope_state_get_array_option(tmp_str,
- config->trigger_slopes, &state->trigger_slope) != SR_OK)
+ config->trigger_slopes, config->num_trigger_slopes, &state->trigger_slope) != SR_OK)
return SR_ERR;
if (sr_scpi_get_float(sdi->conn, "TRIG_DELAY?", &state->horiz_triggerpos) != SR_OK)
const uint8_t num_trigger_sources;
const char *(*trigger_slopes)[];
+ const uint8_t num_trigger_slopes;
const struct sr_rational *timebases;
const uint8_t num_timebases;
break;
case SR_CONF_TRIGGER_SOURCE:
tmp = g_variant_get_string(data, NULL);
- for (i = 0; (*model->trigger_sources)[i]; i++) {
+ for (i = 0; i < model->num_trigger_sources; i++) {
if (g_strcmp0(tmp, (*model->trigger_sources)[i]) != 0)
continue;
state->trigger_source = i;
tmp = g_variant_get_string(data, NULL);
- for (i = 0; (*model->coupling_options)[i]; i++) {
+ for (i = 0; i < model->num_coupling_options; i++) {
if (strcmp(tmp, (*model->coupling_options)[i]) != 0)
continue;
for (j = 1; j <= model->analog_channels; j++) {
case SR_CONF_TRIGGER_SOURCE:
if (!model)
return SR_ERR_ARG;
- *data = g_variant_new_strv(*model->trigger_sources,
- g_strv_length((char **)*model->trigger_sources));
+ *data = g_variant_new_strv(*model->trigger_sources, model->num_trigger_sources);
return SR_OK;
case SR_CONF_TRIGGER_SLOPE:
- *data = g_variant_new_strv(dlm_trigger_slopes,
- g_strv_length((char **)dlm_trigger_slopes));
+ *data = g_variant_new_strv(ARRAY_AND_SIZE(dlm_trigger_slopes));
return SR_OK;
case SR_CONF_NUM_HDIV:
*data = g_variant_new_uint32(model->num_xdivs);
case SR_CONF_COUPLING:
if (cg_type == CG_NONE)
return SR_ERR_CHANNEL_GROUP;
- *data = g_variant_new_strv(*model->coupling_options,
- g_strv_length((char **)*model->coupling_options));
+ *data = g_variant_new_strv(*model->coupling_options, model->num_coupling_options);
break;
case SR_CONF_VDIV:
if (cg_type == CG_NONE)
static const char *coupling_options[] = {
"AC", "DC", "DC50", "GND",
- NULL,
};
static const char *trigger_sources_2ch[] = {
"1", "2", "LINE", "EXT",
- NULL,
};
/* TODO: Is BITx handled correctly or is Dx required? */
"1", "2", "3", "4",
"LINE", "EXT", "BIT1",
"BIT2", "BIT3", "BIT4", "BIT5", "BIT6", "BIT7", "BIT8",
- NULL,
};
/* Note: Values must correlate to the trigger_slopes values. */
-const char *dlm_trigger_slopes[3] = {
+const char *dlm_trigger_slopes[2] = {
"r", "f",
- NULL,
};
const uint64_t dlm_timebases[36][2] = {
.digital_names = &scope_digital_channel_names_8,
.coupling_options = &coupling_options,
+ .num_coupling_options = ARRAY_SIZE(coupling_options),
+
.trigger_sources = &trigger_sources_2ch,
+ .num_trigger_sources = ARRAY_SIZE(trigger_sources_2ch),
.num_xdivs = 10,
.num_ydivs = 8,
.digital_names = &scope_digital_channel_names_8,
.coupling_options = &coupling_options,
+ .num_coupling_options = ARRAY_SIZE(coupling_options),
+
.trigger_sources = &trigger_sources_4ch,
+ .num_trigger_sources = ARRAY_SIZE(trigger_sources_4ch),
.num_xdivs = 10,
.num_ydivs = 8,
.digital_names = NULL,
.coupling_options = &coupling_options,
+ .num_coupling_options = ARRAY_SIZE(coupling_options),
+
.trigger_sources = &trigger_sources_4ch,
+ .num_trigger_sources = ARRAY_SIZE(trigger_sources_4ch),
.num_xdivs = 10,
.num_ydivs = 8,
.digital_names = &scope_digital_channel_names_32,
.coupling_options = &coupling_options,
+ .num_coupling_options = ARRAY_SIZE(coupling_options),
+
.trigger_sources = &trigger_sources_4ch,
+ .num_trigger_sources = ARRAY_SIZE(trigger_sources_4ch),
.num_xdivs = 10,
.num_ydivs = 8,
.digital_names = &scope_digital_channel_names_32,
.coupling_options = &coupling_options,
+ .num_coupling_options = ARRAY_SIZE(coupling_options),
+
.trigger_sources = &trigger_sources_4ch,
+ .num_trigger_sources = ARRAY_SIZE(trigger_sources_4ch),
.num_xdivs = 10,
.num_ydivs = 8,
* @return SR_ERR when value couldn't be found, SR_OK otherwise.
*/
static int array_option_get(char *value, const char *(*array)[],
- int *result)
+ unsigned int n, int *result)
{
unsigned int i;
*result = -1;
- for (i = 0; (*array)[i]; i++)
+ for (i = 0; i < n; i++)
if (!g_strcmp0(value, (*array)[i])) {
*result = i;
break;
}
if (array_option_get(response, config->coupling_options,
+ config->num_coupling_options,
&state->analog_states[i].coupling) != SR_OK) {
g_free(response);
return SR_ERR;
}
if (array_option_get(response, config->trigger_sources,
- &state->trigger_source) != SR_OK) {
+ config->num_trigger_sources, &state->trigger_source) != SR_OK) {
g_free(response);
return SR_ERR;
}
SLOPE_NEGATIVE
};
-extern const char *dlm_trigger_slopes[3];
+extern const char *dlm_trigger_slopes[2];
extern const uint64_t dlm_timebases[36][2];
extern const uint64_t dlm_vdivs[17][2];