#!/bin/sh
# This script is designed to setup user screen with instalation status, fix swapped filters, and operation status of devices.
# Setup Guide: DEVICE TGT FLT1 FLT2 TLAMP GLAMP MTR INOPERABLE

bad=1


# Screen Setup
caput $1:TGTINSTALLED $2
caput $1:FLT1INSTALLED $3
caput $1:FLT2INSTALLED $4
caput $1:TLAMPINSTALLED $5
caput $1:GLAMPINSTALLED $6
caput $1:MTRINSTALLED $7
caput $1:INOPERABLE $10

# Filter 1 swapped
if [ $8 -eq $bad ]
then
    echo Filter 1 is swapped
    caput $1:FLT1_CTRL.ZNAM "In";
    caput $1:FLT1_CTRL.ONAM "Out";
    caput $1:FLT1_STS_CALC.INPA "$1:FLT1_OUT"
    caput $1:FLT1_STS_CALC.INPB "$1:FLT1_IN"
    echo Filter 1 fixed
else
    echo Filter 1 good
fi

# Filter 2 swapped
if [ $9 -eq $bad ] 
then
    echo Filter 2 is swapped
    caput $1:FLT2_CTRL.ZNAM "In"
    caput $1:FLT2_CTRL.ONAM "Out"
    caput $1:FLT2_STS_CALC.INPA "$1:FLT2_OUT"
    caput $1:FLT2_STS_CALC.INPB "$1:FLT2_IN"
    echo Filter 2 fixed
else
    echo Filter 2 good
fi

# Device is inoperable/removed
if [ $10 -eq $bad ]
then
    echo Device is inoperable
    caput $1:TGT_CTRL "Out"
    caput $1:TGT_CTRL.ASG "NOWRITE"
    echo TGT controls dissabled
elif [ [$10 -ne $bad] && [$1:TGT_CTRL.ASG -eq "NOWRITE"] ]
then
    echo Device is operational but TGT controls dissabled
    caput $1:TGT_CTRL.ASG "WRITE"
    echo TGT controls renabled
else
    echo Device is operational
fi

#End of script
