]> git.mxchange.org Git - flightgear.git/commitdiff
Add Manuel Bessler and Stephen Lowry's remote joystick code and add David Magginson...
authorehofman <ehofman>
Wed, 12 Nov 2003 10:06:18 +0000 (10:06 +0000)
committerehofman <ehofman>
Wed, 12 Nov 2003 10:06:18 +0000 (10:06 +0000)
14 files changed:
configure.ac
src/ATC/tower.cxx
src/Main/fg_io.cxx
src/Main/options.cxx
src/Network/Makefile.am
src/Network/jsclient.cxx [new file with mode: 0644]
src/Network/jsclient.hxx [new file with mode: 0644]
utils/3dconvert/.cvsignore [new file with mode: 0644]
utils/3dconvert/3dconvert.cxx [new file with mode: 0644]
utils/3dconvert/Makefile.am [new file with mode: 0644]
utils/Makefile.am
utils/js_server/.cvsignore [new file with mode: 0644]
utils/js_server/Makefile.am [new file with mode: 0644]
utils/js_server/js_server.cxx [new file with mode: 0644]

index 490ddecf8e85fb622fdcc9757363ca0a40b02e90..e60b948f1e88382f5913cc24eee16dba0dadd762 100644 (file)
@@ -553,6 +553,8 @@ AC_CONFIG_FILES([ \
        tests/Makefile \
        utils/Makefile \
        utils/TerraSync/Makefile \
+       utils/js_server/Makefile \
+       utils/3dconvert/Makefile \
 ])
 AC_OUTPUT
 
index 4d809fec8b8c6c15a335efe6364e4ec67df817ca..90be4c30fa7869c75ecbe52f537ae90bf39c7540 100644 (file)
@@ -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 <strings.h>           // bcopy()
+
 #include <Main/globals.hxx>
 #include <Airports/runways.hxx>
 #include <simgear/math/sg_geodesy.hxx>
index e3514841ec1dadc7f138c5748778f9b731527537..55c84f7527b4d7f793f4b552c2b912266af4b7dc 100644 (file)
@@ -46,6 +46,7 @@
 #  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>
@@ -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;
index 53daa5c80716f8ebd4d4ec04b3b65f4215b3dcae..01c072a57e67d682a8a40d22ba799b74198d3d30 100644 (file)
@@ -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 },
index 19617bf19ff619212b2c080865d9f71075dd831a..9f24828d9fee1c6003ebb4fb1189fa128e76a612 100644 (file)
@@ -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 (file)
index 0000000..7a59e78
--- /dev/null
@@ -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 <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;
+}
diff --git a/src/Network/jsclient.hxx b/src/Network/jsclient.hxx
new file mode 100644 (file)
index 0000000..612ec34
--- /dev/null
@@ -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 <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
diff --git a/utils/3dconvert/.cvsignore b/utils/3dconvert/.cvsignore
new file mode 100644 (file)
index 0000000..661fa8a
--- /dev/null
@@ -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 (file)
index 0000000..6ffc1ac
--- /dev/null
@@ -0,0 +1,32 @@
+#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);
+}
diff --git a/utils/3dconvert/Makefile.am b/utils/3dconvert/Makefile.am
new file mode 100644 (file)
index 0000000..a2cd52e
--- /dev/null
@@ -0,0 +1,4 @@
+bin_PROGRAMS = 3dconvert
+
+3dconvert_SOURCES = 3dconvert.cxx
+3dconvert_LDADD = -lplibssg -lplibsg -lplibul $(opengl_LIBS)
index cca72a72cf752717637c92df68bf41141d120160..61c2ecf36b1e21b7be220f6c2742f172ec816e18 100644 (file)
@@ -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 (file)
index 0000000..39c9a08
--- /dev/null
@@ -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 (file)
index 0000000..de629c9
--- /dev/null
@@ -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 (file)
index 0000000..141ff90
--- /dev/null
@@ -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 <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 ;
+}