#!/bin/sh

sqlite3 dbCfg.db3 "delete from tbPort"

# DI
echo "" > SerialPortQuickDef.ini
echo ";DI通讯板接入的接口板地址，及端口号" >> SerialPortQuickDef.ini
echo "[Port.DI]" >> SerialPortQuickDef.ini
echo ";DI通讯板接入只配置接口板地址，一个地址两个端口同时读取，自动按上为通道1下为通道2进行" >> SerialPortQuickDef.ini
echo "1=ttymxc6,21,3" >> SerialPortQuickDef.ini
echo "2=ttymxc6,22,3" >> SerialPortQuickDef.ini
echo "3=ttymxc6,23,3" >> SerialPortQuickDef.ini
echo "4=ttymxc6,24,3" >> SerialPortQuickDef.ini
echo "5=ttymxc6,25,3" >> SerialPortQuickDef.ini
echo "6=ttymxc6,26,3" >> SerialPortQuickDef.ini
echo "7=ttymxc6,27,3" >> SerialPortQuickDef.ini
echo "8=ttymxc6,28,3" >> SerialPortQuickDef.ini
echo "" >> SerialPortQuickDef.ini
for((i=1;i<=16;i++));  
do     
	sqlite3 dbCfg.db3 "insert into tbPort values('DI$i','',1,$(expr $i + 8388608),1)"
done 


# DO
echo ";DO通讯板接入的接口板地址，及端口号" >> SerialPortQuickDef.ini
echo "[Port.DO]" >> SerialPortQuickDef.ini
echo ";DI通讯板接入只配置接口板地址，一个地址两个端口同时读取，写入自动按上为通道1下为通道2进行" >> SerialPortQuickDef.ini
echo "1=ttymxc7,10,3" >> SerialPortQuickDef.ini
echo "2=ttymxc7,11,3" >> SerialPortQuickDef.ini
echo "3=ttymxc7,12,3" >> SerialPortQuickDef.ini
echo "4=ttymxc7,13,3" >> SerialPortQuickDef.ini
echo "5=ttymxc7,14,3" >> SerialPortQuickDef.ini
echo "" >> SerialPortQuickDef.ini
for((i=1;i<=10;i++));  
do     
	sqlite3 dbCfg.db3 "insert into tbPort values('DO$i','',2,$(expr $i + 8388608),1)"
done 

# AI
echo ";AI通讯板接入的接口板地址，及端口号" >> SerialPortQuickDef.ini
echo "[Port.AI]" >> SerialPortQuickDef.ini
echo "1=ttymxc7,7,3" >> SerialPortQuickDef.ini
echo "2=ttymxc7,8,3" >> SerialPortQuickDef.ini
echo "3=ttymxc7,9,3" >> SerialPortQuickDef.ini
echo "" >> SerialPortQuickDef.ini
for((i=1;i<=6;i++));  
do
	sqlite3 dbCfg.db3 "insert into tbPort values('AI$i','',1,$(expr $i + 512),2)"
done 

#232
echo ";RS232通讯板接入的接口板地址，及端口号" >> SerialPortQuickDef.ini
echo ";格式：对外端口号=UART端口号,通讯板地址,通讯板端口(1个通讯板2个端口)" >> SerialPortQuickDef.ini
echo "[Port.Serial]" >> SerialPortQuickDef.ini
addr=1
echo "RS232_1=ttymxc7,$addr,1" >> SerialPortQuickDef.ini
echo "RS232_2=ttymxc7,$addr,2" >> SerialPortQuickDef.ini
sqlite3 dbCfg.db3 "insert into tbPort values('RS232_1:','',3,$(expr 1048576+$addr\*256+1),'')"
sqlite3 dbCfg.db3 "insert into tbPort values('RS232_2:','',3,$(expr 1048576+$addr\*256+2),'')"
addr=3
echo "RS232_3=ttymxc7,$addr,1" >> SerialPortQuickDef.ini
echo "RS232_4=ttymxc7,$addr,2" >> SerialPortQuickDef.ini
sqlite3 dbCfg.db3 "insert into tbPort values('RS232_3:','',3,$(expr 1048576+$addr\*256+1),'')"
sqlite3 dbCfg.db3 "insert into tbPort values('RS232_4:','',3,$(expr 1048576+$addr\*256+2),'')"
addr=5
echo "RS232_5=ttymxc7,$addr,1" >> SerialPortQuickDef.ini
echo "RS232_6=ttymxc7,$addr,2" >> SerialPortQuickDef.ini
sqlite3 dbCfg.db3 "insert into tbPort values('RS232_5:','',3,$(expr 1048576+$addr\*256+1),'')"
sqlite3 dbCfg.db3 "insert into tbPort values('RS232_6:','',3,$(expr 1048576+$addr\*256+2),'')"
echo "" >> SerialPortQuickDef.ini

