tests/Makefile \
utils/Makefile \
utils/TerraSync/Makefile \
+ utils/js_server/Makefile \
+ utils/3dconvert/Makefile \
])
AC_OUTPUT
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+#include <strings.h> // bcopy()
+
#include <Main/globals.hxx>
#include <Airports/runways.hxx>
#include <simgear/math/sg_geodesy.hxx>
# include <Network/jpg-httpd.hxx>
#endif
#include <Network/joyclient.hxx>
+#include <Network/jsclient.hxx>
#include <Network/native.hxx>
#include <Network/native_ctrls.hxx>
#include <Network/native_fdm.hxx>
} 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;
{"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 },
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 \
--- /dev/null
+// 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 <simgear/debug/logstream.hxx>
+#include <simgear/io/iochannel.hxx>
+
+#include <Aircraft/aircraft.hxx>
+
+#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;
+}
--- /dev/null
+// 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 <simgear/compiler.h>
+
+#include STL_STRING
+
+#include <FDM/flight.hxx>
+
+#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
--- /dev/null
+.deps
+Makefile
+Makefile.in
+3dconvert
--- /dev/null
+#include <iostream>
+#include <GL/glut.h>
+#include <plib/ssg.h>
+
+using std::cerr;
+using std::endl;
+
+
+int
+main (int ac, char ** av)
+{
+ if (ac != 3) {
+ cerr << "Usage: " << av[0] << " <file_in> <file_out>" << 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);
+}
--- /dev/null
+bin_PROGRAMS = 3dconvert
+
+3dconvert_SOURCES = 3dconvert.cxx
+3dconvert_LDADD = -lplibssg -lplibsg -lplibul $(opengl_LIBS)
-SUBDIRS = TerraSync
+SUBDIRS = TerraSync js_server 3dconvert
--- /dev/null
+.deps
+Makefile
+Makefile.in
+js_server
--- /dev/null
+sbin_PROGRAMS = js_server
+
+js_server_SOURCES = js_server.cxx
+js_server_LDADD = -lplibjs -lplibnet -lplibul
--- /dev/null
+/*
+ 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 <math.h>
+#include <stdio.h>
+#include <plib/netSocket.h>
+#include <plib/js.h>
+
+void usage(char * progname)
+{
+ printf("This is an UDP based remote joystick server.\n");
+ printf("usage: %s <hostname> <port>\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 ;
+}