Merge branch 'master' of http://8.140.179.55:20000/r/pipIrr-SV
| | |
| | | |
| | | |
| | | /** |
| | | * 模块单元适配器接口 |
| | | * |
| | | * 单元适配器接口 |
| | | */ |
| | | public interface UnitAdapterInterface { |
| | | } |
New file |
| | |
| | | package com.dy.common.mw; |
| | | |
| | | /** |
| | | * 单元启动或停止后回调接口 |
| | | */ |
| | | public interface UnitCallbackInterface { |
| | | /** |
| | | * 回调方法 |
| | | * @param obj |
| | | * @throws Exception |
| | | */ |
| | | void call(Object obj) throws Exception ; |
| | | } |
| | |
| | | package com.dy.common.mw; |
| | | |
| | | /** |
| | | * 模块单元接口 |
| | | * 单元接口 |
| | | * |
| | | */ |
| | | public interface UnitInterface { |
| | |
| | | * 设置适配器 |
| | | * @throws Exception |
| | | */ |
| | | public void setAdapter(UnitAdapterInterface adapter) throws Exception ; |
| | | void setAdapter(UnitAdapterInterface adapter) throws Exception ; |
| | | /** |
| | | * 启动模块 |
| | | * 启动单元运行 |
| | | * @throws Exception |
| | | */ |
| | | public void start(UnitStartedCallbackInterface callback) throws Exception ; |
| | | void start(UnitCallbackInterface callback) throws Exception ; |
| | | /** |
| | | * 停止模块运行 |
| | | * 停止单元运行 |
| | | * @throws Exception |
| | | */ |
| | | public void stop(UnitStartedCallbackInterface callback) throws Exception ; |
| | | |
| | | void stop(UnitCallbackInterface callback) throws Exception ; |
| | | } |
| | |
| | | |
| | | import com.dy.common.mw.UnitAdapterInterface; |
| | | import com.dy.common.mw.UnitInterface; |
| | | import com.dy.common.mw.UnitStartedCallbackInterface; |
| | | import com.dy.common.mw.UnitCallbackInterface; |
| | | |
| | | public class RmiUnit implements UnitInterface { |
| | | |
| | |
| | | /** |
| | | * 启动模块 |
| | | */ |
| | | public void start(UnitStartedCallbackInterface callback) throws Exception { |
| | | public void start(UnitCallbackInterface callback) throws Exception { |
| | | if(!started){ |
| | | started = true ; |
| | | |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void stop(UnitStartedCallbackInterface callback) { |
| | | public void stop(UnitCallbackInterface callback) { |
| | | } |
| | | |
| | | |
| | |
| | | //断包了 |
| | | return false ; |
| | | }else if(dataStatus.isCompleted() || dataStatus.isAdjoined()){ |
| | | //本包数据已经全部接收,并且可能粘有下包数据 |
| | | //本包数据已经全部接收,或可能粘有下包数据 |
| | | this.nextDeal(in, dataStatus.getDataLen(), out) ; |
| | | if(dataStatus.isAdjoined()){ |
| | | //说明粘包了,还有数据,需要对这些数据再次执行doDecode_方法. |
| | |
| | | |
| | | import com.dy.common.mw.UnitAdapterInterface; |
| | | import com.dy.common.mw.UnitInterface; |
| | | import com.dy.common.mw.UnitStartedCallbackInterface; |
| | | import com.dy.common.mw.UnitCallbackInterface; |
| | | |
| | | @SuppressWarnings("unused") |
| | | public class TcpUnit implements UnitInterface { |
| | |
| | | /** |
| | | * 启动模块 |
| | | */ |
| | | public void start(UnitStartedCallbackInterface callback) throws Exception { |
| | | public void start(UnitCallbackInterface callback) throws Exception { |
| | | if(!started){ |
| | | started = true ; |
| | | /** |
| | |
| | | |
| | | //得到网络 通信数据过滤器链 |
| | | DefaultIoFilterChainBuilder chain = acceptor.getFilterChain() ; |
| | | //编解码过滤器 |
| | | //生成编解码过滤器工厂类 |
| | | dataCodecFactory = new DataCodecFactory(this.adapter) ; |
| | | //设置“protocol”,加入编解码过滤器,过滤器在IoProcessor线程中执行 |
| | | chain.addLast("protocol", new ProtocolCodecFilter(dataCodecFactory)); |
| | | |
| | | /* |
| | | * 一般ExecutorFilter 都要放在ProtocolCodecFilter 过滤器的后面, |
| | | * 也就是不要让编解码运行在独立的线程上,而是要运行在IoProcessor 所在的线程, |
| | | * 因为编解码处理的数据都是由IoProcessor 读取和发送的,没必要开启新的线程, |
| | | * 否则性能反而会下降。一般使用ExecutorFilter 的典型场景是将业务逻辑(譬如:耗时的数据库操作) |
| | | * 放在单独的线程中运行,也就是说与IO 处理无关的操作可以考虑使用ExecutorFilter 来异步执行。 |
| | | * 一般ExecutorFilter 都要放在ProtocolCodecFilter过滤器的后面, |
| | | * 也就是让编解码运行在IoProcessor所在的线程,因为编解码处理的数据都是 |
| | | * 由IoProcessor读取和发送的,没必要开启新的线程,否则性能反而会下降。 |
| | | * ExecutorFilter过程器会启动一个线程池,处理后续代码逻辑。 |
| | | * 一般使用ExecutorFilter的典型场景是将业务逻辑(譬如:耗时的数据库操作) |
| | | * 放在单独的线程中运行,也就是说与IO处理无关的操作可以考虑使用ExecutorFilter来异步执行。 |
| | | * 本处用法,使ExecutorFilter线程池中的线程处理IOHandler(TcpIoHandler)操作 |
| | | */ |
| | | chain.addLast("exceutor", new ExecutorFilter()); |
| | | |
| | |
| | | * @throws Exception |
| | | */ |
| | | @Override |
| | | public void stop(UnitStartedCallbackInterface callback) throws Exception { |
| | | public void stop(UnitCallbackInterface callback) throws Exception { |
| | | this.tcpIoHandler.stop(); |
| | | this.dataCodecFactory.stop(); |
| | | this.adapter.newUnitStopCallback().callback(); |
| | |
| | | import com.dy.common.queue.Queue; |
| | | import com.dy.common.mw.UnitAdapterInterface; |
| | | import com.dy.common.mw.UnitInterface; |
| | | import com.dy.common.mw.UnitStartedCallbackInterface; |
| | | import com.dy.common.mw.UnitCallbackInterface; |
| | | |
| | | public class CoreUnit implements UnitInterface { |
| | | |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void start(UnitStartedCallbackInterface callback) throws Exception { |
| | | public void start(UnitCallbackInterface callback) throws Exception { |
| | | if(!started){ |
| | | started = true ; |
| | | CoreThread ct = CoreThread.getInstance() ; |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void stop(UnitStartedCallbackInterface callback) { |
| | | public void stop(UnitCallbackInterface callback) { |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | import com.dy.common.mw.UnitAdapterInterface; |
| | | import com.dy.common.mw.UnitInterface; |
| | | import com.dy.common.mw.UnitStartedCallbackInterface; |
| | | import com.dy.common.mw.UnitCallbackInterface; |
| | | |
| | | |
| | | public class ProtocolUnit implements UnitInterface { |
| | |
| | | /** |
| | | * 启动模块 |
| | | */ |
| | | public void start(UnitStartedCallbackInterface callback) throws Exception { |
| | | public void start(UnitCallbackInterface callback) throws Exception { |
| | | //得到唯一实例, 并在生成唯一实例时,扫描注解类 |
| | | AnnotationScan.getIntance() ; |
| | | |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void stop(UnitStartedCallbackInterface callback) { |
| | | public void stop(UnitCallbackInterface callback) { |
| | | } |
| | | |
| | | /* |
| | |
| | | byte[] bytes = GlCreate.createStart2Cd(para.rtuAddr, para.commandCode); |
| | | if(para.param != null){ |
| | | DataCd81Vo cdData = (DataCd81Vo)para.param ; |
| | | byte[] bs = new byte[8] ; |
| | | byte[] bs = new byte[3] ; |
| | | bs[0] = (byte)(Integer.parseInt(cdData.getControllerType(), 16)); |
| | | bs[1] = cdData.projectNo.byteValue() ; |
| | | GlCreate.createTp(bs, 2) ; |
| | | bs[2] = 0x01 ;//01:成功 81:失败 |
| | | bytes = ByteUtil.bytesMerge(bytes, bs) ; |
| | | }else{ |
| | | throw new Exception("下行命令参数据为null") ; |
| | |
| | | ByteUtil.string2BCD_BE(bs, DateTime.mm(), index + 1) ; |
| | | ByteUtil.string2BCD_BE(bs, DateTime.HH(), index + 2) ; |
| | | ByteUtil.string2BCD_BE(bs, DateTime.dd(), index + 3) ; |
| | | byte month = Byte.parseByte(DateTime.MM()) ; |
| | | byte week = (byte)(DateTime.week_Int().byteValue() << 1) ; |
| | | String month1 = "0" ; |
| | | String month2 = "0" ; |
| | | if(month < 10){ |
| | | month1 = "" + month ; |
| | | }else{ |
| | | if(month == 10){ |
| | | month1 = "0" ; |
| | | }else if(month == 11){ |
| | | month1 = "1" ; |
| | | }else if(month == 12){ |
| | | month1 = "2" ; |
| | | } |
| | | week = (byte)(week | 0x01) ; |
| | | } |
| | | month2 = "" + week ; |
| | | |
| | | ByteUtil.string2BCD_BE(bs, month2 + month1, index + 4) ; |
| | | //以下写法自然也是BCD |
| | | bs[index + 4] = (byte)((DateTime.week_Int().byteValue() << 5 | Byte.parseByte(DateTime.MM()))) ; |
| | | ByteUtil.string2BCD_BE(bs, DateTime.yy(), index + 5) ; |
| | | |
| | | /* |
| | |
| | | import com.dy.common.threadPool.TreadPoolFactory; |
| | | import com.dy.common.mw.UnitAdapterInterface; |
| | | import com.dy.common.mw.UnitInterface; |
| | | import com.dy.common.mw.UnitStartedCallbackInterface; |
| | | import com.dy.common.mw.UnitCallbackInterface; |
| | | |
| | | public class SupportUnit implements UnitInterface { |
| | | |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void start(UnitStartedCallbackInterface callback) throws Exception { |
| | | public void start(UnitCallbackInterface callback) throws Exception { |
| | | if(!started){ |
| | | started = true ; |
| | | if(confVo.enableShortThreadPool) { |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void stop(UnitStartedCallbackInterface callback) { |
| | | public void stop(UnitCallbackInterface callback) { |
| | | } |
| | | |
| | | /* |
| | |
| | | case "周四" -> 4; |
| | | case "周五" -> 5; |
| | | case "周六" -> 6; |
| | | case "周七" -> 7; |
| | | case "周七" -> 0;//根据协议要求星期天为0 |
| | | default -> 0; |
| | | }; |
| | | }else{ |
| | |
| | | case "Thu" -> 4; |
| | | case "Fri" -> 5; |
| | | case "Sat" -> 6; |
| | | case "Sun" -> 7; |
| | | case "Sun" -> 0;//根据协议要求星期天为0 |
| | | default -> 0; |
| | | }; |
| | | } |
| | |
| | | //RTU日志文件存储目录(相对目录) |
| | | resVo.rtuLogDir = conf.getSetAttrTxt(doc, "config.resource", "rtuLogDir", null, false, null) ; |
| | | //RTU日志文件最大字节数(KB) |
| | | resVo.rtuLogFileMaxSize = conf.getSetAttrPlusInt(doc, "config.resource", "rtuLogFileMaxSize", null, 100000, 2000000, null) ; |
| | | resVo.rtuLogFileMaxSize = conf.getSetAttrPlusInt(doc, "config.resource", "rtuLogFileMaxSize", null, 10, 2000000, null) ; |
| | | //RTU日志文件最大文件数 |
| | | resVo.rtuLogFileMaxCount = conf.getSetAttrPlusInt(doc, "config.resource", "rtuLogFileMaxCount", null, 1, 10, null) ; |
| | | |
| | |
| | | */ |
| | | |
| | | ///////////////// |
| | | //RTU上行数据处理模块 |
| | | //RTU上行数据处理模块(任务树) |
| | | RtuDataUnitConfigVo rducVo = new RtuDataUnitConfigVo(); |
| | | rducVo.resourceLoader = this.resourceLoader ; |
| | | AdapterImp_RtuDataUnit rducAdap = new AdapterImp_RtuDataUnit(); |
| | |
| | | |
| | | import com.dy.common.mw.UnitAdapterInterface; |
| | | import com.dy.common.mw.UnitInterface; |
| | | import com.dy.common.mw.UnitStartedCallbackInterface; |
| | | import com.dy.common.mw.UnitCallbackInterface; |
| | | import com.dy.rtuMw.resource.rtuLog.RtuLogManager; |
| | | import com.dy.common.util.DateTime; |
| | | |
| | |
| | | ResourceUnit.springContext = springContext ; |
| | | } |
| | | @Override |
| | | public void start(UnitStartedCallbackInterface callback) throws Exception { |
| | | public void start(UnitCallbackInterface callback) throws Exception { |
| | | if(ResourceUnit.springContext == null){ |
| | | throw new Exception("Spring上下文对象未设置!") ; |
| | | } |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void stop(UnitStartedCallbackInterface callback) { |
| | | public void stop(UnitCallbackInterface callback) { |
| | | } |
| | | |
| | | /** |
| | |
| | | package com.dy.rtuMw.server.local; |
| | | |
| | | import com.dy.common.mw.UnitStartedCallbackInterface; |
| | | import com.dy.common.mw.UnitCallbackInterface; |
| | | import com.dy.common.mw.channel.tcp.TcpUnit; |
| | | import com.dy.common.mw.protocol.Command; |
| | | import com.dy.rtuMw.server.local.localProtocol.*; |
| | |
| | | * @throws Exception |
| | | */ |
| | | private Command stopTcpSv(Command command) throws Exception{ |
| | | TcpUnit.getInstance().stop(new UnitStartedCallbackInterface(){ |
| | | TcpUnit.getInstance().stop(new UnitCallbackInterface(){ |
| | | public void call(Object obj) throws Exception { |
| | | |
| | | } |
| | |
| | | |
| | | import com.dy.common.mw.UnitAdapterInterface; |
| | | import com.dy.common.mw.UnitInterface; |
| | | import com.dy.common.mw.UnitStartedCallbackInterface; |
| | | import com.dy.common.mw.UnitCallbackInterface; |
| | | |
| | | public class RtuDataUnit implements UnitInterface { |
| | | |
| | |
| | | * 初始化上行数据处理任务池 |
| | | */ |
| | | @Override |
| | | public void start(UnitStartedCallbackInterface callback) throws Exception { |
| | | public void start(UnitCallbackInterface callback) throws Exception { |
| | | TaskPool.setTaskTreeCofig(new TreeParse().parseConfig(confVo.resourceLoader)); |
| | | callback.call(null) ; |
| | | System.out.println("RTU数据处理模块成功启动"); |
| | | } |
| | | |
| | | @Override |
| | | public void stop(UnitStartedCallbackInterface callback) throws Exception { |
| | | public void stop(UnitCallbackInterface callback) throws Exception { |
| | | } |
| | | |
| | | } |
| | |
| | | |
| | | import com.dy.common.mw.UnitAdapterInterface; |
| | | import com.dy.common.mw.UnitInterface; |
| | | import com.dy.common.mw.UnitStartedCallbackInterface; |
| | | import com.dy.common.mw.UnitCallbackInterface; |
| | | import com.dy.common.mw.channel.rmi.RmiFrameWork; |
| | | |
| | | public class RmiClUnit implements UnitInterface { |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void start(UnitStartedCallbackInterface callback) throws Exception { |
| | | public void start(UnitCallbackInterface callback) throws Exception { |
| | | System.out.println("Rmi Client模块成功启动"); |
| | | this.doStart(); |
| | | callback.call(null) ; |
| | | } |
| | | |
| | | @Override |
| | | public void stop(UnitStartedCallbackInterface callback) throws Exception { |
| | | public void stop(UnitCallbackInterface callback) throws Exception { |
| | | callback.call(null); |
| | | } |
| | | |
| | |
| | | |
| | | import com.dy.common.mw.UnitAdapterInterface; |
| | | import com.dy.common.mw.UnitInterface; |
| | | import com.dy.common.mw.UnitStartedCallbackInterface; |
| | | import com.dy.common.mw.UnitCallbackInterface; |
| | | import com.dy.common.threadPool.ThreadPool; |
| | | import com.dy.common.threadPool.TreadPoolFactory; |
| | | import com.dy.common.util.Callback; |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void start(UnitStartedCallbackInterface callback) throws Exception { |
| | | public void start(UnitCallbackInterface callback) throws Exception { |
| | | pool = TreadPoolFactory.getThreadPoolLong() ; |
| | | System.out.println("Tcp Client模块成功启动"); |
| | | this.doStart(); |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void stop(UnitStartedCallbackInterface callback) throws Exception { |
| | | public void stop(UnitCallbackInterface callback) throws Exception { |
| | | callback.call(null); |
| | | } |
| | | |
| | |
| | | import org.jdom2.Document; |
| | | |
| | | import com.dy.common.mw.UnitInterface; |
| | | import com.dy.common.mw.UnitStartedCallbackInterface; |
| | | import com.dy.common.mw.UnitCallbackInterface; |
| | | import com.dy.common.mw.channel.rmi.RmiConfigVo; |
| | | import com.dy.common.mw.channel.rmi.RmiUnit; |
| | | import com.dy.common.util.NumUtil; |
| | |
| | | rmiAdap.setConfig(rmiVo); |
| | | RmiUnit rmiUnit = RmiUnit.getInstance(); |
| | | rmiUnit.setAdapter(rmiAdap); |
| | | rmiUnit.start(new UnitStartedCallbackInterface(){ |
| | | rmiUnit.start(new UnitCallbackInterface(){ |
| | | @Override |
| | | public void call(Object obj) { |
| | | } |
| | |
| | | |
| | | import com.dy.common.mw.UnitAdapterInterface; |
| | | import com.dy.common.mw.UnitInterface; |
| | | import com.dy.common.mw.UnitStartedCallbackInterface; |
| | | import com.dy.common.mw.UnitCallbackInterface; |
| | | import com.dy.common.util.Callback; |
| | | import com.dy.pipIrrMwTestRtu.ServerProperties; |
| | | import com.dy.pipIrrMwTestRtu.tcpClient.upData.UpData; |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void start(UnitStartedCallbackInterface callback) throws Exception { |
| | | public void start(UnitCallbackInterface callback) throws Exception { |
| | | System.out.println("Tcp Client模块成功启动"); |
| | | this.doStart(); |
| | | callback.call(null) ; |
| | | } |
| | | |
| | | @Override |
| | | public void stop(UnitStartedCallbackInterface callback) throws Exception { |
| | | public void stop(UnitCallbackInterface callback) throws Exception { |
| | | callback.call(null); |
| | | } |
| | | |