#!/bin/bash
#==============================================================
# facetBpmCalCtl
#
# ARGUMENTS:
#            mode:   0 = disable calibration
#                    1 = enable calibration
#
# OPTION:     
#
# Facility:  SLAC/LCLS
#
# Auth:  02-Dec-2009, Sonya Hoobler   (SONYA)
# Rev:   dd-mmm-yyyy, Reviewer's Name (USERNAME)
#
# Rem:   Enable/disable calibration of the 4 EPICS FACET BPMs
#----------------------------------------------------------------------------
# Mod:
#        
#==============================================================

mode=$1

pvlist="BPMS:LI20:2445:CALBTCTL
EVR:LI20:BP01:EVENT3CTRL.OUT0
EVR:LI20:BP01:EVENT4CTRL.OUT0
BPMS:LI20:3156:CALBTCTL
EVR:LI20:BP01:EVENT3CTRL.OUT1
EVR:LI20:BP01:EVENT4CTRL.OUT1
BPMS:LI20:3265:CALBTCTL
EVR:LI20:BP01:EVENT3CTRL.OUT2
EVR:LI20:BP01:EVENT4CTRL.OUT2
BPMS:LI20:3315:CALBTCTL
EVR:LI20:BP01:EVENT3CTRL.OUT3
EVR:LI20:BP01:EVENT4CTRL.OUT3
"

for i in $pvlist
do
  caput ${i} ${mode}  
done

bpms="BPMS:LI20:2445
BPMS:LI20:3156
BPMS:LI20:3265
BPMS:LI20:3315
"

if [ ${mode} = 0 ]
then
    for i in $bpms
    do
      caput "${i}:STA_ALH.INPB" ""
      caput "${i}:STA_ALH.INPC" ""
      caput -a SIOC:SYS1:ML00:CA048 8 68 105 115 97 98 108 101 100 # "Disabled"
    done
else
    for i in $bpms
    do
      caput "${i}:STA_ALH.INPB" "${i}:GRU.SEVR MS"
      caput "${i}:STA_ALH.INPC" "${i}:GRV.SEVR MS"
      caput -a SIOC:SYS1:ML00:CA048 8 69 110 97 98 108 101 100 # "Enabled"
    done
fi

exit 0

