cansniffer: formatting and variable renaming

Some unification of code formatting and rename of a variable in
print_snifline() which does not represent a CAN ID anymore.

Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
pull/200/head
Oliver Hartkopp 2020-04-29 18:56:25 +02:00
parent ac55db508a
commit ab2e8ffe0e
1 changed files with 48 additions and 55 deletions

View File

@ -128,7 +128,7 @@ static char *interface;
static char *vdl = LDL; /* variable delimiter */ static char *vdl = LDL; /* variable delimiter */
static char *ldl = LDL; /* long delimiter */ static char *ldl = LDL; /* long delimiter */
void print_snifline(int id); void print_snifline(int slot);
int handle_keyb(int fd); int handle_keyb(int fd);
int handle_frame(int fd, long currcms); int handle_frame(int fd, long currcms);
int handle_timeo(long currcms); int handle_timeo(long currcms);
@ -397,8 +397,8 @@ void do_modify_sniftab(unsigned int value, unsigned int mask, char cmd)
} }
} }
int handle_keyb(int fd){ int handle_keyb(int fd)
{
char cmd [25] = {0}; char cmd [25] = {0};
int i, clen; int i, clen;
unsigned int mask; unsigned int mask;
@ -545,8 +545,8 @@ int handle_keyb(int fd){
return 1; /* ok */ return 1; /* ok */
}; };
int handle_frame(int fd, long currcms){ int handle_frame(int fd, long currcms)
{
bool rx_changed = false; bool rx_changed = false;
bool run_qsort = false; bool run_qsort = false;
int nbytes, i, pos; int nbytes, i, pos;
@ -620,8 +620,8 @@ int handle_frame(int fd, long currcms){
return 1; /* ok */ return 1; /* ok */
}; };
int handle_timeo(long currcms){ int handle_timeo(long currcms)
{
int i, j; int i, j;
int force_redraw = 0; int force_redraw = 0;
static unsigned int frame_count; static unsigned int frame_count;
@ -651,18 +651,14 @@ int handle_timeo(long currcms){
frame_count %= 100; frame_count %= 100;
for (i = 0; i < idx; i++) { for (i = 0; i < idx; i++) {
if is_set(i, ENABLE) { if is_set(i, ENABLE) {
if is_set(i, DISPLAY) { if is_set(i, DISPLAY) {
if (is_set(i, UPDATE) || (force_redraw)) { if (is_set(i, UPDATE) || (force_redraw)) {
print_snifline(i); print_snifline(i);
sniftab[i].hold = currcms + hold; sniftab[i].hold = currcms + hold;
do_clr(i, UPDATE); do_clr(i, UPDATE);
} }
else else if ((sniftab[i].hold) && (sniftab[i].hold < currcms)) {
if ((sniftab[i].hold) && (sniftab[i].hold < currcms)) {
memset(&sniftab[i].marker.data, 0, 8); memset(&sniftab[i].marker.data, 0, 8);
print_snifline(i); print_snifline(i);
sniftab[i].hold = 0; /* disable update by hold */ sniftab[i].hold = 0; /* disable update by hold */
@ -681,15 +677,14 @@ int handle_timeo(long currcms){
} }
return 1; /* ok */ return 1; /* ok */
}; };
void print_snifline(int id){ void print_snifline(int slot)
{
long diffsec = sniftab[id].currstamp.tv_sec - sniftab[id].laststamp.tv_sec; long diffsec = sniftab[slot].currstamp.tv_sec - sniftab[slot].laststamp.tv_sec;
long diffusec = sniftab[id].currstamp.tv_usec - sniftab[id].laststamp.tv_usec; long diffusec = sniftab[slot].currstamp.tv_usec - sniftab[slot].laststamp.tv_usec;
int dlc_diff = sniftab[id].last.can_dlc - sniftab[id].current.can_dlc; int dlc_diff = sniftab[slot].last.can_dlc - sniftab[slot].current.can_dlc;
canid_t cid = sniftab[id].current.can_id; canid_t cid = sniftab[slot].current.can_id;
int i,j; int i,j;
if (diffusec < 0) if (diffusec < 0)
@ -709,17 +704,16 @@ void print_snifline(int id){
printf("%02ld%03ld%s%03X%s", diffsec, diffusec/1000, ldl, cid & CAN_SFF_MASK, ldl); printf("%02ld%03ld%s%03X%s", diffsec, diffusec/1000, ldl, cid & CAN_SFF_MASK, ldl);
if (binary) { if (binary) {
for (i = 0; i < sniftab[slot].current.can_dlc; i++) {
for (i=0; i<sniftab[id].current.can_dlc; i++) {
for (j=7; j >= 0; j--) { for (j=7; j >= 0; j--) {
if ((color) && (sniftab[id].marker.data[i] & 1<<j) && if ((color) && (sniftab[slot].marker.data[i] & 1<<j) &&
(!(sniftab[id].notch.data[i] & 1<<j))) (!(sniftab[slot].notch.data[i] & 1<<j)))
if (sniftab[id].current.data[i] & 1<<j) if (sniftab[slot].current.data[i] & 1<<j)
printf("%s1%s", ATTCOLOR, ATTRESET); printf("%s1%s", ATTCOLOR, ATTRESET);
else else
printf("%s0%s", ATTCOLOR, ATTRESET); printf("%s0%s", ATTCOLOR, ATTRESET);
else else
if (sniftab[id].current.data[i] & 1<<j) if (sniftab[slot].current.data[i] & 1<<j)
putchar('1'); putchar('1');
else else
putchar('0'); putchar('0');
@ -739,23 +733,22 @@ void print_snifline(int id){
} }
} }
else { else {
for (i = 0; i < sniftab[slot].current.can_dlc; i++)
for (i=0; i<sniftab[id].current.can_dlc; i++) if ((color) && (sniftab[slot].marker.data[i] & ~sniftab[slot].notch.data[i]))
if ((color) && (sniftab[id].marker.data[i] & ~sniftab[id].notch.data[i])) printf("%s%02X%s ", ATTCOLOR, sniftab[slot].current.data[i], ATTRESET);
printf("%s%02X%s ", ATTCOLOR, sniftab[id].current.data[i], ATTRESET);
else else
printf("%02X ", sniftab[id].current.data[i]); printf("%02X ", sniftab[slot].current.data[i]);
if (sniftab[id].current.can_dlc < 8) if (sniftab[slot].current.can_dlc < 8)
printf("%*s", (8 - sniftab[id].current.can_dlc) * 3, ""); printf("%*s", (8 - sniftab[slot].current.can_dlc) * 3, "");
for (i=0; i<sniftab[id].current.can_dlc; i++) for (i = 0; i<sniftab[slot].current.can_dlc; i++)
if ((sniftab[id].current.data[i] > 0x1F) && if ((sniftab[slot].current.data[i] > 0x1F) &&
(sniftab[id].current.data[i] < 0x7F)) (sniftab[slot].current.data[i] < 0x7F))
if ((color) && (sniftab[id].marker.data[i] & ~sniftab[id].notch.data[i])) if ((color) && (sniftab[slot].marker.data[i] & ~sniftab[slot].notch.data[i]))
printf("%s%c%s", ATTCOLOR, sniftab[id].current.data[i], ATTRESET); printf("%s%c%s", ATTCOLOR, sniftab[slot].current.data[i], ATTRESET);
else else
putchar(sniftab[id].current.data[i]); putchar(sniftab[slot].current.data[i]);
else else
putchar('.'); putchar('.');
@ -769,11 +762,11 @@ void print_snifline(int id){
putchar('\n'); putchar('\n');
memset(&sniftab[id].marker.data, 0, 8); memset(&sniftab[slot].marker.data, 0, 8);
}; };
void writesettings(char* name){ void writesettings(char* name)
{
int fd; int fd;
char fname[30] = SETFNAME; char fname[30] = SETFNAME;
int i,j; int i,j;
@ -802,8 +795,8 @@ void writesettings(char* name){
printf("unable to write setting file '%s'!\n", fname); printf("unable to write setting file '%s'!\n", fname);
}; };
int readsettings(char* name) { int readsettings(char* name)
{
int fd; int fd;
char fname[30] = SETFNAME; char fname[30] = SETFNAME;
char buf[25] = {0}; char buf[25] = {0};