1
|
#!/bin/sh
|
2
|
|
3
|
|
4
|
updDatFile=$1
|
5
|
|
6
|
#֧???ͺ????ݲ??????µ???
|
7
|
echo "smType Info upd import: $updDatFile"
|
8
|
|
9
|
cd /NandFlash
|
10
|
|
11
|
echo "CurDir=`pwd`"
|
12
|
|
13
|
getPort()
|
14
|
{
|
15
|
#Ĭ??485
|
16
|
ret=4
|
17
|
#DI;DO;232;485;NET
|
18
|
|
19
|
echo "$1"
|
20
|
|
21
|
case "$1" in
|
22
|
"DI")
|
23
|
ret=1
|
24
|
;;
|
25
|
"DO")
|
26
|
ret=2
|
27
|
;;
|
28
|
"232")
|
29
|
ret=3
|
30
|
;;
|
31
|
"485")
|
32
|
ret=4
|
33
|
;;
|
34
|
"NET")
|
35
|
ret=6
|
36
|
;;
|
37
|
*)
|
38
|
echo "nknow Port"
|
39
|
;;
|
40
|
esac
|
41
|
|
42
|
return ${ret};
|
43
|
}
|
44
|
|
45
|
getSubSys()
|
46
|
{
|
47
|
#Ĭ????
|
48
|
ret=0
|
49
|
#??;1-?е???;2-?????;3-UPS???;4-??ؼ??;5-?¶?ʪ??;6-©ˮ???;7-?յ????;8-???ܿյ?;9-???????;10-??????;11-?Ž??Ŵ?;12-?????Ƶ;13-??????ʾ
|
50
|
|
51
|
echo "$1"
|
52
|
|
53
|
case "$1" in
|
54
|
"1-"*)
|
55
|
ret=1
|
56
|
;;
|
57
|
"2-"*)
|
58
|
ret=2
|
59
|
;;
|
60
|
"3-"*)
|
61
|
ret=3
|
62
|
;;
|
63
|
"4-"*)
|
64
|
ret=4
|
65
|
;;
|
66
|
"5-"*)
|
67
|
ret=5
|
68
|
;;
|
69
|
"6-"*)
|
70
|
ret=6
|
71
|
;;
|
72
|
"7-"*)
|
73
|
ret=7
|
74
|
;;
|
75
|
"8-"*)
|
76
|
ret=8
|
77
|
;;
|
78
|
"9-"*)
|
79
|
ret=9
|
80
|
;;
|
81
|
"10-"*)
|
82
|
ret=10
|
83
|
;;
|
84
|
"11-"*)
|
85
|
ret=11
|
86
|
;;
|
87
|
"12-"*)
|
88
|
ret=12
|
89
|
;;
|
90
|
"13-"*)
|
91
|
ret=13
|
92
|
;;
|
93
|
*)
|
94
|
echo "unknow subsys"
|
95
|
;;
|
96
|
esac
|
97
|
|
98
|
return ${ret};
|
99
|
}
|
100
|
|
101
|
#https://www.runoob.com/w3cnote/shell-read-line.html
|
102
|
|
103
|
while read line
|
104
|
do
|
105
|
#echo $line
|
106
|
|
107
|
#
|
108
|
#arrData=(${line//,/ })
|
109
|
|
110
|
#echo ${!arrData[@]}
|
111
|
|
112
|
#
|
113
|
#echo $line |awk -F, '{print $1}'
|
114
|
|
115
|
#https://blog.csdn.net/u010003835/article/details/80750003
|
116
|
#https://blog.csdn.net/jacob107/article/details/87013243
|
117
|
|
118
|
OLD_IFS="$IFS"
|
119
|
IFS=";"
|
120
|
arr=($line)
|
121
|
IFS="$OLD_IFS"
|
122
|
nPort=4
|
123
|
nSubSys=0
|
124
|
|
125
|
#https://www.cnblogs.com/xibuhaohao/p/11542169.html
|
126
|
expr ${arr[0]} "+" 10 &> /dev/null
|
127
|
if [ $? -eq 0 ];then
|
128
|
echo "${arr[0]} ${arr[1]} ${arr[2]} ${arr[3]} ${arr[4]} ${arr[5]} ${arr[6]} ${arr[7]} ${arr[8]} ${arr[9]}"
|
129
|
|
130
|
#DI;DO;232;485;NET
|
131
|
getPort ${arr[4]}
|
132
|
nPort=$?
|
133
|
|
134
|
echo "nPort=${nPort}"
|
135
|
|
136
|
getSubSys ${arr[9]}
|
137
|
nSubSys=$?
|
138
|
|
139
|
echo "nSubSys=${nSubSys}"
|
140
|
|
141
|
#if [ ]
|
142
|
#AI ?豸???ӣ?tbAIDef??
|
143
|
|
144
|
|
145
|
#tbSMType?б???Ƿ???????
|
146
|
cntIns=$(sqlite3 dbCfg.db3 "select count(*) from tbSMType where Type='${arr[6]}' and Tag1='${arr[7]}'")
|
147
|
echo "cntIns: $cntIns"
|
148
|
if [ $cntIns -eq 0 ];then
|
149
|
#δ????????????
|
150
|
echo "new Type"
|
151
|
Type=${arr[6]}
|
152
|
kind=`expr $Type - $Type % 256`
|
153
|
echo "Type: $Type,Kind: $kind"
|
154
|
$(sqlite3 dbCfg.db3 "insert into tbSMType values(${Type},${kind},'${arr[2]}','${arr[3]}',${arr[7]},${arr[8]},${nPort},'${arr[5]}',0,0,0,0,0,0,${nSubSys})")
|
155
|
|
156
|
#echo "$?"
|
157
|
if [ $? -eq 0 ];then
|
158
|
echo "Add SM${Type}-${arr[7]} Successe"
|
159
|
else
|
160
|
echo "Add SM${Type}-${arr[7]} Fail"
|
161
|
fi
|
162
|
##
|
163
|
else
|
164
|
#???????????
|
165
|
echo "old Type"
|
166
|
Type=${arr[6]}
|
167
|
kind=`expr $Type - $Type % 256`
|
168
|
echo "Type: $Type,Kind: $kind"
|
169
|
$(sqlite3 dbCfg.db3 "update tbSMType set Name='${arr[2]}',Note='${arr[3]}',Ext1=${arr[8]},Port=${nPort},PortDef='${arr[5]}',ASubSys=${nSubSys} where Type=${Type} and Tag1=${arr[7]}")
|
170
|
|
171
|
#echo "$?"
|
172
|
if [ $? -eq 0 ];then
|
173
|
echo "upd SM${Type}-${arr[7]} Successe"
|
174
|
else
|
175
|
echo "upd SM${$Type}-${arr[7]} Fail"
|
176
|
fi
|
177
|
##
|
178
|
fi
|
179
|
#
|
180
|
else
|
181
|
echo "${arr[0]} not SMType Info"
|
182
|
fi
|
183
|
|
184
|
#echo "${arr[0]} ${arr[1]} ${arr[2]} ${arr[3]} ${arr[4]} ${arr[5]} ${arr[6]} ${arr[7]} ${arr[8]} ${arr[9]}"
|
185
|
#echo "${arr[0]} ${arr[5]}"
|
186
|
done < $updDatFile
|