canplayer: Format code according to .clang-format
parent
4657d02b1f
commit
ad850776c3
57
canplayer.c
57
canplayer.c
|
|
@ -81,18 +81,22 @@ void print_usage(char *prg)
|
||||||
fprintf(stderr, "\nUsage: %s <options> [interface assignment]*\n\n", prg);
|
fprintf(stderr, "\nUsage: %s <options> [interface assignment]*\n\n", prg);
|
||||||
fprintf(stderr, "Options:\n");
|
fprintf(stderr, "Options:\n");
|
||||||
fprintf(stderr, " -I <infile> (default stdin)\n");
|
fprintf(stderr, " -I <infile> (default stdin)\n");
|
||||||
fprintf(stderr, " -l <num> "
|
fprintf(stderr,
|
||||||
|
" -l <num> "
|
||||||
"(process input file <num> times)\n"
|
"(process input file <num> times)\n"
|
||||||
" "
|
" "
|
||||||
"(Use 'i' for infinite loop - default: %d)\n", DEFAULT_LOOPS);
|
"(Use 'i' for infinite loop - default: %d)\n",
|
||||||
|
DEFAULT_LOOPS);
|
||||||
fprintf(stderr, " -t (ignore timestamps: "
|
fprintf(stderr, " -t (ignore timestamps: "
|
||||||
"send frames immediately)\n");
|
"send frames immediately)\n");
|
||||||
fprintf(stderr, " -i (interactive - wait "
|
fprintf(stderr, " -i (interactive - wait "
|
||||||
"for ENTER key to process next frame)\n");
|
"for ENTER key to process next frame)\n");
|
||||||
fprintf(stderr, " -n <count> (terminate after "
|
fprintf(stderr, " -n <count> (terminate after "
|
||||||
"processing <count> CAN frames)\n");
|
"processing <count> CAN frames)\n");
|
||||||
fprintf(stderr, " -g <ms> (gap in milli "
|
fprintf(stderr,
|
||||||
"seconds - default: %d ms)\n", DEFAULT_GAP);
|
" -g <ms> (gap in milli "
|
||||||
|
"seconds - default: %d ms)\n",
|
||||||
|
DEFAULT_GAP);
|
||||||
fprintf(stderr, " -s <s> (skip gaps in "
|
fprintf(stderr, " -s <s> (skip gaps in "
|
||||||
"timestamps > 's' seconds)\n");
|
"timestamps > 's' seconds)\n");
|
||||||
fprintf(stderr, " -x (disable local "
|
fprintf(stderr, " -x (disable local "
|
||||||
|
|
@ -125,16 +129,14 @@ static inline int timeval_compare(struct timeval *lhs, struct timeval *rhs)
|
||||||
return lhs->tv_usec - rhs->tv_usec;
|
return lhs->tv_usec - rhs->tv_usec;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void create_diff_tv(struct timeval *today, struct timeval *diff,
|
static inline void create_diff_tv(struct timeval *today, struct timeval *diff, struct timeval *log)
|
||||||
struct timeval *log) {
|
{
|
||||||
|
|
||||||
/* create diff_tv so that log_tv + diff_tv = today_tv */
|
/* create diff_tv so that log_tv + diff_tv = today_tv */
|
||||||
diff->tv_sec = today->tv_sec - log->tv_sec;
|
diff->tv_sec = today->tv_sec - log->tv_sec;
|
||||||
diff->tv_usec = today->tv_usec - log->tv_usec;
|
diff->tv_usec = today->tv_usec - log->tv_usec;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int frames_to_send(struct timeval *today, struct timeval *diff,
|
static inline int frames_to_send(struct timeval *today, struct timeval *diff, struct timeval *log)
|
||||||
struct timeval *log)
|
|
||||||
{
|
{
|
||||||
/* return value <0 when log + diff < today */
|
/* return value <0 when log + diff < today */
|
||||||
|
|
||||||
|
|
@ -156,8 +158,8 @@ static inline int frames_to_send(struct timeval *today, struct timeval *diff,
|
||||||
return timeval_compare(&cmp, today);
|
return timeval_compare(&cmp, today);
|
||||||
}
|
}
|
||||||
|
|
||||||
int get_txidx(char *logif_name) {
|
int get_txidx(char *logif_name)
|
||||||
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < CHANNELS; i++) {
|
for (i = 0; i < CHANNELS; i++) {
|
||||||
|
|
@ -173,8 +175,8 @@ int get_txidx(char *logif_name) {
|
||||||
return asgn[i].txifidx; /* return interface index */
|
return asgn[i].txifidx; /* return interface index */
|
||||||
}
|
}
|
||||||
|
|
||||||
char *get_txname(char *logif_name) {
|
char *get_txname(char *logif_name)
|
||||||
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < CHANNELS; i++) {
|
for (i = 0; i < CHANNELS; i++) {
|
||||||
|
|
@ -190,9 +192,8 @@ char *get_txname(char *logif_name) {
|
||||||
return asgn[i].txif; /* return interface name */
|
return asgn[i].txif; /* return interface name */
|
||||||
}
|
}
|
||||||
|
|
||||||
int add_assignment(char *mode, int socket, char *txname, char *rxname,
|
int add_assignment(char *mode, int socket, char *txname, char *rxname, int verbose)
|
||||||
int verbose) {
|
{
|
||||||
|
|
||||||
struct ifreq ifr;
|
struct ifreq ifr;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
|
@ -231,8 +232,7 @@ int add_assignment(char *mode, int socket, char *txname, char *rxname,
|
||||||
asgn[i].txifidx = STDOUTIDX;
|
asgn[i].txifidx = STDOUTIDX;
|
||||||
|
|
||||||
if (verbose > 1) /* use -v -v to see this */
|
if (verbose > 1) /* use -v -v to see this */
|
||||||
printf("added %s assignment: log-if=%s write-if=%s write-if-idx=%d\n",
|
printf("added %s assignment: log-if=%s write-if=%s write-if-idx=%d\n", mode, asgn[i].rxif, asgn[i].txif, asgn[i].txifidx);
|
||||||
mode, asgn[i].rxif, asgn[i].txif, asgn[i].txifidx);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -273,8 +273,7 @@ int main(int argc, char **argv)
|
||||||
case 'l':
|
case 'l':
|
||||||
if (optarg[0] == 'i')
|
if (optarg[0] == 'i')
|
||||||
infinite_loops = 1;
|
infinite_loops = 1;
|
||||||
else
|
else if (!(loops = atoi(optarg))) {
|
||||||
if (!(loops = atoi(optarg))) {
|
|
||||||
fprintf(stderr, "Invalid argument for option -l !\n");
|
fprintf(stderr, "Invalid argument for option -l !\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
@ -365,8 +364,7 @@ int main(int argc, char **argv)
|
||||||
if (loopback_disable) {
|
if (loopback_disable) {
|
||||||
int loopback = 0;
|
int loopback = 0;
|
||||||
|
|
||||||
setsockopt(s, SOL_CAN_RAW, CAN_RAW_LOOPBACK,
|
setsockopt(s, SOL_CAN_RAW, CAN_RAW_LOOPBACK, &loopback, sizeof(loopback));
|
||||||
&loopback, sizeof(loopback));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bind(s, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
|
if (bind(s, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
|
||||||
|
|
@ -399,7 +397,6 @@ int main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
while (infinite_loops || loops--) {
|
while (infinite_loops || loops--) {
|
||||||
|
|
||||||
if (infile != stdin)
|
if (infile != stdin)
|
||||||
rewind(infile); /* for each loop */
|
rewind(infile); /* for each loop */
|
||||||
|
|
||||||
|
|
@ -419,8 +416,7 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
eof = 0;
|
eof = 0;
|
||||||
|
|
||||||
if (sscanf(buf, "(%lu.%lu) %s %s", &log_tv.tv_sec, &log_tv.tv_usec,
|
if (sscanf(buf, "(%lu.%lu) %s %s", &log_tv.tv_sec, &log_tv.tv_usec, device, ascframe) != 4) {
|
||||||
device, ascframe) != 4) {
|
|
||||||
fprintf(stderr, "incorrect line format in logfile\n");
|
fprintf(stderr, "incorrect line format in logfile\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
@ -442,10 +438,7 @@ int main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
while (!eof) {
|
while (!eof) {
|
||||||
|
while ((!use_timestamps) || (frames_to_send(&today_tv, &diff_tv, &log_tv) < 0)) {
|
||||||
while ((!use_timestamps) ||
|
|
||||||
(frames_to_send(&today_tv, &diff_tv, &log_tv) < 0)) {
|
|
||||||
|
|
||||||
/* wait for keypress to process next frame */
|
/* wait for keypress to process next frame */
|
||||||
if (interactive)
|
if (interactive)
|
||||||
getchar();
|
getchar();
|
||||||
|
|
@ -514,8 +507,7 @@ int main(int argc, char **argv)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sscanf(buf, "(%lu.%lu) %s %s", &log_tv.tv_sec, &log_tv.tv_usec,
|
if (sscanf(buf, "(%lu.%lu) %s %s", &log_tv.tv_sec, &log_tv.tv_usec, device, ascframe) != 4) {
|
||||||
device, ascframe) != 4) {
|
|
||||||
fprintf(stderr, "incorrect line format in logfile\n");
|
fprintf(stderr, "incorrect line format in logfile\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
@ -534,8 +526,7 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
/* test for logfile timestamps jumping backwards OR */
|
/* test for logfile timestamps jumping backwards OR */
|
||||||
/* if the user likes to skip long gaps in the timestamps */
|
/* if the user likes to skip long gaps in the timestamps */
|
||||||
if ((last_log_tv.tv_sec > log_tv.tv_sec) ||
|
if ((last_log_tv.tv_sec > log_tv.tv_sec) || (skipgap && labs(last_log_tv.tv_sec - log_tv.tv_sec) > (long)skipgap))
|
||||||
(skipgap && labs(last_log_tv.tv_sec - log_tv.tv_sec) > (long)skipgap))
|
|
||||||
create_diff_tv(&today_tv, &diff_tv, &log_tv);
|
create_diff_tv(&today_tv, &diff_tv, &log_tv);
|
||||||
|
|
||||||
last_log_tv = log_tv;
|
last_log_tv = log_tv;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue