# -*- coding: utf-8 -*-
# $Header: https://oberon.oapd.inaf.it/shins/trunk/shins/src/scripts/templates/SHINS_SW_TEST/SHINS_TEST_DEBUG.py 3724 2021-10-15 14:26:48Z laud $


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
import Basda
import Ice
import pyds9
import time

from astropy.time import Time, TimeDelta

# cp /home/shinsmgr/shins/src/scripts/templates/SHINS_SW_TEST/SHINS_TEST_DEBUG.py /opt/tan/lib/python/site-packages/shins/templates/SHINS_SW_TEST
# scp /home/shinsmgr/shins/src/scripts/templates/SHINS_SW_TEST/SHINS_TEST_DEBUG.py shinsmgr@sharknirws.oapd.inaf.it:/opt/tan/lib/python/site-packages/shins/templates/SHINS_SW_TEST

scicam_timing = {'Full_Image':4.2783, 'Center':2.6751, 'Bottom':1.0719, 'Top':1.0719, '256x256':0.2745, '128x128':0.0718, '1000x1000':4.0481, 'coro_stripe':0.1283}
scicam_size = {'Full_Image':2048*2048, 'Center':2048*1280, 'Bottom':2048*512, 'Top':2048*512, '256x256':257*257, '128x128':129*129, '1000x1000':1001*1001, 'coro_stripe':2048*60}

class SHINS_TEST_DEBUG_App(SHINSApp):
    def run(self, ins_s=None, det_s=None, tel_s=None, rtc_s=None, **kwargs):
        '''template for log INDI messages
        '''
        #logger.info(__name__)

        self.status = uvars.EXIT_SUCCESS
        lsFitsFilename = []
        units_s = {}
        det_s = {}
        ErrorCounter = 0
        TEST = 0
        if(kwargs and kwargs["test_s"]):
            TEST = eval(kwargs["test_s"])
            logger.info("TEST = %d" % TEST)
        try:
            obsController = self.obsController

            ############################################################
            ######################## Debug Test ########################
            ############################################################
            obsController.sashaGetIndiMsges({"FTEST" : "3", "SEPARATOR" : "Debug Test"})
            logger.info("##########################################")
            logger.info("################ DEBUG TEST ##############")
            logger.info("##########################################")
            if TEST == 0:
                ######## TEST 4: Emergency Abort #########
                logger.info("############### TEST 4: Replace calunitCtrl ##############")
                obsController.sashaGetIndiMsges({"FTEST" : "3", "SEPARATOR" : "Emergency Abort"})
                obsController.emergencyAbortAll()
            elif TEST == 3:
                ########## TEST 4: CAL FIBER Safe moving to Safe ###########
                logger.info("########## TEST 4: CAL FIBER Safe moving to Safe ###########")
                obsController.sashaGetIndiMsges({"FTEST" : "3", "SEPARATOR" : "TEST 4 CAL FIBER Safe moving to Safe"})
                det_s.clear()
                det_s["CORO_SLIT_W"] = "GAUSS"
                det_s["APODIZER_W"] = "SP1_APO"
                det_s["CAL_FIBER_DEP"] = "FOCUS_IN"
                logger.info("Moving CORO_SLIT_W to %s" % det_s["CORO_SLIT_W"])
                logger.info("Moving APODIZER_W to %s" % det_s["APODIZER_W"])
                logger.info("Moving CAL_FIBER_DEP to %s" % det_s["CAL_FIBER_DEP"])
                var = input("Press 1 and Enter To Continue...")
                if var == 1:
                    async_result = obsController.begin_setupInstrument(det_s)
                    self.status = obsController.end_setupInstrument(async_result)
                    if(self.status == uvars.EXIT_FAILURE):
                        logger.error("Error in TEST 4")
                    ufun.error_handler(self.status, "setupInstrument")


                ######## TEST 5: CAL FIBER Moving to dangerous pos #########
                logger.info("######## TEST 5: CAL FIBER Moving to dangerous pos #########")
                obsController.sashaGetIndiMsges({"FTEST" : "3", "SEPARATOR" : "TEST 5: CAL FIBER Moving to dangerous pos"})
                det_s.clear()
                det_s["CORO_SLIT_W"] = "SLIT2"
                det_s["APODIZER_W"] = "HOLE"
                det_s["SCI_FILT_W2"] = "R#-3000."
                det_s["CAL_FIBER_DEP"] = "R#-8000"
                logger.info("Moving CORO_SLIT_W to %s" % det_s["CORO_SLIT_W"])
                logger.info("Moving APODIZER_W to %s" % det_s["APODIZER_W"])
                logger.info("Moving CAL_FIBER_DEP to %s" % det_s["CAL_FIBER_DEP"])
                logger.info("Moving SCI_FILT_W2 to %s" % det_s["SCI_FILT_W2"])
                var = input("Press 1 and Enter To Continue...")
                if var == 1:
                    async_result = obsController.begin_setupInstrument(det_s)
                    self.status = obsController.end_setupInstrument(async_result)
                    if(self.status == uvars.EXIT_FAILURE):
                        logger.error("Error in TEST 5")
                    ufun.error_handler(self.status, "setupInstrument")
            elif TEST == 4:
                ######## TEST 4: replace calunitCtrl #########
                logger.info("############### TEST 4: Replace calunitCtrl ##############")
                obsController.sashaGetIndiMsges({"FTEST" : "3", "SEPARATOR" : "TEST 4: Replace calunitCtrl Start"})
                obsController.sashaGetIndiMsges({"FTEST" : "4", "SEPARATOR" : "TEST 4: Replace calunitCtrl"})
                obsController.sashaGetIndiMsges({"FTEST" : "4", "SEPARATOR" : "TEST 4: Replace calunitCtrl End"})
            elif TEST == 5:
                rtc_s = {}
                rtc_s["TTCAMCMD"] = "snake blm_en"
                logger.info("Sending command to camera : \"%s\"" % rtc_s["TTCAMCMD"])
                strCommand = rtc_s["TTCAMCMD"]
                self.status, strReply = obsController.RTCTTSendCameraCommand(strCommand)
                logger.info("Camera reply: {:s}".format(strReply))
                rtc_s["TTCAMCMD"] = "temperatures"
                logger.info("Sending command to camera : \"%s\"" % rtc_s["TTCAMCMD"])
                strCommand = rtc_s["TTCAMCMD"]
                self.status, strReply = obsController.RTCTTSendCameraCommand(strCommand)
                logger.info("Camera reply: {:s}".format(strReply))
                rtc_s["TTCAMCMD"] = "cropping"
                logger.info("Sending command to camera : \"%s\"" % rtc_s["TTCAMCMD"])
                strCommand = rtc_s["TTCAMCMD"]
                self.status, strReply = obsController.RTCTTSendCameraCommand(strCommand)
                logger.info("Camera reply: {:s}".format(strReply))
                rtc_s["TTCAMCMD"] = "cropping columns"
                logger.info("Sending command to camera : \"%s\"" % rtc_s["TTCAMCMD"])
                strCommand = rtc_s["TTCAMCMD"]
                self.status, strReply = obsController.RTCTTSendCameraCommand(strCommand)
                logger.info("Camera reply: {:s}".format(strReply))
                if strReply == "":
                    self.status = uvars.EXIT_FAILURE
                ufun.error_handler(self.status, "RTCTTSendCameraCommand")
            elif TEST == 51:
                rtc_s = {}
                rtc_s["TTCAMCMD"] = "set tint 0.000994919"
                logger.info("Sending command to camera : \"%s\"" % rtc_s["TTCAMCMD"])
                strCommand = rtc_s["TTCAMCMD"]
                self.status, strReply = obsController.RTCTTSendCameraCommand(strCommand)
                logger.info("Camera reply: {:s}".format(strReply))
                if strReply == "":
                    self.status = uvars.EXIT_FAILURE
                ufun.error_handler(self.status, "RTCTTSendCameraCommand")
            elif TEST == 52:
                # tester.py -t SHINS_TEST_DEBUG --targs 52 -a1 "exec httpserver start"
                # tester.py -t SHINS_TEST_DEBUG --targs 52 -a1 shutdown
                rtc_s = {}
                rtc_s["TTCAMCMD"] = "set tint 0.000994919"
                if(kwargs and kwargs["test_s1"]):
                    rtc_s["TTCAMCMD"] = kwargs["test_s1"]
                    logger.info("TTCAMCMD = %s" % kwargs["test_s1"])
                logger.info("Sending command to camera : \"%s\"" % rtc_s["TTCAMCMD"])
                strCommand = rtc_s["TTCAMCMD"]
                self.status, strReply = obsController.RTCTTSendCameraCommand(strCommand)
                logger.info("Camera reply: {:s}".format(strReply))
                if strReply == "":
                    self.status = uvars.EXIT_FAILURE
                ufun.error_handler(self.status, "RTCTTSendCameraCommand")
            elif TEST == 6:
                # tester.py -t SHINS_TEST_DEBUG --targs 6 -a1 tttesttime -a2 ttdiagdecimation -a3 ttpixeldecimation
                logger.info("Save Teccam Image : a1->TTTESTTIME a2->TTDIAGDECIMATION a3->TTPIXELDECIMATION")
                # rtc_s = {"TTDIAGENABLED":"true", "TTDIAGDECIMATION":"0", "TTPIXELENABLED":"1", "TTPIXELDECIMATION":"50", "TTTESTTIME":"2000000", "TTLOOPENABLED":"false"}
                rtc_s = {}
                rtc_s["TTDIAGENABLED"] = "true" # or "1"
                rtc_s["TTDIAGDECIMATION"] = "0"
                rtc_s["TTPIXELENABLED"] = "true"
                rtc_s["TTPIXELDECIMATION"] = "50" # if 0 master diagnostic stops
                rtc_s["TTTESTTIME"] = "20000000"
                rtc_s["TTLOOPENABLED"] = "false"
                if(kwargs and kwargs["test_s1"]):
                    rtc_s["TTTESTTIME"] = kwargs["test_s1"]
                    logger.info("{TTTESTTIME : %s}" % (kwargs["test_s1"]))
                    if(kwargs["test_s2"]):
                        rtc_s["TTDIAGDECIMATION"]=kwargs["test_s2"]
                        logger.info("{TTDIAGDECIMATION : %s}" % (kwargs["test_s2"]))
                        if(kwargs["test_s3"]):
                            rtc_s["TTPIXELDECIMATION"] = kwargs["test_s3"]
                            logger.info("{TTPIXELDECIMATION : %s}" % (kwargs["test_s3"]))

                self.status, result_file = obsController.RTCTTTeccamExpose(rtc_s)
                logger.info("Saved file : {:s}".format(result_file))
                ufun.error_handler(self.status, "RTCTTTeccamExpose")
            elif TEST == 61:
                # tester.py -t SHINS_TEST_DEBUG --targs 61 -a1 1000000
                logger.info("Save Teccam Image as bias: a1->TTTESTTIME a2->TTDIAGDECIMATION a3->TTPIXELDECIMATION")
                rtc_s = {}
                rtc_s["TTDIAGENABLED"] = "true" # or "1"
                rtc_s["TTDIAGDECIMATION"] = "0"
                rtc_s["TTPIXELENABLED"] = "1"
                rtc_s["TTPIXELDECIMATION"] = "0" # if 0 master diagnostic stops
                rtc_s["TTLOOPENABLED"] = "false"
                rtc_s["TTSAVEASBIAS"] = "true"
                rtc_s["TTTESTTIME"] = "7000000"
                if(kwargs and kwargs["test_s1"]):
                    rtc_s["TTTESTTIME"] = kwargs["test_s1"]
                    logger.info("{TTTESTTIME : %s}" % (kwargs["test_s1"]))
                    if(kwargs["test_s2"]):
                        rtc_s["TTDIAGDECIMATION"]=kwargs["test_s2"]
                        logger.info("{TTDIAGDECIMATION : %s}" % (kwargs["test_s2"]))
                        if(kwargs["test_s3"]):
                            rtc_s["TTPIXELDECIMATION"] = kwargs["test_s3"]
                            logger.info("{TTPIXELDECIMATION : %s}" % (kwargs["test_s3"]))
                #self.status = obsController.RTCTTConfigCamera(rtc_s)
                #ufun.error_handler(self.status, "RTCTTConfigCamera")

                self.status, result_file = obsController.RTCTTTeccamExpose(rtc_s)
                logger.info("Saved file : {:s}".format(result_file))
                ufun.error_handler(self.status, "RTCTTTeccamExpose")
            elif TEST == 62:
                # tester.py -t SHINS_TEST_DEBUG --targs 62 -a1 1000000
                logger.info("Save Teccam Image as bias and load it to RTC: a1->TTTESTTIME a2->TTDIAGDECIMATION a3->TTPIXELDECIMATION")
                rtc_s = {}
                rtc_s["TTDIAGENABLED"] = "true" # or "1"
                rtc_s["TTDIAGDECIMATION"] = "0"
                rtc_s["TTPIXELENABLED"] = "1"
                rtc_s["TTPIXELDECIMATION"] = "0" # if 0 master diagnostic stops
                rtc_s["TTLOOPENABLED"] = "false"
                rtc_s["TTSAVEASBIAS"] = "true"
                rtc_s["TTUPDATEBIAS"] = "true"
                rtc_s["TTTESTTIME"] = "1000000"
                if(kwargs and kwargs["test_s1"]):
                    rtc_s["TTTESTTIME"] = kwargs["test_s1"]
                    logger.info("{TTTESTTIME : %s}" % (kwargs["test_s1"]))
                    if(kwargs["test_s2"]):
                        rtc_s["TTDIAGDECIMATION"]=kwargs["test_s2"]
                        logger.info("{TTDIAGDECIMATION : %s}" % (kwargs["test_s2"]))
                        if(kwargs["test_s3"]):
                            rtc_s["TTPIXELDECIMATION"] = kwargs["test_s3"]
                            logger.info("{TTPIXELDECIMATION : %s}" % (kwargs["test_s3"]))

                self.status, result_file = obsController.RTCTTTeccamExpose(rtc_s)
                logger.info("Saved file : {:s}".format(result_file))
                ufun.error_handler(self.status, "RTCTTTeccamExpose")
            elif TEST == 7:
                # tester.py -t SHINS_TEST_DEBUG --targs 7
                rtc_s = {}
                rtc_s["TTDIAGENABLED"] = "true" # or "1"
                rtc_s["TTDIAGDECIMATION"] = "9"
                rtc_s["TTPIXELENABLED"] = "1"
                rtc_s["TTPIXELDECIMATION"] = "9"
                rtc_s["TTDIAGRECORDIPV4"] = "192.168.61.113"
                rtc_s["TTDIAGRECORDMAC"] = "4C:D9:8F:A0:22:44" # "4C:D9:8F:A0:22:43"
                rtc_s["TTDIAGRECORDPORT"] = "8000"
                rtc_s["TTMASTERDECIMATION"] = "0"
                rtc_s["TTJUMBOFRAMESENABLED"] = "false" # or "0"
                rtc_s["TTMASTERDECENABLED"] = "true"
                self.status = obsController.RTCTTEnableDiagnostic(rtc_s)
                ufun.error_handler(self.status, "RTCTTEnableDiagnostic")
            elif TEST == 8:
                rtc_s = {}
                self.status = obsController.RTCTTSetCentroidPos(0.01, -0.01)
                ufun.error_handler(self.status, "RTCTTSetCentroidPos")
            elif TEST == 9:
                rtc_s = {}
                self.status = obsController.RTCTTModeUpload([0.01, -0.01])
                ufun.error_handler(self.status, "RTCTTModeUpload")
            elif TEST == 10:
                rtc_s = {}
                rtc_s["TTDOWNLOADDSPCODE"] = "true"
                if(kwargs and kwargs["test_s1"]):
                    rtc_s["TTDOWNLOADDSPCODE"] = kwargs["test_s1"]

                rtc_s["TTM2CFILE"] = "20220603-Zernike-FullPupil-Arcetri-1u-rms-4rtc.dat" # "ALPAO97-M2C_matrix.fits"
                rtc_s["TTACTUATORMAPFILE"] = "BAX479-DM97-map.dat"
                rtc_s["TTACTUATORSIGNMAPFILE"] = "BAX479-DM97-sign.dat"
                rtc_s["TTBIASFILE"] = "dark64x64_1000Hz+20deg_14_02_22.dat"
                rtc_s["TTCAMTINT"] = "0.000994919"
                rtc_s["TTCENTROIDGAINX"] = "-4.249796"
                rtc_s["TTCENTROIDGAINY"] = "3.7651188"
                rtc_s["TTCENTROIDORIGX"] = "-0.0000"
                rtc_s["TTCENTROIDORIGY"] = "0.0000"
                rtc_s["TTDIAGDECIMATION"] = "0"
                rtc_s["TTDIAGENABLED"] = "true" # or "1"
                rtc_s["TTDIAGRECORDIPV4"] = "192.168.61.113"
                rtc_s["TTDIAGRECORDMAC"] = "4c:d9:8f:a0:22:44" # "4C:D9:8F:A0:22:43"
                rtc_s["TTDIAGRECORDPORT"] = "8001"
                rtc_s["TTDMFLATFILE"] = "dm_shape_2023-03-20-16-19-46_int_138b_90el_T-4C_0as.txt" #  "BAX479-DM97-FLAT.dat" # "FLAT_19_02_2021.dat"
                rtc_s["TTDMMAXPOWER"] = "10"
                rtc_s["TTDMOUTPUTENABLED"] = "1"
                rtc_s["TTFRAMERATE"] = "1000"
                rtc_s["TTHISTORYENABLED"] = "0"
                rtc_s["TTLOOPENABLED"] = "0"
                rtc_s["TTMASTERDECENABLED"] = "true"
                rtc_s["TTMAXCENTROIDVAL"] = "+1"
                rtc_s["TTMAXTTCOMMAND"] = "3"
                rtc_s["TTMINCENTROIDVAL"] = "-1"
                rtc_s["TTMINTHRESHOLD"] = "100"
                rtc_s["TTMINTTCOMMAND"] = "-3"
                rtc_s["TTNSLOPEPIXELS"] = "4096"
                rtc_s["TTPIXELDECIMATION"] = "49"
                rtc_s["TTPIXELENABLED"] = "1"
                rtc_s["TTPIXELGAINFILE"] = "flat_gain_64x64.dat"
                rtc_s["TTPIXELGAINMODE"] = "FLATGAIN" # POINTGAIN FLATGAIN FILEGAIN
                rtc_s["TTRTCMDENABLED"] = "0"
                rtc_s["TTTIMEHISTLEN"] = "50000"
                rtc_s["TTTIMEHISTORYFILE"] = "TimeHistory.dat"
                rtc_s["TTWINCOLS"] = "64"
                rtc_s["TTWINCOORDX"] = "224"
                rtc_s["TTWINCOORDY"] = "212"
                rtc_s["TTWINROWS"] = "64"
                # VULTUS
                # rtc_s["TTDIAGRECORDIPV4"] = "193.206.241.172"
                # rtc_s["TTDIAGRECORDMAC"] = "00:0C:29:5D:DC:81"

                # rtc_s["TTRTCMDENABLED"] = 0

                ########################
                # REAL-TIME RTCTT INIT #
                ########################
                status = obsController.RTCTTInit(rtc_s)
                logger.debug(status)
                ufun.error_handler(status, "RTCTTIsInit")
            elif TEST == 101: # zonal
                rtc_s = {}
                rtc_s["TTDOWNLOADDSPCODE"] = "true"
                if(kwargs and kwargs["test_s1"]):
                    rtc_s["TTDOWNLOADDSPCODE"] = kwargs["test_s1"]

                rtc_s["TTM2CFILE"] = "IDENTITY"
                rtc_s["TTACTUATORMAPFILE"] = "BAX479-DM97-map.dat"
                rtc_s["TTACTUATORSIGNMAPFILE"] = "BAX479-DM97-sign.dat"
                rtc_s["TTBIASFILE"] = "dark64x64_1000Hz+20deg_14_02_22.dat"
                rtc_s["TTCAMTINT"] = "0.000994919"
                rtc_s["TTCENTROIDGAINX"] = "-4.249796"
                rtc_s["TTCENTROIDGAINY"] = "3.7651188"
                rtc_s["TTCENTROIDORIGX"] = "-0.0000"
                rtc_s["TTCENTROIDORIGY"] = "0.0000"
                rtc_s["TTDIAGDECIMATION"] = "0"
                rtc_s["TTDIAGENABLED"] = "true" # or "1"
                rtc_s["TTDIAGRECORDIPV4"] = "192.168.61.113"
                rtc_s["TTDIAGRECORDMAC"] = "4c:d9:8f:a0:22:44" # "4C:D9:8F:A0:22:43"
                rtc_s["TTDIAGRECORDPORT"] = "8001"
                rtc_s["TTDMFLATFILE"] = "dm_command_2022-11-22-05-45-54_int_140b_90el_T1C.txt"
                rtc_s["TTDMMAXPOWER"] = "10"
                rtc_s["TTDMOUTPUTENABLED"] = "1"
                rtc_s["TTFRAMERATE"] = "1000"
                rtc_s["TTHISTORYENABLED"] = "0"
                rtc_s["TTLOOPENABLED"] = "0"
                rtc_s["TTMASTERDECENABLED"] = "true"
                rtc_s["TTMAXCENTROIDVAL"] = "+1"
                rtc_s["TTMAXTTCOMMAND"] = "3"
                rtc_s["TTMINCENTROIDVAL"] = "-1"
                rtc_s["TTMINTHRESHOLD"] = "100"
                rtc_s["TTMINTTCOMMAND"] = "-3"
                rtc_s["TTNSLOPEPIXELS"] = "4096"
                rtc_s["TTPIXELDECIMATION"] = "49"
                rtc_s["TTPIXELENABLED"] = "1"
                rtc_s["TTPIXELGAINFILE"] = "flat_gain_64x64.dat"
                rtc_s["TTPIXELGAINMODE"] = "FLATGAIN" # POINTGAIN FLATGAIN FILEGAIN
                rtc_s["TTRTCMDENABLED"] = "0"
                rtc_s["TTTIMEHISTLEN"] = "50000"
                rtc_s["TTTIMEHISTORYFILE"] = "TimeHistory.dat"
                rtc_s["TTWINCOLS"] = "64"
                rtc_s["TTWINCOORDX"] = "224"
                rtc_s["TTWINCOORDY"] = "212"
                rtc_s["TTWINROWS"] = "64"

                ########################
                # REAL-TIME RTCTT INIT #
                ########################
                status = obsController.RTCTTInit(rtc_s)
                logger.debug(status)
                ufun.error_handler(status, "RTCTTInit")
            elif TEST == 11:
                #########################
                # SETUP REAL-TIME RTCTT #
                #########################
                logger.info("RTCTT setup")
                status = obsController.RTCTTSetup()
                logger.debug(status)
                ufun.error_handler(status, "RTCTTSetup")

                #########################
                # START REAL-TIME RTCTT #
                #########################
                
                logger.info("RTCTT start")
                status = obsController.RTCTTStart()
                logger.debug(status)
                ufun.error_handler(status, "RTCTTStart")
            elif TEST == 106:
                rtc_s = {}
                rtc_s["TTM2CFILE"] = "20220603-Zernike-FullPupil-Arcetri-1u-rms-4rtc.dat" # "ALPAO97-M2C_matrix.fits"
                rtc_s["TTWINCOORDX"] = "0"
                rtc_s["TTWINCOORDY"] = "0"
                rtc_s["TTWINCOLS"] = "640"
                rtc_s["TTWINROWS"] = "512"
                rtc_s["TTFRAMERATE"] = "200"
                rtc_s["TTNSLOPEPIXELS"] = "16"
                rtc_s["TTBIASFILE"] = ""
                rtc_s["TTPIXELGAINFILE"] = ""
                rtc_s["TTCAMTINT"] = "0.004995574"
                rtc_s["TTPIXELGAINMODE"] = "FLATGAIN" # POINTGAIN FLATGAIN FILEGAIN

                logger.info("RTCTT Switch CCD Mode")
                status = obsController.RTCTTSwitchCcdMode(rtc_s)
                logger.debug(status)
                ufun.error_handler(status, "RTCTTSwitchCcdMode")
            elif TEST == 107:
                rtc_s = {}
                rtc_s["TTWINCOORDX"] = "224"
                rtc_s["TTWINCOORDY"] = "200"
                rtc_s["TTWINCOLS"] = "96"
                rtc_s["TTWINROWS"] = "84"
                rtc_s["TTFRAMERATE"] = "1000"
                rtc_s["TTNSLOPEPIXELS"] = "8064"
                rtc_s["TTBIASFILE"] = "2022-02-20-00-14-24_PixelBias_19.9°C_1000Hz-096x084.dat"
                rtc_s["TTPIXELGAINFILE"] = "flat_gain_96x84.dat"
                rtc_s["TTCAMTINT"] = "0.000994919"

                logger.info("RTCTT Switch CCD Mode")
                status = obsController.RTCTTSwitchCcdMode(rtc_s)
                logger.debug(status)
                ufun.error_handler(status, "RTCTTSwitchCcdMode")
            elif TEST == 108: # ZONAL
                rtc_s = {}
                rtc_s["TTWINCOORDX"] = "64"
                rtc_s["TTWINCOORDY"] = "84"
                rtc_s["TTWINCOLS"] = "320"
                rtc_s["TTWINROWS"] = "256"
                rtc_s["TTFRAMERATE"] = "200"
                rtc_s["TTNSLOPEPIXELS"] = "16"
                rtc_s["TTBIASFILE"] = ""
                rtc_s["TTPIXELGAINFILE"] = "flat_gain_320x256.dat"
                rtc_s["TTCAMTINT"] = "0.004995574"

                logger.info("RTCTT Switch CCD Mode")
                status = obsController.RTCTTSwitchCcdMode(rtc_s)
                logger.debug(status)
                ufun.error_handler(status, "RTCTTSwitchCcdMode")
            elif TEST == 109:
                rtc_s = {}
                rtc_s["TTM2CFILE"] = "20220603-Zernike-FullPupil-Arcetri-1u-rms-4rtc.dat" # "ALPAO97-M2C_matrix.fits"
                rtc_s["TTWINCOORDX"] = "224"
                rtc_s["TTWINCOORDY"] = "212"
                rtc_s["TTWINCOLS"] = "64"
                rtc_s["TTWINROWS"] = "64"
                rtc_s["TTFRAMERATE"] = "1000"
                rtc_s["TTNSLOPEPIXELS"] = "4096"
                rtc_s["TTBIASFILE"] = "2022-02-19-23-45-23_PixelBias_19.95°C_1000Hz-064x064.dat"
                rtc_s["TTPIXELGAINFILE"] = "flat_gain_64x64.dat"
                rtc_s["TTCAMTINT"] = "0.000994919"
                rtc_s["TTPIXELGAINMODE"] = "FLATGAIN" # POINTGAIN FLATGAIN FILEGAIN

                logger.info("RTCTT Switch CCD Mode")
                status = obsController.RTCTTSwitchCcdMode(rtc_s)
                logger.debug(status)
                ufun.error_handler(status, "RTCTTSwitchCcdMode")
            elif TEST == 110: # ZONAL
                rtc_s = {}
                rtc_s["TTWINCOORDX"] = "256"
                rtc_s["TTWINCOORDY"] = "228"
                rtc_s["TTWINCOLS"] = "32"
                rtc_s["TTWINROWS"] = "32"
                rtc_s["TTFRAMERATE"] = "1000"
                rtc_s["TTNSLOPEPIXELS"] = "1024"
                rtc_s["TTBIASFILE"] = "2022-02-19-23-55-43_PixelBias_19.80°C_1000Hz-032x032.dat"
                rtc_s["TTPIXELGAINFILE"] = "flat_gain_32x32.dat"
                rtc_s["TTCAMTINT"] = "0.000994919"

                logger.info("RTCTT Switch CCD Mode")
                status = obsController.RTCTTSwitchCcdMode(rtc_s)
                logger.debug(status)
                ufun.error_handler(status, "RTCTTSwitchCcdMode")
            elif TEST == 111: # ZONAL
                rtc_s = {}
                rtc_s["TTWINCOORDX"] = "96"
                rtc_s["TTWINCOORDY"] = "84"
                rtc_s["TTWINCOLS"] = "256"
                rtc_s["TTWINROWS"] = "256"
                rtc_s["TTFRAMERATE"] = "1000"
                rtc_s["TTNSLOPEPIXELS"] = "16" # to be set
                rtc_s["TTBIASFILE"] = ""
                rtc_s["TTPIXELGAINFILE"] = "flat_gain_256x256.dat"
                rtc_s["TTCAMTINT"] = "0.000994919"

                logger.info("RTCTT Switch CCD Mode")
                status = obsController.RTCTTSwitchCcdMode(rtc_s)
                logger.debug(status)
                ufun.error_handler(status, "RTCTTSwitchCcdMode")
            elif TEST == 112: # ZONAL
                rtc_s = {}
                rtc_s["TTWINCOORDX"] = "96"
                rtc_s["TTWINCOORDY"] = "84"
                rtc_s["TTWINCOLS"] = "288"
                rtc_s["TTWINROWS"] = "224"
                rtc_s["TTFRAMERATE"] = "1000"
                rtc_s["TTNSLOPEPIXELS"] = "16" # to be set
                rtc_s["TTBIASFILE"] = ""
                rtc_s["TTPIXELGAINFILE"] = "flat_gain_288x224.dat"
                rtc_s["TTCAMTINT"] = "0.000994919"

                logger.info("RTCTT Switch CCD Mode")
                status = obsController.RTCTTSwitchCcdMode(rtc_s)
                logger.debug(status)
                ufun.error_handler(status, "RTCTTSwitchCcdMode")
            elif TEST == 113: # MODAL
                rtc_s = {}
                rtc_s["TTWINCOORDX"] = "224"
                rtc_s["TTWINCOORDY"] = "212"
                rtc_s["TTWINCOLS"] = "64"
                rtc_s["TTWINROWS"] = "64"
                rtc_s["TTM2CFILE"] = "20220603-Zernike-FullPupil-Arcetri-1u-rms-4rtc.dat"
                rtc_s["TTDMFLATFILE"] = "dm_command_2022-11-22-05-45-54_int_140b_90el_T1C.txt" # "zeri.txt"
                rtc_s["TTBIASFILE"] = "dark64x64_1000Hz+20deg_14_02_22.dat"
                rtc_s["TTFRAMERATE"] = "1000"
                rtc_s["TTNSLOPEPIXELS"] = "4096"
                rtc_s["TTCAMTINT"] = "0.000994919"
                logger.info("RTCTT Switch CCD Mode")
                status = obsController.RTCTTSwitchCcdMode(rtc_s)
                logger.debug(status)
                ufun.error_handler(status, "RTCTTSwitchCcdMode")
            elif TEST == 114: # ZONAL
                rtc_s = {}
                rtc_s["TTWINCOORDX"] = "224"
                rtc_s["TTWINCOORDY"] = "212"
                rtc_s["TTWINCOLS"] = "64"
                rtc_s["TTWINROWS"] = "64"
                rtc_s["TTM2CFILE"] = "IDENTITY"
                rtc_s["TTDMFLATFILE"] = "dm_command_2022-11-22-05-45-54_int_140b_90el_T1C.txt" # "zeri.txt"
                rtc_s["TTBIASFILE"] = "dark64x64_1000Hz+20deg_14_02_22.dat"
                rtc_s["TTFRAMERATE"] = "1000"
                rtc_s["TTNSLOPEPIXELS"] = "4096"
                rtc_s["TTCAMTINT"] = "0.000994919"
                logger.info("RTCTT Switch CCD Mode")
                status = obsController.RTCTTSwitchCcdMode(rtc_s)
                logger.debug(status)
                ufun.error_handler(status, "RTCTTSwitchCcdMode")
            elif TEST == 115:
                rtc_s = {}
                rtc_s["TTM2CFILE"] = "20220603-Zernike-FullPupil-Arcetri-1u-rms-4rtc.dat"
                rtc_s["TTWINCOORDX"] = "64"
                rtc_s["TTWINCOORDY"] = "0"
                rtc_s["TTWINCOLS"] = "512"
                rtc_s["TTWINROWS"] = "512"
                rtc_s["TTFRAMERATE"] = "50"
                rtc_s["TTNSLOPEPIXELS"] = "16" # to be set
                rtc_s["TTBIASFILE"] = ""
