From d5ef4f01b55f2bd86d9821c1feada1f74bc95a76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Fillod=2C=20F8CFE?= Date: Thu, 7 Mar 2002 22:49:00 +0000 Subject: [PATCH] split serial_open in open and serial_setup git-svn-id: https://hamlib.svn.sourceforge.net/svnroot/hamlib/trunk@1012 7ae35d74-ebe9-4afe-98af-79ac388436b8 --- src/serial.c | 65 +++++++++++++++++++++++++++++++++------------------- src/serial.h | 5 ++-- 2 files changed, 45 insertions(+), 25 deletions(-) diff --git a/src/serial.c b/src/serial.c index b0c1e2aa8..6c18714c0 100644 --- a/src/serial.c +++ b/src/serial.c @@ -1,10 +1,10 @@ /* * Hamlib Interface - serial communication low-level support - * Copyright (c) 2000,2001,2002 by Stephane Fillod and Frank Singleton + * Copyright (c) 2000-2002 by Stephane Fillod and Frank Singleton * Parts of the PTT handling are derived from soundmodem, an excellent * ham packet softmodem written by Thomas Sailer, HB9JNX. * - * $Id: serial.c,v 1.24 2002-01-22 21:17:54 fillods Exp $ + * $Id: serial.c,v 1.25 2002-03-07 22:49:00 fillods Exp $ * * This library is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as @@ -86,17 +86,7 @@ int serial_open(port_t *rp) { int fd; /* File descriptor for the port */ - speed_t speed; /* serial comm speed */ - -#ifdef HAVE_TERMIOS_H - struct termios options; -#elif defined(HAVE_TERMIO_H) - struct termio options; -#elif defined(HAVE_SGTTY_H) - struct sgttyb sg; -#else -#error "No term control supported!" -#endif + int err; if (!rp) return -RIG_EINVAL; @@ -115,6 +105,45 @@ int serial_open(port_t *rp) { return -RIG_EIO; } + rp->fd = fd; + + err = serial_setup(rp); + if (err != RIG_OK) { + close(fd); + return err; + } + + rp->stream = fdopen(fd, "r+b"); + if (rp->stream == NULL) { + rig_debug(RIG_DEBUG_ERR, "open_serial: fdopen failed: %s\n", + strerror(errno)); + close(fd); + return -RIG_EIO; /* arg, so close! */ + } + + return RIG_OK; +} + + +int serial_setup(port_t *rp) +{ + speed_t speed; /* serial comm speed */ + int fd; +#ifdef HAVE_TERMIOS_H + struct termios options; +#elif defined(HAVE_TERMIO_H) + struct termio options; +#elif defined(HAVE_SGTTY_H) + struct sgttyb sg; +#else +#error "No term control supported!" +#endif + + if (!rp) + return -RIG_EINVAL; + + fd = rp->fd; + /* * Get the current options for the port... */ @@ -328,16 +357,6 @@ int serial_open(port_t *rp) { } #endif - rp->stream = fdopen(fd, "r+b"); - if (rp->stream == NULL) { - rig_debug(RIG_DEBUG_ERR, "open_serial: fdopen failed: %s\n", - strerror(errno)); - close(fd); - return -RIG_EIO; /* arg, so close! */ - } - - rp->fd = fd; - return RIG_OK; } diff --git a/src/serial.h b/src/serial.h index 19738ce49..233d04fc6 100644 --- a/src/serial.h +++ b/src/serial.h @@ -1,8 +1,8 @@ /* * Hamlib Interface - serial communication header - * Copyright (c) 2000,2001 by Stephane Fillod and Frank Singleton + * Copyright (c) 2000-2002 by Stephane Fillod and Frank Singleton * - * $Id: serial.h,v 1.16 2002-01-16 22:58:50 fillods Exp $ + * $Id: serial.h,v 1.17 2002-03-07 22:49:00 fillods Exp $ * * This library is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as @@ -28,6 +28,7 @@ extern HAMLIB_EXPORT(int) serial_open(port_t *rs); +extern HAMLIB_EXPORT(int) serial_setup(port_t *rs); extern HAMLIB_EXPORT(int) serial_flush(port_t *p); /* Hamlib internal use, see rig.c */