diff --git a/src/Network/jsclient.cxx b/src/Network/jsclient.cxx index 1fff200ad..33c80d24b 100644 --- a/src/Network/jsclient.cxx +++ b/src/Network/jsclient.cxx @@ -27,6 +27,7 @@ #include #include +#include #include #include
@@ -91,8 +92,7 @@ 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 = (int32_t *)buf; for( int i = 0; i < 4; ++i ) { axis[i] = ((double)msg[i] / 2147483647.0); @@ -105,8 +105,7 @@ 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 = (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 ) diff --git a/utils/js_server/js_server.cxx b/utils/js_server/js_server.cxx index 620b4b57e..4da358ce7 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; @@ -101,25 +101,25 @@ int main ( int argc, char ** argv ) 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; + int32_t axisvalue = (int32_t)(ax[axis]*2147483647.0); + printf("axisval=%li\n", (long)axisvalue); + 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; - memcpy(packet+len, &b_l, 4); - len+=4; + int32_t b_l = b; + memcpy(packet+len, &b_l, sizeof(b_l)); + len+=sizeof(b_l); - char termstr[5] = "\0\0\r\n"; - memcpy(packet+len, &termstr, 4); + const char * termstr = "\0\0\r\n"; + memcpy(packet+len, termstr, 4); len += 4; c.send( packet, len, 0 );