From fbc250276c78ca2afa45a55e8af8deddd65e4f8a Mon Sep 17 00:00:00 2001
From: liurunyu <lry9898@163.com>
Date: 星期一, 16 十二月 2024 11:23:41 +0800
Subject: [PATCH] 临时任务功能,修改bug
---
pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V1/CommonV1.java | 142 +++++++++++++++++++++++++++++++++--------------
1 files changed, 100 insertions(+), 42 deletions(-)
diff --git a/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V1/CommonV1.java b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V1/CommonV1.java
index fb408c2..4eb2494 100644
--- a/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V1/CommonV1.java
+++ b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V1/CommonV1.java
@@ -1,44 +1,60 @@
package com.dy.common.mw.protocol.p206V1;
+import com.dy.common.mw.channel.tcp.TcpIoSessionAttrIdIsRtuAddr;
import com.dy.common.util.ByteUtil;
import com.dy.common.util.ByteUtilUnsigned;
+import com.dy.common.util.CRC16;
import com.dy.common.util.CRC8_for_2_0;
+import org.apache.mina.core.session.IoSession;
public class CommonV1 {
+
+
/**
* 妫�鏌ュご
* @param bs 涓婅瀛楄妭鏁扮粍
- * @return true鏄�,false鍚�
+ * @return [rt1->true:鏄湰鍗忚P206锛宖alse:涓嶆槸鏈崗璁�; rt2->true:鏄按璧勬簮鍗忚锛宖alse:鏄崌绾у崗璁甝
* @throws Exception 寮傚父
*/
- public Boolean isThisProtocolHead(byte[] bs) throws Exception{
+ public Boolean[] isThisProtocolHead(byte[] bs) throws Exception{
if(bs == null){
return null ;
}else if(bs.length >= (ProtocolConstantV206V1.ctrlIndex)
&& bs[0] == ProtocolConstantV206V1.P_Head_Byte
&& bs[2] == ProtocolConstantV206V1.P_Head_Byte){
- //String vs = this.parseVersion(bs) ;
- //return vs.equals(ProtocolConstantV206V1.version);
- return true ;
+ return new Boolean[]{true, true} ;
+ }else if(bs.length >= (ProtocolConstantV206V1.UG_codeIndex)
+ && bs[0] == ProtocolConstantV206V1.UG_P_Head_Byte
+ && bs[3] == ProtocolConstantV206V1.UG_P_Head_Byte){
+ return new Boolean[]{true, false} ;
}else{
- return false ;
+ return new Boolean[]{false, false} ;
}
}
-
+
/**
- * 妫�鏌ュご
- * @param bs 涓婅瀛楄妭鏁扮粍
- * @throws Exception 寮傚父
+ * 妫�鏌ュ崗璁被鍨�
+ * @param bs 涓婅瀛楄妭鏁扮粍
+ * @return 鍗忚绫诲瀷
+ * @throws Exception 寮傚父
*/
- public void checkHead(byte[] bs) throws Exception{
- if(bs.length < ProtocolConstantV206V1.onLineDataMinLength
- || bs[0] != ProtocolConstantV206V1.P_Head_Byte
- || bs[2] != ProtocolConstantV206V1.P_Head_Byte){
- throw new Exception("涓婅鏁版嵁甯уご涓嶆纭紒") ;
+ public Boolean protocolType_p206TrueUgFalse(byte[] bs){
+ if(bs == null){
+ return null ;
+ }else if(bs.length >= (ProtocolConstantV206V1.ctrlIndex)
+ && bs[0] == ProtocolConstantV206V1.P_Head_Byte
+ && bs[2] == ProtocolConstantV206V1.P_Head_Byte){
+ return true ;
+ }else if(bs.length >= (ProtocolConstantV206V1.UG_codeIndex)
+ && bs[0] == ProtocolConstantV206V1.UG_P_Head_Byte
+ && bs[3] == ProtocolConstantV206V1.UG_P_Head_Byte){
+ return false ;
+ }else{
+ return null ;
}
}
-
+
/**
* 妫�鏌ュ熬
* @param bs 涓婅瀛楄妭鏁扮粍
@@ -54,40 +70,62 @@
/**
* 鍒嗘瀽甯ч暱搴�
* @param bs 涓婅瀛楄妭鏁扮粍
+ * @param p206TrueUgFalse 206鍗忚涓簍rue锛屽崌绾у崗璁负false
* @return 鏁版嵁闀垮害
* @throws Exception 寮傚父
*/
- public int parseFrameLen(byte[] bs)throws Exception{
- int len = ByteUtilUnsigned.byte2Byte(bs, ProtocolConstantV206V1.dataLenIndex) ;
- return len + ProtocolConstantV206V1.lenHead2ctrl + ProtocolConstantV206V1.lenTail ;
+ public int parseFrameLen(byte[] bs, boolean p206TrueUgFalse)throws Exception{
+ if(p206TrueUgFalse) {
+ int len = ByteUtilUnsigned.byte2Byte(bs, ProtocolConstantV206V1.dataLenIndex);
+ return len + ProtocolConstantV206V1.lenHead2ctrl + ProtocolConstantV206V1.lenTail;
+ }else{
+ int len = ByteUtilUnsigned.bytes2Short_BE(bs, ProtocolConstantV206V1.UG_dataLenIndex_start);
+ return len + ProtocolConstantV206V1.UG_lenHead2Cmd + ProtocolConstantV206V1.UG_lenTail;
+ }
}
/**
- * 鍒嗘瀽鐢ㄦ埛鏁版嵁鍩熷瓧鑺傛暟
+ * 鍒嗘瀽鐢ㄦ埛鏁版嵁鍩熷瓧鑺傛暟(榛樿鏄潪鍗囩骇鍗忚)
* @param bs 涓婅瀛楄妭鏁扮粍
* @return 鏁版嵁闀垮害
* @throws Exception 寮傚父
*/
- public int parseDataLen(byte[] bs)throws Exception{
+ public int parseDataLen4P206(byte[] bs)throws Exception{
int len = ByteUtilUnsigned.byte2Byte(bs, ProtocolConstantV206V1.dataLenIndex) ;
- return len + ProtocolConstantV206V1.lenHead2ctrl + ProtocolConstantV206V1.lenTail ;
+ return len - ProtocolConstantV206V1.lenCtrl - ProtocolConstantV206V1.lenRtuAddr ;
+ }
+
+ /**
+ * 鍒嗘瀽鐢ㄦ埛鏁版嵁鍩熷瓧鑺傛暟(鍗囩骇鍗忚)
+ * @param bs 涓婅瀛楄妭鏁扮粍
+ * @return 鏁版嵁闀垮害
+ * @throws Exception 寮傚父
+ */
+ public int parseDataLen4Ug(byte[] bs)throws Exception{
+ int len = ByteUtilUnsigned.bytes2Short_LE(bs, ProtocolConstantV206V1.UG_dataLenIndex_start) ;
+ return len - ProtocolConstantV206V1.UG_lenCmd - ProtocolConstantV206V1.UG_lenRtuAddr ;
}
/**
* 鍒嗘瀽Rtu鍦板潃
* @param bs 涓婅瀛楄妭鏁扮粍
+ * @param p206TrueUgFalse 206鍗忚涓簍rue锛屽崌绾у崗璁负false
* @return 鎺у埗鍣ㄥ湴鍧�
* @throws Exception 寮傚父
*/
- public String parseRtuAddr(byte[] bs)throws Exception{
- String rtuAddrBCD = "" + ByteUtil.BCD2Long_BE(bs, ProtocolConstantV206V1.rtuAddr1Index_start, ProtocolConstantV206V1.rtuAddr1Index_end) ;
- String rtuAddrStr = "" + ByteUtilUnsigned.bytes2Short_LE(bs, ProtocolConstantV206V1.rtuAddr2Index_start) ;
- while(rtuAddrStr.length() <= 5){
- rtuAddrStr = "0" + rtuAddrStr ;
+ public String parseRtuAddr(byte[] bs, boolean p206TrueUgFalse)throws Exception{
+ if(p206TrueUgFalse){
+ String rtuAddrBCD = "" + ByteUtil.BCD2Long_BE(bs, ProtocolConstantV206V1.rtuAddr1Index_start, ProtocolConstantV206V1.rtuAddr1Index_end) ;
+ String rtuAddrStr = "" + ByteUtilUnsigned.bytes2Short_LE(bs, ProtocolConstantV206V1.rtuAddr2Index_start) ;
+ while(rtuAddrStr.length() <= 5){
+ rtuAddrStr = "0" + rtuAddrStr ;
+ }
+ return rtuAddrBCD + rtuAddrStr ;
+ }else{
+ return ("" + ByteUtil.BCD2Long_BE(bs, ProtocolConstantV206V1.UG_rtuAddrIndex_start, ProtocolConstantV206V1.UG_rtuAddrIndex_end)) ;
}
- return rtuAddrBCD + rtuAddrStr ;
}
@@ -98,13 +136,17 @@
* @return 鎺у埗鍣ㄥ湴鍧�
* @throws Exception 寮傚父
*/
- public String parseRtuAddr(byte[] bs, int index)throws Exception{
- String rtuAddrBCD = "" + ByteUtil.BCD2Long_BE(bs, index, index + 2) ;//鍦板潃鏄ぇ绔ā寮�
- String rtuAddrStr = "" + ByteUtilUnsigned.bytes2Short_LE(bs, index + 3) ;
- while(rtuAddrStr.length() <= 5){
- rtuAddrStr = "0" + rtuAddrStr ;
+ public String parseRtuAddr(byte[] bs, int index, boolean p206TrueUgFalse)throws Exception{
+ if(p206TrueUgFalse){
+ String rtuAddrBCD = "" + ByteUtil.BCD2Long_BE(bs, index, index + 2) ;//鍦板潃鏄ぇ绔ā寮�
+ String rtuAddrStr = "" + ByteUtilUnsigned.bytes2Short_LE(bs, index + 3) ;
+ while(rtuAddrStr.length() <= 5){
+ rtuAddrStr = "0" + rtuAddrStr ;
+ }
+ return rtuAddrBCD + rtuAddrStr ;
+ }else{
+ throw new Exception("鍗囩骇鍗忚鏃犺缃湴鍧�") ;
}
- return rtuAddrBCD + rtuAddrStr ;
}
@@ -113,23 +155,39 @@
* @param bs 涓婅瀛楄妭鏁扮粍
* @return 鍔熻兘鐮�
*/
- public String parseCode(byte[] bs){
- return ByteUtil.bytes2Hex(bs, false, ProtocolConstantV206V1.codeIndex, 1) ;
+ public String parseCode(byte[] bs, boolean p206TrueUgFalse){
+ if(p206TrueUgFalse) {
+ return ByteUtil.bytes2Hex(bs, false, ProtocolConstantV206V1.codeIndex, 1);
+ }else{
+ return ByteUtil.bytes2Hex(bs, false, ProtocolConstantV206V1.UG_codeIndex, 2);
+ }
}
/**
* 鏍¢獙鍜屾鏌�
* @param bs 涓婅瀛楄妭鏁扮粍
+ * @param p206TrueUgFalse 206鍗忚涓簍rue锛屽崌绾у崗璁负false
* @return 閫氳繃null锛屾湭閫氳繃杩斿洖鍘熷洜
* @throws Exception 寮傚父
*/
- public String checkCrc_str(byte[] bs) throws Exception {
- byte crcCompute = (byte)new CRC8_for_2_0().CRC8(bs, ProtocolConstantV206V1.ctrlIndex, bs.length - 3) ;
- byte crcInBs = bs[bs.length - 2] ;
- if(crcCompute == crcInBs){
- return null ;
+ public String checkCrc_str(byte[] bs, boolean p206TrueUgFalse) throws Exception {
+ if(p206TrueUgFalse){
+ byte crcCompute = (byte)new CRC8_for_2_0().CRC8(bs, ProtocolConstantV206V1.ctrlIndex, bs.length - 3) ;
+ byte crcInBs = bs[bs.length - 2] ;
+ if(crcCompute == crcInBs){
+ return null ;
+ }else{
+ return "璁$畻CRC鏄�:" + crcCompute + "锛屼笂浼燙RC鏄�" + crcInBs ;
+ }
}else{
- return "璁$畻CRC鏄�:" + crcCompute + "锛屼笂浼燙RC鏄�" + crcInBs ;
+ short crcCompute = new CRC16().CRC(bs, 0, bs.length - 4) ;
+ short crcInBs = ByteUtil.bytes2Short_BE(bs,bs.length - 3) ;
+ //int crcInBs = ByteUtilUnsigned.bytes2Short_BE(bs, bs.length - 3) ;
+ if(crcCompute == crcInBs){
+ return null ;
+ }else{
+ return "璁$畻CRC鏄�:" + crcCompute + "锛屼笂浼燙RC鏄�" + crcInBs ;
+ }
}
}
--
Gitblit v1.8.0