# $Header: https://oberon.oapd.inaf.it/shins/trunk/shins/src/scripts/templates/tpl/testOB_tiptilt_close_loop.py 3790 2022-01-17 19:18:52Z depa $

import sys
import Ice
from util.shinsLogger import logger
from util import variables as uvars
from util import functions as ufun
from util import exception
from shinsapp import SHINSApp

class SHARKNIR_gen_tiptilt_gain(SHINSApp):

    @exception.handler_for_run
    def run(self, ins_s=None, det_s=None, tel_s=None, rtc_s=None, **kwargs):
        '''Close tiptilt loop
        '''

        logger.info(__name__)
        logger.info('Taking dark for TT ... ')

        self.status = uvars.EXIT_SUCCESS
        obsController = self.obsController
        
        ######################
        # Change Gain on RTC #
        ######################
        if self.paragraph("Change Gain on RTC"):
        
            logger.debug("Enumerating RTC setup")
            for element, value in rtc_s.items():
                logger.debug("Element : % 20s  -  Value % 20s    " % (element, value))
            
            logger.info("TT update gain")
            self.status = obsController.RTCTTExecuteSetup(rtc_s)
            ufun.error_handler(self.status, "RTCTTTeccamExpose")
            logger.info("TT update gain... DONE.")
