X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FCockpit%2Fradiostack.cxx;h=4a6d38da58f44bffff14f5bdc27f0a378501809c;hb=c0b4531d04215f76f9cf65afbdaed6b7c0b32634;hp=46931cf66146ce8fa8437828ec10afc1fcd582a7;hpb=0c8c3ac0d69536c36e5d345e9cb5bc9f23dcd470;p=flightgear.git diff --git a/src/Cockpit/radiostack.cxx b/src/Cockpit/radiostack.cxx index 46931cf66..4a6d38da5 100644 --- a/src/Cockpit/radiostack.cxx +++ b/src/Cockpit/radiostack.cxx @@ -21,36 +21,24 @@ // $Id$ +#ifdef HAVE_CONFIG_H +# include +#endif + +#include // snprintf + +#include +#include + #include -#include
#include +#include #include #include "radiostack.hxx" -/** - * Boy, this is ugly! Make the VOR range vary by altitude difference. - */ -static inline double -kludgeRange (double stationElev, double aircraftElev, double nominalRange) -{ - // Assume that the nominal range (usually - // 50nm) applies at a 5,000 ft difference. - // Just a wild guess! - double factor = ((aircraftElev*METER_TO_FEET) - stationElev) / 1000.0; - double range = fabs(nominalRange * factor); - - // Clamp the range to keep it sane; for - // now, never less than 25% or more than - // 500% of nominal range. - if (range < nominalRange/4.0) { - range = nominalRange/4.0; - } else if (range > nominalRange*5.0) { - range = nominalRange*5.0; - } - - return range; -} +#include +SG_USING_STD(string); FGRadioStack *current_radiostack; @@ -58,262 +46,88 @@ FGRadioStack *current_radiostack; // Constructor FGRadioStack::FGRadioStack() { - nav1_dme_dist = 0.0; - need_update = true; } // Destructor -FGRadioStack::~FGRadioStack() { +FGRadioStack::~FGRadioStack() +{ + adf.unbind(); + beacon.unbind(); + navcom1.unbind(); + navcom2.unbind(); + xponder.unbind(); } -// Search the database for the current frequencies given current location -void FGRadioStack::update( double lon, double lat, double elev ) { - need_update = false; - - Point3D aircraft = fgGeodToCart( Point3D( lon, lat, elev ) ); - Point3D station; - double az1, az2, s; - - if ( nav1_valid ) { - station = Point3D( nav1_x, nav1_y, nav1_z ); - nav1_loc_dist = aircraft.distance3D( station ); - - if ( nav1_has_dme ) { - // staightline distance - station = Point3D( nav1_dme_x, nav1_dme_y, nav1_dme_z ); - nav1_dme_dist = aircraft.distance3D( station ); - } else { - nav1_dme_dist = 0.0; - } - - if ( nav1_has_gs ) { - station = Point3D( nav1_gs_x, nav1_gs_y, nav1_gs_z ); - nav1_gs_dist = aircraft.distance3D( station ); - } else { - nav1_gs_dist = 0.0; - } - - if ( nav1_loc_dist < nav1_effective_range * NM_TO_METER ) { - nav1_inrange = true; - - // wgs84 heading - geo_inverse_wgs_84( elev, lat * RAD_TO_DEG, lon * RAD_TO_DEG, - nav1_loclat, nav1_loclon, - &az1, &az2, &s ); - nav1_heading = az1; - // Alex: nav1_heading = - (az1 - FGBFI::getMagVar() / RAD_TO_DEG); - - // cout << " heading = " << nav1_heading - // << " dist = " << nav1_dist << endl; - } else { - nav1_inrange = false; - } - - if ( nav1_loc ) { - } else { - nav1_radial = nav1_sel_radial; - } - } else { - nav1_inrange = false; - // cout << "not picking up vor. :-(" << endl; - } - - if ( nav2_valid ) { - station = Point3D( nav2_x, nav2_y, nav2_z ); - nav2_loc_dist = aircraft.distance3D( station ); - - if ( nav2_has_dme ) { - // staightline distance - station = Point3D( nav2_dme_x, nav2_dme_y, nav2_dme_z ); - nav2_dme_dist = aircraft.distance3D( station ); - } else { - nav2_dme_dist = 0.0; - } - - if ( nav2_has_gs ) { - station = Point3D( nav2_gs_x, nav2_gs_y, nav2_gs_z ); - nav2_gs_dist = aircraft.distance3D( station ); - } else { - nav2_gs_dist = 0.0; - } - - if ( nav2_loc_dist < nav2_effective_range * NM_TO_METER ) { - nav2_inrange = true; - - // wgs84 heading - geo_inverse_wgs_84( elev, lat * RAD_TO_DEG, lon * RAD_TO_DEG, - nav2_loclat, nav2_loclon, - &az1, &az2, &s ); - nav2_heading = az1; - // Alex: nav2_heading = - (az1 - FGBFI::getMagVar() / RAD_TO_DEG); - - // cout << " heading = " << nav2_heading - // << " dist = " << nav2_dist << endl; - } else { - nav2_inrange = false; - } - - if ( !nav2_loc ) { - nav2_radial = nav2_sel_radial; - } - } else { - nav2_inrange = false; - // cout << "not picking up vor. :-(" << endl; - } +void +FGRadioStack::init () +{ + navcom1.set_bind_index( 0 ); + navcom1.init(); - // adf - if ( adf_valid ) { - // staightline distance - station = Point3D( adf_x, adf_y, adf_z ); - adf_dist = aircraft.distance3D( station ); + navcom2.set_bind_index( 1 ); + navcom2.init(); - if ( adf_dist < adf_effective_range * NM_TO_METER ) { - adf_inrange = true; + adf.init(); + beacon.init(); + xponder.init(); - // wgs84 heading - geo_inverse_wgs_84( elev, lat * RAD_TO_DEG, lon * RAD_TO_DEG, - adf_lat, adf_lon, - &az1, &az2, &s ); - adf_heading = az1; + search(); + update(0); // FIXME: use dt - // cout << " heading = " << nav2_heading - // << " dist = " << nav2_dist << endl; - } else { - adf_inrange = false; - } - } else { - adf_inrange = false; - } + // Search radio database once per second + globals->get_event_mgr()->addTask( "fgRadioSearch()", current_radiostack, + &FGRadioStack::search, 1 ); } -// Update current nav/adf radio stations based on current postition -void FGRadioStack::search( double lon, double lat, double elev ) { - // nav1 - FGILS ils; - FGNav nav; - - if ( current_ilslist->query( lon, lat, elev, nav1_freq, &ils ) ) { - nav1_valid = true; - nav1_loc = true; - nav1_has_dme = ils.get_has_dme(); - nav1_has_gs = ils.get_has_gs(); - - nav1_loclon = ils.get_loclon(); - nav1_loclat = ils.get_loclat(); - nav1_gslon = ils.get_gslon(); - nav1_gslat = ils.get_gslat(); - nav1_dmelon = ils.get_dmelon(); - nav1_dmelat = ils.get_dmelat(); - nav1_elev = ils.get_gselev(); - nav1_effective_range = FG_ILS_DEFAULT_RANGE; - nav1_target_gs = ils.get_gsangle(); - nav1_radial = ils.get_locheading(); - while ( nav1_radial < 0.0 ) { nav1_radial += 360.0; } - while ( nav1_radial > 360.0 ) { nav1_radial -= 360.0; } - nav1_x = ils.get_x(); - nav1_y = ils.get_y(); - nav1_z = ils.get_z(); - nav1_gs_x = ils.get_gs_x(); - nav1_gs_y = ils.get_gs_y(); - nav1_gs_z = ils.get_gs_z(); - nav1_dme_x = ils.get_dme_x(); - nav1_dme_y = ils.get_dme_y(); - nav1_dme_z = ils.get_dme_z(); - // cout << "Found an ils station in range" << endl; - // cout << " id = " << ils.get_locident() << endl; - } else if ( current_navlist->query( lon, lat, elev, nav1_freq, &nav ) ) { - nav1_valid = true; - nav1_loc = false; - nav1_has_dme = nav.get_has_dme(); - nav1_has_gs = false; - nav1_loclon = nav.get_lon(); - nav1_loclat = nav.get_lat(); - nav1_elev = nav.get_elev(); - nav1_effective_range = kludgeRange(nav1_elev, elev, nav.get_range()); - nav1_target_gs = 0.0; - nav1_radial = nav1_sel_radial; - nav1_x = nav1_dme_x = nav.get_x(); - nav1_y = nav1_dme_y = nav.get_y(); - nav1_z = nav1_dme_z = nav.get_z(); - // cout << "Found a vor station in range" << endl; - // cout << " id = " << nav.get_ident() << endl; - } else { - nav1_valid = false; - // cout << "not picking up vor1. :-(" << endl; - } +void +FGRadioStack::bind () +{ + adf.bind(); + beacon.bind(); + dme.bind(); + navcom1.set_bind_index( 0 ); + navcom1.bind(); + navcom2.set_bind_index( 1 ); + navcom2.bind(); + xponder.bind(); +} - if ( current_ilslist->query( lon, lat, elev, nav2_freq, &ils ) ) { - nav2_valid = true; - nav2_loc = true; - nav2_has_dme = ils.get_has_dme(); - nav2_has_gs = ils.get_has_gs(); - nav2_loclon = ils.get_loclon(); - nav2_loclat = ils.get_loclat(); - nav2_elev = ils.get_gselev(); - nav2_effective_range = FG_ILS_DEFAULT_RANGE; - nav2_target_gs = ils.get_gsangle(); - nav2_radial = ils.get_locheading(); - while ( nav2_radial < 0.0 ) { nav2_radial += 360.0; } - while ( nav2_radial > 360.0 ) { nav2_radial -= 360.0; } - nav2_x = ils.get_x(); - nav2_y = ils.get_y(); - nav2_z = ils.get_z(); - nav2_gs_x = ils.get_gs_x(); - nav2_gs_y = ils.get_gs_y(); - nav2_gs_z = ils.get_gs_z(); - nav2_dme_x = ils.get_dme_x(); - nav2_dme_y = ils.get_dme_y(); - nav2_dme_z = ils.get_dme_z(); - // cout << "Found an ils station in range" << endl; - // cout << " id = " << ils.get_locident() << endl; - } else if ( current_navlist->query( lon, lat, elev, nav2_freq, &nav ) ) { - nav2_valid = true; - nav2_loc = false; - nav2_has_dme = nav.get_has_dme(); - nav2_has_dme = false; - nav2_loclon = nav.get_lon(); - nav2_loclat = nav.get_lat(); - nav2_elev = nav.get_elev(); - nav2_effective_range = kludgeRange(nav2_elev, elev, nav.get_range()); - nav2_target_gs = 0.0; - nav2_radial = nav2_sel_radial; - nav2_x = nav2_dme_x = nav.get_x(); - nav2_y = nav2_dme_y = nav.get_y(); - nav2_z = nav2_dme_z = nav.get_z(); - // cout << "Found a vor station in range" << endl; - // cout << " id = " << nav.get_ident() << endl; - } else { - nav2_valid = false; - // cout << "not picking up vor2. :-(" << endl; - } +void +FGRadioStack::unbind () +{ + adf.unbind(); + beacon.unbind(); + dme.unbind(); + navcom1.unbind(); + navcom2.unbind(); + xponder.unbind(); +} - // adf - if ( current_navlist->query( lon, lat, elev, adf_freq, &nav ) ) { - adf_valid = true; - adf_lon = nav.get_lon(); - adf_lat = nav.get_lat(); - adf_elev = nav.get_elev(); - adf_effective_range = kludgeRange(adf_elev, elev, nav.get_range()); - adf_x = nav.get_x(); - adf_y = nav.get_y(); - adf_z = nav.get_z(); - // cout << "Found an adf station in range" << endl; - // cout << " id = " << nav.get_ident() << endl; - } else { - adf_valid = false; - // cout << "not picking up adf. :-(" << endl; - } +// Update the various nav values based on position and valid tuned in navs +void +FGRadioStack::update(double dt) +{ + adf.update( dt ); + beacon.update( dt ); + navcom1.update( dt ); + navcom2.update( dt ); + dme.update( dt ); // dme is updated after the navcom's + xponder.update( dt ); } -// periodic radio station search wrapper -void fgRadioSearch( void ) { - current_radiostack->search( cur_fdm_state->get_Longitude(), - cur_fdm_state->get_Latitude(), - cur_fdm_state->get_Altitude() * FEET_TO_METER ); +// Update current nav/adf radio stations based on current postition +void FGRadioStack::search() +{ + adf.search(); + beacon.search(); + navcom1.search(); + navcom2.search(); + dme.search(); + xponder.search(); }