]> git.mxchange.org Git - flightgear.git/commitdiff
Add a net_byte_order flag so that the calling code can specify if network
authorcurt <curt>
Mon, 3 Mar 2003 04:35:09 +0000 (04:35 +0000)
committercurt <curt>
Mon, 3 Mar 2003 04:35:09 +0000 (04:35 +0000)
byte order conversion is desired (defaults to true.)

src/Network/native_ctrls.cxx
src/Network/native_ctrls.hxx
src/Network/native_fdm.cxx
src/Network/native_fdm.hxx

index 404fc994a9c92dcc52fe66e23194eea752b904d9..ecc6b68e9b107927665cd68830aff271d1ed55b9 100644 (file)
@@ -98,7 +98,7 @@ static void htond (double &x)
 
 
 // Populate the FGNetCtrls structure from the property tree.
-void FGProps2NetCtrls( FGNetCtrls *net ) {
+void FGProps2NetCtrls( FGNetCtrls *net, bool net_byte_order ) {
     int i;
 
     SGPropertyNode * node = fgGetNode("/controls", true);
@@ -183,85 +183,89 @@ void FGProps2NetCtrls( FGNetCtrls *net ) {
         net->freeze |= 0x04;
     }
 
-    // convert to network byte order
-    net->version = htonl(net->version);
-    htond(net->aileron);
-    htond(net->elevator);
-    htond(net->elevator_trim);
-    htond(net->rudder);
-    htond(net->flaps);
-    net->flaps_power = htonl(net->flaps_power);
-    for ( i = 0; i < FGNetCtrls::FG_MAX_ENGINES; ++i ) {
-       htond(net->throttle[i]);
-       htond(net->mixture[i]);
-        net->fuel_pump_power[i] = htonl(net->fuel_pump_power[i]);
-       htond(net->prop_advance[i]);
-       net->magnetos[i] = htonl(net->magnetos[i]);
-       net->starter_power[i] = htonl(net->starter_power[i]);
-    }
-    net->num_engines = htonl(net->num_engines);
-    for ( i = 0; i < FGNetCtrls::FG_MAX_TANKS; ++i ) {
-        net->fuel_selector[i] = htonl(net->fuel_selector[i]);
-    }
-    net->num_tanks = htonl(net->num_tanks);
-    for ( i = 0; i < FGNetCtrls::FG_MAX_WHEELS; ++i ) {
-       htond(net->brake[i]);
+    if ( net_byte_order ) {
+        // convert to network byte order
+        net->version = htonl(net->version);
+        htond(net->aileron);
+        htond(net->elevator);
+        htond(net->elevator_trim);
+        htond(net->rudder);
+        htond(net->flaps);
+        net->flaps_power = htonl(net->flaps_power);
+        for ( i = 0; i < FGNetCtrls::FG_MAX_ENGINES; ++i ) {
+            htond(net->throttle[i]);
+            htond(net->mixture[i]);
+            net->fuel_pump_power[i] = htonl(net->fuel_pump_power[i]);
+            htond(net->prop_advance[i]);
+            net->magnetos[i] = htonl(net->magnetos[i]);
+            net->starter_power[i] = htonl(net->starter_power[i]);
+        }
+        net->num_engines = htonl(net->num_engines);
+        for ( i = 0; i < FGNetCtrls::FG_MAX_TANKS; ++i ) {
+            net->fuel_selector[i] = htonl(net->fuel_selector[i]);
+        }
+        net->num_tanks = htonl(net->num_tanks);
+        for ( i = 0; i < FGNetCtrls::FG_MAX_WHEELS; ++i ) {
+            htond(net->brake[i]);
+        }
+        net->num_wheels = htonl(net->num_wheels);
+        net->gear_handle = htonl(net->gear_handle);
+        net->master_bat = htonl(net->master_bat);
+        net->master_alt = htonl(net->master_alt);
+        net->master_avionics = htonl(net->master_avionics);
+        htond(net->wind_speed_kt);
+        htond(net->wind_dir_deg);
+        htond(net->hground);
+        htond(net->magvar);
+        net->speedup = htonl(net->speedup);
+        net->freeze = htonl(net->freeze);
     }
-    net->num_wheels = htonl(net->num_wheels);
-    net->gear_handle = htonl(net->gear_handle);
-    net->master_bat = htonl(net->master_bat);
-    net->master_alt = htonl(net->master_alt);
-    net->master_avionics = htonl(net->master_avionics);
-    htond(net->wind_speed_kt);
-    htond(net->wind_dir_deg);
-    htond(net->hground);
-    htond(net->magvar);
-    net->speedup = htonl(net->speedup);
-    net->freeze = htonl(net->freeze);
 }
 
 
 // Update the property tree from the FGNetCtrls structure.
-void FGNetCtrls2Props( FGNetCtrls *net ) {
+void FGNetCtrls2Props( FGNetCtrls *net, bool net_byte_order ) {
     int i;
 
     SGPropertyNode * node = fgGetNode("/controls", true);
 
-    // convert from network byte order
-    net->version = htonl(net->version);
-    htond(net->aileron);
-    htond(net->elevator);
-    htond(net->elevator_trim);
-    htond(net->rudder);
-    htond(net->flaps);
-    net->flaps_power = htonl(net->flaps_power);
-    net->num_engines = htonl(net->num_engines);
-    for ( i = 0; i < net->num_engines; ++i ) {
-        net->magnetos[i] = htonl(net->magnetos[i]);
-        net->starter_power[i] = htonl(net->starter_power[i]);
-       htond(net->throttle[i]);
-       htond(net->mixture[i]);
-        net->fuel_pump_power[i] = htonl(net->fuel_pump_power[i]);
-       htond(net->prop_advance[i]);
-    }
-    net->num_tanks = htonl(net->num_tanks);
-    for ( i = 0; i < net->num_tanks; ++i ) {
-       net->fuel_selector[i] = htonl(net->fuel_selector[i]);
-    }
-    net->num_wheels = htonl(net->num_wheels);
-    for ( i = 0; i < net->num_wheels; ++i ) {
-       htond(net->brake[i]);
+    if ( net_byte_order ) {
+        // convert from network byte order
+        net->version = htonl(net->version);
+        htond(net->aileron);
+        htond(net->elevator);
+        htond(net->elevator_trim);
+        htond(net->rudder);
+        htond(net->flaps);
+        net->flaps_power = htonl(net->flaps_power);
+        net->num_engines = htonl(net->num_engines);
+        for ( i = 0; i < net->num_engines; ++i ) {
+            net->magnetos[i] = htonl(net->magnetos[i]);
+            net->starter_power[i] = htonl(net->starter_power[i]);
+            htond(net->throttle[i]);
+            htond(net->mixture[i]);
+            net->fuel_pump_power[i] = htonl(net->fuel_pump_power[i]);
+            htond(net->prop_advance[i]);
+        }
+        net->num_tanks = htonl(net->num_tanks);
+        for ( i = 0; i < net->num_tanks; ++i ) {
+            net->fuel_selector[i] = htonl(net->fuel_selector[i]);
+        }
+        net->num_wheels = htonl(net->num_wheels);
+        for ( i = 0; i < net->num_wheels; ++i ) {
+            htond(net->brake[i]);
+        }
+        net->gear_handle = htonl(net->gear_handle);
+        net->master_bat = htonl(net->master_bat);
+        net->master_alt = htonl(net->master_alt);
+        net->master_avionics = htonl(net->master_avionics);
+        htond(net->wind_speed_kt);
+        htond(net->wind_dir_deg);
+        htond(net->hground);
+        htond(net->magvar);
+        net->speedup = htonl(net->speedup);
+        net->freeze = htonl(net->freeze);
     }
-    net->gear_handle = htonl(net->gear_handle);
-    net->master_bat = htonl(net->master_bat);
-    net->master_alt = htonl(net->master_alt);
-    net->master_avionics = htonl(net->master_avionics);
-    htond(net->wind_speed_kt);
-    htond(net->wind_dir_deg);
-    htond(net->hground);
-    htond(net->magvar);
-    net->speedup = htonl(net->speedup);
-    net->freeze = htonl(net->freeze);
 
     if ( net->version != FG_NET_CTRLS_VERSION ) {
        SG_LOG( SG_IO, SG_ALERT,
index e903e3b03122a12017adb9f142d15379ccfaa916..d64d072007225ae13babc6ce43dbdcd04fe0c6df 100644 (file)
@@ -63,10 +63,10 @@ public:
 // Helper functions which may be useful outside this class
 
 // Populate the FGNetCtrls structure from the property tree.
-void FGProps2NetCtrls( FGNetCtrls *net );
+void FGProps2NetCtrls( FGNetCtrls *net, bool net_byte_order = true );
 
 // Update the property tree from the FGNetCtrls structure.
-void FGNetCtrls2Props( FGNetCtrls *net );
+void FGNetCtrls2Props( FGNetCtrls *net, bool net_byte_order = true );
 
 
 #endif // _FG_NATIVE_CTRLS_HXX
index eb2a9a5ca9a1ccd692b6342e748a8b2764c2e432..8a8d743a9dc644fd9ac45409088084f20e70026e 100644 (file)
@@ -100,7 +100,7 @@ bool FGNativeFDM::open() {
 }
 
 
-void FGProps2NetFDM( FGNetFDM *net ) {
+void FGProps2NetFDM( FGNetFDM *net, bool net_byte_order ) {
     int i;
 
     // Version sanity checking
@@ -174,112 +174,117 @@ void FGProps2NetFDM( FGNetFDM *net ) {
     net->warp = globals->get_warp();
     net->visibility = fgGetDouble("/environment/visibility-m");
 
-    // Convert the net buffer to network format
-    net->version = htonl(net->version);
-
-    htond(net->longitude);
-    htond(net->latitude);
-    htond(net->altitude);
-    htond(net->phi);
-    htond(net->theta);
-    htond(net->psi);
-
-    htond(net->phidot);
-    htond(net->thetadot);
-    htond(net->psidot);
-    htond(net->vcas);
-    htond(net->climb_rate);
-    htond(net->v_north);
-    htond(net->v_east);
-    htond(net->v_down);
-    htond(net->v_wind_body_north);
-    htond(net->v_wind_body_east);
-    htond(net->v_wind_body_down);
-    htond(net->stall_warning);
-
-    htond(net->A_X_pilot);
-    htond(net->A_Y_pilot);
-    htond(net->A_Z_pilot);
+    if ( net_byte_order ) {
+        // Convert the net buffer to network format
+        net->version = htonl(net->version);
+
+        htond(net->longitude);
+        htond(net->latitude);
+        htond(net->altitude);
+        htond(net->phi);
+        htond(net->theta);
+        htond(net->psi);
+
+        htond(net->phidot);
+        htond(net->thetadot);
+        htond(net->psidot);
+        htond(net->vcas);
+        htond(net->climb_rate);
+        htond(net->v_north);
+        htond(net->v_east);
+        htond(net->v_down);
+        htond(net->v_wind_body_north);
+        htond(net->v_wind_body_east);
+        htond(net->v_wind_body_down);
+        htond(net->stall_warning);
+
+        htond(net->A_X_pilot);
+        htond(net->A_Y_pilot);
+        htond(net->A_Z_pilot);
+
+        for ( i = 0; i < net->num_engines; ++i ) {
+            htonl(net->eng_state[i]);
+            htond(net->rpm[i]);
+            htond(net->fuel_flow[i]);
+            htond(net->EGT[i]);
+            htond(net->oil_temp[i]);
+            htond(net->oil_px[i]);
+        }
+        net->num_engines = htonl(net->num_engines);
 
-    for ( i = 0; i < net->num_engines; ++i ) {
-        htonl(net->eng_state[i]);
-        htond(net->rpm[i]);
-        htond(net->fuel_flow[i]);
-        htond(net->EGT[i]);
-        htond(net->oil_temp[i]);
-        htond(net->oil_px[i]);
-    }
-    net->num_engines = htonl(net->num_engines);
+        for ( i = 0; i < net->num_tanks; ++i ) {
+            htond(net->fuel_quantity[i]);
+        }
+        net->num_tanks = htonl(net->num_tanks);
 
-    for ( i = 0; i < net->num_tanks; ++i ) {
-        htond(net->fuel_quantity[i]);
-    }
-    net->num_tanks = htonl(net->num_tanks);
+        for ( i = 0; i < net->num_wheels; ++i ) {
+            net->wow[i] = htonl(net->wow[i]);
+        }
+        net->num_wheels = htonl(net->num_wheels);
+        htond(net->flap_deflection);
 
-    for ( i = 0; i < net->num_wheels; ++i ) {
-        net->wow[i] = htonl(net->wow[i]);
+        net->cur_time = htonl( net->cur_time );
+        net->warp = htonl( net->warp );
+        htond(net->visibility);
     }
-    net->num_wheels = htonl(net->num_wheels);
-    htond(net->flap_deflection);
-
-    net->cur_time = htonl( net->cur_time );
-    net->warp = htonl( net->warp );
-    htond(net->visibility);
 }
 
 
-void FGNetFDM2Props( FGNetFDM *net ) {
+void FGNetFDM2Props( FGNetFDM *net, bool net_byte_order ) {
     int i;
 
-    // Convert to the net buffer from network format
-    net->version = ntohl(net->version);
-
-    htond(net->longitude);
-    htond(net->latitude);
-    htond(net->altitude);
-    htond(net->phi);
-    htond(net->theta);
-    htond(net->psi);
-
-    htond(net->phidot);
-    htond(net->thetadot);
-    htond(net->psidot);
-    htond(net->vcas);
-    htond(net->climb_rate);
-    htond(net->v_north);
-    htond(net->v_east);
-    htond(net->v_down);
-    htond(net->v_wind_body_north);
-    htond(net->v_wind_body_east);
-    htond(net->v_wind_body_down);
-    htond(net->stall_warning);
-
-    htond(net->A_X_pilot);
-    htond(net->A_Y_pilot);
-    htond(net->A_Z_pilot);
-
-    net->num_engines = htonl(net->num_engines);
-    for ( i = 0; i < net->num_engines; ++i ) {
-       htonl(net->eng_state[i]);
-       htond(net->rpm[i]);
-       htond(net->fuel_flow[i]);
-       htond(net->EGT[i]);
-       htond(net->oil_temp[i]);
-       htond(net->oil_px[i]);
-    }
+    if ( net_byte_order ) {
+        // Convert to the net buffer from network format
+        net->version = ntohl(net->version);
+
+        htond(net->longitude);
+        htond(net->latitude);
+        htond(net->altitude);
+        htond(net->phi);
+        htond(net->theta);
+        htond(net->psi);
+
+        htond(net->phidot);
+        htond(net->thetadot);
+        htond(net->psidot);
+        htond(net->vcas);
+        htond(net->climb_rate);
+        htond(net->v_north);
+        htond(net->v_east);
+        htond(net->v_down);
+        htond(net->v_wind_body_north);
+        htond(net->v_wind_body_east);
+        htond(net->v_wind_body_down);
+        htond(net->stall_warning);
+
+        htond(net->A_X_pilot);
+        htond(net->A_Y_pilot);
+        htond(net->A_Z_pilot);
+
+        net->num_engines = htonl(net->num_engines);
+        for ( i = 0; i < net->num_engines; ++i ) {
+            htonl(net->eng_state[i]);
+            htond(net->rpm[i]);
+            htond(net->fuel_flow[i]);
+            htond(net->EGT[i]);
+            htond(net->oil_temp[i]);
+            htond(net->oil_px[i]);
+        }
 
-    net->num_tanks = htonl(net->num_tanks);
-    for ( i = 0; i < net->num_tanks; ++i ) {
-       htond(net->fuel_quantity[i]);
-    }
+        net->num_tanks = htonl(net->num_tanks);
+        for ( i = 0; i < net->num_tanks; ++i ) {
+            htond(net->fuel_quantity[i]);
+        }
 
-    net->num_wheels = htonl(net->num_wheels);
-    // I don't need to convert the Wow flags, since they are one byte in size
-    htond(net->flap_deflection);
+        net->num_wheels = htonl(net->num_wheels);
+        // I don't need to convert the Wow flags, since they are one
+        // byte in size
+        htond(net->flap_deflection);
 
-    net->cur_time = ntohl(net->cur_time);
-    net->warp = ntohl(net->warp);
-    htond(net->visibility);
+        net->cur_time = ntohl(net->cur_time);
+        net->warp = ntohl(net->warp);
+        htond(net->visibility);
+    }
 
     if ( net->version == FG_NET_FDM_VERSION ) {
         // cout << "pos = " << net->longitude << " " << net->latitude << endl;
index 2afbf0954c154b81e72a007650ac99ecad811707..adb78ecbf5f238abab3c103eecc399b841f2e3e6 100644 (file)
@@ -57,10 +57,10 @@ public:
 // Helper functions which may be useful outside this class
 
 // Populate the FGNetFDM structure from the property tree.
-void FGProps2NetFDM( FGNetFDM *net );
+void FGProps2NetFDM( FGNetFDM *net, bool net_byte_order = true );
 
 // Update the property tree from the FGNetFDM structure.
-void FGNetFDM2Props( FGNetFDM *net );
+void FGNetFDM2Props( FGNetFDM *net, bool net_byte_order = true );
 
 
 #endif // _FG_NATIVE_FDM_HXX