]> git.gag.com Git - fw/altos/blob - ao-bringup/turnon_teledongle
altos: Add lambda support to lisp
[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
32 case $# in
33     1)
34         SERIAL="$1"
35         echo "$PRODUCT-$VERSION serial number: $SERIAL" 
36         ;;
37     0)
38         echo -n "$PRODUCT-$VERSION serial number: "
39         read SERIAL
40         ;;
41     *)
42         echo "Usage: $0 <serial-number>" 1>&2
43         exit 1;
44         ;;
45 esac
46
47 BINARIES=$HOME/altusmetrumllc/Binaries
48
49 LOADER="$BINARIES/loaders/$PRODUCT-v$VERSION-"*.elf
50 ALTOS="$BINARIES/$PRODUCT-v$VERSION"*.elf
51
52 $FLASH_LPC $LOADER || exit 1
53
54 sleep 2
55
56 $USBLOAD --serial=$SERIAL $ALTOS || exit 1
57
58 sleep 5
59
60 dev=`ao-list | awk '/TeleDongle-v'"$VERSION"'/ { print $3; exit(0); }'`
61
62 case "$dev" in
63 /dev/tty*)
64         echo "TeleDongle found on $dev"
65         ;;
66 *)
67         echo 'No TeleDongle-v'"$VERSION"' found'
68         exit 1
69         ;;
70 esac
71
72 echo 'E 0' > $dev
73
74 SERIAL=$SERIAL ./cal-freq $dev
75
76 case $? in
77     0)
78         ;;
79     *)
80         echo "Frequency calibration failed"
81         exit 1
82         ;;
83 esac
84
85 CAL_VALUE=`grep "^$SERIAL," cal_values | tail -1 | sed 's/^[^,]*,//'`
86
87 case "$CAL_VALUE" in
88     [1-9]*)
89     ;;
90     *)
91         echo "Invalid calibration value: $CAL_VALUE"
92         exit 1
93         ;;
94 esac
95
96 echo "Reflashing with calibration: $CAL_VALUE"
97
98 $USBLOAD --cal=$CAL_VALUE --tty=$dev $ALTOS || exit 1
99
100 echo "$PRODUCT_NAME-v$VERSION $SERIAL is ready to ship"
101
102 exit $?