;+
; Project     :	SOHO - CDS
;
; Name        :	SAFE_SLIT
;
; Purpose     :	Write out backup slit commands to series file to cure oscillation problem.
;
; Explanation :	Use of prime slit position or slit number commands can result in the slit motor
;               not switching off. Use of backup slit commands forces the motor to turn off.
;               In order to use backup commands, MCU backup must first be turned off because this
;               translates all commands into prime commands.
;
;               Perl script uses format required by CB5FILS i.e token list for getpar :
;
;               1) COMMAND 1 2 3 4                    # simple scc
;
;               2) SCRIPT                             # script
;                  0x1 
;                  0x2
;                  TERMINATE
;
;               NB All commands or scripts must be to macro and so begin CB5* ...
;               Perl script need format:
;              
; Use         : <safe_slit, /SERIES>
;
; Inputs      : None.
;
; Opt. Inputs : unit     : INT logical unit no. for TTC file.
;               timenow  : DOUBLE current TAI time in deferred copmmand store.
;               commands : INT no. of commands used in deferred command store.
;
; Outputs     : Writes commands to series file.
;
; Opt. Outputs:	None.
;
; Keywords    : /SERIES : indicates that commands sent to series table file.
;               /TTC    : indicates that commands sent to deferred command store.
;
; Calls       :	shorthex, fileout, macro_wait.
;                
; Common      :	None.
;
; Restrictions:	None.
;
; Side effects:	None.
;
; Category    :	Command preparation.
;
; Prev. Hist. :	None.
;
; Written     :	Version 0.0, Martin Carter, RAL, 18/10/96
;
; Modified    :	Version 0.1, Martin Carter, RAL, 26/11/96
;                 Added 10 sec delay before sending MCU BACKUP disable command
;                 to allow monitoring of slit power.
;               Version 0.2, Martin Carter, RAL, 28/11/96
;                 Added extra 10 sec delay after sending slit down command to allow 
;                 monitoring and moved slit power monitoring delay to after MCU backup disable.
;               Version 0.3, MKC, 21/1/97
;                 Turned off safe slit commands to allow flight code patch to operate.
; Version     :	Version 0.3, 21/1/97
;-
;**********************************************************

PRO safe_slit, SERIES=series, TTC=ttc, unit, timenow, commands

  RETURN ; omit safe slit commands

  IF KEYWORD_SET(series) THEN BEGIN

    ; send slit step up and down commands

    fileout, words=3, 'CB5SIC' + '          # turn off MCU backup mode' 
    fileout, 'CB2DIS'
    fileout, 'TERMINATE'
    fileout, ''

    ; delay for monitoring slit power

    macro_wait, 10000
    fileout, ''  

    fileout, words=3, 'CB5SIC' + '          # send slit up' 
    fileout, 'CBMSLITU'
    fileout, 'TERMINATE'
    fileout, ''

    ; delay for monitoring slit up

    macro_wait, 10000
    fileout, ''  

    fileout, words=3, 'CB5SIC' + '          # send slit down' 
    fileout, 'CBMSLITD'
    fileout, 'TERMINATE'
    fileout, ''

    ; delay for monitoring slit down

    macro_wait, 10000
    fileout, ''  

    fileout, words=3, 'CB5SIC' + '          # turn on MCU backup mode' 
    fileout, 'CB2EN'
    fileout, 'TERMINATE'
    fileout, ''

  ENDIF ELSE IF KEYWORD_SET(ttc) THEN BEGIN

    PRINTF, unit, '#  safe slit motor'
    PRINTF, unit

    PRINTF, unit, '#  turn off MCU backup'
    PRINTF, unit
    PRINTF, unit, '"', tai2utc ( timenow, /ECS),'"   "CB2DIS"'
    PRINTF, unit
                      
    PRINTF, unit, '#  wait 10 secs to monitor slit power'
    PRINTF, unit

    timenow = timenow + 10.0 

    commands = commands + 4  ;  increment no. of INT16 words used in deferred command store by entry

    PRINTF, unit, '#  tell mcu to step slit up'
    PRINTF, unit
    PRINTF, unit, '"', tai2utc ( timenow, /ECS),'"   "CBMSLITU"'
    PRINTF, unit
                      
    PRINTF, unit, '#  wait 10 secs to monitor slit step up'
    PRINTF, unit

    timenow = timenow + 10.0 

    commands = commands + 4  ;  increment no. of INT16 words used in deferred command store by entry

    PRINTF, unit, '#  tell mcu to step slit down'
    PRINTF, unit
    PRINTF, unit, '"', tai2utc ( timenow, /ECS),'"   "CBMSLITD"'
    PRINTF, unit
                      
    PRINTF, unit, '#  wait 10 secs to monitor slit step down'
    PRINTF, unit

    timenow = timenow + 10.0 

    commands = commands + 4  ;  increment no. of INT16 words used in deferred command store by entry

    PRINTF, unit, '#  turn on MCU backup'
    PRINTF, unit
    PRINTF, unit, '"', tai2utc ( timenow, /ECS),'"   "CB2EN"'
    PRINTF, unit
                      
    timenow = timenow + 1 ; wait 1 sec

    commands = commands + 4  ;  increment no. of INT16 words used in deferred command store by entry

  ENDIF

END

