# $Header: https://oberon.oapd.inaf.it/shins/trunk/shins/src/scripts/templates/tpl/testOB_tcs_OffsetPointing.py 3808 2022-01-25 12:43:04Z depa $

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

# cp /home/shinsmgr/SHINS/trunk/shins/src/scripts/templates/tpl/testOB_tcs_OffsetPointing.py /opt/tan/lib/python/site-packages/shins/templates/tpl/

class testOB_tcs_OffsetPointing(SHINSApp):

    @exception.handler_for_run
    def run(self, ins_s=None, det_s=None, tel_s=None, rtc_s=None, **kwargs):
        '''Try some tcs command
        '''
        logger.info(__name__)

        self.status = uvars.EXIT_SUCCESS
            
        obsController = self.obsController
        
        ###############################################
        ############### OFFSET POINTING ###############
        ###############################################
        
        # tel_s = {"OFFSETX"         :"0.0",              # in radians
        #          "OFFSETY"         :"0.000024",         # in radians
        #          # "OFFSETY"         :"-0.008726646",     # in radians
        #          "CoordinateSystem":"AZALT",            # "RADEC", "AZALT", "DETXY", "GALACTIC" ("AZALT" not supported on our TCS sim)
        #          "MoveType"        :"ABS",              # "REL", "RELCS", "ABS", "ABSCS"
        #          "TelescopeSide"   :"LEFT",
        #          "BinocularFlag"    : "OFF"
        #          }

        #########################
        # SHOW INSTRUMENT SETUP #
        #########################
        
        logger.info("Telescope Setup")
        for element, value in tel_s.items():
            logger.debug("{:>22} : {:<22}".format(element, str(value)))
            
        print("Start Offset Pointing ....")
        # asyncres = obsController.begin_OffsetPointing(tel_s)
        # status = obsController.end_OffsetPointing(asyncres)
        self.status = obsController.OffsetPointing(tel_s)
        ufun.error_handler(self.status, "OffsetPointing")
    

