]> git.mxchange.org Git - simgear.git/blobdiff - simgear/serial/serial.cxx
Add a function which might return whether a texture is in video memory, delete the...
[simgear.git] / simgear / serial / serial.cxx
index 7bac809c06aadcd8bc1fab5960d6ea22aeb4ce7f..aca930a6136e25a03821a5a943fc89b4c7cdd416 100644 (file)
@@ -4,30 +4,29 @@
 //
 // Copyright (C) 1998  Curtis L. Olson - curt@flightgear.org
 //
-// This program is free software; you can redistribute it and/or
-// modify it under the terms of the GNU General Public License as
-// published by the Free Software Foundation; either version 2 of the
-// License, or (at your option) any later version.
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Library General Public
+// License as published by the Free Software Foundation; either
+// version 2 of the License, or (at your option) any later version.
 //
-// This program is distributed in the hope that it will be useful, but
-// WITHOUT ANY WARRANTY; without even the implied warranty of
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-// General Public License for more details.
+// Library General Public License for more details.
 //
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+// You should have received a copy of the GNU Library General Public
+// License along with this library; if not, write to the
+// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+// Boston, MA  02111-1307, USA.
 //
 // $Id$
 
 
-#ifdef HAVE_CONFIG_H
-#  include <config.h>
-#endif
-
 #include <simgear/compiler.h>
 
-#ifdef FG_HAVE_STD_INCLUDE
+#include STL_IOSTREAM
+
+#ifdef SG_HAVE_STD_INCLUDE
 #  include <cerrno>
 #else
 #  include <errno.h>
 #  include <unistd.h>
 #endif
 
-#include <simgear/logstream.hxx>
+#include <simgear/debug/logstream.hxx>
 
 #include "serial.hxx"
 
-
-FGSerialPort::FGSerialPort()
+SGSerialPort::SGSerialPort()
     : dev_open(false)
 {
     // empty
 }
 
