Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes to camViewer #94

Merged
merged 32 commits into from
Mar 19, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
0390af7
ENH:Added full worded options --enable and --disable
spenc333 Jan 11, 2022
7920e8a
ENH:Allows cameras outside of hutch to be enabled and disabled
spenc333 Jan 12, 2022
6570eaf
BUG: Fixed -H option
spenc333 Jan 13, 2022
ef12eb1
BUG: Modified previous -H fix to work with other options
spenc333 Jan 13, 2022
20d716e
DEV: Initial commit for imgr script
spenc333 Jan 13, 2022
2132e0a
BUG:Added conditions to take care of all commands
spenc333 Jan 13, 2022
5cab304
Removed conditionals
spenc333 Jan 14, 2022
d23b085
Created iocinfo() to avoid code duplication for enable/disable
spenc333 Jan 14, 2022
77f0bcf
Fixed fully worded enable/disable options and removed else statement …
spenc333 Jan 14, 2022
8aac235
Removed sourcing
spenc333 Jan 14, 2022
c50a9c6
ENH: Changed how iocinfo deals with multiple iocs
spenc333 Jan 15, 2022
7d0af74
Added engineering tools to path
spenc333 Jan 15, 2022
c3c55c9
Revised adding engineering tools to path
spenc333 Jan 15, 2022
db69540
Updated imgr to use script specific to each hutch. Removed help funct…
spenc333 Jan 21, 2022
db4aba8
Fixed styling and edited -l and -c options
spenc333 Jan 21, 2022
3815117
Amended where the hutch gets defined
spenc333 Jan 21, 2022
673b647
STY: Style fixes from shellcheck
spenc333 Jan 21, 2022
7de00d4
Merge branch 'master' into camviewer-76
ZryletTC Feb 16, 2022
aa398e1
Removed imgr
spenc333 Feb 25, 2022
2b43155
Merge branch 'master' of https://github.com/pcdshub/engineering_tools…
spenc333 Feb 25, 2022
df4ac3d
Merge branch 'camviewer-76' of https://github.com/spenc333/engineerin…
spenc333 Feb 25, 2022
31a2f44
BUG: Fixed syntax errors that broke the default camera selection
spenc333 Mar 2, 2022
8536d20
Fixed enable and disable command line long options
spenc333 Mar 11, 2022
fb4a672
Updated usage function
spenc333 Mar 11, 2022
bda7203
Changed path instance
spenc333 Mar 12, 2022
e4f53db
Style Fixes
spenc333 Mar 16, 2022
1a8a311
More style fixes
spenc333 Mar 16, 2022
2935c52
Error handling
spenc333 Mar 19, 2022
9a67d97
Added usage function to unknown hutch error.
spenc333 Mar 19, 2022
14b0c9e
Merge branch 'master' of https://github.com/pcdshub/engineering_tools…
spenc333 Mar 19, 2022
8acdad4
Fixing a git push
spenc333 Mar 19, 2022
7044a3e
Syntax fixes
spenc333 Mar 19, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
155 changes: 80 additions & 75 deletions scripts/camViewer
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

DIR=$(readlink -f $(dirname "${BASH_SOURCE[0]}"))
DIR=$(readlink -f "$(dirname "${BASH_SOURCE[0]}")")
PATH=$PATH:$DIR

