}
-void FGProps2NetFDM( FGNetFDM *net ) {
+void FGProps2NetFDM( FGNetFDM *net, bool net_byte_order ) {
int i;
// Version sanity checking
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;
last_warp = net->warp;
*/
} else {
- SG_LOG( SG_IO, SG_ALERT, "Error: version mismatch in net2global()" );
+ SG_LOG( SG_IO, SG_ALERT,
+ "Error: version mismatch in FGNetFDM2Props()" );
SG_LOG( SG_IO, SG_ALERT,
"\tread " << net->version << " need " << FG_NET_FDM_VERSION );
SG_LOG( SG_IO, SG_ALERT,
- "\tsomeone needs to upgrade net_fdm.hxx and recompile." );
+ "\tNeeds to upgrade net_fdm.hxx and recompile." );
}
}
FGNetFDM2Props( &buf );
}
} else {
- while ( io->read( (char *)(& buf), length ) == length ) {
- SG_LOG( SG_IO, SG_DEBUG, "Success reading data." );
- FGNetFDM2Props( &buf );
+ // double dt = 1000000.0 / 30.0;
+ // SGTimeStamp current; current.stamp();
+ int result;
+ result = io->read( (char *)(& buf), length );
+ if ( result == length ) {
+ SG_LOG( SG_IO, SG_DEBUG, " Success reading data." );
+ FGNetFDM2Props( &buf );
+ }
+ while ( result == length /* || current - last_time < dt */ ) {
+ result = io->read( (char *)(& buf), length );
+ if ( result == length ) {
+ SG_LOG( SG_IO, SG_DEBUG, " Success reading data." );
+ FGNetFDM2Props( &buf );
+ }
+ // current.stamp();
}
+ // last_time = current;
}
}