From e88894e34db4cb1f1dc28dbff244a5d145b42a6c Mon Sep 17 00:00:00 2001 From: fengzero Date: Fri, 7 Jul 2023 09:13:01 +0000 Subject: [PATCH] serial: using smart link --- src/connection/connection.c | 9 ++++++--- src/connection/smart_link.c | 4 +++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/connection/connection.c b/src/connection/connection.c index 885b3b19..d5513191 100644 --- a/src/connection/connection.c +++ b/src/connection/connection.c @@ -854,15 +854,18 @@ static void conn_connect(neu_conn_t *conn) break; } case NEU_CONN_TTY_CLIENT: { + struct termios tty_opt = { 0 }; #ifdef NEU_SMART_LINK #include "connection/neu_smart_link.h" int ret = neu_conn_smart_link_auto_set(conn->param.params.tty_client.device); zlog_notice(conn->param.log, "smart link ret: %d", ret); -#endif - struct termios tty_opt = { 0 }; - + if (ret > 0) { + fd = ret; + } +#else fd = open(conn->param.params.tty_client.device, O_RDWR | O_NOCTTY, 0); +#endif if (fd <= 0) { zlog_error(conn->param.log, "open %s error: %s(%d)", conn->param.params.tty_client.device, strerror(errno), diff --git a/src/connection/smart_link.c b/src/connection/smart_link.c index 4d1b4ccb..f6e3d719 100644 --- a/src/connection/smart_link.c +++ b/src/connection/smart_link.c @@ -230,7 +230,7 @@ static int set_serial_mode(const char *dev_path, int baudrate, int mode) break; } - if ((serial_fd = open(dev_path, O_RDWR | O_NOCTTY | O_NDELAY)) < 0) { + if ((serial_fd = open(dev_path, O_RDWR | O_NOCTTY)) < 0) { fprintf(stderr, "open %s failed, fd: %d, strerr: %s\n", dev_path, serial_fd, strerror(errno)); goto out; @@ -276,7 +276,9 @@ static int set_serial_mode(const char *dev_path, int baudrate, int mode) close(switch_fd); out2: close(serial_fd); + serial_fd = -1; out: pthread_mutex_unlock(&mode_switch_mtx); + ret = serial_fd; return ret; }