##                rtc_s["TTPIXELGAINFILE"] = "flat_gain_256x256.dat"
                rtc_s["TTCAMTINT"] = "0.000994919"
                rtc_s["TTPIXELGAINMODE"] = "FLATGAIN" # POINTGAIN FLATGAIN FILEGAIN

                logger.info("RTCTT Switch CCD Mode")
                status = obsController.RTCTTSwitchCcdMode(rtc_s)
                logger.debug(status)
                ufun.error_handler(status, "RTCTTSwitchCcdMode")
            elif TEST == 14:
                # tester.py -t SHINS_TEST_DEBUG --targs 14 -a1 -0.44 -a2 -0.62
                rtc_s = {}
                logger.info("RTCTT Set Centroid Origin")
                centroidx = 0.0
                centroidy = 0.0
                if(kwargs and kwargs["test_s1"] and kwargs["test_s2"]):
                    centroidx = eval(kwargs["test_s1"])
                    centroidy = eval(kwargs["test_s2"])
                logger.info("Setting centroid origin to (%s, %s)" % (centroidx, centroidy))
                status = obsController.RTCTTSetCentroidPos(centroidx, centroidy)
                logger.debug(status)
                ufun.error_handler(status, "RTCTTSetCentroidPos")
            elif TEST == 15:
                obsController.osLogBanner("Successful")
            elif TEST == 16:
                #NGROUPS:NREADS:NDROPS
                rtc_s = {}
                ins_s = {"InstrumentMode":"TestF", "OBJECTNAME":"Test Fulvio", "NCOADDS":"1"}
                ins_s["NRESETS"] = "1"
                ins_s["NDIT"] = "1"
                ins_s["SAVE"] = "1"
                ins_s["READOUT"] = '128x128'
                counter = 0
                for readout in scicam_timing.keys():
                    counter = counter + 1
                    # if counter < 6:
                        # continue
                    # if counter == 7:
                        # break
                    ins_s["InstrumentMode"] = readout
                    ins_s["READOUT"] = readout
      #          for i in range(2, 3):
                    ins_s["NGROUPS"] = ("%d" % 1)
                    for j in range(1, 2):
                        ins_s["NREADS"] = ("%d" % j)
                        for k in range(4, 5):
                            ins_s["NDROPS"] = ("%d" % 12)
                            iG = eval(ins_s["NGROUPS"])
                            jR = eval(ins_s["NREADS"])
                            kD = eval(ins_s["NDROPS"])
                            lC = eval(ins_s["NCOADDS"])
                            ins_s["OBJECTNAME"] = ("Test %d:%d:%d" % (iG, jR, kD))
                            timing = (iG - 1)*(jR*lC + kD) + jR*lC
                            frame_size = 0
                            if ins_s["READOUT"] in scicam_timing.keys():
                                timing = timing*scicam_timing[ins_s["READOUT"]]
                                frame_size = scicam_size[ins_s["READOUT"]]
                            num_frames = iG*jR
                            if lC > 1 :
                                num_frames = num_frames*2
                            obsController.sashaSetup(ins_s)
                            obsController.sashaExpose(ins_s)
                            async_result = obsController.begin_sashaGetFitsFileSync(ins_s, ins_s["InstrumentMode"])
 #                           time.sleep(50)
 #                           obsController.emergencyAbortAll()
                            status, filename = obsController.end_sashaGetFitsFileSync(async_result)
                            logger.info("Saved file : %s" % filename)
                            logger.info("Esposed %s - NGROUPS:%d NREADS:%d NDROPS:%d;" % (readout, iG, jR, kD))
                            logger.info("timing:%3f; filesize expected:%d" % (timing, int((num_frames*frame_size + 2879)/2880)*2880 + 2880))
            elif TEST == 161:
                #NGROUPS:NREADS:NDROPS
                rtc_s = {}
                ins_s = {"InstrumentMode":"TestF", "OBJECTNAME":"Test Fulvio", "NCOADDS":"1"}
                ins_s["NRESETS"] = "1"
                ins_s["NDIT"] = "1"
                ins_s["SAVE"] = "1"
                for i in range(2, 3):
                    ins_s["NGROUPS"] = ("%d" % i)
                    for j in range(1, 2):
                        ins_s["NREADS"] = ("%d" % j)
                        for k in range(4, 5):
                            timing = 1 + (i - 1)*(j + k) + j
                            file_size = i*j
                            ins_s["OBJECTNAME"] = ("Test %d:%d:%d" % (i, j, k))
                            ins_s["NDROPS"] = ("%d" % k)
                            obsController.sashaSetup(ins_s)
                            obsController.sashaExpose(rtc_s)
                            async_result = obsController.begin_sashaGetFitsFileSync(rtc_s, ins_s["InstrumentMode"])
                            time.sleep(15)
                            obsController.emergencyAbortAll()
                            status, filename = obsController.end_sashaGetFitsFileSync(async_result)
                            logger.info("Saved file : %s" % filename)
                            logger.info("Esposed NGROUPS:%d NREADS:%d NDROPS:%d; timing:%d; filesize expected:%d" % (i, j, k, timing*4.2783, file_size*8*1048576 + 2880))
            elif TEST == 162:
                log_msg = "TEST %d : %s" % (TEST, "Double Sasha Expose")
                logger.info("######## %s #########" % log_msg)
                obsController.sashaGetIndiMsges({"FTEST" : "3", "SEPARATOR" : log_msg})
                #NGROUPS:NREADS:NDROPS
                rtc_s = {}
                ins_s = {"InstrumentMode":"TestF", "OBJECTNAME":"Test Fulvio", "NCOADDS":"1"}
                ins_s["NRESETS"] = "1"
                ins_s["NDIT"] = "1"
                ins_s["SAVE"] = "1"
                for i in range(2, 3):
                    ins_s["NGROUPS"] = ("%d" % i)
                    for j in range(1, 2):
                        ins_s["NREADS"] = ("%d" % j)
                        for k in range(4, 5):
                            timing = 1 + (i - 1)*(j + k) + j
                            file_size = i*j
                            ins_s["OBJECTNAME"] = ("Test %d:%d:%d" % (i, j, k))
                            ins_s["NDROPS"] = ("%d" % k)
                            obsController.sashaSetup(ins_s)
                            obsController.sashaExpose(rtc_s)
                            asyncRes = obsController.begin_sashaGetFitsFileSync(rtc_s, ins_s["InstrumentMode"])
                            time.sleep(15)
                            #obsController.emergencyAbortAll()
                            status, filename = obsController.end_sashaGetFitsFileSync(asyncRes)
                            logger.info("Saved file : %s" % filename)
                            asyncres = obsController.begin_sashaExpose(rtc_s)
                            obsController.end_sashaExpose(asyncres)
                            asyncRes2 = obsController.begin_sashaGetFitsFileSync(rtc_s, ins_s["InstrumentMode"])
                            status, filename = obsController.end_sashaGetFitsFileSync(asyncRes2)
                            logger.info("Saved file : %s" % filename)
                            logger.info("Esposed NGROUPS:%d NREADS:%d NDROPS:%d; timing:%d; filesize expected:%d" % (i, j, k, timing*4.2783, file_size*8*1048576 + 2880))
            elif TEST == 163:
                #NGROUPS:NREADS:NDROPS
                i = 1
                j = 15
                k = 0
                rtc_s = {}
                ins_s = {"InstrumentMode":"TestF", "OBJECTNAME":"Test Fulvio", "NCOADDS":"1"}
                ins_s["NRESETS"] = "1"
                ins_s["NDIT"] = "1"
                ins_s["SAVE"] = "1"
                ins_s["NGROUPS"] = ("%d" % i)
                ins_s["NREADS"] = ("%d" % j)
                ins_s["NDROPS"] = ("%d" % k)
                ins_s["OBJECTNAME"] = ("Test %d:%d:%d" % (i, j , k))
                
                timing = 1 + (i - 1)*(j + k) + j
                file_size = i*j
                obsController.sashaSetup(ins_s)
                obsController.sashaExpose(rtc_s)
                async_result = obsController.begin_sashaGetFitsFileSync(rtc_s, ins_s["InstrumentMode"])
                status, filename = obsController.end_sashaGetFitsFileSync(async_result)
                logger.info("Saved file : %s" % filename)
                logger.info("Esposed NGROUPS:%d NREADS:%d NDROPS:%d; timing:%d; filesize expected:%d" % (i, j, k, timing*4.2783, file_size*8*1048576 + 2880))
            elif TEST == 164:
                #NGROUPS:NREADS:NDROPS
                ins_s = {"InstrumentMode":"TestF", "OBJECTNAME":"Test Fulvio", "NCOADDS":"1"}
                ins_s["NREADS"] = "1"
                ins_s["NRESETS"] = "1"
                ins_s["NDIT"] = "1"
                ins_s["NGROUPS"] = "1"
                ins_s["NDROPS"] = "0"
                ins_s["SAVE"] = "1"
                ins_s["READOUT"] = 'Full_Image'
                status = obsController.sashaSetup(ins_s)
                status , file_name = obsController.sashaExpose(ins_s)
                logger.info("Saved file : %s" % file_name)
                ufun.error_handler(status, "sashaExpose")
            elif TEST == 165:
                #NGROUPS:NREADS:NDROPS
                # tester.py -t SHINS_TEST_DEBUG --targs 165 -a1 "{\"InstrumentMode\":\"TestF\", \"OBJECTNAME\":\"Test\", \"NCOADDS\":\"1\", \"NREADS\":\"1\", \"NRESETS\":\"1\", \"NDIT\":\"1\", \"NGROUPS\":\"1\", \"NDROPS\":\"0\", \"SAVE\":\"0\", \"READOUT\":\"128x128\"}"
                ins_s = {"InstrumentMode":"TestF", "OBJECTNAME":"Test", "NCOADDS":"1"}
                ins_s["NREADS"] = "1"
                ins_s["NRESETS"] = "1"
                ins_s["NDIT"] = "5"
                ins_s["NGROUPS"] = "2"
                ins_s["NDROPS"] = "0"
                ins_s["SAVE"] = "0"
                ins_s["READOUT"] = '128x128'
                if(kwargs and kwargs["test_s1"]):
                    ins_s = eval(kwargs["test_s1"])
                # ins_s["FREQUENCY"] = '250kHz'
