Skip to content

Commit

Permalink
canplayer: introduce option to limit the number of processed frames
Browse files Browse the repository at this point in the history
Analogue to the '-n <count>' option to limit the number of processed CAN
frames in candump and cangen this option makes sense in canplayer too.

Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
  • Loading branch information
hartkopp committed Oct 30, 2021
1 parent ab9bd4f commit 0d84033
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion canplayer.c
Expand Up @@ -89,6 +89,8 @@ void print_usage(char *prg)
"send frames immediately)\n");
fprintf(stderr, " -i (interactive - wait "
"for ENTER key to process next frame)\n");
fprintf(stderr, " -n <count> (terminate after "
"processing <count> CAN frames)\n");
fprintf(stderr, " -g <ms> (gap in milli "
"seconds - default: %d ms)\n", DEFAULT_GAP);
fprintf(stderr, " -s <s> (skip gaps in "
Expand Down Expand Up @@ -247,6 +249,7 @@ int main(int argc, char **argv)
unsigned long gap = DEFAULT_GAP;
int use_timestamps = 1;
int interactive = 0; /* wait for ENTER keypress to process next frame */
int count = 0; /* end replay after sending count frames. 0 = disabled */
static int verbose, opt, delay_loops;
static unsigned long skipgap;
static int loopback_disable = 0;
Expand All @@ -257,7 +260,7 @@ int main(int argc, char **argv)
int eof, txmtu, i, j;
char *fret;

while ((opt = getopt(argc, argv, "I:l:tig:s:xv?")) != -1) {
while ((opt = getopt(argc, argv, "I:l:tin:g:s:xv?")) != -1) {
switch (opt) {
case 'I':
infile = fopen(optarg, "r");
Expand Down Expand Up @@ -285,6 +288,14 @@ int main(int argc, char **argv)
interactive = 1;
break;

case 'n':
count = atoi(optarg);
if (count < 1) {
print_usage(basename(argv[0]));
exit(1);
}
break;

case 'g':
gap = strtoul(optarg, NULL, 10);
break;
Expand Down Expand Up @@ -476,6 +487,9 @@ int main(int argc, char **argv)
else
fprint_long_canframe(stdout, &frame, "\n", CANLIB_VIEW_INDENT_SFF, CANFD_MAX_DLEN);
}

if (count && (--count == 0))
goto out;
}

/* read next non-comment frame from logfile */
Expand Down

0 comments on commit 0d84033

Please sign in to comment.