-FGSerialPort::FGSerialPort(const string& device, int baud) {
+SGSerialPort::SGSerialPort(const string& device, int baud) {
     open_port(device);
     
     if ( dev_open ) {
@@ -62,13 +60,13 @@ FGSerialPort::FGSerialPort(const string& device, int baud) {
     }
 }
 
-FGSerialPort::~FGSerialPort() {
+SGSerialPort::~SGSerialPort() {
     // closing the port here screws us up because if we would even so
-    // much as make a copy of an FGSerialPort object and then delete it,
+    // much as make a copy of an SGSerialPort object and then delete it,
     // the file descriptor gets closed.  Doh!!!
 }
 
-bool FGSerialPort::open_port(const string& device) {
+bool SGSerialPort::open_port(const string& device) {
 
 #if defined( WIN32 ) && !defined( __CYGWIN__) && !defined( __CYGWIN32__ )
 
@@ -93,7 +91,7 @@ bool FGSerialPort::open_port(const string& device) {
             0,
             NULL );
 
-        FG_LOG( FG_IO, FG_ALERT, "Error opening serial device \"" 
+        SG_LOG( SG_IO, SG_ALERT, "Error opening serial device \"" 
             << device << "\" " << (const char*) lpMsgBuf );
         LocalFree( lpMsgBuf );
         return false;
@@ -107,10 +105,10 @@ bool FGSerialPort::open_port(const string& device) {
     struct termios config;
 
     fd = open(device.c_str(), O_RDWR | O_NONBLOCK);
-    cout << "Serial fd created = " << fd << endl;
+    SG_LOG( SG_EVENT, SG_DEBUG, "Serial fd created = " << fd);
 
     if ( fd  == -1 ) {
-       FG_LOG( FG_IO, FG_ALERT, "Cannot open " << device
+       SG_LOG( SG_IO, SG_ALERT, "Cannot open " << device
                << " for serial I/O" );
        return false;
     } else {
@@ -119,7 +117,7 @@ bool FGSerialPort::open_port(const string& device) {
 
     // set required port parameters 
     if ( tcgetattr( fd, &config ) != 0 ) {
-       FG_LOG( FG_IO, FG_ALERT, "Unable to poll port settings" );
+       SG_LOG( SG_IO, SG_ALERT, "Unable to poll port settings" );
        return false;
     }
 
@@ -141,7 +139,7 @@ bool FGSerialPort::open_port(const string& device) {
     // cout << "config.c_iflag = " << config.c_iflag << endl;
 
     if ( tcsetattr( fd, TCSANOW, &config ) != 0 ) {
-       FG_LOG( FG_IO, FG_ALERT, "Unable to update port settings" );
+       SG_LOG( SG_IO, SG_ALERT, "Unable to update port settings" );
        return false;
     }
 
@@ -150,7 +148,7 @@ bool FGSerialPort::open_port(const string& device) {
 }
 
 
-bool FGSerialPort::close_port() {
+bool SGSerialPort::close_port() {
 #if defined( WIN32 ) && !defined( __CYGWIN__) && !defined( __CYGWIN32__ )
     CloseHandle( fd );
 #else
@@ -163,7 +161,7 @@ bool FGSerialPort::close_port() {
 }
 
 
-bool FGSerialPort::set_baud(int baud) {
+bool SGSerialPort::set_baud(int baud) {
 
 #if defined( WIN32 ) && !defined( __CYGWIN__) && !defined( __CYGWIN32__ )
 
@@ -175,7 +173,7 @@ bool FGSerialPort::set_baud(int baud) {
     speed_t speed = B9600;
 
     if ( tcgetattr( fd, &config ) != 0 ) {
-       FG_LOG( FG_IO, FG_ALERT, "Unable to poll port settings" );
+       SG_LOG( SG_IO, SG_ALERT, "Unable to poll port settings" );
        return false;
     }
 
@@ -202,22 +200,22 @@ bool FGSerialPort::set_baud(int baud) {
        speed = B230400;
 #endif
     } else {
-       FG_LOG( FG_IO, FG_ALERT, "Unsupported baud rate " << baud );
+       SG_LOG( SG_IO, SG_ALERT, "Unsupported baud rate " << baud );
        return false;
     }
 
     if ( cfsetispeed( &config, speed ) != 0 ) {
-       FG_LOG( FG_IO, FG_ALERT, "Problem setting input baud rate" );
+       SG_LOG( SG_IO, SG_ALERT, "Problem setting input baud rate" );
        return false;
     }
 
     if ( cfsetospeed( &config, speed ) != 0 ) {
-       FG_LOG( FG_IO, FG_ALERT, "Problem setting output baud rate" );
+       SG_LOG( SG_IO, SG_ALERT, "Problem setting output baud rate" );
        return false;
     }
 
     if ( tcsetattr( fd, TCSANOW, &config ) != 0 ) {
-       FG_LOG( FG_IO, FG_ALERT, "Unable to update port settings" );
+       SG_LOG( SG_IO, SG_ALERT, "Unable to update port settings" );
        return false;
     }
 
@@ -227,7 +225,7 @@ bool FGSerialPort::set_baud(int baud) {
 
 }
 
-string FGSerialPort::read_port() {
+string SGSerialPort::read_port() {
 
 #if defined( WIN32 ) && !defined( __CYGWIN__) && !defined( __CYGWIN32__ )
 
@@ -247,7 +245,7 @@ string FGSerialPort::read_port() {
     if ( count < 0 ) {
        // error condition
        if ( errno != EAGAIN ) {
-           FG_LOG( FG_IO, FG_ALERT, 
+           SG_LOG( SG_IO, SG_ALERT, 
                    "Serial I/O on read, error number = " << errno );
        }
 
@@ -263,7 +261,7 @@ string FGSerialPort::read_port() {
 
 }
 
-int FGSerialPort::read_port(char *buf, int len) {
+int SGSerialPort::read_port(char *buf, int len) {
 
 #if defined( WIN32 ) && !defined( __CYGWIN__) && !defined( __CYGWIN32__ )
 
@@ -280,7 +278,7 @@ int FGSerialPort::read_port(char *buf, int len) {
     if ( count < 0 ) {
        // error condition
        if ( errno != EAGAIN ) {
-           FG_LOG( FG_IO, FG_ALERT, 
+           SG_LOG( SG_IO, SG_ALERT, 
                    "Serial I/O on read, error number = " << errno );
        }
 
@@ -297,7 +295,7 @@ int FGSerialPort::read_port(char *buf, int len) {
 }
 
 
-int FGSerialPort::write_port(const string& value) {
+int SGSerialPort::write_port(const string& value) {
 
 #if defined( WIN32 ) && !defined( __CYGWIN__) && !defined( __CYGWIN32__ )
 
@@ -324,7 +322,7 @@ int FGSerialPort::write_port(const string& value) {
             0,
             NULL );
 
-        FG_LOG( FG_IO, FG_ALERT, "Serial I/O write error: " 
+        SG_LOG( SG_IO, SG_ALERT, "Serial I/O write error: " 
              << (const char*) lpMsgBuf );
         LocalFree( lpMsgBuf );
         return int(lpNumberOfBytesWritten);
@@ -338,7 +336,7 @@ int FGSerialPort::write_port(const string& value) {
     int count;
 
     if ( error ) {
-        FG_LOG( FG_IO, FG_ALERT, "attempting serial write error recovery" );
+        SG_LOG( SG_IO, SG_ALERT, "attempting serial write error recovery" );
        // attempt some sort of error recovery
        count = write(fd, "\n", 1);
        if ( count == 1 ) {
@@ -361,7 +359,7 @@ int FGSerialPort::write_port(const string& value) {
            error = false;
        } else {
            error = true;
-           FG_LOG( FG_IO, FG_ALERT,
+           SG_LOG( SG_IO, SG_ALERT,
                    "Serial I/O on write, error number = " << errno );
        }
     }
@@ -373,7 +371,7 @@ int FGSerialPort::write_port(const string& value) {
 }
 
 
-int FGSerialPort::write_port(const char* buf, int len) {
+int SGSerialPort::write_port(const char* buf, int len) {
 #if defined( WIN32 ) && !defined( __CYGWIN__) && !defined( __CYGWIN32__ )
 
     LPCVOID lpBuffer = buf;
@@ -399,7 +397,7 @@ int FGSerialPort::write_port(const char* buf, int len) {
             0,
             NULL );
 
-        FG_LOG( FG_IO, FG_ALERT, "Serial I/O write error: " 
+        SG_LOG( SG_IO, SG_ALERT, "Serial I/O write error: " 
              << (const char*) lpMsgBuf );
         LocalFree( lpMsgBuf );
         return int(lpNumberOfBytesWritten);
@@ -434,7 +432,7 @@ int FGSerialPort::write_port(const char* buf, int len) {
            // 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_IO, FG_ALERT,
+           SG_LOG( SG_IO, SG_ALERT,
                    "Serial I/O on write, error number = " << errno );
        }
     }