1 // bfi.cxx - Big Friendly Interface implementation
3 // Written by David Megginson, started February, 2000.
5 // Copyright (C) 2000 David Megginson - david@megginson.com
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 #if defined( FG_HAVE_NATIVE_SGI_COMPILERS )
29 # include <iostream.h>
34 #include <simgear/constants.h>
35 #include <simgear/debug/logstream.hxx>
36 #include <simgear/ephemeris/ephemeris.hxx>
37 #include <simgear/math/fg_types.hxx>
38 #include <simgear/misc/props.hxx>
39 #include <simgear/timing/sg_time.hxx>
41 #include <Aircraft/aircraft.hxx>
42 #include <FDM/UIUCModel/uiuc_aircraftdir.h>
43 #include <Controls/controls.hxx>
44 #include <Autopilot/newauto.hxx>
45 #include <Scenery/scenery.hxx>
46 #include <Time/light.hxx>
47 #include <Time/event.hxx>
48 #include <Time/sunpos.hxx>
49 #include <Time/tmp.hxx>
50 #include <Cockpit/radiostack.hxx>
51 #ifndef FG_OLD_WEATHER
52 # include <WeatherCM/FGLocalWeatherDatabase.h>
54 # include <Weather/weather.hxx>
57 #include "globals.hxx"
58 #include "options.hxx"
60 #include "fg_init.hxx"
61 #include <simgear/misc/props.hxx>
63 FG_USING_NAMESPACE(std);
70 ////////////////////////////////////////////////////////////////////////
72 ////////////////////////////////////////////////////////////////////////
74 bool FGBFI::_needReinit = false;
78 ////////////////////////////////////////////////////////////////////////
80 ////////////////////////////////////////////////////////////////////////
84 * Initialize the BFI by binding its functions to properties.
86 * TODO: perhaps these should migrate into the individual modules
87 * (i.e. they should register themselves).
92 FG_LOG(FG_GENERAL, FG_INFO, "Starting BFI init");
94 current_properties.tieInt("/sim/flight-model",
95 getFlightModel, setFlightModel);
96 // current_properties.tieString("/sim/aircraft",
97 // getAircraft, setAircraft);
99 current_properties.tieString("/sim/time/gmt-string",
101 current_properties.tieBool("/sim/hud/visibility",
102 getHUDVisible, setHUDVisible);
103 current_properties.tieBool("/sim/panel/visibility",
104 getPanelVisible, setPanelVisible);
107 current_properties.tieDouble("/position/latitude",
108 getLatitude, setLatitude);
109 current_properties.tieDouble("/position/longitude",
110 getLongitude, setLongitude);
111 current_properties.tieDouble("/position/altitude",
112 getAltitude, setAltitude);
113 current_properties.tieDouble("/position/altitude-agl",
117 current_properties.tieDouble("/orientation/heading",
118 getHeading, setHeading);
119 current_properties.tieDouble("/orientation/heading-magnetic",
121 current_properties.tieDouble("/orientation/pitch",
123 current_properties.tieDouble("/orientation/roll",
127 current_properties.tieDouble("/velocities/airspeed",
129 current_properties.tieDouble("/velocities/side-slip",
131 current_properties.tieDouble("/velocities/vertical-speed",
132 getVerticalSpeed, 0);
133 current_properties.tieDouble("/velocities/speed-north",
134 getSpeedNorth, setSpeedNorth);
135 current_properties.tieDouble("/velocities/speed-east",
136 getSpeedEast, setSpeedEast);
137 current_properties.tieDouble("/velocities/speed-down",
138 getSpeedDown, setSpeedDown);
141 current_properties.tieDouble("/controls/throttle",
142 getThrottle, setThrottle);
143 current_properties.tieDouble("/controls/flaps",
145 current_properties.tieDouble("/controls/aileron",
146 getAileron, setAileron);
147 current_properties.tieDouble("/controls/rudder",
148 getRudder, setRudder);
149 current_properties.tieDouble("/controls/elevator",
150 getElevator, setElevator);
151 current_properties.tieDouble("/controls/elevator-trim",
152 getElevatorTrim, setElevatorTrim);
153 current_properties.tieDouble("/controls/brakes/all",
154 getBrakes, setBrakes);
155 current_properties.tieDouble("/controls/brakes/left",
156 getLeftBrake, setLeftBrake);
157 current_properties.tieDouble("/controls/brakes/right",
158 getRightBrake, setRightBrake);
159 current_properties.tieDouble("/controls/brakes/center",
160 getRightBrake, setCenterBrake);
163 current_properties.tieDouble("/controls/brake",
164 getBrakes, setBrakes);
165 current_properties.tieDouble("/controls/left-brake",
166 getLeftBrake, setLeftBrake);
167 current_properties.tieDouble("/controls/right-brake",
168 getRightBrake, setRightBrake);
171 current_properties.tieBool("/autopilot/locks/altitude",
172 getAPAltitudeLock, setAPAltitudeLock);
173 current_properties.tieDouble("/autopilot/settings/altitude",
174 getAPAltitude, setAPAltitude);
175 current_properties.tieBool("/autopilot/locks/heading",
176 getAPHeadingLock, setAPHeadingLock);
177 current_properties.tieDouble("/autopilot/settings/heading",
178 getAPHeading, setAPHeading);
179 current_properties.tieDouble("/autopilot/settings/heading-magnetic",
180 getAPHeadingMag, setAPHeadingMag);
181 current_properties.tieBool("/autopilot/locks/nav1",
182 getAPNAV1Lock, setAPNAV1Lock);
185 current_properties.tieDouble("/radios/nav1/frequencies/selected",
186 getNAV1Freq, setNAV1Freq);
187 current_properties.tieDouble("/radios/nav1/frequencies/standby",
188 getNAV1AltFreq, setNAV1AltFreq);
189 current_properties.tieDouble("/radios/nav1/radials/actual",
191 current_properties.tieDouble("/radios/nav1/radials/selected",
192 getNAV1SelRadial, setNAV1SelRadial);
193 current_properties.tieDouble("/radios/nav1/dme/distance",
195 current_properties.tieBool("/radios/nav1/to-flag",
197 current_properties.tieBool("/radios/nav1/from-flag",
199 current_properties.tieBool("/radios/nav1/in-range",
201 current_properties.tieBool("/radios/nav1/dme/in-range",
202 getNAV1DMEInRange, 0);
204 current_properties.tieDouble("/radios/nav2/frequencies/selected",
205 getNAV2Freq, setNAV2Freq);
206 current_properties.tieDouble("/radios/nav2/frequencies/standby",
207 getNAV2AltFreq, setNAV2AltFreq);
208 current_properties.tieDouble("/radios/nav2/radials/actual",
210 current_properties.tieDouble("/radios/nav2/radials/selected",
211 getNAV2SelRadial, setNAV2SelRadial);
212 current_properties.tieDouble("/radios/nav2/dme/distance",
214 current_properties.tieBool("/radios/nav2/to-flag",
216 current_properties.tieBool("/radios/nav2/from-flag",
218 current_properties.tieBool("/radios/nav2/in-range",
220 current_properties.tieBool("/radios/nav2/dme/in-range",
221 getNAV2DMEInRange, 0);
223 current_properties.tieDouble("/radios/adf/frequencies/selected",
224 getADFFreq, setADFFreq);
225 current_properties.tieDouble("/radios/adf/frequencies/standby",
226 getADFAltFreq, setADFAltFreq);
227 current_properties.tieDouble("/radios/adf/rotation",
228 getADFRotation, setADFRotation);
230 FG_LOG(FG_GENERAL, FG_INFO, "Ending BFI init");
235 * Reinitialize FGFS if required.
237 * Some changes (especially those in aircraft position) require that
238 * FGFS be reinitialized afterwards. Rather than reinitialize after
239 * every change, the setter methods simply set a flag so that there
240 * can be a single reinit at the end of the frame.
252 * Reinitialize FGFS to use the new BFI settings.
257 // Save the state of everything
258 // that's going to get clobbered
259 // when we reinit the subsystems.
261 cout << "BFI: start reinit\n";
263 // setHeading(getHeading());
264 // setPitch(getPitch());
265 // setRoll(getRoll());
266 // setSpeedNorth(getSpeedNorth());
267 // setSpeedEast(getSpeedEast());
268 // setSpeedDown(getSpeedDown());
269 // setLatitude(getLatitude());
270 // setLongitude(getLongitude());
271 // setAltitude(getAltitude());
273 // TODO: add more AP stuff
274 double elevator = getElevator();
275 double aileron = getAileron();
276 double rudder = getRudder();
277 double throttle = getThrottle();
278 double elevator_trim = getElevatorTrim();
279 double flaps = getFlaps();
280 double brake = getBrakes();
281 bool apHeadingLock = getAPHeadingLock();
282 double apHeadingMag = getAPHeadingMag();
283 bool apAltitudeLock = getAPAltitudeLock();
284 double apAltitude = getAPAltitude();
285 const string &targetAirport = getTargetAirport();
286 bool gpsLock = getGPSLock();
287 double gpsLatitude = getGPSTargetLatitude();
288 double gpsLongitude = getGPSTargetLongitude();
290 setTargetAirport("");
291 cout << "Target airport is " << current_options.get_airport_id() << endl;
293 fgReInitSubsystems();
295 // FIXME: this is wrong.
296 // All of these are scheduled events,
297 // and it should be possible to force
298 // them all to run once.
301 cur_light_params.Update();
303 fgUpdateWeatherDatabase();
306 // Restore all of the old states.
307 setElevator(elevator);
310 setThrottle(throttle);
311 setElevatorTrim(elevator_trim);
314 setAPHeadingLock(apHeadingLock);
315 setAPHeadingMag(apHeadingMag);
316 setAPAltitudeLock(apAltitudeLock);
317 setAPAltitude(apAltitude);
318 setTargetAirport(targetAirport);
320 setGPSTargetLatitude(gpsLatitude);
321 setGPSTargetLongitude(gpsLongitude);
325 cout << "BFI: end reinit\n";
330 ////////////////////////////////////////////////////////////////////////
332 ////////////////////////////////////////////////////////////////////////
336 * Return the flight model as an integer.
338 * TODO: use a string instead.
341 FGBFI::getFlightModel ()
343 return current_options.get_flight_model();
348 * Return the current aircraft as a string.
351 FGBFI::getAircraft ()
353 return current_options.get_aircraft();
358 * Return the current aircraft directory (UIUC) as a string.
361 FGBFI::getAircraftDir ()
368 * Set the flight model as an integer.
370 * TODO: use a string instead.
373 FGBFI::setFlightModel (int model)
375 current_options.set_flight_model(model);
381 * Set the current aircraft.
384 FGBFI::setAircraft (const string &aircraft)
386 current_options.set_aircraft(aircraft);
392 * Set the current aircraft directory (UIUC).
395 FGBFI::setAircraftDir (const string &dir)
403 * Return the current Zulu time.
408 return globals->get_time_params()->get_cur_time();
413 * Set the current Zulu time.
416 FGBFI::setTimeGMT (time_t time)
418 // FIXME: need to update lighting
420 current_options.set_time_offset(time);
421 current_options.set_time_offset_type(fgOPTIONS::FG_TIME_GMT_ABSOLUTE);
422 globals->get_time_params()->update( cur_fdm_state->get_Longitude(),
423 cur_fdm_state->get_Latitude(),
424 globals->get_warp() );
430 * Return the GMT as a string.
433 FGBFI::getGMTString ()
435 static string out; // FIXME: not thread-safe
437 struct tm * t = globals->get_time_params()->getGmt();
438 sprintf(buf, " %.2d:%.2d:%.2d",
439 t->tm_hour, t->tm_min, t->tm_sec);
446 * Return true if the HUD is visible.
449 FGBFI::getHUDVisible ()
451 return current_options.get_hud_status();
456 * Ensure that the HUD is visible or hidden.
459 FGBFI::setHUDVisible (bool visible)
461 current_options.set_hud_status(visible);
466 * Return true if the 2D panel is visible.
469 FGBFI::getPanelVisible ()
471 return current_options.get_panel_status();
476 * Ensure that the 2D panel is visible or hidden.
479 FGBFI::setPanelVisible (bool visible)
481 if (current_options.get_panel_status() != visible) {
482 current_options.toggle_panel();
488 ////////////////////////////////////////////////////////////////////////
490 ////////////////////////////////////////////////////////////////////////
494 * Return the current latitude in degrees (negative for south).
497 FGBFI::getLatitude ()
499 return current_aircraft.fdm_state->get_Latitude() * RAD_TO_DEG;
504 * Set the current latitude in degrees (negative for south).
507 FGBFI::setLatitude (double latitude)
509 current_options.set_lat(latitude);
510 current_aircraft.fdm_state->set_Latitude(latitude * DEG_TO_RAD);
516 * Return the current longitude in degrees (negative for west).
519 FGBFI::getLongitude ()
521 return current_aircraft.fdm_state->get_Longitude() * RAD_TO_DEG;
526 * Set the current longitude in degrees (negative for west).
529 FGBFI::setLongitude (double longitude)
531 current_options.set_lon(longitude);
532 current_aircraft.fdm_state->set_Longitude(longitude * DEG_TO_RAD);
538 * Return the current altitude in feet.
541 FGBFI::getAltitude ()
543 return current_aircraft.fdm_state->get_Altitude();
549 * Return the current altitude in above the terrain.
554 return current_aircraft.fdm_state->get_Altitude()
555 - (scenery.cur_elev * METER_TO_FEET);
560 * Set the current altitude in feet.
563 FGBFI::setAltitude (double altitude)
565 fgFDMForceAltitude(getFlightModel(), altitude * FEET_TO_METER);
566 current_options.set_altitude(altitude * FEET_TO_METER);
567 current_aircraft.fdm_state->set_Altitude(altitude);
573 ////////////////////////////////////////////////////////////////////////
575 ////////////////////////////////////////////////////////////////////////
579 * Return the current heading in degrees.
584 return current_aircraft.fdm_state->get_Psi() * RAD_TO_DEG;
589 * Return the current heading in degrees.
592 FGBFI::getHeadingMag ()
594 return current_aircraft.fdm_state->get_Psi() * RAD_TO_DEG - getMagVar();
599 * Set the current heading in degrees.
602 FGBFI::setHeading (double heading)
604 current_options.set_heading(heading);
605 current_aircraft.fdm_state->set_Euler_Angles(getRoll() * DEG_TO_RAD,
606 getPitch() * DEG_TO_RAD,
607 heading * DEG_TO_RAD);
613 * Return the current pitch in degrees.
618 return current_aircraft.fdm_state->get_Theta() * RAD_TO_DEG;
623 * Set the current pitch in degrees.
626 FGBFI::setPitch (double pitch)
629 current_options.set_pitch(pitch);
630 current_aircraft.fdm_state->set_Euler_Angles(getRoll() * DEG_TO_RAD,
632 getHeading() * DEG_TO_RAD);
638 * Return the current roll in degrees.
643 return current_aircraft.fdm_state->get_Phi() * RAD_TO_DEG;
648 * Set the current roll in degrees.
651 FGBFI::setRoll (double roll)
653 current_options.set_roll(roll);
654 current_aircraft.fdm_state->set_Euler_Angles(roll * DEG_TO_RAD,
655 getPitch() * DEG_TO_RAD,
656 getHeading() * DEG_TO_RAD);
662 ////////////////////////////////////////////////////////////////////////
664 ////////////////////////////////////////////////////////////////////////
668 * Return the current airspeed in knots.
671 FGBFI::getAirspeed ()
673 // FIXME: should we add speed-up?
674 return current_aircraft.fdm_state->get_V_calibrated_kts();
679 * Return the current sideslip (FIXME: units unknown).
682 FGBFI::getSideSlip ()
684 return current_aircraft.fdm_state->get_Beta();
689 * Return the current climb rate in feet/minute
692 FGBFI::getVerticalSpeed ()
694 // What about meters?
695 return current_aircraft.fdm_state->get_Climb_Rate() * 60.0;
700 * Get the current north velocity (units??).
703 FGBFI::getSpeedNorth ()
705 return current_aircraft.fdm_state->get_V_north();
710 * Set the current north velocity (units??).
713 FGBFI::setSpeedNorth (double speed)
715 current_options.set_uBody(speed);
716 current_aircraft.fdm_state->set_Velocities_Local(speed,
724 * Get the current east velocity (units??).
727 FGBFI::getSpeedEast ()
729 return current_aircraft.fdm_state->get_V_east();
734 * Set the current east velocity (units??).
737 FGBFI::setSpeedEast (double speed)
739 current_options.set_vBody(speed);
740 current_aircraft.fdm_state->set_Velocities_Local(getSpeedNorth(),
748 * Get the current down velocity (units??).
751 FGBFI::getSpeedDown ()
753 return current_aircraft.fdm_state->get_V_down();
758 * Set the current down velocity (units??).
761 FGBFI::setSpeedDown (double speed)
763 current_options.set_wBody(speed);
764 current_aircraft.fdm_state->set_Velocities_Local(getSpeedNorth(),
772 ////////////////////////////////////////////////////////////////////////
774 ////////////////////////////////////////////////////////////////////////
778 * Get the throttle setting, from 0.0 (none) to 1.0 (full).
781 FGBFI::getThrottle ()
783 // FIXME: add throttle selector
784 return controls.get_throttle(0);
789 * Set the throttle, from 0.0 (none) to 1.0 (full).
792 FGBFI::setThrottle (double throttle)
794 // FIXME: allow throttle selection
796 controls.set_throttle(0, throttle);
801 * Get the flaps setting, from 0.0 (none) to 1.0 (full).
806 return controls.get_flaps();
811 * Set the flaps, from 0.0 (none) to 1.0 (full).
814 FGBFI::setFlaps (double flaps)
817 controls.set_flaps(flaps);
822 * Get the aileron, from -1.0 (left) to 1.0 (right).
827 return controls.get_aileron();
832 * Set the aileron, from -1.0 (left) to 1.0 (right).
835 FGBFI::setAileron (double aileron)
838 controls.set_aileron(aileron);
843 * Get the rudder setting, from -1.0 (left) to 1.0 (right).
848 return controls.get_rudder();
853 * Set the rudder, from -1.0 (left) to 1.0 (right).
856 FGBFI::setRudder (double rudder)
859 controls.set_rudder(rudder);
864 * Get the elevator setting, from -1.0 (down) to 1.0 (up).
867 FGBFI::getElevator ()
869 return controls.get_elevator();
874 * Set the elevator, from -1.0 (down) to 1.0 (up).
877 FGBFI::setElevator (double elevator)
880 controls.set_elevator(elevator);
885 * Get the elevator trim, from -1.0 (down) to 1.0 (up).
888 FGBFI::getElevatorTrim ()
890 return controls.get_elevator_trim();
895 * Set the elevator trim, from -1.0 (down) to 1.0 (up).
898 FGBFI::setElevatorTrim (double trim)
901 controls.set_elevator_trim(trim);
906 * Get the highest brake setting, from 0.0 (none) to 1.0 (full).
911 double b1 = getCenterBrake();
912 double b2 = getLeftBrake();
913 double b3 = getRightBrake();
914 return (b1 > b2 ? (b1 > b3 ? b1 : b3) : (b2 > b3 ? b2 : b3));
919 * Set all brakes, from 0.0 (none) to 1.0 (full).
922 FGBFI::setBrakes (double brake)
924 setCenterBrake(brake);
926 setRightBrake(brake);
931 * Get the center brake, from 0.0 (none) to 1.0 (full).
934 FGBFI::getCenterBrake ()
936 return controls.get_brake(2);
941 * Set the center brake, from 0.0 (none) to 1.0 (full).
944 FGBFI::setCenterBrake (double brake)
946 controls.set_brake(2, brake);
951 * Get the left brake, from 0.0 (none) to 1.0 (full).
954 FGBFI::getLeftBrake ()
956 return controls.get_brake(0);
961 * Set the left brake, from 0.0 (none) to 1.0 (full).
964 FGBFI::setLeftBrake (double brake)
966 controls.set_brake(0, brake);
971 * Get the right brake, from 0.0 (none) to 1.0 (full).
974 FGBFI::getRightBrake ()
976 return controls.get_brake(1);
981 * Set the right brake, from 0.0 (none) to 1.0 (full).
984 FGBFI::setRightBrake (double brake)
986 controls.set_brake(1, brake);
993 ////////////////////////////////////////////////////////////////////////
995 ////////////////////////////////////////////////////////////////////////
999 * Get the autopilot altitude lock (true=on).
1002 FGBFI::getAPAltitudeLock ()
1004 return current_autopilot->get_AltitudeEnabled();
1009 * Set the autopilot altitude lock (true=on).
1012 FGBFI::setAPAltitudeLock (bool lock)
1014 current_autopilot->set_AltitudeMode(FGAutopilot::FG_ALTITUDE_LOCK);
1015 current_autopilot->set_AltitudeEnabled(lock);
1020 * Get the autopilot target altitude in feet.
1023 FGBFI::getAPAltitude ()
1025 return current_autopilot->get_TargetAltitude() * METER_TO_FEET;
1030 * Set the autopilot target altitude in feet.
1033 FGBFI::setAPAltitude (double altitude)
1035 current_autopilot->set_TargetAltitude( altitude );
1040 * Get the autopilot heading lock (true=on).
1043 FGBFI::getAPHeadingLock ()
1046 (current_autopilot->get_HeadingEnabled() &&
1047 current_autopilot->get_HeadingMode() == FGAutopilot::FG_HEADING_LOCK);
1052 * Set the autopilot heading lock (true=on).
1055 FGBFI::setAPHeadingLock (bool lock)
1058 // We need to do this so that
1059 // it's possible to lock onto a
1060 // heading other than the current
1062 double heading = getAPHeadingMag();
1063 current_autopilot->set_HeadingMode(FGAutopilot::FG_HEADING_LOCK);
1064 current_autopilot->set_HeadingEnabled(true);
1065 setAPHeadingMag(heading);
1066 } else if (current_autopilot->get_HeadingMode() ==
1067 FGAutopilot::FG_HEADING_LOCK) {
1068 current_autopilot->set_HeadingEnabled(false);
1074 * Get the autopilot target heading in degrees.
1077 FGBFI::getAPHeading ()
1079 return current_autopilot->get_TargetHeading();
1084 * Set the autopilot target heading in degrees.
1087 FGBFI::setAPHeading (double heading)
1089 current_autopilot->set_TargetHeading( heading );
1094 * Get the autopilot target heading in degrees.
1097 FGBFI::getAPHeadingMag ()
1099 return current_autopilot->get_TargetHeading() - getMagVar();
1104 * Set the autopilot target heading in degrees.
1107 FGBFI::setAPHeadingMag (double heading)
1109 current_autopilot->set_TargetHeading( heading + getMagVar() );
1114 * Return true if the autopilot is locked to NAV1.
1117 FGBFI::getAPNAV1Lock ()
1120 (current_autopilot->get_HeadingEnabled() &&
1121 current_autopilot->get_HeadingMode() == FGAutopilot::FG_HEADING_NAV1);
1126 * Set the autopilot NAV1 lock.
1129 FGBFI::setAPNAV1Lock (bool lock)
1132 current_autopilot->set_HeadingMode(FGAutopilot::FG_HEADING_NAV1);
1133 current_autopilot->set_HeadingEnabled(true);
1134 } else if (current_autopilot->get_HeadingMode() ==
1135 FGAutopilot::FG_HEADING_NAV1) {
1136 current_autopilot->set_HeadingEnabled(false);
1142 ////////////////////////////////////////////////////////////////////////
1143 // Radio navigation.
1144 ////////////////////////////////////////////////////////////////////////
1147 FGBFI::getNAV1Freq ()
1149 return current_radiostack->get_nav1_freq();
1153 FGBFI::getNAV1AltFreq ()
1155 return current_radiostack->get_nav1_alt_freq();
1159 FGBFI::getNAV1Radial ()
1161 return current_radiostack->get_nav1_radial();
1165 FGBFI::getNAV1SelRadial ()
1167 return current_radiostack->get_nav1_sel_radial();
1171 FGBFI::getNAV1DistDME ()
1173 return current_radiostack->get_nav1_dme_dist();
1179 if (current_radiostack->get_nav1_inrange()) {
1180 double heading = current_radiostack->get_nav1_heading();
1181 double radial = current_radiostack->get_nav1_radial();
1182 double var = FGBFI::getMagVar();
1183 if (current_radiostack->get_nav1_loc()) {
1184 double offset = fabs(heading - radial);
1185 return (offset<= 8.0 || offset >= 352.0);
1188 fabs(heading - var - radial);
1189 return (offset <= 20.0 || offset >= 340.0);
1197 FGBFI::getNAV1FROM ()
1199 if (current_radiostack->get_nav1_inrange()) {
1200 double heading = current_radiostack->get_nav1_heading();
1201 double radial = current_radiostack->get_nav1_radial();
1202 double var = FGBFI::getMagVar();
1203 if (current_radiostack->get_nav1_loc()) {
1204 double offset = fabs(heading - radial);
1205 return (offset >= 172.0 && offset<= 188.0);
1208 fabs(heading - var - radial);
1209 return (offset >= 160.0 && offset <= 200.0);
1217 FGBFI::getNAV1InRange ()
1219 return current_radiostack->get_nav1_inrange();
1223 FGBFI::getNAV1DMEInRange ()
1225 return (current_radiostack->get_nav1_inrange() &&
1226 current_radiostack->get_nav1_has_dme());
1230 FGBFI::getNAV2Freq ()
1232 return current_radiostack->get_nav2_freq();
1236 FGBFI::getNAV2AltFreq ()
1238 return current_radiostack->get_nav2_alt_freq();
1242 FGBFI::getNAV2Radial ()
1244 return current_radiostack->get_nav2_radial();
1248 FGBFI::getNAV2SelRadial ()
1250 return current_radiostack->get_nav2_sel_radial();
1254 FGBFI::getNAV2DistDME ()
1256 return current_radiostack->get_nav2_dme_dist();
1262 if (current_radiostack->get_nav2_inrange()) {
1263 double heading = current_radiostack->get_nav2_heading();
1264 double radial = current_radiostack->get_nav2_radial();
1265 double var = FGBFI::getMagVar();
1266 if (current_radiostack->get_nav2_loc()) {
1267 double offset = fabs(heading - radial);
1268 return (offset<= 8.0 || offset >= 352.0);
1271 fabs(heading - var - radial);
1272 return (offset <= 20.0 || offset >= 340.0);
1280 FGBFI::getNAV2FROM ()
1282 if (current_radiostack->get_nav2_inrange()) {
1283 double heading = current_radiostack->get_nav2_heading();
1284 double radial = current_radiostack->get_nav2_radial();
1285 double var = FGBFI::getMagVar();
1286 if (current_radiostack->get_nav2_loc()) {
1287 double offset = fabs(heading - radial);
1288 return (offset >= 172.0 && offset<= 188.0);
1291 fabs(heading - var - radial);
1292 return (offset >= 160.0 && offset <= 200.0);
1301 FGBFI::getNAV2InRange ()
1303 return current_radiostack->get_nav2_inrange();
1307 FGBFI::getNAV2DMEInRange ()
1309 return (current_radiostack->get_nav2_inrange() &&
1310 current_radiostack->get_nav2_has_dme());
1314 FGBFI::getADFFreq ()
1316 return current_radiostack->get_adf_freq();
1320 FGBFI::getADFAltFreq ()
1322 return current_radiostack->get_adf_alt_freq();
1326 FGBFI::getADFRotation ()
1328 return current_radiostack->get_adf_rotation();
1332 FGBFI::setNAV1Freq (double freq)
1334 current_radiostack->set_nav1_freq(freq);
1338 FGBFI::setNAV1AltFreq (double freq)
1340 current_radiostack->set_nav1_alt_freq(freq);
1344 FGBFI::setNAV1SelRadial (double radial)
1346 current_radiostack->set_nav1_sel_radial(radial);
1350 FGBFI::setNAV2Freq (double freq)
1352 current_radiostack->set_nav2_freq(freq);
1356 FGBFI::setNAV2AltFreq (double freq)
1358 current_radiostack->set_nav2_alt_freq(freq);
1362 FGBFI::setNAV2SelRadial (double radial)
1364 current_radiostack->set_nav2_sel_radial(radial);
1368 FGBFI::setADFFreq (double freq)
1370 current_radiostack->set_adf_freq(freq);
1374 FGBFI::setADFAltFreq (double freq)
1376 current_radiostack->set_adf_alt_freq(freq);
1380 FGBFI::setADFRotation (double rot)
1382 current_radiostack->set_adf_rotation(rot);
1387 ////////////////////////////////////////////////////////////////////////
1389 ////////////////////////////////////////////////////////////////////////
1393 * Get the autopilot GPS lock (true=on).
1396 FGBFI::getGPSLock ()
1398 return (current_autopilot->get_HeadingEnabled() &&
1399 (current_autopilot->get_HeadingMode() ==
1400 FGAutopilot::FG_HEADING_WAYPOINT ));
1405 * Set the autopilot GPS lock (true=on).
1408 FGBFI::setGPSLock (bool lock)
1411 current_autopilot->set_HeadingMode(FGAutopilot::FG_HEADING_WAYPOINT);
1412 current_autopilot->set_HeadingEnabled(true);
1413 } else if (current_autopilot->get_HeadingMode() ==
1414 FGAutopilot::FG_HEADING_WAYPOINT) {
1415 current_autopilot->set_HeadingEnabled(false);
1421 * Get the GPS target airport code.
1424 FGBFI::getTargetAirport ()
1426 return current_options.get_airport_id();
1431 * Set the GPS target airport code.
1434 FGBFI::setTargetAirport (const string &airportId)
1436 current_options.set_airport_id(airportId);
1441 * Get the GPS target latitude in degrees (negative for south).
1444 FGBFI::getGPSTargetLatitude ()
1446 return current_autopilot->get_TargetLatitude();
1451 * Set the GPS target latitude in degrees (negative for south).
1454 FGBFI::setGPSTargetLatitude (double latitude)
1456 current_autopilot->set_TargetLatitude( latitude );
1461 * Get the GPS target longitude in degrees (negative for west).
1464 FGBFI::getGPSTargetLongitude ()
1466 return current_autopilot->get_TargetLongitude();
1471 * Set the GPS target longitude in degrees (negative for west).
1474 FGBFI::setGPSTargetLongitude (double longitude)
1476 current_autopilot->set_TargetLongitude( longitude );
1481 ////////////////////////////////////////////////////////////////////////
1483 ////////////////////////////////////////////////////////////////////////
1487 * Get the current visible (units??).
1490 FGBFI::getVisibility ()
1492 #ifndef FG_OLD_WEATHER
1493 return WeatherDatabase->getWeatherVisibility();
1495 return current_weather.get_visibility();
1501 * Check whether clouds are enabled.
1506 return current_options.get_clouds();
1511 * Check the height of the clouds ASL (units?).
1514 FGBFI::getCloudsASL ()
1516 return current_options.get_clouds_asl();
1521 * Set the current visibility (units??).
1524 FGBFI::setVisibility (double visibility)
1526 #ifndef FG_OLD_WEATHER
1527 WeatherDatabase->setWeatherVisibility(visibility);
1529 current_weather.set_visibility(visibility);
1535 * Switch clouds on or off.
1538 FGBFI::setClouds (bool clouds)
1540 cout << "Set clouds to " << clouds << endl;
1541 current_options.set_clouds(clouds);
1547 * Set the cloud height.
1550 FGBFI::setCloudsASL (double cloudsASL)
1552 current_options.set_clouds_asl(cloudsASL);
1558 ////////////////////////////////////////////////////////////////////////
1560 ////////////////////////////////////////////////////////////////////////
1563 * Return the magnetic variation
1568 return globals->get_mag()->get_magvar() * RAD_TO_DEG;
1573 * Return the magnetic variation
1578 return globals->get_mag()->get_magdip() * RAD_TO_DEG;