-$RAWLOAD -D 100 -r ao_radio_xmit.ihx
-echo -n "Generating RF carrier. Please enter measured frequency: "
-read FREQ
+dev=`ao-list | awk '/TeleDongle-v'"$VERSION"'/ { print $3; exit(0); }'`
+
+case "$dev" in
+/dev/tty*)
+ echo "TeleDongle found on $dev"
+ ;;
+*)
+ echo 'No TeleDongle-v'"$VERSION"' found'
+ exit 1
+ ;;
+esac
+
+echo 'E 0' > $dev
+
+CALFILE=cal-$SERIAL.txt
+
+../ao-tools/ao-cal-freq/ao-cal-freq --verbose --nosave --output=$CALFILE --tty=$dev
+
+case $? in
+ 0)
+ ;;
+ *)
+ echo "Frequency calibration failed"
+ exit 1
+ ;;
+esac
+
+CAL_VALUE=`cat $CALFILE`
+
+case "$CAL_VALUE" in
+ [1-9]*)
+ ;;
+ *)
+ echo "Invalid calibration value: $CAL_VALUE"
+ exit 1
+ ;;
+esac
+
+echo $SERIAL","$CAL_VALUE >> cal_values
+
+echo "Reflashing with calibration: $CAL_VALUE"