lecroy-xstream: Fix sample rate
We can't use the memory size command because it returns the *maximum* memory used, not the *actual* memory used. Hence, we only know the number of samples per div once sample data actually comes in.
This commit is contained in:
parent
86f76e6cae
commit
e0b6855bd4
|
@ -204,7 +204,6 @@ 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;
|
||||||
double tmp_d;
|
double tmp_d;
|
||||||
gboolean update_sample_rate;
|
|
||||||
|
|
||||||
if (!sdi)
|
if (!sdi)
|
||||||
return SR_ERR_ARG;
|
return SR_ERR_ARG;
|
||||||
|
@ -213,7 +212,6 @@ static int config_set(uint32_t key, GVariant *data,
|
||||||
|
|
||||||
model = devc->model_config;
|
model = devc->model_config;
|
||||||
state = devc->model_state;
|
state = devc->model_state;
|
||||||
update_sample_rate = FALSE;
|
|
||||||
|
|
||||||
ret = SR_ERR_NA;
|
ret = SR_ERR_NA;
|
||||||
|
|
||||||
|
@ -249,7 +247,6 @@ static int config_set(uint32_t key, GVariant *data,
|
||||||
g_snprintf(command, sizeof(command),
|
g_snprintf(command, sizeof(command),
|
||||||
"TIME_DIV %E", (float) (*model->timebases)[idx][0] / (*model->timebases)[idx][1]);
|
"TIME_DIV %E", (float) (*model->timebases)[idx][0] / (*model->timebases)[idx][1]);
|
||||||
ret = sr_scpi_send(sdi->conn, command);
|
ret = sr_scpi_send(sdi->conn, command);
|
||||||
update_sample_rate = TRUE;
|
|
||||||
break;
|
break;
|
||||||
case SR_CONF_HORIZ_TRIGGERPOS:
|
case SR_CONF_HORIZ_TRIGGERPOS:
|
||||||
tmp_d = g_variant_get_double(data);
|
tmp_d = g_variant_get_double(data);
|
||||||
|
@ -296,9 +293,6 @@ static int config_set(uint32_t key, GVariant *data,
|
||||||
if (ret == SR_OK)
|
if (ret == SR_OK)
|
||||||
ret = sr_scpi_get_opc(sdi->conn);
|
ret = sr_scpi_get_opc(sdi->conn);
|
||||||
|
|
||||||
if (ret == SR_OK && update_sample_rate)
|
|
||||||
ret = lecroy_xstream_update_sample_rate(sdi);
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -378,7 +372,6 @@ SR_PRIV int lecroy_xstream_request_data(const struct sr_dev_inst *sdi)
|
||||||
static int setup_channels(const struct sr_dev_inst *sdi)
|
static int setup_channels(const struct sr_dev_inst *sdi)
|
||||||
{
|
{
|
||||||
GSList *l;
|
GSList *l;
|
||||||
gboolean setup_changed;
|
|
||||||
char command[MAX_COMMAND_SIZE];
|
char command[MAX_COMMAND_SIZE];
|
||||||
struct scope_state *state;
|
struct scope_state *state;
|
||||||
struct sr_channel *ch;
|
struct sr_channel *ch;
|
||||||
|
@ -388,7 +381,6 @@ static int setup_channels(const struct sr_dev_inst *sdi)
|
||||||
devc = sdi->priv;
|
devc = sdi->priv;
|
||||||
scpi = sdi->conn;
|
scpi = sdi->conn;
|
||||||
state = devc->model_state;
|
state = devc->model_state;
|
||||||
setup_changed = FALSE;
|
|
||||||
|
|
||||||
for (l = sdi->channels; l; l = l->next) {
|
for (l = sdi->channels; l; l = l->next) {
|
||||||
ch = l->data;
|
ch = l->data;
|
||||||
|
@ -403,16 +395,12 @@ static int setup_channels(const struct sr_dev_inst *sdi)
|
||||||
return SR_ERR;
|
return SR_ERR;
|
||||||
|
|
||||||
state->analog_channels[ch->index].state = ch->enabled;
|
state->analog_channels[ch->index].state = ch->enabled;
|
||||||
setup_changed = TRUE;
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return SR_ERR;
|
return SR_ERR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (setup_changed && lecroy_xstream_update_sample_rate(sdi) != SR_OK)
|
|
||||||
return SR_ERR;
|
|
||||||
|
|
||||||
return SR_OK;
|
return SR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -421,6 +409,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
|
||||||
GSList *l;
|
GSList *l;
|
||||||
struct sr_channel *ch;
|
struct sr_channel *ch;
|
||||||
struct dev_context *devc;
|
struct dev_context *devc;
|
||||||
|
struct scope_state *state;
|
||||||
int ret;
|
int ret;
|
||||||
struct sr_scpi_dev_inst *scpi;
|
struct sr_scpi_dev_inst *scpi;
|
||||||
|
|
||||||
|
@ -430,6 +419,8 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
|
||||||
/* Preset empty results. */
|
/* Preset empty results. */
|
||||||
g_slist_free(devc->enabled_channels);
|
g_slist_free(devc->enabled_channels);
|
||||||
devc->enabled_channels = NULL;
|
devc->enabled_channels = NULL;
|
||||||
|
state = devc->model_state;
|
||||||
|
state->sample_rate = 0;
|
||||||
|
|
||||||
/* Contruct the list of enabled channels. */
|
/* Contruct the list of enabled channels. */
|
||||||
for (l = sdi->channels; l; l = l->next) {
|
for (l = sdi->channels; l; l = l->next) {
|
||||||
|
|
|
@ -366,24 +366,22 @@ SR_PRIV int lecroy_xstream_channel_state_set(const struct sr_dev_inst *sdi,
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
SR_PRIV int lecroy_xstream_update_sample_rate(const struct sr_dev_inst *sdi)
|
SR_PRIV int lecroy_xstream_update_sample_rate(const struct sr_dev_inst *sdi,
|
||||||
|
int num_of_samples)
|
||||||
{
|
{
|
||||||
struct dev_context *devc;
|
struct dev_context *devc;
|
||||||
struct scope_state *state;
|
struct scope_state *state;
|
||||||
const struct scope_config *config;
|
const struct scope_config *config;
|
||||||
float memsize, timediv;
|
double time_div;
|
||||||
|
|
||||||
devc = sdi->priv;
|
devc = sdi->priv;
|
||||||
state = devc->model_state;
|
|
||||||
config = devc->model_config;
|
config = devc->model_config;
|
||||||
|
state = devc->model_state;
|
||||||
|
|
||||||
if (sr_scpi_get_float(sdi->conn, "MEMORY_SIZE?", &memsize) != SR_OK)
|
if (sr_scpi_get_double(sdi->conn, "TIME_DIV?", &time_div) != SR_OK)
|
||||||
return SR_ERR;
|
return SR_ERR;
|
||||||
|
|
||||||
if (sr_scpi_get_float(sdi->conn, "TIME_DIV?", &timediv) != SR_OK)
|
state->sample_rate = num_of_samples / (time_div * config->num_xdivs);
|
||||||
return SR_ERR;
|
|
||||||
|
|
||||||
state->sample_rate = 1 / ((timediv * config->num_xdivs) / memsize);
|
|
||||||
|
|
||||||
return SR_OK;
|
return SR_OK;
|
||||||
}
|
}
|
||||||
|
@ -454,9 +452,6 @@ SR_PRIV int lecroy_xstream_state_get(struct sr_dev_inst *sdi)
|
||||||
if (sr_scpi_get_float(sdi->conn, "TRIG_DELAY?", &state->horiz_triggerpos) != SR_OK)
|
if (sr_scpi_get_float(sdi->conn, "TRIG_DELAY?", &state->horiz_triggerpos) != SR_OK)
|
||||||
return SR_ERR;
|
return SR_ERR;
|
||||||
|
|
||||||
if (lecroy_xstream_update_sample_rate(sdi) != SR_OK)
|
|
||||||
return SR_ERR;
|
|
||||||
|
|
||||||
sr_info("Fetching finished.");
|
sr_info("Fetching finished.");
|
||||||
|
|
||||||
scope_state_dump(config, state);
|
scope_state_dump(config, state);
|
||||||
|
@ -624,6 +619,7 @@ SR_PRIV int lecroy_xstream_receive_data(int fd, int revents, void *cb_data)
|
||||||
struct sr_channel *ch;
|
struct sr_channel *ch;
|
||||||
struct sr_dev_inst *sdi;
|
struct sr_dev_inst *sdi;
|
||||||
struct dev_context *devc;
|
struct dev_context *devc;
|
||||||
|
struct scope_state *state;
|
||||||
struct sr_datafeed_packet packet;
|
struct sr_datafeed_packet packet;
|
||||||
GByteArray *data;
|
GByteArray *data;
|
||||||
struct sr_datafeed_analog analog;
|
struct sr_datafeed_analog analog;
|
||||||
|
@ -644,6 +640,7 @@ SR_PRIV int lecroy_xstream_receive_data(int fd, int revents, void *cb_data)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
ch = devc->current_channel->data;
|
ch = devc->current_channel->data;
|
||||||
|
state = devc->model_state;
|
||||||
|
|
||||||
if (ch->type != SR_CHANNEL_ANALOG)
|
if (ch->type != SR_CHANNEL_ANALOG)
|
||||||
return SR_ERR;
|
return SR_ERR;
|
||||||
|
@ -671,7 +668,14 @@ SR_PRIV int lecroy_xstream_receive_data(int fd, int revents, void *cb_data)
|
||||||
/* No data available, we have to acquire data first. */
|
/* No data available, we have to acquire data first. */
|
||||||
g_snprintf(command, sizeof(command), "ARM;WAIT;*OPC;C%d:WAVEFORM?", ch->index + 1);
|
g_snprintf(command, sizeof(command), "ARM;WAIT;*OPC;C%d:WAVEFORM?", ch->index + 1);
|
||||||
sr_scpi_send(sdi->conn, command);
|
sr_scpi_send(sdi->conn, command);
|
||||||
|
|
||||||
|
state->sample_rate = 0;
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
} else {
|
||||||
|
/* Update sample rate if needed. */
|
||||||
|
if (state->sample_rate == 0)
|
||||||
|
if (lecroy_xstream_update_sample_rate(sdi, analog.num_samples) != SR_OK)
|
||||||
|
return SR_ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -98,6 +98,7 @@ SR_PRIV void lecroy_xstream_state_free(struct scope_state *state);
|
||||||
SR_PRIV int lecroy_xstream_state_get(struct sr_dev_inst *sdi);
|
SR_PRIV int lecroy_xstream_state_get(struct sr_dev_inst *sdi);
|
||||||
SR_PRIV int lecroy_xstream_channel_state_set(const struct sr_dev_inst *sdi,
|
SR_PRIV int lecroy_xstream_channel_state_set(const struct sr_dev_inst *sdi,
|
||||||
const int ch_index, gboolean ch_state);
|
const int ch_index, gboolean ch_state);
|
||||||
SR_PRIV int lecroy_xstream_update_sample_rate(const struct sr_dev_inst *sdi);
|
SR_PRIV int lecroy_xstream_update_sample_rate(const struct sr_dev_inst *sdi,
|
||||||
|
int num_of_samples);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue