Auto start/stop of capture process for each observation.
parent
330fb965fc
commit
3c8d6c3ddf
|
@ -24,76 +24,83 @@ fi
|
|||
|
||||
export CAMERADEV=`cat $ST_OBSDIR/control/camera.txt | awk '{print $((7))}'`
|
||||
|
||||
echo "Status: "$STATE
|
||||
|
||||
# For ever loop
|
||||
while true; do
|
||||
# Get number of files
|
||||
NFILES=`ls -1 $PGMDIR/img*.pgm 2>/dev/null | wc -l`
|
||||
|
||||
# Get state
|
||||
export STATE=`cat $ST_OBSDIR/control/state.txt`
|
||||
|
||||
# Create new directory
|
||||
if [ $STATE == "restart" ]; then
|
||||
export DIR=`date -u +%FT%T | sed -e "s/-//g" -e "s/\://g" -e "s|T|/|g"`
|
||||
mkdir -p $ST_OBSDIR/$DIR
|
||||
cd $ST_OBSDIR/$DIR
|
||||
echo "Moving to $ST_OBSDIR/$DIR"
|
||||
echo "observing" >$ST_OBSDIR/control/state.txt
|
||||
cp $ST_OBSDIR/control/position.txt .
|
||||
# cp $ST_OBSDIR/control/scale.txt .
|
||||
cp $ST_OBSDIR/control/camera.txt .
|
||||
export CAMERADEV=`cat $ST_OBSDIR/control/camera.txt | awk '{print $((7))}'`
|
||||
# Remove old captured frames
|
||||
echo "Removing all captured frames"
|
||||
# ls -1 $PGMDIR/img*.pgm | awk '{printf("sudo rm -rf %s\n",$1)}' | sh
|
||||
ls -1 $PGMDIR/img*.pgm | awk '{printf("rm -rf %s\n",$1)}' | sh
|
||||
fi
|
||||
|
||||
# kill capture process just when scheduler sends stop signal
|
||||
if [ $STATE == "stop" ]; then
|
||||
if [ $(($CAPTUREPID)) != 0 ]; then
|
||||
echo "Stopping capture process"
|
||||
kill -9 $CAPTUREPID
|
||||
CAPTUREPID=0
|
||||
fi
|
||||
fi
|
||||
|
||||
# Get number of captured frames
|
||||
NFILES=`ls -1 $PGMDIR/img*.pgm 2>/dev/null | wc -l`
|
||||
# If enough, process
|
||||
if [ $NFILES -ge $N ]; then
|
||||
|
||||
# Create new directory
|
||||
if [ $STATE == "restart" ]; then
|
||||
export DIR=`date -u +%FT%T | sed -e "s/-//g" -e "s/\://g" -e "s|T|/|g"`
|
||||
mkdir -p $ST_OBSDIR/$DIR
|
||||
cd $ST_OBSDIR/$DIR
|
||||
echo "Moving to $ST_OBSDIR/$DIR"
|
||||
echo "observing" >$ST_OBSDIR/control/state.txt
|
||||
cp $ST_OBSDIR/control/position.txt .
|
||||
# cp $ST_OBSDIR/control/scale.txt .
|
||||
cp $ST_OBSDIR/control/camera.txt .
|
||||
export CAMERADEV=`cat $ST_OBSDIR/control/camera.txt | awk '{print $((7))}'`
|
||||
fi
|
||||
|
||||
# Process only if not restarting
|
||||
if [ $STATE != "restart" ]; then
|
||||
echo "Compressing captured frames"
|
||||
echo "Compressing $N captured frames"
|
||||
|
||||
# Start point
|
||||
M=`ls -1 $PGMDIR/img*.pgm | head -n1 | sed -e "s/[^0-9]*//g"`
|
||||
# Start point
|
||||
M=`ls -1 $PGMDIR/img*.pgm | head -n1 | sed -e "s/[^0-9]*//g"`
|
||||
|
||||
# Run pgm2fits
|
||||
# Run pgm2fits
|
||||
# pgm2fits -p $PGMDIR/img -w 720 -h 576 -s $M -n $N
|
||||
pgm2fits -p $PGMDIR/img -w 720 -h 576 -s $M -n $N >/dev/null
|
||||
pgm2fits -p $PGMDIR/img -w 720 -h 576 -s $M -n $N >/dev/null
|
||||
|
||||
# Run viewer
|
||||
viewer `ls -1 2*.fits | tail -n1`
|
||||
cp avg.pgm $ST_OBSDIR
|
||||
fi
|
||||
|
||||
# kill capture process just when scheduler sends stop signal
|
||||
if [ $STATE == "stop" ]; then
|
||||
if [ $(($CAPTUREPID)) != 0 ]; then
|
||||
kill -9 $CAPTUREPID
|
||||
CAPTUREPID=0
|
||||
fi
|
||||
fi
|
||||
# Run viewer
|
||||
viewer `ls -1 2*.fits | tail -n1`
|
||||
cp avg.pgm $ST_OBSDIR
|
||||
|
||||
# Remove files
|
||||
echo "Removing captured frames"
|
||||
echo "Removing $N captured frames"
|
||||
# ls -1 $PGMDIR/img*.pgm | head -n$N | awk '{printf("sudo rm -rf %s\n",$1)}' | sh
|
||||
ls -1 $PGMDIR/img*.pgm | head -n$N | awk '{printf("rm -rf %s\n",$1)}' | sh
|
||||
|
||||
echo "Finished"
|
||||
# echo "Finished"
|
||||
else
|
||||
# There are not enough captured frames
|
||||
# Launch capture process if state is not stop
|
||||
# if time passes with still no images re-launch capture process
|
||||
if [ $STATE != "stop" ]; then
|
||||
echo "Waiting for images. Status: "$STATE
|
||||
echo "Waiting for frames. Status: "$STATE
|
||||
COUNT=$(($COUNT+1))
|
||||
if [ $COUNT -ge $WAIT ]; then
|
||||
COUNT=0
|
||||
echo "No images found, restarting capture script"
|
||||
echo "No frames found, restarting capture script"
|
||||
# sh $ST_DATADIR/scripts/st_capture.sh /dev/video-$CAMERA &
|
||||
sh $ST_DATADIR/scripts/st_capture.sh $CAMERADEV &
|
||||
sleep 1
|
||||
CAPTUREPID=`pgrep -o -x ffmpeg`
|
||||
fi
|
||||
# if restarting then relaunch capture script now
|
||||
if [ $STATE == "restart" ]; then
|
||||
if [ $(($CAPTUREPID)) == 0 ]; then
|
||||
echo "Restarting capture script"
|
||||
# sh $ST_DATADIR/scripts/st_capture.sh /dev/video-$CAMERA &
|
||||
sh $ST_DATADIR/scripts/st_capture.sh $CAMERADEV &
|
||||
sleep 1
|
||||
|
@ -101,8 +108,10 @@ while true; do
|
|||
fi
|
||||
fi
|
||||
else
|
||||
echo "Status: "$STATE
|
||||
# we are stopped, check for bogus capture process
|
||||
# echo "Status: "$STATE
|
||||
if [ $(($CAPTUREPID)) != 0 ]; then
|
||||
echo "Stopping capture process"
|
||||
kill -9 $CAPTUREPID
|
||||
CAPTUREPID=0
|
||||
fi
|
||||
|
|
Loading…
Reference in New Issue