//
// 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
#include "sg_serial.hxx"
-FG_USING_STD(string);
+SG_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;
}
// 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 );
+ SG_LOG( SG_IO, SG_ALERT, "Error setting baud: " << baud );
return false;
}
// copy to external buffer
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 ) {
// 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;
// write null terminated string to port
-int SGSerial::writestring( char *str ) {
+int SGSerial::writestring( const char *str ) {
int length = strlen( str );
return write( str, length );
}