Updates to the net_gui code that can spit out updated flight information
to the network which a gui might be interested in.
This commit is contained in:
parent
9d726c1bd8
commit
9f6cd30b34
3 changed files with 79 additions and 23 deletions
|
@ -67,6 +67,7 @@ public:
|
|||
// Update nav/adf radios based on current postition
|
||||
void search ();
|
||||
|
||||
inline FGDME *get_dme() { return &dme; }
|
||||
inline FGNavCom *get_navcom1() { return &navcom1; }
|
||||
inline FGNavCom *get_navcom2() { return &navcom2; }
|
||||
};
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#include <simgear/io/iochannel.hxx>
|
||||
#include <simgear/timing/sg_time.hxx>
|
||||
|
||||
#include <Cockpit/radiostack.hxx>
|
||||
#include <FDM/flight.hxx>
|
||||
#include <Time/tmp.hxx>
|
||||
#include <Main/fg_props.hxx>
|
||||
|
@ -69,6 +70,20 @@ static void htond (double &x)
|
|||
return;
|
||||
}
|
||||
}
|
||||
static void htonf (float &x)
|
||||
{
|
||||
if ( sgIsLittleEndian() ) {
|
||||
int *Float_Overlay;
|
||||
int Holding_Buffer;
|
||||
|
||||
Float_Overlay = (int *) &x;
|
||||
Holding_Buffer = Float_Overlay [0];
|
||||
|
||||
Float_Overlay [0] = htonl (Holding_Buffer);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
FGNativeGUI::FGNativeGUI() {
|
||||
|
@ -129,25 +144,49 @@ void FGProps2NetGUI( FGNetGUI *net ) {
|
|||
net->cur_time = globals->get_time_params()->get_cur_time();
|
||||
net->warp = globals->get_warp();
|
||||
|
||||
// Approach
|
||||
net->dist_nm = current_radiostack->get_dme()->get_dist();
|
||||
net->course_deviation_deg
|
||||
= current_radiostack->get_navcom1()->get_nav_heading()
|
||||
- current_radiostack->get_navcom1()->get_nav_radial();
|
||||
while ( net->course_deviation_deg > 180.0 ) {
|
||||
net->course_deviation_deg -= 360.0;
|
||||
}
|
||||
while ( net->course_deviation_deg < -180.0 ) {
|
||||
net->course_deviation_deg += 360.0;
|
||||
}
|
||||
if ( fabs(net->course_deviation_deg) > 90.0 )
|
||||
net->course_deviation_deg
|
||||
= ( net->course_deviation_deg<0.0
|
||||
? -net->course_deviation_deg - 180.0
|
||||
: -net->course_deviation_deg + 180.0 );
|
||||
net->gs_deviation_deg
|
||||
= current_radiostack->get_navcom1()->get_nav_gs_needle_deflection()
|
||||
/ 5.0;
|
||||
|
||||
// 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->vcas);
|
||||
htond(net->climb_rate);
|
||||
htonf(net->altitude);
|
||||
htonf(net->phi);
|
||||
htonf(net->theta);
|
||||
htonf(net->psi);
|
||||
htonf(net->vcas);
|
||||
htonf(net->climb_rate);
|
||||
|
||||
for ( i = 0; i < net->num_tanks; ++i ) {
|
||||
htond(net->fuel_quantity[i]);
|
||||
htonf(net->fuel_quantity[i]);
|
||||
}
|
||||
net->num_tanks = htonl(net->num_tanks);
|
||||
|
||||
net->cur_time = htonl( net->cur_time );
|
||||
net->warp = htonl( net->warp );
|
||||
|
||||
htonf(net->dist_nm);
|
||||
htonf(net->course_deviation_deg);
|
||||
htonf(net->gs_deviation_deg);
|
||||
}
|
||||
|
||||
|
||||
|
@ -159,21 +198,25 @@ void FGNetGUI2Props( FGNetGUI *net ) {
|
|||
|
||||
htond(net->longitude);
|
||||
htond(net->latitude);
|
||||
htond(net->altitude);
|
||||
htond(net->phi);
|
||||
htond(net->theta);
|
||||
htond(net->psi);
|
||||
htond(net->vcas);
|
||||
htond(net->climb_rate);
|
||||
htonf(net->altitude);
|
||||
htonf(net->phi);
|
||||
htonf(net->theta);
|
||||
htonf(net->psi);
|
||||
htonf(net->vcas);
|
||||
htonf(net->climb_rate);
|
||||
|
||||
net->num_tanks = htonl(net->num_tanks);
|
||||
for ( i = 0; i < net->num_tanks; ++i ) {
|
||||
htond(net->fuel_quantity[i]);
|
||||
htonf(net->fuel_quantity[i]);
|
||||
}
|
||||
|
||||
net->cur_time = ntohl(net->cur_time);
|
||||
net->warp = ntohl(net->warp);
|
||||
|
||||
htonf(net->dist_nm);
|
||||
htonf(net->course_deviation_deg);
|
||||
htonf(net->gs_deviation_deg);
|
||||
|
||||
if ( net->version == FG_NET_GUI_VERSION ) {
|
||||
// cout << "pos = " << net->longitude << " " << net->latitude << endl;
|
||||
// cout << "sea level rad = " << cur_fdm_state->get_Sea_level_radius()
|
||||
|
@ -200,6 +243,13 @@ void FGNetGUI2Props( FGNetGUI *net ) {
|
|||
}
|
||||
|
||||
globals->set_warp( net->warp );
|
||||
|
||||
// Approach
|
||||
fgSetDouble( "/radios/dme/distance-nm", net->dist_nm );
|
||||
fgSetDouble( "/radios/nav[0]/heading-needle-deflection",
|
||||
net->course_deviation_deg );
|
||||
fgSetDouble( "/radios/nav[0]/gs-needle-deflection",
|
||||
net->gs_deviation_deg );
|
||||
} else {
|
||||
SG_LOG( SG_IO, SG_ALERT,
|
||||
"Error: version mismatch in FGNetNativeGUI2Props()" );
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
#endif
|
||||
|
||||
|
||||
const int FG_NET_GUI_VERSION = 1;
|
||||
const int FG_NET_GUI_VERSION = 2;
|
||||
|
||||
|
||||
// Define a structure containing the top level flight dynamics model
|
||||
|
@ -56,23 +56,28 @@ public:
|
|||
// Positions
|
||||
double longitude; // geodetic (radians)
|
||||
double latitude; // geodetic (radians)
|
||||
double altitude; // above sea level (meters)
|
||||
double agl; // above ground level (meters)
|
||||
double phi; // roll (radians)
|
||||
double theta; // pitch (radians)
|
||||
double psi; // yaw or true heading (radians)
|
||||
float altitude; // above sea level (meters)
|
||||
float agl; // above ground level (meters)
|
||||
float phi; // roll (radians)
|
||||
float theta; // pitch (radians)
|
||||
float psi; // yaw or true heading (radians)
|
||||
|
||||
// Velocities
|
||||
double vcas;
|
||||
double climb_rate; // feet per second
|
||||
float vcas;
|
||||
float climb_rate; // feet per second
|
||||
|
||||
// Consumables
|
||||
int num_tanks; // Max number of fuel tanks
|
||||
double fuel_quantity[FG_MAX_TANKS];
|
||||
float fuel_quantity[FG_MAX_TANKS];
|
||||
|
||||
// Environment
|
||||
time_t cur_time; // current unix time
|
||||
long int warp; // offset in seconds to unix time
|
||||
|
||||
// Approach
|
||||
float dist_nm; // distance to tuned navaid in nautical miles
|
||||
float course_deviation_deg; // degrees off target course
|
||||
float gs_deviation_deg; // degrees off target glide slope
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue