|  |  |  | 
|---|
|  |  |  | import com.dy.rtuMw.server.tasks.FromRtuComResultConstantTask; | 
|---|
|  |  |  | import com.dy.rtuMw.server.tasks.FromRtuDataConstantTask; | 
|---|
|  |  |  | import com.dy.common.mw.UnitInterface; | 
|---|
|  |  |  | import com.dy.common.mw.channel.rmi.RmiConfigVo; | 
|---|
|  |  |  | import com.dy.common.mw.channel.rmi.RmiUnit; | 
|---|
|  |  |  | import com.dy.common.mw.channel.tcp.TcpConfigVo; | 
|---|
|  |  |  | import com.dy.common.mw.channel.tcp.TcpUnit; | 
|---|
|  |  |  | import com.dy.common.mw.core.CoreUnit; | 
|---|
|  |  |  | 
|---|
|  |  |  | 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.ToRtuConstantTask; | 
|---|
|  |  |  | import com.dy.rtuMw.resource.ResourceUnit; | 
|---|
|  |  |  | import com.dy.rtuMw.resource.ResourceUnitConfigVo; | 
|---|
|  |  |  | 
|---|
|  |  |  | new Server().startServer(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | */ | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public void  startServer(){ | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | URL url = Server.class.getResource("/config/this.licence"); | 
|---|
|  |  |  | if(!new Lnp(null).parese(url.getPath())){ | 
|---|
|  |  |  | System.out.println("licence error!") ; | 
|---|
|  |  |  | return ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | System.out.println("licence error!") ; | 
|---|
|  |  |  | return ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | if(this.doStartServer()){ | 
|---|
|  |  |  | ServerShutDownHook.OnShutDown(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 启动服务 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public void startServer(){ | 
|---|
|  |  |  | //      try { | 
|---|
|  |  |  | //         URL url = Server.class.getResource("/config/this.licence"); | 
|---|
|  |  |  | //         if(!new Lnp(null).parese(url.getPath())){ | 
|---|
|  |  |  | //            System.out.println("zhzc licence error!") ; | 
|---|
|  |  |  | //            return ; | 
|---|
|  |  |  | //         } | 
|---|
|  |  |  | //      } catch (Exception e) { | 
|---|
|  |  |  | //         System.out.println("zhzc licence error!") ; | 
|---|
|  |  |  | //         return ; | 
|---|
|  |  |  | //      } | 
|---|
|  |  |  | //Server sv = new Server(); | 
|---|
|  |  |  | private boolean doStartServer(){ | 
|---|
|  |  |  | boolean running = false ; | 
|---|
|  |  |  | long start = System.currentTimeMillis() ; | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | //ConfigProperties.init(this.getClass().getResourceAsStream("/config/config.properties"), false); | 
|---|
|  |  |  | 
|---|
|  |  |  | System.out.println("@@@@@@@@@@@@@@@@@@@@@@#      &@@@@@@@@       Runing in standalone mode" ) ; | 
|---|
|  |  |  | System.out.println("@@@@@@@@@@@@@@@@@@@@@&       &@@@@@@@@       Startup in " + (System.currentTimeMillis() - start) + " MS" ) ; | 
|---|
|  |  |  | System.out.println("@@@@@@@@@@@@@@@@@@@#         &@@@@@@@@       " + company) ; | 
|---|
|  |  |  | System.out.println("@@@@@@@@@@@@@@@@#O           &@@@@@@@@") ; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | System.out.println("@@@@@@@@@@@@@@@@#O           &@@@@@@@@") ; | 
|---|
|  |  |  | running = true ; | 
|---|
|  |  |  | }catch(Exception e){ | 
|---|
|  |  |  | e.printStackTrace(); | 
|---|
|  |  |  | running = false ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return running ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private void startUnits(){ | 
|---|
|  |  |  | 
|---|
|  |  |  | if(ServerProperties.isLowPower == null){ | 
|---|
|  |  |  | ServerProperties.isLowPower = false ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | String onlyDealRtus = conf.getSetAttrTxt(doc, "config.base", "onlyDealRtus", null, true, null) ; | 
|---|
|  |  |  | if(onlyDealRtus == null || onlyDealRtus.trim().equals("")){ | 
|---|
|  |  |  | ServerProperties.onlyDealRtusTest = false ; | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | onlyDealRtus = onlyDealRtus.replaceAll(",", ",") ; | 
|---|
|  |  |  | onlyDealRtus = onlyDealRtus.replaceAll(" ", "") ; | 
|---|
|  |  |  | ServerProperties.onlyDealRtus = onlyDealRtus.split(",") ; | 
|---|
|  |  |  | if(ServerProperties.onlyDealRtus != null && ServerProperties.onlyDealRtus.length > 0){ | 
|---|
|  |  |  | ServerProperties.onlyDealRtusTest = true ; | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | ServerProperties.onlyDealRtusTest = false ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //在支持多通信协议时,只有RTU上线了,才能识别出该RTU实际用的通信协议,进而用此协议解析上行数据及构造下行命令。 | 
|---|
|  |  |  | //如果RTU未曾上线(通信中间件启动后该RTU未曾上线),那么在向它发送下行命令时,不能判断出其采用的协议,也不能构造命令,尤其是低功耗情况下,不上线是正常现象。 | 
|---|
|  |  |  | // 当只有一个协议情况下,在RTU未曾上线时,也能用此协议构造命令并缓存下来,尤其适合低功耗情况。 | 
|---|
|  |  |  | 
|---|
|  |  |  | //针对一个RTU,下发命令的时间间隔 | 
|---|
|  |  |  | ServerProperties.commandSendInterval = conf.getSetAttrPlusInt(doc, "config.base", "commandSendInterval", null, 1, 40, null) * 1000L ; | 
|---|
|  |  |  | //命令已经发送达最大次数,仍未收到命令结果,需要在缓存继续等待,其等待最大时长 | 
|---|
|  |  |  | ServerProperties.cachWaitResultTimeout = conf.getSetAttrPlusInt(doc, "config.base", "cachWaitResultTimeout", null, 10, 60, null) * 1000L ; | 
|---|
|  |  |  | ServerProperties.cachWaitResultTimeout = conf.getSetAttrPlusInt(doc, "config.base", "cachWaitResultTimeout", null, 10, 360, null) * 1000L ; | 
|---|
|  |  |  | //不在线缓存的命令最大缓存时长 | 
|---|
|  |  |  | ServerProperties.offLineCachTimeout = conf.getSetAttrPlusInt(doc, "config.base", "offLineCachTimeout", null, 15, 172800, null) * 1000L ; | 
|---|
|  |  |  | //TCP上行数据时刻缓存时长,当达到时长时,TCP上行数据时刻被清空,采用TCP上行数据时刻目的是,阻止上数据同时下发数据,因为RTU处理不过来 | 
|---|
|  |  |  | 
|---|
|  |  |  | if(ServerProperties.cacheUpDownDataMaxCount <= ServerProperties.cacheUpDownDataWarnCount){ | 
|---|
|  |  |  | throw new Exception("cacheUpDownDataMaxCount必须大于cacheUpDownDataWarnCount") ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //没有上行数据的分钟数,达到这个分钟数,认为RTU断网了,取值范围是2_100 | 
|---|
|  |  |  | //没有上行数据的分钟数,达到这个分钟数,认为RTU断网了,取值范围是2-100 | 
|---|
|  |  |  | ServerProperties.disconnectedByNoUpDataMinutes =  0L + conf.getSetAttrPlusInt(doc, "config.base", "disconnectedByNoUpDataMinutes", null, 1, 100, null) ; | 
|---|
|  |  |  | if(ServerProperties.disconnectedByNoUpDataMinutes < 1 || ServerProperties.disconnectedByNoUpDataMinutes > 100){ | 
|---|
|  |  |  | throw new Exception("disconnectedByNoUpDataMinutes取值必须是1~100") ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | ServerProperties.disconnectedByNoUpDataMinutes = ServerProperties.disconnectedByNoUpDataMinutes * 60 * 1000 ; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //工作报太频繁,N次上报处理1次,取值范围是1-100 | 
|---|
|  |  |  | ServerProperties.workReportDealOneByTimes =  conf.getSetAttrPlusInt(doc, "config.base", "workReportDealOneByTimes", null, 1, 100, null) ; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //有报警发生时,向钉钉发送消息的间隔时长(分钟) | 
|---|
|  |  |  | ServerProperties.sendDingDingAlarmMsInterval =  conf.getSetAttrPlusInt(doc, "config.base", "sendDingDingAlarmMsInterval", null, 1, 600, null) ; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //设置ID生成器的后缀 | 
|---|
|  |  |  | IDLongGenerator.setSuffix(ServerProperties.dbDataIdSuffix.intValue()); | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | ///////////////// | 
|---|
|  |  |  | //RMI模块 | 
|---|
|  |  |  | //RMI模块 暂时不应用 | 
|---|
|  |  |  | /* | 
|---|
|  |  |  | RmiConfigVo rmiVo = new RmiConfigVo(); | 
|---|
|  |  |  | rmiVo.enable = conf.getSetAttrBoolean(doc, "config.rmi", "enable", null, null) ; | 
|---|
|  |  |  | if(rmiVo.enable){ | 
|---|
|  |  |  | 
|---|
|  |  |  | RmiSvUrl = "[ip]:" + rmiVo.port + "/" + rmiVo.context ; | 
|---|
|  |  |  | units.add(rmiUnit) ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | */ | 
|---|
|  |  |  |  | 
|---|
|  |  |  | ///////////////// | 
|---|
|  |  |  | //RTU上行数据处理模块 | 
|---|
|  |  |  | 
|---|
|  |  |  | CoreUnit.addConstantTask(new ToRtuConstantTask()); | 
|---|
|  |  |  | CoreUnit.addConstantTask(new FromRtuDataConstantTask()); | 
|---|
|  |  |  | CoreUnit.addConstantTask(new FromRtuComResultConstantTask()); | 
|---|
|  |  |  | CoreUnit.addConstantTask(new SendMsConstantTask()); | 
|---|
|  |  |  | coreUnit.start(obj -> { | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | units.add(coreUnit) ; | 
|---|