2 Plib based joystick server based on PLIBs js_demo.cxx
4 js_server is Copyright (C) 2003
5 by Stephen Lowry and Manuel Bessler
7 PLIB - A Suite of Portable Game Libraries
8 Copyright (C) 2001 Steve Baker
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 For further information visit http://plib.sourceforge.net
30 #include <plib/netSocket.h>
33 void usage(char * progname)
35 printf("This is an UDP based remote joystick server.\n");
36 printf("usage: %s <hostname> <port>\n", progname);
39 int main ( int argc, char ** argv )
44 char * host; /* = "192.168.1.7"; */
57 js = new jsJoystick ( 0 ) ;
59 if ( js->notWorking () )
61 printf ( "no Joystick detected... exitting\n" ) ;
64 printf ( "Joystick is \"%s\"\n", js->getName() ) ;
66 int numaxes = js->getNumAxes();
67 ax = new float [ numaxes ] ;
72 printf("max 4 axes joysticks supported at the moment, however %i axes were detected\nWill only use the first 4 axes!\n", numaxes);
76 // Must call this before any other net stuff
77 netInit( &argc,argv );
81 if ( ! c.open( false ) ) { // open a UDP socket
82 printf("error opening socket\n");
86 c.setBlocking( false );
88 if ( c.connect( host, port ) == -1 ) {
89 printf("error connecting to %s:%d\n", host, port);
94 char packet[256] = "Hello world!";
102 for ( axis = 0 ; axis < activeaxes ; axis++ )
104 long axisvalue = (long int)(ax[axis]*2147483647.0);
105 printf("axisval=%li\n", axisvalue);
106 memcpy(packet+len, &axisvalue, 4);
109 // fill emtpy values into packes when less than 4 axes
110 for( ; axis < 4; axis++ )
113 memcpy(packet+len, &axisvalue, 4);
118 memcpy(packet+len, &b_l, 4);
121 char termstr[5] = "\0\0\r\n";
122 memcpy(packet+len, &termstr, 4);
125 c.send( packet, len, 0 );
127 /* give other processes a chance */