1
0
Fork 0

Add Manuel Bessler and Stephen Lowry's remote joystick code and add David Magginson's 3dconvert utility

This commit is contained in:
ehofman 2003-11-12 10:06:18 +00:00
parent 8a036fb77a
commit e6cd7a0ed7
14 changed files with 388 additions and 1 deletions

View file

@ -553,6 +553,8 @@ AC_CONFIG_FILES([ \
tests/Makefile \ tests/Makefile \
utils/Makefile \ utils/Makefile \
utils/TerraSync/Makefile \ utils/TerraSync/Makefile \
utils/js_server/Makefile \
utils/3dconvert/Makefile \
]) ])
AC_OUTPUT AC_OUTPUT

View file

@ -18,6 +18,8 @@
// along with this program; if not, write to the Free Software // along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#include <strings.h> // bcopy()
#include <Main/globals.hxx> #include <Main/globals.hxx>
#include <Airports/runways.hxx> #include <Airports/runways.hxx>
#include <simgear/math/sg_geodesy.hxx> #include <simgear/math/sg_geodesy.hxx>

View file

@ -46,6 +46,7 @@
# include <Network/jpg-httpd.hxx> # include <Network/jpg-httpd.hxx>
#endif #endif
#include <Network/joyclient.hxx> #include <Network/joyclient.hxx>
#include <Network/jsclient.hxx>
#include <Network/native.hxx> #include <Network/native.hxx>
#include <Network/native_ctrls.hxx> #include <Network/native_ctrls.hxx>
#include <Network/native_fdm.hxx> #include <Network/native_fdm.hxx>
@ -138,6 +139,9 @@ FGIO::parse_port_config( const string& config )
} else if ( protocol == "joyclient" ) { } else if ( protocol == "joyclient" ) {
FGJoyClient *joyclient = new FGJoyClient; FGJoyClient *joyclient = new FGJoyClient;
io = joyclient; io = joyclient;
} else if ( protocol == "jsclient" ) {
FGJsClient *jsclient = new FGJsClient;
io = jsclient;
} else if ( protocol == "native" ) { } else if ( protocol == "native" ) {
FGNative *native = new FGNative; FGNative *native = new FGNative;
io = native; io = native;

View file

@ -1367,6 +1367,7 @@ struct OptionDesc {
{"ray", true, OPTION_CHANNEL, "", false, "", 0 }, {"ray", true, OPTION_CHANNEL, "", false, "", 0 },
{"rul", true, OPTION_CHANNEL, "", false, "", 0 }, {"rul", true, OPTION_CHANNEL, "", false, "", 0 },
{"joyclient", true, OPTION_CHANNEL, "", false, "", 0 }, {"joyclient", true, OPTION_CHANNEL, "", false, "", 0 },
{"jsclient", true, OPTION_CHANNEL, "", false, "", 0 },
#ifdef FG_NETWORK_OLK #ifdef FG_NETWORK_OLK
{"disable-network-olk", false, OPTION_BOOL, "/sim/networking/olk", false, "", 0 }, {"disable-network-olk", false, OPTION_BOOL, "/sim/networking/olk", false, "", 0 },
{"enable-network-olk", false, OPTION_BOOL, "/sim/networking/olk", true, "", 0 }, {"enable-network-olk", false, OPTION_BOOL, "/sim/networking/olk", true, "", 0 },

View file

@ -20,6 +20,7 @@ libNetwork_a_SOURCES = \
httpd.cxx httpd.hxx \ httpd.cxx httpd.hxx \
$(JPEG_SERVER) \ $(JPEG_SERVER) \
joyclient.cxx joyclient.hxx \ joyclient.cxx joyclient.hxx \
jsclient.cxx jsclient.hxx \
native.cxx native.hxx \ native.cxx native.hxx \
native_ctrls.cxx native_ctrls.hxx \ native_ctrls.cxx native_ctrls.hxx \
native_fdm.cxx native_fdm.hxx \ native_fdm.cxx native_fdm.hxx \

127
src/Network/jsclient.cxx Normal file
View file

@ -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;
}

61
src/Network/jsclient.hxx Normal file
View file

@ -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

View file

@ -0,0 +1,4 @@
.deps
Makefile
Makefile.in
3dconvert

View file

@ -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);
}

View file

@ -0,0 +1,4 @@
bin_PROGRAMS = 3dconvert
3dconvert_SOURCES = 3dconvert.cxx
3dconvert_LDADD = -lplibssg -lplibsg -lplibul $(opengl_LIBS)

View file

@ -1 +1 @@
SUBDIRS = TerraSync SUBDIRS = TerraSync js_server 3dconvert

View file

@ -0,0 +1,4 @@
.deps
Makefile
Makefile.in
js_server

View file

@ -0,0 +1,4 @@
sbin_PROGRAMS = js_server
js_server_SOURCES = js_server.cxx
js_server_LDADD = -lplibjs -lplibnet -lplibul

View file

@ -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 ;
}