1、完善代码;
2、江海协议时标(tp)实现中的bug修改。
 
	
	
	
	
	
	
	
	
	
	
	
	
	
 |  |  | 
 |  |  |  | 
 |  |  |  | 
 |  |  | /** | 
 |  |  |  * 模块单元适配器接口 | 
 |  |  |  * | 
 |  |  |  * 单元适配器接口 | 
 |  |  |  */ | 
 |  |  | 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) { | 
 |  |  |     } | 
 |  |  |      | 
 |  |  |  | 
 
 |  |  | 
 |  |  |  | 
 |  |  | 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 ; | 
 |  |  |             /** | 
 |  |  | 
 |  |  |      * @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上行数据处理模块 | 
 |  |  |             //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); | 
 |  |  |     } | 
 |  |  |  |