Add a net_byte_order flag so that the calling code can specify if network
byte order conversion is desired (defaults to true.)
This commit is contained in:
parent
000e86756c
commit
2b534ebf6d
4 changed files with 175 additions and 166 deletions
|
@ -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]);
|
||||
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_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);
|
||||
}
|
||||
|
||||
|
||||
// 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]);
|
||||
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->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);
|
||||
|
||||
if ( net->version != FG_NET_CTRLS_VERSION ) {
|
||||
SG_LOG( SG_IO, SG_ALERT,
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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,113 +174,118 @@ 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);
|
||||
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->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->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);
|
||||
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]);
|
||||
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_wheels; ++i ) {
|
||||
net->wow[i] = htonl(net->wow[i]);
|
||||
}
|
||||
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);
|
||||
}
|
||||
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_wheels; ++i ) {
|
||||
net->wow[i] = htonl(net->wow[i]);
|
||||
}
|
||||
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);
|
||||
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->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->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);
|
||||
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_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_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->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->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;
|
||||
// cout << "sea level rad = " << cur_fdm_state->get_Sea_level_radius()
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue