#!/bin/bash


####
# Modified Summer 2011 for MBARI Ocean Imaging
#
# 09/16/11  RGH   Changed mono and color to left and right
#


#rm ../config/master.cfg
#ln ../config/stereo_bw_master.cfg ../config/master.cfg
#ln ../config/structlighttest.cfg ../config/master.cfg
rm ../config/dir_tree


DIVE_NUMBER="d$(date +%Y%m%d)"
SURV_TYPE="oi_survey_$(date +%H%M)"


IM_DIR_PATH="./images"

mkdir -p $IM_DIR_PATH'/'${DIVE_NUMBER}
mkdir -p $IM_DIR_PATH'/'${DIVE_NUMBER}'/'${SURV_TYPE}

rm -rf latest
ln -s $IM_DIR_PATH'/'${DIVE_NUMBER}'/'${SURV_TYPE} latest

cp ../config/master.cfg ./latest/.

IM_PATH=$IM_DIR_PATH'/'${DIVE_NUMBER}'/'${SURV_TYPE}'/images'
NAV_PATH=$IM_DIR_PATH'/'${DIVE_NUMBER}'/'${SURV_TYPE}'/nav'
SON_PATH=$IM_DIR_PATH'/'${DIVE_NUMBER}'/'${SURV_TYPE}'/sonar'

echo $IM_PATH

echo '#!/bin/bash' >> ../config/dir_tree
echo export IM_PATH=${IM_PATH} >> ../config/dir_tree
echo export SON_PATH=${SON_PATH} >> ../config/dir_tree

sudo chmod 775 ../config/dir_tree

#add a route for multicast traffic and set the TTL
export LCM_DEFAULT_URL=udpm://239.255.76.67:7667?ttl=1
sudo route add -net 239.255.0.0/16 dev eth0

#run lcm-spy to configure local environment variables
#lcm-spy


#run camunits
#/home/ginglis/Desktop/camunits-0.2.1/camview/camview --chain bw_chain.xml&
#/home/ginglis/Desktop/camunits-0.2.1/camview/camview --chain color_chain.xml&


echo "Creating new survey image directories..."
mkdir -p $IM_PATH
mkdir -p $NAV_PATH
mkdir -p $SON_PATH

#make the directory for the right-side images
RIGHT_PATH=$IM_PATH/right
mkdir -p $RIGHT_PATH

#make the directory for the left-side images
LEFT_PATH=$IM_PATH/left
mkdir -p $LEFT_PATH

echo "Launching camera drivers for survey ${SURV_TYPE}..."
#run the driver, 
#These first two pipe output to a log file
./prosilica -k sensor.right --publish true -d ${RIGHT_PATH} --strftime rIMG-%Y%m%d-%H%M%S-%i-%f.tif -l 2> /dev/null > ${RIGHT_PATH}/logfile.txt &

./prosilica -k sensor.left  --publish true -d ${LEFT_PATH}  --strftime lIMG-%Y%m%d-%H%M%S-%i-%f.tif -l 2> /dev/null > ${LEFT_PATH}/logfile.txt  &

#./prosilica -k sensor.color --publish true -d ${IM_PATH}/left  --strftime cIMG-%Y%m%d-%H%M%S-%i-%f.tif -l 

#./prosilica -k sensor.mono --publish true -d ${IM_PATH}/right  --strftime IMG-%Y%m%d-%H%M%S-%i-%f.tif -l 
