diff --git a/configure.ac b/configure.ac index 490ddecf8..e60b948f1 100644 --- a/configure.ac +++ b/configure.ac @@ -553,6 +553,8 @@ AC_CONFIG_FILES([ \ tests/Makefile \ utils/Makefile \ utils/TerraSync/Makefile \ + utils/js_server/Makefile \ + utils/3dconvert/Makefile \ ]) AC_OUTPUT diff --git a/src/ATC/tower.cxx b/src/ATC/tower.cxx index 4d809fec8..90be4c30f 100644 --- a/src/ATC/tower.cxx +++ b/src/ATC/tower.cxx @@ -18,6 +18,8 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#include // bcopy() + #include
#include #include diff --git a/src/Main/fg_io.cxx b/src/Main/fg_io.cxx index e3514841e..55c84f752 100644 --- a/src/Main/fg_io.cxx +++ b/src/Main/fg_io.cxx @@ -46,6 +46,7 @@ # include #endif #include +#include #include #include #include @@ -138,6 +139,9 @@ FGIO::parse_port_config( const string& config ) } else if ( protocol == "joyclient" ) { FGJoyClient *joyclient = new FGJoyClient; io = joyclient; + } else if ( protocol == "jsclient" ) { + FGJsClient *jsclient = new FGJsClient; + io = jsclient; } else if ( protocol == "native" ) { FGNative *native = new FGNative; io = native; diff --git a/src/Main/options.cxx b/src/Main/options.cxx index 53daa5c80..01c072a57 100644 --- a/src/Main/options.cxx +++ b/src/Main/options.cxx @@ -1367,6 +1367,7 @@ struct OptionDesc { {"ray", true, OPTION_CHANNEL, "", false, "", 0 }, {"rul", true, OPTION_CHANNEL, "", false, "", 0 }, {"joyclient", true, OPTION_CHANNEL, "", false, "", 0 }, + {"jsclient", true, OPTION_CHANNEL, "", false, "", 0 }, #ifdef FG_NETWORK_OLK {"disable-network-olk", false, OPTION_BOOL, "/sim/networking/olk", false, "", 0 }, {"enable-network-olk", false, OPTION_BOOL, "/sim/networking/olk", true, "", 0 }, diff --git a/src/Network/Makefile.am b/src/Network/Makefile.am index 19617bf19..9f24828d9 100644 --- a/src/Network/Makefile.am +++ b/src/Network/Makefile.am @@ -20,6 +20,7 @@ libNetwork_a_SOURCES = \ httpd.cxx httpd.hxx \ $(JPEG_SERVER) \ joyclient.cxx joyclient.hxx \ + jsclient.cxx jsclient.hxx \ native.cxx native.hxx \ native_ctrls.cxx native_ctrls.hxx \ native_fdm.cxx native_fdm.hxx \ diff --git a/src/Network/jsclient.cxx b/src/Network/jsclient.cxx new file mode 100644 index 000000000..7a59e78ea --- /dev/null +++ b/src/Network/jsclient.cxx @@ -0,0 +1,127 @@ +// jsclient.cxx -- simple UDP networked joystick client +// +// Copyright (C) 2003 by Manuel Bessler and Stephen Lowry +// +// based on joyclient.cxx by Curtis Olson +// Copyright (C) 2000 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 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$ + + +#include +#include + +#include + +#include "jsclient.hxx" + + +FGJsClient::FGJsClient() { +} + +FGJsClient::~FGJsClient() { +} + + +// open hailing frequencies +bool FGJsClient::open() { + if ( is_enabled() ) { + SG_LOG( SG_IO, SG_ALERT, "This shouldn't happen, but the channel " + << "is already in use, ignoring" ); + return false; + } + + SGIOChannel *io = get_io_channel(); + + if ( ! io->open( get_direction() ) ) { + SG_LOG( SG_IO, SG_ALERT, "Error opening channel communication layer." ); + return false; + } + + set_enabled( true ); + + return true; +} + + +// process work for this port +bool FGJsClient::process() { + SGIOChannel *io = get_io_channel(); + int length = 4+4+4+4+4+4; + + if ( get_direction() == SG_IO_OUT ) { + SG_LOG( SG_IO, SG_ALERT, "JsClient protocol is read only" ); + return false; + } else if ( get_direction() == SG_IO_IN ) { + SG_LOG( SG_IO, SG_DEBUG, "Searching for data." ); + if ( io->get_type() == sgFileType ) { + if ( io->read( (char *)(& buf), length ) == length ) { + SG_LOG( SG_IO, SG_DEBUG, "Success reading data." ); + long int *msg; + msg = (long int *)buf; + SG_LOG( SG_IO, SG_DEBUG, "ax0 = " << msg[0] << " ax1 = " + << msg[1] << "ax2 = " << msg[2] << "ax3 = " << msg[3]); + double axis1 = ((double)msg[0] / 2147483647.0); + double axis2 = ((double)msg[1] / 2147483647.0); + if ( fabs(axis1) < 0.05 ) { + axis1 = 0.0; + } + if ( fabs(axis2) < 0.05 ) { + axis2 = 0.0; + } + globals->get_controls()->set_throttle(FGControls::ALL_ENGINES, axis1); +// globals->get_controls()->set_aileron( axis1 ); +// globals->get_controls()->set_elevator( -axis2 ); + } + } else { + while ( io->read( (char *)(& buf), length ) == length ) { + SG_LOG( SG_IO, SG_DEBUG, "Success reading data." ); + long int *msg; + msg = (long int *)buf; + SG_LOG( SG_IO, SG_DEBUG, "ax0 = " << msg[0] << " ax1 = " + << msg[1] << "ax2 = " << msg[2] << "ax3 = " << msg[3]); + double axis1 = ((double)msg[0] / 2147483647.0); + double axis2 = ((double)msg[1] / 2147483647.0); + if ( fabs(axis1) < 0.05 ) { + axis1 = 0.0; + } + if ( fabs(axis2) < 0.05 ) { + axis2 = 0.0; + } + globals->get_controls()->set_throttle(FGControls::ALL_ENGINES, axis1); +// globals->get_controls()->set_aileron( axis1 ); +// globals->get_controls()->set_elevator( -axis2 ); + } + } + } + + return true; +} + + +// close the channel +bool FGJsClient::close() { + SGIOChannel *io = get_io_channel(); + + set_enabled( false ); + + if ( ! io->close() ) { + return false; + } + + return true; +} diff --git a/src/Network/jsclient.hxx b/src/Network/jsclient.hxx new file mode 100644 index 000000000..612ec34d9 --- /dev/null +++ b/src/Network/jsclient.hxx @@ -0,0 +1,61 @@ +// jsclient.cxx -- simple UDP networked jsstick client +// +// Copyright (C) 2003 by Manuel Bessler and Stephen Lowry +// +// based on jsclient.cxx by Curtis Olson +// Copyright (C) 2000 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 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$ + + +#ifndef _FG_JSCLIENT_HXX +#define _FG_JSCLIENT_HXX + + +#include + +#include STL_STRING + +#include + +#include "protocol.hxx" + +SG_USING_STD(string); + + +class FGJsClient : public FGProtocol { + + char buf[256]; + int length; + +public: + + FGJsClient(); + ~FGJsClient(); + + // open hailing frequencies + bool open(); + + // process work for this port + bool process(); + + // close the channel + bool close(); +}; + + +#endif // _FG_JSCLIENT_HXX diff --git a/utils/3dconvert/.cvsignore b/utils/3dconvert/.cvsignore new file mode 100644 index 000000000..661fa8a93 --- /dev/null +++ b/utils/3dconvert/.cvsignore @@ -0,0 +1,4 @@ +.deps +Makefile +Makefile.in +3dconvert diff --git a/utils/3dconvert/3dconvert.cxx b/utils/3dconvert/3dconvert.cxx new file mode 100644 index 000000000..6ffc1ac7b --- /dev/null +++ b/utils/3dconvert/3dconvert.cxx @@ -0,0 +1,32 @@ +#include +#include +#include + +using std::cerr; +using std::endl; + + +int +main (int ac, char ** av) +{ + if (ac != 3) { + cerr << "Usage: " << av[0] << " " << endl; + return 1; + } + + int fakeac = 1; + char * fakeav[] = { "3dconvert", + "Convert a 3D Model", + 0 }; + glutInit(&fakeac, fakeav); + glutCreateWindow(fakeav[1]); + + ssgInit(); + ssgEntity * object = ssgLoad(av[1]); + if (object == 0) { + cerr << "Failed to load " << av[1] << endl; + return 2; + } + + ssgSave(av[2], object); +} diff --git a/utils/3dconvert/Makefile.am b/utils/3dconvert/Makefile.am new file mode 100644 index 000000000..a2cd52e57 --- /dev/null +++ b/utils/3dconvert/Makefile.am @@ -0,0 +1,4 @@ +bin_PROGRAMS = 3dconvert + +3dconvert_SOURCES = 3dconvert.cxx +3dconvert_LDADD = -lplibssg -lplibsg -lplibul $(opengl_LIBS) diff --git a/utils/Makefile.am b/utils/Makefile.am index cca72a72c..61c2ecf36 100644 --- a/utils/Makefile.am +++ b/utils/Makefile.am @@ -1 +1 @@ -SUBDIRS = TerraSync +SUBDIRS = TerraSync js_server 3dconvert diff --git a/utils/js_server/.cvsignore b/utils/js_server/.cvsignore new file mode 100644 index 000000000..39c9a08ff --- /dev/null +++ b/utils/js_server/.cvsignore @@ -0,0 +1,4 @@ +.deps +Makefile +Makefile.in +js_server diff --git a/utils/js_server/Makefile.am b/utils/js_server/Makefile.am new file mode 100644 index 000000000..de629c901 --- /dev/null +++ b/utils/js_server/Makefile.am @@ -0,0 +1,4 @@ +sbin_PROGRAMS = js_server + +js_server_SOURCES = js_server.cxx +js_server_LDADD = -lplibjs -lplibnet -lplibul diff --git a/utils/js_server/js_server.cxx b/utils/js_server/js_server.cxx new file mode 100644 index 000000000..141ff90bf --- /dev/null +++ b/utils/js_server/js_server.cxx @@ -0,0 +1,141 @@ +/* + Plib based joystick server based on PLIBs js_demo.cxx + + js_server is Copyright (C) 2003 + by Stephen Lowry and Manuel Bessler + + PLIB - A Suite of Portable Game Libraries + Copyright (C) 2001 Steve Baker + + 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + For further information visit http://plib.sourceforge.net + +*/ + +#include +#include +#include +#include + +void usage(char * progname) +{ + printf("This is an UDP based remote joystick server.\n"); + printf("usage: %s \n", progname); +} + +int main ( int argc, char ** argv ) +{ + jsJoystick * js ; + float * ax; + int port = 16759; + char * host; /* = "192.168.1.7"; */ + int activeaxes = 4; + + if( argc != 3 ) + { + usage(argv[0]); + exit(1); + } + host = argv[1]; + port = atoi(argv[2]); + + jsInit () ; + + js = new jsJoystick ( 0 ) ; + + if ( js->notWorking () ) + { + printf ( "no Joystick detected... exitting\n" ) ; + exit(1); + } + printf ( "Joystick is \"%s\"\n", js->getName() ) ; + + int numaxes = js->getNumAxes(); + ax = new float [ numaxes ] ; + activeaxes = numaxes; + + if( numaxes < 4 ) + { + printf("max 4 axes joysticks supported at the moment, however %i axes were detected\nWill only use the first 4 axes!\n", numaxes); + activeaxes = 4; + } + + // Must call this before any other net stuff + netInit( &argc,argv ); + + netSocket c; + + if ( ! c.open( false ) ) { // open a UDP socket + printf("error opening socket\n"); + return -1; + } + + c.setBlocking( false ); + + if ( c.connect( host, port ) == -1 ) { + printf("error connecting to %s:%d\n", host, port); + return -1; + } + + + char packet[256] = "Hello world!"; + while(1) + { + int b; + int len = 0; + int axis = 0; + + js->read( &b, ax ); + for ( axis = 0 ; axis < activeaxes ; axis++ ) + { + long axisvalue = (long int)(ax[axis]*2147483647.0); + printf("axisval=%li\n", axisvalue); + memcpy(packet+len, &axisvalue, 4); + len+=4; + } + // fill emtpy values into packes when less than 4 axes + for( ; axis < 4; axis++ ) + { + long axisvalue = 0; + memcpy(packet+len, &axisvalue, 4); + len+=4; + } + + long int b_l = b; + memcpy(packet+len, &b_l, 4); + len+=4; + + char termstr[5] = "\0\0\r\n"; + memcpy(packet+len, &termstr, 4); + len += 4; + + c.send( packet, len, 0 ); + + /* give other processes a chance */ + +#ifdef WIN32 + Sleep ( 1 ) ; +#elif defined(sgi) + sginap ( 1 ) ; +#else + usleep ( 200 ) ; +#endif + printf("."); + fflush(stdout); + } + + return 0 ; +}