Skip to content

Commit e9dd86f

Browse files
Merge pull request #300 from hartkopp/master
canplayer: add interactive single-step frame processing mode
2 parents affdc1b + aaa7fd2 commit e9dd86f

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

canplayer.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ void print_usage(char *prg)
8787
"(Use 'i' for infinite loop - default: %d)\n", DEFAULT_LOOPS);
8888
fprintf(stderr, " -t (ignore timestamps: "
8989
"send frames immediately)\n");
90+
fprintf(stderr, " -i (interactive - wait "
91+
"for ENTER key to process next frame)\n");
9092
fprintf(stderr, " -g <ms> (gap in milli "
9193
"seconds - default: %d ms)\n", DEFAULT_GAP);
9294
fprintf(stderr, " -s <s> (skip gaps in "
@@ -244,6 +246,7 @@ int main(int argc, char **argv)
244246
FILE *infile = stdin;
245247
unsigned long gap = DEFAULT_GAP;
246248
int use_timestamps = 1;
249+
int interactive = 0; /* wait for ENTER keypress to process next frame */
247250
static int verbose, opt, delay_loops;
248251
static unsigned long skipgap;
249252
static int loopback_disable = 0;
@@ -254,7 +257,7 @@ int main(int argc, char **argv)
254257
int eof, txmtu, i, j;
255258
char *fret;
256259

257-
while ((opt = getopt(argc, argv, "I:l:tg:s:xv?")) != -1) {
260+
while ((opt = getopt(argc, argv, "I:l:tig:s:xv?")) != -1) {
258261
switch (opt) {
259262
case 'I':
260263
infile = fopen(optarg, "r");
@@ -278,6 +281,10 @@ int main(int argc, char **argv)
278281
use_timestamps = 0;
279282
break;
280283

284+
case 'i':
285+
interactive = 1;
286+
break;
287+
281288
case 'g':
282289
gap = strtoul(optarg, NULL, 10);
283290
break;
@@ -320,6 +327,12 @@ int main(int argc, char **argv)
320327
printf("%d loops\n", loops);
321328
}
322329

330+
/* ignore timestamps from logfile when in single step keypress mode */
331+
if (interactive) {
332+
use_timestamps = 0;
333+
printf("interactive mode: press ENTER to process next CAN frame ...\n");
334+
}
335+
323336
sleep_ts.tv_sec = gap / 1000;
324337
sleep_ts.tv_nsec = (gap % 1000) * 1000000;
325338

@@ -413,6 +426,10 @@ int main(int argc, char **argv)
413426
while ((!use_timestamps) ||
414427
(frames_to_send(&today_tv, &diff_tv, &log_tv) < 0)) {
415428

429+
/* wait for keypress to process next frame */
430+
if (interactive)
431+
getchar();
432+
416433
/* log_tv/device/ascframe are valid here */
417434

418435
if (strlen(device) >= IFNAMSIZ) {

0 commit comments

Comments
 (0)