# $Header: https://oberon.oapd.inaf.it/shins/trunk/shins/src/scripts/templates/tpl/test_instrument_setup.py 3710 2021-08-17 16:03:12Z depa $

import sys

def test_instrument_setup():
    print('test_instrument_setup')
    status = 0
    ic = None  # Ice Communicator
    try:
        ic = Ice.initialize(sys.argv)
        base = ic.stringToProxy("ObsControlAdapterSeq:default -p 10500")
        obsController = sharknir.obsControl.SequencerPrx.checkedCast(base)

        if (not obsController):
            raise RuntimeError("Invalid Proxy")
    except:
        traceback.print_exc()
        status = 1

    ins_sup = {'PUPIL_LENS_DEP': 'IN',
               'INBEAM_TT': 'center'}
    time_out = long(120000)  # Ice.Unset
    print("Start ...")
    status = obsController.setupInstrumentStart(ins_sup)
    status = obsController.setupInstrumentWait(ins_sup, time_out)
    print("End ...")
    ins_sup = {'PUPIL_LENS_DEP': 'OUT',
               'INBEAM_TT': 'NPOS 2'}
    print("Start ...")
    status = obsController.setupInstrumentStart(ins_sup)
    status = obsController.setupInstrumentWait(ins_sup, time_out)
    print("End ...")
    print("Start ...")
    ins_sup.clear()
    ins_sup = {'INBEAM_TT_X': npr.ranf()*17,
               'INBEAM_TT_Y': npr.ranf()*17}
    print (ins_sup)
    status = obsController.setupInstrumentAbsolutePositionStart(ins_sup, "MM")
    status = obsController.setupInstrumentAbsolutePositionWait(ins_sup, time_out)
    print("End ...")
    if ic:
        # Clean up
        try:
            ic.destroy()
        except:
            #traceback.print_exc()
            status = 1
            print('SHARKNIR_ci_acq: end')
            logger.info('SHARKNIR_ci_acq: end')

    pass

if __name__ == '__main__':
    test_instrument_setup()
