1
0
Fork 0

Added httpd protocol so you can interface to a running copy of FlightGear

via a web browser, see README.IO for more details.
This commit is contained in:
curt 2001-08-21 21:13:55 +00:00
parent b6520485ca
commit c2e6992b5e
5 changed files with 103 additions and 83 deletions

View file

@ -79,7 +79,7 @@ fgfs_LDADD = \
-lsgmath -lsgbucket -lsgdebug -lsgmagvar -lsgmisc -lsgxml \ -lsgmath -lsgbucket -lsgdebug -lsgmagvar -lsgmisc -lsgxml \
$(SERIAL_LIBS) \ $(SERIAL_LIBS) \
$(THREAD_LIBS) \ $(THREAD_LIBS) \
-lplibpu -lplibfnt -lplibssg -lplibsg \ -lplibpu -lplibfnt -lplibnet -lplibssg -lplibsg \
-lmk4 -lz \ -lmk4 -lz \
$(opengl_LIBS) \ $(opengl_LIBS) \
$(audio_LIBS) $(audio_LIBS)

View file

@ -23,6 +23,8 @@
#include <simgear/compiler.h> #include <simgear/compiler.h>
#include <stdlib.h> // atoi()
#include STL_STRING #include STL_STRING
#include <simgear/debug/logstream.hxx> #include <simgear/debug/logstream.hxx>
@ -36,6 +38,7 @@
#include <Network/protocol.hxx> #include <Network/protocol.hxx>
#include <Network/atlas.hxx> #include <Network/atlas.hxx>
#include <Network/garmin.hxx> #include <Network/garmin.hxx>
#include <Network/httpd.hxx>
#include <Network/joyclient.hxx> #include <Network/joyclient.hxx>
#include <Network/native.hxx> #include <Network/native.hxx>
#include <Network/native_ctrls.hxx> #include <Network/native_ctrls.hxx>
@ -57,6 +60,8 @@ io_container global_io_list;
// configure a port based on the config string // configure a port based on the config string
static FGProtocol *parse_port_config( const string& config ) static FGProtocol *parse_port_config( const string& config )
{ {
bool short_circuit = false;
string::size_type begin, end; string::size_type begin, end;
begin = 0; begin = 0;
@ -80,6 +85,12 @@ static FGProtocol *parse_port_config( const string& config )
} else if ( protocol == "garmin" ) { } else if ( protocol == "garmin" ) {
FGGarmin *garmin = new FGGarmin; FGGarmin *garmin = new FGGarmin;
io = garmin; io = garmin;
} else if ( protocol == "httpd" ) {
// determine port
string port = config.substr(begin);
FGHttpd *httpd = new FGHttpd( atoi(port.c_str()) );
io = httpd;
short_circuit = true;
} else if ( protocol == "joyclient" ) { } else if ( protocol == "joyclient" ) {
FGJoyClient *joyclient = new FGJoyClient; FGJoyClient *joyclient = new FGJoyClient;
io = joyclient; io = joyclient;
@ -108,90 +119,92 @@ static FGProtocol *parse_port_config( const string& config )
return NULL; return NULL;
} }
// determine medium if ( ! short_circuit ) {
end = config.find(",", begin); // determine medium
if ( end == string::npos ) { end = config.find(",", begin);
return NULL; // dummy if ( end == string::npos ) {
} return NULL; // dummy
}
string medium = config.substr(begin, end - begin); string medium = config.substr(begin, end - begin);
begin = end + 1; begin = end + 1;
SG_LOG( SG_IO, SG_INFO, " medium = " << medium ); SG_LOG( SG_IO, SG_INFO, " medium = " << medium );
// determine direction // determine direction
end = config.find(",", begin); end = config.find(",", begin);
if ( end == string::npos ) { if ( end == string::npos ) {
return NULL; // dummy return NULL; // dummy
} }
string direction = config.substr(begin, end - begin); string direction = config.substr(begin, end - begin);
begin = end + 1; begin = end + 1;
io->set_direction( direction ); io->set_direction( direction );
SG_LOG( SG_IO, SG_INFO, " direction = " << direction ); SG_LOG( SG_IO, SG_INFO, " direction = " << direction );
// determine hertz // determine hertz
end = config.find(",", begin); end = config.find(",", begin);
if ( end == string::npos ) { if ( end == string::npos ) {
return NULL; // dummy return NULL; // dummy
} }
string hertz_str = config.substr(begin, end - begin); string hertz_str = config.substr(begin, end - begin);
begin = end + 1; begin = end + 1;
double hertz = atof( hertz_str.c_str() ); double hertz = atof( hertz_str.c_str() );
io->set_hz( hertz ); io->set_hz( hertz );
SG_LOG( SG_IO, SG_INFO, " hertz = " << hertz ); SG_LOG( SG_IO, SG_INFO, " hertz = " << hertz );
if ( medium == "serial" ) { if ( medium == "serial" ) {
// device name // device name
end = config.find(",", begin); end = config.find(",", begin);
if ( end == string::npos ) { if ( end == string::npos ) {
return NULL; return NULL;
} }
string device = config.substr(begin, end - begin); string device = config.substr(begin, end - begin);
begin = end + 1; begin = end + 1;
SG_LOG( SG_IO, SG_INFO, " device = " << device ); SG_LOG( SG_IO, SG_INFO, " device = " << device );
// baud // baud
string baud = config.substr(begin); string baud = config.substr(begin);
SG_LOG( SG_IO, SG_INFO, " baud = " << baud ); SG_LOG( SG_IO, SG_INFO, " baud = " << baud );
SGSerial *ch = new SGSerial( device, baud ); SGSerial *ch = new SGSerial( device, baud );
io->set_io_channel( ch ); io->set_io_channel( ch );
} else if ( medium == "file" ) { } else if ( medium == "file" ) {
// file name // file name
string file = config.substr(begin); string file = config.substr(begin);
SG_LOG( SG_IO, SG_INFO, " file name = " << file ); SG_LOG( SG_IO, SG_INFO, " file name = " << file );
SGFile *ch = new SGFile( file ); SGFile *ch = new SGFile( file );
io->set_io_channel( ch ); io->set_io_channel( ch );
} else if ( medium == "socket" ) { } else if ( medium == "socket" ) {
// hostname // hostname
end = config.find(",", begin); end = config.find(",", begin);
if ( end == string::npos ) { if ( end == string::npos ) {
return NULL; return NULL;
} }
string hostname = config.substr(begin, end - begin); string hostname = config.substr(begin, end - begin);
begin = end + 1; begin = end + 1;
SG_LOG( SG_IO, SG_INFO, " hostname = " << hostname ); SG_LOG( SG_IO, SG_INFO, " hostname = " << hostname );
// port string // port string
end = config.find(",", begin); end = config.find(",", begin);
if ( end == string::npos ) { if ( end == string::npos ) {
return NULL; return NULL;
} }
string port = config.substr(begin, end - begin); string port = config.substr(begin, end - begin);
begin = end + 1; begin = end + 1;
SG_LOG( SG_IO, SG_INFO, " port string = " << port ); SG_LOG( SG_IO, SG_INFO, " port string = " << port );
// socket style // socket style
string style_str = config.substr(begin); string style_str = config.substr(begin);
SG_LOG( SG_IO, SG_INFO, " style string = " << style_str ); SG_LOG( SG_IO, SG_INFO, " style string = " << style_str );
SGSocket *ch = new SGSocket( hostname, port, style_str ); SGSocket *ch = new SGSocket( hostname, port, style_str );
io->set_io_channel( ch ); io->set_io_channel( ch );
}
} }
return io; return io;

