-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathenmea
executable file
·200 lines (182 loc) · 6.07 KB
/
enmea
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
#!/bin/bash
detecting="GGA|GPGSV|GLGSV"
if [ -z "$1" -o -z "$2" ]
then
echo "Format isn't correct!"
echo "Use:"
echo "enmea input_file output_filename [show_progress]"
exit 1
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
max_sat_num=96
IN_FILE_LIST=$1
GGA_decode_counter=0
GSV_decode_counter=0
unknown_decode_counter=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`
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 "$detecting" $IN_FILE_LIST | cut -d "*" -f1 | sed 's/,08,/,8,/g' | sed 's/,09,/,9,/g' | sed 's/,09[1-9],/,9,/g' > /tmp/nmea
pushd /tmp > /dev/null
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 > /dev/null
rm -f "$2"
function snrs() {
if [ -n $2 ] && [ ! $2 == T ]; then
sat_v[$1]=$2
fi
if [ -n $4 ] && [ ! $4 == T ]; then
sat_v[$3]=$4
fi
if [ -n $6 ] && [ ! $6 == T ]; then
sat_v[$5]=$6
fi
if [ -n $8 ] && [ ! $8 == T ]; then
sat_v[$7]=$8
fi
}
function part_processing() {
local sat_v=( 0 0 )
for i in $(seq 1 $max_sat_num); do
sat_v[$i]=0
done
rm -f "$2"
local navmes
local message_time
local hdop
local GGA_decode_counter
local total_messages
local message_number
local sv_number
local total_GGA=`grep -c GGA "$1"`
local FILE_IN=`grep -E "$detecting" $1 | cut -d "*" -f1`
#echo "$FILE_IN" | tail
# dbg_i=0
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
sat_v[0]=$message_time
echo "${sat_v[@]} $hdop" >> "$2"
#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
for i in $(seq 1 $max_sat_num); do
sat_v[$i]=0
done
# if [ -z "$3" ]
# then
# echo -ne "\rGGA: $GGA_decode_counter of $total_GGA"
# fi
elif [ "$navmes" == "\$GPGSV" ] || [ "$navmes" == "\$GLGSV" ]; 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`
# ELEVATION[$M]=`echo "$one_string" | cut -d "," -f${FF[1]}`
# AZIMUTH[$M]=`echo "$one_string" | cut -d "," -f${FF[2]}`
sv_in_string=$(echo "$one_string" | cut -d "*" -f1 | sed 's|,,|,T,|g' | sed 's|,\*|,T,|g' \
| cut -d "," -f5,8,9,12,13,16,17,20 | tr "," " ")
snrs $sv_in_string
#GSV_decode_counter=`expr $GSV_decode_counter + 1`
else
echo -n ""
#echo "Unknown Navigation message"
#$unknown_decode_counter=`expr $unknown_decode_counter + 1`
fi
# dbg_i=`expr $dbg_i + 1`
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
tail -n +2 /tmp/nmea_decode_0 > /tmp/nmea_decode_00
tail -n +2 /tmp/nmea_decode_1 > /tmp/nmea_decode_11
cat /tmp/nmea_decode_00 /tmp/nmea_decode_11 > "$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 satellites numbers: "
for ((k=2; k < 98 ; 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 ""