Formatting, Cleanup, & Suggested Changes
Corrected formatting, removed old commented code, made suggested code changes. Update README.mdpull/88/head
parent
384ed8d919
commit
042038fb52
|
|
@ -13,7 +13,7 @@ subsystem (aka SocketCAN):
|
|||
* canplayer : replay CAN logfiles
|
||||
* cansend : send a single frame
|
||||
* cangen : generate (random) CAN traffic
|
||||
* cansniffer : display CAN data content differences ~~(just 11bit CAN IDs)~~
|
||||
* cansniffer : display CAN data content differences
|
||||
|
||||
#### CAN access via IP sockets
|
||||
* canlogserver : log CAN frames from a remote/local host
|
||||
|
|
|
|||
50
cansniffer.c
50
cansniffer.c
|
|
@ -106,9 +106,9 @@ struct snif {
|
|||
struct can_frame notch;
|
||||
} sniftab[MAX_SLOTS];
|
||||
|
||||
|
||||
extern int optind, opterr, optopt;
|
||||
|
||||
static int idx;
|
||||
static int running = 1;
|
||||
static int clearscreen = 1;
|
||||
static int notch;
|
||||
|
|
@ -124,23 +124,23 @@ void print_snifline(int slot);
|
|||
int handle_keyb(int fd);
|
||||
int handle_frame(int fd, long currcms);
|
||||
int handle_timeo(int fd, long currcms);
|
||||
int sniftab_index(canid_t id);
|
||||
void writesettings(char* name);
|
||||
void readsettings(char* name, int sockfd);
|
||||
|
||||
int idx = 0;
|
||||
|
||||
static int sniftab_index(canid_t id);
|
||||
|
||||
int comp (const void * elem1, const void * elem2)
|
||||
{
|
||||
unsigned long f = ((struct snif*)elem1)->current.can_id;
|
||||
unsigned long s = ((struct snif*)elem2)->current.can_id;
|
||||
if (f > s) return 1;
|
||||
if (f < s) return -1;
|
||||
|
||||
if (f > s)
|
||||
return 1;
|
||||
if (f < s)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void print_usage(char *prg)
|
||||
{
|
||||
const char manual [] = {
|
||||
|
|
@ -164,20 +164,10 @@ void print_usage(char *prg)
|
|||
"29 bit IDs:\n"
|
||||
"+18FEDF55<ENTER> - add CAN-ID 0x18FEDF55\n"
|
||||
"-00000090<ENTER> - remove CAN-ID 0x00000090\n"
|
||||
/* "-42E7FF<ENTER> - remove CAN-ID 0x42E (using Bitmask)\N"*/
|
||||
/* "-500700<ENTER> - remove CAN-IDs 0x500 - 0x5FF\n"*/
|
||||
/* "+400600<ENTER> - add CAN-IDs 0x400 - 0x5FF\n"*/
|
||||
/* "+000000<ENTER> - add all CAN-IDs\n"*/
|
||||
/* "-000000<ENTER> - remove all CAN-IDs\n"*/
|
||||
/* "\n"*/
|
||||
/* "if (id & filter) == (sniff-id & filter) the action (+/-) IS PERFORMED,\N" */
|
||||
/* "which is quite easy when the filter is 000\n"*/
|
||||
"\n"
|
||||
};
|
||||
|
||||
fprintf(stderr, "\nUsage: %s [can-interface]\n", prg);
|
||||
// fprintf(stderr, "Options: -m <mask> (initial FILTER default 0x00000000)\n");
|
||||
// fprintf(stderr, " -v <value> (initial FILTER default 0x00000000)\n");
|
||||
fprintf(stderr, "Options: -q (quiet - all slots are deactivated)\n");
|
||||
fprintf(stderr, " -r <name> (read %sname from file)\n", SETFNAME);
|
||||
fprintf(stderr, " -b (start with binary mode)\n");
|
||||
|
|
@ -200,8 +190,6 @@ int main(int argc, char **argv)
|
|||
{
|
||||
fd_set rdfs;
|
||||
int s;
|
||||
// canid_t mask = 0;
|
||||
// canid_t value = 0;
|
||||
long currcms = 0;
|
||||
long lastcms = 0;
|
||||
unsigned char quiet = 0;
|
||||
|
|
@ -211,7 +199,6 @@ int main(int argc, char **argv)
|
|||
struct ifreq ifr;
|
||||
int i;
|
||||
|
||||
|
||||
signal(SIGTERM, sigterm);
|
||||
signal(SIGHUP, sigterm);
|
||||
signal(SIGINT, sigterm);
|
||||
|
|
@ -221,14 +208,6 @@ int main(int argc, char **argv)
|
|||
|
||||
while ((opt = getopt(argc, argv, "m:v:r:t:h:l:qbBcf?")) != -1) {
|
||||
switch (opt) {
|
||||
// case 'm':
|
||||
// sscanf(optarg, "%x", &mask);
|
||||
// break;
|
||||
//
|
||||
// case 'v':
|
||||
// sscanf(optarg, "%x", &value);
|
||||
// break;
|
||||
//
|
||||
case 'r':
|
||||
readsettings(optarg, 0);
|
||||
break;
|
||||
|
|
@ -281,16 +260,6 @@ int main(int argc, char **argv)
|
|||
for (i = 0; i < MAX_SLOTS; i++)
|
||||
do_clr(i, ENABLE);
|
||||
|
||||
// Change this to do socket filtering
|
||||
// else if (mask || value) {
|
||||
// for (i=0; i < MAX_SLOTS ;i++) {
|
||||
// if ((i & mask) == (value & mask))
|
||||
// do_set(i, ENABLE);
|
||||
// else
|
||||
// do_clr(i, ENABLE);
|
||||
// }
|
||||
// }
|
||||
|
||||
if (strlen(argv[optind]) >= IFNAMSIZ) {
|
||||
printf("name of CAN device '%s' is too long!\n", argv[optind]);
|
||||
return 1;
|
||||
|
|
@ -733,7 +702,6 @@ void readsettings(char* name, int sockfd){
|
|||
(__u8) strtoul(&buf[2*j+12], (char **)NULL, 16) & 0xFF;
|
||||
buf[2*j+12] = 0; /* cut off each time */
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
if (!sockfd)
|
||||
|
|
@ -752,7 +720,7 @@ void readsettings(char* name, int sockfd){
|
|||
printf("unable to read setting file '%s'!\n", fname);
|
||||
};
|
||||
|
||||
int sniftab_index(canid_t id){
|
||||
static int sniftab_index(canid_t id) {
|
||||
|
||||
int i;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue