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
32 #include <plib/netSocket.h>
35 void usage(char * progname)
37 printf("This is an UDP based remote joystick server.\n");
38 printf("usage: %s <hostname> <port>\n", progname);
41 int main ( int argc, char ** argv )
46 char * host; /* = "192.168.1.7"; */
59 js = new jsJoystick ( 0 ) ;
61 if ( js->notWorking () )
63 printf ( "no Joystick detected... exitting\n" ) ;
66 printf ( "Joystick is \"%s\"\n", js->getName() ) ;
68 int numaxes = js->getNumAxes();
69 ax = new float [ numaxes ] ;
74 printf("max 4 axes joysticks supported at the moment, however %i axes were detected\nWill only use the first 4 axes!\n", numaxes);
78 // Must call this before any other net stuff
79 netInit( &argc,argv );
83 if ( ! c.open( false ) ) { // open a UDP socket
84 printf("error opening socket\n");
88 c.setBlocking( false );
90 if ( c.connect( host, port ) == -1 ) {
91 printf("error connecting to %s:%d\n", host, port);
96 char packet[256] = "Hello world!";
104 for ( axis = 0 ; axis < activeaxes ; axis++ )
106 int32_t axisvalue = (int32_t)(ax[axis]*2147483647.0);
107 printf("axisval=%li\n", (long)axisvalue);
108 memcpy(packet+len, &axisvalue, sizeof(axisvalue));
109 len+=sizeof(axisvalue);
111 // fill emtpy values into packes when less than 4 axes
112 for( ; axis < 4; axis++ )
114 int32_t axisvalue = 0;
115 memcpy(packet+len, &axisvalue, sizeof(axisvalue));
116 len+=sizeof(axisvalue);
120 memcpy(packet+len, &b_l, sizeof(b_l));
123 const char * termstr = "\0\0\r\n";
124 memcpy(packet+len, termstr, 4);
127 c.send( packet, len, 0 );
129 /* give other processes a chance */