###CHECKPOINT ARGS: -nolog-flow -nolog-blocks -nostartlog
program "%Z% MODULE: %M% RELEASE: %R%.%L% CREATED: %G% %U%"
source "/mdisw/cfl/flight/src/checkiss_v03.src"
descr "checkiss - check for proper ISS state to be able to use it"
# program checkiss.src, created 95.12.14 Igor Zayer 
#	96.01.23  (IZ)	added checkpoint options
#
# Part of alignment procedure; read ISS parameters to assure the
# proper parameters are set. Called by 'setup_iss'. Turn ON ISS
# if needed. Set pre-amp gain to LOW and offsets to FINE in any case.
#
# Calls: (iss_on), check_errsig, log_iss_par
# ------
#
# Variable usage:
#----------------
# !GI8: 'error signal nulled' indicator (0 = not nulled, 1 = OK to lock ISS)
# !GS6: 'OK to proceed with ISS' indicator (= "enable ISS" if OK)
# !GS9: name of user logfile
#----------------

display "Executing procedure checkiss"
write  !GS9 "Executing procedure checkiss :"
write  !GS9 " %s" !DATE
writen !GS9 " %s" !TIME

## LOG INITIAL ISS STATUS
perform  log_iss_par_v02

## DON'T ASSUME ANYTHING: DISABLE !GS6 STRING
setstr !GS6 = "  "

## TURN ISS ON PROPERLY IF NECESSARY
if getdig(mkpwlt) <> "          ON" then
  beep
  beep
  display " ISS is NOT ON!"
  writen !GS9 " ISS is not ON..."
  menu !LS0 "Turn ISS ON properly?" "YES, turn ISS ON" "No, just QUIT!!"
  if !LS0 = "No, just QUIT!!" then
    goto giveup
  end if
  perform  iss_on_v01
  ###sync hk###
  ## SEE IF WE SUCCEEDED TO TURN POWER ON
  if getdig(mkpwlt) <>  "          ON" then
    beep
    beep
    display "Failed to power up ISS!!"
    writen !GS9 " Failed to power up ISS!!"
    goto giveup
  end if
  perform  check_errsig_v02
  goto good 
end if

## NOW CHECK THE ALIGNMENT
perform  check_errsig_v02

## SEE WHAT THE LOOP DOES
if getdig(mkltloop) = "       CLOSE" then
  if !GI8 = 1 then
    beep
    writen !GS9 " ISS loop is closed and alignment seems good!"
    display " ISS loop is closed and alignment seems good!"
    menu !LS0 "Leave ISS locked?" "leave it LOCKED" "OPEN the loop"
    if !LS0 = "OPEN the loop" then
      tcblock mbltopnl
      display "...opening ISS loop                           "
      writen !GS9 "...opening ISS loop"
      ###sync_hk###
    else
      goto giveup
    end if
  else
    beep
    beep
    writen !GS9 " ISS is LOCKED, BUT error signal is bad - OPENING ISS LOOP!"
    display " ISS loop is closed BUT error signal is bad - OPENING ISS LOOP!"
    tcblock mbltopnl
    ###sync_hk###
  end if
end if

## MAKE SURE THE PRE-AMP IS SET FOR LOW (SUN) & OFFSETS ARE FINE
writen !GS9 " Making sure the pre-amp is LOW & offsets on FINE.."
writen !GS9 " ..sending tcblock mbltlogn and tcblock mbltfine"
display " Making sure the pre-amp is LOW & offsets on FINE"
tcblock mbltlogn	## low gain (sun)
tcblock mbltfine	## fine offsets

good:
## ALL IS WELL IF WE MADE IT THROUGH HERE...!
setstr !GS6 = "enable ISS" 

goto done  ## skip the 'giveup' if all went well

giveup:
writen !GS9 " ...giving up!!"
setstr !GS6 = " "	## disable continuation of caller 'setup_iss'

done:
## LOG FINAL ISS STATUS
perform  log_iss_par_v02

writen !GS9 "Finished procedure checkiss : %s" !TIME
writen !GS9 " "
display "Finished Procedure checkiss                                      "
return
