#!/bin/sh
# Syntorxgen Configuration File Builder v0.1
# 12/21/03
# (C) 2003 Kris Kirby <kris@catonic.net>
# All Rights Reserved.
echo "Syntorxgen Configbuilder"
echo "(C) 2003 Kris Kirby <kris@catonic.net>"
echo "All Rights Reserved. Enter "q" at \"Label:\" prompt to exit and save."
file=$1
mode=1
timeout=300
if [ $# -ne 1 ]; then
	echo "Missing output filename or have too much stuff on command line."
	exit 0
fi

while true; do
echo "Mode: $mode"
echo -n " Label:" ; read label
if [ "${label}" = "q" ]; then 
	echo "nmodes `expr $mode - 1`;" >> $file
	exit
fi
echo -n " RX Freq:"; read rxfreq
if [ `echo ${rxfreq} | grep "+" | wc -l` -eq 1 ]; then
	rxfreq=`echo $rxfreq | sed -e "s/+//g" -e "s/ //g"`
	IFS="."
	set $rxfreq
	tmp=`echo $1`
	IFS=""
	if [ \( ${tmp} -ge 28 \) -a \( ${tmp} -le 30 \) ]; then 
		echo "  >Setting TX to +100KHz"
		txfreq=`echo $rxfreq + 0.100 | bc -l`
	fi
	if [ \( ${tmp} -ge 50 \) -a \( ${tmp} -le 54 \) ]; then 
		echo "  >Setting TX to +1MHz"
		txfreq=`echo $rxfreq + 1.000 | bc -l`
	fi
	if [ \( ${tmp} -ge 144 \) -a \( ${tmp} -le 148 \) ]; then 
		echo "  >Setting TX to +600KHz"
		txfreq=`echo $rxfreq + 0.600 | bc -l`
	fi
	if [ \( ${tmp} -ge 222 \) -a \( ${tmp} -le 225 \) ]; then 
		echo "  >Setting TX to +1.6MHz"
		txfreq=`echo $rxfreq + 1.600 | bc -l`
	fi
	if [ \( ${tmp} -ge 420 \) -a \( ${tmp} -le 470 \) ]; then 
		echo "  >Setting TX to +5MHz"
		txfreq=`echo $rxfreq + 5.000 | bc -l`
	fi
	if [ \( ${tmp} -ge 902 \) -a \( ${tmp} -le 928 \) ]; then 
		echo "  >Setting TX to +12MHz"
		txfreq=`echo $rxfreq + 12.000 | bc -l`
	fi
	unset tmp
elif [ `echo ${rxfreq} | grep "-" | wc -l` -eq 1 ]; then
	rxfreq=`echo $rxfreq | sed -e "s/-//g" -e "s/ //g"`
	IFS="."
	set $rxfreq
	tmp=`echo $1`
	IFS=""
	if [ \( ${tmp} -ge 28 \) -a \( ${tmp} -le 30 \) ]; then 
		echo "  >Setting TX to -100KHz"
		txfreq=`echo $rxfreq - 0.100 | bc -l`
	fi
	if [ \( ${tmp} -ge 50 \) -a \( ${tmp} -le 54 \) ]; then 
		echo "  >Setting TX to -1MHz"
		txfreq=`echo $rxfreq - 1.000 | bc -l`
	fi
	if [ \( ${tmp} -ge 144 \) -a \( ${tmp} -le 148 \) ]; then 
		echo "  >Setting TX to -600KHz"
		txfreq=`echo $rxfreq - 0.600 | bc -l`
	fi
	if [ \( ${tmp} -ge 222 \) -a \( ${tmp} -le 225 \) ]; then 
		echo "  >Setting TX to -1.6MHz"
		txfreq=`echo $rxfreq - 1.600 | bc -l`
	fi
	if [ \( ${tmp} -ge 420 \) -a \( ${tmp} -le 470 \) ]; then 
		echo "  >Setting TX to -5MHz"
		txfreq=`echo $rxfreq - 5.000 | bc -l`
	fi
	if [ \( ${tmp} -ge 902 \) -a \( ${tmp} -le 928 \) ]; then 
		echo "  >Setting TX to -12MHz"
		txfreq=`echo $rxfreq - 12.000 | bc -l`
	fi
	unset tmp
fi

if [ -z ${txfreq} ]; then
echo -n " TX Freq:"; read txfreq
fi

echo -n " PL:"; read pl
echo -n " DPL:"; read dpl

echo "mode $mode {" >> $file
echo "	label \"$label\";" >> $file
echo "	rxfreq $rxfreq;" >> $file 
echo "	txfreq $txfreq;" >> $file
if [ -z ${pl} ]; then
else
	echo "	rxpl $pl;" >> $file
	echo "	txpl $pl;" >> $file
fi
if [ -z ${dpl} ]; then
else
	echo "	rxdpl $dpl;" >> $file
	echo "	txdpl $dpl;" >> $file
fi
echo "	timeout $timeout;" >> $file
echo "};" >> $file
mode=`expr $mode + 1`
unset txfreq

# figure this out later
#nmodes 5;
#txvcosplit 150.000; # Fix us!  For tx, factory setting mostly works
#rxvcosplit 154.000; # For rx, it depends on how you mod the VCO
#	mode 1
#	{
#		label "KB4CRG 147.24+";
#		txfreq 147.840;
#		rxfreq 147.240;
#		txpl 82.5;
#		rxpl 82.5;
#		timeout 300;
#	};

done
