back-seat-instruments.nas 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. var UPDATE_PERIOD = 0.05;
  2. # Check pilot's aircraft path from it's callsign.
  3. var PilotCallsign = props.globals.getNode("/sim/remote/pilot-callsign");
  4. var Pilot = nil;
  5. var check_pilot_callsign = func() {
  6. r_callsign = PilotCallsign.getValue();
  7. if ( r_callsign ) {
  8. var mpplayers = props.globals.getNode("/ai/models").getChildren("multiplayer");
  9. foreach (var p; mpplayers) {
  10. if ( p.getChild("callsign").getValue() == r_callsign ) {
  11. Pilot = p;
  12. }
  13. }
  14. } else {
  15. Pilot = nil;
  16. }
  17. }
  18. var select_ecm_nav = func {
  19. var ecm_nav_mode = Pilot.getNode("sim/model/f-14b/controls/rio-ecm-display/mode-ecm-nav");
  20. ecm_nav_mode.setBoolValue( ! ecm_nav_mode.getBoolValue());
  21. }
  22. ##
  23. # Receive basic instruments data over MP from pilot's aircraft.
  24. var PilotInstrString = nil;
  25. instruments_data_import = func {
  26. if ( Pilot == nil ) { return }
  27. PilotInstrString = Pilot.getNode("sim/multiplay/generic/string[1]", 1);
  28. var str = PilotInstrString.getValue();
  29. if ( str != nil ) {
  30. var l = split(";", str);
  31. # Todo: Create the needed nodes only at connection/de-connection time.
  32. # ias, mach, fuel_total, tc_mode, tc_bearing, tc_in_range, tc_range, steer_mode_code, cdi, radial.
  33. if ( size(l) > 1 ) {
  34. Pilot.getNode("instrumentation/airspeed-indicator/indicated-speed-kt", 1).setValue( l[0] );
  35. Pilot.getNode("velocities/mach", 1).setValue( l[1] );
  36. Pilot.getNode("sim/model/f-14b/instrumentation/fuel-gauges/total", 1).setValue( l[2] );
  37. Pilot.getNode("sim/model/f-14b/instrumentation/tacan/mode", 1).setValue( l[3] );
  38. Pilot.getNode("instrumentation/tacan/indicated-mag-bearing-deg", 1).setValue( l[4] );
  39. Pilot.getNode("instrumentation/tacan/in-range", 1).setBoolValue( l[5] );
  40. Pilot.getNode("instrumentation/tacan/indicated-distance-nm", 1).setValue( l[6] );
  41. var SteerSubmodeCode = Pilot.getNode("sim/model/f-14b/controls/pilots-displays/steer-submode-code", 1);
  42. SteerSubmodeCode.setValue( l[7] );
  43. Pilot.getNode("sim/model/f-14b/instrumentation/hsd/needle-deflection", 1).setValue( l[8] );
  44. Pilot.getNode("instrumentation/nav[1]/radials/selected-deg", 1).setValue( l[9] );
  45. if (size(l) > 11)
  46. {
  47. var ac_powered = l[10] != nil and l[10] == "1";
  48. setprop("/fdm/jsbsim/systems/electrics/ac-essential-bus1",ac_powered);
  49. setprop("/fdm/jsbsim/systems/electrics/ac-essential-bus2",ac_powered);
  50. setprop("/fdm/jsbsim/systems/electrics/ac-left-main-bus",ac_powered);
  51. setprop("/fdm/jsbsim/systems/electrics/ac-right-main-bus",ac_powered);
  52. setprop("/fdm/jsbsim/systems/electrics/dc-essential-bus1",ac_powered);
  53. setprop("/fdm/jsbsim/systems/electrics/dc-essential-bus2",ac_powered);
  54. setprop("/fdm/jsbsim/systems/electrics/dc-main-bus",ac_powered);
  55. }
  56. }
  57. }
  58. #PilotInstrString2 = Pilot.getNode("sim/multiplay/generic/string[2]", 1);
  59. #var str2 = PilotInstrString2.getValue();
  60. #if ( str2 != nil ) {
  61. #Pilot.getNode("instrumentation/radar/radar2-range", 1).setValue(str2);
  62. #}
  63. }
  64. # Send a/c type over MP for pilot.
  65. var InstrString = props.globals.getNode("sim/multiplay/generic/string[1]", 1);
  66. var ACString = props.globals.getNode("sim/aircraft");
  67. instruments_data_export = func {
  68. # Aircraft variant
  69. var ac_string = ACString.getValue();
  70. var l_s = [ac_string];
  71. var str = "";
  72. foreach( s ; l_s ) {
  73. str = str ~ s ~ ";";
  74. }
  75. InstrString.setValue(str);
  76. }
  77. # Main loop ###############
  78. var cnt = 0;
  79. var main_loop = func {
  80. cnt += 1;
  81. # done each 0.05 sec.
  82. awg_9.rdr_loop();
  83. var a = cnt / 2;
  84. if ( ( a ) == int( a )) {
  85. # done each 0.1 sec, cnt even.
  86. #if (( cnt == 6 ) or ( cnt == 12 )) {
  87. # done each 0.3 sec.
  88. #if ( cnt == 12 ) {
  89. # done each 0.6 sec.
  90. #cnt = 0;
  91. #}
  92. #}
  93. } else {
  94. # done each 0.1 sec, cnt odd.
  95. check_pilot_callsign();
  96. instruments_data_import();
  97. instruments_data_export();
  98. #if (( cnt == 5 ) or ( cnt == 11 )) {
  99. # done each 0.3 sec.
  100. #if ( cnt == 11 ) {
  101. # done each 0.6 sec.
  102. #}
  103. #}
  104. }
  105. settimer(main_loop, UPDATE_PERIOD);
  106. }
  107. # Init ####################
  108. var init = func {
  109. print("Initializing F-14B Back Seat Systems");
  110. #
  111. #
  112. # Set the electrics for yasim (basic electrical model)
  113. setprop("/fdm/jsbsim/systems/electrics/ac-essential-bus1",75);
  114. setprop("/fdm/jsbsim/systems/electrics/ac-essential-bus2",75);
  115. setprop("/fdm/jsbsim/systems/electrics/ac-left-main-bus",75);
  116. setprop("/fdm/jsbsim/systems/electrics/ac-right-main-bus",75);
  117. setprop("/fdm/jsbsim/systems/electrics/dc-essential-bus1",28);
  118. setprop("/fdm/jsbsim/systems/electrics/dc-essential-bus2",28);
  119. setprop("/fdm/jsbsim/systems/electrics/dc-main-bus",28);
  120. setprop("/fdm/jsbsim/systems/electrics/egenerator-kva",0);
  121. setprop("/fdm/jsbsim/systems/electrics/emerg-generator-status",0);
  122. setprop("/fdm/jsbsim/systems/electrics/lgenerator-kva",75);
  123. setprop("/fdm/jsbsim/systems/electrics/rgenerator-kva",75);
  124. setprop("/fdm/jsbsim/systems/electrics/transrect-online",2);
  125. setprop("fdm/jsbsim/systems/hydraulics/combined-system-psi",2398);
  126. setprop("fdm/jsbsim/systems/hydraulics/flight-system-psi",2396);
  127. setprop("engines/engine[0]/oil-pressure-psi", 28);
  128. setprop("engines/engine[1]/oil-pressure-psi", 28);
  129. # launch
  130. check_pilot_callsign();
  131. radardist.init();
  132. awg_9.init();
  133. settimer(main_loop, 0.5);
  134. }
  135. setlistener("sim/signals/fdm-initialized", init);