1、RTU模拟测试系统开发;
2、RTU模拟测试系统管控系统开发;
3、联合测试中发现的协议bug修改;
4、联合测试中发现通信中间件的bug修改。
15 文件已重命名
27个文件已修改
6个文件已添加
1个文件已删除
| | |
| | | |
| | | 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 æ°æ®é¿åº¦ |
| | | * @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{ |
| | | return ByteUtilUnsigned.bytes2Short_BE(bs, ProtocolConstantV206V1_0_0.dataLenIndex) ; |
| | | int len = ByteUtilUnsigned.byte2Byte(bs, ProtocolConstantV206V1_0_0.dataLenIndex) ; |
| | | return len + ProtocolConstantV206V1_0_0.lenHead2ctrl + ProtocolConstantV206V1_0_0.lenTail ; |
| | | } |
| | | |
| | | |
| | |
| | | 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() < 6){ |
| | | while(rtuAddrStr.length() < 4){ |
| | | rtuAddrStr = "0" + rtuAddrStr ; |
| | | } |
| | | return rtuAddrBCD + rtuAddrStr ; |
| | |
| | | return ByteUtil.bytes2Hex(bs, false, ProtocolConstantV206V1_0_0.codeIndex, 1) ; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * æ ¡éªåæ£æ¥ |
| | | * @param bs ä¸è¡åèæ°ç» |
| | | * @return éè¿true,æªéè¿false |
| | | */ |
| | | public boolean checkCrc(byte[] bs) { |
| | | byte he = 0 ; |
| | | for(int i = 0 ; i <= bs.length - 3 ; i++){ |
| | | he = (byte)(he + bs[i]) ; |
| | | } |
| | | return bs[bs.length - 2] == he ; |
| | | } |
| | | |
| | | /** |
| | | * æ ¡éªåæ£æ¥ |
| | | * @param bs ä¸è¡åèæ°ç» |
| | |
| | | * @throws Exception å¼å¸¸ |
| | | */ |
| | | public String checkCrc_str(byte[] bs) throws Exception { |
| | | byte[] he = new byte[1] ; |
| | | for(int i = 0 ; i <= bs.length - 3 ; i++){ |
| | | he[0] = (byte)(he[0] + bs[i]) ; |
| | | } |
| | | short hes = ByteUtilUnsigned.byte2Byte(he, 0); |
| | | short heOrg = ByteUtilUnsigned.byte2Byte(bs, bs.length - 2); |
| | | if(hes == heOrg){ |
| | | 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 "è®¡ç®æ ¡éªåæ¯:" + hes + "ï¼ä¸ä¼ æ ¡éªåæ¯" + heOrg ; |
| | | return "计ç®CRCæ¯:" + crcCompute + "ï¼ä¸ä¼ CRCæ¯" + crcInBs ; |
| | | } |
| | | } |
| | | |
| | |
| | | D7 D6 D5ï½D4 D3ï½D0 |
| | | ä¼ è¾æ¹åä½ DIR æåæ å¿ä½ DIV 帧计æ°ä½ FCB åè½ç |
| | | */ |
| | | public byte createCtrl(byte funcCode){ |
| | | byte b = 0 ; |
| | | public byte createCtrl(byte dir, byte funcCode){ |
| | | byte b = dir;//(byte)0x80//æ§å¶åï¼DIR=1ï¼è¡¨ç¤ºæ¤å¸§æ¥ææ¯ç±ç»ç«¯ååºçä¸è¡æ¥æï¼ |
| | | b = (byte)(b | funcCode) ; |
| | | //FCB == 3 |
| | | b = (byte)(b | (byte)60) ; |
| | | b = (byte)(b | (byte)0x18) ; |
| | | //DIV = 0 |
| | | //DIR = 0 |
| | | return b ; |
| | |
| | | sb.append(" æ§å¶å¨æ¶éï¼"); |
| | | sb.append(rtuDt==null?"":rtuDt); |
| | | sb.append("\n"); |
| | | sb.append(alarmVo==null?"":alarmVo.toString()); |
| | | sb.append("\n"); |
| | | sb.append(stateVo==null?"":stateVo.toString()); |
| | | 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() ; |
| | | } |
| | |
| | | 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() ; |
| | | } |
| | | } |
| | |
| | | @AnnotationDriver(name= ProtocolConstantV206V1_0_0.protocolName) |
| | | public class DriverV1_0_1 extends Driver { |
| | | |
| | | private static String scanRootPackage = "" ; |
| | | private static String scanRootPackage = "com.dy.common.mw.protocol.p206V1_0_0." ; |
| | | |
| | | //å¨Driver䏿¯åä¾ï¼éDriverçåä¾å¯¹è±¡å¨å线ç¨ä¸è¿è¡ |
| | | private ParseParamsForUpV1_0_1 upCpParams ; |
| | |
| | | return null ; |
| | | } |
| | | |
| | | Integer dataLen = parseCommon.parseDataLen(preByte) ; |
| | | Integer dataLen = parseCommon.parseFrameLen(preByte) ; |
| | | |
| | | if(dataLen == null){ |
| | | String headHex = ByteUtil.bytes2Hex(preByte, true) ; |
| | |
| | | * RTUä¸çº¿æ°æ®ï¼ä¸çº¿å第ä¸å
æ°æ®ï¼æå°é¿åº¦ï¼è®¾ç½®è¯¥å±æ§ä»¥å¤è¿è¡å®æ´æ§æ£æ¥ï¼ |
| | | * 峿å
æ£æ¥ï¼ä½¿å°½å¯è½æ¶å
¨ä¸çº¿æ°æ®ï¼åå¼èå´1-100ï¼ |
| | | */ |
| | | public static final int onLineDataMinLength = 30 ;//éç¨éæ§åæ§ï¼å
¶é¿åº¦æçï¼çåèæ° |
| | | public static final int onLineDataMinLength = 13 ;//éç¨å¿è·³ä¸è¡æ°æ®é¿åº¦ |
| | | |
| | | /** |
| | | * RTU䏿¥æ°æ®ç头鍿å°é¿åº¦ï¼ä¸æ¥æ°æ®ä¸ï¼åè¿ä¸ªæå°é¿åº¦çé¨åæ°æ®ä¸ï¼ |
| | |
| | | public static final String P_Head_Hex = "68" ; |
| | | public static final String P_Tail_Hex = "16" ; |
| | | |
| | | public static final byte lenHead2Code = 10 ; //ä»å¤´å°åè½ç åèæ°ç»é¿åº¦ |
| | | public static final byte lenHead2ctrl = 3 ; //ä»å¤´å°æ§å¶åï¼ä¸å
æ¬ï¼åèæ°ç»é¿åº¦ |
| | | public static final byte lenHead2Code = 10 ; //ä»å¤´å°åè½ç ï¼å
æ¬ï¼åèæ°ç»é¿åº¦ |
| | | public static final byte lenTail = 2 ; //帧尾é¨åèæ°ç»é¿åº¦ |
| | | /** |
| | | * æå¨åèæ°ç»çä½ç½®ï¼ä¸æ ï¼ |
| | |
| | | bsHead[index] = ProtocolConstantV206V1_0_0.P_Head_Byte ; |
| | | |
| | | index++ ; |
| | | bsHead[index] = commonV1_0_1.createCtrl((byte)0) ; |
| | | bsHead[index] = commonV1_0_1.createCtrl((byte)0, (byte)0) ; |
| | | |
| | | index++ ; |
| | | GlCreate.createRtuAddr(para.rtuAddr, bsHead, index); |
| | |
| | | |
| | | GlCreate.createLen(bytes);//é¿åº¦æ¾åèæ°ç»ä¸ |
| | | |
| | | bytes = GlCreate.createCrcTail(bytes) ;//CRCåå°¾å å åèæ°ç»ä¸ |
| | | byte[] bsTail = GlCreate.createCrcTail(bytes) ;//CRCåå°¾å å åèæ°ç»ä¸ |
| | | |
| | | bytes = ByteUtil.bytesMerge(bytes, bsTail) ; |
| | | |
| | | return bytes ; |
| | | } |
| | |
| | | bsHead[index] = ProtocolConstantV206V1_0_0.P_Head_Byte ; |
| | | |
| | | index++ ; |
| | | bsHead[index] = commonV1_0_1.createCtrl((byte)0) ; |
| | | bsHead[index] = commonV1_0_1.createCtrl((byte)0, (byte)0) ; |
| | | |
| | | index++ ; |
| | | GlCreate.createRtuAddr(para.rtuAddr, bsHead, index); |
| | |
| | | |
| | | GlCreate.createLen(bytes);//é¿åº¦æ¾åèæ°ç»ä¸ |
| | | |
| | | bytes = GlCreate.createCrcTail(bytes) ;//CRCåå°¾å å åèæ°ç»ä¸ |
| | | byte[] bsTail = GlCreate.createCrcTail(bytes) ;//CRCåå°¾å å åèæ°ç»ä¸ |
| | | |
| | | bytes = ByteUtil.bytesMerge(bytes, bsTail) ; |
| | | |
| | | return bytes ; |
| | | } |
| | |
| | | bsHead[index] = ProtocolConstantV206V1_0_0.P_Head_Byte ; |
| | | |
| | | index++ ; |
| | | bsHead[index] = commonV1_0_1.createCtrl((byte)0) ; |
| | | bsHead[index] = commonV1_0_1.createCtrl((byte)0, (byte)0) ; |
| | | |
| | | index++ ; |
| | | GlCreate.createRtuAddr(para.rtuAddr, bsHead, index); |
| | |
| | | |
| | | GlCreate.createLen(bytes);//é¿åº¦æ¾åèæ°ç»ä¸ |
| | | |
| | | bytes = GlCreate.createCrcTail(bytes) ;//CRCåå°¾å å åèæ°ç»ä¸ |
| | | byte[] bsTail = GlCreate.createCrcTail(bytes) ;//CRCåå°¾å å åèæ°ç»ä¸ |
| | | |
| | | bytes = ByteUtil.bytesMerge(bytes, bsTail) ; |
| | | |
| | | return bytes ; |
| | | } |
| | |
| | | bsHead[index] = ProtocolConstantV206V1_0_0.P_Head_Byte ; |
| | | |
| | | index++ ; |
| | | bsHead[index] = commonV1_0_1.createCtrl((byte)0) ; |
| | | bsHead[index] = commonV1_0_1.createCtrl((byte)0, (byte)0) ; |
| | | |
| | | index++ ; |
| | | GlCreate.createRtuAddr(para.rtuAddr, bsHead, index); |
| | |
| | | |
| | | GlCreate.createLen(bytes);//é¿åº¦æ¾åèæ°ç»ä¸ |
| | | |
| | | bytes = GlCreate.createCrcTail(bytes) ;//CRCåå°¾å å åèæ°ç»ä¸ |
| | | byte[] bsTail = GlCreate.createCrcTail(bytes) ;//CRCåå°¾å å åèæ°ç»ä¸ |
| | | |
| | | bytes = ByteUtil.bytesMerge(bytes, bsTail) ; |
| | | |
| | | return bytes ; |
| | | } |
| | |
| | | bsHead[index] = ProtocolConstantV206V1_0_0.P_Head_Byte ; |
| | | |
| | | index++ ; |
| | | bsHead[index] = commonV1_0_1.createCtrl((byte)0) ; |
| | | bsHead[index] = commonV1_0_1.createCtrl((byte)0, (byte)0) ; |
| | | |
| | | index++ ; |
| | | GlCreate.createRtuAddr(para.rtuAddr, bsHead, index); |
| | |
| | | |
| | | GlCreate.createLen(bytes);//é¿åº¦æ¾åèæ°ç»ä¸ |
| | | |
| | | bytes = GlCreate.createCrcTail(bytes) ;//CRCåå°¾å å åèæ°ç»ä¸ |
| | | byte[] bsTail = GlCreate.createCrcTail(bytes) ;//CRCåå°¾å å åèæ°ç»ä¸ |
| | | |
| | | bytes = ByteUtil.bytesMerge(bytes, bsTail) ; |
| | | |
| | | return bytes ; |
| | | } |
| | |
| | | String rtuAddr1 = rtuAddr.substring(0, 6) ; |
| | | String rtuAddr2 = rtuAddr.substring(6) ; |
| | | |
| | | index++ ; |
| | | ByteUtil.string2BCD_BE(bs, rtuAddr1, index) ; |
| | | index += 3 ; |
| | | |
| | |
| | | } |
| | | |
| | | public static void createTp(byte[] bs, int index) throws Exception { |
| | | ByteUtil.string2BCD_BE(bs, DateTime.yyMMddhhmmss(), index) ; |
| | | ByteUtil.string2BCD_LE(bs, DateTime.yyMMddhhmmss(), index) ; |
| | | } |
| | | |
| | | public static void createLen(byte[] bs) throws Exception { |
| | | int len = bs.length + ProtocolConstantV206V1_0_0.lenTail; |
| | | bs[ProtocolConstantV206V1_0_0.dataLenIndex] = (byte)len ; |
| | | 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[] bs) throws Exception { |
| | | int crc = new CRC8_for_2_0().CRC8(bs, ProtocolConstantV206V1_0_0.ctrlIndex, bs.length -1) ; |
| | | bs = new byte[ProtocolConstantV206V1_0_0.lenTail] ; |
| | | bs[0] = (byte)crc ; |
| | | bs[1] = ProtocolConstantV206V1_0_0.P_Tail_Byte ; |
| | | return ByteUtil.bytesMerge(bs, bs) ; |
| | | 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 ; |
| | | } |
| | | } |
| | |
| | | index++ ; |
| | | dt = ByteUtil.BCD2String_BE(bs, index, index) + ":" + dt ;//å |
| | | index++ ; |
| | | dt = ByteUtil.BCD2String_BE(bs, index, index) + " " + dt ;//æ¶ |
| | | dt = ByteUtil.BCD2String_BE(bs, index, index) + ":" + dt ;//æ¶ |
| | | index++ ; |
| | | dt = ByteUtil.BCD2String_BE(bs, index, index) + "-" + dt ;//æ¥ |
| | | dt = ByteUtil.BCD2String_BE(bs, index, index) + " " + dt ;//æ¥ |
| | | index++ ; |
| | | bs[index] = (byte)(bs[index] & 0x10); |
| | | dt = ByteUtil.BCD2String_BE(bs, index, index) + "-" + dt ;//æ |
| | |
| | | <scope>test</scope> |
| | | </dependency> |
| | | </dependencies> |
| | | |
| | | <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.tasks.BusiConstantTask; |
| | | 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) ; |
| | | //ä¸ä¸è¡æ°æ®ç¼åéåä¸ç¼åæ°æ®ä¸ªæ°çæå¤§å¼ï¼è¿ä¸ªä¸ç°å®é¡¹ç®ææ¥æ°´è¡¨æ°ç¸å
³ |
| | |
| | | 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) ; |
| | | |
| | |
| | | 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) ; |
| | | |
| | | |
| | | |
| | | // /////////////// |
| | | // æ ¸å¿ |
| | |
| | | CoreUnit coreUnit = CoreUnit.getInstance(); |
| | | coreUnit.setAdapter(coreAdap); |
| | | CoreUnit.addConstantTask(new ToRtuConstantTask()); |
| | | CoreUnit.addConstantTask(new BusiConstantTask()); |
| | | 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.busi.AboutRtuNode; |
| | | import com.dy.aceMw.server.busi.TcpUpDataCache; |
| | | 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; |
| | | |
| | |
| | | */ |
| | | private void nextDeal(boolean reportOrResponse_trueOrFalse, MidResultFromRtu resFromRtu){ |
| | | try{ |
| | | TcpUpDataCache.cacheRtuUpData(reportOrResponse_trueOrFalse, new AboutRtuNode(resFromRtu.data)); |
| | | RtuDataCache.cacheRtuUpData(reportOrResponse_trueOrFalse, new RtuDataNode(resFromRtu.data)); |
| | | }catch(Exception e){ |
| | | log.error(e.getMessage(), e); |
| | | } |
File was renamed from pipIrr-platform/pipIrr-mw/pipIrr-mw-accept/src/main/java/com/dy/aceMw/server/busi/TcpUpDataCache.java |
| | |
| | | package com.dy.aceMw.server.busi; |
| | | 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 TcpUpDataCache { |
| | | public class RtuDataCache { |
| | | |
| | | //TCPä¸è¡å½ä»¤ç¼åéå |
| | | private static Queue cacheQueue = new Queue("tcpUpDataQueue") ; |
| | | |
| | | private static TcpUpDataCache instance = new TcpUpDataCache() ; |
| | | private static RtuDataCache instance = new RtuDataCache() ; |
| | | |
| | | private TcpUpDataCache(){ |
| | | private RtuDataCache(){ |
| | | cacheQueue.setLimit(ServerProperties.cacheUpDownDataWarnCount, ServerProperties.cacheUpDownDataMaxCount); |
| | | } |
| | | |
| | | public static TcpUpDataCache getInstance(){ |
| | | public static RtuDataCache getInstance(){ |
| | | return instance ; |
| | | } |
| | | |
| | |
| | | * @param node node |
| | | * @throws Exception å¼å¸¸ |
| | | */ |
| | | public static void cacheRtuUpData(boolean reportOrResponse_trueOrFalse, AboutRtuNode 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); |
File was renamed from pipIrr-platform/pipIrr-mw/pipIrr-mw-accept/src/main/java/com/dy/aceMw/server/busi/AboutRtuNode.java |
| | |
| | | package com.dy.aceMw.server.busi; |
| | | package com.dy.aceMw.server.rtuData; |
| | | |
| | | import com.dy.aceMw.server.busi.deal.TaskPool; |
| | | import com.dy.aceMw.server.busi.deal.TaskSurpport; |
| | | 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 AboutRtuNode implements NodeObj { |
| | | public class RtuDataNode implements NodeObj { |
| | | |
| | | private static final Logger log = LogManager.getLogger(AboutRtuNode.class.getName()); |
| | | private static final Logger log = LogManager.getLogger(RtuDataNode.class.getName()); |
| | | |
| | | public Object obj ;//æ°æ® |
| | | |
| | | public AboutRtuNode(Object obj){ |
| | | public RtuDataNode(Object obj){ |
| | | this.obj = obj ; |
| | | } |
| | | /** |
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 { |
| | | |
| | | } |
File was renamed from pipIrr-platform/pipIrr-mw/pipIrr-mw-accept/src/main/java/com/dy/aceMw/server/busi/deal/Task.java |
| | |
| | | package com.dy.aceMw.server.busi.deal; |
| | | package com.dy.aceMw.server.rtuData; |
| | | |
| | | public interface Task { |
| | | |
File was renamed from pipIrr-platform/pipIrr-mw/pipIrr-mw-accept/src/main/java/com/dy/aceMw/server/busi/deal/TaskConfig.java |
| | |
| | | package com.dy.aceMw.server.busi.deal; |
| | | package com.dy.aceMw.server.rtuData; |
| | | |
| | | |
| | | public class TaskConfig { |
File was renamed from pipIrr-platform/pipIrr-mw/pipIrr-mw-accept/src/main/java/com/dy/aceMw/server/busi/deal/TaskPool.java |
| | |
| | | package com.dy.aceMw.server.busi.deal; |
| | | package com.dy.aceMw.server.rtuData; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | |
| | | if (c == null) { |
| | | throw new Exception("å®ä¾åä¸è¡æ°æ®å¤çä»»å¡å¯¹è±¡æ 失败ï¼ä»»å¡ç±»ä¸º" + clazz + "ï¼"); |
| | | }else{ |
| | | return (TaskSurpport)c.newInstance(); |
| | | return (TaskSurpport)c.getDeclaredConstructor().newInstance(); |
| | | //return (TaskSurpport)c.newInstance(); |
| | | } |
| | | } |
| | | |
File was renamed from pipIrr-platform/pipIrr-mw/pipIrr-mw-accept/src/main/java/com/dy/aceMw/server/busi/deal/TaskSurpport.java |
| | |
| | | package com.dy.aceMw.server.busi.deal; |
| | | package com.dy.aceMw.server.rtuData; |
| | | |
| | | import org.apache.logging.log4j.LogManager; |
| | | import org.apache.logging.log4j.Logger; |
File was renamed from pipIrr-platform/pipIrr-mw/pipIrr-mw-accept/src/main/java/com/dy/aceMw/server/busi/deal/TkReceive.java |
| | |
| | | package com.dy.aceMw.server.busi.deal; |
| | | package com.dy.aceMw.server.rtuData; |
| | | |
| | | import com.dy.common.mw.protocol.Data; |
| | | import org.apache.logging.log4j.LogManager; |
File was renamed from pipIrr-platform/pipIrr-mw/pipIrr-mw-accept/src/main/java/com/dy/aceMw/server/busi/deal/TkRtuData.java |
| | |
| | | package com.dy.aceMw.server.busi.deal; |
| | | package com.dy.aceMw.server.rtuData; |
| | | |
| | | import com.dy.common.mw.protocol.Data; |
| | | import org.apache.logging.log4j.LogManager; |
File was renamed from pipIrr-platform/pipIrr-mw/pipIrr-mw-accept/src/main/java/com/dy/aceMw/server/busi/deal/TreeConfig.java |
| | |
| | | package com.dy.aceMw.server.busi.deal; |
| | | package com.dy.aceMw.server.rtuData; |
| | | |
| | | public class TreeConfig { |
| | | public TaskConfig taskConf ; |
File was renamed from pipIrr-platform/pipIrr-mw/pipIrr-mw-accept/src/main/java/com/dy/aceMw/server/busi/deal/TreeParse.java |
| | |
| | | package com.dy.aceMw.server.busi.deal; |
| | | package com.dy.aceMw.server.rtuData; |
| | | |
| | | |
| | | import java.net.URL; |
| | |
| | | */ |
| | | protected TreeConfig parseConfig() { |
| | | try { |
| | | URL configFileURL = TreeParse.class.getResource("Tree.xml"); |
| | | ClassLoader classLoader = ClassLoader.getSystemClassLoader(); |
| | | URL configFileURL = classLoader.getResource("RtuDataDealTree.xml"); |
| | | return this.parse(this.createDom(configFileURL)) ; |
| | | } catch (Exception e) { |
| | | System.out.println("ç³»ç»å¯å¨æ¶ï¼åå§ä¸è¡æ°æ®å¤çä»»å¡é
ç½®åºé !"); |
| | |
| | | private TreeConfig parse(Document doc) throws Exception { |
| | | Element root = doc.getRootElement(); |
| | | if (root == null) { |
| | | throw new Exception("æªå¾å°ä¸è¡æ°æ®å¤çä»»å¡é
ç½®æä»¶æ ¹å
ç´ config!"); |
| | | throw new Exception("æªå¾å°ä¸è¡æ°æ®å¤çä»»å¡é
ç½®æä»¶æ ¹å
ç´ project!"); |
| | | } |
| | | |
| | | List<Element> rootTasks = root.getChildren("task") ; |
File was renamed from pipIrr-platform/pipIrr-mw/pipIrr-mw-accept/src/main/java/com/dy/aceMw/server/busi/deal/dbSv/RtuSv.java |
| | |
| | | package com.dy.aceMw.server.busi.deal.dbSv; |
| | | package com.dy.aceMw.server.rtuData.dbSv; |
| | | |
| | | import org.springframework.stereotype.Service; |
| | | |
File was renamed from pipIrr-platform/pipIrr-mw/pipIrr-mw-accept/src/main/java/com/dy/aceMw/server/busi/deal/p206V1_0_0/TkFindP206V1_0_0.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 com.dy.common.mw.protocol.p206V1_0_0.ProtocolConstantV206V1_0_0; |
| | | |
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() ; |
File was renamed from pipIrr-platform/pipIrr-mw/pipIrr-mw-accept/src/main/java/com/dy/aceMw/server/tasks/BusiConstantTask.java |
| | |
| | | package com.dy.aceMw.server.tasks; |
| | | |
| | | import com.dy.aceMw.server.busi.AboutRtuNode; |
| | | import com.dy.aceMw.server.busi.TcpUpDataCache; |
| | | 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; |
| | |
| | | /** |
| | | * 对RTUä¸è¡æ°æ®è¿è¡ä¸å¡å¤ç |
| | | */ |
| | | public class BusiConstantTask extends CoreTask { |
| | | private static final Logger log = LogManager.getLogger(BusiConstantTask.class.getName()); |
| | | public class FromRtuConstantTask extends CoreTask { |
| | | private static final Logger log = LogManager.getLogger(FromRtuConstantTask.class.getName()); |
| | | |
| | | /** |
| | | * å¨å线ç¨ç¯å¢ä¸è¿è¡ |
| | |
| | | @Override |
| | | public Integer excute() { |
| | | try{ |
| | | return dealRtuUpdata() ; |
| | | return dealRtuUpData() ; |
| | | }catch(Exception e){ |
| | | log.error(e); |
| | | } |
| | |
| | | /** |
| | | * å¤çä¸è¡æ°æ® |
| | | */ |
| | | public Integer dealRtuUpdata() { |
| | | Node first = TcpUpDataCache.getFirstQueueNode() ; |
| | | public Integer dealRtuUpData() { |
| | | Node first = RtuDataCache.getFirstQueueNode() ; |
| | | if(first != null){ |
| | | Integer count = TcpUpDataCache.size() ; |
| | | Node last = TcpUpDataCache.getLastQueueNode() ; |
| | | this.doDealRtuUpdata(first, last); |
| | | 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){ |
| | | 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) ; |
| | | doDealRtuUpData(first, pre) ; |
| | | }else if(first != null && first == last){ |
| | | //忢 |
| | | }else if(first == null){ |
| | | //è¿ç§æ
åµä¸ä¼åå¨ |
| | | doDealRtuUpdata(null, pre) ; |
| | | doDealRtuUpData(null, pre) ; |
| | | } |
| | | } |
| | | } |
| | |
| | | * @param node èç¹ |
| | | */ |
| | | private void dealNode(Node node){ |
| | | AboutRtuNode obj = (AboutRtuNode)node.obj ; |
| | | RtuDataNode obj = (RtuDataNode)node.obj ; |
| | | obj.dealSelf() ; |
| | | TcpUpDataCache.removeNode(node); |
| | | 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 ; |
| | | } |
| | | } |
| | | |
| | |
| | | public String code ; |
| | | |
| | | public Integer count;//mwTest䏿¥æ°æ®æ°é |
| | | |
| | | |
| | | public Integer overCount;//aepTestç»æä¸æ¥æ°æ®æ°é |
| | | |
| | | public Boolean over ;//mwTest䏿¥æ°æ®ç»æ |
| | | |
| | | public Long seconds ;//mwTest䏿¥æ°æ®ç¨æ¶(ç§) |
| | |
| | | public void setSeconds(Long seconds) { |
| | | this.seconds = seconds; |
| | | } |
| | | |
| | | |
| | | public Integer getOverCount() { |
| | | return overCount; |
| | | } |
| | | |
| | | public void setOverCount(Integer overCount) { |
| | | this.overCount = overCount; |
| | | } |
| | | } |