-
Notifications
You must be signed in to change notification settings - Fork 0
/
ezchromato_multi.sh
201 lines (152 loc) · 4.13 KB
/
ezchromato_multi.sh
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#!/bin/bash
#
#-----computer install-----
# app needed
#sudo apt install gnuplot-qt smbclient
# add your user to the 'dialout' group to access usb
#sudo usermod -a -G dialout $USER
# and REBOOT the computer
# to avoid /dev/ttyUSB0 disconnections on ubuntu
#apt remove brltty
#-----script configuration-----
# data refresh rate in Hz (needed for gnuplot x range)
refreshRate=20
# enables network file copy [yes/no]
network_file_copy="yes"
# //server/share/folder (folder is optionnal)
server="serveur"
share="_inbox_"
folder="gc_inbox"
cd data
#-----------------------
# closing ezchromato
killall ezchromato > /dev/null 2>&1
# closing cat
killall cat > /dev/null 2>&1
# closing gnuplot
killall gnuplot > /dev/null 2>&1
killall gnuplot_qt > /dev/null 2>&1
clear
printf "
***********************************************************
____ _ _
___ ____/ ___| |__ _ __ ___ _ __ ___ __ _| |_ ___
/ _ \_ / | | '_ \| '__/ _ \| \'_ \` _ \ / _\` | __/ _ \
| __// /| |___| | | | | | (_) | | | | | | (_| | || (_) |
\___/___|\____|_| |_|_| \___/|_| |_| |_|\__,_|\__\___/
***********************************************************
"
num=$(($2+1))
now=`date +"%Y-%m-%d_%Hh%Mm%S"`
filename=$now"_"$num".fid"
mtime=$1
# echo " ->S1 : "$1
# echo " ->S2 : "$2
if [ -n "$mtime" ]
then
time=$((mtime*60))
gpxrange=$((time*$refreshRate))
else
echo "no time argument specified - exit"
echo "usage : ezchromato_multi.sh time"
exit 0
fi
#echo " ->filename : "$filename
#echo " ->time : "$time
echo -n ' '
# ctrl+c exits script but copy file to network share before
trap ctrl_c INT
function ctrl_c() {
#ctrl_cc $filename
echo
echo
echo " ctrl+c detected -> save and exit"
# closing cat
killall cat > /dev/null 2>&1
# closing gnuplot
killall gnuplot > /dev/null 2>&1
killall gnuplot_qt > /dev/null 2>&1
# closing ezchromato_multi
#killall ezchromato_multi > /dev/null 2>&1
exit 1
}
# function ctrl_cc() {
# echo
# echo
# echo " ctrl+c detected -> save and exit"
# if [ $network_file_copy = "yes" ]; then
# copy $filename
# fi
# }
function copy() {
echo
echo " copying file, please wait"
#echo -n " "
# quiet smbclient upload
smbclient -d 0 //$server/$share -U guest% -c 'cd '$folder' ; put '$1 > /dev/null 2>&1
# debug smbclient upload
#smbclient //$server/$share -U guest% -c 'cd '$folder' ; put '$1
}
# set com port to raw to avoid extra new lines in data
stty raw -F /dev/ttyUSB0 115200 cs8 -cstopb -parenb
# purge old data from com port buffer
timeout 1 cat /dev/ttyUSB0 > /dev/null
# set com port to raw to avoid extra new lines in data
stty raw -F /dev/ttyUSB0 115200 cs8 -cstopb -parenb
echo "file : "$filename
echo -n ' '
# create the file
echo "" > $filename
# realtime data plotting
#gnuplot -e "acquisition_in_progress='$filename'" ezchromato.gp 2> /dev/null &
#gnuplot -e "acquisition_in_progress='$filename'" -e "ezrange='$gpxrange'" ../ezchromato.gp &
gnuplot -e "acquisition_in_progress='$filename'" -e "ezrange='$gpxrange'" ../ezchromato.gp 2> /dev/null &
# acquisition to file
#cat -v /dev/ttyUSB0
cat /dev/ttyUSB0 > $filename &
echo
echo " waiting for data"
# acquisition waiting loop
filesize=0
while [[ $filesize = [0] ]]; do
# waiting for acquisition
filesize=$(stat --format=%s $filename)
sleep 0.01
#echo -n "."
done
echo
echo " acquisition started"
# waiting while acquisition method 1
sleep $time
# waiting while acquisition method 2 (more precise than sleep)
# wwaEnd=$((SECONDS+$time))
# while [ $SECONDS -lt $wwaEnd ]; do
# # waiting while acquisition
# sleep 0.05
# #echo -n ""
# done
# closing cat
killall cat > /dev/null 2>&1
# closing gnuplot
killall gnuplot > /dev/null 2>&1
killall gnuplot_qt > /dev/null 2>&1
# reset com port to stop arduino acquisition
stty raw -F /dev/ttyUSB0 115200 cs8 -cstopb -parenb
echo
echo " acquisition stopped"
# copy file to network share
if [ $network_file_copy = "yes" ]; then
copy $filename
fi
echo
echo " all ok - goodbye"
echo "
***********************************************************
"
cd ..
./ezchromato_multi.sh $mtime $num &
#1=''
#2=''
#mtime=''
#num=''
exit 0