Here are three bugfixes for the UDP based remote joystick server and client. Is int32_t the correct type for a 32 bit integer value in FlightGear? I see it is used in other places in the code, but not that many, so I wasn't sure. --
js_server.cxx is using long which becomes 64 bits on 64 bit systems, but was passing 4 in memcpy and to advance len, so technically it was getting by on 64 bit little endian systems. Fixed it to use int32_t. -- process() is reading 4+4+4+4+4+4 = 6*4 = 24 bytes of data, but typecasting it to (long int*) which is 64 bits on a 64 bit Unix system, 6*8 = 48 bytes. Correct long to int32_t to not turn into a 64 bit data time when run on a 64 bit system. -- The comparison is incorrect. It intended to limit the maximum axes count to 4, so if it is more than 4 limit it. -- David Fries <da...@fries.net> http://fries.net/~david/ (PGP encryption key available) commit 9594847fde2456363bf95cfd4826037bebe9650e Author: David Fries <da...@fries.net> Date: Sat Feb 20 20:42:32 2010 -0600 js_server.cxx fixes for 64 bit systems js_server.cxx is using long which becomes 64 bits on 64 bit systems, but was passing 4 in memcpy and to advance len, so technically it was getting by on 64 bit little endian systems. Fixed it to use int32_t. diff --git a/utils/js_server/js_server.cxx b/utils/js_server/js_server.cxx index 90adc36..65f6e57 100644 --- a/utils/js_server/js_server.cxx +++ b/utils/js_server/js_server.cxx @@ -101,17 +101,17 @@ int main ( int argc, char ** argv ) js->read( &b, ax ); for ( axis = 0 ; axis < activeaxes ; axis++ ) { - long axisvalue = (long int)(ax[axis]*2147483647.0); + int32_t axisvalue = (int32_t)(ax[axis]*2147483647.0); printf("axisval=%li\n", axisvalue); - memcpy(packet+len, &axisvalue, 4); - len+=4; + memcpy(packet+len, &axisvalue, sizeof(axisvalue)); + len+=sizeof(axisvalue); } // fill emtpy values into packes when less than 4 axes for( ; axis < 4; axis++ ) { - long axisvalue = 0; - memcpy(packet+len, &axisvalue, 4); - len+=4; + int32_t axisvalue = 0; + memcpy(packet+len, &axisvalue, sizeof(axisvalue)); + len+=sizeof(axisvalue); } long int b_l = b; commit d51b713d3a0292a3b6afb1d118f1c4b453b2a8e5 Author: David Fries <da...@fries.net> Date: Sat Feb 20 20:17:04 2010 -0600 jsclient.cxx fix for 64 bit systems process() is reading 4+4+4+4+4+4 = 6*4 = 24 bytes of data, but typecasting it to (long int*) which is 64 bits on a 64 bit Unix system, 6*8 = 48 bytes. Correct long to int32_t to not turn into a 64 bit data time when run on a 64 bit system. diff --git a/src/Network/jsclient.cxx b/src/Network/jsclient.cxx index ab6faa5..b1ed804 100644 --- a/src/Network/jsclient.cxx +++ b/src/Network/jsclient.cxx @@ -91,8 +91,8 @@ bool FGJsClient::process() { 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; + int32_t *msg; + msg = (int32_t*)buf; for( int i = 0; i < 4; ++i ) { axis[i] = ((double)msg[i] / 2147483647.0); @@ -105,8 +105,8 @@ bool FGJsClient::process() { } else { while ( io->read( (char *)(& buf), length ) == length ) { SG_LOG( SG_IO, SG_DEBUG, "Success reading data." ); - long int *msg; - msg = (long int *)buf; + int32_t *msg; + msg = (int32_t *)buf; SG_LOG( SG_IO, SG_DEBUG, "ax0 = " << msg[0] << " ax1 = " << msg[1] << "ax2 = " << msg[2] << "ax3 = " << msg[3]); for( int i = 0; i < 4; ++i ) commit afae732d25854a074c4b3acd9f0ac8e9e1fde12e Author: David Fries <da...@fries.net> Date: Sun Feb 21 08:38:06 2010 -0600 Fix comparison, max 4 not min 4. The comparison is incorrect. It intended to limit the maximum axes count to 4, so if it is more than 4 limit it. diff --git a/utils/js_server/js_server.cxx b/utils/js_server/js_server.cxx index f52acbd..90adc36 100644 --- a/utils/js_server/js_server.cxx +++ b/utils/js_server/js_server.cxx @@ -67,7 +67,7 @@ int main ( int argc, char ** argv ) ax = new float [ numaxes ] ; activeaxes = numaxes; - if( numaxes < 4 ) + 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; ------------------------------------------------------------------------------ Download Intel® Parallel Studio Eval Try the new software tools for yourself. Speed compiling, find bugs proactively, and fine-tune applications for parallel performance. See why Intel Parallel Studio got high marks during beta. http://p.sf.net/sfu/intel-sw-dev _______________________________________________ Flightgear-devel mailing list Flightgear-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/flightgear-devel