# $Header: https://oberon.oapd.inaf.it/shins/trunk/shins/src/scripts/templates/tpl/SHARKNIR_gen_tiptilt_shutdown.py 3828 2022-02-25 17:46:12Z 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_shutdown(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('Tiptilt system shutdown ... ')

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


        ############################
        # REAL-TIME RTCTT SHUTDOWN #
        ############################
        logger.info("Calling RTC setup")

        if self.paragraph("RTC SHUTDOWN"):
        
            logger.debug("Enumerating RTC setup")
            for element, value in rtc_s.items():
                logger.debug("Element : % 20s  -  Value % 20s    " % (element, value))
            
            ############################
            # REAL-TIME RTCTT SHUTDOWN #
            ############################
            
            logger.warning("Send shutdown command")
            status = obsController.RTCTTSendCameraCommand("shutdown")
            logger.debug(status)
            ufun.error_handler(status, "RTCTTSendCameraCommand")

