#!/usr/bin/python

import time
import sys
import subprocess

import test_async
import test_sync
import test_ready_hw
import test_setup_hw
import test_standby_hw
import test_ready
import test_setup
import test_standby

#
# Some EPICS PVs need to be simulation mode when we test code without PXI board.
# When user uses sim mode, new value must be written into PV.SVAL and PV itselfself.
#
print '### Start State Machine Sequence Test ###'

print '---------- Pre setup for the test ----------'
test_setup.test_setup()
#test_setup_hw.test_setup()

print 'Enter to continue test:'
inpval = raw_input()
################################################################################
# set SELECT and STANDBY signal
################################################################################
print '---------- WatiStandby test ----------'
test_standby.test_standby()
#test_standby_hw.test_standby()

print 'Enter to continue test'
inpval = raw_input()

################################################################################
# set READY and CCPS_ON_REQUEST signal
################################################################################
print '---------- WatiReady test ----------'
test_ready.test_ready()
#test_ready_hw.test_ready()

print 'Enter to continue test'
inpval = raw_input()
################################################################################
# set PERMIT and ON  signal
################################################################################
print 'Simulate PERMIT signal. State should go to WaitHVON state'
while(1):
    print '''Select test type and push enter key:
        1: GYA / Async mode
        2: GYB / Async mode
        3: Two Gyrotron operation
        4: Mode limit detection
        5: Short pulse
        6: Long pulse
        7: PrePro operation
        8: SYNC mode operation
        9: GYA / Async mode --- operator set delay and pulse length on HMI
        10: GYB / Async mode --- operator set delay and pulse length on HMI
    '''
    inpval = raw_input()

    if inpval == "1":
        test_async.test_async_GYA()
    elif inpval == "2":
        test_async.test_async_GYB()
    elif inpval == "3":
        test_async.test_async_both()
    elif inpval == "4":
        test_async.test_async_limit()
    elif inpval == "5":
        test_async.test_async_shortpulse()
    elif inpval == "6":
        test_async.test_async_longpulse()
    elif inpval == "7":
        test_async.test_async_prepro()
    elif inpval == "8":
        test_sync.test_sync()
    elif inpval == "9":
        test_async.test_async_GYA_manual()
    elif inpval == "10":
        test_async.test_async_GYB_manual()
    else:
        print 'invalid value. Enter 1 to 10!'
        continue

print '..... End of test code .....'
