1 // mk_viii.cxx -- Honeywell MK VIII EGPWS emulation
3 // Written by Jean-Yves Lefort, started September 2005.
5 // Copyright (C) 2005, 2006 Jean-Yves Lefort - jylefort@FreeBSD.org
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.
22 #ifndef __INSTRUMENTS_MK_VIII_HXX
23 #define __INSTRUMENTS_MK_VIII_HXX
31 #include <simgear/props/props.hxx>
32 #include <simgear/sound/sample_openal.hxx>
33 #include <simgear/structure/subsystem_mgr.hxx>
41 #include <Airports/runways.hxx>
42 #include <Airports/simple.hxx>
43 #include <Main/globals.hxx>
46 # pragma warning( push )
47 # pragma warning( disable: 4355 )
50 ///////////////////////////////////////////////////////////////////////////////
51 // MK_VIII ////////////////////////////////////////////////////////////////////
52 ///////////////////////////////////////////////////////////////////////////////
54 class MK_VIII : public SGSubsystem
56 // keep in sync with Mode6Handler::altitude_callout_definitions[]
57 static const unsigned n_altitude_callouts = 11;
59 /////////////////////////////////////////////////////////////////////////////
60 // MK_VIII::RawValueMethodsData /////////////////////////////////////////////
61 /////////////////////////////////////////////////////////////////////////////
63 template <class C, class VT, class DT>
64 class RawValueMethodsData : public SGRawValue<VT>
67 typedef VT (C::*getter_t) (DT) const;
68 typedef void (C::*setter_t) (DT, VT);
70 RawValueMethodsData (C &obj, DT data, getter_t getter = 0, setter_t setter = 0)
71 : _obj(obj), _data(data), _getter(getter), _setter(setter) {}
73 virtual VT getValue () const
76 return (_obj.*_getter)(_data);
78 return SGRawValue<VT>::DefaultValue();
80 virtual bool setValue (VT value)
84 (_obj.*_setter)(_data, value);
90 virtual SGRawValue<VT> *clone () const
92 return new RawValueMethodsData<C,VT,DT>(_obj, _data, _getter, _setter);
102 /////////////////////////////////////////////////////////////////////////////
103 // MK_VIII::Parameter ///////////////////////////////////////////////////////
104 /////////////////////////////////////////////////////////////////////////////
115 : _value(0), ncd(true) {}
117 inline T get () const { assert(! ncd); return _value; }
118 inline T *get_pointer () { return &_value; }
119 inline void set (T value) { ncd = false; _value = value; }
120 inline void unset () { ncd = true; }
122 inline void set (const Parameter<T> *parameter)
127 set(parameter->get());
130 inline void set (const Parameter<double> *parameter, double factor)
135 set(parameter->get() * factor);
139 /////////////////////////////////////////////////////////////////////////////
140 // MK_VIII::Sample //////////////////////////////////////////////////////////
141 /////////////////////////////////////////////////////////////////////////////
150 inline Sample (T _value)
151 : timestamp(globals->get_sim_time_sec()), value(_value) {}
154 /////////////////////////////////////////////////////////////////////////////
155 // MK_VIII::Timer ///////////////////////////////////////////////////////////
156 /////////////////////////////////////////////////////////////////////////////
168 inline void start () { running = true; start_time = globals->get_sim_time_sec(); }
169 inline void stop () { running = false; }
170 inline double elapsed () const { assert(running); return globals->get_sim_time_sec() - start_time; }
171 inline double start_or_elapsed ()
183 /////////////////////////////////////////////////////////////////////////////
184 // MK_VIII::PropertiesHandler ///////////////////////////////////////////////
185 /////////////////////////////////////////////////////////////////////////////
187 class PropertiesHandler
191 vector<SGPropertyNode_ptr> tied_properties;
196 SGPropertyNode_ptr ai_caged;
197 SGPropertyNode_ptr ai_roll;
198 SGPropertyNode_ptr ai_serviceable;
199 SGPropertyNode_ptr altimeter_altitude;
200 SGPropertyNode_ptr altimeter_serviceable;
201 SGPropertyNode_ptr altitude;
202 SGPropertyNode_ptr altitude_agl;
203 SGPropertyNode_ptr asi_serviceable;
204 SGPropertyNode_ptr asi_speed;
205 SGPropertyNode_ptr autopilot_heading_lock;
206 SGPropertyNode_ptr flaps;
207 SGPropertyNode_ptr gear_down;
208 SGPropertyNode_ptr latitude;
209 SGPropertyNode_ptr longitude;
210 SGPropertyNode_ptr nav0_cdi_serviceable;
211 SGPropertyNode_ptr nav0_gs_distance;
212 SGPropertyNode_ptr nav0_gs_needle_deflection;
213 SGPropertyNode_ptr nav0_gs_serviceable;
214 SGPropertyNode_ptr nav0_has_gs;
215 SGPropertyNode_ptr nav0_heading_needle_deflection;
216 SGPropertyNode_ptr nav0_in_range;
217 SGPropertyNode_ptr nav0_nav_loc;
218 SGPropertyNode_ptr nav0_serviceable;
219 SGPropertyNode_ptr power;
220 SGPropertyNode_ptr replay_state;
221 SGPropertyNode_ptr vs;
222 } external_properties;
224 inline PropertiesHandler (MK_VIII *device)
228 inline void tie (SGPropertyNode *node, const SGRawValue<T> &raw_value)
230 node->tie(raw_value);
231 tied_properties.push_back(node);
235 inline void tie (SGPropertyNode *node,
236 const char *relative_path,
237 const SGRawValue<T> &raw_value)
239 tie(node->getNode(relative_path, true), raw_value);
242 PropertiesHandler() {};
249 PropertiesHandler properties_handler;
252 /////////////////////////////////////////////////////////////////////////////
253 // MK_VIII::PowerHandler ////////////////////////////////////////////////////
254 /////////////////////////////////////////////////////////////////////////////
263 Timer power_loss_timer;
264 Timer abnormal_timer;
265 Timer low_surge_timer;
266 Timer high_surge_timer;
267 Timer very_high_surge_timer;
269 bool handle_abnormal_voltage (bool abnormal,
271 double max_duration);
277 inline PowerHandler (MK_VIII *device)
278 : mk(device), serviceable(false), powered(false) {}
280 void bind (SGPropertyNode *node);
284 /////////////////////////////////////////////////////////////////////////////
285 // MK_VIII::SystemHandler ///////////////////////////////////////////////////
286 /////////////////////////////////////////////////////////////////////////////
295 int last_replay_state;
296 Timer reposition_timer;
309 inline SystemHandler (MK_VIII *device)
310 : mk(device), state(STATE_OFF) {}
317 /////////////////////////////////////////////////////////////////////////////
318 // MK_VIII::ConfigurationModule /////////////////////////////////////////////
319 /////////////////////////////////////////////////////////////////////////////
321 class ConfigurationModule
324 // keep in sync with IOHandler::present_status()
327 CATEGORY_AIRCRAFT_MODE_TYPE_SELECT,
328 CATEGORY_AIR_DATA_INPUT_SELECT,
329 CATEGORY_POSITION_INPUT_SELECT,
330 CATEGORY_ALTITUDE_CALLOUTS,
331 CATEGORY_AUDIO_MENU_SELECT,
332 CATEGORY_TERRAIN_DISPLAY_SELECT,
333 CATEGORY_OPTIONS_SELECT_GROUP_1,
334 CATEGORY_RADIO_ALTITUDE_INPUT_SELECT,
335 CATEGORY_NAVIGATION_INPUT_SELECT,
336 CATEGORY_ATTITUDE_INPUT_SELECT,
337 CATEGORY_HEADING_INPUT_SELECT,
338 CATEGORY_WINDSHEAR_INPUT_SELECT,
339 CATEGORY_INPUT_OUTPUT_DISCRETE_TYPE_SELECT,
340 CATEGORY_AUDIO_OUTPUT_LEVEL,
341 CATEGORY_UNDEFINED_INPUT_SELECT_1,
342 CATEGORY_UNDEFINED_INPUT_SELECT_2,
343 CATEGORY_UNDEFINED_INPUT_SELECT_3,
350 STATE_INVALID_DATABASE,
351 STATE_INVALID_AIRCRAFT_TYPE
355 int effective_categories[N_CATEGORIES];
357 ConfigurationModule (MK_VIII *device);
360 void bind (SGPropertyNode *node);
365 int categories[N_CATEGORIES];
367 bool read_aircraft_mode_type_select (int value);
368 bool read_air_data_input_select (int value);
369 bool read_position_input_select (int value);
370 bool read_altitude_callouts (int value);
371 bool read_audio_menu_select (int value);
372 bool read_terrain_display_select (int value);
373 bool read_options_select_group_1 (int value);
374 bool read_radio_altitude_input_select (int value);
375 bool read_navigation_input_select (int value);
376 bool read_attitude_input_select (int value);
377 bool read_heading_input_select (int value);
378 bool read_windshear_input_select (int value);
379 bool read_input_output_discrete_type_select (int value);
380 bool read_audio_output_level (int value);
381 bool read_undefined_input_select (int value);
383 static bool m6_t2_is_bank_angle (Parameter<double> *agl,
386 static bool m6_t4_is_bank_angle (Parameter<double> *agl,
391 /////////////////////////////////////////////////////////////////////////////
392 // MK_VIII::FaultHandler ////////////////////////////////////////////////////
393 /////////////////////////////////////////////////////////////////////////////
405 static const unsigned int fault_inops[];
407 bool has_faults (unsigned int inop);
410 // keep in sync with IOHandler::present_status()
413 FAULT_ALL_MODES_INHIBIT,
416 FAULT_MOMENTARY_FLAP_OVERRIDE_INVALID,
417 FAULT_SELF_TEST_INVALID,
418 FAULT_GLIDESLOPE_CANCEL_INVALID,
419 FAULT_STEEP_APPROACH_INVALID,
421 FAULT_TA_TCF_INHIBIT,
422 FAULT_MODES14_INPUTS_INVALID,
423 FAULT_MODE5_INPUTS_INVALID,
424 FAULT_MODE6_INPUTS_INVALID,
425 FAULT_BANK_ANGLE_INPUTS_INVALID,
426 FAULT_TCF_INPUTS_INVALID,
430 bool faults[N_FAULTS];
432 inline FaultHandler (MK_VIII *device)
437 void set_fault (Fault fault);
438 void unset_fault (Fault fault);
440 bool has_faults () const;
443 /////////////////////////////////////////////////////////////////////////////
444 // MK_VIII::IOHandler ///////////////////////////////////////////////////////
445 /////////////////////////////////////////////////////////////////////////////
459 struct LampConfiguration
465 struct FaultsConfiguration
467 double max_flaps_down_airspeed;
468 double max_gear_down_airspeed;
473 const LampConfiguration *lamp;
474 const FaultsConfiguration *faults;
476 bool steep_approach_enabled;
477 bool gpws_inhibit_enabled;
478 bool momentary_flap_override_enabled;
479 bool alternate_steep_approach;
480 bool use_internal_gps;
481 bool localizer_enabled;
484 struct _s_input_feeders
490 bool glideslope_inhibit;
491 bool decision_height;
492 bool autopilot_engaged;
497 bool uncorrected_barometric_altitude;
498 bool barometric_altitude_rate;
500 bool glideslope_deviation;
502 bool localizer_deviation;
503 bool computed_airspeed;
504 bool decision_height;
512 bool landing_gear; // appendix E 6.6.2, 3.15.1.4
513 bool landing_flaps; // appendix E 6.6.4, 3.15.1.2
514 bool momentary_flap_override; // appendix E 6.6.6, 3.15.1.6
515 bool self_test; // appendix E 6.6.7, 3.15.1.10
516 bool glideslope_inhibit; // appendix E 6.6.11, 3.15.1.1
517 bool glideslope_cancel; // appendix E 6.6.13, 3.15.1.5
518 bool decision_height; // appendix E 6.6.14, 3.10.2
519 bool mode6_low_volume; // appendix E 6.6.15, 3.15.1.7
520 bool audio_inhibit; // appendix E 6.6.16, 3.15.1.3
521 bool ta_tcf_inhibit; // appendix E 6.6.20, 3.15.1.9
522 bool autopilot_engaged; // appendix E 6.6.21, 3.15.1.8
523 bool steep_approach; // appendix E 6.6.25, 3.15.1.11
524 bool gpws_inhibit; // appendix E 6.6.27, 3.15.1.12
529 Parameter<double> uncorrected_barometric_altitude; // appendix E 6.2.1
530 Parameter<double> barometric_altitude_rate; // appendix E 6.2.2
531 Parameter<double> gps_altitude; // appendix E 6.2.4
532 Parameter<double> gps_latitude; // appendix E 6.2.7
533 Parameter<double> gps_longitude; // appendix E 6.2.8
534 Parameter<double> gps_vertical_figure_of_merit; // appendix E 6.2.13
535 Parameter<double> radio_altitude; // appendix E 6.2.29
536 Parameter<double> glideslope_deviation; // appendix E 6.2.30
537 Parameter<double> roll_angle; // appendix E 6.2.31
538 Parameter<double> localizer_deviation; // appendix E 6.2.33
539 Parameter<double> computed_airspeed; // appendix E 6.2.39
540 Parameter<double> decision_height; // appendix E 6.2.41
548 bool gpws_warning; // appendix E 7.4.1, 3.15.2.5
549 bool gpws_alert; // appendix E 7.4.1, 3.15.2.6
550 bool audio_on; // appendix E 7.4.2, 3.15.2.10
551 bool gpws_inop; // appendix E 7.4.3, 3.15.2.3
552 bool tad_inop; // appendix E 7.4.3, 3.15.2.4
553 bool flap_override; // appendix E 7.4.5, 3.15.2.8
554 bool glideslope_cancel; // appendix E 7.4.6, 3.15.2.7
555 bool steep_approach; // appendix E 7.4.12, 3.15.2.9
560 int egpws_alert_discrete_1; // appendix E 7.1.1.1
561 int egpwc_logic_discretes; // appendix E 7.1.1.2
562 int mode6_callouts_discrete_1; // appendix E 7.1.1.3
563 int mode6_callouts_discrete_2; // appendix E 7.1.1.4
564 int egpws_alert_discrete_2; // appendix E 7.1.1.5
565 int egpwc_alert_discrete_3; // appendix E 7.1.1.6
573 Parameter<double> barometric_altitude_rate;
574 Parameter<double> decision_height;
575 Parameter<double> geometric_altitude;
576 Parameter<double> glideslope_deviation_dots;
577 Parameter<double> gps_altitude;
578 Parameter<double> gps_latitude;
579 Parameter<double> gps_longitude;
580 Parameter<double> gps_vertical_figure_of_merit;
581 Parameter<double> localizer_deviation_dots;
582 Parameter<double> radio_altitude;
583 Parameter<double> roll_angle;
584 Parameter<double> terrain_clearance;
587 IOHandler (MK_VIII *device);
593 void enter_ground ();
594 void enter_takeoff ();
596 void update_inputs ();
597 void update_input_faults ();
598 void update_alternate_discrete_input (bool *ptr);
599 void update_internal_latches ();
601 void update_egpws_alert_discrete_1 ();
602 void update_egpwc_logic_discretes ();
603 void update_mode6_callouts_discrete_1 ();
604 void update_mode6_callouts_discrete_2 ();
605 void update_egpws_alert_discrete_2 ();
606 void update_egpwc_alert_discrete_3 ();
607 void update_outputs ();
609 void update_lamps ();
610 void set_lamp (Lamp lamp);
612 bool gpws_inhibit () const;
613 bool real_flaps_down () const;
614 bool flaps_down () const;
615 bool flap_override () const;
616 bool steep_approach () const;
617 bool momentary_steep_approach_enabled () const;
619 void bind (SGPropertyNode *node);
625 ///////////////////////////////////////////////////////////////////////////
626 // MK_VIII::IOHandler::TerrainClearanceFilter /////////////////////////////
627 ///////////////////////////////////////////////////////////////////////////
629 class TerrainClearanceFilter
631 typedef deque< Sample<double> > samples_type;
632 samples_type samples;
636 inline TerrainClearanceFilter ()
639 double update (double agl);
643 ///////////////////////////////////////////////////////////////////////////
644 // MK_VIII::IOHandler (continued) /////////////////////////////////////////
645 ///////////////////////////////////////////////////////////////////////////
647 TerrainClearanceFilter terrain_clearance_filter;
652 Timer audio_inhibit_fault_timer;
653 Timer landing_gear_fault_timer;
654 Timer flaps_down_fault_timer;
655 Timer momentary_flap_override_fault_timer;
656 Timer self_test_fault_timer;
657 Timer glideslope_cancel_fault_timer;
658 Timer steep_approach_fault_timer;
659 Timer gpws_inhibit_fault_timer;
660 Timer ta_tcf_inhibit_fault_timer;
662 bool last_landing_gear;
663 bool last_real_flaps_down;
665 typedef deque< Sample< Parameter<double> > > altitude_samples_type;
666 altitude_samples_type altitude_samples;
670 bool glideslope_cancel;
673 void update_terrain_clearance ();
674 void reset_terrain_clearance ();
676 void handle_input_fault (bool test, FaultHandler::Fault fault);
677 void handle_input_fault (bool test,
680 FaultHandler::Fault fault);
682 void tie_input (SGPropertyNode *node,
686 void tie_input (SGPropertyNode *node,
688 Parameter<double> *input,
690 void tie_output (SGPropertyNode *node,
693 void tie_output (SGPropertyNode *node,
699 bool get_discrete_input (bool *ptr) const;
700 void set_discrete_input (bool *ptr, bool value);
702 void present_status ();
703 void present_status_section (const char *name);
704 void present_status_item (const char *name, const char *value = NULL);
705 void present_status_subitem (const char *name);
707 bool get_present_status () const;
708 void set_present_status (bool value);
710 bool *get_lamp_output (Lamp lamp);
713 /////////////////////////////////////////////////////////////////////////////
714 // MK_VIII::VoicePlayer /////////////////////////////////////////////////////
715 /////////////////////////////////////////////////////////////////////////////
721 ///////////////////////////////////////////////////////////////////////////
722 // MK_VIII::VoicePlayer::Voice ////////////////////////////////////////////
723 ///////////////////////////////////////////////////////////////////////////
729 /////////////////////////////////////////////////////////////////////////
730 // MK_VIII::VoicePlayer::Voice::Element ////////////////////////////////////////
731 /////////////////////////////////////////////////////////////////////////
738 virtual inline void play (float volume) {}
739 virtual inline void stop () {}
740 virtual bool is_playing () = 0;
741 virtual inline void set_volume (float volume) {}
744 /////////////////////////////////////////////////////////////////////////
745 // MK_VIII::VoicePlayer::Voice::SampleElement ///////////////////////////
746 /////////////////////////////////////////////////////////////////////////
748 class SampleElement : public Element
750 SGSharedPtr<SGSoundSample> _sample;
754 inline SampleElement (SGSharedPtr<SGSoundSample> sample, float volume = 1.0)
755 : _sample(sample), _volume(volume) { silence = false; }
757 virtual inline void play (float volume) { if (_sample && (volume > 0.05)) { set_volume(volume); _sample->play_once(); } }
758 virtual inline void stop () { if (_sample) _sample->stop(); }
759 virtual inline bool is_playing () { return _sample ? _sample->is_playing() : false; }
760 virtual inline void set_volume (float volume) { if (_sample) _sample->set_volume(volume * _volume); }
763 /////////////////////////////////////////////////////////////////////////
764 // MK_VIII::VoicePlayer::Voice::SilenceElement //////////////////////////
765 /////////////////////////////////////////////////////////////////////////
767 class SilenceElement : public Element
773 inline SilenceElement (double duration)
774 : _duration(duration) { silence = true; }
776 virtual inline void play (float volume) { start_time = globals->get_sim_time_sec(); }
777 virtual inline bool is_playing () { return globals->get_sim_time_sec() - start_time < _duration; }
780 /////////////////////////////////////////////////////////////////////////
781 // MK_VIII::VoicePlayer::Voice (continued) //////////////////////////////
782 /////////////////////////////////////////////////////////////////////////
786 inline Voice (VoicePlayer *_player)
787 : element(NULL), player(_player), volume(1.0) {}
791 inline void append (Element *_element) { elements.push_back(_element); }
794 void stop (bool now);
795 void set_volume (float _volume);
796 void volume_changed ();
804 vector<Element *> elements;
805 vector<Element *>::iterator iter;
807 inline float get_volume () const { return player->volume * player->speaker.volume * volume; }
810 ///////////////////////////////////////////////////////////////////////////
811 // MK_VIII::VoicePlayer (continued) ///////////////////////////////////////
812 ///////////////////////////////////////////////////////////////////////////
826 Voice *application_data_base_failed;
828 Voice *bank_angle_bank_angle;
829 Voice *bank_angle_bank_angle_3;
830 Voice *bank_angle_inop;
831 Voice *bank_angle_pause_bank_angle;
832 Voice *bank_angle_pause_bank_angle_3;
833 Voice *callouts_inop;
834 Voice *configuration_type_invalid;
836 Voice *dont_sink_pause_dont_sink;
837 Voice *five_hundred_above;
839 Voice *glideslope_inop;
841 Voice *hard_glideslope;
843 Voice *minimums_minimums;
846 Voice *sink_rate_pause_sink_rate;
847 Voice *soft_glideslope;
849 Voice *terrain_pause_terrain;
850 Voice *too_low_flaps;
852 Voice *too_low_terrain;
853 Voice *altitude_callouts[n_altitude_callouts];
856 inline VoicePlayer (MK_VIII *device)
857 : voice(NULL), next_voice(NULL), mk(device), speaker(this) {}
868 void play (Voice *_voice, unsigned int flags = 0);
874 void stop (unsigned int flags = 0);
876 void set_volume (float _volume);
879 inline void bind (SGPropertyNode *node) { speaker.bind(node); }
883 ///////////////////////////////////////////////////////////////////////////
884 // MK_VIII::VoicePlayer::Speaker //////////////////////////////////////////
885 ///////////////////////////////////////////////////////////////////////////
894 inline void tie (SGPropertyNode *node, const char *name, T *ptr)
896 player->mk->properties_handler.tie
897 (node, (string("speaker/") + name).c_str(),
898 RawValueMethodsData<MK_VIII::VoicePlayer::Speaker,T,T*>
900 &MK_VIII::VoicePlayer::Speaker::get_property,
901 &MK_VIII::VoicePlayer::Speaker::set_property));
906 inline void set_property (T *ptr, T value) { *ptr = value; update_configuration(); }
909 inline T get_property (T *ptr) const { return *ptr; }
913 inline Speaker (VoicePlayer *_player)
920 void bind (SGPropertyNode *node);
921 void update_configuration ();
925 ///////////////////////////////////////////////////////////////////////////
926 // MK_VIII::VoicePlayer (continued) ///////////////////////////////////////
927 ///////////////////////////////////////////////////////////////////////////
931 SGSharedPtr<SGSampleGroup> _sgr;
934 map< string, SGSharedPtr<SGSoundSample> > samples;
935 vector<Voice *> _voices;
940 SGSoundSample *get_sample (const char *name);
942 inline void append (Voice *voice, Voice::Element *element) { voice->append(element); }
943 inline void append (Voice *voice, const char *sample_name) { voice->append(new Voice::SampleElement(get_sample(sample_name))); }
944 inline void append (Voice *voice, double silence) { voice->append(new Voice::SilenceElement(silence)); }
946 inline void make_voice (Voice **voice) { *voice = new Voice(this); _voices.push_back(*voice); }
949 inline void make_voice (Voice **voice, T1 e1) { make_voice(voice); append(*voice, e1); }
950 template <class T1, class T2>
951 inline void make_voice (Voice **voice, T1 e1, T2 e2) { make_voice(voice, e1); append(*voice, e2); }
952 template <class T1, class T2, class T3>
953 inline void make_voice (Voice **voice, T1 e1, T2 e2, T3 e3) { make_voice(voice, e1, e2); append(*voice, e3); }
954 template <class T1, class T2, class T3, class T4>
955 inline void make_voice (Voice **voice, T1 e1, T2 e2, T3 e3, T4 e4) { make_voice(voice, e1, e2, e3); append(*voice, e4); }
959 /////////////////////////////////////////////////////////////////////////////
960 // MK_VIII::SelfTestHandler /////////////////////////////////////////////////
961 /////////////////////////////////////////////////////////////////////////////
963 class SelfTestHandler
976 ACTION_SLEEP = 1 << 0,
977 ACTION_VOICE = 1 << 1,
978 ACTION_DISCRETE_ON_OFF = 1 << 2,
985 double sleep_duration;
993 double button_press_timestamp;
994 IOHandler::Outputs saved_outputs;
997 bool _was_here (int position);
999 Action sleep (double duration);
1000 Action play (VoicePlayer::Voice *voice);
1001 Action discrete_on (bool *discrete, double duration);
1002 Action discrete_on_off (bool *discrete, double duration);
1003 Action discrete_on_off (bool *discrete, VoicePlayer::Voice *voice);
1022 inline SelfTestHandler (MK_VIII *device)
1023 : mk(device), button_pressed(false), state(STATE_NONE) {}
1025 inline void power_off () { stop(); }
1026 inline void set_inop () { stop(); }
1027 void handle_button_event (bool value);
1031 /////////////////////////////////////////////////////////////////////////////
1032 // MK_VIII::AlertHandler ////////////////////////////////////////////////////
1033 /////////////////////////////////////////////////////////////////////////////
1039 unsigned int old_alerts;
1040 unsigned int voice_alerts;
1041 unsigned int repeated_alerts;
1042 VoicePlayer::Voice *altitude_callout_voice;
1045 inline bool has_alerts (unsigned int test) const { return (alerts & test) != 0; }
1046 inline bool has_old_alerts (unsigned int test) const { return (old_alerts & test) != 0; }
1047 inline bool must_play_voice (unsigned int test) const { return ! has_old_alerts(test) || (repeated_alerts & test) != 0; }
1048 bool select_voice_alerts (unsigned int test);
1053 ALERT_MODE1_PULL_UP = 1 << 0,
1054 ALERT_MODE1_SINK_RATE = 1 << 1,
1056 ALERT_MODE2A_PREFACE = 1 << 2,
1057 ALERT_MODE2B_PREFACE = 1 << 3,
1058 ALERT_MODE2A = 1 << 4,
1059 ALERT_MODE2B = 1 << 5,
1060 ALERT_MODE2B_LANDING_MODE = 1 << 6,
1061 ALERT_MODE2A_ALTITUDE_GAIN = 1 << 7,
1062 ALERT_MODE2A_ALTITUDE_GAIN_TERRAIN_CLOSING = 1 << 8,
1064 ALERT_MODE3 = 1 << 9,
1066 ALERT_MODE4_TOO_LOW_FLAPS = 1 << 10,
1067 ALERT_MODE4_TOO_LOW_GEAR = 1 << 11,
1068 ALERT_MODE4AB_TOO_LOW_TERRAIN = 1 << 12,
1069 ALERT_MODE4C_TOO_LOW_TERRAIN = 1 << 13,
1071 ALERT_MODE5_SOFT = 1 << 14,
1072 ALERT_MODE5_HARD = 1 << 15,
1074 ALERT_MODE6_MINIMUMS = 1 << 16,
1075 ALERT_MODE6_ALTITUDE_CALLOUT = 1 << 17,
1076 ALERT_MODE6_LOW_BANK_ANGLE_1 = 1 << 18,
1077 ALERT_MODE6_HIGH_BANK_ANGLE_1 = 1 << 19,
1078 ALERT_MODE6_LOW_BANK_ANGLE_2 = 1 << 20,
1079 ALERT_MODE6_HIGH_BANK_ANGLE_2 = 1 << 21,
1080 ALERT_MODE6_LOW_BANK_ANGLE_3 = 1 << 22,
1081 ALERT_MODE6_HIGH_BANK_ANGLE_3 = 1 << 23,
1083 ALERT_TCF_TOO_LOW_TERRAIN = 1 << 24
1088 ALERT_FLAG_REPEAT = 1 << 0
1091 unsigned int alerts;
1093 inline AlertHandler (MK_VIII *device)
1100 void set_alerts (unsigned int _alerts,
1101 unsigned int flags = 0,
1102 VoicePlayer::Voice *_altitude_callout_voice = NULL);
1103 void unset_alerts (unsigned int _alerts);
1105 inline void repeat_alert (unsigned int alert) { set_alerts(alert, ALERT_FLAG_REPEAT); }
1106 inline void set_altitude_callout_alert (VoicePlayer::Voice *voice) { set_alerts(ALERT_MODE6_ALTITUDE_CALLOUT, 0, voice); }
1109 /////////////////////////////////////////////////////////////////////////////
1110 // MK_VIII::StateHandler ////////////////////////////////////////////////////
1111 /////////////////////////////////////////////////////////////////////////////
1117 Timer potentially_airborne_timer;
1119 void update_ground ();
1120 void enter_ground ();
1121 void leave_ground ();
1123 void update_takeoff ();
1124 void enter_takeoff ();
1125 void leave_takeoff ();
1131 inline StateHandler (MK_VIII *device)
1132 : mk(device), ground(true), takeoff(true) {}
1134 void post_reposition ();
1138 /////////////////////////////////////////////////////////////////////////////
1139 // MK_VIII::Mode1Handler ////////////////////////////////////////////////////
1140 /////////////////////////////////////////////////////////////////////////////
1146 Timer pull_up_timer;
1147 Timer sink_rate_timer;
1149 double sink_rate_tti; // time-to-impact in minutes
1151 double get_pull_up_bias ();
1154 double get_sink_rate_bias ();
1155 bool is_sink_rate ();
1156 double get_sink_rate_tti ();
1158 void update_pull_up ();
1159 void update_sink_rate ();
1164 bool flap_override_bias;
1166 double (*pull_up_min_agl1) (double vs);
1167 int pull_up_max_agl1;
1168 double (*pull_up_min_agl2) (double vs);
1169 int pull_up_max_agl2;
1170 } EnvelopesConfiguration;
1174 const EnvelopesConfiguration *envelopes;
1177 inline Mode1Handler (MK_VIII *device)
1183 /////////////////////////////////////////////////////////////////////////////
1184 // MK_VIII::Mode2Handler ////////////////////////////////////////////////////
1185 /////////////////////////////////////////////////////////////////////////////
1190 ///////////////////////////////////////////////////////////////////////////
1191 // MK_VIII::Mode2Handler::ClosureRateFilter ///////////////////////////////
1192 ///////////////////////////////////////////////////////////////////////////
1194 class ClosureRateFilter
1196 /////////////////////////////////////////////////////////////////////////
1197 // MK_VIII::Mode2Handler::ClosureRateFilter::PassFilter /////////////////
1198 /////////////////////////////////////////////////////////////////////////
1210 inline PassFilter (double _a0, double _a1, double _b1)
1211 : a0(_a0), a1(_a1), b1(_b1) {}
1213 inline double filter (double input)
1215 last_output = a0 * input + a1 * last_input + b1 * last_output;
1221 inline void reset ()
1228 /////////////////////////////////////////////////////////////////////////
1229 // MK_VIII::Mode2Handler::ClosureRateFilter (continued) /////////////////
1230 /////////////////////////////////////////////////////////////////////////
1235 Parameter<double> last_ra; // last radio altitude
1236 Parameter<double> last_ba; // last barometric altitude
1237 PassFilter ra_filter; // radio altitude rate filter
1238 PassFilter ba_filter; // barometric altitude rate filter
1240 double limit_radio_altitude_rate (double r);
1243 Parameter<double> output;
1245 inline ClosureRateFilter (MK_VIII *device)
1247 ra_filter(0.05, 0, 0.95), // low-pass filter
1248 ba_filter(0.93, -0.93, 0.86) {} // high-pass-filter
1254 ///////////////////////////////////////////////////////////////////////////
1255 // MK_VIII::Mode2Handler (continued) //////////////////////////////////////
1256 ///////////////////////////////////////////////////////////////////////////
1260 ClosureRateFilter closure_rate_filter;
1262 Timer takeoff_timer;
1263 Timer pull_up_timer;
1265 double a_start_time;
1266 Timer a_altitude_gain_timer;
1267 double a_altitude_gain_alt;
1269 void check_pull_up (unsigned int preface_alert, unsigned int alert);
1271 bool b_conditions ();
1286 const Configuration *conf;
1288 inline Mode2Handler (MK_VIII *device)
1289 : mk(device), closure_rate_filter(device) {}
1293 void leave_ground ();
1294 void enter_takeoff ();
1298 /////////////////////////////////////////////////////////////////////////////
1299 // MK_VIII::Mode3Handler ////////////////////////////////////////////////////
1300 /////////////////////////////////////////////////////////////////////////////
1307 bool has_descent_alt;
1311 double max_alt_loss (double _bias);
1312 double get_bias (double initial_bias, double alt_loss);
1313 bool is (double *alt_loss);
1319 int (*max_agl) (bool flap_override);
1320 double (*max_alt_loss) (bool flap_override, double agl);
1323 const Configuration *conf;
1325 inline Mode3Handler (MK_VIII *device)
1326 : mk(device), armed(false), has_descent_alt(false) {}
1328 void enter_takeoff ();
1332 /////////////////////////////////////////////////////////////////////////////
1333 // MK_VIII::Mode4Handler ////////////////////////////////////////////////////
1334 /////////////////////////////////////////////////////////////////////////////
1344 double (*min_agl2) (double airspeed);
1346 } EnvelopesConfiguration;
1350 const EnvelopesConfiguration *ac;
1351 const EnvelopesConfiguration *b;
1352 } ModesConfiguration;
1356 VoicePlayer::Voice *voice_too_low_gear;
1357 const ModesConfiguration *modes;
1360 inline Mode4Handler (MK_VIII *device)
1363 double get_upper_agl (const EnvelopesConfiguration *c);
1370 double ab_expanded_bias;
1373 const EnvelopesConfiguration *get_ab_envelope ();
1374 double get_bias (double initial_bias, double min_agl);
1375 void handle_alert (unsigned int alert, double min_agl, double *bias);
1378 void update_ab_expanded ();
1382 /////////////////////////////////////////////////////////////////////////////
1383 // MK_VIII::Mode5Handler ////////////////////////////////////////////////////
1384 /////////////////////////////////////////////////////////////////////////////
1396 bool is_soft (double bias);
1398 double get_soft_bias (double initial_bias);
1400 void update_hard (bool is);
1401 void update_soft (bool is);
1404 inline Mode5Handler (MK_VIII *device)
1410 /////////////////////////////////////////////////////////////////////////////
1411 // MK_VIII::Mode6Handler ////////////////////////////////////////////////////
1412 /////////////////////////////////////////////////////////////////////////////
1417 // keep in sync with altitude_callout_definitions[]
1420 ALTITUDE_CALLOUT_1000,
1421 ALTITUDE_CALLOUT_500,
1422 ALTITUDE_CALLOUT_400,
1423 ALTITUDE_CALLOUT_300,
1424 ALTITUDE_CALLOUT_200,
1425 ALTITUDE_CALLOUT_100,
1426 ALTITUDE_CALLOUT_50,
1427 ALTITUDE_CALLOUT_40,
1428 ALTITUDE_CALLOUT_30,
1429 ALTITUDE_CALLOUT_20,
1433 typedef bool (*BankAnglePredicate) (Parameter<double> *agl,
1434 double abs_roll_deg,
1439 bool minimums_enabled;
1440 bool smart_500_enabled;
1441 VoicePlayer::Voice *above_field_voice;
1443 bool altitude_callouts_enabled[n_altitude_callouts];
1444 bool bank_angle_enabled;
1445 BankAnglePredicate is_bank_angle;
1448 static const int altitude_callout_definitions[];
1450 inline Mode6Handler (MK_VIII *device)
1455 void enter_takeoff ();
1456 void leave_takeoff ();
1457 void set_volume (float volume);
1458 bool altitude_callouts_enabled ();
1464 bool last_decision_height;
1465 Parameter<double> last_radio_altitude;
1466 Parameter<double> last_altitude_above_field;
1468 bool altitude_callouts_issued[n_altitude_callouts];
1469 bool minimums_issued;
1470 bool above_field_issued;
1473 Parameter<bool> has_runway;
1477 double elevation; // elevation in feet
1480 void reset_minimums ();
1481 void reset_altitude_callouts ();
1482 bool is_playing_altitude_callout ();
1483 bool is_near_minimums (double callout);
1484 bool is_outside_band (double elevation, double callout);
1485 bool inhibit_smart_500 ();
1487 void update_minimums ();
1488 void update_altitude_callouts ();
1490 bool test_runway (const FGRunway *_runway);
1491 bool test_airport (const FGAirport *airport);
1492 void update_runway ();
1494 void get_altitude_above_field (Parameter<double> *parameter);
1495 void update_above_field_callout ();
1497 bool is_bank_angle (double abs_roll_angle, double bias);
1498 bool is_high_bank_angle ();
1499 unsigned int get_bank_angle_alerts ();
1500 void update_bank_angle ();
1502 class AirportFilter : public FGAirport::AirportFilter
1505 AirportFilter(Mode6Handler *s)
1508 virtual bool passAirport(FGAirport *a) const;
1510 virtual FGPositioned::Type maxType() const {
1511 return FGPositioned::AIRPORT;
1519 /////////////////////////////////////////////////////////////////////////////
1520 // MK_VIII::TCFHandler //////////////////////////////////////////////////////
1521 /////////////////////////////////////////////////////////////////////////////
1527 double latitude; // latitude in degrees
1528 double longitude; // longitude in degrees
1533 Position position; // position of threshold
1534 double heading; // runway heading
1539 static const double k;
1546 Position center; // center point
1547 double elevation; // elevation in feet
1548 double half_length; // runway half length, in nautical miles
1549 RunwayEdge edges[2]; // runway threshold and end
1550 Position bias_area[4]; // vertices of the bias area
1555 double initial_value;
1557 double get_azimuth_difference (double from_lat,
1562 double get_azimuth_difference (const FGRunway *_runway);
1564 FGRunway* select_runway (const FGAirport *airport);
1565 void update_runway ();
1567 void get_bias_area_edges (Position *edge,
1569 double half_width_m,
1570 Position *bias_edge1,
1571 Position *bias_edge2);
1573 bool is_inside_edge_triangle (RunwayEdge *edge);
1574 bool is_inside_bias_area ();
1579 class AirportFilter : public FGAirport::AirportFilter
1582 AirportFilter(MK_VIII *device)
1585 virtual bool passAirport(FGAirport *a) const;
1595 inline TCFHandler (MK_VIII *device)
1601 /////////////////////////////////////////////////////////////////////////////
1602 // MK_VIII (continued) //////////////////////////////////////////////////////
1603 /////////////////////////////////////////////////////////////////////////////
1608 PowerHandler power_handler;
1609 SystemHandler system_handler;
1610 ConfigurationModule configuration_module;
1611 FaultHandler fault_handler;
1612 IOHandler io_handler;
1613 VoicePlayer voice_player;
1614 SelfTestHandler self_test_handler;
1615 AlertHandler alert_handler;
1616 StateHandler state_handler;
1617 Mode1Handler mode1_handler;
1618 Mode2Handler mode2_handler;
1619 Mode3Handler mode3_handler;
1620 Mode4Handler mode4_handler;
1621 Mode5Handler mode5_handler;
1622 Mode6Handler mode6_handler;
1623 TCFHandler tcf_handler;
1627 int runway_database;
1631 MK_VIII (SGPropertyNode *node);
1633 virtual void init ();
1634 virtual void bind ();
1635 virtual void unbind ();
1636 virtual void update (double dt);
1640 # pragma warning( pop )
1643 #endif // __INSTRUMENTS_MK_VIII_HXX