#!/bin/bash

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


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


IM_DIR_PATH="./images"

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

IM_PATH=$IM_DIR_PATH'/'${DIVE_NUMBER}'/'${SURV_TYPE}'/images'
NAV_PATH=$IM_DIR_PATH'/'${DIVE_NUMBER}'/'${SURV_TYPE}'/compass'

echo $IM_PATH

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

sudo chmod 775 ../config/dir_tree

mkdir -p $IM_PATH
mkdir -p $NAV_PATH

#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&


#make the directory for the color images
echo "making new image directory: ${IM_PATH}/color"
mkdir $IM_PATH/color

#make the directory for the bw images
echo "making new image directory: ${IM_PATH}/bw"
mkdir $IM_PATH/bw

#run the driver, 
./prosilica -k sensor.color --publish false -d ${IM_PATH}/color  --strftime cIMG-%Y%m%d-%H%M%S-%i-%f.tif -l --view 2> /dev/null > ${IM_PATH}/color/logfile.txt  &

#./prosilica -k sensor.color --publish false -d ${IM_PATH}/color  --strftime cIMG-%Y%m%d-%H%M%S-%i-%f.tif -l 2> /dev/null | egrep '(plug)|(Frame)'& #> ${IM_PATH}/color/logfile.txt  &

sleep 3


./prosilica -k sensor.mono --publish false -d ${IM_PATH}/bw  --strftime IMG-%Y%m%d-%H%M%S-%i-%f.tif -l --view 2> /dev/null > ${IM_PATH}/bw/logfile.txt  &

#./prosilica -k sensor.mono --publish false -d ${IM_PATH}/bw  --strftime IMG-%Y%m%d-%H%M%S-%i-%f.tif 2> /dev/null1> ${IM_PATH}/bw/logfile.txt &

sleep 3

#./os-compass -k sensor.compass -l ${NAV_PATH} > /dev/null &

