module CTdsSwingEnum
    use OperationScenariosModule
    use SimulationVariables
    use UnitySignalsModule
    implicit none
    contains
    
    subroutine Evaluate_TdsSwing()
        implicit none
        
        if (data%Configuration%Hoisting%DriveType == TopDrive_DriveType) then
#ifdef OST
            print*, 'Evaluate_TdsSwing=TopDrive'
#endif


            !TOPDRIVE-CODE=37
            if (Get_SwingDrillPermission() .and.&
                Get_TdsSwing() == TDS_SWING_OFF_END .and.&
                Get_FillMouseHoleLed() == .false. .and.&
                data%EquipmentControl%TopDrivePanel%TopDriveLinkTiltState == TdsLinkTilt_DRILL) then
            
                call Set_TdsSwing(TDS_SWING_DRILL_BEGIN)
                data%EquipmentControl%TopDrivePanel%TopDriveLinkTiltLed = LED_ON
                return
            end if
            
                
                
            !TOPDRIVE-CODE=38
            if (Get_SwingTiltPermission() .and.&
                Get_TdsSwing() == TDS_SWING_TILT_END .and.&
                data%EquipmentControl%TopDrivePanel%TopDriveLinkTiltState == TdsLinkTilt_TILT) then
            
                call Set_TdsSwing(TDS_SWING_TILT_BEGIN)
                data%EquipmentControl%TopDrivePanel%TopDriveLinkTiltLed = LED_ON
                return
            end if    
                
                
                
            !TOPDRIVE-CODE=39
            if (Get_SwingOffPermission() .and.&
                Get_TdsConnectionModes() == TDS_CONNECTION_NOTHING .and.&
                Get_TdsSwing() == TDS_SWING_OFF_END .and.&
                data%EquipmentControl%TopDrivePanel%TopDriveLinkTiltState == TdsLinkTilt_OFF) then
            
                call Set_TdsSwing(TDS_SWING_OFF_BEGIN)
                data%EquipmentControl%TopDrivePanel%TopDriveLinkTiltLed = LED_ON
                return
            end if     
                
                
                
               
                
            !TOPDRIVE-CODE=40
            if (Get_SwingTiltPermission() .and.&
                Get_TdsElevatorModes() == TDS_ELEVATOR_CONNECTION_NOTHING .and.&
                Get_TdsSwing() == TDS_SWING_OFF_END .and.&
                data%EquipmentControl%TopDrivePanel%TopDriveLinkTiltState == TdsLinkTilt_TILT) then
            
                call Set_TdsSwing(TDS_SWING_TILT_BEGIN)
                data%EquipmentControl%TopDrivePanel%TopDriveLinkTiltLed = LED_ON
                return
            end if    
                
                
                
                
                
            !TOPDRIVE-CODE=41
            if (Get_SwingOffPermission() .and.&
                Get_TdsElevatorModes() == TDS_ELEVATOR_CONNECTION_NOTHING .and.&
                Get_TdsSwing() == TDS_SWING_TILT_END .and.&
                data%EquipmentControl%TopDrivePanel%TopDriveLinkTiltState == TdsLinkTilt_OFF) then
            
                call Set_TdsSwing(TDS_SWING_OFF_BEGIN)
                data%EquipmentControl%TopDrivePanel%TopDriveLinkTiltLed = LED_ON
                return
            end if  
                
                
                
                
                
            !TOPDRIVE-CODE=42
            if (Get_HookHeight() > (TL() + NFC() + data%State%OperationScenario%PL - data%State%OperationScenario%ECG) .and.&
                Get_SwingTiltPermission() .and.&
                Get_TdsElevatorModes() == TDS_ELEVATOR_CONNECTION_SINGLE .and.&
                Get_TdsSwing() == TDS_SWING_OFF_END .and.&
                data%EquipmentControl%TopDrivePanel%TopDriveLinkTiltState == TdsLinkTilt_TILT) then
            
                call Set_TdsSwing(TDS_SWING_TILT_BEGIN)
                data%EquipmentControl%TopDrivePanel%TopDriveLinkTiltLed = LED_ON
                return
            end if     
                
                
                
                
            !TOPDRIVE-CODE=43
            if (Get_HookHeight() > (TL() + NFC() + data%State%OperationScenario%PL - data%State%OperationScenario%ECG) .and.&
                Get_SwingOffPermission() .and.&
                Get_TdsElevatorModes() == TDS_ELEVATOR_CONNECTION_SINGLE .and.&
                Get_TdsSwing() == TDS_SWING_TILT_END .and.&
                data%EquipmentControl%TopDrivePanel%TopDriveLinkTiltState == TdsLinkTilt_OFF) then
            
                call Set_TdsSwing(TDS_SWING_OFF_BEGIN)
                data%EquipmentControl%TopDrivePanel%TopDriveLinkTiltLed = LED_ON
                return
            end if    
                
                

        endif
        
        
        
        
        
        
        
        
        
        
        
        
!        if (DriveType == Kelly_DriveType) then
!#ifdef OST
!            print*, 'Evaluate_TdsSwing=Kelly'
!#endif
!        endif
        
    end subroutine
    
    subroutine Subscribe_TdsSwing()
        use CDrillingConsoleVariables
    use SimulationVariables
    use SimulationVariables
        implicit none
    end subroutine
    
end module CTdsSwingEnum