Merge branch 'master' of http://8.140.179.55:20000/r/pipIrr-SV
Conflicts:
pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V1_0_0/CommonV1_0_1.java
pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V1_0_0/DataCdC0Vo.java
pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V1_0_0/DataV1_0_1.java
pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V1_0_0/DriverV1_0_1.java
pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V1_0_0/PrefixedDataAvailableV1_0_1.java
pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V1_0_0/ProtocolConstantV206V1_0_0.java
pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V1_0_0/parse/Cd_02_Down.java
pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V1_0_0/parse/Cd_71_Down.java
pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V1_0_0/parse/Cd_83_Down.java
pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V1_0_0/parse/Cd_84_Down.java
pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V1_0_0/parse/Cd_C0_Down.java
pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V1_0_0/parse/global/GlCreate.java
pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V1_0_0/parse/global/GlParse.java
pipIrr-platform/pipIrr-mw/pipIrr-mw-accept/pom.xml
pipIrr-platform/pipIrr-mw/pipIrr-mw-accept/src/main/java/com/dy/aceMw/Server.java
pipIrr-platform/pipIrr-mw/pipIrr-mw-accept/src/main/java/com/dy/aceMw/server/forTcp/MidResultActionFromRtu.java
pipIrr-platform/pipIrr-mw/pipIrr-mw-accept/src/main/java/com/dy/aceMw/server/rtuData/RtuDataCache.java
pipIrr-platform/pipIrr-mw/pipIrr-mw-accept/src/main/java/com/dy/aceMw/server/rtuData/RtuDataNode.java
pipIrr-platform/pipIrr-mw/pipIrr-mw-accept/src/main/java/com/dy/aceMw/server/rtuData/Task.java
pipIrr-platform/pipIrr-mw/pipIrr-mw-accept/src/main/java/com/dy/aceMw/server/rtuData/TaskConfig.java
pipIrr-platform/pipIrr-mw/pipIrr-mw-accept/src/main/java/com/dy/aceMw/server/rtuData/TaskPool.java
pipIrr-platform/pipIrr-mw/pipIrr-mw-accept/src/main/java/com/dy/aceMw/server/rtuData/TaskSurpport.java
pipIrr-platform/pipIrr-mw/pipIrr-mw-accept/src/main/java/com/dy/aceMw/server/rtuData/TkReceive.java
pipIrr-platform/pipIrr-mw/pipIrr-mw-accept/src/main/java/com/dy/aceMw/server/rtuData/TkRtuData.java
pipIrr-platform/pipIrr-mw/pipIrr-mw-accept/src/main/java/com/dy/aceMw/server/rtuData/TreeConfig.java
pipIrr-platform/pipIrr-mw/pipIrr-mw-accept/src/main/java/com/dy/aceMw/server/rtuData/TreeParse.java
pipIrr-platform/pipIrr-mw/pipIrr-mw-accept/src/main/java/com/dy/aceMw/server/rtuData/dbSv/RtuSv.java
pipIrr-platform/pipIrr-mw/pipIrr-mw-accept/src/main/java/com/dy/aceMw/server/rtuData/dbSv/说明.txt
pipIrr-platform/pipIrr-mw/pipIrr-mw-accept/src/main/java/com/dy/aceMw/server/rtuData/p206V1_0_0/TkFindP206V1_0_0.java
pipIrr-platform/pipIrr-mw/pipIrr-mw-accept/src/main/java/com/dy/aceMw/server/tasks/FromRtuConstantTask.java
pipIrr-platform/pipIrr-mw/pipIrr-mwTest-server/src/main/java/com/dy/testServer/forRmi/RmiRequestVo.java
1 文件已重命名
34个文件已添加
14个文件已修改
New file |
| | |
| | | package com.dy.common.mw.protocol.p206V1_0_0; |
| | | |
| | | import com.dy.common.util.ByteUtil; |
| | | import com.dy.common.util.ByteUtilUnsigned; |
| | | import com.dy.common.util.CRC8_for_2_0; |
| | | |
| | | |
| | | public class CommonV1_0_1 { |
| | | /** |
| | | * æ£æ¥å¤´ |
| | | * @param bs ä¸è¡åèæ°ç» |
| | | * @return trueæ¯,falseå¦ |
| | | * @throws Exception å¼å¸¸ |
| | | */ |
| | | public Boolean isThisProtocolHead(byte[] bs) throws Exception{ |
| | | if(bs == null){ |
| | | return null ; |
| | | }else if(bs.length >= (ProtocolConstantV206V1_0_0.ctrlIndex - 1) |
| | | && bs[0] == ProtocolConstantV206V1_0_0.P_Head_Byte |
| | | && bs[2] == ProtocolConstantV206V1_0_0.P_Head_Byte){ |
| | | //String vs = this.parseVersion(bs) ; |
| | | //return vs.equals(ProtocolConstantV206V1_0_0.version); |
| | | return true ; |
| | | }else{ |
| | | return false ; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * æ£æ¥å¤´ |
| | | * @param bs ä¸è¡åèæ°ç» |
| | | * @throws Exception å¼å¸¸ |
| | | */ |
| | | public void checkHead(byte[] bs) throws Exception{ |
| | | if(bs.length < 13 || bs[0] != ProtocolConstantV206V1_0_0.P_Head_Byte || bs[2] != ProtocolConstantV206V1_0_0.P_Head_Byte){ |
| | | throw new Exception("ä¸è¡æ°æ®å¸§å¤´ä¸æ£ç¡®ï¼") ; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * æ£æ¥å°¾ |
| | | * @param bs ä¸è¡åèæ°ç» |
| | | * @throws Exception å¼å¸¸ |
| | | */ |
| | | public void checkTail(byte[] bs) throws Exception{ |
| | | if(bs.length < 1 || bs[bs.length - 1] != ProtocolConstantV206V1_0_0.P_Tail_Byte){ |
| | | throw new Exception("ä¸è¡æ°æ®å°¾ä¸æ£ç¡®ï¼") ; |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * åæå¸§é¿åº¦ |
| | | * @param bs ä¸è¡åèæ°ç» |
| | | * @return æ°æ®é¿åº¦ |
| | | * @throws Exception å¼å¸¸ |
| | | */ |
| | | public int parseFrameLen(byte[] bs)throws Exception{ |
| | | int len = ByteUtilUnsigned.byte2Byte(bs, ProtocolConstantV206V1_0_0.dataLenIndex) ; |
| | | return len + ProtocolConstantV206V1_0_0.lenHead2ctrl + ProtocolConstantV206V1_0_0.lenTail ; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * åæç¨æ·æ°æ®ååèæ° |
| | | * @param bs ä¸è¡åèæ°ç» |
| | | * @return æ°æ®é¿åº¦ |
| | | * @throws Exception å¼å¸¸ |
| | | */ |
| | | public int parseDataLen(byte[] bs)throws Exception{ |
| | | int len = ByteUtilUnsigned.byte2Byte(bs, ProtocolConstantV206V1_0_0.dataLenIndex) ; |
| | | return len + ProtocolConstantV206V1_0_0.lenHead2ctrl + ProtocolConstantV206V1_0_0.lenTail ; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * åæRtuå°å |
| | | * @param bs ä¸è¡åèæ°ç» |
| | | * @return æ§å¶å¨å°å |
| | | * @throws Exception å¼å¸¸ |
| | | */ |
| | | public String parseRtuAddr(byte[] bs)throws Exception{ |
| | | String rtuAddrBCD = "" + ByteUtil.BCD2Long_BE(bs, ProtocolConstantV206V1_0_0.rtuAddr1Index_start, ProtocolConstantV206V1_0_0.rtuAddr1Index_end) ; |
| | | String rtuAddrStr = "" + ByteUtilUnsigned.bytes2Short_BE(bs, ProtocolConstantV206V1_0_0.rtuAddr2Index_start) ; |
| | | while(rtuAddrStr.length() < 4){ |
| | | rtuAddrStr = "0" + rtuAddrStr ; |
| | | } |
| | | return rtuAddrBCD + rtuAddrStr ; |
| | | } |
| | | |
| | | /** |
| | | * åæåè½ç |
| | | * @param bs ä¸è¡åèæ°ç» |
| | | * @return åè½ç |
| | | */ |
| | | public String parseCode(byte[] bs){ |
| | | return ByteUtil.bytes2Hex(bs, false, ProtocolConstantV206V1_0_0.codeIndex, 1) ; |
| | | } |
| | | |
| | | /** |
| | | * æ ¡éªåæ£æ¥ |
| | | * @param bs ä¸è¡åèæ°ç» |
| | | * @return éè¿nullï¼æªéè¿è¿ååå |
| | | * @throws Exception å¼å¸¸ |
| | | */ |
| | | public String checkCrc_str(byte[] bs) throws Exception { |
| | | byte crcCompute = (byte)new CRC8_for_2_0().CRC8(bs, ProtocolConstantV206V1_0_0.ctrlIndex, bs.length - 3) ; |
| | | byte crcInBs = bs[bs.length - 2] ; |
| | | if(crcCompute == crcInBs){ |
| | | return null ; |
| | | }else{ |
| | | return "计ç®CRCæ¯:" + crcCompute + "ï¼ä¸ä¼ CRCæ¯" + crcInBs ; |
| | | } |
| | | } |
| | | |
| | | |
| | | /* |
| | | æé æ§å¶å |
| | | D7 D6 D5ï½D4 D3ï½D0 |
| | | ä¼ è¾æ¹åä½ DIR æåæ å¿ä½ DIV 帧计æ°ä½ FCB åè½ç |
| | | */ |
| | | public byte createCtrl(byte dir, byte funcCode){ |
| | | byte b = dir;//(byte)0x80//æ§å¶åï¼DIR=1ï¼è¡¨ç¤ºæ¤å¸§æ¥ææ¯ç±ç»ç«¯ååºçä¸è¡æ¥æï¼ |
| | | b = (byte)(b | funcCode) ; |
| | | //FCB == 3 |
| | | b = (byte)(b | (byte)0x18) ; |
| | | //DIV = 0 |
| | | //DIR = 0 |
| | | return b ; |
| | | } |
| | | |
| | | /** |
| | | * å¾å°å
³å¼éç±»ååç§° |
| | | * @param type åè |
| | | * @return åç§° |
| | | */ |
| | | public static String openCloseValveType(byte type){ |
| | | return switch (type) { |
| | | case 1 -> "å·å¡å¼é"; |
| | | case 2 -> "å·å¡å
³é"; |
| | | case 3 -> "ä¸å¿ç«å¼é"; |
| | | case 4 -> "ä¸å¿ç«å
³é"; |
| | | case 5 -> "æ¬ è´¹å
³é"; |
| | | case 6 -> "æµé计æ
éå
³é"; |
| | | case 7 -> "ç´§æ¥å
³é"; |
| | | case 8 -> "ç¨æ·è¿ç¨å¼é"; |
| | | case 9 -> "ç¨æ·è¿ç¨å
³é"; |
| | | default -> "æªç¥"; |
| | | }; |
| | | } |
| | | |
| | | /* |
| | | * åæçæ¬å· |
| | | * @param bs ä¸è¡åèæ°ç» |
| | | * @return çæ¬å· |
| | | * @throws Exception å¼å¸¸ |
| | | public String parseVersion(byte[] bs)throws Exception{ |
| | | short ver = ByteUtilUnsigned.byte2Byte(bs, ProtocolConstantV206V1_0_0.versionIndex) ; |
| | | char[] cs = ("" + ver).toCharArray() ; |
| | | StringBuilder vs = new StringBuilder() ; |
| | | for(byte i = 0 ; i < cs.length; i++){ |
| | | if(i == 0){ |
| | | vs.append(cs[i]) ; |
| | | }else{ |
| | | vs.append(".").append(cs[i]) ; |
| | | } |
| | | } |
| | | return vs.toString() ; |
| | | } |
| | | */ |
| | | |
| | | } |
New file |
| | |
| | | package com.dy.common.mw.protocol.p206V1_0_0; |
| | | |
| | | import lombok.Data; |
| | | |
| | | @Data |
| | | public class DataCdC0Vo { |
| | | public Double instantAmount; //ç¬æ¶æµéï¼5åèBCDç ï¼åå¼èå´0~9999999.999ï¼åä½ä¸ºm3/hã |
| | | public Double totalAmount; //累计æµéï¼5åèBCDç ï¼åå¼èå´0~9999999999ï¼åä½ä¸ºm3ã |
| | | public Double lossAmount; //æå¤±æµéï¼5åèBCDç ï¼åå¼èå´0~9999999999ï¼åä½ä¸ºm3ã |
| | | public Double waterPress; //æ°´åï¼4åèBCDç ï¼åå¼èå´0~999999.99ï¼åä½ä¸ºKPaã |
| | | public Double batteryVolt;//èçµæ± çµå:4åèBCDç ï¼åå¼èå´0~99.99ï¼åä½ä¸ºVã |
| | | public Double sunVolt ;//太é³è½çµå:4åèBCDç ï¼åå¼èå´0~99.99ï¼åä½ä¸ºVã |
| | | public Integer signal; //ä¿¡å·å¼ºåº¦ï¼1åèBCDç ï¼åå¼èå´0~99ã |
| | | public String rtuDt ;//æ§å¶å¨æ¶é |
| | | public DataAlarmVo alarmVo ;//æ¥è¦ |
| | | public DataStateVo stateVo ;//ç¶æ |
| | | public String toString(){ |
| | | StringBuilder sb = new StringBuilder() ; |
| | | sb.append(" ç»ç«¯èªæ¥å®æ¶æ°æ®:\n"); |
| | | sb.append(" ç¬æ¶æµéï¼"); |
| | | sb.append(instantAmount==null?"":instantAmount); |
| | | sb.append("\n"); |
| | | sb.append(" 累计æµéï¼"); |
| | | sb.append(totalAmount==null?"":totalAmount); |
| | | sb.append("\n"); |
| | | sb.append(" æå¤±æµéï¼"); |
| | | sb.append(lossAmount==null?"":lossAmount); |
| | | sb.append("\n"); |
| | | sb.append(" æ°´åï¼"); |
| | | sb.append(waterPress==null?"":waterPress); |
| | | sb.append("\n"); |
| | | sb.append(" èçµæ± çµåï¼"); |
| | | sb.append(batteryVolt==null?"":batteryVolt); |
| | | sb.append("\n"); |
| | | sb.append(" 太é³è½çµåï¼"); |
| | | sb.append(sunVolt==null?"":sunVolt); |
| | | sb.append("\n"); |
| | | sb.append(" ä¿¡å·å¼ºåº¦ï¼"); |
| | | sb.append(signal==null?"":signal); |
| | | sb.append("\n"); |
| | | sb.append(" æ§å¶å¨æ¶éï¼"); |
| | | sb.append(rtuDt==null?"":rtuDt); |
| | | sb.append("\n"); |
| | | if(alarmVo != null){ |
| | | sb.append(alarmVo.toString()); |
| | | sb.append("\n"); |
| | | } |
| | | if(stateVo != null){ |
| | | sb.append(stateVo.toString()); |
| | | sb.append("\n"); |
| | | } |
| | | |
| | | return sb.toString() ; |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.dy.common.mw.protocol.p206V1_0_0; |
| | | |
| | | import lombok.Data; |
| | | |
| | | @Data |
| | | public class DataV1_0_1 implements java.io.Serializable{ |
| | | |
| | | private static final long serialVersionUID = 202211271110001L; |
| | | |
| | | public String rtuAddr ;//RtuAddr |
| | | |
| | | public DataCd02Vo dataCd02Vo;//é¾è·¯æ£æµ |
| | | public DataCdC0Vo dataCdC0Vo;//ç»ç«¯èªæ¥å®æ¶æ°æ® |
| | | public DataCd83OpenVo dataCd83OpenVo;//å¼éèªæ¥ |
| | | public DataCd83CloseVo dataCd83CloseVo;//å
³éèªæ¥ |
| | | public DataCd84Vo dataCd84Vo;//å¼é工使¥ |
| | | public DataCd71Vo dataCd71Vo;//æ¥è¯¢éé¨ç¶æ |
| | | |
| | | public String dt ;//éä¿¡ä¸é´ä»¶äº§ç忥æ¶é´(yyyy-MM-dd hh:mm:ss) |
| | | |
| | | public String toString(){ |
| | | StringBuffer sb = new StringBuffer() ; |
| | | sb.append(" æ§å¶å¨å°å : " + (rtuAddr==null?"":rtuAddr) + "\n") ; |
| | | sb.append(" ç»ç«¯æ°æ®:\n") ; |
| | | if(dataCd02Vo != null){ |
| | | sb.append(dataCd02Vo.toString()) ; |
| | | } |
| | | if(dataCdC0Vo != null){ |
| | | sb.append(dataCdC0Vo.toString()) ; |
| | | } |
| | | if(dataCd83OpenVo != null){ |
| | | sb.append(dataCd83OpenVo.toString()) ; |
| | | } |
| | | if(dataCd83CloseVo != null){ |
| | | sb.append(dataCd83CloseVo.toString()) ; |
| | | } |
| | | if(dataCd84Vo != null){ |
| | | sb.append(dataCd84Vo.toString()) ; |
| | | } |
| | | if(dataCd71Vo != null){ |
| | | sb.append(dataCd71Vo.toString()) ; |
| | | } |
| | | return sb.toString() ; |
| | | } |
| | | } |
New file |
| | |
| | | package com.dy.common.mw.protocol.p206V1_0_0; |
| | | |
| | | import com.dy.common.mw.protocol.*; |
| | | import com.dy.common.util.DateTime; |
| | | |
| | | import java.net.URI; |
| | | import java.net.URL; |
| | | |
| | | @AnnotationDriver(name= ProtocolConstantV206V1_0_0.protocolName) |
| | | public class DriverV1_0_1 extends Driver { |
| | | |
| | | private static String scanRootPackage = "com.dy.common.mw.protocol.p206V1_0_0." ; |
| | | |
| | | //å¨Driver䏿¯åä¾ï¼éDriverçåä¾å¯¹è±¡å¨å线ç¨ä¸è¿è¡ |
| | | private ParseParamsForUpV1_0_1 upCpParams ; |
| | | private ParseParamsForDownV1_0_1 downCpParams ; |
| | | |
| | | private Boolean reportOrResponse_trueOrFalse = null ; |
| | | private String rtuAddrInData = null ; |
| | | |
| | | public DriverV1_0_1(){ |
| | | upCpParams = new ParseParamsForUpV1_0_1() ; |
| | | downCpParams = new ParseParamsForDownV1_0_1() ; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * æ«æè¯å«åè½ç 注解类 |
| | | */ |
| | | @Override |
| | | public void scanAnnotationCode() throws Exception{ |
| | | if(!scanRootPackage.endsWith(".")){ |
| | | scanRootPackage += "." ; |
| | | } |
| | | URL url = this.getClass().getResource("/" + scanRootPackage.replace('.', '/')); |
| | | URI uri = new URI(url.toString()); |
| | | super.doScanAnnotationCode(this, ProtocolConstantV206V1_0_0.protocolName, uri, scanRootPackage) ; |
| | | } |
| | | |
| | | /** |
| | | * è§£æä¸è¡æ°æ® |
| | | * @param isLowPower æ¯å¦å¨ä½åèç¯å¢ä¸è¿è¡ |
| | | * @param rtuAddr |
| | | * @param upBuffer |
| | | * @param callback |
| | | * @param upHex |
| | | * @return |
| | | */ |
| | | @Override |
| | | public MidResult[] parseData(Boolean isLowPower, String rtuAddr, byte[] upBuffer, String upHex, DriverParserDataCallback callback, Object... params) { |
| | | reportOrResponse_trueOrFalse = null ; |
| | | boolean isFail = false ; |
| | | String upCode = null ; |
| | | try{ |
| | | CommonV1_0_1 cp = new CommonV1_0_1() ; |
| | | cp.checkHead(upBuffer) ; |
| | | cp.checkTail(upBuffer) ; |
| | | String crcStr = cp.checkCrc_str(upBuffer) ; |
| | | if(crcStr != null){ |
| | | return new MidResult[]{(new MidResultError(ProtocolConstantV206V1_0_0.protocolName, rtuAddr, "严éé误ï¼ä¸è¡æ°æ®CRCæ£æ¥å¤±è´¥ï¼" + crcStr, null))} ; |
| | | } |
| | | rtuAddr = cp.parseRtuAddr(upBuffer) ; |
| | | upCode = cp.parseCode(upBuffer) ; |
| | | if(upCode == null){ |
| | | return new MidResult[]{(new MidResultError(ProtocolConstantV206V1_0_0.protocolName, rtuAddr, "严ééè¯¯ï¼æªè½ä»ä¸è¡æ°æ®ä¸è§£æåºåè½ç ï¼", null))} ; |
| | | } |
| | | //Integer dataLen = cp.parseFrameLen(upBuffer) ; |
| | | Data upData = new Data() ; |
| | | upData.setRtuAddr(rtuAddr) ; |
| | | upData.setProtocol(ProtocolConstantV206V1_0_0.protocolName); |
| | | upData.setCode(upCode) ; |
| | | upData.setHex(upHex) ; |
| | | |
| | | |
| | | DataV1_0_1 dV1_0_1 = new DataV1_0_1() ; |
| | | //dV1_0_1.version = cp.parseVersion(upBuffer) ; |
| | | dV1_0_1.rtuAddr = rtuAddr ; |
| | | dV1_0_1.dt = DateTime.yyyy_MM_dd_HH_mm_ss() ; |
| | | |
| | | upData.setSubData(dV1_0_1) ; |
| | | |
| | | this.upCpParams.clear(); |
| | | this.upCpParams.setValue(ProtocolConstantV206V1_0_0.protocolName, |
| | | rtuAddr, |
| | | upCode, |
| | | upHex, |
| | | upBuffer, |
| | | upData); |
| | | CodeParse codeParse = this.getUpCodeParser(upCode) ; |
| | | if(codeParse == null){ |
| | | return new MidResult[]{(new MidResultError(ProtocolConstantV206V1_0_0.protocolName, rtuAddr, "严ééè¯¯ï¼æªè½å¾å°ä¸è¡æ°æ®åè½ç " + upCode + "å¤çç±»!", null))} ; |
| | | }else{ |
| | | return codeParse.parse(isLowPower, this.upCpParams, new CodeParseCallback(){ |
| | | @Override |
| | | public void callback(Boolean flag) { |
| | | reportOrResponse_trueOrFalse = flag ; |
| | | rtuAddrInData = dV1_0_1.getRtuAddr() ; |
| | | } |
| | | }); |
| | | } |
| | | |
| | | } catch (Exception e) { |
| | | isFail = true ; |
| | | return new MidResult[]{(new MidResultError(ProtocolConstantV206V1_0_0.protocolName, rtuAddr, "严éé误ï¼åæRtuæ°æ®åºéï¼æ°æ®ä¸ºï¼" + upHex + (e.getMessage() == null?"":("ï¼åºéä¿¡æ¯ï¼" + e.getMessage())), e))} ; |
| | | } finally{ |
| | | callback.callback(rtuAddr, upCode, upHex, reportOrResponse_trueOrFalse, isFail, rtuAddrInData); |
| | | } |
| | | } |
| | | /** |
| | | * æé ä¸è¡æ°æ®ï¼å½ä»¤ï¼ |
| | | * @param isLowPower æ¯å¦å¨ä½åèç¯å¢ä¸è¿è¡ |
| | | * @param command å½ä»¤ |
| | | * @return |
| | | */ |
| | | @Override |
| | | public MidResult[] createCommand(Boolean isLowPower, Command command, Object... params) { |
| | | String rtuAddr = command.getRtuAddr() ; |
| | | if(rtuAddr == null){ |
| | | return new MidResult[]{(new MidResultError(ProtocolConstantV206V1_0_0.protocolName, null, "严éé误ï¼å½ä»¤ä¸Rtuå°å为空ï¼ä¸è½æå»ºä»»ä½å½ä»¤ï¼", null))} ; |
| | | } |
| | | try { |
| | | String commandCode = command.getCode() ; |
| | | |
| | | this.downCpParams.clear(); |
| | | this.downCpParams.setValue( |
| | | ProtocolConstantV206V1_0_0.protocolName, |
| | | rtuAddr, |
| | | command.getId(), |
| | | commandCode, |
| | | command.getParam(), |
| | | command.getAttachment()); |
| | | |
| | | if(commandCode == null){ |
| | | return new MidResult[]{(new MidResultError(ProtocolConstantV206V1_0_0.protocolName, rtuAddr, "严éé误ï¼å½ä»¤ä¸åè½ç 为空ï¼ä¸è½æå»ºä»»ä½å½ä»¤ï¼", null))} ; |
| | | }else{ |
| | | CodeParse codeParse = this.getDownCodeParser(commandCode) ; |
| | | if(codeParse == null){ |
| | | return new MidResult[]{(new MidResultError(ProtocolConstantV206V1_0_0.protocolName, rtuAddr, "严ééè¯¯ï¼æªè½å¾å°ä¸è¡æ°æ®åè½ç " + commandCode + "å¤çç±»!", null))} ; |
| | | }else{ |
| | | return codeParse.parse(isLowPower, this.downCpParams, null); |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | return new MidResult[]{(new MidResultError(ProtocolConstantV206V1_0_0.protocolName, rtuAddr, "严ééè¯¯ï¼æé ä¸è¡æ°æ®åºéï¼å½ä»¤ä¸ºï¼" + command.toString(), e))} ; |
| | | } |
| | | } |
| | | |
| | | |
| | | } |
New file |
| | |
| | | package com.dy.common.mw.protocol.p206V1_0_0; |
| | | |
| | | import com.dy.common.mw.channel.tcp.PrefixedDataAvailableStatus; |
| | | import com.dy.common.mw.protocol.AnnotationPrefixedDataAvailable; |
| | | import com.dy.common.mw.protocol.PrefixedDataAvailable; |
| | | import com.dy.common.util.ByteUtil; |
| | | import org.apache.logging.log4j.LogManager; |
| | | import org.apache.logging.log4j.Logger; |
| | | import org.apache.mina.core.buffer.BufferDataException; |
| | | import org.apache.mina.core.buffer.IoBuffer; |
| | | |
| | | |
| | | @AnnotationPrefixedDataAvailable( |
| | | protocolName = ProtocolConstantV206V1_0_0.protocolName, |
| | | priority = ProtocolConstantV206V1_0_0.priority, |
| | | onLineDataMinLength = ProtocolConstantV206V1_0_0.onLineDataMinLength, |
| | | headMinLength = ProtocolConstantV206V1_0_0.headMinLength) |
| | | @SuppressWarnings("unused") |
| | | public class PrefixedDataAvailableV1_0_1 implements PrefixedDataAvailable { |
| | | |
| | | private static final Logger log = LogManager.getLogger(PrefixedDataAvailableV1_0_1.class) ; |
| | | |
| | | private static final String protocolName = ProtocolConstantV206V1_0_0.protocolName ; |
| | | |
| | | |
| | | /** |
| | | * åæä¸çº¿æ°æ®(ç½ç»è¿æ¥å第ä¸å
æ°æ®)æ¯å¦å¯è·å¾ |
| | | * @param in IoBuffer |
| | | * @param remain ä¸å®æ¶å¤§äº0çæ°æ® |
| | | * @param minDataLength æå°æ°æ®é¿åº¦ |
| | | * @param maxDataLength æå¤§æ°æ®é¿åº¦ï¼è¾¾å°æè¶
è¿æ¤é¿åº¦ï¼è®¤ä¸ºæ¯å徿°æ®ãä¾å¦ï¼æ°æ®å¤´é¨æ¯æ£ç¡®çï¼ä½åæ³æ°æ®ç»å°¾æ»ä¸åºç°ï¼è®¤ä¸ºæ¤æ°æ®å徿°æ® |
| | | * @return 䏿¯æ¬åè®®æ°æ®æ¶è¿å空 |
| | | * @throws Exception å¼å¸¸ |
| | | */ |
| | | public PrefixedDataAvailableStatus forOnLine(IoBuffer in, |
| | | int remain, |
| | | int minDataLength, //对åºProtocolConstantV2_0.onLineDataMinLength |
| | | int maxDataLength //对åºProtocolConstant.errorMaxLength |
| | | ) throws Exception { |
| | | |
| | | int oldPosition = in.position() ; |
| | | byte[] preByte = new byte[remain]; |
| | | in.get(preByte) ; |
| | | //in.position(0) ;//éè¯¯ç¨æ³ï¼å¦æåçç²å
æ°æ®ï¼å°ä¼æ»å¾ªç¯ |
| | | in.position(oldPosition) ; |
| | | |
| | | return this.doForData(preByte, minDataLength, maxDataLength) ; |
| | | } |
| | | |
| | | /** |
| | | * åæä¸çº¿å(ç½ç»è¿æ¥åé第ä¸å
æ°æ®)æ¯å¦å¯è·å¾ |
| | | * @param in IoBuffer |
| | | * @param remain å©ä½ |
| | | * @param minDataLength æå°æ°æ®é¿åº¦ |
| | | * @param maxDataLength æå¤§æ°æ®é¿åº¦ |
| | | * @return PrefixedDataAvailableStatus |
| | | * @throws Exception å¼å¸¸ |
| | | */ |
| | | @Override |
| | | public PrefixedDataAvailableStatus forUpData(IoBuffer in, |
| | | int remain, |
| | | int minDataLength, |
| | | int maxDataLength) throws Exception { |
| | | int oldPosition = in.position() ; |
| | | byte[] preByte = new byte[remain]; |
| | | in.get(preByte) ; |
| | | //in.position(0) ;//éè¯¯ç¨æ³ï¼å¦æåçç²å
æ°æ®ï¼å°ä¼æ»å¾ªç¯ |
| | | in.position(oldPosition) ; |
| | | |
| | | return this.doForData(preByte, minDataLength, maxDataLength) ; |
| | | |
| | | } |
| | | /** |
| | | * è¿è¡å¤æ |
| | | * @param preByte byte[] |
| | | * @param minDataLength æå°æ°æ®é¿åº¦ |
| | | * @param maxDataLength æå¤§æ°æ®é¿åº¦ |
| | | * @return PrefixedDataAvailableStatus |
| | | * @throws Exception å¼å¸¸ |
| | | */ |
| | | private PrefixedDataAvailableStatus doForData(byte[] preByte, int minDataLength, int maxDataLength) throws Exception{ |
| | | int remain = preByte.length ; |
| | | |
| | | if (remain < minDataLength) { |
| | | log.warn("åºäºåè®®ï¼" + protocolName + "ï¼å¤ææ°æ®å¤´é¨åçæå
ç°è±¡ã") ; |
| | | return new PrefixedDataAvailableStatus().breaked() ; |
| | | } |
| | | |
| | | if(remain >= maxDataLength){ |
| | | //è¶
åºäºæå¤§é¿åº¦éå¶,ä¾å¦ï¼æ°æ®å¤´é¨æ¯æ£ç¡®çï¼ä½åæ³æ°æ®ç»å°¾æ»ä¸åºç°ï¼è®¤ä¸ºæ¤æ°æ®å徿°æ® |
| | | return new PrefixedDataAvailableStatus().rubbish(remain) ; |
| | | } |
| | | |
| | | |
| | | CommonV1_0_1 parseCommon = new CommonV1_0_1(); |
| | | boolean isThisProtocolData = parseCommon.isThisProtocolHead(preByte) ; |
| | | |
| | | if(!isThisProtocolData){ |
| | | //䏿¯æ¬åè®®æ°æ® |
| | | return null ; |
| | | } |
| | | |
| | | Integer dataLen = parseCommon.parseFrameLen(preByte) ; |
| | | |
| | | if(dataLen == null){ |
| | | String headHex = ByteUtil.bytes2Hex(preByte, true) ; |
| | | throw new BufferDataException("æ¶å°æ°æ®ä¹å¸§åé¨ï¼" + headHex + "ï¼ä½ä¸¥éé误ï¼å¨è¿è¡æå
ä¸ç²å
æ£æ¥æ¶ï¼æªè½å¾å°æ°æ®å¸§çé¿åº¦ã"); |
| | | } |
| | | |
| | | if (dataLen <= 0 || dataLen > maxDataLength) { |
| | | String headHex = ByteUtil.bytes2Hex(preByte, true) ; |
| | | throw new BufferDataException("æ¶å°æ°æ®ä¹å¸§åé¨ï¼" + headHex + "ï¼ä½ä¸¥éé误ï¼å¨è¿è¡æå
ä¸ç²å
æ£æ¥æ¶ï¼æ°æ®å¸§çé¿åº¦(" + dataLen + ")è¶
åºåæ³èå´ã"); |
| | | } |
| | | |
| | | if(remain == dataLen){ |
| | | //䏿ä¸ç² |
| | | return new PrefixedDataAvailableStatus().completed(dataLen) ; |
| | | }else if(remain > dataLen){ |
| | | String headHex = ByteUtil.bytes2Hex(preByte, true) ; |
| | | log.warn("æ¶å°æ°æ®ä¹å¸§åé¨ï¼" + headHex + "ï¼ä½åçç²å
ç°è±¡ã") ; |
| | | return new PrefixedDataAvailableStatus().adjoined(dataLen) ; |
| | | }else{ |
| | | // remain < dataLen |
| | | String headHex = ByteUtil.bytes2Hex(preByte, true) ; |
| | | log.warn("æ¶å°æ°æ®ä¹å¸§åé¨ï¼" + headHex + "ï¼ä½åçæå
ç°è±¡ã") ; |
| | | return new PrefixedDataAvailableStatus().breaked() ; |
| | | } |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.dy.common.mw.protocol.p206V1_0_0; |
| | | |
| | | public class ProtocolConstantV206V1_0_0 { |
| | | |
| | | public static final String version = "1.0.1" ; |
| | | public static final Byte versionByte = 101 ; |
| | | |
| | | /** |
| | | * 注解ç¸å
³ |
| | | */ |
| | | public static final String protocolName = "p206V1_0_1" ; |
| | | public static final int priority = 1 ;//ä¼å
级 |
| | | /** |
| | | * RTUä¸çº¿æ°æ®ï¼ä¸çº¿å第ä¸å
æ°æ®ï¼æå°é¿åº¦ï¼è®¾ç½®è¯¥å±æ§ä»¥å¤è¿è¡å®æ´æ§æ£æ¥ï¼ |
| | | * 峿å
æ£æ¥ï¼ä½¿å°½å¯è½æ¶å
¨ä¸çº¿æ°æ®ï¼åå¼èå´1-100ï¼ |
| | | */ |
| | | public static final int onLineDataMinLength = 13 ;//éç¨å¿è·³ä¸è¡æ°æ®é¿åº¦ |
| | | |
| | | /** |
| | | * RTU䏿¥æ°æ®ç头鍿å°é¿åº¦ï¼ä¸æ¥æ°æ®ä¸ï¼åè¿ä¸ªæå°é¿åº¦çé¨åæ°æ®ä¸ï¼ |
| | | * è¦ä¸å®å
嫿°æ®å¸§é¿åº¦ï¼ä»¥å¤ååºæ°æ®å¸§é¿åº¦æ¥ï¼è¿è¡å®æ´æ§æ£æ¥ï¼ |
| | | * 峿å
ä¸ç²å
æ£æ¥(åå¼èå´0-100ï¼å
¶ä¸åå¼ä¸º0æ¶ï¼è¡¨ç¤ºheadMinLengthæ°æ®æ ä½ç¨ï¼ç±åè®®å®ç°æ¥æ§å¶) |
| | | */ |
| | | public static final int headMinLength = 3 ; |
| | | |
| | | |
| | | //å¸§èµ·å§ |
| | | public static final byte P_Head_Byte = (byte)0x68 ; |
| | | public static final byte P_Tail_Byte = (byte)0x16 ; |
| | | |
| | | public static final byte P_Default_mode = (byte)0x0F ;//é»è®¤å·¥ä½æ¨¡å¼ |
| | | |
| | | public static final String P_Head_Hex = "68" ; |
| | | public static final String P_Tail_Hex = "16" ; |
| | | |
| | | public static final byte lenHead2ctrl = 3 ; //ä»å¤´å°æ§å¶åï¼ä¸å
æ¬ï¼åèæ°ç»é¿åº¦ |
| | | public static final byte lenHead2Code = 10 ; //ä»å¤´å°åè½ç ï¼å
æ¬ï¼åèæ°ç»é¿åº¦ |
| | | public static final byte lenTail = 2 ; //帧尾é¨åèæ°ç»é¿åº¦ |
| | | /** |
| | | * æå¨åèæ°ç»çä½ç½®ï¼ä¸æ ï¼ |
| | | */ |
| | | public static final int dataLenIndex = 1 ;//帧é¿åº¦æå¨ åèæ°ç»èµ·å§ä¸æ |
| | | public static final int ctrlIndex = 3 ;//æ§å¶åæå¨ åèæ°ç»èµ·å§ä¸æ |
| | | public static final int rtuAddr1Index_start = 4 ;//æ§å¶å¨å°å åèæ°ç»å¼å§ä¸æ |
| | | public static final int rtuAddr1Index_end = 6 ;//æ§å¶å¨å°å åèæ°ç»å¼å§ä¸æ |
| | | public static final int rtuAddr2Index_start = 7 ;//æ§å¶å¨å°å åèæ°ç»æªæ¢ä¸æ |
| | | public static final int rtuAddr2Index_end = 8 ;//æ§å¶å¨å°å åèæ°ç»æªæ¢ä¸æ |
| | | public static final int codeIndex = 9 ;//åè½ç åèæ°ç»ä¸æ |
| | | public static final int dataIndex = 10 ;//å
·ä½æ°æ®åèæ°ç»ä¸æ |
| | | |
| | | |
| | | |
| | | } |
New file |
| | |
| | | package com.dy.common.mw.protocol.p206V1_0_0.parse; |
| | | |
| | | import com.dy.common.mw.protocol.*; |
| | | import com.dy.common.mw.protocol.p206V1_0_0.*; |
| | | import com.dy.common.mw.protocol.p206V1_0_0.parse.global.GlCreate; |
| | | import com.dy.common.util.ByteUtil; |
| | | |
| | | @AnnotationCodeDown(ifAny={ |
| | | CodeV1_0_1.cd_02 |
| | | }) |
| | | public class Cd_02_Down implements CodeParse { |
| | | |
| | | //private static Logger log = LogManager.getLogger(Cd_02_Down.class); |
| | | |
| | | @Override |
| | | public MidResult[] parse(Boolean isLowPower, CodeParseParams params, CodeParseCallback callback) throws Exception { |
| | | ParseParamsForDownV1_0_1 para = (ParseParamsForDownV1_0_1) params ; |
| | | byte[] bs = this.doParse(para) ; |
| | | |
| | | MidResultToRtu midRs = new MidResultToRtu() ; |
| | | midRs.protocolName = para.protocolName ;//åè®®åç§° |
| | | midRs.rtuAddr = para.rtuAddr ;//Rtuå°åï¼çµä¿¡å¹³å°è®¾å¤IMEIï¼ |
| | | midRs.commandId = para.commandId ;//å½ä»¤IDï¼åèµ·å½ä»¤ç客æ·ç«¯(web端)çæï¼ä»¥å¹é
å½ä»¤ç»æ |
| | | midRs.downCode = para.commandCode ;//ä¸è¡å½ä»¤åè½ç ; |
| | | midRs.downBuffer = bs ;//ä¸è¡å½ä»¤æ°æ® |
| | | midRs.downBufHex = ByteUtil.bytes2Hex(bs, true) ;//ä¸è¡å½ä»¤æ°æ®åå
è¿å¶å½¢å¼ |
| | | midRs.hasResponse = false ;//æ¯å¦æåºç |
| | | midRs.maxSendTimes = 1 ;//å½ä»¤æå¤§å鿬¡æ°(彿¶ä¸å°åºçæ¶ï¼å°éå)ï¼å¦æä¸è®¾ç½®ï¼å½ä»¤ç¼åå¨è¿è¡è¡¥å
设置 |
| | | midRs.isCachForOffLine = false ;//RTUä¸å¨çº¿ï¼å½ä»¤æ¯å¦ç¼åï¼ä½åèæ¶ä¸ºtrue |
| | | |
| | | midRs.isSendFirst = true ;//å½ä»¤åºçï¼é¦å
åéï¼é²æ¢RTU鿰䏿¥ |
| | | if(isLowPower != null && isLowPower.booleanValue()){ |
| | | //ä½åèæ¶ï¼å°½å¿«åé |
| | | midRs.isQuickSend = true ; |
| | | } |
| | | |
| | | return new MidResult[]{midRs} ; |
| | | } |
| | | /** |
| | | * æé ä¸è¡æ°æ® |
| | | * @param para åæ° |
| | | * @return åèæ°ç» |
| | | * @throws Exception å¼å¸¸ |
| | | */ |
| | | public byte[] doParse(ParseParamsForDownV1_0_1 para) throws Exception { |
| | | CommonV1_0_1 commonV1_0_1 = new CommonV1_0_1() ; |
| | | byte[] bytes ; |
| | | byte[] bsHead = new byte[ProtocolConstantV206V1_0_0.lenHead2Code] ; |
| | | byte index = 0 ; |
| | | bsHead[index] = ProtocolConstantV206V1_0_0.P_Head_Byte ; |
| | | |
| | | index++ ; |
| | | bsHead[index] = 0 ;//帧é¿åº¦ |
| | | |
| | | index++ ; |
| | | bsHead[index] = ProtocolConstantV206V1_0_0.P_Head_Byte ; |
| | | |
| | | index++ ; |
| | | bsHead[index] = commonV1_0_1.createCtrl((byte)0, (byte)0) ; |
| | | |
| | | index++ ; |
| | | GlCreate.createRtuAddr(para.rtuAddr, bsHead, index); |
| | | index += 5 ; |
| | | |
| | | ByteUtil.hex2Bytes(para.commandCode, bsHead, index) ; |
| | | |
| | | byte[] bs = new byte[7] ; |
| | | bs[0] = (byte)0xF2 ;//æ°æ®åï¼ 1 个åèï¼F0 ç»å½ï¼ F1 éåºç»å½ï¼F2 å¨çº¿ä¿æã |
| | | GlCreate.createTp(bs, 1); |
| | | |
| | | bytes = ByteUtil.bytesMerge(bsHead, bs) ; |
| | | |
| | | GlCreate.createLen(bytes);//é¿åº¦æ¾åèæ°ç»ä¸ |
| | | |
| | | byte[] bsTail = GlCreate.createCrcTail(bytes) ;//CRCåå°¾å å åèæ°ç»ä¸ |
| | | |
| | | bytes = ByteUtil.bytesMerge(bytes, bsTail) ; |
| | | |
| | | return bytes ; |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.dy.common.mw.protocol.p206V1_0_0.parse; |
| | | |
| | | import com.dy.common.mw.protocol.*; |
| | | import com.dy.common.mw.protocol.p206V1_0_0.CodeV1_0_1; |
| | | import com.dy.common.mw.protocol.p206V1_0_0.CommonV1_0_1; |
| | | import com.dy.common.mw.protocol.p206V1_0_0.ParseParamsForDownV1_0_1; |
| | | import com.dy.common.mw.protocol.p206V1_0_0.ProtocolConstantV206V1_0_0; |
| | | import com.dy.common.mw.protocol.p206V1_0_0.parse.global.GlCreate; |
| | | import com.dy.common.util.ByteUtil; |
| | | |
| | | @AnnotationCodeDown(ifAny={ |
| | | CodeV1_0_1.cd_71 |
| | | }) |
| | | public class Cd_71_Down implements CodeParse { |
| | | |
| | | //private static Logger log = LogManager.getLogger(Cd_71_Down.class); |
| | | |
| | | @Override |
| | | public MidResult[] parse(Boolean isLowPower, CodeParseParams params, CodeParseCallback callback) throws Exception { |
| | | ParseParamsForDownV1_0_1 para = (ParseParamsForDownV1_0_1) params ; |
| | | byte[] bs = this.doParse(para) ; |
| | | |
| | | MidResultToRtu midRs = new MidResultToRtu() ; |
| | | midRs.protocolName = para.protocolName ;//åè®®åç§° |
| | | midRs.rtuAddr = para.rtuAddr ;//Rtuå°åï¼çµä¿¡å¹³å°è®¾å¤IMEIï¼ |
| | | midRs.commandId = para.commandId ;//å½ä»¤IDï¼åèµ·å½ä»¤ç客æ·ç«¯(web端)çæï¼ä»¥å¹é
å½ä»¤ç»æ |
| | | midRs.downCode = para.commandCode ;//ä¸è¡å½ä»¤åè½ç ; |
| | | midRs.downBuffer = bs ;//ä¸è¡å½ä»¤æ°æ® |
| | | midRs.downBufHex = ByteUtil.bytes2Hex(bs, true) ;//ä¸è¡å½ä»¤æ°æ®åå
è¿å¶å½¢å¼ |
| | | midRs.hasResponse = true ;//æ¯å¦æåºç |
| | | midRs.maxSendTimes = null ;//å½ä»¤æå¤§å鿬¡æ°(彿¶ä¸å°åºçæ¶ï¼å°éå)ï¼å¦æä¸è®¾ç½®ï¼å½ä»¤ç¼åå¨è¿è¡è¡¥å
设置 |
| | | midRs.isCachForOffLine = false ;//RTUä¸å¨çº¿ï¼å½ä»¤æ¯å¦ç¼åï¼ä½åèæ¶ä¸ºtrue |
| | | |
| | | if(isLowPower != null && isLowPower.booleanValue()){ |
| | | //ä½åèæ¶ï¼å°½å¿«åé |
| | | midRs.isQuickSend = true ; |
| | | } |
| | | |
| | | return new MidResult[]{midRs} ; |
| | | } |
| | | |
| | | /** |
| | | * æé ä¸è¡æ°æ® |
| | | * @param para åæ° |
| | | * @return åèæ°ç» |
| | | * @throws Exception å¼å¸¸ |
| | | */ |
| | | public byte[] doParse(ParseParamsForDownV1_0_1 para) throws Exception { |
| | | CommonV1_0_1 commonV1_0_1 = new CommonV1_0_1() ; |
| | | byte[] bytes ; |
| | | byte[] bsHead = new byte[ProtocolConstantV206V1_0_0.lenHead2Code] ; |
| | | byte index = 0 ; |
| | | bsHead[index] = ProtocolConstantV206V1_0_0.P_Head_Byte ; |
| | | |
| | | index++ ; |
| | | bsHead[index] = 0 ;//帧é¿åº¦ |
| | | |
| | | index++ ; |
| | | bsHead[index] = ProtocolConstantV206V1_0_0.P_Head_Byte ; |
| | | |
| | | index++ ; |
| | | bsHead[index] = commonV1_0_1.createCtrl((byte)0, (byte)0) ; |
| | | |
| | | index++ ; |
| | | GlCreate.createRtuAddr(para.rtuAddr, bsHead, index); |
| | | index += 5 ; |
| | | |
| | | ByteUtil.hex2Bytes(para.commandCode, bsHead, index) ; |
| | | |
| | | byte[] bs = new byte[0] ; |
| | | //ç¡®è®¤å¸§çæ°æ®åç¨äºé¥æµç»ç«¯å·¥ä½æ¨¡å¼ç确认æè½¬æ¢ãæ°æ®ä¸º 1 个åè HEXï¼00H æ¶é¥æµç» |
| | | //端å¨å
¼å®¹å·¥ä½ç¶æï¼ 01H æ¶é¥æµç»ç«¯å¨èªæ¥å·¥ä½ç¶æï¼ 02H æ¶é¥æµç»ç«¯å¨æ¥è¯¢/åºçå·¥ä½ |
| | | //ç¶æï¼ 03H æ¶é¥æµç»ç«¯å¨è°è¯/ç»´ä¿®ç¶æã |
| | | bs[0] = (byte)0xF1;//æ°æ®å |
| | | |
| | | bytes = ByteUtil.bytesMerge(bsHead, bs) ; |
| | | |
| | | GlCreate.createLen(bytes);//é¿åº¦æ¾åèæ°ç»ä¸ |
| | | |
| | | byte[] bsTail = GlCreate.createCrcTail(bytes) ;//CRCåå°¾å å åèæ°ç»ä¸ |
| | | |
| | | bytes = ByteUtil.bytesMerge(bytes, bsTail) ; |
| | | |
| | | return bytes ; |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.dy.common.mw.protocol.p206V1_0_0.parse; |
| | | |
| | | import com.dy.common.mw.protocol.*; |
| | | import com.dy.common.mw.protocol.p206V1_0_0.CodeV1_0_1; |
| | | import com.dy.common.mw.protocol.p206V1_0_0.CommonV1_0_1; |
| | | import com.dy.common.mw.protocol.p206V1_0_0.ParseParamsForDownV1_0_1; |
| | | import com.dy.common.mw.protocol.p206V1_0_0.ProtocolConstantV206V1_0_0; |
| | | import com.dy.common.mw.protocol.p206V1_0_0.parse.global.GlCreate; |
| | | import com.dy.common.util.ByteUtil; |
| | | |
| | | @AnnotationCodeDown(ifAny={ |
| | | CodeV1_0_1.cd_83 |
| | | }) |
| | | public class Cd_83_Down implements CodeParse { |
| | | |
| | | //private static Logger log = LogManager.getLogger(Cd_C0_Down.class); |
| | | |
| | | @Override |
| | | public MidResult[] parse(Boolean isLowPower, CodeParseParams params, CodeParseCallback callback) throws Exception { |
| | | ParseParamsForDownV1_0_1 para = (ParseParamsForDownV1_0_1) params ; |
| | | byte[] bs = this.doParse(para) ; |
| | | |
| | | MidResultToRtu midRs = new MidResultToRtu() ; |
| | | midRs.protocolName = para.protocolName ;//åè®®åç§° |
| | | midRs.rtuAddr = para.rtuAddr ;//Rtuå°åï¼çµä¿¡å¹³å°è®¾å¤IMEIï¼ |
| | | midRs.commandId = para.commandId ;//å½ä»¤IDï¼åèµ·å½ä»¤ç客æ·ç«¯(web端)çæï¼ä»¥å¹é
å½ä»¤ç»æ |
| | | midRs.downCode = para.commandCode ;//ä¸è¡å½ä»¤åè½ç ; |
| | | midRs.downBuffer = bs ;//ä¸è¡å½ä»¤æ°æ® |
| | | midRs.downBufHex = ByteUtil.bytes2Hex(bs, true) ;//ä¸è¡å½ä»¤æ°æ®åå
è¿å¶å½¢å¼ |
| | | midRs.hasResponse = false ;//æ¯å¦æåºç |
| | | midRs.maxSendTimes = 1 ;//å½ä»¤æå¤§å鿬¡æ°(彿¶ä¸å°åºçæ¶ï¼å°éå)ï¼å¦æä¸è®¾ç½®ï¼å½ä»¤ç¼åå¨è¿è¡è¡¥å
设置 |
| | | midRs.isCachForOffLine = false ;//RTUä¸å¨çº¿ï¼å½ä»¤æ¯å¦ç¼åï¼ä½åèæ¶ä¸ºtrue |
| | | |
| | | midRs.isSendFirst = true ;//å½ä»¤åºçï¼é¦å
åéï¼é²æ¢RTU鿰䏿¥ |
| | | if(isLowPower != null && isLowPower.booleanValue()){ |
| | | //ä½åèæ¶ï¼å°½å¿«åé |
| | | midRs.isQuickSend = true ; |
| | | } |
| | | |
| | | return new MidResult[]{midRs} ; |
| | | } |
| | | |
| | | /** |
| | | * æé ä¸è¡æ°æ® |
| | | * @param para åæ° |
| | | * @return åèæ°ç» |
| | | * @throws Exception å¼å¸¸ |
| | | */ |
| | | public byte[] doParse(ParseParamsForDownV1_0_1 para) throws Exception { |
| | | CommonV1_0_1 commonV1_0_1 = new CommonV1_0_1() ; |
| | | byte[] bytes ; |
| | | byte[] bsHead = new byte[ProtocolConstantV206V1_0_0.lenHead2Code] ; |
| | | byte index = 0 ; |
| | | bsHead[index] = ProtocolConstantV206V1_0_0.P_Head_Byte ; |
| | | |
| | | index++ ; |
| | | bsHead[index] = 0 ;//帧é¿åº¦ |
| | | |
| | | index++ ; |
| | | bsHead[index] = ProtocolConstantV206V1_0_0.P_Head_Byte ; |
| | | |
| | | index++ ; |
| | | bsHead[index] = commonV1_0_1.createCtrl((byte)0, (byte)0) ; |
| | | |
| | | index++ ; |
| | | GlCreate.createRtuAddr(para.rtuAddr, bsHead, index); |
| | | index += 5 ; |
| | | |
| | | ByteUtil.hex2Bytes(para.commandCode, bsHead, index) ; |
| | | |
| | | byte[] bs = new byte[7] ; |
| | | //ç¡®è®¤å¸§çæ°æ®åç¨äºé¥æµç»ç«¯å·¥ä½æ¨¡å¼ç确认æè½¬æ¢ãæ°æ®ä¸º 1 个åè HEXï¼00H æ¶é¥æµç» |
| | | //端å¨å
¼å®¹å·¥ä½ç¶æï¼ 01H æ¶é¥æµç»ç«¯å¨èªæ¥å·¥ä½ç¶æï¼ 02H æ¶é¥æµç»ç«¯å¨æ¥è¯¢/åºçå·¥ä½ |
| | | //ç¶æï¼ 03H æ¶é¥æµç»ç«¯å¨è°è¯/ç»´ä¿®ç¶æã |
| | | bs[0] = ProtocolConstantV206V1_0_0.P_Default_mode;//æ°æ®å |
| | | GlCreate.createTp(bs, 1); |
| | | |
| | | bytes = ByteUtil.bytesMerge(bsHead, bs) ; |
| | | |
| | | GlCreate.createLen(bytes);//é¿åº¦æ¾åèæ°ç»ä¸ |
| | | |
| | | byte[] bsTail = GlCreate.createCrcTail(bytes) ;//CRCåå°¾å å åèæ°ç»ä¸ |
| | | |
| | | bytes = ByteUtil.bytesMerge(bytes, bsTail) ; |
| | | |
| | | return bytes ; |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.dy.common.mw.protocol.p206V1_0_0.parse; |
| | | |
| | | import com.dy.common.mw.protocol.*; |
| | | import com.dy.common.mw.protocol.p206V1_0_0.CodeV1_0_1; |
| | | import com.dy.common.mw.protocol.p206V1_0_0.CommonV1_0_1; |
| | | import com.dy.common.mw.protocol.p206V1_0_0.ParseParamsForDownV1_0_1; |
| | | import com.dy.common.mw.protocol.p206V1_0_0.ProtocolConstantV206V1_0_0; |
| | | import com.dy.common.mw.protocol.p206V1_0_0.parse.global.GlCreate; |
| | | import com.dy.common.util.ByteUtil; |
| | | |
| | | @AnnotationCodeDown(ifAny={ |
| | | CodeV1_0_1.cd_84 |
| | | }) |
| | | public class Cd_84_Down implements CodeParse { |
| | | |
| | | //private static Logger log = LogManager.getLogger(Cd_C0_Down.class); |
| | | |
| | | @Override |
| | | public MidResult[] parse(Boolean isLowPower, CodeParseParams params, CodeParseCallback callback) throws Exception { |
| | | ParseParamsForDownV1_0_1 para = (ParseParamsForDownV1_0_1) params ; |
| | | byte[] bs = this.doParse(para) ; |
| | | |
| | | MidResultToRtu midRs = new MidResultToRtu() ; |
| | | midRs.protocolName = para.protocolName ;//åè®®åç§° |
| | | midRs.rtuAddr = para.rtuAddr ;//Rtuå°åï¼çµä¿¡å¹³å°è®¾å¤IMEIï¼ |
| | | midRs.commandId = para.commandId ;//å½ä»¤IDï¼åèµ·å½ä»¤ç客æ·ç«¯(web端)çæï¼ä»¥å¹é
å½ä»¤ç»æ |
| | | midRs.downCode = para.commandCode ;//ä¸è¡å½ä»¤åè½ç ; |
| | | midRs.downBuffer = bs ;//ä¸è¡å½ä»¤æ°æ® |
| | | midRs.downBufHex = ByteUtil.bytes2Hex(bs, true) ;//ä¸è¡å½ä»¤æ°æ®åå
è¿å¶å½¢å¼ |
| | | midRs.hasResponse = false ;//æ¯å¦æåºç |
| | | midRs.maxSendTimes = 1 ;//å½ä»¤æå¤§å鿬¡æ°(彿¶ä¸å°åºçæ¶ï¼å°éå)ï¼å¦æä¸è®¾ç½®ï¼å½ä»¤ç¼åå¨è¿è¡è¡¥å
设置 |
| | | midRs.isCachForOffLine = false ;//RTUä¸å¨çº¿ï¼å½ä»¤æ¯å¦ç¼åï¼ä½åèæ¶ä¸ºtrue |
| | | |
| | | midRs.isSendFirst = true ;//å½ä»¤åºçï¼é¦å
åéï¼é²æ¢RTU鿰䏿¥ |
| | | if(isLowPower != null && isLowPower.booleanValue()){ |
| | | //ä½åèæ¶ï¼å°½å¿«åé |
| | | midRs.isQuickSend = true ; |
| | | } |
| | | |
| | | return new MidResult[]{midRs} ; |
| | | } |
| | | |
| | | /** |
| | | * æé ä¸è¡æ°æ® |
| | | * @param para åæ° |
| | | * @return åèæ°ç» |
| | | * @throws Exception å¼å¸¸ |
| | | */ |
| | | public byte[] doParse(ParseParamsForDownV1_0_1 para) throws Exception { |
| | | CommonV1_0_1 commonV1_0_1 = new CommonV1_0_1() ; |
| | | byte[] bytes ; |
| | | byte[] bsHead = new byte[ProtocolConstantV206V1_0_0.lenHead2Code] ; |
| | | byte index = 0 ; |
| | | bsHead[index] = ProtocolConstantV206V1_0_0.P_Head_Byte ; |
| | | |
| | | index++ ; |
| | | bsHead[index] = 0 ;//帧é¿åº¦ |
| | | |
| | | index++ ; |
| | | bsHead[index] = ProtocolConstantV206V1_0_0.P_Head_Byte ; |
| | | |
| | | index++ ; |
| | | bsHead[index] = commonV1_0_1.createCtrl((byte)0, (byte)0) ; |
| | | |
| | | index++ ; |
| | | GlCreate.createRtuAddr(para.rtuAddr, bsHead, index); |
| | | index += 5 ; |
| | | |
| | | ByteUtil.hex2Bytes(para.commandCode, bsHead, index) ; |
| | | |
| | | byte[] bs = new byte[7] ; |
| | | //ç¡®è®¤å¸§çæ°æ®åç¨äºé¥æµç»ç«¯å·¥ä½æ¨¡å¼ç确认æè½¬æ¢ãæ°æ®ä¸º 1 个åè HEXï¼00H æ¶é¥æµç» |
| | | //端å¨å
¼å®¹å·¥ä½ç¶æï¼ 01H æ¶é¥æµç»ç«¯å¨èªæ¥å·¥ä½ç¶æï¼ 02H æ¶é¥æµç»ç«¯å¨æ¥è¯¢/åºçå·¥ä½ |
| | | //ç¶æï¼ 03H æ¶é¥æµç»ç«¯å¨è°è¯/ç»´ä¿®ç¶æã |
| | | bs[0] = ProtocolConstantV206V1_0_0.P_Default_mode;//æ°æ®å |
| | | GlCreate.createTp(bs, 1); |
| | | |
| | | bytes = ByteUtil.bytesMerge(bsHead, bs) ; |
| | | |
| | | GlCreate.createLen(bytes);//é¿åº¦æ¾åèæ°ç»ä¸ |
| | | |
| | | byte[] bsTail = GlCreate.createCrcTail(bytes) ;//CRCåå°¾å å åèæ°ç»ä¸ |
| | | |
| | | bytes = ByteUtil.bytesMerge(bytes, bsTail) ; |
| | | |
| | | return bytes ; |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.dy.common.mw.protocol.p206V1_0_0.parse; |
| | | |
| | | import com.dy.common.mw.protocol.*; |
| | | import com.dy.common.mw.protocol.p206V1_0_0.CodeV1_0_1; |
| | | import com.dy.common.mw.protocol.p206V1_0_0.CommonV1_0_1; |
| | | import com.dy.common.mw.protocol.p206V1_0_0.ParseParamsForDownV1_0_1; |
| | | import com.dy.common.mw.protocol.p206V1_0_0.ProtocolConstantV206V1_0_0; |
| | | import com.dy.common.mw.protocol.p206V1_0_0.parse.global.GlCreate; |
| | | import com.dy.common.util.ByteUtil; |
| | | |
| | | @AnnotationCodeDown(ifAny={ |
| | | CodeV1_0_1.cd_C0 |
| | | }) |
| | | public class Cd_C0_Down implements CodeParse { |
| | | |
| | | //private static Logger log = LogManager.getLogger(Cd_C0_Down.class); |
| | | |
| | | @Override |
| | | public MidResult[] parse(Boolean isLowPower, CodeParseParams params, CodeParseCallback callback) throws Exception { |
| | | ParseParamsForDownV1_0_1 para = (ParseParamsForDownV1_0_1) params ; |
| | | byte[] bs = this.doParse(para) ; |
| | | |
| | | MidResultToRtu midRs = new MidResultToRtu() ; |
| | | midRs.protocolName = para.protocolName ;//åè®®åç§° |
| | | midRs.rtuAddr = para.rtuAddr ;//Rtuå°åï¼çµä¿¡å¹³å°è®¾å¤IMEIï¼ |
| | | midRs.commandId = para.commandId ;//å½ä»¤IDï¼åèµ·å½ä»¤ç客æ·ç«¯(web端)çæï¼ä»¥å¹é
å½ä»¤ç»æ |
| | | midRs.downCode = para.commandCode ;//ä¸è¡å½ä»¤åè½ç ; |
| | | midRs.downBuffer = bs ;//ä¸è¡å½ä»¤æ°æ® |
| | | midRs.downBufHex = ByteUtil.bytes2Hex(bs, true) ;//ä¸è¡å½ä»¤æ°æ®åå
è¿å¶å½¢å¼ |
| | | midRs.hasResponse = false ;//æ¯å¦æåºç |
| | | midRs.maxSendTimes = 1 ;//å½ä»¤æå¤§å鿬¡æ°(彿¶ä¸å°åºçæ¶ï¼å°éå)ï¼å¦æä¸è®¾ç½®ï¼å½ä»¤ç¼åå¨è¿è¡è¡¥å
设置 |
| | | midRs.isCachForOffLine = false ;//RTUä¸å¨çº¿ï¼å½ä»¤æ¯å¦ç¼åï¼ä½åèæ¶ä¸ºtrue |
| | | |
| | | midRs.isSendFirst = true ;//å½ä»¤åºçï¼é¦å
åéï¼é²æ¢RTU鿰䏿¥ |
| | | if(isLowPower != null && isLowPower.booleanValue()){ |
| | | //ä½åèæ¶ï¼å°½å¿«åé |
| | | midRs.isQuickSend = true ; |
| | | } |
| | | |
| | | return new MidResult[]{midRs} ; |
| | | } |
| | | |
| | | /** |
| | | * æé ä¸è¡æ°æ® |
| | | * @param para åæ° |
| | | * @return åèæ°ç» |
| | | * @throws Exception å¼å¸¸ |
| | | */ |
| | | public byte[] doParse(ParseParamsForDownV1_0_1 para) throws Exception { |
| | | CommonV1_0_1 commonV1_0_1 = new CommonV1_0_1() ; |
| | | byte[] bytes ; |
| | | byte[] bsHead = new byte[ProtocolConstantV206V1_0_0.lenHead2Code] ; |
| | | byte index = 0 ; |
| | | bsHead[index] = ProtocolConstantV206V1_0_0.P_Head_Byte ; |
| | | |
| | | index++ ; |
| | | bsHead[index] = 0 ;//帧é¿åº¦ |
| | | |
| | | index++ ; |
| | | bsHead[index] = ProtocolConstantV206V1_0_0.P_Head_Byte ; |
| | | |
| | | index++ ; |
| | | bsHead[index] = commonV1_0_1.createCtrl((byte)0, (byte)0) ; |
| | | |
| | | index++ ; |
| | | GlCreate.createRtuAddr(para.rtuAddr, bsHead, index); |
| | | index += 5 ; |
| | | |
| | | ByteUtil.hex2Bytes(para.commandCode, bsHead, index) ; |
| | | |
| | | byte[] bs = new byte[7] ; |
| | | //ç¡®è®¤å¸§çæ°æ®åç¨äºé¥æµç»ç«¯å·¥ä½æ¨¡å¼ç确认æè½¬æ¢ãæ°æ®ä¸º 1 个åè HEXï¼00H æ¶é¥æµç» |
| | | //端å¨å
¼å®¹å·¥ä½ç¶æï¼ 01H æ¶é¥æµç»ç«¯å¨èªæ¥å·¥ä½ç¶æï¼ 02H æ¶é¥æµç»ç«¯å¨æ¥è¯¢/åºçå·¥ä½ |
| | | //ç¶æï¼ 03H æ¶é¥æµç»ç«¯å¨è°è¯/ç»´ä¿®ç¶æã |
| | | bs[0] = ProtocolConstantV206V1_0_0.P_Default_mode;//æ°æ®å |
| | | GlCreate.createTp(bs, 1); |
| | | |
| | | bytes = ByteUtil.bytesMerge(bsHead, bs) ; |
| | | |
| | | GlCreate.createLen(bytes);//é¿åº¦æ¾åèæ°ç»ä¸ |
| | | |
| | | byte[] bsTail = GlCreate.createCrcTail(bytes) ;//CRCåå°¾å å åèæ°ç»ä¸ |
| | | |
| | | bytes = ByteUtil.bytesMerge(bytes, bsTail) ; |
| | | |
| | | return bytes ; |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.dy.common.mw.protocol.p206V1_0_0.parse.global; |
| | | |
| | | import com.dy.common.mw.protocol.p206V1_0_0.ProtocolConstantV206V1_0_0; |
| | | import com.dy.common.util.ByteUtil; |
| | | import com.dy.common.util.ByteUtilUnsigned; |
| | | import com.dy.common.util.CRC8_for_2_0; |
| | | import com.dy.common.util.DateTime; |
| | | |
| | | public class GlCreate { |
| | | |
| | | public static void createRtuAddr(String rtuAddr, byte[] bs, int index) throws Exception { |
| | | String rtuAddr1 = rtuAddr.substring(0, 6) ; |
| | | String rtuAddr2 = rtuAddr.substring(6) ; |
| | | |
| | | ByteUtil.string2BCD_BE(bs, rtuAddr1, index) ; |
| | | index += 3 ; |
| | | |
| | | Integer rtuAddr2Int = Integer.parseInt(rtuAddr2) ; |
| | | ByteUtilUnsigned.short2Bytes_BE(bs, rtuAddr2Int.shortValue(), index); |
| | | } |
| | | |
| | | public static void createTp(byte[] bs, int index) throws Exception { |
| | | ByteUtil.string2BCD_LE(bs, DateTime.yyMMddhhmmss(), index) ; |
| | | } |
| | | |
| | | public static void createLen(byte[] bsNoTail) throws Exception { |
| | | int len = bsNoTail.length - ProtocolConstantV206V1_0_0.lenHead2ctrl; |
| | | bsNoTail[ProtocolConstantV206V1_0_0.dataLenIndex] = (byte)len ; |
| | | } |
| | | |
| | | public static byte[] createCrcTail(byte[] bsNoTail) throws Exception { |
| | | int crc = new CRC8_for_2_0().CRC8(bsNoTail, ProtocolConstantV206V1_0_0.ctrlIndex, bsNoTail.length -1) ; |
| | | byte[] bytes = new byte[ProtocolConstantV206V1_0_0.lenTail] ; |
| | | bytes[0] = (byte)crc ; |
| | | bytes[1] = ProtocolConstantV206V1_0_0.P_Tail_Byte ; |
| | | return bytes ; |
| | | } |
| | | } |
New file |
| | |
| | | package com.dy.common.mw.protocol.p206V1_0_0.parse.global; |
| | | |
| | | import com.dy.common.mw.protocol.p206V1_0_0.DataAlarmVo; |
| | | import com.dy.common.mw.protocol.p206V1_0_0.DataStateVo; |
| | | import com.dy.common.util.ByteUtil; |
| | | import org.apache.logging.log4j.LogManager; |
| | | import org.apache.logging.log4j.Logger; |
| | | |
| | | public class GlParse { |
| | | |
| | | private static final Logger log = LogManager.getLogger(GlParse.class); |
| | | |
| | | public static DataAlarmVo parseAlarm(byte[] bs, short index){ |
| | | DataAlarmVo avo = new DataAlarmVo() ; |
| | | byte b = bs[index] ; |
| | | index++ ; |
| | | avo.batteryVolt = (byte)(b & 0x2) ; |
| | | avo.loss = (byte)(b & 0x8) ; |
| | | avo.meter = (byte)(b & 0x20) ; |
| | | |
| | | b = bs[index] ; |
| | | avo.valve = (byte)(b & 0x20) ; |
| | | return avo ; |
| | | } |
| | | |
| | | public static DataStateVo parseState(byte[] bs, short index){ |
| | | DataStateVo avo = new DataStateVo() ; |
| | | byte b = bs[index] ; |
| | | index++ ; |
| | | avo.idCard = (byte)(b & 0x4) ; |
| | | avo.work = (byte)(b & 0x8) ; |
| | | avo.valve = (byte)(b & 0x20) ; |
| | | return avo ; |
| | | } |
| | | |
| | | public static String parseTp(byte[] bs, short index){ |
| | | String dt = "" ; |
| | | try{ |
| | | dt = dt + ByteUtil.BCD2String_BE(bs, index, index) ;//ç§ |
| | | index++ ; |
| | | dt = ByteUtil.BCD2String_BE(bs, index, index) + ":" + dt ;//å |
| | | index++ ; |
| | | dt = ByteUtil.BCD2String_BE(bs, index, index) + ":" + dt ;//æ¶ |
| | | index++ ; |
| | | dt = ByteUtil.BCD2String_BE(bs, index, index) + " " + dt ;//æ¥ |
| | | index++ ; |
| | | bs[index] = (byte)(bs[index] & 0x10); |
| | | dt = ByteUtil.BCD2String_BE(bs, index, index) + "-" + dt ;//æ |
| | | index++ ; |
| | | dt = "20" + ByteUtil.BCD2String_BE(bs, index, index) + "-" + dt ;//å¹´ |
| | | }catch (Exception e){ |
| | | log.error("è§£ææ§å¶å¨æ¶éæ¶å¼å¸¸ï¼" + e.getMessage(), e); |
| | | } |
| | | return dt ; |
| | | } |
| | | } |
| | |
| | | public void test2(){ |
| | | System.out.println("test2"); |
| | | } |
| | | public void test3(){ |
| | | System.out.println("test31"); |
| | | System.out.println("test32"); |
| | | System.out.println("test33"); |
| | | System.out.println("test34"); |
| | | System.out.println("test33"); |
| | | } |
| | | } |
| | |
| | | <scope>test</scope> |
| | | </dependency> |
| | | </dependencies> |
| | | </project> |
| | | |
| | | <build> |
| | | <plugins> |
| | | <!-- çæä¸å
å«ä¾èµjarç坿§è¡jarå
|
| | | <plugin> |
| | | !- spring bootæä¾çmavenæå
æä»¶ - |
| | | <groupId>org.springframework.boot</groupId> |
| | | <artifactId>spring-boot-maven-plugin</artifactId> |
| | | <executions> |
| | | <execution> |
| | | !- |
| | | <goals> |
| | | <goal>repackage</goal> |
| | | </goals> |
| | | - |
| | | <configuration> |
| | | !- ä¸å çè¯æç»å
å为: ${artifactId}-${version}.jar, å äºçè¯æç»å
å: ${artifactId}-${version}-${classifier}.jar - |
| | | <classifier>execute</classifier> |
| | | !- 䏿å®çæè·¯å¾çè¯, é»è®¤ä¿åå¨ ${build.directory} ä¸ - |
| | | <outputDirectory>${project.build.directory}/execute</outputDirectory> |
| | | <finalName>${artifactId}-${version}</finalName> |
| | | <layout>ZIP</layout> |
| | | <mainClass>com.dy.pipIrrBase.PipIrrBaseApplication</mainClass> |
| | | <includes> |
| | | <include> |
| | | <groupId>com.dy</groupId> |
| | | <artifactId>pipIrr-common</artifactId> |
| | | </include> |
| | | <include> |
| | | <groupId>com.dy</groupId> |
| | | <artifactId>pipIrr-global</artifactId> |
| | | </include> |
| | | </includes> |
| | | <excludes> |
| | | <exclude> |
| | | <groupId>org.projectlombok</groupId> |
| | | <artifactId>lombok</artifactId> |
| | | </exclude> |
| | | </excludes> |
| | | </configuration> |
| | | </execution> |
| | | </executions> |
| | | |
| | | </plugin> |
| | | --> |
| | | <!-- æ·è´ä¾èµçjarå
å°libç®å½--> |
| | | <plugin> |
| | | <groupId>org.springframework.boot</groupId> |
| | | <artifactId>spring-boot-maven-plugin</artifactId> |
| | | <executions> |
| | | <execution> |
| | | <configuration> |
| | | <!-- ä¸å çè¯æç»å
å为: ${artifactId}-${version}.jar, å äºçè¯æç»å
å: ${artifactId}-${version}-${classifier}.jar |
| | | <classifier>execute</classifier> |
| | | --> |
| | | <!-- ${project.build.directory}æ¯mavenåéï¼å
ç½®çï¼è¡¨ç¤ºtargetç®å½,妿ä¸åï¼å°å¨æ ¹ç®å½ä¸å建/lib --> |
| | | <outputDirectory>${project.build.directory}/lib</outputDirectory> |
| | | <!-- excludeTransitive:æ¯å¦ä¸å
å«é´æ¥ä¾èµå
ï¼æ¯å¦æä»¬ä¾èµAï¼ä½æ¯Aåä¾èµäºBï¼æä»¬æ¯å¦ä¹è¦æBæè¿å» é»è®¤ä¸æ--> |
| | | <excludeTransitive>false</excludeTransitive> |
| | | <!-- å¤å¶çjaræä»¶å»æçæ¬ä¿¡æ¯ --> |
| | | <stripVersion>false</stripVersion> |
| | | <finalName>${project.artifactId}-${project.version}</finalName> |
| | | <layout>ZIP</layout> |
| | | <mainClass>com.dy.aceMw.PipIrrMwAcceptApplication</mainClass> |
| | | <includes> |
| | | <include> |
| | | <groupId>com.dy</groupId> |
| | | <artifactId>pipIrr-common</artifactId> |
| | | </include> |
| | | <include> |
| | | <groupId>com.dy</groupId> |
| | | <artifactId>pipIrr-global</artifactId> |
| | | </include> |
| | | </includes> |
| | | <excludes> |
| | | <exclude> |
| | | <groupId>org.projectlombok</groupId> |
| | | <artifactId>lombok</artifactId> |
| | | </exclude> |
| | | </excludes> |
| | | </configuration> |
| | | </execution> |
| | | </executions> |
| | | </plugin> |
| | | |
| | | <plugin> |
| | | <!-- 设置javaç¼è¯çæ¬ï¼è¿è¡ç¯å¢çæ¬ --> |
| | | <groupId>org.apache.maven.plugins</groupId> |
| | | <artifactId>maven-compiler-plugin</artifactId> |
| | | <!-- sourceï¼ æºä»£ç ç¼è¯çæ¬ï¼targetï¼ ç®æ å¹³å°ç¼è¯çæ¬ï¼encodingï¼ å符éç¼ç ã --> |
| | | <configuration> |
| | | <source>${java.version}</source> |
| | | <target>${java.version}</target> |
| | | <encoding>${encoding}</encoding> |
| | | </configuration> |
| | | </plugin> |
| | | <plugin> |
| | | <!-- è§£å³èµæºæä»¶çç¼ç é®é¢ --> |
| | | <groupId>org.apache.maven.plugins</groupId> |
| | | <artifactId>maven-resources-plugin</artifactId> |
| | | <configuration> |
| | | <encoding>${encoding}</encoding> |
| | | </configuration> |
| | | </plugin> |
| | | <plugin> |
| | | <!-- mavenéæ§è¡æµè¯ç¨ä¾çæä»¶ --> |
| | | <groupId>org.apache.maven.plugins</groupId> |
| | | <artifactId>maven-surefire-plugin</artifactId> |
| | | <configuration> |
| | | <skipTests>true</skipTests> |
| | | </configuration> |
| | | </plugin> |
| | | <plugin> |
| | | <!-- ä¸é¢è§£å³ï¼å½è¿è¡Maven Lifecycle packageæ¶æ¥éï¼Could not find artifact org.apache.mina:mina-core:bundle:2.2.1 in maven (https://repo1.maven.org/maven2/)--> |
| | | <groupId>org.apache.felix</groupId> |
| | | <artifactId>maven-bundle-plugin</artifactId> |
| | | <extensions>true</extensions> |
| | | </plugin> |
| | | </plugins> |
| | | </build> |
| | | </project> |
| | |
| | | @EnableAspectJAutoProxy |
| | | @EnableMultiDataSource |
| | | @ComponentScan(basePackages = {"com.dy.common", "com.dy.pipIrrGlobal", "com.dy.aceMw"}) |
| | | @MapperScan(basePackages={"com.dy.pipIrrGlobal.daoBa"}) |
| | | @MapperScan(basePackages={"com.dy.pipIrrGlobal.daoRm"}) |
| | | public class PipIrrMwAcceptApplication implements CommandLineRunner { |
| | | |
| | | public static void main(String[] args) { |
| | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | import com.dy.aceMw.server.*; |
| | | import com.dy.aceMw.server.rtuData.RtuDataUnit; |
| | | import com.dy.aceMw.server.rtuData.RtuDataUnitConfigVo; |
| | | import com.dy.aceMw.server.tasks.FromRtuConstantTask; |
| | | import com.dy.common.mw.UnitInterface; |
| | | import com.dy.common.mw.UnitStartedCallbackInterface; |
| | | import com.dy.common.mw.channel.rmi.RmiConfigVo; |
| | |
| | | import com.dy.common.mw.protocol.ProtocolUnit; |
| | | import com.dy.common.mw.support.SupportUnit; |
| | | import com.dy.common.mw.support.SupportUnitConfigVo; |
| | | import com.dy.aceMw.server.AdapterImp_CoreUnit; |
| | | import com.dy.aceMw.server.AdapterImp_ProtocolUnit; |
| | | import com.dy.aceMw.server.AdapterImp_RmiUnit; |
| | | import com.dy.aceMw.server.AdapterImp_TcpUnit; |
| | | import com.dy.aceMw.server.ServerProperties; |
| | | import com.dy.aceMw.server.tasks.ToRtuConstantTask; |
| | | import com.dy.aceMw.server.AdapterImp_SupportUnit; |
| | | import com.dy.aceMw.resource.ResourceUnit; |
| | | import com.dy.aceMw.resource.ResourceUnitConfigVo; |
| | | import com.dy.aceMw.server.AdapterImp_ResourceUnit; |
| | | import com.dy.common.springUtil.SpringContextUtil; |
| | | import com.dy.common.util.ConfigXml; |
| | | import com.dy.common.util.IDLongGenerator; |
| | |
| | | //TCPä¸è¡æ°æ®æ¶å»ç¼åæ¶é¿ï¼å½è¾¾å°æ¶é¿æ¶ï¼TCPä¸è¡æ°æ®æ¶å»è¢«æ¸
空ï¼éç¨TCPä¸è¡æ°æ®æ¶å»ç®çæ¯ï¼é»æ¢ä¸æ°æ®åæ¶ä¸åæ°æ®ï¼å 为RTUå¤çä¸è¿æ¥ |
| | | ServerProperties.lastUpDataTimeLive = conf.getSetAttrPlusInt(doc, "config.base", "lastUpDataTimeLive", null, 0, 5, null) * 1000L ; |
| | | //æ°æ®åºæ°æ®idçæå¨çidåç¼ï¼0æ¯é»è®¤çåç¼ï¼ä¸è¬webç³»ç»åºç¨ï¼æ°æ®ä¸é´ä»¶idåç¼å¤§äºçäº1 |
| | | ServerProperties.dbDataIdSuffix = conf.getSetAttrInt(doc, "config.base", "dbDataIdSuffix", null, 1, 9, null); |
| | | |
| | | ServerProperties.dbDataIdSuffix = conf.getSetAttrInt(doc, "config.base", "dbDataIdSuffix", null, 0, 99, null); |
| | | //ä¸ä¸è¡æ°æ®ç¼åéåä¸ç¼åæ°æ®ä¸ªæ°çæ¥è¦éï¼è¿ä¸ªä¸ç°å®é¡¹ç®ææ¥æ°´è¡¨æ°ç¸å
³ |
| | | ServerProperties.cacheUpDownDataWarnCount = conf.getSetAttrPlusInt(doc, "config.base", "cacheUpDownDataWarnCount", null, 1, null, null) ; |
| | | //ä¸ä¸è¡æ°æ®ç¼åéåä¸ç¼åæ°æ®ä¸ªæ°çæå¤§å¼ï¼è¿ä¸ªä¸ç°å®é¡¹ç®ææ¥æ°´è¡¨æ°ç¸å
³ |
| | | ServerProperties.cacheUpDownDataMaxCount = conf.getSetAttrPlusInt(doc, "config.base", "cacheUpDownDataMaxCount", null, 1, null, null) ; |
| | | if(ServerProperties.cacheUpDownDataMaxCount <= ServerProperties.cacheUpDownDataWarnCount){ |
| | | throw new Exception("cacheUpDownDataMaxCountå¿
须大äºcacheUpDownDataWarnCount") ; |
| | | } |
| | | |
| | | //设置IDçæå¨çåç¼ |
| | | IDLongGenerator.setSuffix(ServerProperties.dbDataIdSuffix.intValue()); |
| | | |
| | |
| | | protoAdap.setConfig(protoVo); |
| | | ProtocolUnit protoUnit = ProtocolUnit.getInstance(); |
| | | protoUnit.setAdapter(protoAdap); |
| | | protoUnit.start(new UnitStartedCallbackInterface(){ |
| | | @Override |
| | | public void call(Object obj) { |
| | | } |
| | | protoUnit.start(obj -> { |
| | | }); |
| | | units.add(protoUnit) ; |
| | | |
| | |
| | | //æ¯ææ¨¡åï¼ springHibernateå çº¿ç¨æ± |
| | | SupportUnitConfigVo supVo = new SupportUnitConfigVo() ; |
| | | //ç工使¶é¿çº¿ç¨æ± ï¼çº¿ç¨è´è´£ç¨æ¶è¾ççå·¥ä½ä»»å¡ |
| | | supVo.short_maxThread = conf.getSetAttrPlusInt(doc, "config.support", "short_maxThread", null, 1, 1000, null) ;//æ± ä¸æå¤§çº¿ç¨æ°ä¸ºææCPUæ ¸æ°+1 |
| | | supVo.short_minThread = conf.getSetAttrPlusInt(doc, "config.support", "short_minThread", null, 1, 5, null) ;//æ± ä¸æå°çº¿ç¨æ° |
| | | supVo.short_maxThread = conf.getSetAttrPlusInt(doc, "config.support", "short_maxThread", null, -1, 1000, null) ;//æ± ä¸æå¤§çº¿ç¨æ°ä¸ºææCPUæ ¸æ°+1 |
| | | if(supVo.short_maxThread < 0){ |
| | | supVo.short_maxThread = -1 ; |
| | | } |
| | | supVo.short_minThread = conf.getSetAttrPlusInt(doc, "config.support", "short_minThread", null, -1, 100, null) ;//æ± ä¸æå°çº¿ç¨æ° |
| | | if(supVo.short_minThread < 0){ |
| | | supVo.short_minThread = -1 ; |
| | | } |
| | | supVo.short_freeTimeout = conf.getSetAttrPlusInt(doc, "config.support", "short_freeTimeout", null, 1, 90, null) * 1000 ;//çº¿ç¨æ°ç©ºé²æ¶é¿ï¼è¥æ± ä¸çº¿ç¨æ°é大äºminThreadï¼ä¸æç线ç¨ç©ºé²æ¶é¿è¶
è¿freeTimeoutï¼åæ¸
é¤è¯¥çº¿ç¨ï¼ä¸ºäºä¸æ¸
é¤ï¼æminThreadä¸maxThread设置ç¸ç |
| | | supVo.short_busyTimeout = conf.getSetAttrPlusInt(doc, "config.support", "short_busyTimeout", null, 1, 10, null) * 1000 ;//线ç¨ä¸é´æå·¥ä½æ¶é¿ï¼åä½ä¸ºç§)è¶
æ¶éï¼è®¤ä¸ºçº¿ç¨å·²ç»äºå´©æºï¼å°å¼ºå¶æ¸
é¤ï¼ç工使¶é¿è®¾ç½®ä¸º5ç§ |
| | | if(supVo.short_maxThread == 0 || supVo.short_minThread == 0){ |
| | | supVo.enableShortThreadPool = false ; |
| | | }else{ |
| | | supVo.enableShortThreadPool = true ; |
| | | } |
| | | |
| | | //é¿å·¥ä½æ¶é¿çº¿ç¨æ± ï¼çº¿ç¨è´è´£ç¨æ¶è¾é¿çå·¥ä½ä»»å¡ |
| | | supVo.long_maxThread = conf.getSetAttrInt(doc, "config.support", "long_maxThread", null, -1, 1000, null) ;//æ± ä¸æå¤§çº¿ç¨æ°,è¥ä¸º-1ï¼ä¸åéå¶ |
| | | if(supVo.long_maxThread < 0){ |
| | | supVo.long_maxThread = -1 ; |
| | | } |
| | | supVo.long_minThread = conf.getSetAttrPlusInt(doc, "config.support", "long_minThread", null, 0, 5, null) ;//æ± ä¸æå°çº¿ç¨æ° |
| | | supVo.long_minThread = conf.getSetAttrPlusInt(doc, "config.support", "long_minThread", null, -1, 100, null) ;//æ± ä¸æå°çº¿ç¨æ° |
| | | if(supVo.long_minThread < 0){ |
| | | supVo.long_minThread = -1 ; |
| | | } |
| | | supVo.long_freeTimeout = conf.getSetAttrPlusInt(doc, "config.support", "long_freeTimeout", null, 1, 90, null) * 1000 ;//çº¿ç¨æ°ç©ºé²æ¶é¿ï¼è¥æ± ä¸çº¿ç¨æ°é大äºminThreadï¼ä¸æç线ç¨ç©ºé²æ¶é¿è¶
è¿freeTimeoutï¼åæ¸
é¤è¯¥çº¿ç¨ |
| | | supVo.long_busyTimeout = conf.getSetAttrInt(doc, "config.support", "long_busyTimeout", null, -1, 10, null) ;//线ç¨ä¸é´æå·¥ä½æ¶é¿ï¼åä½ä¸ºç§)è¶
æ¶éï¼è¥ä¸º-1ï¼ä¸åéå¶ |
| | | if(supVo.long_busyTimeout < 0){ |
| | | supVo.long_busyTimeout = -1 ; |
| | | } |
| | | |
| | | supVo.enableThreadPool = conf.getSetAttrBoolean(doc, "config.support", "enableThreadPool", null, null) ; |
| | | |
| | | // supVo.enableSpringHibernate = conf.getSetAttrBoolean(doc, "config.support", "enableSpringHibernate", null, null) ; |
| | | // if(supVo.enableSpringHibernate){ |
| | | // supVo.springXmlFile = conf.getSetAttrTxt(doc, "config.support", "springXmlFile", null, false, null) ; |
| | | // } |
| | | |
| | | if(supVo.long_maxThread == 0 || supVo.long_minThread == 0){ |
| | | supVo.enableLongThreadPool = false ; |
| | | }else{ |
| | | supVo.enableLongThreadPool = true ; |
| | | } |
| | | |
| | | supVo.showStartInfo = showStartInfo ; |
| | | |
| | | AdapterImp_SupportUnit supAdap = new AdapterImp_SupportUnit() ; |
| | | supAdap.setConfig(supVo); |
| | | SupportUnit supUnit = SupportUnit.getInstance() ; |
| | | supUnit.setAdapter(supAdap); |
| | | supUnit.start(new UnitStartedCallbackInterface(){ |
| | | @Override |
| | | public void call(Object obj) { |
| | | } |
| | | supUnit.start(obj -> { |
| | | }); |
| | | units.add(supUnit) ; |
| | | |
| | |
| | | //å½åæ¯æspring + hibernate |
| | | resUnit.setSpringContext(SpringContextUtil.getApplicationContext()); |
| | | |
| | | resUnit.start(new UnitStartedCallbackInterface(){ |
| | | @Override |
| | | public void call(Object obj) { |
| | | } |
| | | resUnit.start(obj -> { |
| | | }); |
| | | units.add(resUnit) ; |
| | | |
| | |
| | | rmiAdap.setConfig(rmiVo); |
| | | RmiUnit rmiUnit = RmiUnit.getInstance(); |
| | | rmiUnit.setAdapter(rmiAdap); |
| | | rmiUnit.start(new UnitStartedCallbackInterface(){ |
| | | @Override |
| | | public void call(Object obj) { |
| | | } |
| | | rmiUnit.start(obj -> { |
| | | }); |
| | | RmiSvUrl = "[ip]:" + rmiVo.port + "/" + rmiVo.context ; |
| | | units.add(rmiUnit) ; |
| | | } |
| | | |
| | | |
| | | ///////////////// |
| | | //RTUä¸è¡æ°æ®å¤ç模å |
| | | RtuDataUnitConfigVo rducVo = new RtuDataUnitConfigVo(); |
| | | AdapterImp_RtuDataUnit rducAdap = new AdapterImp_RtuDataUnit(); |
| | | rducAdap.setConfig(rducVo); |
| | | RtuDataUnit rducUnit = RtuDataUnit.getInstance(); |
| | | rducUnit.setAdapter(rducAdap); |
| | | rducUnit.start(obj -> { |
| | | }); |
| | | units.add(rducUnit) ; |
| | | |
| | | |
| | | |
| | | // /////////////// |
| | | // æ ¸å¿ |
| | | CoreUnitConfigVo coreConfVo = new CoreUnitConfigVo(); |
| | | coreConfVo.sleepBigBusy = conf.getSetAttrPlusInt(doc, "config.core", "sleepBigBusy", null, 1, 200, null).longValue() ; |
| | | coreConfVo.sleepSmallBusy = conf.getSetAttrPlusInt(doc, "config.core", "sleepSmallBusy", null, 2, 1000, null).longValue(); |
| | | coreConfVo.queueWarnSize = conf.getSetAttrPlusInt(doc, "config.core", "queueWarnSize", null, 500, 1000000, null) ; |
| | | coreConfVo.queueMaxSize = conf.getSetAttrPlusInt(doc, "config.core", "queueMaxSize", null, 5000, 3000000, null) ; |
| | | coreConfVo.queueWarnSize = ServerProperties.cacheUpDownDataWarnCount ; |
| | | coreConfVo.queueMaxSize = ServerProperties.cacheUpDownDataMaxCount ; |
| | | coreConfVo.showStartInfo = showStartInfo ; |
| | | AdapterImp_CoreUnit coreAdap = new AdapterImp_CoreUnit(); |
| | | coreAdap.setConfig(coreConfVo); |
| | | CoreUnit coreUnit = CoreUnit.getInstance(); |
| | | coreUnit.setAdapter(coreAdap); |
| | | CoreUnit.addConstantTask(new ToRtuConstantTask()); |
| | | coreUnit.start(new UnitStartedCallbackInterface(){ |
| | | @Override |
| | | public void call(Object obj) { |
| | | } |
| | | CoreUnit.addConstantTask(new FromRtuConstantTask()); |
| | | coreUnit.start(obj -> { |
| | | }); |
| | | units.add(coreUnit) ; |
| | | |
| | |
| | | tcpAdap.setConfig(tcpVo); |
| | | TcpUnit tcpUnit = TcpUnit.getInstance(); |
| | | tcpUnit.setAdapter(tcpAdap); |
| | | tcpUnit.start(new UnitStartedCallbackInterface(){ |
| | | @Override |
| | | public void call(Object obj) { |
| | | } |
| | | tcpUnit.start(obj -> { |
| | | }); |
| | | TcpSvUrl = "[ip]:" + tcpVo.port ; |
| | | units.add(tcpUnit) ; |
New file |
| | |
| | | package com.dy.aceMw.server; |
| | | |
| | | |
| | | import com.dy.aceMw.server.rtuData.RtuDataUnitAdapter; |
| | | import com.dy.aceMw.server.rtuData.RtuDataUnitConfigVo; |
| | | |
| | | public class AdapterImp_RtuDataUnit implements RtuDataUnitAdapter { |
| | | |
| | | private RtuDataUnitConfigVo configVo ; |
| | | |
| | | public RtuDataUnitConfigVo getConfig() { |
| | | return configVo; |
| | | } |
| | | |
| | | public void setConfig(RtuDataUnitConfigVo configVo){ |
| | | this.configVo = configVo ; |
| | | } |
| | | |
| | | } |
| | |
| | | package com.dy.aceMw.server.forTcp; |
| | | |
| | | import com.dy.aceMw.server.rtuData.RtuDataNode; |
| | | import com.dy.aceMw.server.rtuData.RtuDataCache; |
| | | import org.apache.logging.log4j.LogManager; |
| | | import org.apache.logging.log4j.Logger; |
| | | |
| | |
| | | //æ¤å¤å®ç°ï¼ä¸ä»¥åä¸ä¸æ ·ï¼ |
| | | //以åå®ç°ï¼å¹é
å½ä»¤æ¯ä»åååå¹é
ï¼ |
| | | //å½åå®ç°ï¼å¹é
å½ä»¤æ¯ä»åååå¹é
ï¼åå ï¼ä¸¾ä¾ï¼å½æ¹éä¸åè¡¥å¬å½ä»¤ï¼å¦æä»åå¹é
ï¼ååé¢å½ä»¤ä¼ä¸å夿¬¡ï¼å³ä¸ä¸ªä¸æ¥æ¬¡æ°æ®ä¼è¡¥å¬å¤æ¬¡ |
| | | MidResultToRtu resToRtu = TcpDownCommandCach.matchFromHead(resFromRtu) ; |
| | | MidResultToRtu resToRtu = TcpDownCommandCache.matchFromHead(resFromRtu) ; |
| | | if(resToRtu != null){ |
| | | //å¹é
å°ä¸åçå½ä»¤ |
| | | resFromRtu.setCommandId(resToRtu.commandId) ; |
| | | this.sendResult(false, resFromRtu); |
| | | this.nextDeal(false, resFromRtu); |
| | | }else{ |
| | | this.sendResult(false, resFromRtu); |
| | | this.nextDeal(false, resFromRtu); |
| | | //æªå¹é
å°ä¸åçå½ä»¤ï¼å½ä»¤å¨ç¼åå è¶
æ¶è¢«æ¸
é¤äº |
| | | RtuStatusDealer.commandFail2Success(resFromRtu.rtuAddr) ; |
| | | } |
| | | }else{ |
| | | //主å¨ä¸æ¥æ°æ® |
| | | this.sendResult(true, resFromRtu); |
| | | this.nextDeal(true, resFromRtu); |
| | | } |
| | | } |
| | | } |
| | | private void sendResult(boolean reportOrResponse_trueOrFalse, MidResultFromRtu resFromRtu){ |
| | | |
| | | /** |
| | | * è¿å
¥å¤çº¿ç¨ç¯å¢ä¸è¿è¡ |
| | | * @param reportOrResponse_trueOrFalse |
| | | * @param resFromRtu |
| | | */ |
| | | private void nextDeal(boolean reportOrResponse_trueOrFalse, MidResultFromRtu resFromRtu){ |
| | | try{ |
| | | String json = resFromRtu.data.toJson() ; |
| | | // if(reportOrResponse_trueOrFalse){ |
| | | // ToMqMessageCach.cachObj(MessageType.RtuAutoReport, json); |
| | | // }else{ |
| | | // ToMqMessageCach.cachObj(MessageType.RtuCmdResponse, json); |
| | | // } |
| | | RtuDataCache.cacheRtuUpData(reportOrResponse_trueOrFalse, new RtuDataNode(resFromRtu.data)); |
| | | }catch(Exception e){ |
| | | log.error(e.getMessage(), e); |
| | | } |
| | | |
| | | } |
| | | } |
New file |
| | |
| | | package com.dy.aceMw.server.rtuData; |
| | | |
| | | import com.dy.aceMw.server.ServerProperties; |
| | | import com.dy.common.queue.Node; |
| | | import com.dy.common.queue.Queue; |
| | | |
| | | public class RtuDataCache { |
| | | |
| | | //TCPä¸è¡å½ä»¤ç¼åéå |
| | | private static Queue cacheQueue = new Queue("tcpUpDataQueue") ; |
| | | |
| | | private static RtuDataCache instance = new RtuDataCache() ; |
| | | |
| | | private RtuDataCache(){ |
| | | cacheQueue.setLimit(ServerProperties.cacheUpDownDataWarnCount, ServerProperties.cacheUpDownDataMaxCount); |
| | | } |
| | | |
| | | public static RtuDataCache getInstance(){ |
| | | return instance ; |
| | | } |
| | | |
| | | /** |
| | | * ç¼åèç¹ |
| | | * @param reportOrResponse_trueOrFalse reportOrResponse_trueOrFalse |
| | | * @param node node |
| | | * @throws Exception å¼å¸¸ |
| | | */ |
| | | public static void cacheRtuUpData(boolean reportOrResponse_trueOrFalse, RtuDataNode node) throws Exception{ |
| | | if(node != null && node.obj != null){ |
| | | if(reportOrResponse_trueOrFalse){ |
| | | cacheQueue.pushHead(node); |
| | | }else{ |
| | | cacheQueue.pushTail(node); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * å¾å°ç¬¬ä¸ä¸ªèç¹ |
| | | * @return Node |
| | | */ |
| | | public static Node getFirstQueueNode(){ |
| | | return cacheQueue.getFirstNode() ; |
| | | } |
| | | |
| | | /** |
| | | * å¾å°æåä¸ä¸ªèç¹ |
| | | * @return Node |
| | | */ |
| | | public static Node getLastQueueNode(){ |
| | | return cacheQueue.getLastNode() ; |
| | | } |
| | | |
| | | /** |
| | | * ç§»é¤èç¹ |
| | | * @param node |
| | | */ |
| | | public static void removeNode(Node node){ |
| | | cacheQueue.remove(node); |
| | | } |
| | | |
| | | /** |
| | | * ç¼åçèç¹æ° |
| | | * @Return ç¼åèç¹æ° |
| | | */ |
| | | public static Integer size(){ |
| | | return cacheQueue.size() ; |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.dy.aceMw.server.rtuData; |
| | | |
| | | import com.dy.common.queue.NodeObj; |
| | | import com.dy.common.threadPool.ThreadPool; |
| | | import com.dy.common.threadPool.TreadPoolFactory; |
| | | import org.apache.logging.log4j.LogManager; |
| | | import org.apache.logging.log4j.Logger; |
| | | |
| | | public class RtuDataNode implements NodeObj { |
| | | |
| | | private static final Logger log = LogManager.getLogger(RtuDataNode.class.getName()); |
| | | |
| | | public Object obj ;//æ°æ® |
| | | |
| | | public RtuDataNode(Object obj){ |
| | | this.obj = obj ; |
| | | } |
| | | /** |
| | | * èªå·±å¤çèªå·± |
| | | * @return |
| | | */ |
| | | public boolean dealSelf(){ |
| | | try { |
| | | ThreadPool.Pool pool = TreadPoolFactory.getThreadPoolLong() ; |
| | | pool.putJob(new ThreadPool.Job() { |
| | | public void execute() { |
| | | if(obj != null){ |
| | | TaskSurpport t = null ; |
| | | try{ |
| | | t = TaskPool.popTask() ; |
| | | if(t != null){ |
| | | t.execute(obj); |
| | | }else{ |
| | | log.error("æªå¾å°RTU主å¨ä¸æ¥æ°æ®å¤çä»»å¡ï¼"); |
| | | } |
| | | }catch(Exception e){ |
| | | if(t != null){ |
| | | //彿å¼å¸¸æ¶ï¼try catchä¸ç代ç 坿²¡ææ§è¡freeAndCleanTask |
| | | TaskPool.freeAndCleanTask(t); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | @Override |
| | | public void destroy(){ |
| | | } |
| | | @Override |
| | | public boolean isDestroy(){ |
| | | return false ; |
| | | } |
| | | |
| | | }); |
| | | } catch (Exception e) { |
| | | log.error("å¨RtuDataNodeå
åçå¼å¸¸", e); |
| | | } |
| | | return true ; |
| | | } |
| | | |
| | | |
| | | } |
New file |
| | |
| | | package com.dy.aceMw.server.rtuData; |
| | | |
| | | import com.dy.common.mw.UnitAdapterInterface; |
| | | import com.dy.common.mw.UnitInterface; |
| | | import com.dy.common.mw.UnitStartedCallbackInterface; |
| | | |
| | | public class RtuDataUnit implements UnitInterface { |
| | | |
| | | private static RtuDataUnit instance = new RtuDataUnit() ; |
| | | |
| | | public static RtuDataUnitAdapter adapter ; |
| | | public static RtuDataUnitConfigVo confVo ; |
| | | |
| | | private RtuDataUnit(){} ; |
| | | |
| | | public static RtuDataUnit getInstance(){ |
| | | return instance ; |
| | | } |
| | | |
| | | @Override |
| | | public void setAdapter(UnitAdapterInterface adapter) throws Exception { |
| | | if(adapter == null){ |
| | | throw new Exception("RTUæ°æ®å¤ç模åéé
å¨å¯¹è±¡ä¸è½ä¸ºç©ºï¼") ; |
| | | } |
| | | RtuDataUnit.adapter = (RtuDataUnitAdapter)adapter ; |
| | | RtuDataUnit.confVo = RtuDataUnit.adapter.getConfig() ; |
| | | if(RtuDataUnit.confVo == null){ |
| | | throw new Exception("RTUæ°æ®å¤ç模åé
置对象ä¸è½ä¸ºç©ºï¼") ; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * åå§åä¸è¡æ°æ®å¤ç任塿± |
| | | */ |
| | | @Override |
| | | public void start(UnitStartedCallbackInterface callback) throws Exception { |
| | | TaskPool.setTaskTreeCofig(new TreeParse().parseConfig()); |
| | | callback.call(null) ; |
| | | System.out.println("RTUæ°æ®å¤ç模åæåå¯å¨"); |
| | | } |
| | | |
| | | @Override |
| | | public void stop(UnitStartedCallbackInterface callback) throws Exception { |
| | | } |
| | | |
| | | } |
| | | |
New file |
| | |
| | | package com.dy.aceMw.server.rtuData; |
| | | |
| | | |
| | | import com.dy.common.mw.UnitAdapterInterface; |
| | | |
| | | public interface RtuDataUnitAdapter extends UnitAdapterInterface { |
| | | |
| | | public RtuDataUnitConfigVo getConfig() ; |
| | | |
| | | } |
New file |
| | |
| | | package com.dy.aceMw.server.rtuData; |
| | | |
| | | public class RtuDataUnitConfigVo { |
| | | |
| | | } |
New file |
| | |
| | | package com.dy.aceMw.server.rtuData; |
| | | |
| | | public interface Task { |
| | | |
| | | |
| | | /** |
| | | * ä»»å¡éç¨å¯¹è±¡æ± ï¼ä»¥ä¾¿éç¨ä»»å¡å¯¹è±¡ï¼ |
| | | * éç¨åè¦è¿è¡å¯¹è±¡åå§åï¼æ¸
é¤ä¸æ¬¡æ§è¡ä»»å¡æ¶éççå¯¹è±¡å±æ§æ°æ® |
| | | * åå§åæ¬ä»»å¡åææåä»»å¡ |
| | | */ |
| | | public void cleanMeAndSubs() ; |
| | | |
| | | /** |
| | | * æ§è¡èç¹ä»»å¡ |
| | | * @param data éè¦å¤ççæ°æ® |
| | | */ |
| | | public void execute(Object data) ; |
| | | |
| | | /** |
| | | * å¾å°æ¬ä»»å¡èç¹å¤ç产ççä¸é´ç»æï¼ä»¥ä¾æ¬èç¹æå¨æ æçä¸çº§ä»»å¡èç¹åæ¬æ æçå·¦ä¾§ï¼æ ¹å¨ä¸ï¼æææ æçèç¹åºç¨æ¬ç»æ |
| | | * @return |
| | | */ |
| | | public Object[] getMyResults() ; |
| | | |
| | | /** |
| | | * å¾å°æå®ä»»å¡èç¹å¤ç产ççä¸é´ç»æï¼ä»¥ä¾æ¬èç¹æå¨æ æçä¸çº§ä»»å¡èç¹åæ¬æ æçå·¦ä¾§ï¼æ ¹å¨ä¸ï¼æææ æçèç¹åºç¨æ¬ç»æ |
| | | * @param id æå®ä»»å¡ID |
| | | * @return |
| | | */ |
| | | public Object[] getTaskResults(String id); |
| | | |
| | | /** |
| | | * 转ä¸çº§ä»»å¡èç¹å¤çï¼é¦å
è¦å®ä½åææåèç¹ã |
| | | * @param data éè¦å¤ççæ°æ® |
| | | */ |
| | | public void toNextTasks(Object data) ; |
| | | |
| | | |
| | | /** |
| | | * 转ä¸çº§æä¸ªä»»å¡èç¹å¤ç |
| | | * @param data éè¦å¤ççæ°æ® |
| | | * @param id æå®ä»»å¡ID |
| | | */ |
| | | public void toNextOneTask(Object data, String id); |
| | | |
| | | } |
New file |
| | |
| | | package com.dy.aceMw.server.rtuData; |
| | | |
| | | |
| | | public class TaskConfig { |
| | | public String id ; |
| | | public String name ; |
| | | public Boolean enable ;//æ¯å¦æ§è¡èç¹çæ°æ®å¤çä»»å¡ä»»å¡ |
| | | public String clazz ; |
| | | } |
New file |
| | |
| | | package com.dy.aceMw.server.rtuData; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | import org.apache.logging.log4j.LogManager; |
| | | import org.apache.logging.log4j.Logger; |
| | | |
| | | |
| | | public class TaskPool { |
| | | |
| | | private static Logger log = LogManager.getLogger(TaskPool.class.getName()) ; |
| | | |
| | | private static List<TaskSurpport> tasks = new ArrayList<TaskSurpport>() ; |
| | | |
| | | private static TreeConfig taskTreeConf ; |
| | | |
| | | |
| | | public static void setTaskTreeCofig(TreeConfig conf){ |
| | | taskTreeConf = conf ; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * å¾å°ä»»å¡ |
| | | * å¤çº¿ç¨ç¯å¢ä¸è¿è¡ |
| | | * @return |
| | | */ |
| | | public static synchronized TaskSurpport popTask(){ |
| | | TaskSurpport t = (tasks.size() > 0)?tasks.get(0):null ; |
| | | if(t != null){ |
| | | tasks.remove(0) ; |
| | | }else{ |
| | | try { |
| | | t = newTaskTree() ; |
| | | } catch (Exception e) { |
| | | log.error(e.getMessage() == null?"å®ä¾åä¸è¡æ°æ®å¤çä»»å¡å¯¹è±¡æ 失败ï¼" : e.getMessage(), e); |
| | | } finally { |
| | | if(t == null){ |
| | | log.error("å®ä¾åä¸è¡æ°æ®å¤çä»»å¡å¯¹è±¡å¤±è´¥ï¼" ); |
| | | } |
| | | } |
| | | } |
| | | |
| | | return t ; |
| | | } |
| | | |
| | | /** |
| | | * æ¾åä»»å¡ |
| | | * å¤çº¿ç¨ç¯å¢ä¸è¿è¡ |
| | | * è¿ééè¦åæ¥éï¼å 为ä¸é¢æ¹æ³ä¸æ§è¡å®tasks.get(0)䏿ªæ§è¡tasks.remove(0)æé´ï¼æ¬æ¹æ³æ§è¡å¹¶ä¸æ§è¡å®ï¼é£ä¹åæå°±ä¼åºä¹±å |
| | | * @param t |
| | | */ |
| | | public static synchronized void freeAndCleanTask(TaskSurpport t){ |
| | | if(t != null){ |
| | | boolean find = false ; |
| | | for(TaskSurpport tin : tasks){ |
| | | if(tin == t){ |
| | | find = true ; |
| | | break ; |
| | | } |
| | | } |
| | | if(!find){ |
| | | t.cleanMeAndSubs(); |
| | | tasks.add(0, t) ; |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * å®ä¾åä»»å¡å¯¹è±¡æ |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | private static TaskSurpport newTaskTree() throws Exception{ |
| | | TaskSurpport t = null ; |
| | | if(taskTreeConf != null){ |
| | | t = newTask(null, taskTreeConf.taskConf, taskTreeConf.subTreeConfs) ; |
| | | } |
| | | return t ; |
| | | } |
| | | |
| | | private static TaskSurpport newTask(TaskSurpport root, TaskConfig taskConf, TreeConfig[] subTreeConfs) throws Exception{ |
| | | TaskSurpport t = null ; |
| | | if(taskConf != null){ |
| | | t = instanceTask(taskConf.clazz) ; |
| | | if(t != null){ |
| | | t.conf = taskConf ; |
| | | t.root = root ; |
| | | if(root == null){ |
| | | root = t ; |
| | | } |
| | | newSubTask(root, t, subTreeConfs); |
| | | } |
| | | } |
| | | return t ; |
| | | } |
| | | private static void newSubTask(TaskSurpport root, TaskSurpport parent, TreeConfig[] treeConfs)throws Exception{ |
| | | if(parent != null && treeConfs != null && treeConfs.length > 0){ |
| | | parent.subTasks = new TaskSurpport[treeConfs.length] ; |
| | | for(int i = 0 ; i < treeConfs.length; i++){ |
| | | parent.subTasks[i] = newTask(root, treeConfs[i].taskConf, treeConfs[i].subTreeConfs) ; |
| | | } |
| | | } |
| | | } |
| | | private static TaskSurpport instanceTask(String clazz)throws Exception{ |
| | | Class<?> c = Class.forName(clazz); |
| | | if (c == null) { |
| | | throw new Exception("å®ä¾åä¸è¡æ°æ®å¤çä»»å¡å¯¹è±¡æ 失败ï¼ä»»å¡ç±»ä¸º" + clazz + "ï¼"); |
| | | }else{ |
| | | return (TaskSurpport)c.getDeclaredConstructor().newInstance(); |
| | | //return (TaskSurpport)c.newInstance(); |
| | | } |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.dy.aceMw.server.rtuData; |
| | | |
| | | import org.apache.logging.log4j.LogManager; |
| | | import org.apache.logging.log4j.Logger; |
| | | |
| | | /** |
| | | * é¨åå®ç°Task |
| | | */ |
| | | public abstract class TaskSurpport implements Task { |
| | | |
| | | private static final Logger log = LogManager.getLogger(TaskSurpport.class.getName()) ; |
| | | |
| | | //å½åæå¤ççä¸è¡æ°æ®æå±RTUçå°å |
| | | public String rtuAddr_inRootTk ;//åªå¨æ ¹rootä»»å¡å¯¹è±¡ä¸ä¼ä»æ¤å¼ |
| | | //æ¬èç¹é
ç½® |
| | | protected TaskConfig conf ; |
| | | //æ ¹ä»»å¡ |
| | | protected TaskSurpport root ; |
| | | //æ¬ä»»å¡çåä»»å¡ |
| | | protected TaskSurpport[] subTasks ; |
| | | //æ¬ä»»å¡çå¤çç»æ |
| | | protected Object[] taskResult ; |
| | | |
| | | /** |
| | | * æ§è¡èç¹ä»»å¡ |
| | | * @param data éè¦å¤ççæ°æ® |
| | | */ |
| | | @Override |
| | | public abstract void execute(Object data) ; |
| | | |
| | | /** |
| | | * ä»»å¡éç¨å¯¹è±¡æ± ï¼ä»¥ä¾¿éç¨ä»»å¡å¯¹è±¡ï¼ |
| | | * éç¨åè¦è¿è¡å¯¹è±¡åå§åï¼æ¸
é¤ä¸æ¬¡æ§è¡ä»»å¡æ¶éççå¯¹è±¡å±æ§æ°æ® |
| | | * åå§åæ¬ä»»å¡åææåä»»å¡ |
| | | */ |
| | | @Override |
| | | public void cleanMeAndSubs() { |
| | | rtuAddr_inRootTk = null ; |
| | | taskResult = null ; |
| | | if(this.subTasks != null && this.subTasks.length > 0){ |
| | | for(int i = 0 ; i < this.subTasks.length; i++){ |
| | | this.subTasks[i].cleanMeAndSubs() ; |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * å¾å°æ¬ä»»å¡èç¹å¤ç产ççä¸é´ç»æï¼ä»¥ä¾æ¬èç¹æå¨æ æçä¸çº§ä»»å¡èç¹åæ¬æ æçå·¦ä¾§ï¼æ ¹å¨ä¸ï¼æææ æçèç¹åºç¨æ¬ç»æ |
| | | * @return |
| | | */ |
| | | @Override |
| | | public Object[] getMyResults(){ |
| | | return taskResult ; |
| | | } |
| | | |
| | | /** |
| | | * å¾å°æå®ä»»å¡èç¹å¤ç产ççä¸é´ç»æï¼ä»¥ä¾æ¬èç¹æå¨æ æçä¸çº§ä»»å¡èç¹åæ¬æ æçå·¦ä¾§ï¼æ ¹å¨ä¸ï¼æææ æçèç¹åºç¨æ¬ç»æ |
| | | * @param id æå®ä»»å¡ID |
| | | * @return |
| | | */ |
| | | public Object[] getTaskResults(String id){ |
| | | if(root != null){ |
| | | return this.getTaskResults(root, id) ; |
| | | } |
| | | return null ; |
| | | } |
| | | private Object[] getTaskResults(TaskSurpport task, String id){ |
| | | if(task != null && task.conf != null && task.conf.id != null && task.conf.id.equals(id)){ |
| | | return task.getMyResults() ; |
| | | }else{ |
| | | if(task.subTasks != null && task.subTasks.length > 0){ |
| | | Object[] rs = null ; |
| | | for(int i = 0 ; i < task.subTasks.length; i++){ |
| | | rs = getTaskResults(task.subTasks[i], id) ; |
| | | if(rs != null){ |
| | | return rs ; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | return null ; |
| | | } |
| | | |
| | | /** |
| | | * 转ä¸çº§ä»»å¡èç¹å¤çï¼é¦å
è¦å®ä½åææåèç¹ã |
| | | * @param data éè¦å¤ççæ°æ® |
| | | */ |
| | | @Override |
| | | public void toNextTasks(Object data) { |
| | | try { |
| | | if(subTasks != null && subTasks.length > 0){ |
| | | for(int i = 0 ; i < subTasks.length ; i++){ |
| | | if(subTasks[i].conf.enable){ |
| | | subTasks[i].execute(data) ; |
| | | }else{ |
| | | //æ¬èç¹ä¸èµ·ä½ç¨ï¼ç´æ¥è¿å
¥æ¬èçåèç¹ |
| | | subTasks[i].toNextTasks(data) ; |
| | | } |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("åä¸çº§ä»»å¡ä¼ é工使¶åºéï¼" , e); |
| | | }finally{ |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 转ä¸çº§æä¸ªä»»å¡èç¹å¤ç |
| | | * @param data éè¦å¤ççæ°æ® |
| | | * @param id æå®ä»»å¡ID |
| | | */ |
| | | public void toNextOneTask(Object data, String id){ |
| | | try { |
| | | if(subTasks != null && subTasks.length > 0){ |
| | | for(int i = 0 ; i < subTasks.length ; i++){ |
| | | if(subTasks[i].conf.id.equals(id)){ |
| | | if(subTasks[i].conf.enable){ |
| | | subTasks[i].execute(data) ; |
| | | }else{ |
| | | //æ¬èç¹ä¸èµ·ä½ç¨ï¼ç´æ¥è¿å
¥æ¬èçåèç¹ |
| | | subTasks[i].toNextTasks(data) ; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("åæå®åä»»å¡ï¼" + id + "ï¼ä¼ é任塿¶åºéï¼" , e); |
| | | }finally{ |
| | | } |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.dy.aceMw.server.rtuData; |
| | | |
| | | import com.dy.common.mw.protocol.Data; |
| | | import org.apache.logging.log4j.LogManager; |
| | | import org.apache.logging.log4j.Logger; |
| | | |
| | | public class TkReceive extends TaskSurpport { |
| | | |
| | | private static final Logger log = LogManager.getLogger(TkReceive.class.getName()) ; |
| | | |
| | | //ç±»IDï¼ä¸å®ä¸Tree.xmlé
ç½®æä»¶ä¸é
ç½®ä¸è´ |
| | | public static final String taskId = "TkReceive" ; |
| | | |
| | | /** |
| | | * æ§è¡èç¹ä»»å¡ |
| | | * @param data éè¦å¤ççæ°æ® |
| | | */ |
| | | @Override |
| | | public void execute(Object data) { |
| | | if(data == null){ |
| | | log.error("严éé误ï¼RTUä¸è¡æ°æ®ä¸ºç©ºï¼" ); |
| | | }else{ |
| | | if(data instanceof Data){ |
| | | this.toNextTasks(data); |
| | | }else{ |
| | | log.error("严éé误ï¼è¯¥æ°æ®ç±»åï¼" + data.getClass().getName() + "ï¼ï¼æ¥æ¶æ°æ®ä»»å¡è¿æªå®ç°ï¼" ); |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.dy.aceMw.server.rtuData; |
| | | |
| | | import com.dy.common.mw.protocol.Data; |
| | | import org.apache.logging.log4j.LogManager; |
| | | import org.apache.logging.log4j.Logger; |
| | | |
| | | public class TkRtuData extends TaskSurpport { |
| | | |
| | | private static Logger log = LogManager.getLogger(TkRtuData.class.getName()) ; |
| | | |
| | | //ç±»IDï¼ä¸å®ä¸Tree.xmlé
ç½®æä»¶ä¸é
ç½®ä¸è´ |
| | | public static final String taskId = "TkRtuData" ; |
| | | |
| | | /** |
| | | * æ§è¡èç¹ä»»å¡ |
| | | * @param data éè¦å¤ççæ°æ® |
| | | */ |
| | | @Override |
| | | public void execute(Object data) { |
| | | Data d = (Data)data ; |
| | | String rtuAddr = d.getRtuAddr() ; |
| | | if(rtuAddr == null){ |
| | | log.error("严éé误ï¼RTUä¸è¡æ°æ®ä¸æ RTUå°åï¼" ); |
| | | }else{ |
| | | this.toNextTasks(data); |
| | | } |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.dy.aceMw.server.rtuData; |
| | | |
| | | public class TreeConfig { |
| | | public TaskConfig taskConf ; |
| | | public TreeConfig[] subTreeConfs ;//ææåèç¹ |
| | | } |
New file |
| | |
| | | package com.dy.aceMw.server.rtuData; |
| | | |
| | | |
| | | import java.net.URL; |
| | | import java.util.*; |
| | | |
| | | import org.jdom2.Document; |
| | | import org.jdom2.Element; |
| | | import org.jdom2.input.SAXBuilder; |
| | | |
| | | |
| | | public class TreeParse { |
| | | public List<String> ids ; |
| | | public List<String> classes ; |
| | | |
| | | // public static void main(String args[]) { |
| | | // TreeParse o = new TreeParse(); |
| | | // TreeConfig conf = o.parseConfig(); |
| | | // } |
| | | |
| | | public TreeParse(){ |
| | | ids = new ArrayList<String>() ; |
| | | classes = new ArrayList<String>() ; |
| | | } |
| | | |
| | | /** |
| | | * è§£æå¤çå¨é
ç½® |
| | | * @return |
| | | */ |
| | | protected TreeConfig parseConfig() { |
| | | try { |
| | | ClassLoader classLoader = ClassLoader.getSystemClassLoader(); |
| | | URL configFileURL = classLoader.getResource("RtuDataDealTree.xml"); |
| | | return this.parse(this.createDom(configFileURL)) ; |
| | | } catch (Exception e) { |
| | | System.out.println("ç³»ç»å¯å¨æ¶ï¼åå§ä¸è¡æ°æ®å¤çä»»å¡é
ç½®åºé !"); |
| | | System.out.println(e.getMessage()); |
| | | e.printStackTrace(); |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * |
| | | * @return |
| | | */ |
| | | private Document createDom(URL configFileURL) throws Exception { |
| | | if (configFileURL == null) { |
| | | throw new Exception("æªå¾å°ä¸è¡æ°æ®å¤çä»»å¡é
ç½®æä»¶!", null); |
| | | } |
| | | Document doc = null; |
| | | try { |
| | | SAXBuilder sb = new SAXBuilder(); |
| | | doc = sb.build(configFileURL); |
| | | if (doc == null) { |
| | | throw new Exception("æªçæä¸è¡æ°æ®å¤çä»»å¡é
ç½®æä»¶çDOM对象!", null); |
| | | } |
| | | } catch (Exception e) { |
| | | throw new Exception("çæä¸è¡æ°æ®å¤çä»»å¡é
ç½®æä»¶çDOM对象失败!", e); |
| | | } |
| | | return doc; |
| | | } |
| | | |
| | | /** |
| | | * åæ |
| | | * @return ArrayList<String> |
| | | * @throws Exception |
| | | */ |
| | | private TreeConfig parse(Document doc) throws Exception { |
| | | Element root = doc.getRootElement(); |
| | | if (root == null) { |
| | | throw new Exception("æªå¾å°ä¸è¡æ°æ®å¤çä»»å¡é
ç½®æä»¶æ ¹å
ç´ project!"); |
| | | } |
| | | |
| | | List<Element> rootTasks = root.getChildren("task") ; |
| | | if(rootTasks == null || rootTasks.size() == 0){ |
| | | throw new Exception("æªå¾å°ä¸è¡æ°æ®å¤çä»»å¡é
ç½®æä»¶æ ¹ä»»å¡task!"); |
| | | } |
| | | if(rootTasks.size() > 1){ |
| | | throw new Exception("æªå¾å°ä¸è¡æ°æ®å¤çä»»å¡é
ç½®æä»¶æ ¹ä»»å¡taskå¿
é¡»åªæä¸ä¸ª!"); |
| | | } |
| | | |
| | | TreeConfig tree = new TreeConfig() ; |
| | | tree.taskConf = new TaskConfig() ; |
| | | |
| | | this.parseNode(rootTasks.get(0), tree, tree.taskConf) ; |
| | | return tree ; |
| | | } |
| | | |
| | | private void parseNode(Element taskEle, TreeConfig me, TaskConfig taskConf)throws Exception { |
| | | // <task id="task2.1" name="æé æ°æ®" enable="true" class="" /> |
| | | if(taskEle == null){ |
| | | throw new Exception("åæä¸è¡æ°æ®å¤çä»»å¡é
ç½®æä»¶åºéï¼"); |
| | | } |
| | | |
| | | String id = taskEle.getAttributeValue("id") ; |
| | | if(id == null || id.trim().equals("")){ |
| | | throw new Exception("ä¸è¡æ°æ®å¤çä»»å¡é
ç½®æä»¶ä¸idå¿
é¡»é
ç½®ï¼"); |
| | | } |
| | | id = id.trim() ; |
| | | if(ids.contains(id)){ |
| | | throw new Exception("ä¸è¡æ°æ®å¤çä»»å¡é
ç½®æä»¶ä¸id=" + id + "éå¤é
ç½®ï¼"); |
| | | } |
| | | taskConf.id = id ; |
| | | ids.add(id) ; |
| | | |
| | | String name = taskEle.getAttributeValue("name") ; |
| | | if(name == null || name.trim().equals("")){ |
| | | throw new Exception("ä¸è¡æ°æ®å¤çä»»å¡é
ç½®æä»¶ä¸nameå¿
é¡»é
ç½®ï¼"); |
| | | } |
| | | name = name.trim() ; |
| | | taskConf.name = name ; |
| | | |
| | | String enable = taskEle.getAttributeValue("enable") ; |
| | | if(enable == null || !(enable.trim().equals("true") || enable.trim().equals("false"))){ |
| | | throw new Exception("ä¸è¡æ°æ®å¤çä»»å¡é
ç½®æä»¶ä¸enableå¿
é¡»é
ç½®ï¼å¹¶ä¸å¼åªè½ä¸ºtrueæfalseï¼"); |
| | | } |
| | | if(enable.trim().equals("true")){ |
| | | taskConf.enable = true ; |
| | | } |
| | | if(enable.trim().equals("false")){ |
| | | taskConf.enable = false ; |
| | | } |
| | | |
| | | String clazz = taskEle.getAttributeValue("class") ; |
| | | if(clazz == null || clazz.trim().equals("")){ |
| | | throw new Exception("ä¸è¡æ°æ®å¤çä»»å¡é
ç½®æä»¶ä¸classå¿
é¡»é
ç½®ï¼"); |
| | | } |
| | | clazz = clazz.trim() ; |
| | | if(classes.contains(clazz)){ |
| | | throw new Exception("ä¸è¡æ°æ®å¤çä»»å¡é
ç½®æä»¶ä¸class=" + clazz + "éå¤é
ç½®ï¼"); |
| | | } |
| | | taskConf.clazz = clazz ; |
| | | classes.add(clazz) ; |
| | | this.checkClass(taskConf.clazz) ; |
| | | |
| | | this.parseSubNode(taskEle, me) ; |
| | | |
| | | } |
| | | |
| | | private void parseSubNode(Element ele, TreeConfig parent)throws Exception { |
| | | List<?> list = ele.getChildren("task") ; |
| | | if(list != null && list.size() > 0){ |
| | | parent.subTreeConfs = new TreeConfig[list.size()] ; |
| | | Iterator<?> it = list.iterator(); |
| | | Element e = null; |
| | | int count = 0 ; |
| | | TreeConfig me ; |
| | | while(it.hasNext()){ |
| | | e = (Element) it.next(); |
| | | me = new TreeConfig() ; |
| | | me.taskConf = new TaskConfig() ; |
| | | parent.subTreeConfs[count++] = me ; |
| | | parseNode(e, me, me.taskConf) ; |
| | | } |
| | | } |
| | | } |
| | | |
| | | private void checkClass(String clazz)throws Exception { |
| | | Class<?> c = Class.forName(clazz); |
| | | if (c == null) { |
| | | throw new Exception("ä¸è¡æ°æ®å¤çä»»å¡é
ç½®æä»¶ä¸ä¸è½å®ä¾åclass=" + clazz + "ï¼"); |
| | | }else{ |
| | | Object o = c.newInstance(); |
| | | if(o instanceof Task){ |
| | | }else{ |
| | | throw new Exception("ä¸è¡æ°æ®å¤çä»»å¡é
ç½®æä»¶ä¸class=" + clazz + "å¿
é¡»å®ç°Taskæ¥å£ï¼"); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
New file |
| | |
| | | package com.dy.aceMw.server.rtuData.dbSv; |
| | | |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | @Service |
| | | public class RtuSv { |
| | | } |
New file |
| | |
| | | springboot容å¨ä¸çServer bean |
New file |
| | |
| | | package com.dy.aceMw.server.rtuData.p206V1_0_0; |
| | | |
| | | |
| | | import com.dy.aceMw.server.rtuData.TaskSurpport; |
| | | import com.dy.common.mw.protocol.Data; |
| | | import com.dy.common.mw.protocol.p206V1_0_0.ProtocolConstantV206V1_0_0; |
| | | |
| | | public class TkFindP206V1_0_0 extends TaskSurpport { |
| | | |
| | | //ç±»IDï¼ä¸å®ä¸Tree.xmlé
ç½®æä»¶ä¸é
ç½®ä¸è´ |
| | | public static final String taskId = "TkFindP206V1_0_0" ; |
| | | |
| | | /** |
| | | * æ§è¡èç¹ä»»å¡ |
| | | * @param data éè¦å¤ççæ°æ® |
| | | */ |
| | | @Override |
| | | public void execute(Object data) { |
| | | Data d = (Data)data ; |
| | | if(d.getProtocol() != null && d.getProtocol().equals(ProtocolConstantV206V1_0_0.protocolName)){ |
| | | this.toNextTasks(data); |
| | | }else{ |
| | | //䏿¯æ¬åè®®çæ°æ® |
| | | } |
| | | } |
| | | |
| | | } |
File was renamed from pipIrr-platform/pipIrr-mw/pipIrr-mw-accept/src/main/java/com/dy/aceMw/server/busi/deal/p206V1_0_0/TkPreGenObjs.java |
| | |
| | | package com.dy.aceMw.server.busi.deal.p206V1_0_0; |
| | | package com.dy.aceMw.server.rtuData.p206V1_0_0; |
| | | |
| | | import com.dy.aceMw.server.busi.deal.TaskSurpport; |
| | | import com.dy.aceMw.server.rtuData.TaskSurpport; |
| | | import com.dy.common.mw.protocol.Data; |
| | | import org.apache.logging.log4j.LogManager; |
| | | import org.apache.logging.log4j.Logger; |
| | |
| | | public void execute(Object data) { |
| | | Data d = (Data)data ; |
| | | String rtuAddr = d.getRtuAddr() ; |
| | | log.info("RTU" + rtuAddr + "æ°æ®å°æ¤ï¼è¿æªå®ç°å¤ç:" + data.toString()); |
| | | //å¾å°æ¬å°RTU æ°æ®ï¼ä»¥å¤åé¢èç¹åºç¨ |
| | | /* |
| | | BuziInterface baseBusi = BuziGeter.getBaseBusi() ; |
New file |
| | |
| | | package com.dy.aceMw.server.tasks; |
| | | |
| | | import com.dy.aceMw.server.rtuData.RtuDataNode; |
| | | import com.dy.aceMw.server.rtuData.RtuDataCache; |
| | | import com.dy.common.mw.core.CoreTask; |
| | | import com.dy.common.queue.Node; |
| | | import org.apache.logging.log4j.LogManager; |
| | | import org.apache.logging.log4j.Logger; |
| | | |
| | | /** |
| | | * 对RTUä¸è¡æ°æ®è¿è¡ä¸å¡å¤ç |
| | | */ |
| | | public class FromRtuConstantTask extends CoreTask { |
| | | private static final Logger log = LogManager.getLogger(FromRtuConstantTask.class.getName()); |
| | | |
| | | /** |
| | | * å¨å线ç¨ç¯å¢ä¸è¿è¡ |
| | | */ |
| | | @Override |
| | | public Integer excute() { |
| | | try{ |
| | | return dealRtuUpData() ; |
| | | }catch(Exception e){ |
| | | log.error(e); |
| | | } |
| | | return null ; |
| | | } |
| | | |
| | | /** |
| | | * å¤çä¸è¡æ°æ® |
| | | */ |
| | | public Integer dealRtuUpData() { |
| | | Node first = RtuDataCache.getFirstQueueNode() ; |
| | | if(first != null){ |
| | | Integer count = RtuDataCache.size() ; |
| | | Node last = RtuDataCache.getLastQueueNode() ; |
| | | this.doDealRtuUpData(first, last); |
| | | return count ; |
| | | } |
| | | return null ; |
| | | } |
| | | |
| | | /** |
| | | * å¤çç¼åçä¸è¡æ°æ®èç¹ |
| | | * @param first 第ä¸ä¸ªèç¹ |
| | | * @param last æåä¸ä¸ªèç¹ |
| | | */ |
| | | private void doDealRtuUpData(Node first, Node last){ |
| | | if(last != null){ |
| | | //å¨dealNodeæ¹æ³ä¸ï¼å¯è½è¦ælastä»éåä¸ç§»é¤ï¼è¿æ¶last.preä¸ºç©ºï¼æä»¥æåælast.preååºæ¥ |
| | | Node pre = last.pre ; |
| | | dealNode(last) ; |
| | | if(first != null && first != last){ |
| | | doDealRtuUpData(first, pre) ; |
| | | }else if(first != null && first == last){ |
| | | //忢 |
| | | }else if(first == null){ |
| | | //è¿ç§æ
åµä¸ä¼åå¨ |
| | | doDealRtuUpData(null, pre) ; |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * å¤çä¸ä¸ªèç¹ |
| | | * @param node èç¹ |
| | | */ |
| | | private void dealNode(Node node){ |
| | | RtuDataNode obj = (RtuDataNode)node.obj ; |
| | | obj.dealSelf() ; |
| | | RtuDataCache.removeNode(node); |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | <!DOCTYPE project> |
| | | <project> |
| | | <!-- |
| | | id:ä¸å¯¹åºç±»ä¸çéææååétaskIdä¸è´ |
| | | enable:æ è¯æ¬èç¹æ¯å¦æ§è¡ï¼è¥æ¬èç¹ä¸æ§è¡ï¼åç´æ¥è¿å
¥å
¶åèç¹ |
| | | --> |
| | | <task id="TkReceive" name="æ¥æ¶æ°æ®" enable="true" class="com.dy.aceMw.server.rtuData.TkReceive"> |
| | | <task id="TkRtuData" name="æ¥æ¶RTUæ°æ®" enable="true" class="com.dy.aceMw.server.rtuData.TkRtuData"> |
| | | <task id="TkFindP206V1_0_0" name="è¯å«P206V1_0_0æ°æ®" enable="true" class="com.dy.aceMw.server.rtuData.p206V1_0_0.TkFindP206V1_0_0"> |
| | | <task id="TkPreGenObjs" name="é¢å
åå¤å对象" enable="true" class="com.dy.aceMw.server.rtuData.p206V1_0_0.TkPreGenObjs"> |
| | | </task> |
| | | </task> |
| | | </task> |
| | | </task> |
| | | </project> |
New file |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | <!DOCTYPE project> |
| | | <project> |
| | | <!-- |
| | | id:ä¸å¯¹åºç±»ä¸çéææååétaskIdä¸è´ |
| | | enable:æ è¯æ¬èç¹æ¯å¦æ§è¡ï¼è¥æ¬èç¹ä¸æ§è¡ï¼åç´æ¥è¿å
¥å
¶åèç¹ |
| | | --> |
| | | <task id="TkReceive" name="æ¥æ¶æ°æ®" enable="true" class="com.dy.aceMw.server.rtuData.TkReceive"> |
| | | <task id="TkRtuData" name="æ¥æ¶RTUæ°æ®" enable="true" class="com.dy.aceMw.server.rtuData.TkRtuData"> |
| | | <task id="TkFindP206V1_0_0" name="è¯å«P206V1_0_0æ°æ®" enable="true" class="com.dy.aceMw.server.rtuData.p206V1_0_0.TkFindP206V1_0_0"> |
| | | <task id="TkPreGenObjs" name="é¢å
åå¤å对象" enable="true" class="com.dy.aceMw.server.rtuData.p206V1_0_0.TkPreGenObjs"> |
| | | <!-- è¯å«æµæµªè
RTUï¼æ°æ®åºä¸æ²¡æææ°æ®åºåå¨ä½æªåé
ç½®ä¾æ°´æºæ --> |
| | | <task id="TkDealRtuTramp" name="è¯å«æµæµªè
RTU" enable="true" class="com.dy.aceMw.server.rtuData.p206V1_0_0.TkDealRtuTramp" /> |
| | | <!-- éæµæµªè
RTUï¼å¿
é¡»æ¾å¨TkDealRtuTrampåé¢ --> |
| | | <task id="TkDealNoRtuTramp" name="éæµæµªè
RTU" enable="true" class="com.dy.aceMw.server.rtuData.p206V1_0_0.TkDealNoRtuTramp"> |
| | | <!-- è¯å«ä¸»å¨ä¸æ¥æ°æ® --> |
| | | <task id="TkFindAutoReport" name="è¯å«ä¸»å¨ä¸æ¥å触å䏿¥æ°æ®" enable="true" class="com.dy.aceMw.server.rtuData.p206V1_0_0.TkFindAutoReport"> |
| | | <!-- æ£æ¥æ¶é´ç䏿£ç¡®ç䏿¥æ°æ® --> |
| | | <task id="TkCheckAutoReport" name="æ£æ¥æ¶é´ç䏿£ç¡®ç䏿¥æ°æ®" enable="true" class="com.dy.aceMw.server.rtuData.p206V1_0_0.autoReport.TkCheckAutoReport"> |
| | | <!-- æ£æ¥éå¤ä¸æ¥æ°æ® --> |
| | | <task id="TkCheckRepeatReport" name="æ£æ¥éå¤ä¸æ¥æ°æ®" enable="true" class="com.dy.aceMw.server.rtuData.p206V1_0_0.autoReport.TkCheckRepeatReport"> |
| | | <!-- Mnè¿ç»´ç³»ç» --> |
| | | <task id="TkMnRtuDealAutoReportLastAlarm" name="è¿ç»´RTU䏿¥ææ°æ¥è¦" enable="true" class="com.dy.aceMw.server.rtuData.p206V1_0_0.autoReport.TkMnRtuDealAutoReportLastAlarm" /> |
| | | <!-- RTU主å¨ä¸æ¥æ°æ®å¿
é¡»å¨RTU主å¨ä¸æ¥æ¥è¦ä»»å¡çä¸é¢ï¼ä»¥å¤ä¸»å¨ä¸æ¥æ°æ®ä¸è®°å½æ¯å¦ææ¥è¦--> |
| | | <task id="TkMnRtuDealAutoReportLastData" name="è¿ç»´RTU主å¨ä¸æ¥ææ°æ°æ®" enable="true" class="com.dy.aceMw.server.rtuData.p206V1_0_0.autoReport.TkMnRtuDealAutoReportLastData" /> |
| | | <!-- RTU宿¶ï¼è§¦åï¼ä¸æ¥æ°æ®å¿
é¡»å¨RTU主å¨ä¸æ¥æ¥è¦ä»»å¡çä¸é¢ï¼ä»¥å¤ä¸»å¨ä¸æ¥æ°æ®ä¸è®°å½æ¯å¦ææ¥è¦--> |
| | | <task id="TkMnRtuDealRealReportLastData" name="è¿ç»´RTU宿¶ï¼è§¦åï¼ä¸æ¥ææ°æ°æ®" enable="true" class="com.dy.aceMw.server.rtuData.p206V1_0_0.autoReport.TkMnRtuDealRealReportLastData" /> |
| | | <!-- Org便°´æºæç³»ç» --> |
| | | <task id="TkOrgRtuDealAutoReportLastAlarm" name="便°´æºæRTU主å¨ä¸æ¥ææ°æ¥è¦" enable="true" class="com.dy.aceMw.server.rtuData.p206V1_0_0.autoReport.TkOrgRtuDealAutoReportLastAlarm"> |
| | | <task id="TkOrgRtuDealAutoReportAlarm" name="便°´æºæRTU主å¨ä¸æ¥æ¥è¦" enable="true" class="com.dy.aceMw.server.rtuData.p206V1_0_0.autoReport.TkOrgRtuDealAutoReportAlarm" /> |
| | | <task id="TkOrgRtuDealReportValveOpResult" name="便°´æºæRTU主å¨ä¸æ¥å¼å
³éç»æ" enable="true" class="com.dy.aceMw.server.rtuData.p206V1_0_0.autoReport.TkOrgRtuDealReportValveOpResult" /> |
| | | </task> |
| | | <!-- RTU主å¨ä¸æ¥æ°æ®å¿
é¡»å¨RTU主å¨ä¸æ¥æ¥è¦ä»»å¡çä¸é¢ï¼ä»¥å¤ä¸»å¨ä¸æ¥æ°æ®ä¸è®°å½æ¯å¦ææ¥è¦--> |
| | | <task id="TkOrgRtuDealDayAmountAlarm" name="便°´æºæRTUæ¥ç»ç´¯è®¡æµéæ¥è¦" enable="true" class="com.dy.aceMw.server.rtuData.p206V1_0_0.autoReport.TkOrgRtuDealDayAmountAlarm" > |
| | | <task id="TkOrgRtuDeal48HourNoAmount" name="便°´æºæRTU48å°æ¶æªç¨æ°´" enable="true" class="com.dy.aceMw.server.rtuData.p206V1_0_0.autoReport.TkOrgRtuDeal48HourNoAmount" > |
| | | <task id="TkOrgRtuDealAutoReportLastData" name="便°´æºæRTU主å¨ä¸æ¥ææ°æ°æ®" enable="true" class="com.dy.aceMw.server.rtuData.p206V1_0_0.autoReport.TkOrgRtuDealAutoReportLastData"> |
| | | <task id="TkOrgRtuDealAutoReportData" name="便°´æºæRTU主å¨ä¸æ¥æ°æ®" enable="true" class="com.dy.aceMw.server.rtuData.p206V1_0_0.autoReport.TkOrgRtuDealAutoReportData" /> |
| | | <task id="TkOrgRtuDealCycleData" name="便°´æºæRTU主å¨ä¸æ¥å¨æééæ°æ®" enable="true" class="com.dy.aceMw.server.rtuData.p206V1_0_0.autoReport.TkOrgRtuDealCycleData"> |
| | | <task id="TkOrgRtuDealCycleLongSmallAmountAlarm" name="便°´æºæRTU主å¨ä¸æ¥å¨æééæ°æ®é¿æµæ°´åæ" enable="true" class="com.dy.aceMw.server.rtuData.p206V1_0_0.autoReport.TkOrgRtuDealCycleLongSmallAmountAlarm" /> |
| | | </task> |
| | | <task id="TkOrgRtuDealAmountCost" name="便°´æºæRTU主å¨ä¸æ¥è®¡ç®æ¥æ°´éãææ°´éãåæ°´è´¹" enable="true" class="com.dy.aceMw.server.rtuData.p206V1_0_0.autoReport.TkOrgRtuDealAmountCost" > |
| | | <task id="TkOrgRtuDealPayCost" name="便°´æºæç¨æ°´æ·æ°´è¡¨çµåé±å
æ¯ä»æ°´è´¹" enable="true" class="com.dy.aceMw.server.rtuData.p206V1_0_0.autoReport.TkOrgRtuDealPayCost" /> |
| | | </task> |
| | | </task> |
| | | </task> |
| | | </task> |
| | | <!-- RTU宿¶ï¼è§¦åï¼ä¸æ¥æ°æ®å¿
é¡»å¨RTU主å¨ä¸æ¥æ¥è¦ä»»å¡çä¸é¢ï¼ä»¥å¤ä¸»å¨ä¸æ¥æ°æ®ä¸è®°å½æ¯å¦ææ¥è¦--> |
| | | <task id="TkOrgRtuDealRealReportLastData" name="便°´æºæRTU宿¶ï¼è§¦åï¼ä¸æ¥ææ°æ°æ®" enable="true" class="com.dy.aceMw.server.rtuData.p206V1_0_0.autoReport.TkOrgRtuDealRealReportLastData"> |
| | | <task id="TkOrgRtuDealRealReportData" name="便°´æºæRTU宿¶ï¼è§¦åï¼ä¸æ¥æ°æ®" enable="true" class="com.dy.aceMw.server.rtuData.p206V1_0_0.autoReport.TkOrgRtuDealRealReportData" /> |
| | | </task> |
| | | </task> |
| | | </task> |
| | | </task> |
| | | <!-- è¯å«å½ä»¤ååºæ°æ® --> |
| | | <task id="TkFindComResponse" name="è¯å«ååºå½ä»¤æ°æ®" enable="true" class="com.dy.aceMw.server.rtuData.p206V1_0_0.TkFindComResponse"> |
| | | <task id="TkRtuDealCommandResponse" name="RTUååºå½ä»¤æ°æ®" enable="true" class="com.dy.aceMw.server.rtuData.p206V1_0_0.comResponse.TkRtuDealCommandResponse" > |
| | | <task id="TkRtuDealSetParamComResponse" name="RTUååºè®¾ç½®åæ°å½ä»¤æ°æ®" enable="true" class="com.dy.aceMw.server.rtuData.p206V1_0_0.comResponse.TkRtuDealSetParamComResponse" /> |
| | | </task> |
| | | </task> |
| | | </task> |
| | | </task> |
| | | </task> |
| | | <task id="TkFindHAC_NBhV2_5" name="è¯å«HAC_NBhV2_5æ°æ®" enable="true" class="com.dy.busi.server.rtuData.HAC_NBhV2_5.TkFindHAC_NBhV2_5"> |
| | | <task id="TkPipPreGenObjs" name="é¢å
åå¤å对象" enable="true" class="com.dy.busi.server.rtuData.HAC_NBhV2_5.TkPipPreGenObjs"> |
| | | <!-- è¯å«æµæµªè
ç®¡ç½æ°´è¡¨ï¼æ°æ®åºä¸æ²¡æææ°æ®åºåå¨ä½æªåé
ç½®ä¾æ°´æºæ --> |
| | | <task id="TkPipDealRtuTramp" name="è¯å«æµæµªè
ç®¡ç½æ°´è¡¨" enable="true" class="com.dy.busi.server.rtuData.HAC_NBhV2_5.TkPipDealRtuTramp" /> |
| | | <!-- éæµæµªè
ç®¡ç½æ°´è¡¨ï¼å¿
é¡»æ¾å¨TkDealRtuTrampåé¢ --> |
| | | <task id="TkPipDealNoRtuTramp" name="éæµæµªè
ç®¡ç½æ°´è¡¨" enable="true" class="com.dy.busi.server.rtuData.HAC_NBhV2_5.TkPipDealNoRtuTramp"> |
| | | <!-- è¯å«ä¸»å¨ä¸æ¥æ°æ® --> |
| | | <task id="TkPipFindAutoReport" name="è¯å«ä¸»å¨ä¸æ¥å触å䏿¥æ°æ®" enable="true" class="com.dy.busi.server.rtuData.HAC_NBhV2_5.TkPipFindAutoReport"> |
| | | <!-- æ£æ¥æ¶é´ç䏿£ç¡®ç䏿¥æ°æ® --> |
| | | <task id="TkPipCheckAutoReport" name="æ£æ¥æ¶é´ç䏿£ç¡®ç䏿¥æ°æ®" enable="true" class="com.dy.busi.server.rtuData.HAC_NBhV2_5.autoReport.TkPipCheckAutoReport"> |
| | | <task id="TkPipCheckRepeatAutoReport" name="æ£æ¥éå¤ä¸æ¥æ°æ®" enable="true" class="com.dy.busi.server.rtuData.HAC_NBhV2_5.autoReport.TkPipCheckRepeatAutoReport"> |
| | | <!-- Mnè¿ç»´ç³»ç» --> |
| | | <task id="TkPipMnRtuDealAutoReportLastAlarm" name="è¿ç»´ç®¡ç½æ°´è¡¨ä¸æ¥ææ°æ¥è¦" enable="true" class="com.dy.busi.server.rtuData.HAC_NBhV2_5.autoReport.TkPipMnRtuDealAutoReportLastAlarm" /> |
| | | <!-- RTU主å¨ä¸æ¥æ°æ®å¿
é¡»å¨RTU主å¨ä¸æ¥æ¥è¦ä»»å¡çä¸é¢ï¼ä»¥å¤ä¸»å¨ä¸æ¥æ°æ®ä¸è®°å½æ¯å¦ææ¥è¦--> |
| | | <task id="TkPipMnRtuDealAutoReportLastData" name="è¿ç»´ç®¡ç½æ°´è¡¨ä¸»å¨ä¸æ¥ææ°æ°æ®" enable="true" class="com.dy.busi.server.rtuData.HAC_NBhV2_5.autoReport.TkPipMnRtuDealAutoReportLastData" /> |
| | | <!-- Org便°´æºæç³»ç» --> |
| | | <task id="TkPipOrgRtuDealAutoReportLastAlarm" name="便°´æºæç®¡ç½æ°´è¡¨ä¸»å¨ä¸æ¥ææ°æ¥è¦" enable="true" class="com.dy.busi.server.rtuData.HAC_NBhV2_5.autoReport.TkPipOrgRtuDealAutoReportLastAlarm"> |
| | | <task id="TkPipOrgRtuDealAutoReportAlarm" name="便°´æºæç®¡ç½æ°´è¡¨ä¸»å¨ä¸æ¥æ¥è¦" enable="true" class="com.dy.busi.server.rtuData.HAC_NBhV2_5.autoReport.TkPipOrgRtuDealAutoReportAlarm" /> |
| | | </task> |
| | | <!-- RTU主å¨ä¸æ¥æ°æ®å¿
é¡»å¨RTU主å¨ä¸æ¥æ¥è¦ä»»å¡çä¸é¢ï¼ä»¥å¤ä¸»å¨ä¸æ¥æ°æ®ä¸è®°å½æ¯å¦ææ¥è¦--> |
| | | <task id="TkPipOrgRtuDealAutoReportLastData" name="便°´æºæç®¡ç½æ°´è¡¨ä¸»å¨ä¸æ¥ææ°æ°æ®" enable="true" class="com.dy.busi.server.rtuData.HAC_NBhV2_5.autoReport.TkPipOrgRtuDealAutoReportLastData"> |
| | | <task id="TkPipOrgRtuDealAutoReportData" name="便°´æºæç®¡ç½æ°´è¡¨ä¸»å¨ä¸æ¥æ°æ®" enable="true" class="com.dy.busi.server.rtuData.HAC_NBhV2_5.autoReport.TkPipOrgRtuDealAutoReportData" /> |
| | | <task id="TkPipOrgRtuDealAmount" name="便°´æºæç®¡ç½æ°´è¡¨ææµéç»è®¡" enable="true" class="com.dy.busi.server.rtuData.HAC_NBhV2_5.autoReport.TkPipOrgRtuDealAmount" /> |
| | | </task> |
| | | </task> |
| | | </task> |
| | | </task> |
| | | </task> |
| | | </task> |
| | | </task> |
| | | </task> |
| | | </task> |
| | | </project> |
| | |
| | | </dependencies> |
| | | |
| | | <build> |
| | | <resources> |
| | | <resource> |
| | | <directory>src/main/java</directory> |
| | | <includes> |
| | | <include>**/*.xml</include> |
| | | </includes> |
| | | </resource> |
| | | <resource> |
| | | <directory>src/main/resources</directory> |
| | | <includes> |
| | | <include>**/*.xml</include> |
| | | <include>**/*.yml</include> |
| | | </includes> |
| | | </resource> |
| | | </resources> |
| | | <plugins> |
| | | <plugin> |
| | | <!-- 该æä»¶ä¸ä¼å°é¡¹ç®ä¸å¼å
¥çä¾èµæè¿æç»ç Jar æä»¶ --> |
| | |
| | | rqVo.id = id ; |
| | | rqVo.token = token ; |
| | | rqVo.code = Code.cd5 ; |
| | | rqVo.count = count ; |
| | | rqVo.overCount = count ; |
| | | String json = rqVo.toJson() ; |
| | | frmWork.syncRequest(json) ; |
| | | } catch (Exception e) { |
| | |
| | | public String token ; |
| | | |
| | | public String code ; |
| | | |
| | | |
| | | public Integer count;//aepTest䏿¥æ°æ®æ°é |
| | | |
| | | |
| | | public Integer overCount;//aepTestç»æä¸æ¥æ°æ®æ°é |
| | | |
| | | public Boolean over ;//aepTest䏿¥æ°æ®ç»æ |
| | | |
| | | public Long seconds ;//aepTest䏿¥æ°æ®ç¨æ¶(ç§) |
| | |
| | | package com.dy.testClient.tcpClient; |
| | | |
| | | import com.dy.common.util.ByteUtil; |
| | | import org.apache.logging.log4j.LogManager; |
| | | import org.apache.logging.log4j.Logger; |
| | | import org.apache.mina.core.buffer.IoBuffer; |
| | | import org.apache.mina.core.session.IoSession; |
| | | import org.apache.mina.filter.codec.CumulativeProtocolDecoder; |
| | |
| | | import java.io.IOException; |
| | | |
| | | public class LocalDecoder extends CumulativeProtocolDecoder { |
| | | |
| | | private static final Logger log = LogManager.getLogger(LocalDecoder.class) ; |
| | | |
| | | private static final String DECODER_STATE_KEY = LocalDecoder.class.getName() + ".STATE"; |
| | | |
| | |
| | | byte[] preByte = new byte[remain]; |
| | | in.get(preByte) ; |
| | | in.position(0) ; |
| | | log.info("æ¶å°ä¸å¿åºçæ°æ®ï¼" + ByteUtil.bytes2Hex(preByte, true)); |
| | | } |
| | | return true; |
| | | } |
| | |
| | | import com.dy.common.threadPool.ThreadPool; |
| | | import com.dy.common.util.ByteUtil; |
| | | import com.dy.testClient.ServerProperties; |
| | | import org.apache.mina.core.future.CloseFuture; |
| | | import org.apache.logging.log4j.LogManager; |
| | | import org.apache.logging.log4j.Logger; |
| | | import org.apache.mina.core.session.IoSession; |
| | | |
| | | public class MyThreadJob implements ThreadPool.Job { |
| | | |
| | | private static final Logger log = LogManager.getLogger(MyThreadJob.class) ; |
| | | |
| | | public String rtuAddr; |
| | | public String serverIp; |
| | | public Integer serverPort; |
| | | |
| | | public IoSession session ; |
| | | public boolean exceptionOnConnect = false ; |
| | | |
| | | public static final int connectTimeout = 3000 ; |
| | | |
| | |
| | | |
| | | @Override |
| | | public void execute() throws Exception { |
| | | if(session == null){ |
| | | IoSession se = new TcpConnect().createSession(this.rtuAddr, this, this.serverIp, this.serverPort, connectTimeout, new TcpHandler()) ; |
| | | if(se != null){ |
| | | this.session = se ; |
| | | } |
| | | }else{ |
| | | log.info("RTU" + rtuAddr + "å¼å§ä»»å¡"); |
| | | if(session != null){ |
| | | log.info("RTU" + rtuAddr + "å°è¦æ§è¡" + ServerProperties.sendTimes + "轮次任å¡ï¼å½å轮次æ¯" + sendTimes); |
| | | if(sendTimes <= ServerProperties.sendTimes){ |
| | | sendDataOfP206V1_0_0() ; |
| | | }else{ |
| | |
| | | if(heartbeatTimes >= ServerProperties.heartbeatTimes){ |
| | | heartbeatTimes = 0 ; |
| | | this.sendReportData() ; |
| | | TcpClUnit.clientSendData(); |
| | | sendTimes++ ; |
| | | }else{ |
| | | this.sendHeartbeat() ; |
| | | TcpClUnit.clientSendData(); |
| | | heartbeatTimes++ ; |
| | | } |
| | | }catch(Exception e){ |
| | |
| | | try{ |
| | | byte[] bs = this.createHeartbeat() ; |
| | | this.session.write(bs) ; |
| | | log.info("RTU" + rtuAddr + "åéäºå¿è·³æ°æ®ï¼" + ByteUtil.bytes2Hex(bs, false)); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | private void sendReportData(){ |
| | | TcpClUnit.clientSendData(); |
| | | try{ |
| | | byte[] bs = this.createReport() ; |
| | | this.session.write(bs) ; |
| | | log.info("RTU" + rtuAddr + "åéäºä¸æ¥æ°æ®ï¼" + ByteUtil.bytes2Hex(bs, false)); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | private void jobOver(){ |
| | | CloseFuture closeFuture = session.closeOnFlush() ; |
| | | session.closeOnFlush() ; |
| | | this.isOver = true ; |
| | | TcpClUnit.clientOver() ; |
| | | } |
| | | |
| | | /** |
| | | * æé ä¸è¡æ°æ® |
| | | * æé å¿è·³æ°æ® |
| | | * @return åèæ°ç» |
| | | * @throws Exception å¼å¸¸ |
| | | */ |
| | |
| | | bsHead[index] = ProtocolConstantV206V1_0_0.P_Head_Byte ; |
| | | |
| | | index++ ; |
| | | bsHead[index] = commonV1_0_1.createCtrl((byte)0) ; |
| | | bsHead[index] = commonV1_0_1.createCtrl((byte)0x80, (byte)0) ;//æ§å¶ååè½ç ï¼ç¡®è®¤ è®¤å¯ |
| | | |
| | | index++ ; |
| | | GlCreate.createRtuAddr(this.rtuAddr, bsHead, index); |
| | |
| | | |
| | | GlCreate.createLen(bytes);//é¿åº¦æ¾åèæ°ç»ä¸ |
| | | |
| | | bytes = GlCreate.createCrcTail(bytes) ;//CRCåå°¾å å åèæ°ç»ä¸ |
| | | byte[] bsTail = GlCreate.createCrcTail(bytes) ;//CRCåå°¾å å åèæ°ç»ä¸ |
| | | |
| | | bytes = ByteUtil.bytesMerge(bytes, bsTail) ; |
| | | |
| | | return bytes ; |
| | | } |
| | | |
| | | /** |
| | | * æé 䏿¥æ°æ® |
| | | * @return åèæ°ç» |
| | | * @throws Exception å¼å¸¸ |
| | | */ |
| | | public byte[] createReport( ) throws Exception { |
| | | CommonV1_0_1 commonV1_0_1 = new CommonV1_0_1() ; |
| | | byte[] bytes ; |
| | | byte[] bsHead = new byte[ProtocolConstantV206V1_0_0.lenHead2Code] ; |
| | | byte index = 0 ; |
| | | bsHead[index] = ProtocolConstantV206V1_0_0.P_Head_Byte ; |
| | | |
| | | index++ ; |
| | | bsHead[index] = 0 ;//帧é¿åº¦ |
| | | |
| | | index++ ; |
| | | bsHead[index] = ProtocolConstantV206V1_0_0.P_Head_Byte ; |
| | | |
| | | index++ ; |
| | | bsHead[index] = commonV1_0_1.createCtrl((byte)0x80, (byte)3) ;//æ§å¶ååè½ç 3ï¼èªæ¥å¸§ï¼æµéï¼æ°´éï¼åæ° |
| | | |
| | | index++ ; |
| | | GlCreate.createRtuAddr(this.rtuAddr, bsHead, index); |
| | | index += 5 ; |
| | | |
| | | ByteUtil.hex2Bytes("C0", bsHead, index) ; |
| | | |
| | | byte[] bs = new byte[2] ; |
| | | bs[0] = (byte)0x04 ;//ææµéæ°æ® |
| | | bs[1] = (byte)0xE0 ;//ææ°´åãçµæ± çµåãä¿¡å·å¼ºåº¦ |
| | | |
| | | bytes = ByteUtil.bytesMerge(bsHead, bs) ; |
| | | |
| | | bs = new byte[5] ;//ç¬æ¶æµé |
| | | bs[0] = ByteUtil.int2BCD_LE (21)[0] ; |
| | | bs[1] = ByteUtil.int2BCD_LE (43)[0] ; |
| | | bs[2] = ByteUtil.int2BCD_LE (65)[0] ; |
| | | bytes = ByteUtil.bytesMerge(bytes, bs) ; |
| | | |
| | | bs = new byte[5] ;//累计æµé |
| | | bs[0] = ByteUtil.int2BCD_LE (21)[0] ; |
| | | bs[1] = ByteUtil.int2BCD_LE (43)[0] ; |
| | | bs[2] = ByteUtil.int2BCD_LE (65)[0] ; |
| | | bs[3] = ByteUtil.int2BCD_LE (87)[0] ; |
| | | bytes = ByteUtil.bytesMerge(bytes, bs) ; |
| | | |
| | | bs = new byte[5] ;//æå¤±æµé |
| | | bs[0] = ByteUtil.int2BCD_LE (10)[0] ; |
| | | bs[1] = ByteUtil.int2BCD_LE (32)[0] ; |
| | | bs[2] = ByteUtil.int2BCD_LE (54)[0] ; |
| | | bytes = ByteUtil.bytesMerge(bytes, bs) ; |
| | | |
| | | bs = new byte[4] ;//æ°´å |
| | | bs[0] = ByteUtil.int2BCD_LE (10)[0] ; |
| | | bs[1] = ByteUtil.int2BCD_LE (32)[0] ; |
| | | bs[2] = ByteUtil.int2BCD_LE (4)[0] ; |
| | | bytes = ByteUtil.bytesMerge(bytes, bs) ; |
| | | |
| | | bs = new byte[4] ;//çµæ± çµå |
| | | bs[0] = ByteUtil.int2BCD_LE (10)[0] ; |
| | | bs[1] = ByteUtil.int2BCD_LE (32)[0] ; |
| | | bs[2] = ByteUtil.int2BCD_LE (10)[0] ; |
| | | bs[3] = ByteUtil.int2BCD_LE (32)[0] ; |
| | | bytes = ByteUtil.bytesMerge(bytes, bs) ; |
| | | |
| | | bs = new byte[1] ;//ä¿¡å·å¼ºåº¦ |
| | | bs[0] = ByteUtil.int2BCD_LE (21)[0] ; |
| | | bytes = ByteUtil.bytesMerge(bytes, bs) ; |
| | | |
| | | bs = new byte[6] ;//æ¶é |
| | | GlCreate.createTp(bs, 0); |
| | | bytes = ByteUtil.bytesMerge(bytes, bs) ; |
| | | |
| | | GlCreate.createLen(bytes);//é¿åº¦æ¾åèæ°ç»ä¸ |
| | | |
| | | byte[] bsTail = GlCreate.createCrcTail(bytes) ;//CRCåå°¾å å åèæ°ç»ä¸ |
| | | |
| | | bytes = ByteUtil.bytesMerge(bytes, bsTail) ; |
| | | |
| | | return bytes ; |
| | | } |
| | |
| | | import com.dy.common.mw.UnitStartedCallbackInterface; |
| | | import com.dy.common.threadPool.ThreadPool; |
| | | import com.dy.common.threadPool.TreadPoolFactory; |
| | | import com.dy.common.util.Callback; |
| | | import com.dy.testClient.ServerProperties; |
| | | import com.dy.testClient.rmiClient.RmiClUnit; |
| | | import org.apache.logging.log4j.LogManager; |
| | | import org.apache.logging.log4j.Logger; |
| | | import org.apache.mina.core.session.IoSession; |
| | | |
| | | import java.util.Collection; |
| | | import java.util.HashMap; |
| | |
| | | private static ThreadPool.Pool pool ; |
| | | private static Map<String, MyThreadJob> jobMap = new HashMap<>() ; |
| | | |
| | | private static Integer totalRunedClientCount = 0; |
| | | private static Integer totalRtuClientCount = 0; |
| | | private static Integer totalSendDataCount = 0; |
| | | private static Integer totalOverClientCount = 0; |
| | | |
| | |
| | | if(!ServerProperties.startWork){ |
| | | Thread.sleep(100L); |
| | | }else{ |
| | | startTime = System.currentTimeMillis() ; |
| | | for(Long addr = ServerProperties.rtuAddrStart; addr <= ServerProperties.rtuAddrEnd; addr++){ |
| | | totalRunedClientCount++ ; |
| | | createImitate(addr) ; |
| | | } |
| | | startJob() ; |
| | | while(true){ |
| | | if(totalOverClientCount.longValue() >= totalRunedClientCount.longValue()){ |
| | | Long seconds = (System.currentTimeMillis() - startTime)/1000 ; |
| | | RmiClUnit.getInstance().allOver(seconds) ; |
| | | System.out.println("å
±ç¨æ¶" + seconds + "ç§"); |
| | | break ; |
| | | }else{ |
| | | Thread.sleep(100L); |
| | | try{ |
| | | startTime = System.currentTimeMillis() ; |
| | | for(Long addr = ServerProperties.rtuAddrStart; addr <= ServerProperties.rtuAddrEnd; addr++){ |
| | | totalRtuClientCount++ ; |
| | | createImitate(addr) ; |
| | | } |
| | | log.info("å
±æ¨¡æäº" + totalRtuClientCount + "å°RTU"); |
| | | |
| | | Collection<MyThreadJob> collection = jobMap.values() ; |
| | | for(MyThreadJob job : collection){ |
| | | connectServer(job) ; |
| | | } |
| | | log.info("å¯å¨ææRTUè¿æ¥éä¿¡ä¸é´ä»¶"); |
| | | |
| | | while (true){ |
| | | int noConnectedCount = checkConnected() ; |
| | | if(noConnectedCount > 0){ |
| | | log.info("çå¾
" + noConnectedCount + "å°RTUè¿æ¥ç½ç»"); |
| | | Thread.sleep(100L); |
| | | }else{ |
| | | break ; |
| | | } |
| | | } |
| | | |
| | | startJob() ; |
| | | while(true){ |
| | | if(totalOverClientCount.longValue() >= totalRtuClientCount.longValue()){ |
| | | Long seconds = (System.currentTimeMillis() - startTime)/1000 ; |
| | | RmiClUnit.getInstance().allOver(seconds) ; |
| | | log.info("å
±ç¨æ¶" + seconds + "ç§"); |
| | | break ; |
| | | }else{ |
| | | Thread.sleep(100L); |
| | | } |
| | | } |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | }finally { |
| | | break ; |
| | | } |
| | | break; |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | |
| | | jobMap.put("" + rtuAddr, new MyThreadJob("" + rtuAddr, ServerProperties.tcpServerIp, ServerProperties.tcpServerPort)) ; |
| | | } |
| | | |
| | | |
| | | private void connectServer(MyThreadJob job){ |
| | | if(job.session == null){ |
| | | try{ |
| | | new TcpConnect().createSession(job.rtuAddr, |
| | | job, |
| | | job.serverIp, |
| | | job.serverPort, |
| | | job.connectTimeout, |
| | | new TcpHandler(), |
| | | new Callback() { |
| | | @Override |
| | | public void call(Object obj) { |
| | | if(obj == null){ |
| | | log.error("å建ç½ç»ä¼è¯è¿å为null"); |
| | | }else{ |
| | | job.session = (IoSession)obj ; |
| | | } |
| | | } |
| | | @Override |
| | | public void call(Object... objs) { |
| | | } |
| | | @Override |
| | | public void exception(Exception e) { |
| | | } |
| | | }) ; |
| | | }catch (Exception e){ |
| | | job.exceptionOnConnect = true ; |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | private int checkConnected(){ |
| | | int noConnectedCount = 0 ; |
| | | Collection<MyThreadJob> collection = jobMap.values() ; |
| | | for(MyThreadJob job : collection){ |
| | | if(job.session == null && !job.exceptionOnConnect){ |
| | | noConnectedCount++ ; |
| | | } |
| | | } |
| | | return noConnectedCount; |
| | | } |
| | | |
| | | private void startJob(){ |
| | | new Thread(new Runnable(){ |
| | | @Override |
| | | public void run() { |
| | | try { |
| | | Thread.sleep(1000L); |
| | | int notOverCount; |
| | | while(true){ |
| | | notOverCount = 0 ; |
| | | Collection<MyThreadJob> collection = jobMap.values() ; |
| | | for(MyThreadJob job : collection){ |
| | | pool.putJob(job); |
| | | if(!job.isOver){ |
| | | notOverCount++ ; |
| | | pool.putJob(job); |
| | | } |
| | | } |
| | | Thread.sleep(ServerProperties.sendInterval * 1000); |
| | | if(notOverCount > 0){ |
| | | log.info("å½åè¿æ" + notOverCount + "å°RTUæªå®æä»»å¡"); |
| | | Thread.sleep(ServerProperties.sendInterval * 1000); |
| | | }else{ |
| | | break ; |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | |
| | | |
| | | public static synchronized void clientSendData(){ |
| | | totalSendDataCount++; |
| | | if(totalSendDataCount % 100 == 0){ |
| | | if(totalOverClientCount.longValue() >= totalRtuClientCount.longValue()){ |
| | | RmiClUnit.getInstance().reportHadReportCount(totalSendDataCount); |
| | | System.out.println("å·²ç»åé" + totalSendDataCount + "æ¡æ°æ®"); |
| | | }else{ |
| | | if(totalRtuClientCount > 100){ |
| | | if(totalSendDataCount % 100 == 0){ |
| | | RmiClUnit.getInstance().reportHadReportCount(totalSendDataCount); |
| | | System.out.println("å·²ç»åé" + totalSendDataCount + "æ¡æ°æ®"); |
| | | } |
| | | }else{ |
| | | RmiClUnit.getInstance().reportHadReportCount(totalSendDataCount); |
| | | System.out.println("å·²ç»åé" + totalSendDataCount + "æ¡æ°æ®"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | public static synchronized void clientOver(){ |
| | | totalOverClientCount++; |
| | | if(totalOverClientCount % 100 == 0){ |
| | | if(totalOverClientCount.longValue() >= totalRtuClientCount.longValue()){ |
| | | RmiClUnit.getInstance().reportHadReportOver(totalOverClientCount); |
| | | System.out.println("å·²æ" + totalOverClientCount + "宿äºä»»å¡"); |
| | | System.out.println("å·²æ" + totalOverClientCount + "个RTU宿äºä»»å¡"); |
| | | }else{ |
| | | if(totalRtuClientCount > 100) { |
| | | if (totalOverClientCount % 100 == 0) { |
| | | RmiClUnit.getInstance().reportHadReportOver(totalOverClientCount); |
| | | System.out.println("å·²æ" + totalOverClientCount + "个RTU宿äºä»»å¡"); |
| | | } |
| | | }else{ |
| | | RmiClUnit.getInstance().reportHadReportOver(totalOverClientCount); |
| | | System.out.println("å·²æ" + totalOverClientCount + "个RTU宿äºä»»å¡"); |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | package com.dy.testClient.tcpClient; |
| | | |
| | | import com.dy.common.util.Callback; |
| | | import org.apache.mina.core.future.ConnectFuture; |
| | | import org.apache.mina.core.session.IoSession; |
| | | import org.apache.mina.filter.codec.ProtocolCodecFilter; |
| | |
| | | * @param job rtuå·¥ä½ç±» |
| | | * @param host æå¡å¨URI |
| | | * @param port æå¡å¨ç«¯å£ |
| | | * @param connectTimeout è¿æ¥è¶
æ¶æ¶é¿ |
| | | * @param handler æ°æ®å¤çè
|
| | | * @param callback åè° |
| | | * @return ç½ç»ä¼è¯ |
| | | */ |
| | | public IoSession createSession(String rtuAddr, MyThreadJob job, String host , int port , int connectTimeout , TcpHandler handler) throws Exception{ |
| | | public void createSession(String rtuAddr, |
| | | MyThreadJob job, |
| | | String host , |
| | | int port , |
| | | int connectTimeout , |
| | | TcpHandler handler, |
| | | Callback callback) throws Exception{ |
| | | SocketConnector connector = new NioSocketConnector(); |
| | | connector.getFilterChain().addLast("codec", new ProtocolCodecFilter(new LocalCodecFactory())); |
| | | connector.setHandler(handler); |
| | |
| | | IoSession se = connectFuture.getSession(); |
| | | se.setAttribute(rtuAddrKey, rtuAddr) ; |
| | | se.setAttribute(threadJobKey, job) ; |
| | | return se ; |
| | | callback.call(se) ; |
| | | } |
| | | |
| | | |
| | |
| | | if(sta.count != null){ |
| | | prtWrt.println(" å·²ç»ä¸æ¥æ°æ®ï¼" + sta.count + "æ¡"); |
| | | } |
| | | if(sta.overCount != null){ |
| | | prtWrt.println(" å·²ç»å®æä¸æ¥æ°æ®ï¼" + sta.overCount + "å°RTU"); |
| | | } |
| | | if(sta.over != null && sta.over){ |
| | | prtWrt.println(" 䏿¥æ°æ®å·²ç»å®æï¼å
±ç¨æ¶ï¼" + sta.seconds + "ç§"); |
| | | } |
| | |
| | | MwTestClientStatus sta = token2ClientMap.get("" + token); |
| | | if(sta == null){ |
| | | sta = new MwTestClientStatus() ; |
| | | sta.overCount = rqVo.count ; |
| | | sta.overCount = rqVo.overCount ; |
| | | token2ClientMap.put("" + token, sta); |
| | | }else{ |
| | | sta.count = rqVo.count ; |
| | | sta.overCount = rqVo.overCount ; |
| | | } |
| | | } |
| | | |
New file |
| | |
| | | package com.dy.testServer.forRmi; |
| | | |
| | | import com.alibaba.fastjson2.JSON; |
| | | |
| | | public class RmiRequestVo { |
| | | |
| | | public String id ;//客æ·ç«¯ID |
| | | |
| | | public String token ;//æå¡ç«¯åé
çtoken |
| | | |
| | | public String code ; |
| | | |
| | | public Integer count;//mwTest䏿¥æ°æ®æ°é |
| | | |
| | | public Integer overCount;//aepTestç»æä¸æ¥æ°æ®æ°é |
| | | |
| | | public Boolean over ;//mwTest䏿¥æ°æ®ç»æ |
| | | |
| | | public Long seconds ;//mwTest䏿¥æ°æ®ç¨æ¶(ç§) |
| | | |
| | | /** |
| | | * 对象转æjson |
| | | * @return json |
| | | * @throws Exception å¼å¸¸ |
| | | */ |
| | | public String toJson()throws Exception{ |
| | | try{ |
| | | return JSON.toJSONString(this) ; |
| | | //return new JSONSerializer().exclude(new String[]{"class", "*.class"}).deepSerialize(this); |
| | | }catch(Exception e){ |
| | | throw new Exception(e.getMessage() , e ) ; |
| | | } |
| | | } |
| | | /** |
| | | * json转æå¯¹è±¡ |
| | | * @param json åæ° |
| | | * @return 对象 |
| | | * @throws Exception å¼å¸¸ |
| | | */ |
| | | public static RmiRequestVo jsonToObject(String json)throws Exception{ |
| | | try{ |
| | | return JSON.parseObject(json, RmiRequestVo.class) ; |
| | | //JSONDeserializer<RmiRequestVo> jsonD = new JSONDeserializer<>() ; |
| | | //RmiRequestVo rqVo = jsonD.deserialize(json, RmiRequestVo.class) ; |
| | | //return rqVo ; |
| | | }catch(Exception e){ |
| | | throw new Exception(e.getMessage() , e ) ; |
| | | } |
| | | } |
| | | |
| | | public String getId() { |
| | | return id; |
| | | } |
| | | public void setId(String id) { |
| | | this.id = id; |
| | | } |
| | | public String getToken() { |
| | | return token; |
| | | } |
| | | public void setToken(String id) { |
| | | this.token = id; |
| | | } |
| | | public String getCode() { |
| | | return code; |
| | | } |
| | | |
| | | public void setCode(String code) { |
| | | this.code = code; |
| | | } |
| | | public Integer getCount() { |
| | | return count; |
| | | } |
| | | public void setCount(Integer count) { |
| | | this.count = count; |
| | | } |
| | | public Boolean getOver() { |
| | | return over; |
| | | } |
| | | public void setOver(Boolean over) { |
| | | this.over = over; |
| | | } |
| | | public Long getSeconds() { |
| | | return seconds; |
| | | } |
| | | public void setSeconds(Long seconds) { |
| | | this.seconds = seconds; |
| | | } |
| | | |
| | | public Integer getOverCount() { |
| | | return overCount; |
| | | } |
| | | |
| | | public void setOverCount(Integer overCount) { |
| | | this.overCount = overCount; |
| | | } |
| | | } |