#
Expand All @@ -18,10 +18,10 @@ if [ $# -lt 2 ]; then
exit
fi
CAMPVFULL=""
hutch=`echo $2 | tr A-Z a-z`
hutch=$(echo "$2" | tr A-Z a-z)
VIEWERCFG=/reg/g/pcds/pyps/config/$hutch/camviewer.cfg
# Match "-" or "_" or " ".
NAME=`echo $1 | sed -e 's/-/ /g' -e 's/_/ /g' -e 's/ /[-_ ]/g'`
NAME=$(echo "$1" | sed -e 's/-/ /g' -e 's/_/ /g' -e 's/ /[-_ ]/g')
#
# The story here:
# See how many matches we have in the hutch.
Expand All @@ -34,37 +34,37 @@ NAME=`echo $1 | sed -e 's/-/ /g' -e 's/_/ /g' -e 's/ /[-_ ]/g'`
#
# Make a temp file with just the PVs and camera names that match.
tmp=/tmp/cv.$$
cat $VIEWERCFG | grep -i "$NAME" | grep -v '#' | awk -F, '{ if (split($2,a,";")==1) n=$2; else n=a[2]; gsub(" ","",n); gsub(" ","",$4); printf "%s %s\n", n, $4; }' >$tmp
c=`wc -l <$tmp`
if [ $c -eq 0 ]; then
VIEWERCFG=/reg/g/pcds/pyps/config/*/camviewer.cfg
cat $VIEWERCFG | grep -i "$NAME" | grep -v '#' | awk -F, '{ if (split($2,a,";")==1) n=$2; else n=a[2]; gsub(" ","",n); gsub(" ","",$4); printf "%s %s\n", n, $4; }' >$tmp
c=`wc -l <$tmp`
if [ $c -eq 0 ]; then
cat "$VIEWERCFG" | grep -i "$NAME" | grep -v '#' | awk -F, '{ if (split($2,a,";")==1) n=$2; else n=a[2]; gsub(" ","",n); gsub(" ","",$4); printf "%s %s\n", n, $4; }' >$tmp
c=$(wc -l <$tmp)
if [ "$c" -eq 0 ]; then
VIEWERCFG='/reg/g/pcds/pyps/config/*/camviewer.cfg'
cat "$VIEWERCFG" | grep -i "$NAME" | grep -v '#' | awk -F, '{ if (split($2,a,";")==1) n=$2; else n=a[2]; gsub(" ","",n); gsub(" ","",$4); printf "%s %s\n", n, $4; }' >$tmp
c=$(wc -l <$tmp)
if [ "$c" -eq 0 ]; then
echo "No match for $1"
rm -f $tmp
exit
fi
fi
if [ $c -eq 1 ]; then
CAMPVFULL=`awk '{print $1;}' <$tmp`
if [ "$c" -eq 1 ]; then
CAMPVFULL=$(awk '{print $1;}' <$tmp)
rm -f $tmp
return
fi
# OK, ambiguous. Look for a complete match on the second word.
if [ `egrep -i " $NAME\$" < $tmp | wc -l` -eq 1 ]; then
CAMPVFULL=`egrep -i " $NAME\$" < $tmp | awk '{print $1;}'`
if [ "$(grep -E -i " $NAME\$" < $tmp | wc -l)" -eq 1 ]; then
CAMPVFULL=$(grep -E -i " $NAME\$" < $tmp | awk '{print $1;}')
rm -f $tmp
return
fi
# What about just a match at the end? (That is, if we are searching
# for "yag1", prefer "mec_yag1" to "mec_yag11".)
if [ `egrep -i "$NAME\$" < $tmp | wc -l` -eq 1 ]; then
CAMPVFULL=`egrep -i "$NAME\$" < $tmp | awk '{print $1;}'`
if [ "$(grep -E -i "$NAME\$" < $tmp | wc -l)" -eq 1 ]; then
CAMPVFULL=$(grep -E -i "$NAME\$" < $tmp | awk '{print $1;}')
rm -f $tmp
return
fi
echo '"'$1'" is ambiguous:'
echo '"'"$1"'" is ambiguous:'
awk '{print $2;}' <$tmp
rm -f $tmp
exit
Expand All @@ -78,10 +78,10 @@ fi
HUTCH=${1^^}
hutch=${1,,}
VIEWERCFG=/reg/g/pcds/pyps/config/$hutch/camviewer.cfg
printf -v GIGENUM "%02d" $2
printf -v GIGENUM "%02d" "$2"
GIGEBASE=$HUTCH:GIGE:$GIGENUM

echo `grep $GIGEBASE $VIEWERCFG | grep -v '#' | awk -F, '{print $4}'`
echo "$(grep "$GIGEBASE" "$VIEWERCFG" | grep -v '#' | awk -F, '{print $4}')"
}

