From 2b534ebf6ddf6e25f196e735d8a5699aed0107d3 Mon Sep 17 00:00:00 2001 From: curt Date: Mon, 3 Mar 2003 04:35:09 +0000 Subject: [PATCH] Add a net_byte_order flag so that the calling code can specify if network byte order conversion is desired (defaults to true.) --- src/Network/native_ctrls.cxx | 144 +++++++++++++------------- src/Network/native_ctrls.hxx | 4 +- src/Network/native_fdm.cxx | 195 ++++++++++++++++++----------------- src/Network/native_fdm.hxx | 4 +- 4 files changed, 178 insertions(+), 169 deletions(-) diff --git a/src/Network/native_ctrls.cxx b/src/Network/native_ctrls.cxx index 404fc994a..ecc6b68e9 100644 --- a/src/Network/native_ctrls.cxx +++ b/src/Network/native_ctrls.cxx @@ -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, diff --git a/src/Network/native_ctrls.hxx b/src/Network/native_ctrls.hxx index e903e3b03..d64d07200 100644 --- a/src/Network/native_ctrls.hxx +++ b/src/Network/native_ctrls.hxx @@ -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 diff --git a/src/Network/native_fdm.cxx b/src/Network/native_fdm.cxx index eb2a9a5ca..8a8d743a9 100644 --- a/src/Network/native_fdm.cxx +++ b/src/Network/native_fdm.cxx @@ -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; diff --git a/src/Network/native_fdm.hxx b/src/Network/native_fdm.hxx index 2afbf0954..adb78ecbf 100644 --- a/src/Network/native_fdm.hxx +++ b/src/Network/native_fdm.hxx @@ -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 -- 2.39.5