#                adapter = self._ic.createObjectAdapter("")
#                cbPrx = CallbackPrx.uncheckedCast(adapter.addwithUUID(CallbackI()))
#                proxy = self._ic.stringToProxy("ObsControlAdapterSeq:default -p 10500")
#                proxy.ice_getCachedConnection().setAdapter(adapter)
#                proxy.addClient(cbPrx)
                status = obsController.sashaSetup(ins_s)
                status , file_name = obsController.sashaExpose()
                logger.info("Saved file : %s" % file_name)
                ufun.error_handler(status, "sashaExpose")
            elif TEST == 17:
                rtc_s = {}
                rtc_s["TTPIXELGAINFILE"] = "flat_gain_64x64.dat"
                status = obsController.RTCTTExecuteSetup(rtc_s)
                ufun.error_handler(status, "RTCTTExecuteSetup")
            elif TEST == 171:
                logger.info("######## TEST 171: Free Execute Setup one keyword #########")
                logger.info(" usage : tester.py -t SHINS_TEST_DEBUG --targs 171 -a1 KEYWORD -a2 VALUE")
                obsController.sashaGetIndiMsges({"FTEST" : "3", "SEPARATOR" : "TEST 171: Free Execute Setup"})
                rtc_s = {}
                if(kwargs and kwargs["test_s1"] and kwargs["test_s2"]):
                    rtc_s[kwargs["test_s1"]] = kwargs["test_s2"]
                    logger.info("{%s : %s}" % (kwargs["test_s1"], kwargs["test_s2"]))
                status = obsController.RTCTTExecuteSetup(rtc_s)
                ufun.error_handler(status, "RTCTTExecuteSetup")
            elif TEST == 18:
                logger.info("######## TEST 18: Load Bias on RTC #########")
                obsController.sashaGetIndiMsges({"FTEST" : "3", "SEPARATOR" : "TEST 18 : Load Bias on RTC"})
                rtc_s = {}
                rtc_s["TTBIASFILE"] = "2022-02-19-23-45-23_PixelBias_19.95°C_1000Hz-064x064.dat"
                if(kwargs and kwargs["test_s1"]):
                    rtc_s["TTBIASFILE"] = kwargs["test_s1"]
                logger.info("TTBIASFILE = %s" % rtc_s["TTBIASFILE"])
                status = obsController.RTCTTExecuteSetup(rtc_s)
                ufun.error_handler(status, "RTCTTExecuteSetup")
            elif TEST == 19:
                rtc_s = {}
                rtc_s["TTCAMTINT"] = "0.000994919"
                status = obsController.RTCTTExecuteSetup(rtc_s)
                ufun.error_handler(status, "RTCTTExecuteSetup")
            elif TEST == 20:
                ######## TEST 20: Wait Result #########
                logger.info("######## TEST 20: wait result #########")
                obsController.sashaGetIndiMsges({"FTEST" : "3", "SEPARATOR" : "TEST 20: Wait Result"})
                det_s.clear()
                det_s["INBEAM_DEP"] = "IN"
                logger.info("Moving INBEAM_DEP to %s" % det_s["INBEAM_DEP"])
                async_result = obsController.begin_setupInstrument(det_s)
                var = input("Press 1 and Enter To Continue...")
                if var == 1:
                    self.status = obsController.end_setupInstrument(async_result)
                if(self.status == uvars.EXIT_FAILURE):
                    logger.error("Error in TEST 20")
                ufun.error_handler(self.status, "setupInstrument")
            elif TEST == 21:
                ######## TEST 20: Wait Result #########
                logger.info("######## TEST 20: wait result #########")
                obsController.sashaGetIndiMsges({"FTEST" : "3", "SEPARATOR" : "TEST 20: Wait Result"})
                det_s.clear()
                det_s["INBEAM_DEP"] = "IN"
                logger.info("Moving INBEAM_DEP to %s" % det_s["INBEAM_DEP"])
                async_result = obsController.begin_setupInstrument(det_s)
                var = input("Press 1 and Enter To Continue...")
                if var == 1:
                    obsController.emergencyAbortAll()
                var = input("Press 1 and Enter To Continue...")
                if var == 1:
                    self.status = obsController.end_setupInstrument(async_result)
                if(self.status == uvars.EXIT_FAILURE):
                    logger.error("Error in TEST 21")
                ufun.error_handler(self.status, "setupInstrument")
            elif TEST == 22:
                ######## TEST 22: Wait Result #########
                logger.info("######## TEST 22: emergencyAbortAll #########")
                obsController.sashaGetIndiMsges({"FTEST" : "3", "SEPARATOR" : "TEST 22: emergencyAbortAll"})
                obsController.emergencyAbortAll()
                if(self.status == uvars.EXIT_FAILURE):
                    logger.error("Error in TEST 22")
                ufun.error_handler(self.status, "emergencyAbortAll")
            elif TEST == 23:
                ######## TEST 22: Wait Result #########
                logger.info("######## TEST 23: setupInstrumentWait #########")
                obsController.sashaGetIndiMsges({"FTEST" : "3", "SEPARATOR" : "TEST 23: setupInstruemntWait"})
                det_s.clear()
                det_s["INBEAM_DEP"] = "IN"
                logger.info("Moving INBEAM_DEP to %s" % det_s["INBEAM_DEP"])
                obsController.setupInstrument(det_s)
                status = uvars.EXIT_FAILURE
                counter = 0
                while(status == uvars.EXIT_FAILURE and counter < 60):
                    counter += 1
                    status = obsController.setupInstrumentWait(0)
                    logger.info("Allowing for external command")
                    time.sleep(1)
                if(self.status == uvars.EXIT_FAILURE):
                    logger.error("Error in TEST 23")
                ufun.error_handler(self.status, "setupInstrument")
            elif TEST == 25:
                log_msg = "TEST %d : %s" % (TEST, "Move Shutter to Negative Limit")
                logger.info("######## %s #########" % log_msg)
                obsController.sashaGetIndiMsges({"FTEST" : "3", "SEPARATOR" : log_msg})
                devices = [ "SHUTTER"]
                self.status = obsController.moveDeviceToNegativeLimit(devices)
                ufun.error_handler(self.status, "moveToNegativeLimit")
                logger.info("%s - Completed" % log_msg)
            elif TEST == 26:
                log_msg = "TEST %d : %s" % (TEST, "Setup while Shutter moving to Negative Limit")
                logger.info("######## %s #########" % log_msg)
                obsController.sashaGetIndiMsges({"FTEST" : "3", "SEPARATOR" : log_msg})
                devices = [ "SHUTTER"]
                async_result = obsController.begin_moveDeviceToNegativeLimit(devices)
                time.sleep(5)
                ins_s = {"SHUTTER":"20000"}
                async_result2 = obsController.begin_setupInstrument(ins_s)
                self.status = obsController.end_moveDeviceToNegativeLimit(async_result)
                obsController.end_setupInstrument(async_result2)
                ufun.error_handler(self.status, "moveToNegativeLimit")
                logger.info("%s - Completed" % log_msg)
            elif TEST == 27:
                log_msg = "TEST %d : %s" % (TEST, "Scicam Teccam Setup")
                logger.info("######## %s #########" % log_msg)
                obsController.sashaGetIndiMsges({"FTEST" : "3", "SEPARATOR" : log_msg})
                ins_s = {}
                ins_s["CORO_SLIT_W"] = "A*335.4346" # "A\"1207564.56"# "A$5.854436" # "A#1850000.00" #HOLE
                ins_s["APODIZER_W"] = "A*237.017" # "1307205.00" # "HOLE5"
                ins_s["CAL_FIBER_DEP"] = "DEFOCUS_IN"
                self.status = obsController.setupInstrument(ins_s)


                ins_s["CORO_SLIT_W"] = "A#553820.00" # "SLIT1"
                ins_s["APODIZER_W"] = "A#1049344.00" # "HOLE4"
                ins_s["CAL_FIBER_DEP"] = "A%-18540.9" # "-2700000.00" # "DANGER_IN"
                #NGROUPS:NREADS:NDROPS
                i = 1
                j = 5
                k = 0
                rtc_s = {}
                rtc_s["TTDIAGENABLED"] = "true" # or "1"
                rtc_s["TTDIAGDECIMATION"] = "0"
                rtc_s["TTPIXELENABLED"] = "true"
                rtc_s["TTPIXELDECIMATION"] = "0" # if 0 master diagnostic stops
                rtc_s["TTTESTTIME"] = "5000000"
                rtc_s["TTLOOPENABLED"] = "false"

                det_s = {"InstrumentMode":"TestF", "OBJECTNAME":"Test Fulvio", "NCOADDS":"1"}
                det_s["NRESETS"] = "1"
                det_s["NDIT"] = "1"
                det_s["SAVE"] = "1"
                det_s["NGROUPS"] = ("%d" % i)
                det_s["NREADS"] = ("%d" % j)
                det_s["NDROPS"] = ("%d" % k)
                det_s["OBJECTNAME"] = ("Test %d:%d:%d" % (i, j , k))
                
                                
                timing = 1 + (i - 1)*(j + k) + j
                file_size = i*j
                obsController.sashaSetup(det_s)
                obsController.sashaExpose(det_s)
                async_resultRes = obsController.begin_sashaGetFitsFileSync(rtc_s, det_s["InstrumentMode"])
                async_resultRtc = obsController.begin_RTCTTTeccamExpose(rtc_s)
                async_resultIns = obsController.begin_setupInstrument(ins_s)

                status, filename = obsController.end_sashaGetFitsFileSync(async_resultRes)
                logger.info("Saved file : {:s}; status : {:d}".format(filename, status))
                status, filename = obsController.end_RTCTTTeccamExpose(async_resultRtc);
                logger.info("Saved file : {:s}; status : {:d}".format(filename, status))
                status = obsController.end_setupInstrument(async_resultIns);
                ufun.error_handler(self.status, "RTCTTTeccamExpose")
                logger.info("Esposed NGROUPS:%d NREADS:%d NDROPS:%d; timing:%d; filesize expected:%d" % (i, j, k, timing*4.2783, file_size*8*1048576 + 2880))
            elif TEST == 28:
                log_msg = "TEST %d : %s" % (TEST, "Scicam Teccam Setup")
                logger.info("######## %s #########" % log_msg)
                obsController.sashaGetIndiMsges({"FTEST" : "3", "SEPARATOR" : log_msg})
                ins_s = {}
                ins_s["CORO_SLIT_W"] = "A*335.4346" # "A\"1207564.56"# "A$5.854436" # "A#1850000.00" #HOLE
                ins_s["APODIZER_W"] = "A*237.017" # "1307205.00" # "HOLE5"
                ins_s["CAL_FIBER_DEP"] = "DEFOCUS_IN"
                self.status = obsController.setupInstrument(ins_s)


                ins_s["CORO_SLIT_W"] = "A#553820.00" # "SLIT1"
                ins_s["APODIZER_W"] = "A#1049344.00" # "HOLE4"
                ins_s["CAL_FIBER_DEP"] = "A%-18540.9" # "-2700000.00" # "DANGER_IN"
                #NGROUPS:NREADS:NDROPS
                i = 1
                j = 5
                k = 0
                rtc_s = {}
                rtc_s["TTDIAGENABLED"] = "true" # or "1"
                rtc_s["TTDIAGDECIMATION"] = "0"
                rtc_s["TTPIXELENABLED"] = "true"
                rtc_s["TTPIXELDECIMATION"] = "0" # if 0 master diagnostic stops
                rtc_s["TTTESTTIME"] = "5000000"
                rtc_s["TTLOOPENABLED"] = "false"

                det_s = {"InstrumentMode":"TestF", "OBJECTNAME":"Test Fulvio", "NCOADDS":"1"}
                det_s["NRESETS"] = "1"
                det_s["NDIT"] = "1"
                det_s["SAVE"] = "1"
                det_s["NGROUPS"] = ("%d" % i)
                det_s["NREADS"] = ("%d" % j)
                det_s["NDROPS"] = ("%d" % k)
                det_s["OBJECTNAME"] = ("Test %d:%d:%d" % (i, j , k))
                
                                
                timing = 1 + (i - 1)*(j + k) + j
                file_size = i*j
                obsController.sashaSetup(det_s)
                obsController.sashaExpose(det_s)
                async_resultRes = obsController.begin_sashaGetFitsFileSync(rtc_s, det_s["InstrumentMode"])
                async_resultRtc = obsController.begin_RTCTTTeccamExpose(rtc_s)
                async_resultIns = obsController.begin_setupInstrument(ins_s)

                time.sleep(5)
                obsController.emergencyAbortAll()


                status, filename = obsController.end_sashaGetFitsFileSync(async_resultRes)
                logger.info("Saved file : {:s}; status : {:d}".format(filename, status))
                status, filename = obsController.end_RTCTTTeccamExpose(async_resultRtc);
                logger.info("Saved file : {:s}; status : {:d}".format(filename, status))
                status = obsController.end_setupInstrument(async_resultIns);
                ufun.error_handler(self.status, "RTCTTTeccamExpose")
                logger.info("Esposed NGROUPS:%d NREADS:%d NDROPS:%d; timing:%d; filesize expected:%d" % (i, j, k, timing*4.2783, file_size*8*1048576 + 2880))
            elif TEST == 29:
                # {"dsp", "shmram", "sram", "sdram"}
                status, seqInt = obsController.RTCTTRead(229380, 1, "sram")
     #           status, seqInt = obsController.RTCTTRead(229388, 1, "shmram")
                for el in seqInt:
                    logger.info("Read %10d" % el)
                ufun.error_handler(status, "RTCTTRead")
            elif TEST == 291:
                # {"dsp", "shmram", "sram", "sdram"}
                status, seqFloat = obsController.RTCTTReadSingle(4432, 2, "dsp")
     #           status, seqInt = obsController.RTCTTRead(229388, 1, "shmram")
                for el in seqFloat:
                    logger.info("Read %10f" % el)
                ufun.error_handler(status, "RTCTTReadSingle")
            elif TEST == 292:
                # tester.py -t SHINS_TEST_DEBUG --targs 292 -a1 4469 -a2 104 -a3 dsp
                if(kwargs and kwargs["test_s1"] and kwargs["test_s2"] and kwargs["test_s3"]):
                    address = eval(kwargs["test_s1"])
                    size = eval(kwargs["test_s2"])
                    memory = kwargs["test_s3"]
                    logger.info("{%s : %s : %s}" % (kwargs["test_s1"], kwargs["test_s2"], kwargs["test_s3"]))
                # {"dsp", "shmram", "sram", "sdram"}
                status, seqFloat = obsController.RTCTTReadSingle(address, size, memory)
     #           status, seqInt = obsController.RTCTTRead(229388, 1, "shmram")
                for el in seqFloat:
                    logger.info("Read %10f" % el)
                ufun.error_handler(status, "RTCTTRead")
            elif TEST == 30:
                status = obsController.RTCTTWrite([1111337152], 229380, "sram")
                ufun.error_handler(status, "RTCTTWrite")
            elif TEST == 31:
                # tester.py -t SHINS_TEST_DEBUG --targs 31 -a1 address -a2 size -a3 "dsp"
                if(kwargs and kwargs["test_s1"] and kwargs["test_s2"] and kwargs["test_s3"]):
                    address = eval(kwargs["test_s1"])
                    size = eval(kwargs["test_s2"])
                    memory = kwargs["test_s3"]
                    logger.info("{%s : %s}" % (kwargs["test_s1"], kwargs["test_s2"]))
                    # {"dsp", "shmram", "sram", "sdram"}
                    status, seqInt = obsController.RTCTTRead(address, size, memory)
                    for el in seqInt:
                        logger.info("Read %10d" % el)
                    ufun.error_handler(status, "RTCTTRead")
                else:
                    logger.info("Please specify (address, size, memory)")
            elif TEST == 32:
                # tester.py -t SHINS_TEST_DEBUG --targs 32 -a1 [-2147483647] -a2 4413 -a3 "dsp"
                if(kwargs and kwargs["test_s1"] and kwargs["test_s2"] and kwargs["test_s3"]):
                    seqInt = eval(kwargs["test_s1"])
                    address = eval(kwargs["test_s2"])
                    memory = kwargs["test_s3"]
                    status = obsController.RTCTTWrite(seqInt, address, memory)
                    ufun.error_handler(status, "RTCTTWrite")
                else:
                    logger.info("Please specify (seqInt, address, memory)")
            elif TEST == 33:
                if(kwargs and kwargs["test_s1"] and kwargs["test_s2"] and kwargs["test_s3"]):
                    tilt = eval(kwargs["test_s1"])
                    tip = eval(kwargs["test_s2"])
                    defocus = eval(kwargs["test_s3"])
                    status = obsController.RTCTTModeUpload([0, 0, tilt, tip, 0, defocus], absolute=True)
                    ufun.error_handler(status, "RTCTTModeUpload")
                else:
                    logger.info("Please specify (seqInt, address, memory)")
            elif TEST == 34:
                if(kwargs and kwargs["test_s1"] and kwargs["test_s2"] and kwargs["test_s3"]):
                    tilt = eval(kwargs["test_s1"])
                    tip = eval(kwargs["test_s2"])
                    defocus = eval(kwargs["test_s3"])
                    status = obsController.RTCTTModeUpload([0, 0, tilt, tip, 0, defocus], absolute=False)
                    ufun.error_handler(status, "RTCTTModeUpload")
                else:
                    logger.info("Please specify (seqInt, address, memory)")
            elif TEST == 35:
                ######## TEST 35: Setup to Negative/Positive Limit #########
                logger.info("######## TEST 35: Setup to Negative/Positive Limit #########")
                obsController.sashaGetIndiMsges({"FTEST" : "3", "SEPARATOR" : "TEST 35: Setup to Negative/Positive Limit"})
                det_s.clear()
                det_s["SHUTTER"] = "NEGATIVELIIMIT"
                logger.info("Moving SHUTTER to %s" % det_s["SHUTTER"])
                self.status = obsController.setupInstrument(det_s)
                if(self.status == uvars.EXIT_FAILURE):
                    logger.error("Error in TEST 35")
                ufun.error_handler(self.status, "setupInstrument")
            elif TEST == 36:
                ######## TEST 36: Setup shutter to IN #########
                logger.info("######## TEST 36: Setup shutter to IN #########")
                obsController.sashaGetIndiMsges({"FTEST" : "3", "SEPARATOR" : "TEST 36: Setup shutter to IN"})
                det_s.clear()
                det_s["SHUTTER"] = "IN"
                logger.info("Moving SHUTTER to %s" % det_s["SHUTTER"])
                self.status = obsController.setupInstrument(det_s)
                if(self.status == uvars.EXIT_FAILURE):
                    logger.error("Error in TEST 36")
                ufun.error_handler(self.status, "setupInstrument")
            elif TEST == 37:
                ########## TEST 37: DROT Move ###########
                logger.info("########## TEST 37: DROT Move ###########")
                obsController.sashaGetIndiMsges({"FTEST" : "3", "SEPARATOR" : "TEST 37 DROT Move"})
                det_s.clear()
                det_s["DROT_PosAng"] = "225.0"
                if(kwargs and kwargs["test_s1"]):
                    det_s["DROT_PoasAng"] = kwargs["test_s1"]
                logger.info("Moving DROT to %s" % det_s["DROT_PosAng"])