isNum(){
Expand All @@ -100,42 +100,42 @@ list_cams()
if [ $# -lt 1 ]; then
echo 'need one arguments: hutch '
fi
HUTCH=`echo $1 | tr a-z A-Z`
hutch=`echo $1 | tr A-Z a-z`
HUTCH=$(echo "$1" | tr a-z A-Z)
hutch=$(echo "$1" | tr A-Z a-z)

ALLVIEWERCFG=/reg/g/pcds/pyps/config/*/camviewer.cfg
echo cat $ALLVIEWERCFG | grep -v '#' | awk -F, '{ if (split($2,a,";")==1) n=$2; else n=a[2]; gsub(" ","",n); gsub(" ","",$4); printf "%s %s\n", n, $4; }'
echo cat "$ALLVIEWERCFG" | grep -v '#' | awk -F, '{ if (split($2,a,";")==1) n=$2; else n=a[2]; gsub(" ","",n); gsub(" ","",$4); printf "%s %s\n", n, $4; }'

VIEWERCFGLFE=/reg/g/pcds/pyps/config/lfe/camviewer.cfg
VIEWERCFG=/reg/g/pcds/pyps/config/$hutch/camviewer.cfg
VIEWERCFGXRT=/reg/g/pcds/pyps/config/xrt/camviewer.cfg

if [ $hutch != 'tmo' ] && [ $hutch != 'rix' ]; then
for gige_cam in `grep -v '#' $VIEWERCFGLFE | awk -F, '{print $4 "\n" }'`; do
echo $gige_cam
if [ "$hutch" != 'tmo' ] && [ "$hutch" != 'rix' ]; then
for gige_cam in $(grep -v '#' $VIEWERCFGLFE | awk -F, '{print $4 "\n" '); do
ZryletTC marked this conversation as resolved.
Show resolved Hide resolved
echo "$gige_cam"
done

for gige_cam in `grep -v '#' $VIEWERCFGXRT | awk -F, '{print $4 "\n" }'`; do
echo $gige_cam
for gige_cam in $(grep -v '#' $VIEWERCFGXRT | awk -F, '{print $4 "\n" }'); do
echo "$gige_cam"
done
fi

for gige_cam in `grep -v '#' $VIEWERCFG | awk -F, '{print $4 "\n" }'`; do
echo $gige_cam
for gige_cam in $(grep -v '#' "$VIEWERCFG" | awk -F, '{print $4 "\n" }'); do
echo "$gige_cam"
done

}

iocfpv() {
grep_pv $1 | sed -n 's/\/reg\/d\/iocData\/\(\S*\)\/iocInfo/\1/p'
grep_pv "$1" | sed -n 's/\/reg\/d\/iocData\/\(\S*\)\/iocInfo/\1/p'
}

iocinfo() {
for ioc in `iocfpv "$CAMPVFULL:IMAGE1"`; do
for ioc in $(iocfpv "$CAMPVFULL:IMAGE1"); do

INFO=$(grep_ioc "$ioc" all | grep "id:'$ioc'")
if [ -n "$INFO" ]; then
iochutch=$(echo $INFO | cut -d'/' -f7)
iochutch=$(echo "$INFO" | cut -d'/' -f7)
fi
done
}
Expand Down Expand Up @@ -165,8 +165,9 @@ if [[ ($1 == "--help") || ($1 == "-h") ]]; then
exit 0
fi


LIST=0
CAMNUM=0
CAMNAME=0
ZryletTC marked this conversation as resolved.
Show resolved Hide resolved
WAIT=0
RATE=-1
REBOOT=0
Expand All @@ -180,18 +181,10 @@ while getopts " -o c:w:u:H:lmre:(enable)d:(disable)" OPTION
do
case $OPTION in
l)
list_cams $hutch
exit 1
LIST=1
;;
c)
CAM=$OPTARG
if isNum $CAM; then
CAMNUM=$CAM
CAMNAME=`gige_num_to_name $hutch $CAM`
else
CAMNAME=$CAM
CAMNUM=-1
fi
;;
w)
WAIT=$OPTARG
Expand Down Expand Up @@ -219,32 +212,44 @@ done


spenc333 marked this conversation as resolved.
Show resolved Hide resolved
if [ "$hutch" == "" ]; then
hutch=`get_info --gethutch`
hutch=$(get_info --gethutch)
if [ "$hutch" == unknown_hutch ]; then
echo 'unknown hutch, cannot use camViewer script'
echo 'unknown hutch, specify using -H option'
exit 1
fi
fi



EXE=/reg/g/pcds/pyps/config/$hutch/camviewer/run_viewer.csh
PVLIST=/reg/g/pcds/pyps/config/$hutch/camviewer.cfg
EXE="/reg/g/pcds/pyps/config/$hutch/camviewer/run_viewer.csh"
PVLIST="/reg/g/pcds/pyps/config/$hutch/camviewer.cfg"

if [ $LIST -gt 0 ]; then
list_cams "$hutch"
exit 1
fi

if isNum "$CAM"; then
CAMNUM=$CAM
CAMNAME=$(gige_num_to_name "$hutch" "$CAM")
else
CAMNAME=$CAM
CAMNUM=-1
fi


if [ $CAMNUM -eq 0 ]; then
if [ $hutch = "tmo" ]; then
if [ "$hutch" = "tmo" ]; then
CAMNAME=IM2K0
elif [ $hutch = "rix" ]; then
elif [ "$hutch" = "rix" ]; then
CAMNAME=IM1K1
elif [ $hutch = "xpp" ]; then
elif [ "$hutch" = "xpp" ]; then
CAMNAME=hx2_sb1_yag
elif [ $hutch = "mfx" ]; then
elif [ "$hutch" = "mfx" ]; then
CAMNAME=mfx_dg1_yag
elif [ $hutch = "cxi" ]; then
elif [ "$hutch" = "cxi" ]; then
CAMNAME=cxi_dg1_yag
elif [ $hutch = "mec" ]; then
elif [ "$hutch" = "mec" ]; then
CAMNAME=GigE_Questar1
else
CAMNAME=xcs_yag2
Expand All @@ -255,23 +260,23 @@ export EPICS_CA_MAX_ARRAY_BYTES=24000000
echo working with camera of name: $CAMNAME


name_to_pv "$CAMNAME" $hutch
name_to_pv "$CAMNAME" "$hutch"

if [ $MAINSCREEN -gt 0 ]; then
echo 'try to get the main screen for: ' $CAMNAME
echo 'start the main screen for camera base PV: ' $CAMPVFULL
cmdName=`caget -St $CAMPVFULL:LAUNCH_EDM`
echo calling edm main screen from: $cmdName
echo 'start the main screen for camera base PV: ' "$CAMPVFULL"
cmdName=$(caget -St "$CAMPVFULL":LAUNCH_EDM)
echo calling edm main screen from: "$cmdName"
$cmdName
exit
fi

if [ $REBOOT -gt 0 ]; then
echo 'reboot IOC for camera: ' $CAMNAME
edmcmdName=`caget -St $CAMPVFULL:LAUNCH_EDM`
IOCPV=`grep 'export IOC_PV' $edmcmdName | awk '{print $2 "\n" }' | sed s/IOC_PV=/''/g`
echo 'restart IOC last started on: ' `caget -t $IOCPV:STARTTOD`
caput $IOCPV:SYSRESET 1
edmcmdName=$(caget -St "$CAMPVFULL":LAUNCH_EDM)
IOCPV=$(grep 'export IOC_PV' "$edmcmdName" | awk '{print $2 "\n" }' | sed s/IOC_PV=/''/g)
echo 'restart IOC last started on: ' "$(caget -t "$IOCPV":STARTTOD)"
caput "$IOCPV":SYSRESET 1
exit
fi

Expand All @@ -289,30 +294,30 @@ if [ $DISABLE -gt 0 ]; then
exit
fi

IS_ACQUIRING=`caget -t -n $CAMPVFULL:Acquire_RBV`
if isNum $IS_ACQUIRING; then
if [ $IS_ACQUIRING -eq 0 ]; then
IS_ACQUIRING=$(caget -t -n "$CAMPVFULL":Acquire_RBV)
if isNum "$IS_ACQUIRING"; then
if [ "$IS_ACQUIRING" -eq 0 ]; then
echo 'start acquiring for camera ' $CAMNAME
caput -n $CAMPVFULL:Acquire 1
caput -n "$CAMPVFULL":Acquire 1
fi
else
echo 'cannot check Acquiring PV, try to open camera viewer anyways....'
fi

if [ $WAIT -gt 0 ]; then
if [ $RATE -gt 0 ]; then
echo $EXE --camerapv $CAMPVFULL --instrument $hutch --pvlist $PVLIST --idle $WAIT --rate $RATE&
$EXE --camerapv $CAMPVFULL --instrument $hutch --pvlist $PVLIST --idle $WAIT --rate $RATE&
if [ "$WAIT" -gt 0 ]; then
if [ "$RATE" -gt 0 ]; then
echo "$EXE" --camerapv "$CAMPVFULL" --instrument "$hutch" --pvlist "$PVLIST" --idle "$WAIT" --rate "$RATE"&
"$EXE" --camerapv "$CAMPVFULL" --instrument "$hutch" --pvlist "$PVLIST" --idle "$WAIT" --rate "$RATE"&
else
echo $EXE --camerapv $CAMPVFULL --instrument $hutch --pvlist $PVLIST --idle $WAIT&
$EXE --camerapv $CAMPVFULL --instrument $hutch --pvlist $PVLIST --idle $WAIT&
echo "$EXE" --camerapv "$CAMPVFULL" --instrument "$hutch" --pvlist "$PVLIST" --idle "$WAIT"&
"$EXE" --camerapv "$CAMPVFULL" --instrument "$hutch" --pvlist "$PVLIST" --idle "$WAIT"&
fi
else
if [ $RATE -gt 0 ]; then
echo $EXE --camerapv $CAMPVFULL --instrument $hutch --pvlist $PVLIST --rate $RATE&
$EXE --camerapv $CAMPVFULL --instrument $hutch --pvlist $PVLIST --rate $RATE&
if [ "$RATE" -gt 0 ]; then
echo "$EXE" --camerapv "$CAMPVFULL" --instrument "$hutch" --pvlist "$PVLIST" --rate "$RATE"&
"$EXE" --camerapv "$CAMPVFULL" --instrument "$hutch" --pvlist "$PVLIST" --rate "$RATE"&
else
echo $EXE --camerapv $CAMPVFULL --instrument $hutch --pvlist $PVLIST &
$EXE --camerapv $CAMPVFULL --instrument $hutch --pvlist $PVLIST &
echo "$EXE" --camerapv "$CAMPVFULL" --instrument "$hutch" --pvlist "$PVLIST" &
"$EXE" --camerapv "$CAMPVFULL" --instrument "$hutch" --pvlist "$PVLIST" &
fi
fi
Loading