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>
39 #include "Airports/runways.hxx"
40 #include "Airports/simple.hxx"
41 #include "Main/globals.hxx"
43 ///////////////////////////////////////////////////////////////////////////////
44 // MK_VIII ////////////////////////////////////////////////////////////////////
45 ///////////////////////////////////////////////////////////////////////////////
47 class MK_VIII : public SGSubsystem
49 // keep in sync with Mode6Handler::altitude_callout_definitions[]
50 static const int n_altitude_callouts = 11;
52 /////////////////////////////////////////////////////////////////////////////
53 // MK_VIII::RawValueMethodsData /////////////////////////////////////////////
54 /////////////////////////////////////////////////////////////////////////////
56 template <class C, class VT, class DT>
57 class RawValueMethodsData : public SGRawValue<VT>
60 typedef VT (C::*getter_t) (DT) const;
61 typedef void (C::*setter_t) (DT, VT);
63 RawValueMethodsData (C &obj, DT data, getter_t getter = 0, setter_t setter = 0)
64 : _obj(obj), _data(data), _getter(getter), _setter(setter) {}
66 virtual VT getValue () const
69 return (_obj.*_getter)(_data);
71 return SGRawValue<VT>::DefaultValue;
73 virtual bool setValue (VT value)
77 (_obj.*_setter)(_data, value);
83 virtual SGRawValue<VT> *clone () const
85 return new RawValueMethodsData<C,VT,DT>(_obj, _data, _getter, _setter);
95 /////////////////////////////////////////////////////////////////////////////
96 // MK_VIII::Parameter ///////////////////////////////////////////////////////
97 /////////////////////////////////////////////////////////////////////////////
108 : _value(0), ncd(true) {}
110 inline T get () const { assert(! ncd); return _value; }
111 inline T *get_pointer () { return &_value; }
112 inline void set (T value) { ncd = false; _value = value; }
113 inline void unset () { ncd = true; }
115 inline void set (const Parameter<T> *parameter)
120 set(parameter->get());
123 inline void set (const Parameter<double> *parameter, double factor)
128 set(parameter->get() * factor);
132 /////////////////////////////////////////////////////////////////////////////
133 // MK_VIII::Sample //////////////////////////////////////////////////////////
134 /////////////////////////////////////////////////////////////////////////////
143 inline Sample (T _value)
144 : timestamp(globals->get_sim_time_sec()), value(_value) {}
147 /////////////////////////////////////////////////////////////////////////////
148 // MK_VIII::Timer ///////////////////////////////////////////////////////////
149 /////////////////////////////////////////////////////////////////////////////
161 inline void start () { running = true; start_time = globals->get_sim_time_sec(); }
162 inline void stop () { running = false; }
163 inline double elapsed () const { assert(running); return globals->get_sim_time_sec() - start_time; }
164 inline double start_or_elapsed ()
176 /////////////////////////////////////////////////////////////////////////////
177 // MK_VIII::PropertiesHandler ///////////////////////////////////////////////
178 /////////////////////////////////////////////////////////////////////////////
180 class PropertiesHandler
184 vector<SGPropertyNode_ptr> tied_properties;
189 SGPropertyNode_ptr ai_caged;
190 SGPropertyNode_ptr ai_roll;
191 SGPropertyNode_ptr ai_serviceable;
192 SGPropertyNode_ptr altimeter_altitude;
193 SGPropertyNode_ptr altimeter_serviceable;
194 SGPropertyNode_ptr altitude;
195 SGPropertyNode_ptr altitude_agl;
196 SGPropertyNode_ptr asi_serviceable;
197 SGPropertyNode_ptr asi_speed;
198 SGPropertyNode_ptr autopilot_heading_lock;
199 SGPropertyNode_ptr flaps;
200 SGPropertyNode_ptr gear_down;
201 SGPropertyNode_ptr latitude;
202 SGPropertyNode_ptr longitude;
203 SGPropertyNode_ptr nav0_cdi_serviceable;
204 SGPropertyNode_ptr nav0_gs_distance;
205 SGPropertyNode_ptr nav0_gs_needle_deflection;
206 SGPropertyNode_ptr nav0_gs_serviceable;
207 SGPropertyNode_ptr nav0_has_gs;
208 SGPropertyNode_ptr nav0_heading_needle_deflection;
209 SGPropertyNode_ptr nav0_in_range;
210 SGPropertyNode_ptr nav0_nav_loc;
211 SGPropertyNode_ptr nav0_serviceable;
212 SGPropertyNode_ptr power;
213 SGPropertyNode_ptr replay_state;
214 SGPropertyNode_ptr vs;
215 } external_properties;
217 inline PropertiesHandler (MK_VIII *device)
221 inline void tie (SGPropertyNode *node, const SGRawValue<T> &raw_value)
223 node->tie(raw_value);
224 tied_properties.push_back(node);
228 inline void tie (SGPropertyNode *node,
229 const char *relative_path,
230 const SGRawValue<T> &raw_value)
232 tie(node->getNode(relative_path, true), raw_value);
235 PropertiesHandler() {};
242 PropertiesHandler properties_handler;
245 /////////////////////////////////////////////////////////////////////////////
246 // MK_VIII::PowerHandler ////////////////////////////////////////////////////
247 /////////////////////////////////////////////////////////////////////////////
256 Timer power_loss_timer;
257 Timer abnormal_timer;
258 Timer low_surge_timer;
259 Timer high_surge_timer;
260 Timer very_high_surge_timer;
262 bool handle_abnormal_voltage (bool abnormal,
264 double max_duration);
270 inline PowerHandler (MK_VIII *device)
271 : mk(device), serviceable(false), powered(false) {}
273 void bind (SGPropertyNode *node);
277 /////////////////////////////////////////////////////////////////////////////
278 // MK_VIII::SystemHandler ///////////////////////////////////////////////////
279 /////////////////////////////////////////////////////////////////////////////
288 int last_replay_state;
289 Timer reposition_timer;
302 inline SystemHandler (MK_VIII *device)
303 : mk(device), state(STATE_OFF) {}
310 /////////////////////////////////////////////////////////////////////////////
311 // MK_VIII::ConfigurationModule /////////////////////////////////////////////
312 /////////////////////////////////////////////////////////////////////////////
314 class ConfigurationModule
317 // keep in sync with IOHandler::present_status()
320 CATEGORY_AIRCRAFT_MODE_TYPE_SELECT,
321 CATEGORY_AIR_DATA_INPUT_SELECT,
322 CATEGORY_POSITION_INPUT_SELECT,
323 CATEGORY_ALTITUDE_CALLOUTS,
324 CATEGORY_AUDIO_MENU_SELECT,
325 CATEGORY_TERRAIN_DISPLAY_SELECT,
326 CATEGORY_OPTIONS_SELECT_GROUP_1,
327 CATEGORY_RADIO_ALTITUDE_INPUT_SELECT,
328 CATEGORY_NAVIGATION_INPUT_SELECT,
329 CATEGORY_ATTITUDE_INPUT_SELECT,
330 CATEGORY_HEADING_INPUT_SELECT,
331 CATEGORY_WINDSHEAR_INPUT_SELECT,
332 CATEGORY_INPUT_OUTPUT_DISCRETE_TYPE_SELECT,
333 CATEGORY_AUDIO_OUTPUT_LEVEL,
334 CATEGORY_UNDEFINED_INPUT_SELECT_1,
335 CATEGORY_UNDEFINED_INPUT_SELECT_2,
336 CATEGORY_UNDEFINED_INPUT_SELECT_3,
343 STATE_INVALID_DATABASE,
344 STATE_INVALID_AIRCRAFT_TYPE
348 int effective_categories[N_CATEGORIES];
350 ConfigurationModule (MK_VIII *device);
353 void bind (SGPropertyNode *node);
358 int categories[N_CATEGORIES];
360 bool read_aircraft_mode_type_select (int value);
361 bool read_air_data_input_select (int value);
362 bool read_position_input_select (int value);
363 bool read_altitude_callouts (int value);
364 bool read_audio_menu_select (int value);
365 bool read_terrain_display_select (int value);
366 bool read_options_select_group_1 (int value);
367 bool read_radio_altitude_input_select (int value);
368 bool read_navigation_input_select (int value);
369 bool read_attitude_input_select (int value);
370 bool read_heading_input_select (int value);
371 bool read_windshear_input_select (int value);
372 bool read_input_output_discrete_type_select (int value);
373 bool read_audio_output_level (int value);
374 bool read_undefined_input_select (int value);
376 static bool m6_t2_is_bank_angle (Parameter<double> *agl,
379 static bool m6_t4_is_bank_angle (Parameter<double> *agl,
384 /////////////////////////////////////////////////////////////////////////////
385 // MK_VIII::FaultHandler ////////////////////////////////////////////////////
386 /////////////////////////////////////////////////////////////////////////////
398 static const unsigned int fault_inops[];
400 bool has_faults (unsigned int inop);
403 // keep in sync with IOHandler::present_status()
406 FAULT_ALL_MODES_INHIBIT,
409 FAULT_MOMENTARY_FLAP_OVERRIDE_INVALID,
410 FAULT_SELF_TEST_INVALID,
411 FAULT_GLIDESLOPE_CANCEL_INVALID,
412 FAULT_STEEP_APPROACH_INVALID,
414 FAULT_TA_TCF_INHIBIT,
415 FAULT_MODES14_INPUTS_INVALID,
416 FAULT_MODE5_INPUTS_INVALID,
417 FAULT_MODE6_INPUTS_INVALID,
418 FAULT_BANK_ANGLE_INPUTS_INVALID,
419 FAULT_TCF_INPUTS_INVALID,
423 bool faults[N_FAULTS];
425 inline FaultHandler (MK_VIII *device)
430 void set_fault (Fault fault);
431 void unset_fault (Fault fault);
433 bool has_faults () const;
436 /////////////////////////////////////////////////////////////////////////////
437 // MK_VIII::IOHandler ///////////////////////////////////////////////////////
438 /////////////////////////////////////////////////////////////////////////////
452 struct LampConfiguration
458 struct FaultsConfiguration
460 double max_flaps_down_airspeed;
461 double max_gear_down_airspeed;
466 const LampConfiguration *lamp;
467 const FaultsConfiguration *faults;
469 bool steep_approach_enabled;
470 bool gpws_inhibit_enabled;
471 bool momentary_flap_override_enabled;
472 bool alternate_steep_approach;
473 bool use_internal_gps;
474 bool localizer_enabled;
477 struct _s_input_feeders
483 bool glideslope_inhibit;
484 bool decision_height;
485 bool autopilot_engaged;
490 bool uncorrected_barometric_altitude;
491 bool barometric_altitude_rate;
493 bool glideslope_deviation;
495 bool localizer_deviation;
496 bool computed_airspeed;
497 bool decision_height;
505 bool landing_gear; // appendix E 6.6.2, 3.15.1.4
506 bool landing_flaps; // appendix E 6.6.4, 3.15.1.2
507 bool momentary_flap_override; // appendix E 6.6.6, 3.15.1.6
508 bool self_test; // appendix E 6.6.7, 3.15.1.10
509 bool glideslope_inhibit; // appendix E 6.6.11, 3.15.1.1
510 bool glideslope_cancel; // appendix E 6.6.13, 3.15.1.5
511 bool decision_height; // appendix E 6.6.14, 3.10.2
512 bool mode6_low_volume; // appendix E 6.6.15, 3.15.1.7
513 bool audio_inhibit; // appendix E 6.6.16, 3.15.1.3
514 bool ta_tcf_inhibit; // appendix E 6.6.20, 3.15.1.9
515 bool autopilot_engaged; // appendix E 6.6.21, 3.15.1.8
516 bool steep_approach; // appendix E 6.6.25, 3.15.1.11
517 bool gpws_inhibit; // appendix E 6.6.27, 3.15.1.12
522 Parameter<double> uncorrected_barometric_altitude; // appendix E 6.2.1
523 Parameter<double> barometric_altitude_rate; // appendix E 6.2.2
524 Parameter<double> gps_altitude; // appendix E 6.2.4
525 Parameter<double> gps_latitude; // appendix E 6.2.7
526 Parameter<double> gps_longitude; // appendix E 6.2.8
527 Parameter<double> gps_vertical_figure_of_merit; // appendix E 6.2.13
528 Parameter<double> radio_altitude; // appendix E 6.2.29
529 Parameter<double> glideslope_deviation; // appendix E 6.2.30
530 Parameter<double> roll_angle; // appendix E 6.2.31
531 Parameter<double> localizer_deviation; // appendix E 6.2.33
532 Parameter<double> computed_airspeed; // appendix E 6.2.39
533 Parameter<double> decision_height; // appendix E 6.2.41
541 bool gpws_warning; // appendix E 7.4.1, 3.15.2.5
542 bool gpws_alert; // appendix E 7.4.1, 3.15.2.6
543 bool audio_on; // appendix E 7.4.2, 3.15.2.10
544 bool gpws_inop; // appendix E 7.4.3, 3.15.2.3
545 bool tad_inop; // appendix E 7.4.3, 3.15.2.4
546 bool flap_override; // appendix E 7.4.5, 3.15.2.8
547 bool glideslope_cancel; // appendix E 7.4.6, 3.15.2.7
548 bool steep_approach; // appendix E 7.4.12, 3.15.2.9
553 int egpws_alert_discrete_1; // appendix E 7.1.1.1
554 int egpwc_logic_discretes; // appendix E 7.1.1.2
555 int mode6_callouts_discrete_1; // appendix E 7.1.1.3
556 int mode6_callouts_discrete_2; // appendix E 7.1.1.4
557 int egpws_alert_discrete_2; // appendix E 7.1.1.5
558 int egpwc_alert_discrete_3; // appendix E 7.1.1.6
566 Parameter<double> barometric_altitude_rate;
567 Parameter<double> decision_height;
568 Parameter<double> geometric_altitude;
569 Parameter<double> glideslope_deviation_dots;
570 Parameter<double> gps_altitude;
571 Parameter<double> gps_latitude;
572 Parameter<double> gps_longitude;
573 Parameter<double> gps_vertical_figure_of_merit;
574 Parameter<double> localizer_deviation_dots;
575 Parameter<double> radio_altitude;
576 Parameter<double> roll_angle;
577 Parameter<double> terrain_clearance;
580 IOHandler (MK_VIII *device);
586 void enter_ground ();
587 void enter_takeoff ();
589 void update_inputs ();
590 void update_input_faults ();
591 void update_alternate_discrete_input (bool *ptr);
592 void update_internal_latches ();
594 void update_egpws_alert_discrete_1 ();
595 void update_egpwc_logic_discretes ();
596 void update_mode6_callouts_discrete_1 ();
597 void update_mode6_callouts_discrete_2 ();
598 void update_egpws_alert_discrete_2 ();
599 void update_egpwc_alert_discrete_3 ();
600 void update_outputs ();
602 void update_lamps ();
603 void set_lamp (Lamp lamp);
605 bool gpws_inhibit () const;
606 bool real_flaps_down () const;
607 bool flaps_down () const;
608 bool flap_override () const;
609 bool steep_approach () const;
610 bool momentary_steep_approach_enabled () const;
612 void bind (SGPropertyNode *node);
618 ///////////////////////////////////////////////////////////////////////////
619 // MK_VIII::IOHandler::TerrainClearanceFilter /////////////////////////////
620 ///////////////////////////////////////////////////////////////////////////
622 class TerrainClearanceFilter
624 typedef deque< Sample<double> > samples_type;
625 samples_type samples;
629 inline TerrainClearanceFilter ()
632 double update (double agl);
636 ///////////////////////////////////////////////////////////////////////////
637 // MK_VIII::IOHandler (continued) /////////////////////////////////////////
638 ///////////////////////////////////////////////////////////////////////////
640 TerrainClearanceFilter terrain_clearance_filter;
645 Timer audio_inhibit_fault_timer;
646 Timer landing_gear_fault_timer;
647 Timer flaps_down_fault_timer;
648 Timer momentary_flap_override_fault_timer;
649 Timer self_test_fault_timer;
650 Timer glideslope_cancel_fault_timer;
651 Timer steep_approach_fault_timer;
652 Timer gpws_inhibit_fault_timer;
653 Timer ta_tcf_inhibit_fault_timer;
655 bool last_landing_gear;
656 bool last_real_flaps_down;
658 typedef deque< Sample< Parameter<double> > > altitude_samples_type;
659 altitude_samples_type altitude_samples;
663 bool glideslope_cancel;
666 void update_terrain_clearance ();
667 void reset_terrain_clearance ();
669 void handle_input_fault (bool test, FaultHandler::Fault fault);
670 void handle_input_fault (bool test,
673 FaultHandler::Fault fault);
675 void tie_input (SGPropertyNode *node,
679 void tie_input (SGPropertyNode *node,
681 Parameter<double> *input,
683 void tie_output (SGPropertyNode *node,
686 void tie_output (SGPropertyNode *node,
692 bool get_discrete_input (bool *ptr) const;
693 void set_discrete_input (bool *ptr, bool value);
695 void present_status ();
696 void present_status_section (const char *name);
697 void present_status_item (const char *name, const char *value = NULL);
698 void present_status_subitem (const char *name);
700 bool get_present_status () const;
701 void set_present_status (bool value);
703 bool *get_lamp_output (Lamp lamp);
706 /////////////////////////////////////////////////////////////////////////////
707 // MK_VIII::VoicePlayer /////////////////////////////////////////////////////
708 /////////////////////////////////////////////////////////////////////////////
714 ///////////////////////////////////////////////////////////////////////////
715 // MK_VIII::VoicePlayer::Voice ////////////////////////////////////////////
716 ///////////////////////////////////////////////////////////////////////////
722 /////////////////////////////////////////////////////////////////////////
723 // MK_VIII::VoicePlayer::Voice::Element ////////////////////////////////////////
724 /////////////////////////////////////////////////////////////////////////
731 virtual inline void play (double volume) {}
732 virtual inline void stop () {}
733 virtual bool is_playing () = 0;
734 virtual inline void set_volume (double volume) {}
737 /////////////////////////////////////////////////////////////////////////
738 // MK_VIII::VoicePlayer::Voice::SampleElement ///////////////////////////
739 /////////////////////////////////////////////////////////////////////////
741 class SampleElement : public Element
743 SGSoundSample *_sample;
747 inline SampleElement (SGSoundSample *sample, double volume = 1.0)
748 : _sample(sample), _volume(volume) { silence = false; }
750 virtual inline void play (double volume) { if (_sample) { set_volume(volume); _sample->play_once(); } }
751 virtual inline void stop () { if (_sample) _sample->stop(); }
752 virtual inline bool is_playing () { return _sample ? _sample->is_playing() : false; }
753 virtual inline void set_volume (double volume) { if (_sample) _sample->set_volume(volume * _volume); }
756 /////////////////////////////////////////////////////////////////////////
757 // MK_VIII::VoicePlayer::Voice::SilenceElement //////////////////////////
758 /////////////////////////////////////////////////////////////////////////
760 class SilenceElement : public Element
766 inline SilenceElement (double duration)
767 : _duration(duration) { silence = true; }
769 virtual inline void play (double volume) { start_time = globals->get_sim_time_sec(); }
770 virtual inline bool is_playing () { return globals->get_sim_time_sec() - start_time < _duration; }
773 /////////////////////////////////////////////////////////////////////////
774 // MK_VIII::VoicePlayer::Voice (continued) //////////////////////////////
775 /////////////////////////////////////////////////////////////////////////
779 inline Voice (VoicePlayer *_player)
780 : player(_player), volume(1.0), element(NULL) {}
784 inline void append (Element *_element) { elements.push_back(_element); }
787 void stop (bool now);
788 void set_volume (double _volume);
789 void volume_changed ();
797 vector<Element *> elements;
798 vector<Element *>::iterator iter;
800 inline double get_volume () const { return player->volume * player->speaker.volume * volume; }
803 ///////////////////////////////////////////////////////////////////////////
804 // MK_VIII::VoicePlayer (continued) ///////////////////////////////////////
805 ///////////////////////////////////////////////////////////////////////////
819 Voice *application_data_base_failed;
821 Voice *bank_angle_bank_angle;
822 Voice *bank_angle_bank_angle_3;
823 Voice *bank_angle_inop;
824 Voice *bank_angle_pause_bank_angle;
825 Voice *bank_angle_pause_bank_angle_3;
826 Voice *callouts_inop;
827 Voice *configuration_type_invalid;
829 Voice *dont_sink_pause_dont_sink;
830 Voice *five_hundred_above;
832 Voice *glideslope_inop;
834 Voice *hard_glideslope;
836 Voice *minimums_minimums;
839 Voice *sink_rate_pause_sink_rate;
840 Voice *soft_glideslope;
842 Voice *terrain_pause_terrain;
843 Voice *too_low_flaps;
845 Voice *too_low_terrain;
846 Voice *altitude_callouts[n_altitude_callouts];
849 inline VoicePlayer (MK_VIII *device)
850 : mk(device), speaker(this), voice(NULL), next_voice(NULL) {}
861 void play (Voice *_voice, unsigned int flags = 0);
867 void stop (unsigned int flags = 0);
869 void set_volume (double _volume);
872 inline void bind (SGPropertyNode *node) { speaker.bind(node); }
876 ///////////////////////////////////////////////////////////////////////////
877 // MK_VIII::VoicePlayer::Speaker //////////////////////////////////////////
878 ///////////////////////////////////////////////////////////////////////////
886 float orientation[3];
890 float reference_dist;
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)
923 position[0] = 0; position[1] = 0; position[2] = 0;
924 orientation[0] = 0; orientation[1] = 0; orientation[2] = 0;
927 void bind (SGPropertyNode *node);
928 void update_configuration ();
932 ///////////////////////////////////////////////////////////////////////////
933 // MK_VIII::VoicePlayer (continued) ///////////////////////////////////////
934 ///////////////////////////////////////////////////////////////////////////
940 map<string, SGSoundSample *> samples;
941 vector<Voice *> _voices;
946 SGSoundSample *get_sample (const char *name);
948 inline void append (Voice *voice, Voice::Element *element) { voice->append(element); }
949 inline void append (Voice *voice, const char *sample_name) { voice->append(new Voice::SampleElement(get_sample(sample_name))); }
950 inline void append (Voice *voice, double silence) { voice->append(new Voice::SilenceElement(silence)); }
952 inline void make_voice (Voice **voice) { *voice = new Voice(this); _voices.push_back(*voice); }
955 inline void make_voice (Voice **voice, T1 e1) { make_voice(voice); append(*voice, e1); }
956 template <class T1, class T2>
957 inline void make_voice (Voice **voice, T1 e1, T2 e2) { make_voice(voice, e1); append(*voice, e2); }
958 template <class T1, class T2, class T3>
959 inline void make_voice (Voice **voice, T1 e1, T2 e2, T3 e3) { make_voice(voice, e1, e2); append(*voice, e3); }
960 template <class T1, class T2, class T3, class T4>
961 inline void make_voice (Voice **voice, T1 e1, T2 e2, T3 e3, T4 e4) { make_voice(voice, e1, e2, e3); append(*voice, e4); }
965 /////////////////////////////////////////////////////////////////////////////
966 // MK_VIII::SelfTestHandler /////////////////////////////////////////////////
967 /////////////////////////////////////////////////////////////////////////////
969 class SelfTestHandler
982 ACTION_SLEEP = 1 << 0,
983 ACTION_VOICE = 1 << 1,
984 ACTION_DISCRETE_ON_OFF = 1 << 2,
991 double sleep_duration;
999 double button_press_timestamp;
1000 IOHandler::Outputs saved_outputs;
1003 bool _was_here (int position);
1005 Action sleep (double duration);
1006 Action play (VoicePlayer::Voice *voice);
1007 Action discrete_on (bool *discrete, double duration);
1008 Action discrete_on_off (bool *discrete, double duration);
1009 Action discrete_on_off (bool *discrete, VoicePlayer::Voice *voice);
1028 inline SelfTestHandler (MK_VIII *device)
1029 : mk(device), state(STATE_NONE), button_pressed(false) {}
1031 inline void power_off () { stop(); }
1032 inline void set_inop () { stop(); }
1033 void handle_button_event (bool value);
1037 /////////////////////////////////////////////////////////////////////////////
1038 // MK_VIII::AlertHandler ////////////////////////////////////////////////////
1039 /////////////////////////////////////////////////////////////////////////////
1045 unsigned int old_alerts;
1046 unsigned int voice_alerts;
1047 unsigned int repeated_alerts;
1048 VoicePlayer::Voice *altitude_callout_voice;
1051 inline bool has_alerts (unsigned int test) const { return (alerts & test) != 0; }
1052 inline bool has_old_alerts (unsigned int test) const { return (old_alerts & test) != 0; }
1053 inline bool must_play_voice (unsigned int test) const { return ! has_old_alerts(test) || (repeated_alerts & test) != 0; }
1054 bool select_voice_alerts (unsigned int test);
1059 ALERT_MODE1_PULL_UP = 1 << 0,
1060 ALERT_MODE1_SINK_RATE = 1 << 1,
1062 ALERT_MODE2A_PREFACE = 1 << 2,
1063 ALERT_MODE2B_PREFACE = 1 << 3,
1064 ALERT_MODE2A = 1 << 4,
1065 ALERT_MODE2B = 1 << 5,
1066 ALERT_MODE2B_LANDING_MODE = 1 << 6,
1067 ALERT_MODE2A_ALTITUDE_GAIN = 1 << 7,
1068 ALERT_MODE2A_ALTITUDE_GAIN_TERRAIN_CLOSING = 1 << 8,
1070 ALERT_MODE3 = 1 << 9,
1072 ALERT_MODE4_TOO_LOW_FLAPS = 1 << 10,
1073 ALERT_MODE4_TOO_LOW_GEAR = 1 << 11,
1074 ALERT_MODE4AB_TOO_LOW_TERRAIN = 1 << 12,
1075 ALERT_MODE4C_TOO_LOW_TERRAIN = 1 << 13,
1077 ALERT_MODE5_SOFT = 1 << 14,
1078 ALERT_MODE5_HARD = 1 << 15,
1080 ALERT_MODE6_MINIMUMS = 1 << 16,
1081 ALERT_MODE6_ALTITUDE_CALLOUT = 1 << 17,
1082 ALERT_MODE6_LOW_BANK_ANGLE_1 = 1 << 18,
1083 ALERT_MODE6_HIGH_BANK_ANGLE_1 = 1 << 19,
1084 ALERT_MODE6_LOW_BANK_ANGLE_2 = 1 << 20,
1085 ALERT_MODE6_HIGH_BANK_ANGLE_2 = 1 << 21,
1086 ALERT_MODE6_LOW_BANK_ANGLE_3 = 1 << 22,
1087 ALERT_MODE6_HIGH_BANK_ANGLE_3 = 1 << 23,
1089 ALERT_TCF_TOO_LOW_TERRAIN = 1 << 24
1094 ALERT_FLAG_REPEAT = 1 << 0
1097 unsigned int alerts;
1099 inline AlertHandler (MK_VIII *device)
1106 void set_alerts (unsigned int _alerts,
1107 unsigned int flags = 0,
1108 VoicePlayer::Voice *_altitude_callout_voice = NULL);
1109 void unset_alerts (unsigned int _alerts);
1111 inline void repeat_alert (unsigned int alert) { set_alerts(alert, ALERT_FLAG_REPEAT); }
1112 inline void set_altitude_callout_alert (VoicePlayer::Voice *voice) { set_alerts(ALERT_MODE6_ALTITUDE_CALLOUT, 0, voice); }
1115 /////////////////////////////////////////////////////////////////////////////
1116 // MK_VIII::StateHandler ////////////////////////////////////////////////////
1117 /////////////////////////////////////////////////////////////////////////////
1123 Timer potentially_airborne_timer;
1125 void update_ground ();
1126 void enter_ground ();
1127 void leave_ground ();
1129 void update_takeoff ();
1130 void enter_takeoff ();
1131 void leave_takeoff ();
1137 inline StateHandler (MK_VIII *device)
1138 : mk(device), ground(true), takeoff(true) {}
1140 void post_reposition ();
1144 /////////////////////////////////////////////////////////////////////////////
1145 // MK_VIII::Mode1Handler ////////////////////////////////////////////////////
1146 /////////////////////////////////////////////////////////////////////////////
1152 Timer pull_up_timer;
1153 Timer sink_rate_timer;
1155 double sink_rate_tti; // time-to-impact in minutes
1157 double get_pull_up_bias ();
1160 double get_sink_rate_bias ();
1161 bool is_sink_rate ();
1162 double get_sink_rate_tti ();
1164 void update_pull_up ();
1165 void update_sink_rate ();
1170 bool flap_override_bias;
1172 double (*pull_up_min_agl1) (double vs);
1173 int pull_up_max_agl1;
1174 double (*pull_up_min_agl2) (double vs);
1175 int pull_up_max_agl2;
1176 } EnvelopesConfiguration;
1180 const EnvelopesConfiguration *envelopes;
1183 inline Mode1Handler (MK_VIII *device)
1189 /////////////////////////////////////////////////////////////////////////////
1190 // MK_VIII::Mode2Handler ////////////////////////////////////////////////////
1191 /////////////////////////////////////////////////////////////////////////////
1196 ///////////////////////////////////////////////////////////////////////////
1197 // MK_VIII::Mode2Handler::ClosureRateFilter ///////////////////////////////
1198 ///////////////////////////////////////////////////////////////////////////
1200 class ClosureRateFilter
1202 /////////////////////////////////////////////////////////////////////////
1203 // MK_VIII::Mode2Handler::ClosureRateFilter::PassFilter /////////////////
1204 /////////////////////////////////////////////////////////////////////////
1216 inline PassFilter (double _a0, double _a1, double _b1)
1217 : a0(_a0), a1(_a1), b1(_b1) {}
1219 inline double filter (double input)
1221 last_output = a0 * input + a1 * last_input + b1 * last_output;
1227 inline void reset ()
1234 /////////////////////////////////////////////////////////////////////////
1235 // MK_VIII::Mode2Handler::ClosureRateFilter (continued) /////////////////
1236 /////////////////////////////////////////////////////////////////////////
1241 Parameter<double> last_ra; // last radio altitude
1242 Parameter<double> last_ba; // last barometric altitude
1243 PassFilter ra_filter; // radio altitude rate filter
1244 PassFilter ba_filter; // barometric altitude rate filter
1246 double limit_radio_altitude_rate (double r);
1249 Parameter<double> output;
1251 inline ClosureRateFilter (MK_VIII *device)
1253 ra_filter(0.05, 0, 0.95), // low-pass filter
1254 ba_filter(0.93, -0.93, 0.86) {} // high-pass-filter
1260 ///////////////////////////////////////////////////////////////////////////
1261 // MK_VIII::Mode2Handler (continued) //////////////////////////////////////
1262 ///////////////////////////////////////////////////////////////////////////
1266 ClosureRateFilter closure_rate_filter;
1268 Timer takeoff_timer;
1269 Timer pull_up_timer;
1271 double a_start_time;
1272 Timer a_altitude_gain_timer;
1273 double a_altitude_gain_alt;
1275 void check_pull_up (unsigned int preface_alert, unsigned int alert);
1277 bool b_conditions ();
1292 const Configuration *conf;
1294 inline Mode2Handler (MK_VIII *device)
1295 : mk(device), closure_rate_filter(device) {}
1299 void leave_ground ();
1300 void enter_takeoff ();
1304 /////////////////////////////////////////////////////////////////////////////
1305 // MK_VIII::Mode3Handler ////////////////////////////////////////////////////
1306 /////////////////////////////////////////////////////////////////////////////
1313 bool has_descent_alt;
1317 double max_alt_loss (double _bias);
1318 double get_bias (double initial_bias, double alt_loss);
1319 bool is (double *alt_loss);
1325 int (*max_agl) (bool flap_override);
1326 double (*max_alt_loss) (bool flap_override, double agl);
1329 const Configuration *conf;
1331 inline Mode3Handler (MK_VIII *device)
1332 : mk(device), armed(false), has_descent_alt(false) {}
1334 void enter_takeoff ();
1338 /////////////////////////////////////////////////////////////////////////////
1339 // MK_VIII::Mode4Handler ////////////////////////////////////////////////////
1340 /////////////////////////////////////////////////////////////////////////////
1350 double (*min_agl2) (double airspeed);
1352 } EnvelopesConfiguration;
1356 const EnvelopesConfiguration *ac;
1357 const EnvelopesConfiguration *b;
1358 } ModesConfiguration;
1362 VoicePlayer::Voice *voice_too_low_gear;
1363 const ModesConfiguration *modes;
1366 inline Mode4Handler (MK_VIII *device)
1369 double get_upper_agl (const EnvelopesConfiguration *c);
1376 double ab_expanded_bias;
1379 const EnvelopesConfiguration *get_ab_envelope ();
1380 double get_bias (double initial_bias, double min_agl);
1381 void handle_alert (unsigned int alert, double min_agl, double *bias);
1384 void update_ab_expanded ();
1388 /////////////////////////////////////////////////////////////////////////////
1389 // MK_VIII::Mode5Handler ////////////////////////////////////////////////////
1390 /////////////////////////////////////////////////////////////////////////////
1402 bool is_soft (double bias);
1404 double get_soft_bias (double initial_bias);
1406 void update_hard (bool is);
1407 void update_soft (bool is);
1410 inline Mode5Handler (MK_VIII *device)
1416 /////////////////////////////////////////////////////////////////////////////
1417 // MK_VIII::Mode6Handler ////////////////////////////////////////////////////
1418 /////////////////////////////////////////////////////////////////////////////
1423 // keep in sync with altitude_callout_definitions[]
1426 ALTITUDE_CALLOUT_1000,
1427 ALTITUDE_CALLOUT_500,
1428 ALTITUDE_CALLOUT_400,
1429 ALTITUDE_CALLOUT_300,
1430 ALTITUDE_CALLOUT_200,
1431 ALTITUDE_CALLOUT_100,
1432 ALTITUDE_CALLOUT_50,
1433 ALTITUDE_CALLOUT_40,
1434 ALTITUDE_CALLOUT_30,
1435 ALTITUDE_CALLOUT_20,
1439 typedef bool (*BankAnglePredicate) (Parameter<double> *agl,
1440 double abs_roll_deg,
1445 bool minimums_enabled;
1446 bool smart_500_enabled;
1447 VoicePlayer::Voice *above_field_voice;
1449 bool altitude_callouts_enabled[n_altitude_callouts];
1450 bool bank_angle_enabled;
1451 BankAnglePredicate is_bank_angle;
1454 static const int altitude_callout_definitions[];
1456 inline Mode6Handler (MK_VIII *device)
1461 void enter_takeoff ();
1462 void leave_takeoff ();
1463 void set_volume (double volume);
1464 bool altitude_callouts_enabled ();
1470 bool last_decision_height;
1471 Parameter<double> last_radio_altitude;
1472 Parameter<double> last_altitude_above_field;
1474 bool altitude_callouts_issued[n_altitude_callouts];
1475 bool minimums_issued;
1476 bool above_field_issued;
1479 Parameter<bool> has_runway;
1483 double elevation; // elevation in feet
1486 void reset_minimums ();
1487 void reset_altitude_callouts ();
1488 bool is_playing_altitude_callout ();
1489 bool is_near_minimums (double callout);
1490 bool is_outside_band (double elevation, double callout);
1491 bool inhibit_smart_500 ();
1493 void update_minimums ();
1494 void update_altitude_callouts ();
1496 bool test_runway (const FGRunway *_runway);
1497 bool test_airport (const FGAirport *airport);
1498 void update_runway ();
1500 void get_altitude_above_field (Parameter<double> *parameter);
1501 void update_above_field_callout ();
1503 bool is_bank_angle (double abs_roll_angle, double bias);
1504 bool is_high_bank_angle ();
1505 unsigned int get_bank_angle_alerts ();
1506 void update_bank_angle ();
1509 /////////////////////////////////////////////////////////////////////////////
1510 // MK_VIII::TCFHandler //////////////////////////////////////////////////////
1511 /////////////////////////////////////////////////////////////////////////////
1517 double latitude; // latitude in degrees
1518 double longitude; // longitude in degrees
1523 Position position; // position of threshold
1524 double heading; // runway heading
1529 static const double k;
1536 Position center; // center point
1537 double elevation; // elevation in feet
1538 double half_length; // runway half length, in nautical miles
1539 RunwayEdge edges[2]; // runway threshold and end
1540 Position bias_area[4]; // vertices of the bias area
1545 double initial_value;
1547 double get_azimuth_difference (double from_lat,
1552 double get_azimuth_difference (const FGRunway *_runway);
1554 void select_runway (const FGAirport *airport, FGRunway *_runway);
1555 bool test_airport (const FGAirport *airport);
1556 void update_runway ();
1558 void get_bias_area_edges (Position *edge,
1560 double half_width_m,
1561 Position *bias_edge1,
1562 Position *bias_edge2);
1564 bool is_inside_edge_triangle (RunwayEdge *edge);
1565 bool is_inside_bias_area ();
1576 inline TCFHandler (MK_VIII *device)
1582 /////////////////////////////////////////////////////////////////////////////
1583 // MK_VIII (continued) //////////////////////////////////////////////////////
1584 /////////////////////////////////////////////////////////////////////////////
1589 PowerHandler power_handler;
1590 SystemHandler system_handler;
1591 ConfigurationModule configuration_module;
1592 FaultHandler fault_handler;
1593 IOHandler io_handler;
1594 VoicePlayer voice_player;
1595 SelfTestHandler self_test_handler;
1596 AlertHandler alert_handler;
1597 StateHandler state_handler;
1598 Mode1Handler mode1_handler;
1599 Mode2Handler mode2_handler;
1600 Mode3Handler mode3_handler;
1601 Mode4Handler mode4_handler;
1602 Mode5Handler mode5_handler;
1603 Mode6Handler mode6_handler;
1604 TCFHandler tcf_handler;
1608 int runway_database;
1612 MK_VIII (SGPropertyNode *node);
1614 virtual void init ();
1615 virtual void bind ();
1616 virtual void unbind ();
1617 virtual void update (double dt);
1620 #endif // __INSTRUMENTS_MK_VIII_HXX