#                var = input("Press 1 and Enter To Continue...")
#                if var == 1:
                self.status = obsController.setupInstrument(det_s)
                if(self.status == uvars.EXIT_FAILURE):
                    logger.error("Error in TEST 37")
                ufun.error_handler(self.status, "setupInstrument")
            elif TEST == 40:
                ########## TEST 40: SET PIXEL GAIN ###########
                # tester.py -t SHINS_TEST_DEBUG --targs 40 -a1 POINTGAIN -a2 5
                logger.info("########## TEST 40: SET PIXEL GAIN ###########")
                obsController.sashaGetIndiMsges({"FTEST" : "3", "SEPARATOR" : "SET PIXEL GAIN"})
                det_s.clear()
                det_s["TTPIXELGAINMODE"] = "POINTGAIN" # POINTGAIN FLATGAIN FILEGAIN
                det_s["TTPIXELGAINRADIUS"] = "32"
                if(kwargs and kwargs["test_s1"]):
                    det_s["TTPIXELGAINMODE"] = kwargs["test_s1"]
                    if kwargs["test_s2"]:
                        if det_s["TTPIXELGAINMODE"] == "FILEGAIN":
                            det_s["TTPIXELGAINFILE"] = kwargs["test_s2"]
                        else:
                            det_s["TTPIXELGAINRADIUS"] = kwargs["test_s2"]
                logger.info("Setting Pixel Gain Mode : %s" % det_s["TTPIXELGAINMODE"])
                self.status = obsController.RTCTTExecuteSetup(det_s)
                if(self.status == uvars.EXIT_FAILURE):
                    logger.error("Error in TEST 40")
                ufun.error_handler(self.status, "RTCTTExecuteSetup")
            elif TEST == 41:
                ########## TEST 41: getJsonStatus ###########
                # tester.py -t SHINS_TEST_DEBUG --targs 41
                logger.info("########## TEST 41: getStatus ###########")
                obsController.sashaGetIndiMsges({"FTEST" : "3", "SEPARATOR" : "GET JSON STATUS"})
                self.status, json_status = obsController.getJsonStatus()
                logger.info(json_status)
                if(self.status == uvars.EXIT_FAILURE):
                    logger.error("Error in TEST 41")
                ufun.error_handler(self.status, "getJsonStatus")
            elif TEST == 42:
                ########## TEST 42: shutter ###########
                # tester.py -t SHINS_TEST_DEBUG --targs 42
                logger.info("########## TEST 42: shutter ###########")
                obsController.sashaGetIndiMsges({"FTEST" : "3", "SEPARATOR" : "SHUTTER"})
                det_s.clear()
                det_s["SHUTTER"] = "R#-100"
                logger.info("test : %s" % det_s["SHUTTER"])
                self.status = obsController.setupInstrument(det_s)
                if(self.status == uvars.EXIT_FAILURE):
                    logger.error("Error in TEST 42")
                ufun.error_handler(self.status, "setupInstrument")
            elif TEST == 43: # DONT USE
                ########## TEST 43: EnableTimeHistory ###########
                # tester.py -t SHINS_TEST_DEBUG --targs 41 -a1 true
                logger.info("########## TEST 43: TimeHistory ###########")
                obsController.sashaGetIndiMsges({"FTEST" : "3", "SEPARATOR" : "Time History"})
                det_s.clear()
                det_s["TTHISTORYENABLED"]="false"
                if(kwargs and kwargs["test_s1"]):
                    det_s["TTHISTORYENABLED"] = kwargs["test_s1"]
                if(kwargs and kwargs["test_s2"]):
                    det_s["TTTIMEHISTORYGAIN"] = kwargs["test_s2"]
                    self.status = obsController.RTCTTExecuteSetup[det_s]
                else:
                    self.status = obsController.RTCTTEnableTimeHistory(det_s)
                if(self.status == uvars.EXIT_FAILURE):
                    logger.error("Error in TEST 43")
                ufun.error_handler(self.status, "RTCTTEnableTimeHistory")
            elif TEST == 44:
                ########## TEST 44: Resest BCU ###########
                # tester.py -t SHINS_TEST_DEBUG --targs 44
                logger.info("########## TEST 44: Reset BCU ###########")
                obsController.sashaGetIndiMsges({"FTEST" : "3", "SEPARATOR" : "Reset BCU"})
                self.status = obsController.RTCTTResetBCU()
                if(self.status == uvars.EXIT_FAILURE):
                    logger.error("Error in TEST 44")
                ufun.error_handler(self.status, "RTCTTResetBCU")
            elif TEST == 45:
                ########## TEST 45: Set Flags ###########
                # tester.py -t SHINS_TEST_DEBUG --targs 45 -a1 flags -a2 moreFlags
                # FLAGS
                # SAVE_INCOMING_SASHA_FILES = 1,
                # SAVE_ONLY_EXPOSED_SASHA_FILES = 2,
                # TCS_SINGLE_SIDE_MODE = 1024,
                logger.info("########## TEST 45: Set Flags ###########")
                flags = 0
                moreFlags = 0
                if(kwargs and kwargs["test_s1"]):
                    flags = eval(kwargs["test_s1"])
                if(kwargs and kwargs["test_s2"]):
                    moreFlags = eval(kwargs["test_s2"])
                obsController.sashaGetIndiMsges({"FTEST" : "3", "SEPARATOR" : "Set Flags"})
                self.status = obsController.setFlags(flags, moreFlags)
                ufun.error_handler(self.status, "setFlags")
            elif TEST == 46:
                ########## TEST 46: Unset Flags ###########
                # tester.py -t SHINS_TEST_DEBUG --targs 46 -a1 flags -a2 moreFlags
                logger.info("########## TEST 46: Set Flags ###########")
                flags = 0
                moreFlags = 0
                if(kwargs and kwargs["test_s1"]):
                    flags = eval(kwargs["test_s1"])
                if(kwargs and kwargs["test_s2"]):
                    moreFlags = eval(kwargs["test_s2"])
                obsController.sashaGetIndiMsges({"FTEST" : "3", "SEPARATOR" : "Unset Flags"})
                self.status = obsController.unsetFlags(flags, moreFlags)
                ufun.error_handler(self.status, "unsetFlags")
            elif TEST == 47:
                ########## TEST 47: Toggle Flags ###########
                # tester.py -t SHINS_TEST_DEBUG --targs 47 -a1 flags -a2 moreFlags
                logger.info("########## TEST 47: Toggle Flags TBD ###########")
                flags = 0
                moreFlags = 0
                if(kwargs and kwargs["test_s1"]):
                    flags = eval(kwargs["test_s1"])
                if(kwargs and kwargs["test_s2"]):
                    moreFlags = eval(kwargs["test_s2"])
                obsController.sashaGetIndiMsges({"FTEST" : "3", "SEPARATOR" : "Toggle Flags"})
                self.status = obsController.toggleFlags(flags, moreFlags)
                ufun.error_handler(self.status, "toggleFlags")
            elif TEST == 48:
                ########## TEST 48: Set Data Dictionary Parameter ###########
                # tester.py -t SHINS_TEST_DEBUG --targs 48 -a1 dd_key -a2 value
                logger.info("########## TEST 48: Set Data Dictionary TBD ###########")
                det_s = {}
                if(kwargs and kwargs["test_s1"] and kwargs["test_s2"]):
                    det_s[kwargs["test_s1"]] = kwargs["test_s2"]
                obsController.sashaGetIndiMsges({"FTEST" : "3", "SEPARATOR" : "Set Data Dictionary Parameter"})
                self.status, DdResult = obsController.setDdParameters(det_s)
                ufun.error_handler(self.status, "setDdParameters")
                print(DdResult)
            elif TEST == 49:
                ########## TEST 49: get Data Dictionary Parameter ###########
                # tester.py -t SHINS_TEST_DEBUG --targs 49 -a1 "[\"LBTTemp\", \"DIMMSeeing\"]"
                logger.info("########## TEST 49: get Data Dictionary ###########")
                seqEntries = ["LBTTemp", "DIMMSeeing"]
                if(kwargs and kwargs["test_s1"]):
                    seqEntries = eval(kwargs["test_s1"])
                obsController.sashaGetIndiMsges({"FTEST" : "3", "SEPARATOR" : "Get Data Dictionary Parameter"})
                self.status, DdResult = obsController.getDdParameters(seqEntries)
                logger.info("getDdParameters : ")
                for el in DdResult:
                    logger.info(el)
                # ufun.error_handler(self.status, "getDdParameters")
            elif TEST == 50:
                ########## TEST 50: Send Wavefront to TCS ###########
                # tester.py -t SHINS_TEST_DEBUG --targs 50 -a1 "[0.01, -0.01, 0.005]" -a2 M2
                logger.info("########## TEST 50: Send Wavefront ###########")
                det_s = {}
                if(kwargs and kwargs["test_s1"] and kwargs["test_s2"]):
                    det_s[kwargs["test_s1"]] = kwargs["test_s2"]
                obsController.sashaGetIndiMsges({"FTEST" : "3", "SEPARATOR" : "Send Wavefront"})
                self.status = obsController.SendWavefront(eval(kwargs["test_s1"]), kwargs["test_s2"])
                ufun.error_handler(self.status, "SendWavefront")
            elif TEST == 53:
                ########## TEST 53: Move Focus to TCS ###########
                # tester.py -t SHINS_TEST_DEBUG --targs 53 -a1 0.01 -a2 M2
                logger.info("########## TEST 53: Move Focus ###########")
                det_s = {}
                if(kwargs and kwargs["test_s1"] and kwargs["test_s2"]):
                    det_s[kwargs["test_s1"]] = kwargs["test_s2"]
                obsController.sashaGetIndiMsges({"FTEST" : "3", "SEPARATOR" : "Move Focus"})
                self.status = obsController.MoveFocus(eval(kwargs["test_s1"]), kwargs["test_s2"])
                ufun.error_handler(self.status, "Move Focus")
            elif TEST == 541:
                ########## TEST 541: Set Derotation Parameters ###########
                # tester.py -t SHINS_TEST_DEBUG --targs 541 -a1 2000 -a2 M2
                # a1 = NumPolynomials, a2 = samplingRate, a3 = frequency;
                logger.info("########## TEST 541 : Set Derotation Parameters ###########")
                numPolynomials = 1200
                samplingRate = 1
                frequency = 1
                if kwargs :
                    if kwargs["test_s1"] :
                        numPolynomials = eval(kwargs["test_s1"])
                    if kwargs["test_s2"] :
                        samplingRate = eval(kwargs["test_s2"])
                    if kwargs["test_s3"] :
                        frequency = eval(kwargs["test_s3"])
                obsController.sashaGetIndiMsges({"FTEST" : "3", "SEPARATOR" : "Set Derotator Parameters"})
                self.status = obsController.setDerotationParameters1(numPolynomials, samplingRate, frequency)
                ufun.error_handler(self.status, "setDerotationParameters1")
            elif TEST == 542:
                ########## TEST 542: Set Derotation Parameters ###########
                # tester.py -t SHINS_TEST_DEBUG --targs 542 -a1 2000 -a2 M2
                # a1 = plynomialOrder, a2 = faultTolerance, a3 = samplesPerSegment;
                logger.info("########## TEST 542 : Set Derotation Parameters ###########")
                polynomialOrder = 2
                faultTolerance = 350
                samplesPerSegment = 100
                if kwargs :
                    if kwargs["test_s1"] :
                        plynomialOrder = eval(kwargs["test_s1"])
                    if kwargs["test_s2"] :
                        faultTolerance = eval(kwargs["test_s2"])
                    if kwargs["test_s3"] :
                        samplesPerSegment = eval(kwargs["test_s3"])
                obsController.sashaGetIndiMsges({"FTEST" : "3", "SEPARATOR" : "Set Derotator Parameters"})
                self.status = obsController.setDerotationParameters2(polynomialOrder, faultTolerance, samplesPerSegment)
                ufun.error_handler(self.status, "setDerotationParameters2")
            elif TEST == 543:
                ########## TEST 543: Set Derotation Parameters ###########
                # tester.py -t SHINS_TEST_DEBUG --targs 543 -a1 2000 -a2 M2
                # a1 = debug1, a2 = debug2, a3 = debug3;
                logger.info("########## TEST 543 : Set Derotation Parameters 3 ###########")
                debug1 = 0
                debug2 = 0
                debug3 = 0
                if kwargs :
                    if kwargs["test_s1"] :
                        debug1 = eval(kwargs["test_s1"])
                    if kwargs["test_s2"] :
                        debug2 = eval(kwargs["test_s2"])
                    if kwargs["test_s3"] :
                        debug3 = eval(kwargs["test_s3"])
                obsController.sashaGetIndiMsges({"FTEST" : "3", "SEPARATOR" : "Set Derotator Parameters"})
                self.status = obsController.setDerotationParameters3(debug1, debug2, debug3)
                ufun.error_handler(self.status, "setDerotationParameters3")
            elif TEST == 55:
                ########## TEST 55: Test setContext ###########
                # tester.py -t SHINS_TEST_DEBUG --targs 55
                logger.info("########## TEST 53: Test setContext ###########")
                det_s = {}
                obsController.sashaGetIndiMsges({"FTEST" : "3", "SEPARATOR" : "Test setContext"})
                self.status = obsController.setContext({"FTEST" : "3", "SEPARATOR" : "Test setContext"})
                ufun.error_handler(self.status, "Test setContext")
            elif TEST == 56:
                ########## TEST 56: Setup Track (DEGREE) ###########
                # tester.py -t SHINS_TEST_DEBUG --targs 56 -a1 20 -a2 -15
                # a1 = ADC1 Pos, a2 = ADC2 Pos, a3 = Drot Pos;
                logger.info("########## TEST 56 : Setup Track (DEGREE) ###########")
                adc1pos = 0
                adc2pos = 0
                drotpos = 0
                ins_s = {}
                if kwargs :
                    if kwargs["test_s1"] :
                        adc1pos = eval(kwargs["test_s1"])
                    if kwargs["test_s2"] :
                        adc2pos = eval(kwargs["test_s2"])
                    if kwargs["test_s3"] :
                        drotpos = eval(kwargs["test_s3"])
                ins_s["ADC1_PosAng"] = ("%f" % adc1pos) # "A\"1207564.56"# "A$5.854436" # "A#1850000.00" #HOLE
                ins_s["ADC2_PosAng"] = ("%f" % adc2pos) # "A*237.017" # "1307205.00" # "HOLE5"
                ins_s["DROT_PosAng"] = ("%f" % drotpos)
                obsController.sashaGetIndiMsges({"FTEST" : "3", "SEPARATOR" : "Setup Track (DEGREE)"})
                self.status = obsController.setupInstrument(ins_s)
                ufun.error_handler(self.status, "setupInstrument")
            elif TEST == 57:
                ########## TEST 57: Setup ADC Mode ###########
                # tester.py -t SHINS_TEST_DEBUG --targs 57 -a1 MODE
                # a1 = {ON, OFF}
                logger.info("########## TEST 57 : Setup ADC Mode ###########")
                adcMode = "OFF"
                ins_s = {}
                if kwargs :
                    if kwargs["test_s1"] :
                        adcMode = kwargs["test_s1"]
                ins_s["ADC_Mode"] = adcMode
                obsController.sashaGetIndiMsges({"FTEST" : "3", "SEPARATOR" : "Setup ADC Mode"})
                self.status = obsController.setupInstrument(ins_s)
                ufun.error_handler(self.status, "setupInstrument")
            elif TEST == 58:
                ########## TEST 58: Setup DROT Mode ###########
                # tester.py -t SHINS_TEST_DEBUG --targs 58 -a1 MODE
                # a1 = {"PUPIL", "FIELD"}
                logger.info("########## TEST 58 : Setup DROT Mode ###########")
                drotMode = "FIELD"
                ins_s = {}
                if kwargs :
                    if kwargs["test_s1"] :
                        drotMode = kwargs["test_s1"]
                ins_s["DROT_Mode"] = drotMode
                obsController.sashaGetIndiMsges({"FTEST" : "3", "SEPARATOR" : "Setup DROT Mode"})
                self.status = obsController.setupInstrument(ins_s)
                ufun.error_handler(self.status, "setupInstrument")
            elif TEST == 60 :
                ########## TEST 60 : Setup Calibration Unit ###########
                # tester.py -t SHINS_TEST_DEBUG --targs 60 -a1 FOCUS_IN -a2 DARK -a3 OUT
                # a1 = {"FOCUS_IN", "DEFOCUS_IN", "NO_FIBERS", "DANGER_IN"}; a2 = {"IN", "OUT", "DARK"}; a3 = {"IN", "OUT"};
                logger.info("########## TEST 60 : Setup Calibration Unit ###########")
                ins_s = {}
                if kwargs :
                    if kwargs["test_s1"] :
                        ins_s["CAL_FIBER_DEP"] = kwargs["test_s1"]
                    if kwargs["test_s2"] :
                        ins_s["CAL_FILTER_DEP"] = kwargs["test_s2"]
                    if kwargs["test_s3"] :
                        ins_s["CAL_MIRROR_DEP"] = kwargs["test_s3"]
                obsController.sashaGetIndiMsges({"FTEST" : "3", "SEPARATOR" : "Setup Calibration Unit"})
                self.status = obsController.setupInstrument(ins_s)
                ufun.error_handler(self.status, "setupInstrument")
            elif TEST == 61 : # used
                pass
            elif TEST == 62 : # used
                pass
            elif TEST == 63 : # 
                ########## TEST 63 : Start Tracking  ###########
                # tester.py -t SHINS_TEST_DEBUG --targs 63
                logger.info("########## TEST 63 : Start Tracking ###########")
                ins_s = {}
                ins_s["DROT_Mode"] = "FIELD_FREE" # FIELD_FREE, FIELD_FIXED, PUPIL
                obsController.sashaGetIndiMsges({"FTEST" : "3", "SEPARATOR" : "Start Tracking"})
                self.status = obsController.setupInstrument(ins_s)
                dateMjd = Time.now()
                # dateMjd = dateMjd # + TimeDelta(120, format='sec')
                position = 140
                ufun.error_handler(self.status, "setupInstrument")
                self.status = obsController.trackingStart2(dateMjd.mjd, 0)
                ufun.error_handler(self.status, "trackingStart")
