Commit 023458f7 authored by Federico Vaga's avatar Federico Vaga

Merge branch 'develop' into release/v4.0.0

parents da5e3353 1e40c00a
...@@ -23,17 +23,19 @@ ...@@ -23,17 +23,19 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <unistd.h> #include <unistd.h>
#include <inttypes.h> #include <inttypes.h>
#include <stdbool.h>
#include <adc-lib.h> #include <adc-lib.h>
#include <adc-lib-100m14b4cha.h> #include <adc-lib-100m14b4cha.h>
static int arg_show_config = 0; static int arg_show_config = 0;
static int arg_no_read = 0; static int arg_no_read = 0;
static int arg_plot = 0; static bool arg_plot = false;
static int arg_x_display = 0; static int arg_x_display = 0;
static int arg_trgsw_delay = 0; static int arg_trgsw_delay = 0;
static int arg_trgsw = 0; static int arg_trgsw = 0;
static int fixup = 0; static int fixup = 0;
static int statistics = 0; static int statistics = 0;
static unsigned arg_plot_selected = 0;
static char git_version[] = "version: " GIT_VERSION; static char git_version[] = "version: " GIT_VERSION;
...@@ -62,7 +64,7 @@ static const char *help_msg_opt = ...@@ -62,7 +64,7 @@ static const char *help_msg_opt =
" --loop|-l <num> number of loop before exiting\n" " --loop|-l <num> number of loop before exiting\n"
" --show-data|-s <num> how many data to display: " " --show-data|-s <num> how many data to display: "
">0 from head, <0 from tail\n" ">0 from head, <0 from tail\n"
" --plot plot acquisition\n" " --plot [<num>] Optionally add channel <num> to limit the plot to a subset of channels\n"
" --X11|-X Gnuplot will use X connection\n" " --X11|-X Gnuplot will use X connection\n"
" --stats It prints some statistics\n" " --stats It prints some statistics\n"
" --version|-V print version information\n" " --version|-V print version information\n"
...@@ -90,7 +92,8 @@ static const char *help_msg_opt_desc = ...@@ -90,7 +92,8 @@ static const char *help_msg_opt_desc =
" <pre-sample>\n" " <pre-sample>\n"
" number of samples to be acquired before trigger\n" " number of samples to be acquired before trigger\n"
" <range>*\n" " <range>*\n"
" voltage range to use in micro Volts (the value depends on the target board)\n" " voltage range to use in micro volts\n"
" (fmc-adc-100m14b: 10V, 1V, 100mV)\n"
" <saturation>*\n" " <saturation>*\n"
" saturation value for an input channel\n" " saturation value for an input channel\n"
" <seconds>\n" " <seconds>\n"
...@@ -148,7 +151,7 @@ static struct option options[] = { ...@@ -148,7 +151,7 @@ static struct option options[] = {
{"dont-read", no_argument, &arg_no_read, 1}, {"dont-read", no_argument, &arg_no_read, 1},
{"loop", required_argument, 0, 'l'}, {"loop", required_argument, 0, 'l'},
{"show-data", required_argument, 0, 's'}, {"show-data", required_argument, 0, 's'},
{"plot", no_argument, &arg_plot, 1}, {"plot", optional_argument, 0, 'p'},
{"X11", no_argument, &arg_x_display , 1}, {"X11", no_argument, &arg_x_display , 1},
/* loop for stess test */ /* loop for stess test */
...@@ -160,7 +163,7 @@ static struct option options[] = { ...@@ -160,7 +163,7 @@ static struct option options[] = {
{0, 0, 0, 0} {0, 0, 0, 0}
}; };
#define GETOPT_STRING "D:Vha:c:T:B:M:l:s:" #define GETOPT_STRING "D:Vha:c:T:B:M:l:s:S:p::"
static void print_version(char *pname) static void print_version(char *pname)
{ {
...@@ -556,11 +559,11 @@ static int fald_acq_channel_configuration(struct adc_dev *adc, char *param) ...@@ -556,11 +559,11 @@ static int fald_acq_channel_configuration(struct adc_dev *adc, char *param)
*/ */
static int fald_trg_software_configuration(struct adc_dev *adc, char *param) static int fald_trg_software_configuration(struct adc_dev *adc, char *param)
{ {
uint32_t delay; double delay;
int ret; int ret;
ret = sscanf(param, "%u", &delay); ret = sscanf(param, "%lf", &delay);
if (ret <= 0) { /* channel is mandatory */ if (ret != 1) { /* delay is mandatory */
errno = EINVAL; errno = EINVAL;
return -1; return -1;
} }
...@@ -570,16 +573,8 @@ static int fald_trg_software_configuration(struct adc_dev *adc, char *param) ...@@ -570,16 +573,8 @@ static int fald_trg_software_configuration(struct adc_dev *adc, char *param)
errno = ADC_ENOP; errno = ADC_ENOP;
return -1; return -1;
} }
arg_trgsw = 1; arg_trgsw = 1;
arg_trgsw_delay = delay * 1000000;
switch (ret) {
case 1:
arg_trgsw_delay = delay;
break;
default:
errno = EINVAL;
return -1;
}
return 0; return 0;
} }
...@@ -865,6 +860,19 @@ static int fald_acq_parse_args_and_configure(struct adc_dev *adc, int argc, char ...@@ -865,6 +860,19 @@ static int fald_acq_parse_args_and_configure(struct adc_dev *adc, int argc, char
return -1; return -1;
} }
break; break;
case 'p':
arg_plot = true;
if (optarg != NULL) {
unsigned int chan;
int ret;
ret = sscanf(optarg, "%u", &chan);
if (ret != 1 || chan > ADC_CONF_100M14B4CHA_CHN_RANGE_N) {
fprintf(stderr, "Invalid channel number \"%s\"\n", optarg);
return -1;
}
arg_plot_selected |= (1 << chan);
}
break;
default: default:
break; break;
} }
...@@ -1019,8 +1027,8 @@ static void fald_acq_plot_data(struct adc_buffer *buf, unsigned int ch) ...@@ -1019,8 +1027,8 @@ static void fald_acq_plot_data(struct adc_buffer *buf, unsigned int ch)
char fname[PATH_MAX]; char fname[PATH_MAX];
char cmd[PATH_MAX + 256]; char cmd[PATH_MAX + 256];
snprintf(fname, sizeof(fname), "/tmp/fmcadc.0x%04x.ch%u.dat", devid, ch); snprintf(fname, sizeof(fname), "/tmp/fmcadc.0x%04x.ch%d.dat", devid, ch);
if (write_file(fname, ch, data, (buf->nsamples)/4) < 0) { if (write_file(fname, ch, data, buf->nsamples) < 0) {
printf("Cannot plot data. Write data into file %s failed.\n", fname); printf("Cannot plot data. Write data into file %s failed.\n", fname);
return; return;
} }
...@@ -1100,8 +1108,11 @@ static void fald_acq_process_buffer(struct adc_buffer *buf, ...@@ -1100,8 +1108,11 @@ static void fald_acq_process_buffer(struct adc_buffer *buf,
if (arg_plot) { if (arg_plot) {
int w; int w;
if (arg_plot_selected == 0)
arg_plot_selected = 0xF;
for (w = 0; w < nchan; ++w) for (w = 0; w < nchan; ++w)
fald_acq_plot_data(buf, w + 1); if (arg_plot_selected & (1 << w))
fald_acq_plot_data(buf, w + 1);
} }
} }
...@@ -1205,18 +1216,24 @@ static int adc_acq_acquisition(struct adc_dev *adc, ...@@ -1205,18 +1216,24 @@ static int adc_acq_acquisition(struct adc_dev *adc,
adc_get_conf(cfg_acq, ADC_CONF_ACQ_PRE_SAMP, &pre); adc_get_conf(cfg_acq, ADC_CONF_ACQ_PRE_SAMP, &pre);
adc_get_conf(cfg_acq, ADC_CONF_ACQ_POST_SAMP, &post); adc_get_conf(cfg_acq, ADC_CONF_ACQ_POST_SAMP, &post);
adc_get_conf(cfg_acq, ADC_CONF_ACQ_N_SHOTS, &nshots); adc_get_conf(cfg_acq, ADC_CONF_ACQ_N_SHOTS, &nshots);
if (arg_trgsw_delay) {
for (k = 0; k < nshots; ++k) {
usleep(arg_trgsw_delay);
err = adc_trigger_fire(adc);
if (err) {
fprintf(stderr, "Cannot fire sw trigger: (%d) %s\n",
errno, adc_strerror(errno));
goto err;
}
}
}
for (k = 0; k < nshots; ++k) { for (k = 0; k < nshots; ++k) {
fprintf(stderr, fprintf(stderr,
"shot: %i/%u, nsamples: %u\n", "shot: %i/%u, nsamples: %u\n",
k + 1, nshots, pre + post); k + 1, nshots, pre + post);
if (arg_trgsw) {
sleep(arg_trgsw_delay);
err = adc_trigger_fire(adc);
if (err)
goto err;
}
tv.tv_sec = 60; tv.tv_sec = 60;
err = adc_fill_buffer(adc, buf, err = adc_fill_buffer(adc, buf,
fixup ? ADC_F_FIXUP: 0, fixup ? ADC_F_FIXUP: 0,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment