slcand: add flow control option
Add option '-t' to specify flow control type. Two types are supported: 'hw' - RTS/CTS and 'sw' - XON/XOFF. Signed-off-by: Yegor Yefremov <yegorslists@googlemail.com> Acked-by: Oliver Hartkopp <socketcan@hartkopp.net> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>pull/1/head
parent
c7aa0b7051
commit
38fb68fb50
30
slcand.c
30
slcand.c
|
|
@ -69,6 +69,11 @@
|
||||||
#define EXIT_SUCCESS 0
|
#define EXIT_SUCCESS 0
|
||||||
#define EXIT_FAILURE 1
|
#define EXIT_FAILURE 1
|
||||||
|
|
||||||
|
/* UART flow control types */
|
||||||
|
#define FLOW_NONE 0
|
||||||
|
#define FLOW_HW 1
|
||||||
|
#define FLOW_SW 2
|
||||||
|
|
||||||
void print_usage(char *prg)
|
void print_usage(char *prg)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "\nUsage: %s [options] <tty> [canif-name]\n\n", prg);
|
fprintf(stderr, "\nUsage: %s [options] <tty> [canif-name]\n\n", prg);
|
||||||
|
|
@ -77,6 +82,7 @@ void print_usage(char *prg)
|
||||||
fprintf(stderr, " -f (read status flags with 'F\\r' to reset error states)\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, " -S <speed> (set UART speed in baud)\n");
|
fprintf(stderr, " -S <speed> (set UART speed in baud)\n");
|
||||||
|
fprintf(stderr, " -t <type> (set UART flow control type 'hw' or 'sw')\n");
|
||||||
fprintf(stderr, " -b <btr> (set bit time register value)\n");
|
fprintf(stderr, " -b <btr> (set bit time register value)\n");
|
||||||
fprintf(stderr, " -F (stay in foreground; no daemonize)\n");
|
fprintf(stderr, " -F (stay in foreground; no daemonize)\n");
|
||||||
fprintf(stderr, " -h (show this help page)\n");
|
fprintf(stderr, " -h (show this help page)\n");
|
||||||
|
|
@ -300,6 +306,7 @@ int main(int argc, char *argv[])
|
||||||
char *speed = NULL;
|
char *speed = NULL;
|
||||||
char *uart_speed_str = NULL;
|
char *uart_speed_str = NULL;
|
||||||
long int uart_speed = 0;
|
long int uart_speed = 0;
|
||||||
|
int flow_type = FLOW_NONE;
|
||||||
char *btr = NULL;
|
char *btr = NULL;
|
||||||
int run_as_daemon = 1;
|
int run_as_daemon = 1;
|
||||||
pid_t parent_pid = 0;
|
pid_t parent_pid = 0;
|
||||||
|
|
@ -309,7 +316,7 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
ttypath[0] = '\0';
|
ttypath[0] = '\0';
|
||||||
|
|
||||||
while ((opt = getopt(argc, argv, "ocfs:S:b:?hF")) != -1) {
|
while ((opt = getopt(argc, argv, "ocfs:S:t:b:?hF")) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 'o':
|
case 'o':
|
||||||
send_open = 1;
|
send_open = 1;
|
||||||
|
|
@ -336,6 +343,16 @@ int main(int argc, char *argv[])
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case 't':
|
||||||
|
if (!strcmp(optarg, "hw")) {
|
||||||
|
flow_type = FLOW_HW;
|
||||||
|
} else if (!strcmp(optarg, "sw")) {
|
||||||
|
flow_type = FLOW_SW;
|
||||||
|
} else {
|
||||||
|
fprintf(stderr, "Unsupported flow type (%s)\n", optarg);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
break;
|
||||||
case 'b':
|
case 'b':
|
||||||
btr = optarg;
|
btr = optarg;
|
||||||
if (strlen(btr) > 6)
|
if (strlen(btr) > 6)
|
||||||
|
|
@ -401,10 +418,21 @@ int main(int argc, char *argv[])
|
||||||
old_ispeed = cfgetispeed(&tios);
|
old_ispeed = cfgetispeed(&tios);
|
||||||
old_ospeed = cfgetospeed(&tios);
|
old_ospeed = cfgetospeed(&tios);
|
||||||
|
|
||||||
|
/* Reset UART settings */
|
||||||
|
cfmakeraw(&tios);
|
||||||
|
tios.c_iflag &= ~IXOFF;
|
||||||
|
tios.c_cflag &= ~CRTSCTS;
|
||||||
|
|
||||||
/* Baud Rate */
|
/* Baud Rate */
|
||||||
cfsetispeed(&tios, look_up_uart_speed(uart_speed));
|
cfsetispeed(&tios, look_up_uart_speed(uart_speed));
|
||||||
cfsetospeed(&tios, look_up_uart_speed(uart_speed));
|
cfsetospeed(&tios, look_up_uart_speed(uart_speed));
|
||||||
|
|
||||||
|
/* Flow control */
|
||||||
|
if (flow_type == FLOW_HW)
|
||||||
|
tios.c_cflag |= CRTSCTS;
|
||||||
|
else if (flow_type == FLOW_SW)
|
||||||
|
tios.c_iflag |= (IXON | IXOFF);
|
||||||
|
|
||||||
/* apply changes */
|
/* apply changes */
|
||||||
if (tcsetattr(fd, TCSADRAIN, &tios) < 0)
|
if (tcsetattr(fd, TCSADRAIN, &tios) < 0)
|
||||||
syslog(LOG_NOTICE, "Cannot set attributes for device \"%s\": %s!\n", ttypath, strerror(errno));
|
syslog(LOG_NOTICE, "Cannot set attributes for device \"%s\": %s!\n", ttypath, strerror(errno));
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue