lecroy-xstream: Use array-based approach for timebases/vdivs.

This makes the driver more consistent with the rest of the code-base
and allows us to use the new array helpers in a few more places.
This commit is contained in:
Uwe Hermann 2017-08-02 20:40:18 +02:00
parent 692716f5d1
commit 76f0fa5dfb
3 changed files with 26 additions and 25 deletions

View File

@ -154,8 +154,8 @@ static int config_get(uint32_t key, GVariant **data,
break; break;
case SR_CONF_TIMEBASE: case SR_CONF_TIMEBASE:
*data = g_variant_new("(tt)", *data = g_variant_new("(tt)",
model->timebases[state->timebase].p, (*model->timebases)[state->timebase][0],
model->timebases[state->timebase].q); (*model->timebases)[state->timebase][1]);
break; break;
case SR_CONF_NUM_VDIV: case SR_CONF_NUM_VDIV:
for (i = 0; i < model->analog_channels; i++) { for (i = 0; i < model->analog_channels; i++) {
@ -169,8 +169,8 @@ static int config_get(uint32_t key, GVariant **data,
if (cg != devc->analog_groups[i]) if (cg != devc->analog_groups[i])
continue; continue;
*data = g_variant_new("(tt)", *data = g_variant_new("(tt)",
model->vdivs[state->analog_channels[i].vdiv].p, (*model->vdivs)[state->analog_channels[i].vdiv][0],
model->vdivs[state->analog_channels[i].vdiv].q); (*model->vdivs)[state->analog_channels[i].vdiv][1]);
} }
break; break;
case SR_CONF_TRIGGER_SOURCE: case SR_CONF_TRIGGER_SOURCE:
@ -212,8 +212,7 @@ static int config_set(uint32_t key, GVariant *data,
const struct scope_config *model; const struct scope_config *model;
struct scope_state *state; struct scope_state *state;
const char *tmp; const char *tmp;
int64_t p; uint64_t p, q;
uint64_t q;
double tmp_d; double tmp_d;
gboolean update_sample_rate; gboolean update_sample_rate;
@ -251,7 +250,7 @@ static int config_set(uint32_t key, GVariant *data,
g_variant_get(data, "(tt)", &p, &q); g_variant_get(data, "(tt)", &p, &q);
for (i = 0; i < model->num_vdivs; i++) { for (i = 0; i < model->num_vdivs; i++) {
if (p != model->vdivs[i].p || q != model->vdivs[i].q) if (p != (*model->vdivs)[i][0] || q != (*model->vdivs)[i][1])
continue; continue;
for (j = 1; j <= model->analog_channels; j++) { for (j = 1; j <= model->analog_channels; j++) {
if (cg != devc->analog_groups[j - 1]) if (cg != devc->analog_groups[j - 1])
@ -275,8 +274,8 @@ static int config_set(uint32_t key, GVariant *data,
g_variant_get(data, "(tt)", &p, &q); g_variant_get(data, "(tt)", &p, &q);
for (i = 0; i < model->num_timebases; i++) { for (i = 0; i < model->num_timebases; i++) {
if (p != model->timebases[i].p || if (p != (*model->timebases)[i][0] ||
q != model->timebases[i].q) q != (*model->timebases)[i][1])
continue; continue;
state->timebase = i; state->timebase = i;
g_snprintf(command, sizeof(command), g_snprintf(command, sizeof(command),
@ -295,8 +294,8 @@ static int config_set(uint32_t key, GVariant *data,
state->horiz_triggerpos = tmp_d; state->horiz_triggerpos = tmp_d;
tmp_d = -(tmp_d - 0.5) * tmp_d = -(tmp_d - 0.5) *
((double)model->timebases[state->timebase].p / ((double)(*model->timebases)[state->timebase][0] /
model->timebases[state->timebase].q) (*model->timebases)[state->timebase][1])
* model->num_xdivs; * model->num_xdivs;
g_snprintf(command, sizeof(command), "TRIG POS %e S", tmp_d); g_snprintf(command, sizeof(command), "TRIG POS %e S", tmp_d);
@ -388,12 +387,12 @@ static int config_list(uint32_t key, GVariant **data,
case SR_CONF_TIMEBASE: case SR_CONF_TIMEBASE:
if (!model) if (!model)
return SR_ERR_ARG; return SR_ERR_ARG;
*data = std_gvar_tuple_rational(model->timebases, model->num_timebases); *data = std_gvar_tuple_array(*model->timebases, model->num_timebases);
break; break;
case SR_CONF_VDIV: case SR_CONF_VDIV:
if (!model) if (!model)
return SR_ERR_ARG; return SR_ERR_ARG;
*data = std_gvar_tuple_rational(model->vdivs, model->num_vdivs); *data = std_gvar_tuple_array(*model->vdivs, model->num_vdivs);
break; break;
default: default:
return SR_ERR_NA; return SR_ERR_NA;

View File

@ -90,7 +90,7 @@ static const char *trigger_sources[] = {
"C1", "C2", "C3", "C4", "LINE", "EXT", "C1", "C2", "C3", "C4", "LINE", "EXT",
}; };
static const struct sr_rational timebases[] = { static const uint64_t timebases[][2] = {
/* picoseconds */ /* picoseconds */
{ 20, 1000000000000 }, { 20, 1000000000000 },
{ 50, 1000000000000 }, { 50, 1000000000000 },
@ -140,7 +140,7 @@ static const struct sr_rational timebases[] = {
{ 1000, 1 }, { 1000, 1 },
}; };
static const struct sr_rational vdivs[] = { static const uint64_t vdivs[][2] = {
/* millivolts */ /* millivolts */
{ 1, 1000 }, { 1, 1000 },
{ 2, 1000 }, { 2, 1000 },
@ -180,10 +180,10 @@ static const struct scope_config scope_models[] = {
.trigger_slopes = &scope_trigger_slopes, .trigger_slopes = &scope_trigger_slopes,
.num_trigger_slopes = ARRAY_SIZE(scope_trigger_slopes), .num_trigger_slopes = ARRAY_SIZE(scope_trigger_slopes),
.timebases = timebases, .timebases = &timebases,
.num_timebases = ARRAY_SIZE(timebases), .num_timebases = ARRAY_SIZE(timebases),
.vdivs = vdivs, .vdivs = &vdivs,
.num_vdivs = ARRAY_SIZE(vdivs), .num_vdivs = ARRAY_SIZE(vdivs),
.num_xdivs = 10, .num_xdivs = 10,
@ -198,16 +198,16 @@ static void scope_state_dump(const struct scope_config *config,
char *tmp; char *tmp;
for (i = 0; i < config->analog_channels; i++) { for (i = 0; i < config->analog_channels; i++) {
tmp = sr_voltage_string(config->vdivs[state->analog_channels[i].vdiv].p, tmp = sr_voltage_string((*config->vdivs)[state->analog_channels[i].vdiv][0],
config->vdivs[state->analog_channels[i].vdiv].q); (*config->vdivs)[state->analog_channels[i].vdiv][1]);
sr_info("State of analog channel %d -> %s : %s (coupling) %s (vdiv) %2.2e (offset)", sr_info("State of analog channel %d -> %s : %s (coupling) %s (vdiv) %2.2e (offset)",
i + 1, state->analog_channels[i].state ? "On" : "Off", i + 1, state->analog_channels[i].state ? "On" : "Off",
(*config->coupling_options)[state->analog_channels[i].coupling], (*config->coupling_options)[state->analog_channels[i].coupling],
tmp, state->analog_channels[i].vertical_offset); tmp, state->analog_channels[i].vertical_offset);
} }
tmp = sr_period_string(config->timebases[state->timebase].p, tmp = sr_period_string((*config->timebases)[state->timebase][0],
config->timebases[state->timebase].q); (*config->timebases)[state->timebase][1]);
sr_info("Current timebase: %s", tmp); sr_info("Current timebase: %s", tmp);
g_free(tmp); g_free(tmp);
@ -247,16 +247,18 @@ static int scope_state_get_array_option(const char *resp,
* *
* @return SR_ERR on any parsing error, SR_OK otherwise. * @return SR_ERR on any parsing error, SR_OK otherwise.
*/ */
static int array_float_get(gchar *value, const struct sr_rational *aval, static int array_float_get(gchar *value, const uint64_t array[][2],
int array_len, unsigned int *result) int array_len, unsigned int *result)
{ {
struct sr_rational rval; struct sr_rational rval;
struct sr_rational aval;
if (sr_parse_rational(value, &rval) != SR_OK) if (sr_parse_rational(value, &rval) != SR_OK)
return SR_ERR; return SR_ERR;
for (int i = 0; i < array_len; i++) { for (int i = 0; i < array_len; i++) {
if (sr_rational_eq(&rval, aval + i)) { sr_rational_set(&aval, array[i][0], array[i][1]);
if (sr_rational_eq(&rval, &aval)) {
*result = i; *result = i;
return SR_OK; return SR_OK;
} }

View File

@ -47,10 +47,10 @@ struct scope_config {
const char *(*trigger_slopes)[]; const char *(*trigger_slopes)[];
const uint8_t num_trigger_slopes; const uint8_t num_trigger_slopes;
const struct sr_rational *timebases; const uint64_t (*timebases)[][2];
const uint8_t num_timebases; const uint8_t num_timebases;
const struct sr_rational *vdivs; const uint64_t (*vdivs)[][2];
const uint8_t num_vdivs; const uint8_t num_vdivs;
const uint8_t num_xdivs; const uint8_t num_xdivs;