#! /bin/sh

#enter the total time you want to allow the mission to run for in seconds
#25200 == 7 hours
#172000 ~ 48 hours
#7500 ~ 2 hours
#2000 ~ 33 minutes

#the name of the script you want to run. This should either be an absolute
#path, or the path will need to be correct relative to the location of this
#script.

# Long mission, 36hours, move into current
#
MISSION_SCRIPT="main.rb -long_mission -safe_move"

# Short mission, 15 minutes, move into current
#
SHORT_MISSION_SCRIPT="main.rb -safe_move"

# Start a short mission, 3 measurement sites, 1 minute incubations
# Dive time = 3 hours
# Mission time = 3 sites * 25 minutes per site = 1.25 hour
# 4.25 hours = 15300 seconds
#
TOTAL_MISSION_TIME=15300
echo "running \"ruby $SHORT_MISSION_SCRIPT &\""
date
ruby $SHORT_MISSION_SCRIPT &
PID=$!
echo "Mission is running under PID $PID"
echo "Mission will be killed in $TOTAL_MISSION_TIME seconds"
sleep $TOTAL_MISSION_TIME
date
echo "killing mission script"
kill -9 $PID
echo "shutting down relays"
sleep 2
echo -ne "f0\r" > /dev/relay1
echo -ne "f0\r" > /dev/relay2

# One long mission, 1 measurement sites, 36 hour incubations
#
# -lt1 means the launch phase is only 1 minute,
# so we can decrease the TOTAL_MISSION_TIME
# 36hrs + 8 extra = 44 hours
# 158400 seconds = 44 hours
#
TOTAL_MISSION_TIME=158400
echo "running \"ruby $MISSION_SCRIPT -lt1 &\""
date
ruby $MISSION_SCRIPT -lt1 &
PID=$!
echo "Mission is running under PID $PID"
echo "Mission will be killed in $TOTAL_MISSION_TIME seconds"
sleep $TOTAL_MISSION_TIME
date
echo "killing mission script"
kill -9 $PID
echo "shutting down relays"
sleep 2
echo -ne "f0\r" > /dev/relay1
echo -ne "f0\r" > /dev/relay2