#   Ice::Int SequencerI::setDerotationParameters(Ice::Int numPolynomials, Ice::Double samplingRate, Ice::Double frequency, Ice::Int polynomialOrder, Ice::Int faultTolerance, Ice::Int samplesPerSegment, const Ice::Current & _c)
            elif TEST == 64 : # 
                ########## TEST 64 :   ###########
                # tester.py -t SHINS_TEST_DEBUG --targs 64
                logger.info("########## TEST 64 : Start Tracking ###########")
                ins_s = {}
                ins_s["DROT_Mode"] = "FIELD_FREE" # FIELD_FREE, FIELD_FIXED, PUPIL
                obsController.sashaGetIndiMsges({"FTEST" : "3", "SEPARATOR" : "Start Tracking"})
                self.status = obsController.setupInstrument(ins_s)
                ufun.error_handler(self.status, "setupInstrument")
                self.status = obsController.trackingStart()
                ufun.error_handler(self.status, "trackingStart")
            elif TEST == 641 : # 
                ########## TEST 64 :   ###########
                # tester.py -t SHINS_TEST_DEBUG --targs 641
                logger.info("########## TEST 641 : Start Tracking ###########")
                ins_s = {}
                ins_s["DROT_Mode"] = "FIELD_FIXED" # FIELD_FREE, FIELD_FIXED, PUPIL
                obsController.sashaGetIndiMsges({"FTEST" : "3", "SEPARATOR" : "Start Tracking"})
                self.status = obsController.setupInstrument(ins_s)
                ufun.error_handler(self.status, "setupInstrument")
                dateMjd = Time.now()
                dateMjd = dateMjd # + TimeDelta(-1, format='sec')
                position = 15
                self.status = obsController.trackingStart2(dateMjd.mjd, position)
                ufun.error_handler(self.status, "trackingStart")

            elif TEST == 65:
                ########## TEST 65 :  Read & Write pointers Poll ###########
                # tester.py -t SHINS_TEST_DEBUG --targs 65
                # {"dsp", "shmram", "sram", "sdram"}
                counter = 0
                DiagRecordReadPtr = 229400
                puntatori = []
                while counter < 3*3600:
                    try:
                        status, seqInt = obsController.RTCTTRead(DiagRecordReadPtr, 2, "sram")
                        puntatori.append(seqInt)
                        time.sleep(10)
                        counter = counter + 10
                    except KeyboardInterrupt:
                    #    logger.error(e)
                        break
                logger.info(puntatori)
                ufun.error_handler(status, "RTCTTRead")
            elif TEST == 66:
                ########## TEST 66 :  Derotation Test ###########
                # tester.py -t SHINS_TEST_DEBUG --targs 66 -a1 0 -a2 190 -a3 25
                startPosDegree = 0
                endPosDegree = 180
                speedDegreeSec = 25
                if kwargs :
                    if kwargs["test_s1"] :
                        startPosDegree = eval(kwargs["test_s1"])
                    if kwargs["test_s2"] :
                        endPosDegree = eval(kwargs["test_s2"])
                    if kwargs["test_s3"] :
                        speedDegreeSec = eval(kwargs["test_s3"])
                logger.info("%f ~ %f ~ %f" % (startPosDegree, endPosDegree, speedDegreeSec))
                obsController.setupInstrument({"DROT_Mode":"FIELD_FIXED"})
                status = obsController.trackingTestStart(startPosDegree, endPosDegree, speedDegreeSec)
                ufun.error_handler(status, "trackingTestStart")
            elif TEST == 67:
                ########## TEST 67 :  Free Setup Instrument ###########
                # tester.py -t SHINS_TEST_DEBUG --targs 67 -a1 "{\"SHUTTER\":\"IN\"}"
                logger.info("########## TEST 67 : setupInstrument free ###########")
                ins_s = {}
                if(kwargs and kwargs["test_s1"]):
                    ins_s = eval(kwargs["test_s1"])
                obsController.sashaGetIndiMsges({"FTEST" : "3", "SEPARATOR" : "Free Setup Instrument"})
                status = obsController.setupInstrument(ins_s)
                ufun.error_handler(status, "setupInstrument")
            elif TEST == 68:
                ########## TEST 68 : Stop Motor  ###########
                # tester.py -t SHINS_TEST_DEBUG --targs 68 -a1 "[\"SHUTTER\", \"CAL_FIBER_DEP\"]"
                logger.info("########## TEST 68 : stopMotion free ###########")
                ins_s = []
                if(kwargs and kwargs["test_s1"]):
                    ins_s = eval(kwargs["test_s1"])
                obsController.sashaGetIndiMsges({"FTEST" : "3", "SEPARATOR" : "Stop Motor"})
                status = obsController.stopMotion(ins_s)
                ufun.error_handler(status, "stopMotion")
            elif TEST == 69:
                ########## TEST 69 : Abort Motor  ###########
                # tester.py -t SHINS_TEST_DEBUG --targs 69 -a1 "[\"SHUTTER\", \"CAL_FIBER_DEP\"]"
                logger.info("########## TEST 69 : abortMotion free ###########")
                ins_s = []
                if(kwargs and kwargs["test_s1"]):
                    ins_s = eval(kwargs["test_s1"])
                obsController.sashaGetIndiMsges({"FTEST" : "3", "SEPARATOR" : "Abort Motor"})
                status = obsController.abortMotion(ins_s)
                ufun.error_handler(status, "abortMotion")
            elif TEST == 710:
                ########## TEST 710 : Preset Telescope RADEC left  ###########
                # tester.py -t SHINS_TEST_DEBUG --targs 710 -a1 "14 15 44.82" -a2 "19 10 7.0" -a3 Arcturus
                logger.info("########## TEST 710 : Preset Telescope RADEC left ###########")
                tel_s = {
                    "CoordinateSystem":"RADEC",
                    "Epoch":"2022.5",
                    "Equinox": "j2000",
                    "OBJEQUIN":"2000",

                    "OBJECTNAME":"Arcturus",
                    "OBJRA":"14 15 44.82",
                    "OBJDEC":"19 10 7.0",

                    "OBJMAG" : "1",
                    "PMRA":"0",
                    "PMDEC":"0",
                    "PMGSRA":"0",
                    "PMGSDEC":"0",
                    "PMAORA":"0",
                    "PMAODEC":"0",
                    "BinocularFlag":"OFF",
                    "TelescopeMode": "ADAPTIVEACE_TRACK", # "TRACK"
                    "TelescopeSide": "LEFT",
                    "AOMODE":"NORMAL" # NORMAL, REPOINT, SKIPREF, SKIPSTART, SKIPSTARTREPOINT, SKIPALL
                }
                if(kwargs and kwargs["test_s1"] and kwargs["test_s2"]):
                    tel_s["OBJRA"] = kwargs["test_s1"]
                    tel_s["OBJDEC"] = kwargs["test_s2"]
                    tel_s["OBJECTNAME"] = "UNDEFINED"
                    if kwargs["test_s3"]:
                        tel_s["OBJECTNAME"] = kwargs["test_s3"]
                obsController.sashaGetIndiMsges({"FTEST" : "3", "SEPARATOR" : "Preset Telescope"})

#                tel_s["OBJECTNAME"] = "Arcturus"
                objra_degree = 15*(14 + 15/60. + 44.82/3600.)
#                tel_s["OBJRA"] = str(objra_degree*3.141592653/180)
                objdec_degree = 19 + 10/60. + 7.0/3600.