View file

@ -60,6 +60,7 @@
// # include <GL/glext.h> // # include <GL/glext.h>
// #endif // #endif
#include <plib/netChat.h>
#include <plib/pu.h> #include <plib/pu.h>
#include <plib/ssg.h> #include <plib/ssg.h>
@ -1517,7 +1518,10 @@ int mainLoop( int argc, char **argv ) {
"GLUT event handler initialization failed ..." ); "GLUT event handler initialization failed ..." );
exit(-1); exit(-1);
} }
// Initialize plib net interface
netInit( &argc, argv );
// Initialize ssg (from plib). Needs to come before we do any // Initialize ssg (from plib). Needs to come before we do any
// other ssg stuff, but after opengl/glut has been initialized. // other ssg stuff, but after opengl/glut has been initialized.
ssgInit(); ssgInit();

View file

@ -456,7 +456,7 @@ parse_fov( const string& arg ) {
// filename = file system file name // filename = file system file name
static bool static bool
parse_channel( const string& type, const string& channel_str ) { add_channel( const string& type, const string& channel_str ) {
// cout << "Channel string = " << channel_str << endl; // cout << "Channel string = " << channel_str << endl;
globals->get_channel_options_list()->push_back( type + "," + channel_str ); globals->get_channel_options_list()->push_back( type + "," + channel_str );
@ -789,25 +789,27 @@ parse_option (const string& arg)
} else if ( arg == "--hud-culled" ) { } else if ( arg == "--hud-culled" ) {
fgSetString("/sim/hud/frame-stat-type", "culled"); fgSetString("/sim/hud/frame-stat-type", "culled");
} else if ( arg.find( "--atlas=" ) == 0 ) { } else if ( arg.find( "--atlas=" ) == 0 ) {
parse_channel( "atlas", arg.substr(8) ); add_channel( "atlas", arg.substr(8) );
} else if ( arg.find( "--httpd=" ) == 0 ) {
add_channel( "httpd", arg.substr(8) );
} else if ( arg.find( "--native=" ) == 0 ) { } else if ( arg.find( "--native=" ) == 0 ) {
parse_channel( "native", arg.substr(9) ); add_channel( "native", arg.substr(9) );
} else if ( arg.find( "--native-ctrls=" ) == 0 ) { } else if ( arg.find( "--native-ctrls=" ) == 0 ) {
parse_channel( "native_ctrls", arg.substr(15) ); add_channel( "native_ctrls", arg.substr(15) );
} else if ( arg.find( "--garmin=" ) == 0 ) { } else if ( arg.find( "--garmin=" ) == 0 ) {
parse_channel( "garmin", arg.substr(9) ); add_channel( "garmin", arg.substr(9) );
} else if ( arg.find( "--nmea=" ) == 0 ) { } else if ( arg.find( "--nmea=" ) == 0 ) {
parse_channel( "nmea", arg.substr(7) ); add_channel( "nmea", arg.substr(7) );
} else if ( arg.find( "--props=" ) == 0 ) { } else if ( arg.find( "--props=" ) == 0 ) {
parse_channel( "props", arg.substr(8) ); add_channel( "props", arg.substr(8) );
} else if ( arg.find( "--pve=" ) == 0 ) { } else if ( arg.find( "--pve=" ) == 0 ) {
parse_channel( "pve", arg.substr(6) ); add_channel( "pve", arg.substr(6) );
} else if ( arg.find( "--ray=" ) == 0 ) { } else if ( arg.find( "--ray=" ) == 0 ) {
parse_channel( "ray", arg.substr(6) ); add_channel( "ray", arg.substr(6) );
} else if ( arg.find( "--rul=" ) == 0 ) { } else if ( arg.find( "--rul=" ) == 0 ) {
parse_channel( "rul", arg.substr(6) ); add_channel( "rul", arg.substr(6) );
} else if ( arg.find( "--joyclient=" ) == 0 ) { } else if ( arg.find( "--joyclient=" ) == 0 ) {
parse_channel( "joyclient", arg.substr(12) ); add_channel( "joyclient", arg.substr(12) );
#ifdef FG_NETWORK_OLK #ifdef FG_NETWORK_OLK
} else if ( arg == "--disable-network-olk" ) { } else if ( arg == "--disable-network-olk" ) {
fgSetBool("/sim/networking/olk", false); fgSetBool("/sim/networking/olk", false);

View file

@ -4,6 +4,7 @@ libNetwork_a_SOURCES = \
protocol.cxx protocol.hxx \ protocol.cxx protocol.hxx \
atlas.cxx atlas.hxx \ atlas.cxx atlas.hxx \
garmin.cxx garmin.hxx \ garmin.cxx garmin.hxx \
httpd.cxx httpd.hxx \
joyclient.cxx joyclient.hxx \ joyclient.cxx joyclient.hxx \
native.cxx native.hxx \ native.cxx native.hxx \
native_ctrls.cxx native_ctrls.hxx \ native_ctrls.cxx native_ctrls.hxx \