Commit dd1fcc01 authored by Alessandro Rubini's avatar Alessandro Rubini

tools: added timeout in fd-raw-input

Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent f7758352
......@@ -1061,6 +1061,11 @@ is only printed once, and later lines begin with a single blank space
(you may see more blanks because they are part of normal output,
for alignment purposes).
If you are using the tool in a script, and you want to capture all the
samples in a burst and then terminate, you can specify a timeout, in
microseconds, using @t{-t}. The timeout is only applied after the
first pulse is received.
Finally, the program uses two environment variables, if set to any value:
@code{FD_SHOW_TIME} make the tool report the time difference between
sequential reads, which is mainly useful to debug the driver workings;
......
......@@ -122,8 +122,9 @@ struct zio_control ctrl;
int main(int argc, char **argv)
{
glob_t glob_buf;
int i, j, maxfd = 0;
int i, j, tout = 0, maxfd = 0;
int fd[MAXFD], seq[MAXFD];
struct timeval tv, *tvp = NULL;
fd_set allset, curset;
int modemask = MODE_HEX;
long double t1[MAXFD] = {0.0,};
......@@ -135,7 +136,7 @@ int main(int argc, char **argv)
if (getenv("FD_SHOW_TIME"))
show_time = 1;
while ((i = getopt(argc, argv, "fprh")) != -1) {
while ((i = getopt(argc, argv, "fprht:")) != -1) {
switch(i) {
case 'f':
......@@ -150,6 +151,9 @@ int main(int argc, char **argv)
case 'h':
modemask |= MODE_HEX;
break;
case 't':
tout = atoi(optarg);
break;
}
}
/* adjust for consumed arguments */
......@@ -196,11 +200,13 @@ int main(int argc, char **argv)
seq[i] = -1;
}
if (tout == 0)
setlinebuf(stdout);
tvp = NULL;
/* Ok, now wait for each of them to spit a timestamp */
setlinebuf(stdout);
while (1) {
curset = allset;
switch(select(maxfd + 1, &curset, NULL, NULL, NULL)) {
switch(select(maxfd + 1, &curset, NULL, NULL, tvp)) {
case -1:
if (errno == EINTR)
continue;
......@@ -208,9 +214,14 @@ int main(int argc, char **argv)
strerror(errno));
exit(1);
case 0:
continue;
exit(0);
}
if (tout) {
/* prepare timeout for next time */
tv.tv_sec = tout / (1000 * 1000);
tv.tv_usec = tout % (1000 * 1000);
tvp = &tv;
}
for (i = 1; i < argc; i++) {
if (!FD_ISSET(fd[i], &curset))
......
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