submodule madness
[fw/altos] / ao-bringup / turnon_teledongle
1 #!/bin/sh
2
3 if [ -x ../ao-tools/ao-flash/ao-flash-lpc ]; then
4         FLASH_LPC=../ao-tools/ao-flash/ao-flash-lpc
5 elif [ -x /usr/bin/ao-flash-lpc ]; then
6         FLASH_LPC=/usr/bin/ao-flash-lpc
7 else
8         echo "Can't find ao-flash-lpc!  Aborting."
9         exit 1
10 fi
11
12 if [ -x /usr/bin/ao-usbload ]; then
13         USBLOAD=/usr/bin/ao-usbload
14 else
15         echo "Can't find ao-usbload!  Aborting."
16         exit 1
17 fi
18
19 PRODUCT=teledongle
20 PRODUCT_NAME=TeleDongle
21 VERSION=3.0
22
23 echo "$PRODUCT_NAME v$VERSION Turn-On and Calibration Program"
24 echo "Copyright © 2015 by Bdale Garbee.  Released under GPL v2"
25 echo
26 echo "Expectations:"
27 echo "\t$PRODUCT_NAME v$VERSION powered from USB"
28 echo "\t\twith ST-Link-V2 cabled to debug header"
29 echo "\t\twith coax from UHF to frequency counter"
30 echo
31 echo -n "$PRODUCT_NAME-$VERSION serial number: "
32 read SERIAL
33
34 BINARIES=$HOME/altusmetrumllc/Binaries
35
36 LOADER="$BINARIES/loaders/$PRODUCT-v$VERSION-"*.elf
37 ALTOS="$BINARIES/$PRODUCT-v$VERSION"*.elf
38
39 $FLASH_LPC $LOADER || exit 1
40
41 sleep 2
42
43 $USBLOAD --serial=$SERIAL $ALTOS || exit 1
44
45 sleep 5
46
47 dev=`ao-list | awk '/TeleDongle-v'"$VERSION"'/ { print $3; exit(0); }'`
48
49 case "$dev" in
50 /dev/tty*)
51         echo "TeleDongle found on $dev"
52         ;;
53 *)
54         echo 'No TeleDongle-v'"$VERSION"' found'
55         exit 1
56         ;;
57 esac
58
59 echo 'E 0' > $dev
60
61 SERIAL=$SERIAL ./cal-freq $dev
62
63 case $? in
64     0)
65         ;;
66     *)
67         echo "Frequency calibration failed"
68         exit 1
69         ;;
70 esac
71
72 CAL_VALUE=`grep "^$SERIAL," cal_values | tail -1 | sed 's/^[^,]*,//'`
73
74 case "$CAL_VALUE" in
75     [1-9]*)
76     ;;
77     *)
78         echo "Invalid calibration value: $CAL_VALUE"
79         exit 1
80         ;;
81 esac
82
83 echo "Reflashing with calibration: $CAL_VALUE"
84
85 $USBLOAD --cal=$CAL_VALUE --tty=$dev $ALTOS || exit 1
86
87 echo "$PRODUCT_NAME-v$VERSION $SERIAL is ready to ship"
88
89 exit $?