#!/bin/bash
# Copyright 2013 Monterey Bay Aquarium Research Institute, all rights reserved.
# Turn off MultiTech CDMA modem

radio=globalstar
# Get power port and serial port from configuration
powerSerial=`python /home/hotspot/smc-script/modemConfig.py $MODEM_CONFIG_FILE $radio`
if [ $? != 0 ]; then
   echo $powerSerial
   echo Could not get configuration for $radio radio
   exit 1
fi

# Get power port
powerPort=`echo $powerSerial | awk '{print $1}'`

# Get serial port
serialPort=`echo $powerSerial | awk '{print $2}'`

# Kill associated pppd
echo Kill $radio ppp daemon
pid=`ps -eaf | grep "pppd.*$serialPort" | grep -v grep | awk '{print $2}'`
kill $pid

echo Turn off $radio modem
/home/smc/bin/SetPowerSwitch $powerPort 0
