cansniffer: increase resolution for timeout values

As requested by Felix Seitz the timeout for screen updates should be
configurable to values smaller than 100ms. Marc Kleine-Budde provided the
original patch to increase the resolution of the timing relevant variables.

The rotating animation was replaced by a rolling screen update counter.
Additionally the CAN-ID is now printed in the same ASCII hex representation
as the CAN data.

Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
pull/1/head
Marc Kleine-Budde 2014-06-24 21:16:48 +02:00 committed by Oliver Hartkopp
parent 53779e43eb
commit 18f8416a40
1 changed files with 13 additions and 14 deletions

View File

@ -86,16 +86,13 @@
/* time defaults */ /* time defaults */
#define TIMEOUT 50 /* in 100ms */ #define TIMEOUT 500 /* in 10ms */
#define HOLD 10 /* in 100ms */ #define HOLD 100 /* in 10ms */
#define LOOP 2 /* in 100ms */ #define LOOP 20 /* in 10ms */
#define MAXANI 8
const char anichar[MAXANI] = {'|', '/', '-', '\\', '|', '/', '-', '\\'};
#define ATTCOLOR ATTBOLD FGRED #define ATTCOLOR ATTBOLD FGRED
#define STARTLINESTR "X time ID data ... " #define STARTLINESTR "XX delta ID data ... "
struct snif { struct snif {
int flags; int flags;
@ -172,9 +169,9 @@ void print_usage(char *prg)
fprintf(stderr, " -B (start with binary mode with gap - exceeds 80 chars!)\n"); fprintf(stderr, " -B (start with binary mode with gap - exceeds 80 chars!)\n");
fprintf(stderr, " -c (color changes)\n"); fprintf(stderr, " -c (color changes)\n");
fprintf(stderr, " -f (filter on CAN-ID only)\n"); fprintf(stderr, " -f (filter on CAN-ID only)\n");
fprintf(stderr, " -t <time> (timeout for ID display [x100ms] default: %d, 0 = OFF)\n", TIMEOUT); fprintf(stderr, " -t <time> (timeout for ID display [x10ms] default: %d, 0 = OFF)\n", TIMEOUT);
fprintf(stderr, " -h <time> (hold marker on changes [x100ms] default: %d)\n", HOLD); fprintf(stderr, " -h <time> (hold marker on changes [x10ms] default: %d)\n", HOLD);
fprintf(stderr, " -l <time> (loop time (display) [x100ms] default: %d)\n", LOOP); fprintf(stderr, " -l <time> (loop time (display) [x10ms] default: %d)\n", LOOP);
fprintf(stderr, "Use interface name '%s' to receive from all can-interfaces\n", ANYDEV); fprintf(stderr, "Use interface name '%s' to receive from all can-interfaces\n", ANYDEV);
fprintf(stderr, "\n"); fprintf(stderr, "\n");
fprintf(stderr, "%s", manual); fprintf(stderr, "%s", manual);
@ -329,7 +326,7 @@ int main(int argc, char **argv)
FD_SET(s, &rdfs); FD_SET(s, &rdfs);
timeo.tv_sec = 0; timeo.tv_sec = 0;
timeo.tv_usec = 100000 * loop; timeo.tv_usec = 10000 * loop;
if ((ret = select(s+1, &rdfs, NULL, NULL, &timeo)) < 0) { if ((ret = select(s+1, &rdfs, NULL, NULL, &timeo)) < 0) {
//perror("select"); //perror("select");
@ -338,7 +335,7 @@ int main(int argc, char **argv)
} }
gettimeofday(&tv, NULL); gettimeofday(&tv, NULL);
currcms = (tv.tv_sec - start_tv.tv_sec) * 10 + (tv.tv_usec / 100000); currcms = (tv.tv_sec - start_tv.tv_sec) * 100 + (tv.tv_usec / 10000);
if (FD_ISSET(0, &rdfs)) if (FD_ISSET(0, &rdfs))
running &= handle_keyb(s); running &= handle_keyb(s);
@ -538,6 +535,7 @@ int handle_timeo(int fd, long currcms){
int i; int i;
int force_redraw = 0; int force_redraw = 0;
static unsigned int frame_count;
if (clearscreen) { if (clearscreen) {
char startline[80]; char startline[80];
@ -555,7 +553,8 @@ int handle_timeo(int fd, long currcms){
} }
printf("%s", CSR_HOME); printf("%s", CSR_HOME);
printf("%c\n", anichar[currcms % MAXANI]); /* funny animation */ printf("%02d\n", frame_count++); /* rolling display update counter */
frame_count %= 100;
for (i=0; i < 2048; i++) { for (i=0; i < 2048; i++) {
@ -608,7 +607,7 @@ void print_snifline(int id){
if (diffsec > 10) if (diffsec > 10)
diffsec = 9, diffusec = 999999; diffsec = 9, diffusec = 999999;
printf("%ld.%06ld %3x ", diffsec, diffusec, id); printf("%ld.%06ld %3X ", diffsec, diffusec, id);
if (binary) { if (binary) {