#485
echo ";RS485通讯板接入的接口板地址，及端口号" >> SerialPortQuickDef.ini
echo ";格式：对外端口号=UART端口号,通讯板地址,通讯板端口(1个通讯板2个端口)" >> SerialPortQuickDef.ini
addr=15
echo "RS485_1=ttymxc6,$addr,1" >> SerialPortQuickDef.ini
echo "RS485_2=ttymxc6,$addr,2" >> SerialPortQuickDef.ini
sqlite3 dbCfg.db3 "insert into tbPort values('RS485_1:','',4,$(expr 1048576+$addr\*256+1),'')"
sqlite3 dbCfg.db3 "insert into tbPort values('RS485_2:','',4,$(expr 1048576+$addr\*256+2),'')"
addr=16
echo "RS485_3=ttymxc6,$addr,1" >> SerialPortQuickDef.ini
echo "RS485_4=ttymxc6,$addr,2" >> SerialPortQuickDef.ini
sqlite3 dbCfg.db3 "insert into tbPort values('RS485_3:','',4,$(expr 1048576+$addr\*256+1),'')"
sqlite3 dbCfg.db3 "insert into tbPort values('RS485_4:','',4,$(expr 1048576+$addr\*256+2),'')"
addr=17
echo "RS485_5=ttymxc6,$addr,1" >> SerialPortQuickDef.ini
echo "RS485_6=ttymxc6,$addr,2" >> SerialPortQuickDef.ini
sqlite3 dbCfg.db3 "insert into tbPort values('RS485_5:','',4,$(expr 1048576+$addr\*256+1),'')"
sqlite3 dbCfg.db3 "insert into tbPort values('RS485_6:','',4,$(expr 1048576+$addr\*256+2),'')"
addr=18
echo "RS485_7=ttymxc6,$addr,1" >> SerialPortQuickDef.ini
echo "RS485_8=ttymxc6,$addr,2" >> SerialPortQuickDef.ini
sqlite3 dbCfg.db3 "insert into tbPort values('RS485_7:','',4,$(expr 1048576+$addr\*256+1),'')"
sqlite3 dbCfg.db3 "insert into tbPort values('RS485_8:','',4,$(expr 1048576+$addr\*256+2),'')"
addr=19
echo "RS485_9=ttymxc6,$addr,1" >> SerialPortQuickDef.ini
echo "RS485_10=ttymxc6,$addr,2" >> SerialPortQuickDef.ini
sqlite3 dbCfg.db3 "insert into tbPort values('RS485_9:','',4,$(expr 1048576+$addr\*256+1),'')"
sqlite3 dbCfg.db3 "insert into tbPort values('RS485_10:','',4,$(expr 1048576+$addr\*256+2),'')"
addr=20
echo "RS485_11=ttymxc6,$addr,1" >> SerialPortQuickDef.ini
echo "RS485_12=ttymxc6,$addr,2" >> SerialPortQuickDef.ini
sqlite3 dbCfg.db3 "insert into tbPort values('RS485_11:','',4,$(expr 1048576+$addr\*256+1),'')"
sqlite3 dbCfg.db3 "insert into tbPort values('RS485_12:','',4,$(expr 1048576+$addr\*256+2),'')"
echo "" >> SerialPortQuickDef.ini