#                tel_s["OBJDEC"] = str(objdec_degree*3.141592653/180)

                logger.info("ObjectName : %s; Obj RA (°): %s; Obj DEC (°): %s" % (tel_s["OBJECTNAME"], str(objra_degree*3.141592653/180), str(objdec_degree*3.141592653/180)))
                logger.info("STRINGS: ObjectName : %s; Obj RA : %s; Obj DEC : %s" % (tel_s["OBJECTNAME"], tel_s["OBJRA"], tel_s["OBJDEC"]))
                tel_s = ufun.to_radians(tel_s)
                logger.info("RADIANS: ObjectName : %s; Obj RA : %s; Obj DEC : %s" % (tel_s["OBJECTNAME"], tel_s["OBJRA"], tel_s["OBJDEC"]))

                logger.info("Running: PresetTelescope")
                status = obsController.PresetTelescope(tel_s)
                ufun.error_handler(status, "PresetTelescope")
            elif TEST == 7101:
                ########## TEST 7101 : Preset Telescope RADEC left Sidereal ###########
                # tester.py -t SHINS_TEST_DEBUG --targs 7101 -a1 "14 15 44.82" -a2 "19 10 7.0" -a3 Arcturus
                # tester.py -t SHINS_TEST_DEBUG --targs 7101 -a1 "{\"CoordinateSystem\":\"RADEC\", \"Epoch\":\"2022.5\", \"Equinox\":\"J2000\",   \"OBJECTNAME\":\"Arcturus\", \"OBJRA\":\"14 15 44.82\", \"OBJDEC\":\"19 10 7.0\",   \"OBJMAG\":\"1\", \"PMRA\":\"0.0\", \"PMDEC\":\"0.0\", \"PMGSRA\":\"0.0\", \"PMGSDEC\":\"0.0\", \"PMAORA\":\"0.0\", \"PMAODEC\":\"0.0\", \"BincocularFlag\":\"OFF\",   \"TargetType\":\"DIFFERENTIAL\", \"TargetFile\":\"\", \"TargetRaRate\":\"10.0\", \"TargetDecRate\":\"20.0\", \"TargetTime\":\"12345678.123\",   \"BinocularFlag\":\"OFF\", \"TelescopeMode\":\"ADAPTIVEACE_TRACK\", \"TelescopeSide\":\"LEFT\", \"AOMODE\":\"NORMAL\"}"
                # tester.py -t SHINS_TEST_DEBUG --targs 7101 -a1 "{\"CoordinateSystem\":\"RADEC\", \"Epoch\":\"2022.5\", \"Equinox\":\"J2000\",   \"OBJECTNAME\":\"Arcturus\", \"OBJRA\":\"14 15 44.82\", \"OBJDEC\":\"19 10 7.0\",   \"OBJMAG\":\"1\", \"PMRA\":\"0.0\", \"PMDEC\":\"0.0\", \"PMGSRA\":\"0.0\", \"PMGSDEC\":\"0.0\", \"PMAORA\":\"0.0\", \"PMAODEC\":\"0.0\", \"BincocularFlag\":\"OFF\",   \"TargetType\":\"FILE\", \"TargetFile\":\"1p/ephemeris_file\", \"TargetRaRate\":\"0.0\", \"TargetDecRate\":\"0.0\", \"TargetTime\":\"12345678.123\",   \"BinocularFlag\":\"OFF\", \"TelescopeMode\":\"ADAPTIVEACE_TRACK\", \"TelescopeSide\":\"LEFT\", \"AOMODE\":\"NORMAL\"}"
                logger.info("########## TEST 710 : Preset Telescope RADEC left ###########")
                tel_s = {
                    "CoordinateSystem":"RADEC",
                    "Epoch":"2022.5",
                    "Equinox": "j2000",
                    "OBJEQUIN":"2000",

                    "OBJECTNAME":"Arcturus",
                    "OBJRA":"14 15 44.82",
                    "OBJDEC":"19 10 7.0",

                    "OBJMAG" : "1",
                    "PMRA":"0",
                    "PMDEC":"0",
                    "PMGSRA":"0",
                    "PMGSDEC":"0",
                    "PMAORA":"0",
                    "PMAODEC":"0",
                    "BinocularFlag":"OFF",

                    "TargetType":"Neptune", # "SIDEREAL", "sidereal", "FILE", "DIFFERENTIAL", planet names es "SATURN"
                #    "TargetFile":"1P/Halley8AUG2011",
                #    "DifferentialMjd", same as Target.time
                #    "DifferentialRa", same as OBJRA
                #    "DifferentialDec", same as OBJDEC
                #    "DifferentialValue3",
                #    "DifferentialValue4",
                #    "TargetRaRate",
                #    "TargetDecRAte",
                #    "TargetTime"

                    "TelescopeMode": "ADAPTIVEACE_TRACK", # "TRACK"
                    "TelescopeSide": "LEFT",
                    "AOMODE":"NORMAL" # NORMAL, REPOINT, SKIPREF, SKIPSTART, SKIPSTARTREPOINT, SKIPALL
                }
                if(kwargs and kwargs["test_s1"] ):
                    tel_s = eval(kwargs["test_s1"])
                obsController.sashaGetIndiMsges({"FTEST" : "3", "SEPARATOR" : "Preset Telescope"})

#                tel_s["OBJECTNAME"] = "Arcturus"
                objra_degree = 15*(14 + 15/60. + 44.82/3600.)
#                tel_s["OBJRA"] = str(objra_degree*3.141592653/180)
                objdec_degree = 19 + 10/60. + 7.0/3600.
#                tel_s["OBJDEC"] = str(objdec_degree*3.141592653/180)

                logger.info("ObjectName : %s; Obj RA (°): %s; Obj DEC (°): %s" % (tel_s["OBJECTNAME"], str(objra_degree*3.141592653/180), str(objdec_degree*3.141592653/180)))
                logger.info("STRINGS: ObjectName : %s; Obj RA : %s; Obj DEC : %s" % (tel_s["OBJECTNAME"], tel_s["OBJRA"], tel_s["OBJDEC"]))
                tel_s = ufun.to_radians(tel_s)
                logger.info("RADIANS: ObjectName : %s; Obj RA : %s; Obj DEC : %s" % (tel_s["OBJECTNAME"], tel_s["OBJRA"], tel_s["OBJDEC"]))

                logger.info("Running: PresetTelescope")
                status = obsController.PresetTelescope(tel_s)
                ufun.error_handler(status, "PresetTelescope")
            elif TEST == 711:
                ########## TEST 711 : Preset Telescope RADEC both  ###########
                # tester.py -t SHINS_TEST_DEBUG --targs 711 -a1 "14 15 44.82" -a2 "19 10 7.0" -a3 Arcturus
                logger.info("########## TEST 711 : Preset Telescope RADEC both ###########")
                tel_s = {
                    "CoordinateSystem":"RADEC",
                    "Epoch":"2022.5",
                    "Equinox": "j2000",
                    "OBJEQUIN":"2000",

                    "OBJECTNAME":"HD23432",
                    "OBJRA":"03 45 54.48",
                    "OBJDEC":"24 33 16.24",

                    "OBJMAG" : "1",
                    "PMRA":"0",
                    "PMDEC":"0",
                    "PMGSRA":"0",
                    "PMGSDEC":"0",
                    "PMAORA":"0",
                    "PMAODEC":"0",
                    "BinocularFlag":"OFF",
                    "TelescopeMode": "TRACK", # "ADAPTIVEACE_TRACK", # "TRACK"
                    "TelescopeSide": "BOTH",
                    "AOMODE":"NORMAL" # NORMAL, REPOINT, SKIPREF, SKIPSTART, SKIPSTARTREPOINT, SKIPALL
                }
                if(kwargs and kwargs["test_s1"] and kwargs["test_s2"]):
                    tel_s["OBJRA"] = kwargs["test_s1"]
                    tel_s["OBJDEC"] = kwargs["test_s2"]
                    tel_s["OBJECTNAME"] = "UNDEFINED"
                    if kwargs["test_s3"]:
                        tel_s["OBJECTNAME"] = kwargs["test_s3"]
                obsController.sashaGetIndiMsges({"FTEST" : "3", "SEPARATOR" : "Preset Telescope"})

#                tel_s["OBJECTNAME"] = "Arcturus"
                objra_degree = 15*(14 + 15/60. + 44.82/3600.)
#                tel_s["OBJRA"] = str(objra_degree*3.141592653/180)
                objdec_degree = 19 + 10/60. + 7.0/3600.
#                tel_s["OBJDEC"] = str(objdec_degree*3.141592653/180)

                logger.info("ObjectName : %s; Obj RA (°): %s; Obj DEC (°): %s" % (tel_s["OBJECTNAME"], str(objra_degree*3.141592653/180), str(objdec_degree*3.141592653/180)))
                logger.info("STRINGS: ObjectName : %s; Obj RA : %s; Obj DEC : %s" % (tel_s["OBJECTNAME"], tel_s["OBJRA"], tel_s["OBJDEC"]))
                tel_s = ufun.to_radians(tel_s)
                logger.info("RADIANS: ObjectName : %s; Obj RA : %s; Obj DEC : %s" % (tel_s["OBJECTNAME"], tel_s["OBJRA"], tel_s["OBJDEC"]))

                logger.info("Running: PresetTelescope")
                status = obsController.PresetTelescope(tel_s)
                ufun.error_handler(status, "PresetTelescope")
            elif TEST == 712:
                ########## TEST 712 : Preset Telescope RADEC right  ###########
                # tester.py -t SHINS_TEST_DEBUG --targs 712 -a1 "14 15 44.82" -a2 "19 10 7.0" -a3 Arcturus
                logger.info("########## TEST 712 : Preset Telescope RADEC right ###########")
                tel_s = {
                    "CoordinateSystem":"RADEC",
                    "Epoch":"2022.5",
                    "Equinox": "j2000",
                    "OBJEQUIN":"2000",

                    "OBJECTNAME":"Arcturus",
                    "OBJRA":"14 15 44.82",
                    "OBJDEC":"19 10 7.0",

                    "OBJMAG" : "1",
                    "PMRA":"0",
                    "PMDEC":"0",
                    "PMGSRA":"0",
                    "PMGSDEC":"0",
                    "PMAORA":"0",
                    "PMAODEC":"0",
                    "BinocularFlag":"OFF",
                    "TelescopeMode": "ADAPTIVEACE_TRACK", # "TRACK"
                    "TelescopeSide": "right",
                    "AOMODE":"NORMAL" # NORMAL, REPOINT, SKIPREF, SKIPSTART, SKIPSTARTREPOINT, SKIPALL
                }
                if(kwargs and kwargs["test_s1"] and kwargs["test_s2"]):
                    tel_s["OBJRA"] = kwargs["test_s1"]
                    tel_s["OBJDEC"] = kwargs["test_s2"]
                    tel_s["OBJECTNAME"] = "UNDEFINED"
                    if kwargs["test_s3"]:
                        tel_s["OBJECTNAME"] = kwargs["test_s3"]
                obsController.sashaGetIndiMsges({"FTEST" : "3", "SEPARATOR" : "Preset Telescope"})

#                tel_s["OBJECTNAME"] = "Arcturus"
                objra_degree = 15*(14 + 15/60. + 44.82/3600.)
#                tel_s["OBJRA"] = str(objra_degree*3.141592653/180)
                objdec_degree = 19 + 10/60. + 7.0/3600.
#                tel_s["OBJDEC"] = str(objdec_degree*3.141592653/180)

                logger.info("ObjectName : %s; Obj RA (°): %s; Obj DEC (°): %s" % (tel_s["OBJECTNAME"], str(objra_degree*3.141592653/180), str(objdec_degree*3.141592653/180)))
                logger.info("STRINGS: ObjectName : %s; Obj RA : %s; Obj DEC : %s" % (tel_s["OBJECTNAME"], tel_s["OBJRA"], tel_s["OBJDEC"]))
                tel_s = ufun.to_radians(tel_s)
                logger.info("RADIANS: ObjectName : %s; Obj RA : %s; Obj DEC : %s" % (tel_s["OBJECTNAME"], tel_s["OBJRA"], tel_s["OBJDEC"]))

                logger.info("Running: PresetTelescope")
                status = obsController.PresetTelescope(tel_s)
                ufun.error_handler(status, "PresetTelescope")
            elif TEST == 713:
                ########## TEST 713 : Sync Preset Telescope RADEC  ###########
                # tester.py -t SHINS_TEST_DEBUG --targs 713 -a1 "14 15 44.82" -a2 "19 10 7.0" -a3 Arcturus
                logger.info("########## TEST 713 : Sync Preset Telescope RADEC ###########")
                tel_s = {
                    "CoordinateSystem":"RADEC",
                    "Epoch":"2022.5",
                    "Equinox": "j2000",
                    "OBJEQUIN":"2000",

                    "OBJECTNAME":"Arcturus",
                    "OBJRA":"14 15 44.82",
                    "OBJDEC":"19 10 7.0",

                    "OBJMAG" : "1",
                    "PMRA":"0",
                    "PMDEC":"0",
                    "PMGSRA":"0",
                    "PMGSDEC":"0",
                    "PMAORA":"0",
                    "PMAODEC":"0",
                    "BinocularFlag":"SYNCPRESET",
                    "TelescopeMode": "ADAPTIVEACE_TRACK", # "TRACK"
                    "TelescopeSide": "right",
                    "AOMODE":"NORMAL" # NORMAL, REPOINT, SKIPREF, SKIPSTART, SKIPSTARTREPOINT, SKIPALL
                }
                if(kwargs and kwargs["test_s1"] and kwargs["test_s2"]):
                    tel_s["OBJRA"] = kwargs["test_s1"]
                    tel_s["OBJDEC"] = kwargs["test_s2"]
                    tel_s["OBJECTNAME"] = "UNDEFINED"
                    if kwargs["test_s3"]:
                        tel_s["OBJECTNAME"] = kwargs["test_s3"]
                obsController.sashaGetIndiMsges({"FTEST" : "3", "SEPARATOR" : "Preset Telescope"})

#                tel_s["OBJECTNAME"] = "Arcturus"
                objra_degree = 15*(14 + 15/60. + 44.82/3600.)
#                tel_s["OBJRA"] = str(objra_degree*3.141592653/180)
                objdec_degree = 19 + 10/60. + 7.0/3600.
#                tel_s["OBJDEC"] = str(objdec_degree*3.141592653/180)

                logger.info("ObjectName : %s; Obj RA (°): %s; Obj DEC (°): %s" % (tel_s["OBJECTNAME"], str(objra_degree*3.141592653/180), str(objdec_degree*3.141592653/180)))
                logger.info("STRINGS: ObjectName : %s; Obj RA : %s; Obj DEC : %s" % (tel_s["OBJECTNAME"], tel_s["OBJRA"], tel_s["OBJDEC"]))
                tel_s = ufun.to_radians(tel_s)
                logger.info("RADIANS: ObjectName : %s; Obj RA : %s; Obj DEC : %s" % (tel_s["OBJECTNAME"], tel_s["OBJRA"], tel_s["OBJDEC"]))

                logger.info("Running: PresetTelescope")
                statusr = obsController.PresetTelescope(tel_s)
                ufun.error_handler(statusr, "PresetTelescope")
            elif TEST == 714:
                ########## TEST 714 :   ###########
                # tester.py -t SHINS_TEST_DEBUG --targs 714 -a1 "14 15 44.82" -a2 "19 10 7.0" -a3 Arcturus
                logger.info("########## TEST 714 : Preset Telescope RADEC ###########")
                tel_s = {
                    "CoordinateSystem":"RADEC",
                    "Epoch":"2022.5",
                    "Equinox": "j2000",
                    "OBJEQUIN":"2000",

                    "OBJECTNAME":"Arcturus",
                    "OBJRA":"14 15 44.82",
                    "OBJDEC":"19 10 7.0",

                    "OBJMAG" : "1",
                    "PMRA":"0",
                    "PMDEC":"0",
                    "PMGSRA":"0",
                    "PMGSDEC":"0",
                    "PMAORA":"0",
                    "PMAODEC":"0",
                    "BinocularFlag":"SYNCPRESET",
                    "TelescopeMode": "ADAPTIVEACE_TRACK", # "TRACK"
                    "TelescopeSide": "left",
                    "AOMODE":"NORMAL" # NORMAL, REPOINT, SKIPREF, SKIPSTART, SKIPSTARTREPOINT, SKIPALL
                }
                if(kwargs and kwargs["test_s1"] and kwargs["test_s2"]):
                    tel_s["OBJRA"] = kwargs["test_s1"]
                    tel_s["OBJDEC"] = kwargs["test_s2"]
                    tel_s["OBJECTNAME"] = "UNDEFINED"
                    if kwargs["test_s3"]:
                        tel_s["OBJECTNAME"] = kwargs["test_s3"]
                obsController.sashaGetIndiMsges({"FTEST" : "3", "SEPARATOR" : "Preset Telescope"})

#                tel_s["OBJECTNAME"] = "Arcturus"
                objra_degree = 15*(14 + 15/60. + 44.82/3600.)
#                tel_s["OBJRA"] = str(objra_degree*3.141592653/180)
                objdec_degree = 19 + 10/60. + 7.0/3600.
#                tel_s["OBJDEC"] = str(objdec_degree*3.141592653/180)

                logger.info("ObjectName : %s; Obj RA (°): %s; Obj DEC (°): %s" % (tel_s["OBJECTNAME"], str(objra_degree*3.141592653/180), str(objdec_degree*3.141592653/180)))
                logger.info("STRINGS: ObjectName : %s; Obj RA : %s; Obj DEC : %s" % (tel_s["OBJECTNAME"], tel_s["OBJRA"], tel_s["OBJDEC"]))
                tel_s = ufun.to_radians(tel_s)
                logger.info("RADIANS: ObjectName : %s; Obj RA : %s; Obj DEC : %s" % (tel_s["OBJECTNAME"], tel_s["OBJRA"], tel_s["OBJDEC"]))

                logger.info("Running: PresetTelescope")
                statusl = obsController.PresetTelescope(tel_s)
                ufun.error_handler(statusl, "PresetTelescope")
            elif TEST == 720: # Do not use
                ########## TEST 720 : Synchronous OffsetPointing  ###########
                # tester.py -t SHINS_TEST_DEBUG --targs 720 -a1 OFFSETX -a2 OFFSETY -a3 COORDSYS (RADEC or AZALT or DETXY or GALACTIC)
                logger.info("########## TEST 720 : Synchronous OffsetPointing RADEC ###########")
                tel_s = {
                    "CoordinateSystem":"RADEC",
                    "BinocularFlag":"SYNCOFFSET",
                    "TelescopeSide": "right",
                    "MoveType" : "REL", # "REL", "ABS"

                    "OFFSETX" : "0.0001",
                    "OFFSETY" : "0.0001",

                }
                if(kwargs and kwargs["test_s1"] and kwargs["test_s2"] and kwargs["test_s3"]):
                    tel_s["OFFSETX"] = kwargs["test_s1"]
                    tel_s["OFFSETY"] = kwargs["test_s2"]
                    tel_s["CoordinateSystem"] = kwargs["test_s3"]
                obsController.sashaGetIndiMsges({"FTEST" : "3", "SEPARATOR" : "Synchronous Offset Pointing"})

                logger.info("Running: OffsetPointing")
                asyncr = obsController.begin_OffsetPointing(tel_s)
                tel_s["TelescopeSide"] = "left"
                tel_s["OFFSETX"] = "-0.0001"
                tel_s["OFFSETY"] = "-0.0001"
                asyncl = obsController.begin_OffsetPointing(tel_s)

                statusr = obsController.end_OffsetPointing(asyncr)
                statusl = obsController.end_OffsetPointing(asyncl)

                ufun.error_handler(statusl, "OffsetPointing")
            elif TEST == 721:
                ########## TEST 721 : Synchronous OffsetPointing  ###########
                # tester.py -t SHINS_TEST_DEBUG --targs 721 -a1 OFFSETX -a2 OFFSETY -a3 COORDSYS (RADEC or AZALT or DETXY or GALACTIC)
                logger.info("########## TEST 721 : Synchronous OffsetPointing RADEC ###########")
                tel_s = {
                    "CoordinateSystem":"RADEC",
                    "BinocularFlag":"SYNCOFFSET",
                    "TelescopeSide": "right",
                    "MoveType" : "REL", # "REL", "ABS"

                    "OFFSETX" : "0.0001",
                    "OFFSETY" : "0.0001",

                }
                if(kwargs and kwargs["test_s1"] and kwargs["test_s2"] and kwargs["test_s3"]):
                    tel_s["OFFSETX"] = kwargs["test_s1"]
                    tel_s["OFFSETY"] = kwargs["test_s2"]
                    tel_s["CoordinateSystem"] = kwargs["test_s3"]
                obsController.sashaGetIndiMsges({"FTEST" : "3", "SEPARATOR" : "Synchronous Offset Pointing"})

                logger.info("Running: OffsetPointing")
                statusr = obsController.OffsetPointing(tel_s)
                tel_s["TelescopeSide"] = "left"
                tel_s["OFFSETX"] = "-0.0001"
                tel_s["OFFSETY"] = "-0.0001"
                statusl = obsController.OffsetPointing(tel_s)

                ufun.error_handler(statusl, "OffsetPointing")
            elif TEST == 722:
                ########## TEST 722 : Synchronous OffsetPointing right right ###########
                # tester.py -t SHINS_TEST_DEBUG --targs 722
                obsController.sashaGetIndiMsges({"FTEST" : "3", "SEPARATOR" : "Test 722 Part 1"})
                logger.info("########## TEST 722 : Synchronous OffsetPointing RADEC right right ###########")
                tel_s = {
                    "CoordinateSystem":"RADEC",
                    "BinocularFlag":"SYNCOFFSET",
                    "TelescopeSide": "right",
                    "MoveType" : "REL", # "REL", "ABS"

                    "OFFSETX" : "0.0001",
                    "OFFSETY" : "0.0001",

                }
                if(kwargs and kwargs["test_s1"] and kwargs["test_s2"] and kwargs["test_s3"]):
                    tel_s["OFFSETX"] = kwargs["test_s1"]
                    tel_s["OFFSETY"] = kwargs["test_s2"]
                    tel_s["CoordinateSystem"] = kwargs["test_s3"]
                obsController.sashaGetIndiMsges({"FTEST" : "3", "SEPARATOR" : "Synchronous Offset Pointing"})

                logger.info("Running: OffsetPointing")
                statusr = obsController.OffsetPointing(tel_s)
