#!/usr/bin/python

import time
import sys
import subprocess


def test_standby():
    """
    In the WaitStandby State, simulate PLC STANDBY signal.
    Turn on FHPS by push auto-on button.
    Turn on SCM PSs automatically.
    State transition condition is checked at last.
    """
    print '---------- Start WatiStandby test ----------'
    print '1. Simulate SELECT signal. State should go to WatiStandby from Disabled.'
    #res = subprocess.call('caput EC-GN-P01-GPS:PLC4110-CON-OPGY1.SVAL 1', shell=True)
    #res = subprocess.call('caput EC-GN-P01-GPS:PLC4110-CON-OPGY1 1', shell=True)
    res = subprocess.call('caput EC-GN-P01-GPS:PLC4110-CON-OPGY2.SVAL 1', shell=True)
    res = subprocess.call('caput EC-GN-P01-GPS:PLC4110-CON-OPGY2 1', shell=True)
    print 'Enter to continue test'
    inpval = raw_input()
    print '2. Set MCPS rampup parameter(target current, sweep rate.)'
    res = subprocess.call('caput EC-GN-P01-GAF-MCPS:PSU2120-TRG-CURR-SET-MI 4', shell=True) #For A
    res = subprocess.call('caput EC-GN-P01-GAF-MCPS:PSU2120-TRG-SWPR-SET 1.69', shell=True)
    res = subprocess.call('caput EC-GN-P01-GAF-GCPS:PSU2130-TRG-CURR-SET-MI 4', shell=True)
    res = subprocess.call('caput EC-GN-P01-GAF-GCPS:PSU2130-TRG-SWPR-SET 1.0', shell=True)
    res = subprocess.call('caput EC-GN-P01-GBF-MCPS:PSU2120-TRG-CURR-SET-MI 4', shell=True) #For B
    res = subprocess.call('caput EC-GN-P01-GBF-MCPS:PSU2120-TRG-SWPR-SET 1.69', shell=True)
    res = subprocess.call('caput EC-GN-P01-GBF-GCPS:PSU2130-TRG-CURR-SET-MI 4', shell=True)
    res = subprocess.call('caput EC-GN-P01-GBF-GCPS:PSU2130-TRG-SWPR-SET 1.0', shell=True)
    time.sleep(1)
    print '3. Simulate STANDBY signal. MCPS, GCPS, FHPS rampup must be started.'
    #res = subprocess.call('caput EC-GN-P01-GPS:PLC4110-YTS-ST1R.SVAL 1', shell=True)
    #res = subprocess.call('caput EC-GN-P01-GPS:PLC4110-YTS-ST1R 1', shell=True)
    print 'Enter to continue test'
    inpval = raw_input()
    print '4. Set FHPS rampup parameter and start it.'
    #res = subprocess.call('caput EC-GN-P01-GAF-FHPS:PSU2610-AUTO-TAGV 6', shell=True)
    #res = subprocess.call('caput EC-GN-P01-GAF-FHPS:PSU2610-AUTO-RU-TIME 60', shell=True) #in second.
    #res = subprocess.call('caput EC-GN-P01-GAF-FHPS:PSU2610-AUTO-START 1', shell=True) #in second.
    #res = subprocess.call('caput EC-GN-P01-GBF-FHPS:PSU2610-AUTO-TAGV 6', shell=True)
    #res = subprocess.call('caput EC-GN-P01-GBF-FHPS:PSU2610-AUTO-RU-TIME 60', shell=True) #in second.
    #res = subprocess.call('caput EC-GN-P01-GBF-FHPS:PSU2610-AUTO-START 1', shell=True) #in second.
    print 'Enter to continue test'
    inpval = raw_input()
    print '5. Simulate FHPS, MCPS and GCPS state.'
    res = subprocess.call('caput EC-GN-P01-GAF-MCPS:PSU2120-ACT-RB.SVAL 3', shell=True)
    res = subprocess.call('caput EC-GN-P01-GAF-MCPS:PSU2120-ACT-RB 3', shell=True)
    res = subprocess.call('caput EC-GN-P01-GAF-MCPS:PSU2120-CURR-MON.SVAL 4', shell=True)
    res = subprocess.call('caput EC-GN-P01-GAF-MCPS:PSU2120-CURR-MON 4', shell=True)
    #res = subprocess.call('caput EC-GN-P01-GAF-GCPS:PSU2130-ACT-RB.SVAL 3', shell=True)  #turn off for GCPS test
    #res = subprocess.call('caput EC-GN-P01-GAF-GCPS:PSU2130-ACT-RB 3', shell=True)       #turn off for GCPS test
    #res = subprocess.call('caput EC-GN-P01-GAF-GCPS:PSU2130-CURR-MON.SVAL 4', shell=True)#turn off for GCPS test
    #res = subprocess.call('caput EC-GN-P01-GAF-GCPS:PSU2130-CURR-MON 4', shell=True)     #turn off for GCPS test
    #res = subprocess.call('caput EC-GN-P01-GAF-FHPS:PSU2610-OUTON-RB.SVAL 1', shell=True)
    #res = subprocess.call('caput EC-GN-P01-GAF-FHPS:PSU2610-OUTON-RB 1', shell=True)
    #res = subprocess.call('caput EC-GN-P01-GAF-FHPS:PSU2610-MEAS-ACV.SVAL 6', shell=True) 
    #res = subprocess.call('caput EC-GN-P01-GAF-FHPS:PSU2610-MEAS-ACV 6', shell=True)     

    res = subprocess.call('caput EC-GN-P01-GBF-MCPS:PSU2120-ACT-RB.SVAL 3', shell=True)
    res = subprocess.call('caput EC-GN-P01-GBF-MCPS:PSU2120-ACT-RB 3', shell=True)
    res = subprocess.call('caput EC-GN-P01-GBF-MCPS:PSU2120-CURR-MON.SVAL 4', shell=True)
    res = subprocess.call('caput EC-GN-P01-GBF-MCPS:PSU2120-CURR-MON 4', shell=True)
    res = subprocess.call('caput EC-GN-P01-GBF-GCPS:PSU2130-ACT-RB.SVAL 3', shell=True)  #turn off for GCPS test
    res = subprocess.call('caput EC-GN-P01-GBF-GCPS:PSU2130-ACT-RB 3', shell=True)       #turn off for GCPS test
    res = subprocess.call('caput EC-GN-P01-GBF-GCPS:PSU2130-CURR-MON.SVAL 4', shell=True)#turn off for GCPS test
    res = subprocess.call('caput EC-GN-P01-GBF-GCPS:PSU2130-CURR-MON 4', shell=True)     #turn off for GCPS test
    res = subprocess.call('caput EC-GN-P01-GBF-FHPS:PSU2610-OUTON-RB.SVAL 1', shell=True)
    res = subprocess.call('caput EC-GN-P01-GBF-FHPS:PSU2610-OUTON-RB 1', shell=True)
    res = subprocess.call('caput EC-GN-P01-GBF-FHPS:PSU2610-MEAS-ACV.SVAL 6', shell=True) 
    res = subprocess.call('caput EC-GN-P01-GBF-FHPS:PSU2610-MEAS-ACV 6', shell=True)   
    time.sleep(1)
    print '6. Confirm FHPS and SCM ramp-up complete. The state goes to WaitREADY from WaitStandby.'
    print '---------- END WaitStandby test ----------'

