Skip to content

Commit

Permalink
slcan_attach: added '-f' commandline option to read status flags.
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
hartkopp committed Jan 9, 2011
1 parent eb1a99f commit 7ef581f
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions slcan_attach.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,14 @@ void print_usage(char *prg)
fprintf(stderr, "\nUsage: %s [options] tty\n\n", prg);
fprintf(stderr, "Options: -o (send open command 'O\\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, " -b <btr> (set bit time register value)\n");
fprintf(stderr, " -d (only detach line discipline)\n");
fprintf(stderr, " -w (attach - wait for keypess - detach)\n");
fprintf(stderr, " -n <name> (assign created netdevice name)\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 -d /dev/ttyS1\n");
fprintf(stderr, "slcan_attach -w -n can15 /dev/ttyS1\n");
Expand All @@ -83,14 +84,15 @@ int main(int argc, char **argv)
int waitkey = 0;
int send_open = 0;
int send_close = 0;
int send_read_status_flags = 0;
char *speed = NULL;
char *btr = NULL;
char buf[IFNAMSIZ+1];
char *tty;
char *name = NULL;
int opt;

while ((opt = getopt(argc, argv, "l:dwocs:b:n:?")) != -1) {
while ((opt = getopt(argc, argv, "l:dwocfs:b:n:?")) != -1) {
switch (opt) {
case 'l':
fprintf(stderr, "Ignored option '-l'\n");
Expand All @@ -112,6 +114,10 @@ int main(int argc, char **argv)
send_close = 1;
break;

case 'f':
send_read_status_flags = 1;
break;

case 's':
speed = optarg;
if (strlen(speed) > 1)
Expand Down Expand Up @@ -159,6 +165,11 @@ int main(int argc, char **argv)
write(fd, buf, strlen(buf));
}

if (send_read_status_flags) {
sprintf(buf, "F\r");
write(fd, buf, strlen(buf));
}

if (send_open) {
sprintf(buf, "O\r");
write(fd, buf, strlen(buf));
Expand Down

0 comments on commit 7ef581f

Please sign in to comment.