-
Notifications
You must be signed in to change notification settings - Fork 5
/
run.sh.in
executable file
·122 lines (101 loc) · 3.14 KB
/
run.sh.in
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
118
119
120
121
122
#!/bin/bash -
#===============================================================================
#
# FILE: run.sh
#
# USAGE: ./run.sh
#
# DESCRIPTION: This script run the acquisition.
# On user unterrupt, we send SIGINT to C++ binary which is the
# best way to cleaup the camera before shutting down.
#
# AUTHOR: Dilawar Singh (), [email protected]
# ORGANIZATION: NCBS Bangalore
# CREATED: Tuesday 06 December 2016 03:05:41 IST
#===============================================================================
set -o nounset # Treat unset variables as an error
set -e
COMMAND=`pwd`/cam_server
MOUSE_PATH="@MOUSE_PATH@"
# Check if user is member of dialout group.
if id -nG $USER | grep -qw "dialout"; then
echo "$USER belongs to dialout group. Cool";
else
echo "Add $USER to dialout group"
echo " Execute 'sudo gpasswd -a $USER dialout' and relogin"
exit;
fi
# Call
function kill_process( )
{
PID=$1
echo "Trying to kill $PID"
CMD=`ps -p $PID -o comm=`
echo "\tCommand: $CMD"
kill -9 $PID
if ps -p $PID > /dev/null; then
printf "\tWARN: Process with PID %d is still running\n", $PID
else
printf "\tSucessfully killed %d\n", $PID
fi
# Just to be sure. Remove other process as well.
killall -9 $COMMAND
}
# Handle Ctrl+C
function kill_acquition_from_point_grey( )
{
echo "Ctrl+c pressed. Terminating processes $1"
kill_process $1
# Cleanup /mnt/ramdisk
find /mnt/ramdisk -user $USER -print0 | xargs -0 rm
}
function kill_acquition_from_mouse( )
{
echo "Ctrl+c pressed. Terminating processes $1"
kill_process $1
}
# First, we execute the binary file acquition_from_point_grey in background and
# save its PID. We can use the PID to kill this process.
if pgrep $(basename $COMMAND)
then
ACQ_PID=$(pgrep $(basename $COMMAND))
ACQ_PID=`echo "$ACQ_PID" | tr -d ' '`
if [ $ACQ_PID ]; then
echo "Camera server already running";
fi
else
echo "Lauching camera server"
$COMMAND &
ACQ_PID=`echo $!`
fi
if [ ! $ACQ_PID ]; then
echo "Can't launch camera. I won't continue"
exit
fi
trap 'kill_acquition_from_point_grey ${ACQ_PID}' INT
echo "Running acquition app , PID = ${ACQ_PID}"
# Sleep for three seconds before launching python script.
sleep 3;
if pgrep $(basename $COMMAND)
then
echo "Camera server is still running. Lets continue ..."
else
echo "Camera server is not running. Won't continue ...."
exit;
fi
# lauch the mouse server.
python ./mouse_server.py ${MOUSE_PATH} &
export MOUSE_PID=$!
trap 'kill_acquition_from_mouse $MOUSE_PID' INT
echo "Lauched MOUSE server with PID=$MOUSE_PID"
# Now check if camera server is still running. If not don't continue
# Now run python script to acquire data. If user press Ctrl+c to stop it, we
# must send ctrl+c to PID acquition_from_point_grey app as well.
echo "Launching ardunio+camera client with options: $@"
set +e
python ./camera_arduino_client.py $@
set -e
# If we have come here successfully, cleanup.
killall $(basename $COMMAND) || echo "Nothing to kill"
# Reset boards
make reset_boards