-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathenmea2
executable file
·247 lines (223 loc) · 7.39 KB
/
enmea2
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
#!/bin/bash
# function parallel() {
# sleep "$1"
# echo p$2
# exit "$2"
# }
#
#
# parallel 3 1 &
# parallel 6 2 &
# wait
# echo end
#exit
if [ -z "$1" -o -z "$2" ]
then
echo "Format isn't correct!"
echo "Use:"
echo "enmea input_file output_filename [show_progress]"
exit
fi
if [ -e "$2" ]
then
echo -n "File $2 exist, rewrite it? (Y/n) "
read item
case "$item" in
y|Y) echo "Start processing..."
;;
n|N) echo "Exit"
exit 0
;;
*) echo "Start processing..."
;;
esac
fi
IN_FILE_LIST=$1
GGA_decode_counter=0
GSV_decode_counter=0
unknown_decode_counter=0
sat_v=( 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 )
sat_v_notnull=( 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 )
start_work=0
total_GGA=`grep -c GGA "$1"`
# message_time_PRE=`cat $IN_FILE_LIST | grep GPGGA -m 1 | cut -d "," -f2 | cut -d "." -f1`
# message_time=`expr $message_time_PRE - 1`
function number_check() {
local nc
if [ -z "$1" ]
then
nc=0
echo "BAD"
else
nc=$1
fi
echo $nc
}
if [[ -z "$4" || $4 == 0 ]]
then
THREADS=`cat /proc/cpuinfo | grep -c processor`
else
THREADS=$4
fi
THREADS=2
echo "Using $THREADS processors"
#rm -rf /tmp/nmea/log
#FILE_IN=`grep -E "GGA|GSV" $IN_FILE_LIST | cut -d "*" -f1`
#echo "$FILE_IN" | sed 's/,/\ /g'
#echo "$FILE_IN" | head
#exit 0
grep -E "GGA|GSV" $IN_FILE_LIST | cut -d "*" -f1 | sed 's/,08,/,8,/g' | sed 's/,09,/,9,/g' > /tmp/nmea
pushd /tmp
string_count=`wc -l nmea | awk '{print $1}'`
strings_in_file=`expr $string_count / $THREADS`
split nmea -d -l $strings_in_file
string_overhead_0=`grep GGA x01 -m 1 -n | cut -d ":" -f1`
string_overhead_1=`expr $string_overhead_0 - 1`
head -n $string_overhead_1 x01 >> x00
tail -n +$string_overhead_0 x01 > x01_tmp
popd
rm -f "$2"
function write_sat() {
if [ -n "${sv_number[$1]}" ]
then
sat_v[${sv_number[$1]}]=`echo "$one_string" | cut -d "," -f$2`
fi
}
function part_processing() {
local sat_v=( 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 )
local sat_v_notnull=( 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 )
rm -f "$2"
local navmes
local message_time
local hdop
local GGA_decode_counter
local total_messages
local message_number
local sv_number=( 0 1 2 3 )
local total_GGA=`grep -c GGA "$1"`
local FILE_IN=`grep -E "GGA|GSV" $1 | cut -d "*" -f1`
#echo "$FILE_IN" | tail
for one_string in `echo "$FILE_IN"`
do
#echo $one_string
#awk '{print $1}' | sed 's/,/\ /g'
#one_string=`echo "$one_string"`
navmes=`echo "$one_string" | cut -d "," -f1 `
if [ "$navmes" == "\$GPGGA" ]
then
#message_time_H=`echo "$one_string" | cut -c8,9`
#message_time_M=`echo "$one_string" | cut -c9,10`
#message_time_S=`echo "$one_string" | cut -c11,12`
#message_time=`expr $message_time_H * 3600 + $message_time_M * 60 + $message_time_S`
message_time=`echo "$one_string" | cut -d "," -f2 | cut -d "." -f1`
#LATITUDE=`echo "$one_string" | cut -d "," -f3`
#N_S=`echo "$one_string" | cut -d "," -f4`
#LONGITUDE=`echo "$one_string" | cut -d "," -f5`
#E_W=`echo "$one_string" | cut -d "," -f6`
#GPS_QUALITY=`echo "$one_string" | cut -d "," -f7`
#TOTAL_SATELLITES=`echo "$one_string" | cut -d "," -f8`
hdop=`echo "$one_string" | cut -d "," -f9`
if [ -z "$hdop" ]
then
hdop=0
fi
#ALTITUDE=`echo "$one_string" | cut -d "," -f10`
#ALTITUDE_UNITS=`echo "$one_string" | cut -d "," -f11`
#GEOIDAL_SEPARATION=`echo "$one_string" | cut -d "," -f12`
#GEOIDAL_SEPARATION_UNITS=`echo "$one_string" | cut -d "," -f13`
#message_time=`echo "$one_string" | cut -d "," -f14`
#message_time=`echo "$one_string" | cut -d "," -f15`
#message_time=`echo "$one_string" | cut -d "," -f16`
GGA_decode_counter=`expr $GGA_decode_counter + 1`
#sat_v contain 33 vars: message_time + 32 satellites
sat_v=( 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 )
# if [ -z "$3" ]
# then
# echo -ne "\rGGA: $GGA_decode_counter of $total_GGA"
# fi
elif [ "$navmes" == "\$GPGSV" ]
then
total_messages=`echo "$one_string" | cut -d "," -f2`
message_number=`echo "$one_string" | cut -d "," -f3`
# TOTAL_SV=`echo "$one_string" | cut -d "," -f4`
sv_number[0]=`echo "$one_string" | cut -d "," -f5`
sv_number[1]=`echo "$one_string" | cut -d "," -f9`
sv_number[2]=`echo "$one_string" | cut -d "," -f13`
sv_number[3]=`echo "$one_string" | cut -d "," -f17`
# ELEVATION[$M]=`echo "$one_string" | cut -d "," -f${FF[1]}`
# AZIMUTH[$M]=`echo "$one_string" | cut -d "," -f${FF[2]}`
write_sat 0 8 &
write_sat 1 12 &
write_sat 2 16 &
write_sat 3 20 &
wait
# sat_v[${sv_number[0]}]=`echo "$one_string" | cut -d "," -f8`
# # sat_v[$sv_number]=`number_check ${sat_v[$sv_number]}`
# if [ -n "${sv_number[1]}" ]
# then
# sat_v[$sv_number[1]]=`echo "$one_string" | cut -d "," -f12`
# # sat_v[$sv_number]=`number_check ${sat_v[$sv_number]}`
# if [ -n "${sv_number[2]}" ]
# then
# sat_v[${sv_number[2]}]=`echo "$one_string" | cut -d "," -f16`
# # sat_v[$sv_number]=`number_check ${sat_v[$sv_number]}`
# if [ -n "${sv_number[3]}" ]
# then
# sat_v[${sv_number[3]}]=`echo "$one_string" | cut -d "," -f20`
# # sat_v[$sv_number]=`number_check ${sat_v[$sv_number]}`
# fi
# fi
# fi
if [ "$total_messages" == "$message_number" ]
then
sat_v[0]=$message_time
echo "${sat_v[@]} $hdop" >> "$2"
fi
#GSV_decode_counter=`expr $GSV_decode_counter + 1`
else
echo -n ""
#echo "Unknown Navigation message"
#$unknown_decode_counter=`expr $unknown_decode_counter + 1`
fi
done
if [ -n "$3" ]
then
echo -e "GGA: $GGA_decode_counter of $total_GGA "
fi
}
part_processing /tmp/x00 /tmp/nmea_decode_0 1 &
part_processing /tmp/x01_tmp /tmp/nmea_decode_1 1 &
wait
cat /tmp/nmea_decode_0 /tmp/nmea_decode_1 > "$2"
#echo -e "\nGSV: $GSV_decode_counter"
if [ -n "$3" ]
then
echo -ne "GGA: $GGA_decode_counter of $total_GGA"
fi
#echo -e "\nUnknown: $unknown_decode_counter"
echo -en "Detected all satellites numbers: "
for ((k=2; k < 34 ; k++))
do
check0=0
check1=0
st=`cut "$2" -d " " -f$k`
for one_string in $st
do
if [ $one_string -ne "0" ]
then
check1=1
else
check0=1
fi
done
if [ $check1 -eq "1" ]
then
if [ $check0 -eq "1" ]
then
echo -en "\e[31m`expr $k - 1`\e[0m "
else
echo -en "\e[32m`expr $k - 1`\e[0m "
fi
fi
done
echo ""