The UDP remote joystick protocol FlightGear supports already requires
six four byte axis values, but it was making use of only four of them.
This patch changes the code to make all six available.

In my case I have a six channel remote control transmitter for a
helicopter and more than four is required to get the collective
control which is independent of the throttle.

-- 
David Fries <da...@fries.net>
Cc me on replies


commit 763130efebf6d216b99ba1583d21a40068cae256
Author: David Fries <da...@fries.net>
Date:   Sun Feb 21 14:18:02 2010 -0600

    Update js_server.cxx to send 6 axes.
    
    It was previously sending the axis count and "\0\0\r\n" for the last
    eight bytes.  jsclient.cxx was ignoring those, now it will accept those
    as additional axes, so send them.

diff --git a/utils/js_server/js_server.cxx b/utils/js_server/js_server.cxx
index 65f6e57..89c545c 100644
--- a/utils/js_server/js_server.cxx
+++ b/utils/js_server/js_server.cxx
@@ -42,7 +42,9 @@ int main ( int argc, char ** argv )
   float      * ax;
   int port = 16759;
   char * host; /* = "192.168.1.7"; */
-  int activeaxes = 4;
+  int activeaxes;
+  /* The FlightGear requires six, four byte integer values. */
+  const int max_axes = 6;
 
   if( argc != 3 )
   {
@@ -67,10 +69,10 @@ int main ( int argc, char ** argv )
   ax = new float [ numaxes ] ;
   activeaxes = numaxes;
   
-  if( numaxes > 4 )
+  if( numaxes > max_axes )
   {
-    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;
+    printf("max %u axes joysticks supported at the moment, however %i axes 
were detected\nWill only use the first %u axes!\n", max_axes, numaxes, 
max_axes);
+    activeaxes = max_axes;
   }
 
   // Must call this before any other net stuff
@@ -106,22 +108,14 @@ int main ( int argc, char ** argv )
          memcpy(packet+len, &axisvalue, sizeof(axisvalue));
          len+=sizeof(axisvalue);
        }
-       // fill emtpy values into packes when less than 4 axes
-       for( ; axis < 4; axis++ )
+       // fill emtpy values into packes when less than max_axes axes
+       for( ; axis < max_axes; axis++ )
        {
          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;
-
-       char termstr[5] = "\0\0\r\n";
-        memcpy(packet+len, &termstr, 4);
-       len += 4;
-
         c.send( packet, len, 0 );
 
     /* give other processes a chance */

commit efb4b4b9fc1c5405b329cab977cfb178dfd6c09f
Author: David Fries <da...@fries.net>
Date:   Sun Feb 21 08:26:50 2010 -0600

    Use 6 axies instead of 4.
    
    The protocol already requires six four byte axis values, but it was making
    use of only four of them.  Change the code to make use of all six
    available.

diff --git a/src/Network/jsclient.cxx b/src/Network/jsclient.cxx
index b1ed804..f068cce 100644
--- a/src/Network/jsclient.cxx
+++ b/src/Network/jsclient.cxx
@@ -38,7 +38,7 @@ FGJsClient::FGJsClient() {
        active = fgHasNode("/jsclient"); // if exist, assume bindings are 
defined
        SG_LOG( SG_IO, SG_INFO, "/jsclient exists, activating JsClient remote 
joystick support");
 
-       for( int i = 0; i < 4; ++i )
+       for( int i = 0; i < JSCLIENT_AXIS; ++i )
        {
            axisdef[i] = fgGetNode("/jsclient/axis", i);
            if( axisdef[i] != NULL )
@@ -93,7 +93,7 @@ bool FGJsClient::process() {
                SG_LOG( SG_IO, SG_DEBUG, "Success reading data." );
                int32_t *msg;
                msg = (int32_t*)buf;
-               for( int i = 0; i < 4; ++i )
+               for( int i = 0; i < JSCLIENT_AXIS; ++i )
                {
                        axis[i] = ((double)msg[i] / 2147483647.0);
                        if ( fabs(axis[i]) < 0.05 )
@@ -109,7 +109,7 @@ bool FGJsClient::process() {
                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 )
+               for( int i = 0; i < JSCLIENT_AXIS; ++i )
                {
                        axis[i] = ((double)msg[i] / 2147483647.0);
                        if ( fabs(axis[i]) < 0.05 )
diff --git a/src/Network/jsclient.hxx b/src/Network/jsclient.hxx
index 70d88d1..d2fb2fa 100644
--- a/src/Network/jsclient.hxx
+++ b/src/Network/jsclient.hxx
@@ -36,14 +36,15 @@
 
 SG_USING_STD(string);
 
+#define JSCLIENT_AXIS 6
 
 class FGJsClient : public FGProtocol {
 
     char buf[256];
     int length;
-    double axis[4];
-    SGPropertyNode_ptr axisdef[4];
-    string axisdefstr[4];
+    double axis[JSCLIENT_AXIS];
+    SGPropertyNode_ptr axisdef[JSCLIENT_AXIS];
+    string axisdefstr[JSCLIENT_AXIS];
     bool active;
                                
 public:


------------------------------------------------------------------------------
Download Intel&#174; 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

Reply via email to