-
Notifications
You must be signed in to change notification settings - Fork 0
/
insert_mysql_modbus_test.sh
executable file
·68 lines (66 loc) · 1.99 KB
/
insert_mysql_modbus_test.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
#!/bin/bash
#@dark_jadeite
#2018.7.22
#自动化插入多一点MeterIdentity的数据
#和一些DataIdentity数据
#用于测试使用
#需要按顺序输入:
#$1--meterID的起始数值
#$2--DTUID的起始数值
#$3--要添加的DTU个数
#$4--每个ModBus总线上仪表个数
if [ $# -le 3 ];then
echo "#需要按顺序输入:\n--meterID的起始数值\n--DTUID的起始数值\n--要添加的DTU个数\n--每个ModBus总线上仪表个数"
exit 1
fi
startMeterID=$1
startDTUID=$2
maxDTUID=$3
maxDeviceNumber=$4
startDeviceNumber=0
meterName="仪表$meterID"
echo "起始meterID:$startMeterID"
echo "起始DTUID:$startDTUID"
echo "要添加的DTU个数:$maxDTUID"
echo "单ModBus总线上要添加仪表个数:$maxDeviceNumber"
echo "ModBus总线上起始仪表地址:$startDeviceNumber"
if [ $# -eq 4 ];then
echo "请确认输入y/n(n)"
read a
case $a in
"y")
echo "已确认"
;;
*)
echo "取消操作"
exit 1
;;
esac
else
sleep 1;
fi
i=0
while [ $i -lt $maxDTUID ]
do
j=0
startDeviceNumber=0
while [ $j -lt $maxDeviceNumber ]
do
meterName="仪表$startMeterID"
mysql -u root<<EOF
use tcp;
insert into MeterIdentify(meterID,DTUID,deviceNumber,meterName)values($startMeterID,$startDTUID,$startDeviceNumber,'$meterName');
insert into DataIdentify(meterID,ord,dataName,address,byteNumber,dataType)values($startMeterID,1,"瞬时流量",0,4,7);
insert into DataIdentify(meterID,ord,dataName,address,byteNumber,dataType)values($startMeterID,2,"累积流量",4,4,7);
insert into DataIdentify(meterID,ord,dataName,address,byteNumber,dataType)values($startMeterID,3,"温度",8,4,7);
insert into DataIdentify(meterID,ord,dataName,address,byteNumber,dataType)values($startMeterID,4,"压力",12,4,7);
insert into DataIdentify(meterID,ord,dataName,address,byteNumber,dataType)values($startMeterID,5,"差压",16,4,7);
EOF
echo "$startMeterID插入完毕!"
j=$(($j + 1))
startMeterID=$(($startMeterID+1))
startDeviceNumber=$(($startDeviceNumber+1))
done
i=$(($i+1))
startDTUID=$(($startDTUID+1))
done