1999-11-19 02:10:24 +00:00
|
|
|
// protocol.cxx -- High level protocal class
|
|
|
|
//
|
|
|
|
// Written by Curtis Olson, started November 1999.
|
|
|
|
//
|
2004-11-19 22:10:41 +00:00
|
|
|
// Copyright (C) 1999 Curtis L. Olson - http://www.flightgear.org/~curt
|
1999-11-19 02:10:24 +00:00
|
|
|
//
|
|
|
|
// 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 program 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.
|
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
// $Id$
|
|
|
|
|
|
|
|
|
2000-02-16 23:01:03 +00:00
|
|
|
#include <simgear/debug/logstream.hxx>
|
2000-07-11 20:40:12 +00:00
|
|
|
#include <simgear/io/iochannel.hxx>
|
1999-11-19 02:10:24 +00:00
|
|
|
|
|
|
|
#include "protocol.hxx"
|
|
|
|
|
|
|
|
|
|
|
|
FGProtocol::FGProtocol() :
|
|
|
|
hz(0.0),
|
2002-12-14 14:37:40 +00:00
|
|
|
count_down(0.0),
|
|
|
|
count(0),
|
1999-11-19 02:10:24 +00:00
|
|
|
enabled(false)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FGProtocol::~FGProtocol() {
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-19 03:02:49 +00:00
|
|
|
// standard I/O channel open routine
|
1999-11-19 02:10:24 +00:00
|
|
|
bool FGProtocol::open() {
|
1999-11-19 03:02:49 +00:00
|
|
|
if ( is_enabled() ) {
|
2001-03-24 06:03:11 +00:00
|
|
|
SG_LOG( SG_IO, SG_ALERT, "This shouldn't happen, but the channel "
|
1999-11-19 03:02:49 +00:00
|
|
|
<< "is already in use, ignoring" );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2000-07-11 20:40:12 +00:00
|
|
|
SGIOChannel *io = get_io_channel();
|
1999-11-19 03:02:49 +00:00
|
|
|
|
|
|
|
if ( ! io->open( get_direction() ) ) {
|
2001-03-24 06:03:11 +00:00
|
|
|
SG_LOG( SG_IO, SG_ALERT, "Error opening channel communication layer." );
|
1999-11-19 03:02:49 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
set_enabled( true );
|
|
|
|
|
|
|
|
return true;
|
1999-11-19 02:10:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// dummy process routine
|
|
|
|
bool FGProtocol::process() {
|
2001-03-24 06:03:11 +00:00
|
|
|
SG_LOG( SG_IO, SG_INFO, "dummy FGProtocol::process()" );
|
1999-11-19 02:10:24 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// dummy close routine
|
|
|
|
bool FGProtocol::close() {
|
2001-03-24 06:03:11 +00:00
|
|
|
SG_LOG( SG_IO, SG_INFO, "dummy FGProtocol::close()" );
|
1999-11-19 02:10:24 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-19 03:02:49 +00:00
|
|
|
// standard I/O channel close routine
|
1999-11-19 02:10:24 +00:00
|
|
|
bool FGProtocol::gen_message() {
|
2000-07-11 20:40:12 +00:00
|
|
|
SGIOChannel *io = get_io_channel();
|
1999-11-19 03:02:49 +00:00
|
|
|
|
|
|
|
set_enabled( false );
|
|
|
|
|
|
|
|
if ( ! io->close() ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
1999-11-19 02:10:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// dummy close routine
|
|
|
|
bool FGProtocol::parse_message() {
|
2001-03-24 06:03:11 +00:00
|
|
|
SG_LOG( SG_IO, SG_INFO, "dummy FGProtocol::close()" );
|
1999-11-19 02:10:24 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-05-15 21:44:34 +00:00
|
|
|
void FGProtocol::set_direction( const string& d ) {
|
|
|
|
if ( d == "in" ) {
|
|
|
|
dir = SG_IO_IN;
|
|
|
|
} else if ( d == "out" ) {
|
|
|
|
dir = SG_IO_OUT;
|
|
|
|
} else if ( d == "bi" ) {
|
|
|
|
dir = SG_IO_BI;
|
|
|
|
} else {
|
|
|
|
dir = SG_IO_NONE;
|
|
|
|
}
|
|
|
|
}
|