slcan_attach: added '-f' commandline option to read status flags.

In the case of pending bus errors on some slcan adapters the read of the
status flags resets the adapter and clears the error LED.

This patch adds the commandline option to send the status read command to the
adapter as suggested by Thorsten Godau.

Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
pull/7/head
Oliver Hartkopp 2011-01-09 11:49:20 +00:00
parent eb1a99f8c7
commit 7ef581fec0
1 changed files with 13 additions and 2 deletions

View File

@ -61,13 +61,14 @@ void print_usage(char *prg)
fprintf(stderr, "\nUsage: %s [options] tty\n\n", prg); fprintf(stderr, "\nUsage: %s [options] tty\n\n", prg);
fprintf(stderr, "Options: -o (send open command 'O\\r')\n"); fprintf(stderr, "Options: -o (send open command 'O\\r')\n");
fprintf(stderr, " -c (send close command 'C\\r')\n"); fprintf(stderr, " -c (send close command 'C\\r')\n");
fprintf(stderr, " -f (read status flags with 'F\\r' to reset error states)\n");
fprintf(stderr, " -s <speed> (set CAN speed 0..8)\n"); fprintf(stderr, " -s <speed> (set CAN speed 0..8)\n");
fprintf(stderr, " -b <btr> (set bit time register value)\n"); fprintf(stderr, " -b <btr> (set bit time register value)\n");
fprintf(stderr, " -d (only detach line discipline)\n"); fprintf(stderr, " -d (only detach line discipline)\n");
fprintf(stderr, " -w (attach - wait for keypess - detach)\n"); fprintf(stderr, " -w (attach - wait for keypess - detach)\n");
fprintf(stderr, " -n <name> (assign created netdevice name)\n"); fprintf(stderr, " -n <name> (assign created netdevice name)\n");
fprintf(stderr, "\nExamples:\n"); fprintf(stderr, "\nExamples:\n");
fprintf(stderr, "slcan_attach -w -o -s6 -c /dev/ttyS1\n"); fprintf(stderr, "slcan_attach -w -o -f -s6 -c /dev/ttyS1\n");
fprintf(stderr, "slcan_attach /dev/ttyS1\n"); fprintf(stderr, "slcan_attach /dev/ttyS1\n");
fprintf(stderr, "slcan_attach -d /dev/ttyS1\n"); fprintf(stderr, "slcan_attach -d /dev/ttyS1\n");
fprintf(stderr, "slcan_attach -w -n can15 /dev/ttyS1\n"); fprintf(stderr, "slcan_attach -w -n can15 /dev/ttyS1\n");
@ -83,6 +84,7 @@ int main(int argc, char **argv)
int waitkey = 0; int waitkey = 0;
int send_open = 0; int send_open = 0;
int send_close = 0; int send_close = 0;
int send_read_status_flags = 0;
char *speed = NULL; char *speed = NULL;
char *btr = NULL; char *btr = NULL;
char buf[IFNAMSIZ+1]; char buf[IFNAMSIZ+1];
@ -90,7 +92,7 @@ int main(int argc, char **argv)
char *name = NULL; char *name = NULL;
int opt; int opt;
while ((opt = getopt(argc, argv, "l:dwocs:b:n:?")) != -1) { while ((opt = getopt(argc, argv, "l:dwocfs:b:n:?")) != -1) {
switch (opt) { switch (opt) {
case 'l': case 'l':
fprintf(stderr, "Ignored option '-l'\n"); fprintf(stderr, "Ignored option '-l'\n");
@ -112,6 +114,10 @@ int main(int argc, char **argv)
send_close = 1; send_close = 1;
break; break;
case 'f':
send_read_status_flags = 1;
break;
case 's': case 's':
speed = optarg; speed = optarg;
if (strlen(speed) > 1) if (strlen(speed) > 1)
@ -159,6 +165,11 @@ int main(int argc, char **argv)
write(fd, buf, strlen(buf)); write(fd, buf, strlen(buf));
} }
if (send_read_status_flags) {
sprintf(buf, "F\r");
write(fd, buf, strlen(buf));
}
if (send_open) { if (send_open) {
sprintf(buf, "O\r"); sprintf(buf, "O\r");
write(fd, buf, strlen(buf)); write(fd, buf, strlen(buf));