X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fio%2Fsg_serial.cxx;h=b7b2f5a94cbca8c45d01928f6ec603eddbc0bcf7;hb=70c5d605641b628039f75cb8761ce783a17a5bdf;hp=2d409fb8f92371d3d195138d223d3f1ee457387c;hpb=22812a0aaef07c8da20b0c7e151016965e29dcff;p=simgear.git diff --git a/simgear/io/sg_serial.cxx b/simgear/io/sg_serial.cxx index 2d409fb8..b7b2f5a9 100644 --- a/simgear/io/sg_serial.cxx +++ b/simgear/io/sg_serial.cxx @@ -2,7 +2,7 @@ // // Written by Curtis Olson, started November 1999. // -// Copyright (C) 1999 Curtis L. Olson - curt@flightgear.org +// Copyright (C) 1999 Curtis L. Olson - http://www.flightgear.org/~curt // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License as @@ -16,27 +16,31 @@ // // 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. +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // // $Id$ +#include +#include #include -#include STL_STRING +#include #include #include #include "sg_serial.hxx" -FG_USING_STD(string); +using std::string; -SGSerial::SGSerial() : +SGSerial::SGSerial( const string& device_name, const string& baud_rate ) : save_len(0) { set_type( sgSerialType ); + device = device_name; + baud = baud_rate; } @@ -45,16 +49,18 @@ SGSerial::~SGSerial() { // open the serial port based on specified direction -bool SGSerial::open( SGProtocolDir dir ) { +bool SGSerial::open( const SGProtocolDir d ) { + set_dir( d ); + if ( ! port.open_port( device ) ) { - FG_LOG( FG_IO, FG_ALERT, "Error opening device: " << device ); + SG_LOG( SG_IO, SG_ALERT, "Error opening device: " << device ); return false; } // cout << "fd = " << port.fd << endl; - if ( ! port.set_baud( atoi( baud.c_str() ) ) ) { - FG_LOG( FG_IO, FG_ALERT, "Error setting baud: " << baud ); + if ( ! port.set_baud( std::atoi( baud.c_str() ) ) ) { + SG_LOG( SG_IO, SG_ALERT, "Error setting baud: " << baud ); return false; } @@ -76,7 +82,7 @@ int SGSerial::read( char *buf, int length ) { result = port.read_port( buf_ptr, length - save_len ); if ( result + save_len == length ) { - strncpy( buf, save_buf, length ); + std::strncpy( buf, save_buf, length ); save_len = 0; return length; @@ -110,9 +116,9 @@ int SGSerial::readline( char *buf, int length ) { // we found an end of line // copy to external buffer - strncpy( buf, save_buf, result ); + std::strncpy( buf, save_buf, result ); buf[result] = '\0'; - FG_LOG( FG_IO, FG_INFO, "fg_serial line = " << buf ); + SG_LOG( SG_IO, SG_INFO, "fg_serial line = " << buf ); // shift save buffer for ( i = result; i < save_len; ++i ) { @@ -125,11 +131,11 @@ int SGSerial::readline( char *buf, int length ) { // write data to port -int SGSerial::write( char *buf, int length ) { +int SGSerial::write( const char *buf, const int length ) { int result = port.write_port( buf, length ); if ( result != length ) { - FG_LOG( FG_IO, FG_ALERT, "Error writing data: " << device ); + SG_LOG( SG_IO, SG_WARN, "Error writing data: " << device ); } return result; @@ -137,8 +143,8 @@ int SGSerial::write( char *buf, int length ) { // write null terminated string to port -int SGSerial::writestring( char *str ) { - int length = strlen( str ); +int SGSerial::writestring( const char *str ) { + int length = std::strlen( str ); return write( str, length ); }