#!/bin/sh
# cd24-lowlatency-in/src/cd24-lowlatency-cancel/cd24-lowlatency-cancel.sh
# 
#  Copyright: ©2011, Güralp Systems Ltd.
#  Author: Laurence Withers <lwithers@guralp.com>
#  License: GPLv3
#
#  This script can be used to cancel low latency mode on the CD24, and put it
#  back into the old BRP mode.
#

PORT="$1"
CF="/etc/conf.d/serial.local/${PORT}.cf"

if [ ! -e "${CF}" ]
then
	echo "Invalid port. Valid ports are:"
	ls /etc/conf.d/serial.local/*.cf | sed -e 's|\.cf$||' -e 's|^.*/||'
	exit 1
fi

fail() {
	echo "Failed!"
	exit 1
}

echo "Stopping port service"
svc "${PORT}" stop

echo "Writing updated configuration file"
gcs_rwvar "gcs_set_varcf" "function" "${CF}" "GCF in" || fail

echo "Sending recovery command"
cat > `gcs_rwvar "gcs_get_varcf" "device" "${CF}"` <<EOF


ok-1
0 fast-sps
go
EOF

echo "Starting port service"
svc "${PORT}" start || fail
