|  |  |  | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.dy.common.util.ConfigProperties; | 
|---|
|  |  |  | import com.dy.common.util.IPUtils; | 
|---|
|  |  |  | import com.dy.rtuMw.server.*; | 
|---|
|  |  |  | import com.dy.rtuMw.server.mqtt.MqttUnit; | 
|---|
|  |  |  | import com.dy.rtuMw.server.mqtt.MqttUnitConfigVo; | 
|---|
|  |  |  | import com.dy.rtuMw.server.msCenter.MsCenterConfigVo; | 
|---|
|  |  |  | import com.dy.rtuMw.server.msCenter.MsCenterUnit; | 
|---|
|  |  |  | import com.dy.rtuMw.server.rtuData.RtuDataUnit; | 
|---|
|  |  |  | import com.dy.rtuMw.server.rtuData.RtuDataUnitConfigVo; | 
|---|
|  |  |  | import com.dy.rtuMw.server.tasks.FromRtuComResultConstantTask; | 
|---|
|  |  |  | import com.dy.rtuMw.server.tasks.FromRtuDataConstantTask; | 
|---|
|  |  |  | import com.dy.rtuMw.server.tasks.*; | 
|---|
|  |  |  | import com.dy.common.mw.UnitInterface; | 
|---|
|  |  |  | import com.dy.common.mw.channel.tcp.TcpConfigVo; | 
|---|
|  |  |  | import com.dy.common.mw.channel.tcp.TcpUnit; | 
|---|
|  |  |  | 
|---|
|  |  |  | import com.dy.common.mw.protocol.ProtocolUnit; | 
|---|
|  |  |  | import com.dy.common.mw.support.SupportUnit; | 
|---|
|  |  |  | import com.dy.common.mw.support.SupportUnitConfigVo; | 
|---|
|  |  |  | import com.dy.rtuMw.server.tasks.SendMsConstantTask; | 
|---|
|  |  |  | import com.dy.rtuMw.server.tasks.RtuDownConstantTask; | 
|---|
|  |  |  | import com.dy.rtuMw.resource.ResourceUnit; | 
|---|
|  |  |  | import com.dy.rtuMw.resource.ResourceUnitConfigVo; | 
|---|
|  |  |  | import com.dy.common.springUtil.SpringContextUtil; | 
|---|
|  |  |  | 
|---|
|  |  |  | }catch(Exception e){ | 
|---|
|  |  |  | company = "" ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | System.out.println("OOOOOOOOOO           OOOOOOOO       OOOOOOOO") ; | 
|---|
|  |  |  | System.out.println("@@@@@@@@@@@@@@@@#O    $@@@@@@@@&    @@@@@@@@#") ; | 
|---|
|  |  |  | System.out.println("@@@@@@@@@@@@@@@@@@@#    @@@@@@@@# $@@@@@@@@&") ; | 
|---|
|  |  |  | System.out.println("@@@@@@@@@@@@@@@@@@@@@#   #@@@@@@@@@@@@@@@@O") ; | 
|---|
|  |  |  | System.out.println("@@@@@@@@@@@@@@@@@@@@@@@   &@@@@@@@@@@@@@@") ; | 
|---|
|  |  |  | System.out.println("@@@@@@$      $@@@@@@@@@&   O@@@@@@@@@@@#") ; | 
|---|
|  |  |  | System.out.println("$$$$$$$$$$$$         $$$$$$$$       $$$$$$$$") ; | 
|---|
|  |  |  | System.out.println("@@@@@@@@@@@@@@@@#$    $@@@@@@@@&    @@@@@@@@#") ; | 
|---|
|  |  |  | System.out.println("@@@@@@@@@@@@@@@@@@@#    @@@@@@@@# $@@@@@@@@&") ; | 
|---|
|  |  |  | System.out.println("@@@@@@@@@@@@@@@@@@@@@#   #@@@@@@@@@@@@@@@@$") ; | 
|---|
|  |  |  | System.out.println("@@@@@@@@@@@@@@@@@@@@@@@   &@@@@@@@@@@@@@@") ; | 
|---|
|  |  |  | System.out.println("@@@@@@$      $@@@@@@@@@&   $@@@@@@@@@@@#") ; | 
|---|
|  |  |  | System.out.println("@@@@@@$        @@@@@@@@@     @@@@@@@@@&      " + this.orgTag + svName + "RtuMw 1.0.00" ) ; | 
|---|
|  |  |  | if(this.HttpSvPath != null && this.HttpSvPort != null){ | 
|---|
|  |  |  | System.out.println("@@@@@@$       O@@@@@@@@@     &@@@@@@@@       HttpSv [ip]:" + this.HttpSvPort + this.HttpSvPath) ; | 
|---|
|  |  |  | 
|---|
|  |  |  | //RTU远程升级模块 | 
|---|
|  |  |  | UpgradeUnitConfigVo ugVo = new UpgradeUnitConfigVo(); | 
|---|
|  |  |  | ugVo.enable = conf.getSetAttrBoolean(doc, "config.upgrade", "enable", null, null) ; | 
|---|
|  |  |  | ugVo.openNoUpgrade = conf.getSetAttrBoolean(doc, "config.upgrade", "openNoUpgrade", null, null) ; | 
|---|
|  |  |  | ugVo.lastOpenMaxGoOn = conf.getSetAttrPlusInt(doc, "config.upgrade", "lastOpenMaxGoOn", null, 5, 360000, null); | 
|---|
|  |  |  | ugVo.lastOpenMaxGoOn = ugVo.lastOpenMaxGoOn * 1000 ;//变成毫秒 | 
|---|
|  |  |  | ugVo.noOneRtuUpgradeMaxDuration = conf.getSetAttrPlusInt(doc, "config.upgrade", "noOneRtuUpgradeMaxDuration", null, 5, 360000, null); | 
|---|
|  |  |  | ugVo.noOneRtuUpgradeMaxDuration = ugVo.noOneRtuUpgradeMaxDuration * 1000 ;//变成毫秒 | 
|---|
|  |  |  | ugVo.runningAndIdleDuration = conf.getSetAttrPlusInt(doc, "config.upgrade", "runningAndIdleDuration", null, 5, 360000, null); | 
|---|
|  |  |  | ugVo.runningAndIdleDuration = ugVo.runningAndIdleDuration * 1000 ;//变成毫秒 | 
|---|
|  |  |  | ugVo.failTryTimes = conf.getSetAttrPlusInt(doc, "config.upgrade", "failTryTimes", null, 0, 100, null); | 
|---|
|  |  |  | ugVo.ugMaxRtuAtOnce = conf.getSetAttrPlusInt(doc, "config.upgrade", "ugMaxRtuAtOnce", null, 0, 1000000, null); | 
|---|
|  |  |  | ugVo.rtuOffLineWaitDuration = conf.getSetAttrPlusInt(doc, "config.upgrade", "rtuOffLineWaitDuration", null, 1, 3600000, null); | 
|---|
|  |  |  | ugVo.rtuOffLineWaitDuration = ugVo.rtuOffLineWaitDuration * 1000;//变成毫秒 | 
|---|
|  |  |  | ugVo.notifyStateInterval = conf.getSetAttrPlusInt(doc, "config.upgrade", "notifyStateInterval", null, 1, 300, null); | 
|---|
|  |  |  | ugVo.notifyStateInterval = ugVo.notifyStateInterval * 1000;//变成毫秒 | 
|---|
|  |  |  | ugVo.notifyTimesAfterOver = conf.getSetAttrPlusInt(doc, "config.upgrade", "notifyTimesAfterOver", null, 0, null, null); | 
|---|
|  |  |  | ugVo.showStartInfo = showStartInfo ; | 
|---|
|  |  |  | AdapterImp_UpgradeUnit ugAdap = new AdapterImp_UpgradeUnit(); | 
|---|
|  |  |  | ugAdap.setConfig(ugVo); | 
|---|
|  |  |  | UpgradeUnit ugUnit = UpgradeUnit.getInstance(); | 
|---|
|  |  |  | ugUnit.setAdapter(ugAdap); | 
|---|
|  |  |  | ugUnit.start(obj -> { | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | units.add(ugUnit) ; | 
|---|
|  |  |  | if(ugVo.enable){ | 
|---|
|  |  |  | ugVo.openNoUpgrade = conf.getSetAttrBoolean(doc, "config.upgrade", "openNoUpgrade", null, null) ; | 
|---|
|  |  |  | ugVo.lastOpenMaxGoOn = conf.getSetAttrPlusInt(doc, "config.upgrade", "lastOpenMaxGoOn", null, 5, 360000, null); | 
|---|
|  |  |  | ugVo.lastOpenMaxGoOn = ugVo.lastOpenMaxGoOn * 1000 ;//变成毫秒 | 
|---|
|  |  |  | ugVo.noOneRtuUpgradeMaxDuration = conf.getSetAttrPlusInt(doc, "config.upgrade", "noOneRtuUpgradeMaxDuration", null, 5, 360000, null); | 
|---|
|  |  |  | ugVo.noOneRtuUpgradeMaxDuration = ugVo.noOneRtuUpgradeMaxDuration * 1000 ;//变成毫秒 | 
|---|
|  |  |  | ugVo.runningAndIdleDuration = conf.getSetAttrPlusInt(doc, "config.upgrade", "runningAndIdleDuration", null, 5, 360000, null); | 
|---|
|  |  |  | ugVo.runningAndIdleDuration = ugVo.runningAndIdleDuration * 1000 ;//变成毫秒 | 
|---|
|  |  |  | ugVo.failTryTimes = conf.getSetAttrPlusInt(doc, "config.upgrade", "failTryTimes", null, 0, 100, null); | 
|---|
|  |  |  | ugVo.ugMaxRtuAtOnce = conf.getSetAttrPlusInt(doc, "config.upgrade", "ugMaxRtuAtOnce", null, 0, 1000000, null); | 
|---|
|  |  |  | ugVo.rtuOffLineWaitDuration = conf.getSetAttrPlusInt(doc, "config.upgrade", "rtuOffLineWaitDuration", null, 1, 3600000, null); | 
|---|
|  |  |  | ugVo.rtuOffLineWaitDuration = ugVo.rtuOffLineWaitDuration * 1000;//变成毫秒 | 
|---|
|  |  |  | ugVo.notifyStateInterval = conf.getSetAttrPlusInt(doc, "config.upgrade", "notifyStateInterval", null, 1, 300, null); | 
|---|
|  |  |  | ugVo.notifyStateInterval = ugVo.notifyStateInterval * 1000;//变成毫秒 | 
|---|
|  |  |  | ugVo.notifyTimesAfterOver = conf.getSetAttrPlusInt(doc, "config.upgrade", "notifyTimesAfterOver", null, 0, null, null); | 
|---|
|  |  |  | ugVo.showStartInfo = showStartInfo ; | 
|---|
|  |  |  | AdapterImp_UpgradeUnit ugAdap = new AdapterImp_UpgradeUnit(); | 
|---|
|  |  |  | ugAdap.setConfig(ugVo); | 
|---|
|  |  |  | UpgradeUnit ugUnit = UpgradeUnit.getInstance(); | 
|---|
|  |  |  | ugUnit.setAdapter(ugAdap); | 
|---|
|  |  |  | ugUnit.start(obj -> { | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | units.add(ugUnit) ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | ///////////////// | 
|---|
|  |  |  | //RTU上行数据处理模块(任务树) | 
|---|
|  |  |  | 
|---|
|  |  |  | CoreUnit.addConstantTask(new RtuDownConstantTask()); | 
|---|
|  |  |  | CoreUnit.addConstantTask(new FromRtuDataConstantTask()); | 
|---|
|  |  |  | CoreUnit.addConstantTask(new FromRtuComResultConstantTask()); | 
|---|
|  |  |  | Boolean enableMq = conf.getSetAttrBoolean(doc, "config.mqtt", "enable", null, null) ; | 
|---|
|  |  |  | if(enableMq != null && enableMq.booleanValue()){ | 
|---|
|  |  |  | CoreUnit.addConstantTask(new MqttSubMessageConstantTask()); | 
|---|
|  |  |  | CoreUnit.addConstantTask(new MqttPubMessageConstantTask()); | 
|---|
|  |  |  | CoreUnit.addConstantTask(new MqttComResultConstantTask()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | CoreUnit.addConstantTask(new SendMsConstantTask()); | 
|---|
|  |  |  | coreUnit.start(obj -> { | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | TcpSvUrl = "[ip]:" + tcpVo.port ; | 
|---|
|  |  |  | units.add(tcpUnit) ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | ///////////////// | 
|---|
|  |  |  | //MQTT模块 | 
|---|
|  |  |  | MqttUnitConfigVo mqVo = new MqttUnitConfigVo(); | 
|---|
|  |  |  | mqVo.enable = conf.getSetAttrBoolean(doc, "config.mqtt", "enable", null, null) ; | 
|---|
|  |  |  | ServerProperties.mqttUnitEnable = mqVo.enable ; | 
|---|
|  |  |  | if(mqVo.enable){ | 
|---|
|  |  |  | mqVo.svIp = conf.getSetAttrTxt(doc, "config.mqtt", "svIp", null, false, null) ; | 
|---|
|  |  |  | if(!IPUtils.ipValid(mqVo.svIp)){ | 
|---|
|  |  |  | throw new Exception("config.mqtt.svIp配置的IP不合法") ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | mqVo.svPort = conf.getSetAttrPlusInt(doc, "config.mqtt", "svPort", null, 5, 360000, null); | 
|---|
|  |  |  | if(mqVo.svPort < 0 || mqVo.svPort > 65535){ | 
|---|
|  |  |  | throw new Exception("config.mqtt.svPort配置的端口不合法") ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | mqVo.svUserName = conf.getSetAttrTxt(doc, "config.mqtt", "svUserName", null, false, null) ; | 
|---|
|  |  |  | if(mqVo.svUserName == null || mqVo.svUserName.trim().equals("")){ | 
|---|
|  |  |  | throw new Exception("config.mqtt.svUserName配置的用户名不合法") ; | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | mqVo.svUserName = mqVo.svUserName.trim() ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | mqVo.svUserPassword = conf.getSetAttrTxt(doc, "config.mqtt", "svUserPassword", null, false, null) ; | 
|---|
|  |  |  | if(mqVo.svUserPassword == null || mqVo.svUserPassword.trim().equals("")){ | 
|---|
|  |  |  | throw new Exception("config.mqtt.svUserName配置的用户密码不合法") ; | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | mqVo.svUserPassword = mqVo.svUserPassword.trim() ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | mqVo.poolMaxSize = conf.getSetAttrPlusInt(doc, "config.mqtt", "poolMaxSize", null, 1, 1000, null); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | mqVo.sendInterval = conf.getSetAttrPlusInt(doc, "config.mqtt", "sendInterval", null, 1, 3600, null) * 1000L ; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | mqVo.reSendTimesByNoResult = conf.getSetAttrPlusInt(doc, "config.mqtt", "reSendTimesByNoResult", null, 0, 100, null); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | mqVo.comCacheTimeout = conf.getSetAttrPlusInt(doc, "config.mqtt", "comCacheTimeout", null, 1, 3600, null) * 1000L ; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | ServerProperties.acceptManureDataMinInterval = conf.getSetAttrPlusInt(doc, "config.mqtt", "acceptManureDataMinInterval", null, 1, 720, null) * 60 * 1000L ; | 
|---|
|  |  |  | ServerProperties.acceptSoilDataMinInterval = conf.getSetAttrPlusInt(doc, "config.mqtt", "acceptSoilDataMinInterval", null, 1, 720, null) * 60 * 1000L ; | 
|---|
|  |  |  | ServerProperties.acceptWeatherDataMinInterval = conf.getSetAttrPlusInt(doc, "config.mqtt", "acceptWeatherDataMinInterval", null, 1, 720, null) * 60 * 1000L ; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | mqVo.useMemoryPersistence = conf.getSetAttrBoolean(doc, "config.mqtt", "useMemoryPersistence", null, null) ; | 
|---|
|  |  |  | String proAndDevIds = conf.getSetAttrTxt(doc, "config.mqtt", "protocolAndDeviceIds", null, true, null) ; | 
|---|
|  |  |  | if(proAndDevIds != null && !proAndDevIds.trim().equals("")){ | 
|---|
|  |  |  | proAndDevIds = proAndDevIds.trim() ; | 
|---|
|  |  |  | proAndDevIds = proAndDevIds.replaceAll(",", ","); | 
|---|
|  |  |  | proAndDevIds = proAndDevIds.replaceAll(";", ";"); | 
|---|
|  |  |  | proAndDevIds = proAndDevIds.replaceAll("\\\\", "/"); | 
|---|
|  |  |  | mqVo.protocolAndDeviceIds = proAndDevIds.split(",") ; | 
|---|
|  |  |  | mqVo.deviceIds = new String[mqVo.protocolAndDeviceIds.length] ; | 
|---|
|  |  |  | int index = 0 ; | 
|---|
|  |  |  | for(String topicAndQosStr : mqVo.protocolAndDeviceIds){ | 
|---|
|  |  |  | String[] pd = topicAndQosStr.split("/") ; | 
|---|
|  |  |  | mqVo.deviceIds[index] = pd[1].trim() ; | 
|---|
|  |  |  | index++ ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | String subTopicAndQos = conf.getSetAttrTxt(doc, "config.mqtt", "subTopicAndQos", null, true, null) ; | 
|---|
|  |  |  | if(subTopicAndQos != null && !subTopicAndQos.trim().equals("")){ | 
|---|
|  |  |  | subTopicAndQos = subTopicAndQos.trim() ; | 
|---|
|  |  |  | subTopicAndQos = subTopicAndQos.replaceAll(",", ","); | 
|---|
|  |  |  | subTopicAndQos = subTopicAndQos.replaceAll(";", ";"); | 
|---|
|  |  |  | String[] topicAndQosArr = subTopicAndQos.split(";") ; | 
|---|
|  |  |  | mqVo.subTopics = new String[topicAndQosArr.length] ; | 
|---|
|  |  |  | mqVo.subTopicsQos = new int[topicAndQosArr.length] ; | 
|---|
|  |  |  | int index = 0 ; | 
|---|
|  |  |  | for(String topicAndQosStr : topicAndQosArr){ | 
|---|
|  |  |  | String[] tq = topicAndQosStr.split(",") ; | 
|---|
|  |  |  | mqVo.subTopics[index] = tq[0].trim() ; | 
|---|
|  |  |  | mqVo.subTopicsQos[index] = Integer.parseInt(tq[1].trim()) ; | 
|---|
|  |  |  | index++ ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | mqVo.pubTopicQos = conf.getSetAttrPlusInt(doc, "config.mqtt", "pubTopicQos", null, 0, 3, null); | 
|---|
|  |  |  | if(mqVo.pubTopicQos < 0 || mqVo.pubTopicQos > 3){ | 
|---|
|  |  |  | throw new Exception("config.mqtt.pubTopicQos配置不合法") ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Integer intNoSubThenOff = conf.getSetAttrPlusInt(doc, "config.mqtt", "noSubThenOff", null, 1, 1440, null); | 
|---|
|  |  |  | mqVo.noSubThenOff = intNoSubThenOff * 60 * 1000L ; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | mqVo.showStartInfo = showStartInfo ; | 
|---|
|  |  |  | AdapterImp_MqttUnit mqAdapt = new AdapterImp_MqttUnit(); | 
|---|
|  |  |  | mqAdapt.setConfig(mqVo); | 
|---|
|  |  |  | MqttUnit mqUnit = MqttUnit.getInstance(); | 
|---|
|  |  |  | mqUnit.setAdapter(mqAdapt); | 
|---|
|  |  |  | mqUnit.start(obj -> { | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | units.add(mqUnit) ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | e.printStackTrace(); | 
|---|
|  |  |  | } | 
|---|