#!/bin/bash

################################ ################################ 
# Created on 14-NOV-2010
# by Chris Melton, SLAC AOSD Operations
#
# This script allows MCC Operators to toggle FEL delivery between
# burst mode and continuous mode with the single press of a 
# button from the Operator Dashboard. The shell script can be run
# or called independently from other programs as well.
################################ ################################ 

burstat=$(caget -t SIOC:SYS0:ML00:CALC008)

# If burst mode isn't set, then set it
if [ $burstat -eq 0 ]
then
caput IOC:BSY0:MP01:REQBYKIKBRST 1
caput EVR:UND1:R02:EVENT1CTRL.OUT0 0
caput EVR:UND1:R02:EVENT14CTRL.OUT0 1
# Set burst mode bit to "enabled"
caput SIOC:SYS0:ML00:AO644 1

# If burst mode is already set, then unset it
elif [ $burstat -eq 1 ]
then
caput IOC:BSY0:MP01:REQBYKIKBRST 0
caput EVR:UND1:R02:EVENT1CTRL.OUT0 1
caput EVR:UND1:R02:EVENT14CTRL.OUT0 0
# Set burst mode bit to "disabled"
caput SIOC:SYS0:ML00:AO644 0

else
echo "Something went wrong, I guess. Dang!"
fi

exit 0
