# $Header: https://oberon.oapd.inaf.it/shins/trunk/shins/src/scripts/templates/tpl/SHARKNIR_gen_tiptilt_init.py 3984 2022-07-05 19:31:56Z depa $

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


class SHARKNIR_gen_tiptilt_init(SHINSApp):
    
    @exception.handler_for_run
    def run(self, ins_s=None, det_s=None, tel_s=None, rtc_s=None, **kwargs):
        '''Initialize and start the RTC BCU, not the real-time tiptilt loop
        input parameter is rtc_s
        '''
        
        logger.info(__name__)
        logger.info('Test tiptilt system initialize ... ')

        self.status = uvars.EXIT_SUCCESS
        obsController = self.obsController

        ########################
        # REAL-TIME RTCTT INIT #
        ########################
        if self.paragraph("RTC INIT"):
        
            logger.debug("Enumerating RTC setup")
            for element, value in rtc_s.items():
                logger.debug("Element : % 20s  -  Value % 20s    " % (element, value))
            
            ########################
            # REAL-TIME RTCTT INIT #
            ########################
            
            # if not(rtcInit):
            logger.warning("RTCTT is not initialized. RTCTT init. wait ~30s")
            self.status = obsController.RTCTTInit(rtc_s)
            logger.debug(self.status)
            ufun.error_handler(self.status, "RTCTTIsInit")

        # #########################
        # # SETUP REAL-TIME RTCTT #
        # #########################
        # if self.paragraph("RTC SETUP AND START"):

            # logger.info("RTCTT setup")
            # self.status = obsController.RTCTTSetup()
            # logger.debug(self.status)
            # ufun.error_handler(self.status, "RTCTTSetup")
            
            # #########################
            # # START REAL-TIME RTCTT #
            # #########################
            
            # logger.info("RTCTT start")
            # self.status = obsController.RTCTTStart()
            # logger.debug(self.status)
            # ufun.error_handler(self.status, "RTCTTStart")