#                tel_s["TelescopeSide"] = "left"
                tel_s["OFFSETX"] = "-0.0001"
                tel_s["OFFSETY"] = "-0.0001"
                try:
                    statusl = obsController.OffsetPointing(tel_s)
                except exception as e:
                    logger.error(e)
                except Exception as e:
#                    logging.error(traceback.format_exc())
                    logger.error(e)

                obsController.sashaGetIndiMsges({"FTEST" : "3", "SEPARATOR" : "Test 722 Part 2"})
                logger.info("########## TEST 722 Bis : Synchronous OffsetPointing RADEC left left ###########")
                tel_s = {
                    "CoordinateSystem":"RADEC",
                    "BinocularFlag":"SYNCOFFSET",
                    "TelescopeSide": "left",
                    "MoveType" : "REL", # "REL", "ABS"

                    "OFFSETX" : "0.0001",
                    "OFFSETY" : "0.0001",

                }
                if(kwargs and kwargs["test_s1"] and kwargs["test_s2"] and kwargs["test_s3"]):
                    tel_s["OFFSETX"] = kwargs["test_s1"]
                    tel_s["OFFSETY"] = kwargs["test_s2"]
                    tel_s["CoordinateSystem"] = kwargs["test_s3"]
                obsController.sashaGetIndiMsges({"FTEST" : "3", "SEPARATOR" : "Synchronous Offset Pointing"})

                logger.info("Running: OffsetPointing")
                statusr = obsController.OffsetPointing(tel_s)
                tel_s["TelescopeSide"] = "left"
                tel_s["OFFSETX"] = "-0.0001"
                tel_s["OFFSETY"] = "-0.0001"
                try:
                    statusl = obsController.OffsetPointing(tel_s)
                except exception as e:
                    logger.error(e)
                except Exception as e:
#                    logging.error(traceback.format_exc())
                    logger.error(e)

            elif TEST == 723:
                ########## TEST 723 : Preset in the middle of Synchronous OffsetPointing ###########
                # tester.py -t SHINS_TEST_DEBUG --targs 723
                logger.info("########## TEST 723 : Preset in the middle of Synchronous OffsetPointing RADEC ###########")
                tel_s = {
                    "CoordinateSystem":"RADEC",
                    "BinocularFlag":"SYNCOFFSET",
                    "TelescopeSide": "right",
                    "MoveType" : "REL", # "REL", "ABS"
                    "OFFSETX" : "0.000025",
                    "OFFSETY" : "0.000025",
                }
                obsController.sashaGetIndiMsges({"FTEST" : "3", "SEPARATOR" : "Preset in the middle of Synchronous Offset Pointing right"})

                logger.info("Running: OffsetPointing")
                statusr = obsController.OffsetPointing(tel_s)

                tel_s = {
                    "CoordinateSystem":"RADEC",
                    "Epoch":"2022.5",
                    "Equinox": "j2000",
                    "OBJEQUIN":"2000",

                    "OBJECTNAME":"Arcturus",
                    "OBJRA":"14 15 44.82",
                    "OBJDEC":"19 10 7.0",

                    "OBJMAG" : "1",
                    "PMRA":"0",
                    "PMDEC":"0",
                    "PMGSRA":"0",
                    "PMGSDEC":"0",
                    "PMAORA":"0",
                    "PMAODEC":"0",
                    "BinocularFlag":"SYNCPRESET",
                    "TelescopeMode": "ADAPTIVEACE_TRACK", # "TRACK"
                    "TelescopeSide": "right",
                    "AOMODE":"NORMAL" # NORMAL, REPOINT, SKIPREF, SKIPSTART, SKIPSTARTREPOINT, SKIPALL
                }

                tel_s = ufun.to_radians(tel_s)
                logger.info("Running: PresetTelescope")
                try:
                    statusr = obsController.PresetTelescope(tel_s)
                except Exception as e:
                    logger.error(e)

                ufun.error_handler(statusr, "OffsetPointing")

                obsController.sashaGetIndiMsges({"FTEST" : "3", "SEPARATOR" : "Preset in the middle of Synchronous Offset Pointing left"})
                logger.info("########## TEST 723 Part 2 : Preset in the middle of Synchronous OffsetPointing RADEC left ###########")
                tel_s = {
                    "CoordinateSystem":"RADEC",
                    "BinocularFlag":"SYNCOFFSET",
                    "TelescopeSide": "left",
                    "MoveType" : "REL", # "REL", "ABS"
                    "OFFSETX" : "0.000025",
                    "OFFSETY" : "0.000025",
                }
                logger.info("Running: OffsetPointing")
                statusr = obsController.OffsetPointing(tel_s)

                tel_s = {
                    "CoordinateSystem":"RADEC",
                    "Epoch":"2022.5",
                    "Equinox": "j2000",
                    "OBJEQUIN":"2000",

                    "OBJECTNAME":"Arcturus",
                    "OBJRA":"14 15 44.82",
                    "OBJDEC":"19 10 7.0",

                    "OBJMAG" : "1",
                    "PMRA":"0",
                    "PMDEC":"0",
                    "PMGSRA":"0",
                    "PMGSDEC":"0",
                    "PMAORA":"0",
                    "PMAODEC":"0",
                    "BinocularFlag":"SYNCPRESET",
                    "TelescopeMode": "ADAPTIVEACE_TRACK", # "TRACK"
                    "TelescopeSide": "right",
                    "AOMODE":"NORMAL"
                }

                tel_s = ufun.to_radians(tel_s)

                logger.info("Running: PresetTelescope")
                try:
                    statusr = obsController.PresetTelescope(tel_s)
                except Exception as e:
                    logger.error(e)

                ufun.error_handler(statusr, "OffsetPointing")
            elif TEST == 724:
                ########## TEST 724 : Synchronous OffsetPointing in the middle of a synchronous preset  ###########
                # tester.py -t SHINS_TEST_DEBUG --targs 724
                obsController.sashaGetIndiMsges({"FTEST" : "3", "SEPARATOR" : "Synchronous OffsetPointing in the middle of a synchronous preset"})
                logger.info("########## TEST 724 Part 1 : Synchronous OffsetPointing in the middle of a synchronous preset ###########")

                tel1_s = {
                    "CoordinateSystem":"RADEC",
                    "Epoch":"2022.5",
                    "Equinox": "j2000",
                    "OBJEQUIN":"2000",

                    "OBJECTNAME":"Arcturus",
                    "OBJRA":"14 15 44.82",
                    "OBJDEC":"19 10 7.0",

                    "OBJMAG" : "1",
                    "PMRA":"0",
                    "PMDEC":"0",
                    "PMGSRA":"0",
                    "PMGSDEC":"0",
                    "PMAORA":"0",
                    "PMAODEC":"0",
                    "BinocularFlag":"SYNCPRESET",
                    "TelescopeMode": "ADAPTIVEACE_TRACK", # "TRACK"
                    "TelescopeSide": "right",
                    "AOMODE":"NORMAL"
                }

                tel1_s = ufun.to_radians(tel1_s)

                logger.info("Running: PresetTelescope")
                statusr = obsController.PresetTelescope(tel1_s)
                ufun.error_handler(statusr, "PresetTelescope")

                tel_s = {
                    "CoordinateSystem":"RADEC",
                    "BinocularFlag":"SYNCOFFSET",
                    "TelescopeSide": "right",
                    "MoveType" : "REL", # "REL", "ABS"
                    "OFFSETX" : "0.0001",
                    "OFFSETY" : "0.0001",
                }

                logger.info("Running: OffsetPointing")
                try:
                    statusr = obsController.OffsetPointing(tel_s)
                except Exception as e:
                    logger.error(e)

                obsController.sashaGetIndiMsges({"FTEST" : "3", "SEPARATOR" : "Synchronous OffsetPointing in the middle of a synchronous preset"})
                logger.info("########## TEST 724 Part 2 : Synchronous OffsetPointing in the middle of a synchronous preset ###########")

                tel1_s["TelescopeSide"] = "left"
                obsController.sashaGetIndiMsges({"FTEST" : "3", "SEPARATOR" : "Preset Telescope"})

                logger.info("Running: PresetTelescope")
                statusr = obsController.PresetTelescope(tel1_s)
                ufun.error_handler(statusr, "PresetTelescope")

                logger.info("Running: OffsetPointing")
                try:
                    statusr = obsController.OffsetPointing(tel_s)
                except Exception as e:
                    logger.error(e)

                logger.info("Test 724 Finished")

            elif TEST == 725:
                ########## TEST 725 : Synchronous OffsetPointing  ###########
                # tester.py -t SHINS_TEST_DEBUG --targs 725)
                logger.info("########## TEST 725 : Synchronous OffsetPointing RADEC ###########")
                tel_s = {
                    "CoordinateSystem":"RADEC",
                    "BinocularFlag":"SYNCOFFSET",
                    "TelescopeSide": "right",
                    "MoveType" : "REL", # "REL", "ABS"

                    "OFFSETX" : "0.0001",
                    "OFFSETY" : "0.0001",

                }
                if(kwargs and kwargs["test_s1"] and kwargs["test_s2"] and kwargs["test_s3"]):
                    tel_s["OFFSETX"] = kwargs["test_s1"]
                    tel_s["OFFSETY"] = kwargs["test_s2"]
                    tel_s["CoordinateSystem"] = kwargs["test_s3"]
                obsController.sashaGetIndiMsges({"FTEST" : "3", "SEPARATOR" : "Synchronous Offset Pointing"})

                logger.info("Running: OffsetPointing")
                statusr = obsController.OffsetPointing(tel_s)
                tel_s["TelescopeSide"] = "left"
                tel_s["OFFSETX"] = "-0.0001"
                tel_s["OFFSETY"] = "-0.0001"
                statusl = obsController.OffsetPointing(tel_s)

                ufun.error_handler(statusl, "OffsetPointing")
            elif TEST == 726:
                ########## TEST 726 : Preset Telescope RADEC left sync  ###########
                # tester.py -t SHINS_TEST_DEBUG --targs 726 -a1 "14 15 44.82" -a2 "19 10 7.0" -a3 Arcturus
                logger.info("########## TEST 726 : Preset Telescope RADEC left sync ###########")
                tel_s = {
                    "CoordinateSystem":"RADEC",
                    "Epoch":"2022.5",
                    "Equinox": "j2000",
                    "OBJEQUIN":"2000",

                    "OBJECTNAME":"HD23432",
                    "OBJRA":"03 45 54.48",
                    "OBJDEC":"24 33 16.24",

                    "OBJMAG" : "1",
                    "PMRA":"0",
                    "PMDEC":"0",
                    "PMGSRA":"0",
                    "PMGSDEC":"0",
                    "PMAORA":"0",
                    "PMAODEC":"0",
                    "BinocularFlag":"SYNCPRESET",
                    "TelescopeMode": "TRACK", # "ADAPTIVEACE_TRACK", # "TRACK"
                    "TelescopeSide": "left",
                    "AOMODE":"NORMAL" # NORMAL, REPOINT, SKIPREF, SKIPSTART, SKIPSTARTREPOINT, SKIPALL
                }
                if(kwargs and kwargs["test_s1"] and kwargs["test_s2"]):
                    tel_s["OBJRA"] = kwargs["test_s1"]
                    tel_s["OBJDEC"] = kwargs["test_s2"]
                    tel_s["OBJECTNAME"] = "UNDEFINED"
                    if kwargs["test_s3"]:
                        tel_s["OBJECTNAME"] = kwargs["test_s3"]
                obsController.sashaGetIndiMsges({"FTEST" : "3", "SEPARATOR" : "Preset Telescope"})

#                tel_s["OBJECTNAME"] = "Arcturus"
                objra_degree = 15*(14 + 15/60. + 44.82/3600.)
#                tel_s["OBJRA"] = str(objra_degree*3.141592653/180)
                objdec_degree = 19 + 10/60. + 7.0/3600.
#                tel_s["OBJDEC"] = str(objdec_degree*3.141592653/180)

                logger.info("ObjectName : %s; Obj RA (°): %s; Obj DEC (°): %s" % (tel_s["OBJECTNAME"], str(objra_degree*3.141592653/180), str(objdec_degree*3.141592653/180)))
                logger.info("STRINGS: ObjectName : %s; Obj RA : %s; Obj DEC : %s" % (tel_s["OBJECTNAME"], tel_s["OBJRA"], tel_s["OBJDEC"]))
                tel_s = ufun.to_radians(tel_s)
                logger.info("RADIANS: ObjectName : %s; Obj RA : %s; Obj DEC : %s" % (tel_s["OBJECTNAME"], tel_s["OBJRA"], tel_s["OBJDEC"]))

                logger.info("Running: PresetTelescope")
                status = obsController.PresetTelescope(tel_s)
                ufun.error_handler(status, "PresetTelescope")
            elif TEST == 727:
                ########## TEST 727 : Preset Telescope RADEC right sync ###########
                # tester.py -t SHINS_TEST_DEBUG --targs 727 -a1 "14 15 44.82" -a2 "19 10 7.0" -a3 Arcturus
                logger.info("########## TEST 727 : Preset Telescope RADEC right sync ###########")
                tel_s = {
                    "CoordinateSystem":"RADEC",
                    "Epoch":"2022.5",
                    "Equinox": "j2000",
                    "OBJEQUIN":"2000",

                    "OBJECTNAME":"Arcturus",
                    "OBJRA":"14 15 44.82",
                    "OBJDEC":"19 10 7.0",

                    "OBJMAG" : "1",
                    "PMRA":"0",
                    "PMDEC":"0",
                    "PMGSRA":"0",
                    "PMGSDEC":"0",
                    "PMAORA":"0",
                    "PMAODEC":"0",
                    "BinocularFlag":"SYNCPRESET",
                    "TelescopeMode": "ADAPTIVEACE_TRACK", # "TRACK"
                    "TelescopeSide": "right",
                    "AOMODE":"NORMAL" # NORMAL, REPOINT, SKIPREF, SKIPSTART, SKIPSTARTREPOINT, SKIPALL
                }
                if(kwargs and kwargs["test_s1"] and kwargs["test_s2"]):
                    tel_s["OBJRA"] = kwargs["test_s1"]
                    tel_s["OBJDEC"] = kwargs["test_s2"]
                    tel_s["OBJECTNAME"] = "UNDEFINED"
                    if kwargs["test_s3"]:
                        tel_s["OBJECTNAME"] = kwargs["test_s3"]
                obsController.sashaGetIndiMsges({"FTEST" : "3", "SEPARATOR" : "Preset Telescope"})

#                tel_s["OBJECTNAME"] = "Arcturus"
                objra_degree = 15*(14 + 15/60. + 44.82/3600.)
#                tel_s["OBJRA"] = str(objra_degree*3.141592653/180)
                objdec_degree = 19 + 10/60. + 7.0/3600.
