


# %% Initialization

from tpl.shinsapp import SHINSApp
from astropy.tim import Time, TimeDelta
from util import functions as ufun

os = SHINSApp().os()




# %% Telescope Preset

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

    "OBJECTNAME":"Kocham",
    "OBJRA":"14 50 43.66",
    "OBJDEC":"74 08 59.6",

    "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
}


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")



# %% Start Derotation Now

# tester.py -t SHINS_TEST_DEBUG --targs 63

ins_s = {}
ins_s["DROT_Mode"] = "FIELD_FREE" # FIELD_FREE, FIELD_FIXED, PUPIL
os.sashaGetIndiMsges({"FTEST" : "3", "SEPARATOR" : "Start Tracking"})
self.status = os.setupInstrument(ins_s)
dateMjd = Time.now()
# dateMjd = dateMjd # + TimeDelta(120, format='sec')
self.status = os.trackingStart2(dateMjd.mjd, 0)




