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/sg_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("/engine0/rpm",
131 current_properties.tieDouble("/velocities/airspeed",
133 current_properties.tieDouble("/velocities/side-slip",
135 current_properties.tieDouble("/velocities/vertical-speed",
136 getVerticalSpeed, 0);
137 current_properties.tieDouble("/velocities/speed-north",
138 getSpeedNorth, setSpeedNorth);
139 current_properties.tieDouble("/velocities/speed-east",
140 getSpeedEast, setSpeedEast);
141 current_properties.tieDouble("/velocities/speed-down",
142 getSpeedDown, setSpeedDown);
145 current_properties.tieDouble("/controls/throttle",
146 getThrottle, setThrottle);
147 current_properties.tieDouble("/controls/flaps",
149 current_properties.tieDouble("/controls/aileron",
150 getAileron, setAileron);
151 current_properties.tieDouble("/controls/rudder",
152 getRudder, setRudder);
153 current_properties.tieDouble("/controls/elevator",
154 getElevator, setElevator);
155 current_properties.tieDouble("/controls/elevator-trim",
156 getElevatorTrim, setElevatorTrim);
157 current_properties.tieDouble("/controls/brakes/all",
158 getBrakes, setBrakes);
159 current_properties.tieDouble("/controls/brakes/left",
160 getLeftBrake, setLeftBrake);
161 current_properties.tieDouble("/controls/brakes/right",
162 getRightBrake, setRightBrake);
163 current_properties.tieDouble("/controls/brakes/center",
164 getRightBrake, setCenterBrake);
167 current_properties.tieDouble("/controls/brake",
168 getBrakes, setBrakes);
169 current_properties.tieDouble("/controls/left-brake",
170 getLeftBrake, setLeftBrake);
171 current_properties.tieDouble("/controls/right-brake",
172 getRightBrake, setRightBrake);
175 current_properties.tieBool("/autopilot/locks/altitude",
176 getAPAltitudeLock, setAPAltitudeLock);
177 current_properties.tieDouble("/autopilot/settings/altitude",
178 getAPAltitude, setAPAltitude);
179 current_properties.tieBool("/autopilot/locks/heading",
180 getAPHeadingLock, setAPHeadingLock);
181 current_properties.tieDouble("/autopilot/settings/heading",
182 getAPHeading, setAPHeading);
183 current_properties.tieDouble("/autopilot/settings/heading-magnetic",
184 getAPHeadingMag, setAPHeadingMag);
185 current_properties.tieBool("/autopilot/locks/nav1",
186 getAPNAV1Lock, setAPNAV1Lock);
189 current_properties.tieDouble("/radios/nav1/frequencies/selected",
190 getNAV1Freq, setNAV1Freq);
191 current_properties.tieDouble("/radios/nav1/frequencies/standby",
192 getNAV1AltFreq, setNAV1AltFreq);
193 current_properties.tieDouble("/radios/nav1/radials/actual",
195 current_properties.tieDouble("/radios/nav1/radials/selected",
196 getNAV1SelRadial, setNAV1SelRadial);
197 current_properties.tieDouble("/radios/nav1/dme/distance",
199 current_properties.tieBool("/radios/nav1/to-flag",
201 current_properties.tieBool("/radios/nav1/from-flag",
203 current_properties.tieBool("/radios/nav1/in-range",
205 current_properties.tieBool("/radios/nav1/dme/in-range",
206 getNAV1DMEInRange, 0);
208 current_properties.tieDouble("/radios/nav2/frequencies/selected",
209 getNAV2Freq, setNAV2Freq);
210 current_properties.tieDouble("/radios/nav2/frequencies/standby",
211 getNAV2AltFreq, setNAV2AltFreq);
212 current_properties.tieDouble("/radios/nav2/radials/actual",
214 current_properties.tieDouble("/radios/nav2/radials/selected",
215 getNAV2SelRadial, setNAV2SelRadial);
216 current_properties.tieDouble("/radios/nav2/dme/distance",
218 current_properties.tieBool("/radios/nav2/to-flag",
220 current_properties.tieBool("/radios/nav2/from-flag",
222 current_properties.tieBool("/radios/nav2/in-range",
224 current_properties.tieBool("/radios/nav2/dme/in-range",
225 getNAV2DMEInRange, 0);
227 current_properties.tieDouble("/radios/adf/frequencies/selected",
228 getADFFreq, setADFFreq);
229 current_properties.tieDouble("/radios/adf/frequencies/standby",
230 getADFAltFreq, setADFAltFreq);
231 current_properties.tieDouble("/radios/adf/rotation",
232 getADFRotation, setADFRotation);
234 FG_LOG(FG_GENERAL, FG_INFO, "Ending BFI init");
239 * Reinitialize FGFS if required.
241 * Some changes (especially those in aircraft position) require that
242 * FGFS be reinitialized afterwards. Rather than reinitialize after
243 * every change, the setter methods simply set a flag so that there
244 * can be a single reinit at the end of the frame.
256 * Reinitialize FGFS to use the new BFI settings.
261 // Save the state of everything
262 // that's going to get clobbered
263 // when we reinit the subsystems.
265 cout << "BFI: start reinit\n";
267 // setHeading(getHeading());
268 // setPitch(getPitch());
269 // setRoll(getRoll());
270 // setSpeedNorth(getSpeedNorth());
271 // setSpeedEast(getSpeedEast());
272 // setSpeedDown(getSpeedDown());
273 // setLatitude(getLatitude());
274 // setLongitude(getLongitude());
275 // setAltitude(getAltitude());
277 // TODO: add more AP stuff
278 double elevator = getElevator();
279 double aileron = getAileron();
280 double rudder = getRudder();
281 double throttle = getThrottle();
282 double elevator_trim = getElevatorTrim();
283 double flaps = getFlaps();
284 double brake = getBrakes();
285 bool apHeadingLock = getAPHeadingLock();
286 double apHeadingMag = getAPHeadingMag();
287 bool apAltitudeLock = getAPAltitudeLock();
288 double apAltitude = getAPAltitude();
289 const string &targetAirport = getTargetAirport();
290 bool gpsLock = getGPSLock();
291 double gpsLatitude = getGPSTargetLatitude();
292 double gpsLongitude = getGPSTargetLongitude();
294 setTargetAirport("");
295 cout << "Target airport is " << current_options.get_airport_id() << endl;
297 fgReInitSubsystems();
299 // FIXME: this is wrong.
300 // All of these are scheduled events,
301 // and it should be possible to force
302 // them all to run once.
305 cur_light_params.Update();
307 fgUpdateWeatherDatabase();
310 // Restore all of the old states.
311 setElevator(elevator);
314 setThrottle(throttle);
315 setElevatorTrim(elevator_trim);
318 setAPHeadingLock(apHeadingLock);
319 setAPHeadingMag(apHeadingMag);
320 setAPAltitudeLock(apAltitudeLock);
321 setAPAltitude(apAltitude);
322 setTargetAirport(targetAirport);
324 setGPSTargetLatitude(gpsLatitude);
325 setGPSTargetLongitude(gpsLongitude);
329 cout << "BFI: end reinit\n";
334 ////////////////////////////////////////////////////////////////////////
336 ////////////////////////////////////////////////////////////////////////
340 * Return the flight model as an integer.
342 * TODO: use a string instead.
345 FGBFI::getFlightModel ()
347 return current_options.get_flight_model();
352 * Return the current aircraft as a string.
355 FGBFI::getAircraft ()
357 return current_options.get_aircraft();
362 * Return the current aircraft directory (UIUC) as a string.
365 FGBFI::getAircraftDir ()
372 * Set the flight model as an integer.
374 * TODO: use a string instead.
377 FGBFI::setFlightModel (int model)
379 current_options.set_flight_model(model);
385 * Set the current aircraft.
388 FGBFI::setAircraft (const string &aircraft)
390 current_options.set_aircraft(aircraft);
396 * Set the current aircraft directory (UIUC).
399 FGBFI::setAircraftDir (const string &dir)
407 * Return the current Zulu time.
412 return globals->get_time_params()->get_cur_time();
417 * Set the current Zulu time.
420 FGBFI::setTimeGMT (time_t time)
422 // FIXME: need to update lighting
424 current_options.set_time_offset(time);
425 current_options.set_time_offset_type(fgOPTIONS::FG_TIME_GMT_ABSOLUTE);
426 globals->get_time_params()->update( cur_fdm_state->get_Longitude(),
427 cur_fdm_state->get_Latitude(),
428 globals->get_warp() );
434 * Return the GMT as a string.
437 FGBFI::getGMTString ()
439 static string out; // FIXME: not thread-safe
441 struct tm * t = globals->get_time_params()->getGmt();
442 sprintf(buf, " %.2d:%.2d:%.2d",
443 t->tm_hour, t->tm_min, t->tm_sec);
450 * Return true if the HUD is visible.
453 FGBFI::getHUDVisible ()
455 return current_options.get_hud_status();
460 * Ensure that the HUD is visible or hidden.
463 FGBFI::setHUDVisible (bool visible)
465 current_options.set_hud_status(visible);
470 * Return true if the 2D panel is visible.
473 FGBFI::getPanelVisible ()
475 return current_options.get_panel_status();
480 * Ensure that the 2D panel is visible or hidden.
483 FGBFI::setPanelVisible (bool visible)
485 if (current_options.get_panel_status() != visible) {
486 current_options.toggle_panel();
492 ////////////////////////////////////////////////////////////////////////
494 ////////////////////////////////////////////////////////////////////////
498 * Return the current latitude in degrees (negative for south).
501 FGBFI::getLatitude ()
503 return current_aircraft.fdm_state->get_Latitude() * RAD_TO_DEG;
508 * Set the current latitude in degrees (negative for south).
511 FGBFI::setLatitude (double latitude)
513 current_options.set_lat(latitude);
514 current_aircraft.fdm_state->set_Latitude(latitude * DEG_TO_RAD);
520 * Return the current longitude in degrees (negative for west).
523 FGBFI::getLongitude ()
525 return current_aircraft.fdm_state->get_Longitude() * RAD_TO_DEG;
530 * Set the current longitude in degrees (negative for west).
533 FGBFI::setLongitude (double longitude)
535 current_options.set_lon(longitude);
536 current_aircraft.fdm_state->set_Longitude(longitude * DEG_TO_RAD);
542 * Return the current altitude in feet.
545 FGBFI::getAltitude ()
547 return current_aircraft.fdm_state->get_Altitude();
553 * Return the current altitude in above the terrain.
558 return current_aircraft.fdm_state->get_Altitude()
559 - (scenery.cur_elev * METER_TO_FEET);
564 * Set the current altitude in feet.
567 FGBFI::setAltitude (double altitude)
569 fgFDMForceAltitude(getFlightModel(), altitude * FEET_TO_METER);
570 current_options.set_altitude(altitude * FEET_TO_METER);
571 current_aircraft.fdm_state->set_Altitude(altitude);
577 ////////////////////////////////////////////////////////////////////////
579 ////////////////////////////////////////////////////////////////////////
583 * Return the current heading in degrees.
588 return current_aircraft.fdm_state->get_Psi() * RAD_TO_DEG;
593 * Return the current heading in degrees.
596 FGBFI::getHeadingMag ()
598 return current_aircraft.fdm_state->get_Psi() * RAD_TO_DEG - getMagVar();
603 * Set the current heading in degrees.
606 FGBFI::setHeading (double heading)
608 current_options.set_heading(heading);
609 current_aircraft.fdm_state->set_Euler_Angles(getRoll() * DEG_TO_RAD,
610 getPitch() * DEG_TO_RAD,
611 heading * DEG_TO_RAD);
617 * Return the current pitch in degrees.
622 return current_aircraft.fdm_state->get_Theta() * RAD_TO_DEG;
627 * Set the current pitch in degrees.
630 FGBFI::setPitch (double pitch)
633 current_options.set_pitch(pitch);
634 current_aircraft.fdm_state->set_Euler_Angles(getRoll() * DEG_TO_RAD,
636 getHeading() * DEG_TO_RAD);
642 * Return the current roll in degrees.
647 return current_aircraft.fdm_state->get_Phi() * RAD_TO_DEG;
652 * Set the current roll in degrees.
655 FGBFI::setRoll (double roll)
657 current_options.set_roll(roll);
658 current_aircraft.fdm_state->set_Euler_Angles(roll * DEG_TO_RAD,
659 getPitch() * DEG_TO_RAD,
660 getHeading() * DEG_TO_RAD);
666 * Return the current engine0 rpm
671 return current_aircraft.fdm_state->get_engine(0)->get_RPM();
676 * Set the current engine0 rpm
679 FGBFI::setRPM (double rpm)
681 current_aircraft.fdm_state->get_engine(0)->set_RPM( rpm );
686 ////////////////////////////////////////////////////////////////////////
688 ////////////////////////////////////////////////////////////////////////
692 * Return the current airspeed in knots.
695 FGBFI::getAirspeed ()
697 // FIXME: should we add speed-up?
698 return current_aircraft.fdm_state->get_V_calibrated_kts();
703 * Return the current sideslip (FIXME: units unknown).
706 FGBFI::getSideSlip ()
708 return current_aircraft.fdm_state->get_Beta();
713 * Return the current climb rate in feet/minute
716 FGBFI::getVerticalSpeed ()
718 // What about meters?
719 return current_aircraft.fdm_state->get_Climb_Rate() * 60.0;
724 * Get the current north velocity (units??).
727 FGBFI::getSpeedNorth ()
729 return current_aircraft.fdm_state->get_V_north();
734 * Set the current north velocity (units??).
737 FGBFI::setSpeedNorth (double speed)
739 current_options.set_uBody(speed);
740 current_aircraft.fdm_state->set_Velocities_Local(speed,
748 * Get the current east velocity (units??).
751 FGBFI::getSpeedEast ()
753 return current_aircraft.fdm_state->get_V_east();
758 * Set the current east velocity (units??).
761 FGBFI::setSpeedEast (double speed)
763 current_options.set_vBody(speed);
764 current_aircraft.fdm_state->set_Velocities_Local(getSpeedNorth(),
772 * Get the current down velocity (units??).
775 FGBFI::getSpeedDown ()
777 return current_aircraft.fdm_state->get_V_down();
782 * Set the current down velocity (units??).
785 FGBFI::setSpeedDown (double speed)
787 current_options.set_wBody(speed);
788 current_aircraft.fdm_state->set_Velocities_Local(getSpeedNorth(),
796 ////////////////////////////////////////////////////////////////////////
798 ////////////////////////////////////////////////////////////////////////
802 * Get the throttle setting, from 0.0 (none) to 1.0 (full).
805 FGBFI::getThrottle ()
807 // FIXME: add throttle selector
808 return controls.get_throttle(0);
813 * Set the throttle, from 0.0 (none) to 1.0 (full).
816 FGBFI::setThrottle (double throttle)
818 // FIXME: allow throttle selection
820 controls.set_throttle(0, throttle);
825 * Get the flaps setting, from 0.0 (none) to 1.0 (full).
830 return controls.get_flaps();
835 * Set the flaps, from 0.0 (none) to 1.0 (full).
838 FGBFI::setFlaps (double flaps)
841 controls.set_flaps(flaps);
846 * Get the aileron, from -1.0 (left) to 1.0 (right).
851 return controls.get_aileron();
856 * Set the aileron, from -1.0 (left) to 1.0 (right).
859 FGBFI::setAileron (double aileron)
862 controls.set_aileron(aileron);
867 * Get the rudder setting, from -1.0 (left) to 1.0 (right).
872 return controls.get_rudder();
877 * Set the rudder, from -1.0 (left) to 1.0 (right).
880 FGBFI::setRudder (double rudder)
883 controls.set_rudder(rudder);
888 * Get the elevator setting, from -1.0 (down) to 1.0 (up).
891 FGBFI::getElevator ()
893 return controls.get_elevator();
898 * Set the elevator, from -1.0 (down) to 1.0 (up).
901 FGBFI::setElevator (double elevator)
904 controls.set_elevator(elevator);
909 * Get the elevator trim, from -1.0 (down) to 1.0 (up).
912 FGBFI::getElevatorTrim ()
914 return controls.get_elevator_trim();
919 * Set the elevator trim, from -1.0 (down) to 1.0 (up).
922 FGBFI::setElevatorTrim (double trim)
925 controls.set_elevator_trim(trim);
930 * Get the highest brake setting, from 0.0 (none) to 1.0 (full).
935 double b1 = getCenterBrake();
936 double b2 = getLeftBrake();
937 double b3 = getRightBrake();
938 return (b1 > b2 ? (b1 > b3 ? b1 : b3) : (b2 > b3 ? b2 : b3));
943 * Set all brakes, from 0.0 (none) to 1.0 (full).
946 FGBFI::setBrakes (double brake)
948 setCenterBrake(brake);
950 setRightBrake(brake);
955 * Get the center brake, from 0.0 (none) to 1.0 (full).
958 FGBFI::getCenterBrake ()
960 return controls.get_brake(2);
965 * Set the center brake, from 0.0 (none) to 1.0 (full).
968 FGBFI::setCenterBrake (double brake)
970 controls.set_brake(2, brake);
975 * Get the left brake, from 0.0 (none) to 1.0 (full).
978 FGBFI::getLeftBrake ()
980 return controls.get_brake(0);
985 * Set the left brake, from 0.0 (none) to 1.0 (full).
988 FGBFI::setLeftBrake (double brake)
990 controls.set_brake(0, brake);
995 * Get the right brake, from 0.0 (none) to 1.0 (full).
998 FGBFI::getRightBrake ()
1000 return controls.get_brake(1);
1005 * Set the right brake, from 0.0 (none) to 1.0 (full).
1008 FGBFI::setRightBrake (double brake)
1010 controls.set_brake(1, brake);
1017 ////////////////////////////////////////////////////////////////////////
1019 ////////////////////////////////////////////////////////////////////////
1023 * Get the autopilot altitude lock (true=on).
1026 FGBFI::getAPAltitudeLock ()
1028 return current_autopilot->get_AltitudeEnabled();
1033 * Set the autopilot altitude lock (true=on).
1036 FGBFI::setAPAltitudeLock (bool lock)
1038 current_autopilot->set_AltitudeMode(FGAutopilot::FG_ALTITUDE_LOCK);
1039 current_autopilot->set_AltitudeEnabled(lock);
1044 * Get the autopilot target altitude in feet.
1047 FGBFI::getAPAltitude ()
1049 return current_autopilot->get_TargetAltitude() * METER_TO_FEET;
1054 * Set the autopilot target altitude in feet.
1057 FGBFI::setAPAltitude (double altitude)
1059 current_autopilot->set_TargetAltitude( altitude );
1064 * Get the autopilot heading lock (true=on).
1067 FGBFI::getAPHeadingLock ()
1070 (current_autopilot->get_HeadingEnabled() &&
1071 current_autopilot->get_HeadingMode() == FGAutopilot::FG_HEADING_LOCK);
1076 * Set the autopilot heading lock (true=on).
1079 FGBFI::setAPHeadingLock (bool lock)
1082 // We need to do this so that
1083 // it's possible to lock onto a
1084 // heading other than the current
1086 double heading = getAPHeadingMag();
1087 current_autopilot->set_HeadingMode(FGAutopilot::FG_HEADING_LOCK);
1088 current_autopilot->set_HeadingEnabled(true);
1089 setAPHeadingMag(heading);
1090 } else if (current_autopilot->get_HeadingMode() ==
1091 FGAutopilot::FG_HEADING_LOCK) {
1092 current_autopilot->set_HeadingEnabled(false);
1098 * Get the autopilot target heading in degrees.
1101 FGBFI::getAPHeading ()
1103 return current_autopilot->get_TargetHeading();
1108 * Set the autopilot target heading in degrees.
1111 FGBFI::setAPHeading (double heading)
1113 current_autopilot->set_TargetHeading( heading );
1118 * Get the autopilot target heading in degrees.
1121 FGBFI::getAPHeadingMag ()
1123 return current_autopilot->get_TargetHeading() - getMagVar();
1128 * Set the autopilot target heading in degrees.
1131 FGBFI::setAPHeadingMag (double heading)
1133 current_autopilot->set_TargetHeading( heading + getMagVar() );
1138 * Return true if the autopilot is locked to NAV1.
1141 FGBFI::getAPNAV1Lock ()
1144 (current_autopilot->get_HeadingEnabled() &&
1145 current_autopilot->get_HeadingMode() == FGAutopilot::FG_HEADING_NAV1);
1150 * Set the autopilot NAV1 lock.
1153 FGBFI::setAPNAV1Lock (bool lock)
1156 current_autopilot->set_HeadingMode(FGAutopilot::FG_HEADING_NAV1);
1157 current_autopilot->set_HeadingEnabled(true);
1158 } else if (current_autopilot->get_HeadingMode() ==
1159 FGAutopilot::FG_HEADING_NAV1) {
1160 current_autopilot->set_HeadingEnabled(false);
1166 ////////////////////////////////////////////////////////////////////////
1167 // Radio navigation.
1168 ////////////////////////////////////////////////////////////////////////
1171 FGBFI::getNAV1Freq ()
1173 return current_radiostack->get_nav1_freq();
1177 FGBFI::getNAV1AltFreq ()
1179 return current_radiostack->get_nav1_alt_freq();
1183 FGBFI::getNAV1Radial ()
1185 return current_radiostack->get_nav1_radial();
1189 FGBFI::getNAV1SelRadial ()
1191 return current_radiostack->get_nav1_sel_radial();
1195 FGBFI::getNAV1DistDME ()
1197 return current_radiostack->get_nav1_dme_dist();
1203 if (current_radiostack->get_nav1_inrange()) {
1204 double heading = current_radiostack->get_nav1_heading();
1205 double radial = current_radiostack->get_nav1_radial();
1206 double var = FGBFI::getMagVar();
1207 if (current_radiostack->get_nav1_loc()) {
1208 double offset = fabs(heading - radial);
1209 return (offset<= 8.0 || offset >= 352.0);
1212 fabs(heading - var - radial);
1213 return (offset <= 20.0 || offset >= 340.0);
1221 FGBFI::getNAV1FROM ()
1223 if (current_radiostack->get_nav1_inrange()) {
1224 double heading = current_radiostack->get_nav1_heading();
1225 double radial = current_radiostack->get_nav1_radial();
1226 double var = FGBFI::getMagVar();
1227 if (current_radiostack->get_nav1_loc()) {
1228 double offset = fabs(heading - radial);
1229 return (offset >= 172.0 && offset<= 188.0);
1232 fabs(heading - var - radial);
1233 return (offset >= 160.0 && offset <= 200.0);
1241 FGBFI::getNAV1InRange ()
1243 return current_radiostack->get_nav1_inrange();
1247 FGBFI::getNAV1DMEInRange ()
1249 return (current_radiostack->get_nav1_inrange() &&
1250 current_radiostack->get_nav1_has_dme());
1254 FGBFI::getNAV2Freq ()
1256 return current_radiostack->get_nav2_freq();
1260 FGBFI::getNAV2AltFreq ()
1262 return current_radiostack->get_nav2_alt_freq();
1266 FGBFI::getNAV2Radial ()
1268 return current_radiostack->get_nav2_radial();
1272 FGBFI::getNAV2SelRadial ()
1274 return current_radiostack->get_nav2_sel_radial();
1278 FGBFI::getNAV2DistDME ()
1280 return current_radiostack->get_nav2_dme_dist();
1286 if (current_radiostack->get_nav2_inrange()) {
1287 double heading = current_radiostack->get_nav2_heading();
1288 double radial = current_radiostack->get_nav2_radial();
1289 double var = FGBFI::getMagVar();
1290 if (current_radiostack->get_nav2_loc()) {
1291 double offset = fabs(heading - radial);
1292 return (offset<= 8.0 || offset >= 352.0);
1295 fabs(heading - var - radial);
1296 return (offset <= 20.0 || offset >= 340.0);
1304 FGBFI::getNAV2FROM ()
1306 if (current_radiostack->get_nav2_inrange()) {
1307 double heading = current_radiostack->get_nav2_heading();
1308 double radial = current_radiostack->get_nav2_radial();
1309 double var = FGBFI::getMagVar();
1310 if (current_radiostack->get_nav2_loc()) {
1311 double offset = fabs(heading - radial);
1312 return (offset >= 172.0 && offset<= 188.0);
1315 fabs(heading - var - radial);
1316 return (offset >= 160.0 && offset <= 200.0);
1325 FGBFI::getNAV2InRange ()
1327 return current_radiostack->get_nav2_inrange();
1331 FGBFI::getNAV2DMEInRange ()
1333 return (current_radiostack->get_nav2_inrange() &&
1334 current_radiostack->get_nav2_has_dme());
1338 FGBFI::getADFFreq ()
1340 return current_radiostack->get_adf_freq();
1344 FGBFI::getADFAltFreq ()
1346 return current_radiostack->get_adf_alt_freq();
1350 FGBFI::getADFRotation ()
1352 return current_radiostack->get_adf_rotation();
1356 FGBFI::setNAV1Freq (double freq)
1358 current_radiostack->set_nav1_freq(freq);
1362 FGBFI::setNAV1AltFreq (double freq)
1364 current_radiostack->set_nav1_alt_freq(freq);
1368 FGBFI::setNAV1SelRadial (double radial)
1370 current_radiostack->set_nav1_sel_radial(radial);
1374 FGBFI::setNAV2Freq (double freq)
1376 current_radiostack->set_nav2_freq(freq);
1380 FGBFI::setNAV2AltFreq (double freq)
1382 current_radiostack->set_nav2_alt_freq(freq);
1386 FGBFI::setNAV2SelRadial (double radial)
1388 current_radiostack->set_nav2_sel_radial(radial);
1392 FGBFI::setADFFreq (double freq)
1394 current_radiostack->set_adf_freq(freq);
1398 FGBFI::setADFAltFreq (double freq)
1400 current_radiostack->set_adf_alt_freq(freq);
1404 FGBFI::setADFRotation (double rot)
1406 current_radiostack->set_adf_rotation(rot);
1411 ////////////////////////////////////////////////////////////////////////
1413 ////////////////////////////////////////////////////////////////////////
1417 * Get the autopilot GPS lock (true=on).
1420 FGBFI::getGPSLock ()
1422 return (current_autopilot->get_HeadingEnabled() &&
1423 (current_autopilot->get_HeadingMode() ==
1424 FGAutopilot::FG_HEADING_WAYPOINT ));
1429 * Set the autopilot GPS lock (true=on).
1432 FGBFI::setGPSLock (bool lock)
1435 current_autopilot->set_HeadingMode(FGAutopilot::FG_HEADING_WAYPOINT);
1436 current_autopilot->set_HeadingEnabled(true);
1437 } else if (current_autopilot->get_HeadingMode() ==
1438 FGAutopilot::FG_HEADING_WAYPOINT) {
1439 current_autopilot->set_HeadingEnabled(false);
1445 * Get the GPS target airport code.
1448 FGBFI::getTargetAirport ()
1450 return current_options.get_airport_id();
1455 * Set the GPS target airport code.
1458 FGBFI::setTargetAirport (const string &airportId)
1460 current_options.set_airport_id(airportId);
1465 * Get the GPS target latitude in degrees (negative for south).
1468 FGBFI::getGPSTargetLatitude ()
1470 return current_autopilot->get_TargetLatitude();
1475 * Set the GPS target latitude in degrees (negative for south).
1478 FGBFI::setGPSTargetLatitude (double latitude)
1480 current_autopilot->set_TargetLatitude( latitude );
1485 * Get the GPS target longitude in degrees (negative for west).
1488 FGBFI::getGPSTargetLongitude ()
1490 return current_autopilot->get_TargetLongitude();
1495 * Set the GPS target longitude in degrees (negative for west).
1498 FGBFI::setGPSTargetLongitude (double longitude)
1500 current_autopilot->set_TargetLongitude( longitude );
1505 ////////////////////////////////////////////////////////////////////////
1507 ////////////////////////////////////////////////////////////////////////
1511 * Get the current visible (units??).
1514 FGBFI::getVisibility ()
1516 #ifndef FG_OLD_WEATHER
1517 return WeatherDatabase->getWeatherVisibility();
1519 return current_weather.get_visibility();
1525 * Check whether clouds are enabled.
1530 return current_options.get_clouds();
1535 * Check the height of the clouds ASL (units?).
1538 FGBFI::getCloudsASL ()
1540 return current_options.get_clouds_asl();
1545 * Set the current visibility (units??).
1548 FGBFI::setVisibility (double visibility)
1550 #ifndef FG_OLD_WEATHER
1551 WeatherDatabase->setWeatherVisibility(visibility);
1553 current_weather.set_visibility(visibility);
1559 * Switch clouds on or off.
1562 FGBFI::setClouds (bool clouds)
1564 cout << "Set clouds to " << clouds << endl;
1565 current_options.set_clouds(clouds);
1571 * Set the cloud height.
1574 FGBFI::setCloudsASL (double cloudsASL)
1576 current_options.set_clouds_asl(cloudsASL);
1582 ////////////////////////////////////////////////////////////////////////
1584 ////////////////////////////////////////////////////////////////////////
1587 * Return the magnetic variation
1592 return globals->get_mag()->get_magvar() * RAD_TO_DEG;
1597 * Return the magnetic variation
1602 return globals->get_mag()->get_magdip() * RAD_TO_DEG;