-$RAWLOAD -D $programmer -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
+
+SERIAL=$SERIAL ./cal-freq $dev
+
+case $? in
+ 0)
+ ;;
+ *)
+ echo "Frequency calibration failed"
+ exit 1
+ ;;
+esac
+
+CAL_VALUE=`grep "^$SERIAL," cal_values | tail -1 | sed 's/^[^,]*,//'`
+
+case "$CAL_VALUE" in
+ [1-9]*)
+ ;;
+ *)
+ echo "Invalid calibration value: $CAL_VALUE"
+ exit 1
+ ;;
+esac
+
+echo "Reflashing with calibration: $CAL_VALUE"