#---------------------------------------分割线-----------------------------------------
# IMX287 ADC
#sqlite3 dbCfg.db3 "update tbSMType set ExtDi=8, ExtDo=4 where Type=2304"
#sqlite3 dbCfg.db3 "update tbSMType set Type=2317 where Type=2323"
# MYS-6ULX-IND ADC
#sqlite3 dbCfg.db3 "update tbSMType set Type=2320 where Type=2317"
# MYC-Y6ULX ADC
#sqlite3 dbCfg.db3 "update tbSMType set Type=2323 where Type=2317"
# 快速主机 ADC
sqlite3 dbCfg.db3 "update tbSMType set ExtDi=16, ExtDo=10 where Type=2304"
sqlite3 dbCfg.db3 "update tbSMType set Type=2324 where Type=2317"
#sqlite3 dbCfg.db3 "update tbSMDef set Type=2324 where Type=2317"
#sqlite3 dbCfg.db3 "update tbSMDefVal set Type=2324 where Type=2317"

#---------------------------------------分割线-----------------------------------------
sqlite3 dbCfg.db3 "delete from tbSM"
sqlite3 dbCfg.db3 "insert into tbSM values(1,2304,2304,'内置DIO','内置设备',0,3,0,1,'',8388608,8388608,'OMI1:',0,0,0,0,0,0,0,0,0)"

# IMX287 ADC
#sqlite3 dbCfg.db3 "insert into tbSM values(2,2304,2304,'内置AI','内置AI设备',0,0,0,1,'',8388608,8388608,'OMI1:',0,0,0,0,0,0,0,0,0)"
# MYS-6ULX-IND ADC
#sqlite3 dbCfg.db3 "insert into tbSM values(2,2304,2320,'内置AI','内置AI设备',0,0,0,1,'',8388608,8388608,'OMI1:',0,0,0,0,0,0,0,0,0)"
# MYC-Y6ULX ADC
#sqlite3 dbCfg.db3 "insert into tbSM values(2,2304,2323,'内置AI','内置AI设备',0,0,0,1,'',8388608,8388608,'OMI1:',0,0,0,0,0,0,0,0,0)"
# 快速主机 ADC
sqlite3 dbCfg.db3 "insert into tbSM values(2,2304,2324,'内置AI','内置AI设备',0,0,0,1,'',8388608,8388608,'OMI1:',0,0,0,0,0,0,0,0,0)"

#DO联动
sqlite3 dbCfg.db3 "insert into tbSM values(3,2560,2562,'联动1','-',0,0,0,1,'',8388608,8388608,'OMI1:',0,null,null,0,0,null,null,0,0)"
sqlite3 dbCfg.db3 "insert into tbSM values(4,2560,2562,'联动2','-',0,0,0,1,'',8388608,8388608,'OMI1:',0,null,null,0,0,null,null,1,0)"
sqlite3 dbCfg.db3 "insert into tbSM values(5,2560,2562,'联动3','-',0,0,0,1,'',8388608,8388608,'OMI1:',0,null,null,0,0,null,null,2,0)"
sqlite3 dbCfg.db3 "insert into tbSM values(6,2560,2562,'联动4','-',0,0,0,1,'',8388608,8388608,'OMI1:',0,null,null,0,0,null,null,3,0)"
sqlite3 dbCfg.db3 "insert into tbSM values(7,2560,2562,'联动5','-',0,0,0,1,'',8388608,8388608,'OMI1:',0,null,null,0,0,null,null,4,0)"
sqlite3 dbCfg.db3 "insert into tbSM values(8,2560,2562,'联动6','-',0,0,0,1,'',8388608,8388608,'OMI1:',0,null,null,0,0,null,null,5,0)"
sqlite3 dbCfg.db3 "insert into tbSM values(9,2560,2562,'联动7','-',0,0,0,1,'',8388608,8388608,'OMI1:',0,null,null,0,0,null,null,6,0)"
sqlite3 dbCfg.db3 "insert into tbSM values(10,2560,2562,'联动8','-',0,0,0,1,'',8388608,8388608,'OMI1:',0,null,null,0,0,null,null,7,0)"
sqlite3 dbCfg.db3 "insert into tbSM values(11,2560,2562,'联动9','-',0,0,0,1,'',8388608,8388608,'OMI1:',0,null,null,0,0,null,null,8,0)"
sqlite3 dbCfg.db3 "insert into tbSM values(12,2560,2562,'联动10','-',0,0,0,1,'',8388608,8388608,'OMI1:',0,null,null,0,0,null,null,9,0)"












