#!/bin/sh
# Copyright 2013 Monterey Bay Aquarium Research Institute, all rights reserved.
# Start or stop HotSpot radios/links
echo executing as `/bin/whoami`
echo PATH - $PATH
echo PYTHONPATH - $PYTHONPATH

if [ $# -ne 1 ]; then
  echo No arguments - should be 'start' or 'stop'
  exit 1
fi

# Need to set config file since this script is executed by root, 
# which may not define MODEM_CONFIG_FILE in its environment
export MODEM_CONFIG_FILE=/opt/hotspot/config/modems.cfg

if [ "$1" == "start" ]; then

  # Scripts use tmp directory
  chmod a+w /tmp

  # Enable radios
  echo `date`
  echo Enable radios

  # Turn on "console" radio
  ### /home/hotspot/smc-script/consoleOn

  # Turn on Iridium console
  echo Turning on Iridium modem
  sudo /home/smc/bin/SetPowerSwitch 1 1

  # Turn on Freewave for LRAUV
  ### echo "Turn on Freewave for LRAUV"
  ### /home/hotspot/smc-script/fwOn

  # Turn on MultiTech cdma modem
  echo Turn on CDMA modem
  /home/hotspot/smc-script/cellOn

  # Monitor route table
  echo 'log changes to route table'
  ip monitor route > /opt/hotspot/logs/routeChanges.out &
  /home/hotspot/smc-script/monitorRoutes.sh | tee /opt/hotspot/logs/monitorRoutes.out &


  # Synchronize clock - not necessary when integrated with Wave Glider,
  # which provides GPS time signal
  echo Synchronize clock via NTP
  ntpdate -u 0.in.pool.ntp.org

  # Set hotspot rsync password
  export RSYNC_PASSWORD=Brynner

  # TEST TEST TEST
  ### echo Enable ethernet
  ### /home/smc/bin/EnableEthernet
  # echo add route to trex3 through ethernet
  # route add -net 134.89.28.0 netmask 255.255.255.0 dev eth0

  echo running startStopComs as `whoami`
  echo PATH = $PATH

  /home/hotspot/smc-script/syncAUV 30 daphne beach &>> /opt/hotspot/logs/syncAUV-lrauv-beach.log &

####  /home/hotspot/smc-script/syncAUV 30 xtreme beach trex2 &>> /opt/hotspot/logs/syncAUV-xtreme-beach-trex2.log &

/home/hotspot/smc-script/syncBeach 300 beach daphne &>> /opt/hotspot/logs/syncBeach-lrauv.log &


 
elif [ "$1" == "stop" ]; then
  echo Turn off radios
###  /home/hotspot/smc-script/cdmaOff
###  /home/hotspot/smc-script/doradoOff
###  /home/hotspot/smc-script/consoleOff  
fi



