]> git.mxchange.org Git - simgear.git/blobdiff - Serial/serial.cxx
Tweak for SGI portability.
[simgear.git] / Serial / serial.cxx
index 18173b43eace7a6b352162419f6b949d621fa0c7..01bd9d863651a8bffeddfe76a172e3e5b8fed043 100644 (file)
@@ -22,6 +22,7 @@
 // (Log is kept at end of this file)
 
 
+#include <errno.h>
 #include <termios.h>
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -46,13 +47,20 @@ fgSERIAL::fgSERIAL(const string& device, int baud) {
 }
 
 fgSERIAL::~fgSERIAL() {
-    close(fd);
+    // closing the port here screws us up because if we would even so
+    // much as make a copy of an fgSERIAL object and then delete it,
+    // the file descriptor gets closed.  Doh!!!
+
+    // close(fd);
 }
 
 bool fgSERIAL::open_port(const string& device) {
     struct termios config;
 
-    if ( (fd = open(device.c_str(), O_RDWR | O_NONBLOCK)) == -1 ) {
+    fd = open(device.c_str(), O_RDWR | O_NONBLOCK);
+    cout << "Serial fd created = " << fd << endl;
+
+    if ( fd  == -1 ) {
        FG_LOG( FG_SERIAL, FG_ALERT, "Cannot open " << device
                << " for serial I/O" );
        return false;
@@ -66,16 +74,20 @@ bool fgSERIAL::open_port(const string& device) {
        return false;
     }
 
-    cfmakeraw( &config );
+    // cfmakeraw( &config );
 
     // cout << "config.c_iflag = " << config.c_iflag << endl;
 
     // software flow control on
-    // config.c_iflag |= IXON;
+    config.c_iflag |= IXON;
     // config.c_iflag |= IXOFF;
 
+    // config.c_cflag |= CLOCAL;
+
+#if ! defined( sgi )    
     // disable hardware flow control
-    // config.c_cflag |= CRTSCTS;
+    config.c_cflag &= ~(CRTSCTS);
+#endif
 
     // cout << "config.c_iflag = " << config.c_iflag << endl;
 
@@ -87,9 +99,16 @@ bool fgSERIAL::open_port(const string& device) {
     return true;
 }
 
+
+bool fgSERIAL::close_port() {
+    close(fd);
+    return true;
+}
+
+
 bool fgSERIAL::set_baud(int baud) {
     struct termios config;
-    speed_t speed;
+    speed_t speed = B9600;
 
     if ( tcgetattr( fd, &config ) != 0 ) {
        FG_LOG( FG_SERIAL, FG_ALERT, "Unable to poll port settings" );
@@ -114,8 +133,10 @@ bool fgSERIAL::set_baud(int baud) {
        speed = B57600;
     } else if ( baud == 115200 ) {
        speed = B115200;
+#if defined( linux ) || defined( __FreeBSD__ )
     } else if ( baud == 230400 ) {
        speed = B230400;
+#endif
     } else {
        FG_LOG( FG_SERIAL, FG_ALERT, "Unsupported baud rate " << baud );
        return false;
@@ -171,8 +192,13 @@ int fgSERIAL::write_port(const string& value) {
     // cout << "write '" << value << "'  " << count << " bytes" << endl;
 
     if ( (int)count != (int)value.length() ) {
-       FG_LOG( FG_SERIAL, FG_ALERT,
-               "Serial I/O on write, error number = " << errno );
+       if ( errno == EAGAIN ) {
+           // ok ... in our context we don't really care if we can't
+           // write a string, we'll just get it the next time around
+       } else {
+           FG_LOG( FG_SERIAL, FG_ALERT,
+                   "Serial I/O on write, error number = " << errno );
+       }
     }
 
     return count;
@@ -180,6 +206,20 @@ int fgSERIAL::write_port(const string& value) {
 
 
 // $Log$
+// Revision 1.7  1998/12/04 01:24:35  curt
+// Tweak for SGI portability.
+//
+// Revision 1.6  1998/11/30 17:15:29  curt
+// Having the class destructor close the fd was a bad idea ... especially if you
+// ever make a copy of the instance and then subsequently destroy either.
+// close_port() is now a separate member function.
+//
+// Revision 1.5  1998/11/25 01:33:23  curt
+// Remove call to cfmakeraw()
+//
+// Revision 1.4  1998/11/23 21:47:00  curt
+// Cygnus tools compatibility tweaks.
+//
 // Revision 1.3  1998/11/19 13:52:54  curt
 // port configuration tweaks & experiments.
 //