#                tel_s["OBJDEC"] = str(objdec_degree*3.141592653/180)

                logger.info("ObjectName : %s; Obj RA (°): %s; Obj DEC (°): %s" % (tel_s["OBJECTNAME"], str(objra_degree*3.141592653/180), str(objdec_degree*3.141592653/180)))
                logger.info("STRINGS: ObjectName : %s; Obj RA : %s; Obj DEC : %s" % (tel_s["OBJECTNAME"], tel_s["OBJRA"], tel_s["OBJDEC"]))
                tel_s = ufun.to_radians(tel_s)
                logger.info("RADIANS: ObjectName : %s; Obj RA : %s; Obj DEC : %s" % (tel_s["OBJECTNAME"], tel_s["OBJRA"], tel_s["OBJDEC"]))

                logger.info("Running: PresetTelescope")
                status = obsController.PresetTelescope(tel_s)
                ufun.error_handler(status, "PresetTelescope")
            elif TEST == 728:
                ########## TEST 728 : Synchronous OffsetPointing Single Sided left ###########
                # tester.py -t SHINS_TEST_DEBUG --targs 728 -a1 OFFSETX -a2 OFFSETY -a3 COORDSYS (RADEC or AZALT or DETXY or GALACTIC)
                logger.info("########## TEST 728 : Synchronous OffsetPointing RADEC Single Sided left ###########")
                tel_s = {
                    "CoordinateSystem":"RADEC",
                    "BinocularFlag":"SYNCOFFSET",
                    "TelescopeSide": "left",
                    "MoveType" : "REL", # "REL", "ABS"

                    "OFFSETX" : "0.0001",
                    "OFFSETY" : "0.0001",

                }
                if(kwargs and kwargs["test_s1"] and kwargs["test_s2"] and kwargs["test_s3"]):
                    tel_s["OFFSETX"] = kwargs["test_s1"]
                    tel_s["OFFSETY"] = kwargs["test_s2"]
                    tel_s["CoordinateSystem"] = kwargs["test_s3"]
                obsController.sashaGetIndiMsges({"FTEST" : "3", "SEPARATOR" : "Synchronous Offset Pointing"})

                logger.info("Running: OffsetPointing")
                statusl = obsController.OffsetPointing(tel_s)

                ufun.error_handler(statusl, "OffsetPointing")
            elif TEST == 729:
                ########## TEST 729 : Synchronous OffsetPointing Single Sided right ###########
                # tester.py -t SHINS_TEST_DEBUG --targs 729 -a1 OFFSETX -a2 OFFSETY -a3 COORDSYS (RADEC or AZALT or DETXY or GALACTIC)
                logger.info("########## TEST 729 : Synchronous OffsetPointing RADEC Single sided right ###########")
                tel_s = {
                    "CoordinateSystem":"RADEC",
                    "BinocularFlag":"SYNCOFFSET",
                    "TelescopeSide": "right",
                    "MoveType" : "REL", # "REL", "ABS"

                    "OFFSETX" : "-0.0001",
                    "OFFSETY" : "-0.0001",

                }
                if(kwargs and kwargs["test_s1"] and kwargs["test_s2"] and kwargs["test_s3"]):
                    tel_s["OFFSETX"] = kwargs["test_s1"]
                    tel_s["OFFSETY"] = kwargs["test_s2"]
                    tel_s["CoordinateSystem"] = kwargs["test_s3"]
                obsController.sashaGetIndiMsges({"FTEST" : "3", "SEPARATOR" : "Synchronous Offset Pointing"})

                logger.info("Running: OffsetPointing")
                statusr = obsController.OffsetPointing(tel_s)

                ufun.error_handler(statusr, "OffsetPointing")
            elif TEST == 72:
                ########## TEST 72 : Preset Telescope No AO   ###########
                # tester.py -t SHINS_TEST_DEBUG --targs 72 -a1 "14 15 44.82" -a2 "19 10 7.0" -a3 Arcturus
                logger.info("########## TEST 72 : Preset Telescope No AO ###########")
                tel_s = {
                    "CoordinateSystem":"RADEC",
                    "Epoch":"2022.5",
                    "Equinox": "j2000",
                    "OBJEQUIN":"2000",

                    "OBJECTNAME":"Arcturus",
                    "OBJRA":"14 15 44.82",
                    "OBJDEC":"19 10 7.0",

                    "OBJMAG" : "1",
                    "PMRA":"0",
                    "PMDEC":"0",
                    "PMGSRA":"0",
                    "PMGSDEC":"0",
                    "PMAORA":"0",
                    "PMAODEC":"0",
                    "BinocularFlag":"OFF",
                    "TelescopeMode": "TRACK",
                    "TelescopeSide": "LEFT",
                    "AOMODE":"OFF"
                }
                if(kwargs and kwargs["test_s1"] and kwargs["test_s2"]):
                    tel_s["OBJRA"] = kwargs["test_s1"]
                    tel_s["OBJDEC"] = kwargs["test_s2"]
                    tel_s["OBJECTNAME"] = "UNDEFINED"
                    if kwargs["test_s3"]:
                        tel_s["OBJECTNAME"] = kwargs["test_s3"]
                obsController.sashaGetIndiMsges({"FTEST" : "3", "SEPARATOR" : "Preset Telescope"})

#                tel_s["OBJECTNAME"] = "Arcturus"
                objra_degree = 15*(14 + 15/60. + 44.82/3600.)
#                tel_s["OBJRA"] = str(objra_degree*3.141592653/180)
                objdec_degree = 19 + 10/60. + 7.0/3600.
#                tel_s["OBJDEC"] = str(objdec_degree*3.141592653/180)

                logger.info("ObjectName : %s; Obj RA (°): %s; Obj DEC (°): %s" % (tel_s["OBJECTNAME"], str(objra_degree*3.141592653/180), str(objdec_degree*3.141592653/180)))

                logger.info("STRINGS: ObjectName : %s; Obj RA : %s; Obj DEC : %s" % (tel_s["OBJECTNAME"], tel_s["OBJRA"], tel_s["OBJDEC"]))

                tel_s = ufun.to_radians(tel_s)

                logger.info("RADIANS: ObjectName : %s; Obj RA : %s; Obj DEC : %s" % (tel_s["OBJECTNAME"], tel_s["OBJRA"], tel_s["OBJDEC"]))

                logger.info("Running: PresetTelescopeNoAO")
                status = obsController.PresetTelescope(tel_s)
                ufun.error_handler(status, "PresetTelescope")
            elif TEST == 73:
                ########## TEST 73 : Derotator Backlash Procedure ###########
                # tester.py -t SHINS_TEST_DEBUG --targs 73
                logger.info("########## TEST 73 : Derotator Backlash Procedure ###########")
                obsController.sashaGetIndiMsges({"FTEST" : "3", "SEPARATOR" : "Derotator Backlash Procedure"})

                logger.info("Running: Derotator Backlash Procedure")
                statusr = obsController.sharkDerotatorBacklashProcedure()

                ufun.error_handler(statusr, "sharkDerotatorBacklashProcedure")
            elif TEST == 90:
                rtc_s = {}
                rtc_s["TTDOWNLOADDSPCODE"] = "true"
                rtc_s["TTM2CFILE"] =  "ZONAL" # "20220603-Zernike-FullPupil-Arcetri-1u-rms-4rtc.dat" # "ALPAO97-M2C_matrix.fits"
                rtc_s["TTACTUATORMAPFILE"] = "BAX479-DM97-map.dat"
                rtc_s["TTACTUATORSIGNMAPFILE"] = "BAX479-DM97-sign.dat"
                rtc_s["TTBIASFILE"] = "dark64x64_1000Hz+20deg_14_02_22.dat"
                rtc_s["TTCAMTINT"] = "0.009994919"
                rtc_s["TTCENTROIDGAINX"] = "-4.249796"
                rtc_s["TTCENTROIDGAINY"] = "3.7651188"
                rtc_s["TTCENTROIDORIGX"] = "-0.0000"
                rtc_s["TTCENTROIDORIGY"] = "0.0000"
                rtc_s["TTDIAGDECIMATION"] = "0"
                rtc_s["TTDIAGENABLED"] = "true" # or "1"
                rtc_s["TTDIAGRECORDIPV4"] = "192.168.61.113"
                rtc_s["TTDIAGRECORDMAC"] = "4c:d9:8f:a0:22:44" # "4C:D9:8F:A0:22:43"
                rtc_s["TTDMFLATFILE"] = "zeri.txt" # "dm_shape_2023-03-20-16-19-46_int_138b_90el_T-4C_0as.txt"
                rtc_s["TTDIAGRECORDPORT"] = "8001"
                rtc_s["TTDMMAXPOWER"] = "10"
                rtc_s["TTDMOUTPUTENABLED"] = "1"
                rtc_s["TTFRAMERATE"] = "100"
                rtc_s["TTHISTORYENABLED"] = "0"
                rtc_s["TTLOOPENABLED"] = "0"
                rtc_s["TTMASTERDECENABLED"] = "true"
                rtc_s["TTMAXCENTROIDVAL"] = "+1"
                rtc_s["TTMAXTTCOMMAND"] = "3"
                rtc_s["TTMINCENTROIDVAL"] = "-1"
                rtc_s["TTMINTHRESHOLD"] = "100"
                rtc_s["TTMINTTCOMMAND"] = "-3"
                rtc_s["TTNSLOPEPIXELS"] = "4096"
                rtc_s["TTPIXELDECIMATION"] = "1"
                rtc_s["TTPIXELENABLED"] = "1"
                rtc_s["TTPIXELGAINFILE"] = "flat_gain_64x64.dat"
                rtc_s["TTPIXELGAINMODE"] = "FLATGAIN" # POINTGAIN FLATGAIN FILEGAIN
                rtc_s["TTRTCMDENABLED"] = "0"
                rtc_s["TTTIMEHISTLEN"] = "50000"
                rtc_s["TTTIMEHISTORYFILE"] = "TimeHistory.dat"
                rtc_s["TTWINCOLS"] = "64"
                rtc_s["TTWINCOORDX"] = "224"
                rtc_s["TTWINCOORDY"] = "212"
                rtc_s["TTWINROWS"] = "64"

                ########################
                # REAL-TIME RTCTT INIT #
                ########################
                status = obsController.RTCTTInit(rtc_s)

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

                #########################
                # START REAL-TIME RTCTT #
                #########################
                time.sleep(1)
                logger.info("RTCTT start")
                status = obsController.RTCTTStart()
                logger.debug(status)
                ufun.error_handler(status, "RTCTTStart")

            elif TEST == 91:

                obsController.initMotion(["SCI_FILT_W2", "SCI_FILT_W1", "ND_FILT_W", "LYOT_GRISM_W", "DB_FILT_W", "CORO_SLIT_W", "APODIZER_W"])
                instrument_setup = {"CAL_FIBER_DEP":"FOCUS_IN", "CAL_FIBER_FOCUS_LAMP":"ON", "PRISM1":"min_disp", "PRISM2":"min_disp"}
                obsController.setupInstrument(instrument_setup)

                wheel_setup = {"SCI_FILT_W2":"NB_ContH", "SCI_FILT_W1":"HOLE2", "ND_FILT_W":"OD2", "LYOT_GRISM_W":"HOLE", "DB_FILT_W":"H2-H3", "CORO_SLIT_W":"HOLE", "APODIZER_W":"HOLE"}
                obsController.setupInstrument(wheel_setup)

            elif TEST  == 92:
                status = 0
                num_actuators = 97
                actuator_range = 0.15
                actuator_steps = 9
                step_size = 2*actuator_range/(actuator_steps - 1)

                sasha_setup = {"InstrumentMode":"TestF", "OBJECTNAME":"Test", "NCOADDS":"1", "NREADS":"1", "NRESETS":"1", "NDIT":"9", "NGROUPS":"1", "NDROPS":"0", "SAVE":"0", "READOUT":"128x128"}

                full_command = [0 for ii in range(num_actuators + 2)]
                obsController.RTCTTModeUpload(full_command, True)
                sasha_setup["InstrumentMode"] = ("%d_%d" % (0, 0))
                obsController.sashaSetup(sasha_setup)
                status , file_name = obsController.sashaExpose()
                logger.info("Saved file : %s" % file_name)
                for i in range(num_actuators):
                    for j in range(9):
                        command = -actuator_range + j*step_size
                        full_command = [0 for ii in range(num_actuators + 2)]
                        full_command[2 + i] = command
                        obsController.RTCTTModeUpload(full_command, True)
                        sasha_setup["InstrumentMode"] = ("%d_%d" % (i + 1, j + 1))
                        obsController.sashaSetup(sasha_setup)
                        status , file_name = obsController.sashaExpose()
                        logger.info("Saved file : %s" % file_name)

                full_command = [0 for ii in range(num_actuators + 2)]
                obsController.RTCTTModeUpload(full_command, True)

                instrument_setup = {"CAL_FIBER_DEP":"NOFIBER", "CAL_FIBER_FOCUS_LAMP":"OFF", "PRISM1":"0", "PRISM2":"0"}
                obsController.setupInstrument(instrument_setup)
                wheel_setup = {"SCI_FILT_W2":"HOLE", "SCI_FILT_W1":"HOLE", "ND_FILT_W":"HOLE", "LYOT_GRISM_W":"HOLE", "DB_FILT_W":"WINDOW", "CORO_SLIT_W":"HOLE", "APODIZER_W":"HOLE"}
                obsController.setupInstrument(wheel_setup)
            elif TEST  == 93:
                status = 0
                num_actuators = 97
                actuator_range = 0.15
                actuator_steps = 4
                step_size = 2*actuator_range/(actuator_steps - 1)

                sasha_setup = {"InstrumentMode":"TestF", "OBJECTNAME":"Test", "NCOADDS":"1", "NREADS":"1", "NRESETS":"1", "NDIT":"9", "NGROUPS":"1", "NDROPS":"0", "SAVE":"0", "READOUT":"128x128"}

                FAST_SAVING_MODE = 8
                obsController.setFlags(FAST_SAVING_MODE, 0)

                full_command = [0 for ii in range(num_actuators + 2)]
                obsController.RTCTTModeUpload(full_command, True)
                sasha_setup["InstrumentMode"] = ("%d_%d" % (0, 0))
                obsController.sashaSetup(sasha_setup)
                status , file_name = obsController.sashaExpose()
                logger.info("Saved file : %s" % file_name)
                for i in range(num_actuators):
                    for j in range(acutator_steps):
                        command = -actuator_range + j*step_size
                        full_command = [0 for ii in range(num_actuators + 2)]
                        full_command[2 + i] = command
                        obsController.RTCTTModeUpload(full_command, True)
                        sasha_setup["InstrumentMode"] = ("%02d_%02d" % (i + 1, j + 1))
                        obsController.sashaSetup(sasha_setup)
                        status , file_name = obsController.sashaExpose()
                        logger.info("Saved file : %s" % file_name)

                toadd = {6, 8, 10, 11}
                selection = {6, 13, 22}
                for i in range(43):
                    for j in range(actuator_steps):
                        command1 = -actuator_range + j*step_size
                        for k in range(actuator_steps):
                            command2 = -actuator_range + j*step_size
                            full_command = [0 for ii in range(num_actuators + 2)]
                            full_command[2 + i] = command1
                            next = i + toadd[0]
                            if i < selection[0]:
                                next = i + toadd[0]
                            else:
                                if i < selection[1]:
                                    next = i + toadd[1]
                                else:
                                    if i < selection[2]:
                                        next = i + toadd[2]
                                    else:
                                        next = i + toadd[3]
                            full_command[2 + i + next] = command2
                            obsController.RTCTTModeUpload(full_command, True)
                            sasha_setup["InstrumentMode"] = ("%02d_%02d_%02d" % (i + 1, j + 1), k + 1)
                            obsController.sashaSetup(sasha_setup)
                            status , file_name = obsController.sashaExpose()
                            logger.info("Saved file : %s" % file_name)
                    for j in range(actuator_steps):
                        command1 = -actuator_range + j*step_size
                        for k in range(actuator_steps):
                            command2 = -actuator_range + j*step_size
                            full_command = [0 for ii in range(num_actuators + 2)]
                            full_command[2 + (96 - i)] = command1
                            next = (97 - i) - toadd[0]
                            if i < selection[0]:
                                next = (96 - i) - toadd[0]
                            else:
                                if i < selection[1]:
                                    next = (96 - i) - toadd[1]
                                else:
                                    if i < selection[2]:
                                        next = (96 - i) - toadd[2]
                                    else:
                                        next = (96 - i) - toadd[3]
                            full_command[2 + next] = command2
                            obsController.RTCTTModeUpload(full_command, True)
                            sasha_setup["InstrumentMode"] = ("%02d_%02d_%02d" % (97 - i, j + 1), k + 1)
                            obsController.sashaSetup(sasha_setup)
                            status , file_name = obsController.sashaExpose()
                            logger.info("Saved file : %s" % file_name)

                full_command = [0 for ii in range(num_actuators + 2)]
                obsController.RTCTTModeUpload(full_command, True)

                obsController.unsetFlags(FAST_SAVING_MODE, 0)

                instrument_setup = {"CAL_FIBER_DEP":"NOFIBER", "CAL_FIBER_FOCUS_LAMP":"OFF", "PRISM1":"0", "PRISM2":"0"}
                obsController.setupInstrument(instrument_setup)
                wheel_setup = {"SCI_FILT_W2":"HOLE", "SCI_FILT_W1":"HOLE", "ND_FILT_W":"HOLE", "LYOT_GRISM_W":"HOLE", "DB_FILT_W":"WINDOW", "CORO_SLIT_W":"HOLE", "APODIZER_W":"HOLE"}
                obsController.setupInstrument(wheel_setup)


            else :
                logger.error("Unrecognized Test Number")





        except Basda.ServiceException as e:
            logger.error("Service Exception was thrown during instrument setup {}".format(e.errmsg))
            self.status = uvars.EXIT_FAILURE
        except exception.TemplateException as e:
            logger.error(e)
            raise e
        except exception as e:
            logger.error(e)
            raise e
        except StandardError as e:
            logger.error(e)
            raise e

        return self.status



def SHINS_TEST_DEBUG(ins_s=None, det_s=None, tel_s=None, rtc_s=None, **kwargs):
    """
    Test template, listening on Indi In channel

    Parameters not used
    ----------
    ins_s : instument setup dictionary; keys are tags from OB file
    det_s : detector setup dictionary; keys are tags from OB file
    tel_s : telescope setup dictionary; keys are tags from OB file
    rtc_s : real-time control system dictonary; keys are tags from OB file
    **kwargs : optional dictionary with additional control keywords.
               E.g. {"EXIT":False} is used to prevent template to call
               sys.exit() method

    Returns
    -------
    Integer value with status of operation:
    0 for success
    1 for failure
    """

    
    logger.info('SHINS_TEST_DEBUG: begin')
    
    app = SHINS_TEST_DEBUG_App()
    if not (uvars.filenameSHINS in kwargs.keys()):
        kwargs[uvars.filenameSHINS] = SHINS_TEST_DEBUG.__name__
    status = app.main(ins_s, det_s, tel_s, rtc_s, **kwargs)

    logger.info('SHINS_TEST_DEBUG: end')
    return status


if __name__ == "__main__":
    SHINS_TEST_DEBUG(ins_s=None, det_s=None, tel_s=None, rtc_s=None, **kwargs)
