@@ -43,12 +43,13 @@ public class GsxController
4343 private bool finalLoadsheetSend = false ;
4444 private bool equipmentRemoved = false ;
4545 private bool pushRunning = false ;
46- private bool pushFinished = true ; //DISABLED - GSX Variable not working
46+ private bool pushFinished = false ;
4747 private bool pushNwsDisco = false ;
4848 private bool pcaRemoved = false ;
4949 private bool deboarding = false ;
5050 private int delayCounter = 0 ;
5151 private int delay = 0 ;
52+ private bool operatorWasSelected = false ;
5253 private string flightPlanID = "0" ;
5354 private int paxPlanned = 0 ;
5455 private bool firstRun = true ;
@@ -93,6 +94,7 @@ public GsxController(ServiceModel model)
9394 SimConnect . SubscribeLvar ( "FSDT_GSX_STAIRS" ) ;
9495 SimConnect . SubscribeLvar ( "FSDT_GSX_OPERATESTAIRS_STATE" ) ;
9596 SimConnect . SubscribeLvar ( "FSDT_GSX_BYPASS_PIN" ) ;
97+ SimConnect . SubscribeLvar ( "FSDT_VAR_Frozen" ) ;
9698 SimConnect . SubscribeLvar ( "S_MIP_PARKING_BRAKE" ) ;
9799 SimConnect . SubscribeLvar ( "S_OH_EXT_LT_BEACON" ) ;
98100 SimConnect . SubscribeLvar ( "I_OH_ELEC_EXT_PWR_L" ) ;
@@ -146,7 +148,7 @@ private void GetAudioSessions()
146148 }
147149 }
148150
149- if ( ! string . IsNullOrEmpty ( Model . Vhf1VolumeApp ) && vhf1AudioSession == null )
151+ if ( Model . IsVhf1Controllable ( ) && vhf1AudioSession == null )
150152 {
151153 MMDeviceEnumerator deviceEnumerator = new ( Guid . NewGuid ( ) ) ;
152154 var devices = deviceEnumerator . EnumerateAudioEndPoints ( DataFlow . Render , DeviceState . Active ) ;
@@ -193,11 +195,12 @@ public void ControlAudio()
193195 {
194196 if ( SimConnect . ReadLvar ( "I_FCU_TRACK_FPA_MODE" ) == 0 && SimConnect . ReadLvar ( "I_FCU_HEADING_VS_MODE" ) == 0 )
195197 {
196- if ( Model . GsxVolumeControl || ! string . IsNullOrEmpty ( Model . Vhf1VolumeApp ) )
198+ if ( Model . GsxVolumeControl || Model . IsVhf1Controllable ( ) )
197199 ResetAudio ( ) ;
198200 return ;
199201 }
200202
203+ //GSX
201204 if ( Model . GsxVolumeControl && gsxAudioSession != null )
202205 {
203206 float volume = SimConnect . ReadLvar ( "A_ASP_INT_VOLUME" ) ;
@@ -230,7 +233,8 @@ public void ControlAudio()
230233 Logger . Log ( LogLevel . Information , "GsxController:ControlAudio" , $ "Disabled Audio Session for GSX (Setting disabled)") ;
231234 }
232235
233- if ( ! string . IsNullOrEmpty ( Model . Vhf1VolumeApp ) && vhf1AudioSession != null )
236+ //VHF1
237+ if ( Model . IsVhf1Controllable ( ) && vhf1AudioSession != null )
234238 {
235239 float volume = SimConnect . ReadLvar ( "A_ASP_VHF_1_VOLUME" ) ;
236240 int muted = ( int ) SimConnect . ReadLvar ( "I_ASP_VHF_1_REC" ) ;
@@ -240,19 +244,35 @@ public void ControlAudio()
240244 vhf1AudioVolume = volume ;
241245 }
242246
243- if ( muted >= 0 && muted != vhf1AudioMute )
247+ if ( Model . Vhf1LatchMute && muted >= 0 && muted != vhf1AudioMute )
244248 {
245249 vhf1AudioSession . SimpleAudioVolume . Mute = muted == 0 ;
246250 vhf1AudioMute = muted ;
247251 }
252+ else if ( ! Model . Vhf1LatchMute && vhf1AudioSession . SimpleAudioVolume . Mute )
253+ {
254+ Logger . Log ( LogLevel . Information , "GsxController:ControlAudio" , $ "Unmuting { lastVhf1App } (App muted and Mute-Option disabled)") ;
255+ vhf1AudioSession . SimpleAudioVolume . Mute = false ;
256+ vhf1AudioMute = - 1 ;
257+ }
248258 }
249- else if ( ! string . IsNullOrEmpty ( Model . Vhf1VolumeApp ) && vhf1AudioSession == null )
259+ else if ( Model . IsVhf1Controllable ( ) && vhf1AudioSession == null )
250260 {
251261 GetAudioSessions ( ) ;
252262 vhf1AudioVolume = - 1 ;
253263 vhf1AudioMute = - 1 ;
254264 }
265+ else if ( ! Model . Vhf1VolumeControl && ! string . IsNullOrEmpty ( lastVhf1App ) && vhf1AudioSession != null )
266+ {
267+ vhf1AudioSession . SimpleAudioVolume . MasterVolume = 1.0f ;
268+ vhf1AudioSession . SimpleAudioVolume . Mute = false ;
269+ vhf1AudioSession = null ;
270+ vhf1AudioVolume = - 1 ;
271+ vhf1AudioMute = - 1 ;
272+ Logger . Log ( LogLevel . Information , "GsxController:ControlAudio" , $ "Disabled Audio Session for { lastVhf1App } (Setting disabled)") ;
273+ }
255274
275+ //App Change
256276 if ( lastVhf1App != Model . Vhf1VolumeApp )
257277 {
258278 if ( vhf1AudioSession != null )
@@ -268,6 +288,7 @@ public void ControlAudio()
268288 }
269289 lastVhf1App = Model . Vhf1VolumeApp ;
270290
291+ //GSX exited
271292 if ( Model . GsxVolumeControl && gsxAudioSession != null && ! IPCManager . IsProcessRunning ( gsxProcess ) )
272293 {
273294 gsxAudioSession = null ;
@@ -276,6 +297,7 @@ public void ControlAudio()
276297 Logger . Log ( LogLevel . Information , "GsxController:ControlAudio" , $ "Disabled Audio Session for GSX (App not running)") ;
277298 }
278299
300+ //COUATL
279301 if ( Model . GsxVolumeControl && gsxAudioSession != null && SimConnect . ReadLvar ( "FSDT_GSX_COUATL_STARTED" ) != 1 )
280302 {
281303 gsxAudioSession . SimpleAudioVolume . MasterVolume = 1.0f ;
@@ -286,7 +308,8 @@ public void ControlAudio()
286308 Logger . Log ( LogLevel . Information , "GsxController:ControlAudio" , $ "Disabled Audio Session for GSX (Couatl Engine not started)") ;
287309 }
288310
289- if ( ! string . IsNullOrEmpty ( Model . Vhf1VolumeApp ) && vhf1AudioSession != null && ! IPCManager . IsProcessRunning ( Model . Vhf1VolumeApp ) )
311+ //VHF1 exited
312+ if ( Model . IsVhf1Controllable ( ) && vhf1AudioSession != null && ! IPCManager . IsProcessRunning ( Model . Vhf1VolumeApp ) )
290313 {
291314 vhf1AudioSession = null ;
292315 vhf1AudioVolume = - 1 ;
@@ -305,6 +328,12 @@ public void RunServices()
305328 bool simOnGround = SimConnect . ReadSimVar ( "SIM ON GROUND" , "Bool" ) != 0.0f ;
306329 FenixController . Update ( false ) ;
307330
331+ if ( operatorWasSelected )
332+ {
333+ MenuOpen ( ) ;
334+ operatorWasSelected = false ;
335+ }
336+
308337 //PREPARATION (On-Ground and Engines not running)
309338 if ( state == FlightState . PREP && simOnGround && ! FenixController . enginesRunning )
310339 {
@@ -335,7 +364,9 @@ public void RunServices()
335364 Thread . Sleep ( ( int ) ( Model . RepositionDelay * 1000.0f ) ) ;
336365 Logger . Log ( LogLevel . Information , "GsxController:RunServices" , $ "Repositioning Plane") ;
337366 MenuOpen ( ) ;
367+ Thread . Sleep ( 100 ) ;
338368 MenuItem ( 10 ) ;
369+ Thread . Sleep ( 250 ) ;
339370 MenuItem ( 1 ) ;
340371 planePositioned = true ;
341372 Thread . Sleep ( 1500 ) ;
@@ -488,7 +519,7 @@ public void RunServices()
488519 finalLoadsheetSend = false ;
489520 equipmentRemoved = false ;
490521 pushRunning = false ;
491- pushFinished = true ; //DISABLED
522+ pushFinished = false ;
492523 pushNwsDisco = false ;
493524 pcaRemoved = false ;
494525 deboarding = false ;
@@ -620,14 +651,15 @@ private void RunDepatureServices()
620651 }
621652 }
622653
654+ //LOADSHEET
623655 int departState = ( int ) SimConnect . ReadLvar ( "FSDT_GSX_DEPARTURE_STATE" ) ;
624656 if ( ! finalLoadsheetSend )
625657 {
626658 if ( delay == 0 )
627659 {
628660 delay = new Random ( ) . Next ( 90 , 150 ) ;
629661 delayCounter = 0 ;
630- Logger . Log ( LogLevel . Information , "GsxController:RunDepatureServices" , $ "Sending Final Loadsheet in { delay } s") ;
662+ Logger . Log ( LogLevel . Information , "GsxController:RunDepatureServices" , $ "Final Loadsheet in { delay } s") ;
631663 }
632664
633665 if ( delayCounter < delay )
@@ -637,11 +669,13 @@ private void RunDepatureServices()
637669 }
638670 else
639671 {
640- Logger . Log ( LogLevel . Information , "GsxController:RunDepatureServices" , $ "Sending Final Loadsheet") ;
672+ Logger . Log ( LogLevel . Information , "GsxController:RunDepatureServices" , $ "Transmitting Final Loadsheet ... ") ;
641673 FenixController . TriggerFinal ( ) ;
642674 finalLoadsheetSend = true ;
675+ Logger . Log ( LogLevel . Information , "GsxController:RunDepatureServices" , $ "Final Loadsheet sent to ACARS") ;
643676 }
644677 }
678+ //EQUIPMENT
645679 else if ( ! equipmentRemoved )
646680 {
647681 equipmentRemoved = SimConnect . ReadLvar ( "S_MIP_PARKING_BRAKE" ) == 1 && SimConnect . ReadLvar ( "S_OH_EXT_LT_BEACON" ) == 1 && SimConnect . ReadLvar ( "I_OH_ELEC_EXT_PWR_L" ) == 0 ;
@@ -659,8 +693,15 @@ private void RunDepatureServices()
659693 FenixController . SetServiceGPU ( false ) ;
660694 }
661695 }
696+ //PUSHBACK
662697 else if ( ! pushFinished )
663698 {
699+ if ( ! Model . SynchBypass )
700+ {
701+ pushFinished = true ;
702+ return ;
703+ }
704+
664705 double gs = SimConnect . ReadSimVar ( "GPS GROUND SPEED" , "Meters per second" ) * 0.00002966071308045356 ;
665706 if ( ! pushRunning && gs > 1.5 && ( SimConnect . ReadLvar ( "A_FC_THROTTLE_LEFT_INPUT" ) > 2.05 || SimConnect . ReadLvar ( "A_FC_THROTTLE_RIGHT_INPUT" ) > 2.05 ) )
666707 {
@@ -674,6 +715,7 @@ private void RunDepatureServices()
674715 {
675716 Logger . Log ( LogLevel . Information , "GsxController:RunDepatureServices" , $ "Push-Back Service is active") ;
676717 pushRunning = true ;
718+ Interval = 100 ;
677719 }
678720
679721 if ( pushRunning )
@@ -682,17 +724,28 @@ private void RunDepatureServices()
682724 if ( gsxPinInserted && ! pushNwsDisco )
683725 {
684726 Logger . Log ( LogLevel . Information , "GsxController:RunDepatureServices" , $ "By Pass Pin inserted") ;
685- FenixController . PushStart ( ) ;
727+ SimConnect . WriteLvar ( "FSDT_VAR_Frozen" , 1 ) ;
686728 pushNwsDisco = true ;
687729 }
730+ else if ( gsxPinInserted && pushNwsDisco )
731+ {
732+ bool isFrozen = SimConnect . ReadLvar ( "FSDT_VAR_Frozen" ) == 1 ;
733+
734+ if ( ! isFrozen )
735+ {
736+ Logger . Log ( LogLevel . Debug , "GsxController:RunDepatureServices" , $ "Re-Freezing Plane") ;
737+ SimConnect . WriteLvar ( "FSDT_VAR_Frozen" , 1 ) ;
738+ }
739+ }
688740
689741 if ( ! gsxPinInserted && pushNwsDisco )
690742 {
691743 Logger . Log ( LogLevel . Information , "GsxController:RunDepatureServices" , $ "By Pass Pin removed") ;
692- FenixController . PushStop ( ) ;
744+ SimConnect . WriteLvar ( "FSDT_VAR_Frozen" , 0 ) ;
693745 pushNwsDisco = false ;
694746 pushRunning = false ;
695747 pushFinished = true ;
748+ Interval = 1000 ;
696749 }
697750 }
698751 }
@@ -845,6 +898,7 @@ private void OperatorSelection()
845898 {
846899 Logger . Log ( LogLevel . Information , "GsxController:OperatorSelection" , $ "Operator Selection active, choosing Option 1") ;
847900 MenuItem ( 1 ) ;
901+ operatorWasSelected = true ;
848902 }
849903 else
850904 Logger . Log ( LogLevel . Information , "GsxController:OperatorSelection" , $ "No Operator Selection needed") ;
@@ -860,21 +914,38 @@ private int IsOperatorSelectionActive()
860914 if ( lines . Length > 1 )
861915 {
862916 if ( ! string . IsNullOrEmpty ( lines [ 0 ] ) && ( lines [ 0 ] == "Select handling operator" || lines [ 0 ] == "Select catering operator" ) )
917+ {
918+ Logger . Log ( LogLevel . Debug , "GsxController:IsOperatorSelectionActive" , $ "Match found for operator Selection: '{ lines [ 0 ] } '") ;
863919 result = 1 ;
920+ }
864921 else if ( string . IsNullOrEmpty ( lines [ 0 ] ) )
922+ {
923+ Logger . Log ( LogLevel . Debug , "GsxController:IsOperatorSelectionActive" , $ "Line is empty! Lines total: { lines . Length } ") ;
865924 result = - 1 ;
925+ }
866926 else
927+ {
928+ Logger . Log ( LogLevel . Debug , "GsxController:IsOperatorSelectionActive" , $ "No Match found for operator Selection: '{ lines [ 0 ] } '") ;
867929 result = 0 ;
930+ }
931+ }
932+ else
933+ {
934+ Logger . Log ( LogLevel . Debug , "GsxController:IsOperatorSelectionActive" , $ "Menu Lines not above 1 ({ lines . Length } )") ;
868935 }
869936 }
937+ else
938+ {
939+ Logger . Log ( LogLevel . Debug , "GsxController:IsOperatorSelectionActive" , $ "Menu File was empty") ;
940+ }
870941
871942 return result ;
872943 }
873944
874945 private void MenuOpen ( )
875946 {
876-
877947 SimConnect . IsGsxMenuReady = false ;
948+ Logger . Log ( LogLevel . Debug , "GsxController:MenuOpen" , $ "Opening GSX Menu") ;
878949 SimConnect . WriteLvar ( "FSDT_GSX_MENU_OPEN" , 1 ) ;
879950 }
880951
@@ -883,13 +954,15 @@ private void MenuItem(int index, bool waitForMenu = true)
883954 if ( waitForMenu )
884955 MenuWaitReady ( ) ;
885956 SimConnect . IsGsxMenuReady = false ;
957+ Logger . Log ( LogLevel . Debug , "GsxController:MenuItem" , $ "Selecting Menu Option { index } (L-Var Value { index - 1 } )") ;
886958 SimConnect . WriteLvar ( "FSDT_GSX_MENU_CHOICE" , index - 1 ) ;
887959 }
888960
889961 private void MenuWaitReady ( )
890962 {
891963 int counter = 0 ;
892964 while ( ! SimConnect . IsGsxMenuReady && counter < 1000 ) { Thread . Sleep ( 100 ) ; counter ++ ; }
965+ Logger . Log ( LogLevel . Debug , "GsxController:MenuWaitReady" , $ "Wait ended after { counter * 100 } ms") ;
893966 }
894967 }
895968}
0 commit comments