-
Notifications
You must be signed in to change notification settings - Fork 13
/
setwave5200
executable file
·118 lines (107 loc) · 2.16 KB
/
setwave5200
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/bin/bash
# I expect to find my .dat and .awk files in the same directory I am in!
if [ -z "$1" -o "$1" == "--help" -o "$1" == "-h" ]
then
cat <<EOF
setwave5200 by Al Williams [email protected]
Public Domain -- use it how you like
Source: https://github.com/wd5gnr/mhs5200a
Usage:
setwave5200 [-f] port csvfile memory [csvfile memory ....]
-f Expect csvfiles to be between -1 and 1
(otherwise expect 0 to 255)
Example:
setwave5200 /dev/ttyUSB0 sine.csv 0 cos.csv 1 noise.csv 15
Memory is between 0 and 15
EOF
exit 1
fi
NORM=0
if [ "$1" == "-f" ]
then
NORM=1
shift
fi
PORT="$1"
stty -F "$PORT" 57600 cread ignbrk -brkint -icrnl -imaxbel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke min 60 time 1 -crtscts
shift
function cleanup() {
exec 3>&-
rm $TFILE
}
exec 3<>"$PORT"
TFILE=`mktemp -t waveXXXXXXXXXX`
RV=255
trap 'echo Aborting; cleanup; exit 255' EXIT
while [ ! -z "$2" ]
do
# Check for in range number
case "$2" in
''|*[!0-9]*)
echo Slot must be between 0 and 15
echo Skipping $1
shift
shift
continue
;;
esac
if [ "$2" -gt 15 ]
then
echo Slot must be between 0 and 15
echo Skipping $1
shift
shift
continue
fi
FILE="$1"
if [ $NORM == 1 ]
then
awk -f $0.norm.awk "$FILE" | awk -vchan="$2" -f "$0.awk" - "$0.dat" >"$TFILE"
RV=$?
else
awk -vchan="$2" -f "$0.awk" "$FILE" "$0.dat" >"$TFILE"
RV=$?
fi
if [ $RV == 0 ]
then
LCT=16
# For some reason this makes things more reliable in some cases
read -rs -t 1 DUMMY <&3
while read -r line
do
if [ "$line" != ":" ]
then
echo -n $LCT..
LCT=$((LCT - 1))
fi
# echo >&3
echo "$line" >&3
# echo >&3
if [ "$line" != ":" ]
then
read -rs -t 1 iline <&3
if [ $? -gt 128 -o "${iline:0:2}" != "ok" ]
then
echo Warning: instrument did not respond
fi
fi
sleep .01 # .005 was unreliable
done <"$TFILE"
echo
echo "$1 done"
else
echo
echo "$1 failed"
fi
shift
shift
done
if [ -n "$1" ]
then
echo Warning: Odd number of arguments
echo Use no arguments for help
exit 5
fi
trap - EXIT
cleanup
exit 0