-
Notifications
You must be signed in to change notification settings - Fork 1
/
crane
executable file
·76 lines (68 loc) · 1.75 KB
/
crane
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
#!/bin/sh
# this is a bot controller script that we can use on botpc to quickly run tests and get data
TTY="/dev/ttyUSB0"
OUTFILE=""
while [ $# -gt 0 ]
do
case "$1" in
-o|--output)
OUTFILE="$2"
if ! [ -d $(dirname $OUTFILE) ]; then
echo "Output directory does not exist!"
exit 1
fi
echo "Saving to output file '$OUTFILE'";
shift 2
;;
start)
COMMAND="xy start";
shift 1
;;
reboot)
COMMAND="reboot";
shift 1
;;
move)
MOVETYPE="$2"
MOVEPOS="$3"
if ! [ "$MOVETYPE" = "abs" ] && ! [ "$MOVETYPE" = "rel" ] && ! [ "$MOVETYPE" = "none" ]; then
echo "Move type must be rel (relative) or abs (absolute) or none (dry run)"
exit 1
fi
if [ "$MOVETYPE" = "none" ]; then
COMMAND="move $MOVETYPE"
shift 2
else
COMMAND="move $MOVETYPE $MOVEPOS"
shift 3
fi
;;
test)
COMMAND="move test";
shift 1;
;;
status)
COMMAND="fb data"
shift 1
;;
esac
done
echo "Running '$COMMAND'"
stty igncr -F "$TTY" -raw 921600 -echo
printf "\r$COMMAND\r" > $TTY
# start as a child process and intercept ctrl-c so we can explicitly kill the child and cleanup
trap 'kill -TERM $PID' INT
if ! [ "$OUTFILE" = "" ]; then
cat $TTY > $OUTFILE &
else
cat $TTY &
fi
PID=$!
wait $PID
trap INT
# send a return key so that current action is aborted
echo "Stopping.."
printf "\r" > $TTY
# clear the command line
sleep 1
echo ""