-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdesip_message_conversion.sh
executable file
·94 lines (87 loc) · 1.64 KB
/
desip_message_conversion.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
#!/bin/bash
INPUT_FILE="invalid"
Usage() {
echo " "
echo "`basename $1` - version:20190405"
echo " "
echo "This script is used to conversion desip message from desip uart log."
echo "The input file's name is necesarry,you could use -f to special its"
echo "name.Also you are able to assign a output file name by -o,if you "
echo "don't use it,the output name will be <input_file>_update.txt."
echo " "
echo "Usage:"
echo "`basename $1` -f <input_file> [-o <output_file>] [-h]"
echo " "
return 0
}
while getopts "f:o:h" arg
do
case $arg in
f)
INPUT_FILE="$OPTARG"
;;
o)
OUTPUT_FILE="$OPTARG"
;;
h|?|*)
Usage $0
exit 0
esac
done
if [ "Y"$INPUT_FILE = "Y" -o ! -f $INPUT_FILE ];then
echo "[ERROR] Please give desip message file name."
Usage $0
exit 1
fi
if [ "Y"$OUTPUT_FILE = "Y" ];then
OUTPUT_FILE="`basename $INPUT_FILE`"
OUTPUT_FILE="${OUTPUT_FILE%.*}_update.txt"
fi
if [ -f $OUTPUT_FILE ];then
rm -rf $OUTPUT_FILE
fi
while read line
do
arr=($line)
count=0
skip=0
for word in ${arr[@]}
do
if [ $skip -gt 0 ];
then
((skip --))
((count ++))
continue
fi
case $word in
"1B")
if [ ${arr[((count+1))]} == "1D" ];
then
echo -n "1B " >> $OUTPUT_FILE
((skip ++))
echo -n "."
elif [ ${arr[((count+1))]} == "1E" ];
then
echo -n "1C " >> $OUTPUT_FILE
((skip ++))
echo -n "."
else
echo " " >> $OUTPUT_FILE
echo $word >> $OUTPUT_FILE
echo -n "."
fi
;;
"1C")
echo "" >> $OUTPUT_FILE
echo -n "|"
;;
*)
echo -n "$word " >> $OUTPUT_FILE
echo -n "."
;;
esac
((count ++))
done
done < $INPUT_FILE
echo ""
exit 0