From 3a709d693bec87de92b4b91abba535d14392810b Mon Sep 17 00:00:00 2001
From: zhubaomin <zhubaomin>
Date: 星期四, 27 三月 2025 16:10:25 +0800
Subject: [PATCH] 获取项目列表接口
---
pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V202404/CommonV202404.java | 228 +++++++++++++++++++++++++++++++++++++++++++++++++--------
1 files changed, 196 insertions(+), 32 deletions(-)
diff --git a/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V202404/CommonV202404.java b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V202404/CommonV202404.java
index 42c9190..1e71d09 100644
--- a/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V202404/CommonV202404.java
+++ b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V202404/CommonV202404.java
@@ -1,11 +1,25 @@
package com.dy.common.mw.protocol.p206V202404;
+import com.dy.common.mw.channel.tcp.TcpIoSessionAttrIdIsRtuAddr;
+import com.dy.common.mw.protocol.p206V1.ProtocolConstantV206V1;
+import com.dy.common.mw.protocol.p206V2.ProtocolConstantV206V2;
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 CommonV202404 {
+
+ /**
+ * 鍦↖o浼氳瘽涓缃崗璁悕绉板強鐗堟湰鍙�
+ * @param ioSession 浼氳瘽
+ */
+ public void setThisProtocolArr2IoSession(IoSession ioSession){
+ ioSession.setAttribute(TcpIoSessionAttrIdIsRtuAddr.sessionArrProtocolName, ProtocolConstantV206V1.protocolName) ;
+ ioSession.setAttribute(TcpIoSessionAttrIdIsRtuAddr.sessionArrProtocolName, ProtocolConstantV206V1.protocolVer) ;
+ }
/**
* 妫�鏌ュご
* @param bs 涓婅瀛楄妭鏁扮粍
@@ -15,14 +29,22 @@
public Boolean isThisProtocolHead(byte[] bs) throws Exception{
if(bs == null){
return null ;
- }else if(bs.length >= (ProtocolConstantV206V202404.ctrlIndex - 1)
+ }else if(bs.length >= ProtocolConstantV206V202404.ctrlIndex
&& bs[0] == ProtocolConstantV206V202404.P_Head_Byte){
if(bs[2] == ProtocolConstantV206V202404.P_Head_Byte){
- return true ;
+ if(bs[3] == (byte)0x80 || bs[3] == (byte)0x81){
+ return true ;
+ }else{
+ return false ;
+ }
}else if((byte)(bs[2] & 0xF8) == ProtocolConstantV206V202404.P_Head_Byte){
- //濡傛灉鎺у埗鍩熴�佸湴鍧�鍩熴�佺敤鎴锋暟鎹煙(搴旂敤灞�)鐨勫瓧鑺傛�绘暟澶т簬255锛屽垯閫氳繃鎵╁睍绗簩涓紑濮嬪瓧绗�0x68鐨勪綆3浣嶄綔涓洪暱L鐨勯珮浣嶆墿灞�
+ //濡傛灉鎺у埗鍩熴�佸湴鍧�鍩熴�佺敤鎴锋暟鎹煙(搴旂敤灞�)鐨勫瓧鑺傛�绘暟澶т簬255锛屽垯閫氳繃鎵╁睍绗簩涓紑濮嬪瓧绗�0x69鐨勪綆3浣嶄綔涓洪暱L鐨勯珮浣嶆墿灞�
//0xF8浜岃繘鍒讹細 11111000
- return true ;
+ if(bs[3] == (byte)0x80 || bs[3] == (byte)0x81){
+ return true ;
+ }else{
+ return false ;
+ }
}else{
return false ;
}
@@ -32,23 +54,24 @@
}
/**
- * 妫�鏌ュご
+ * 妫�鏌ュ崗璁被鍨�
* @param bs 涓婅瀛楄妭鏁扮粍
+ * @return 鍗忚绫诲瀷
* @throws Exception 寮傚父
*/
- public void checkHead(byte[] bs) throws Exception{
- if(bs.length < ProtocolConstantV206V202404.lenHead2Code
- || bs[0] != ProtocolConstantV206V202404.P_Head_Byte){
- throw new Exception("涓婅鏁版嵁甯уご涓嶆纭紒") ;
+ public Boolean protocolType_p206TrueUgFalse(byte[] bs){
+ if(bs == null){
+ return null ;
+ }else if(bs.length >= (ProtocolConstantV206V202404.ctrlIndex)
+ && bs[0] == ProtocolConstantV206V202404.P_Head_Byte
+ && bs[2] == ProtocolConstantV206V202404.P_Head_Byte){
+ return true ;
+ }else if(bs.length >= (ProtocolConstantV206V202404.UG_codeIndex)
+ && bs[0] == ProtocolConstantV206V202404.UG_P_Head_Byte
+ && bs[3] == ProtocolConstantV206V202404.UG_P_Head_Byte){
+ return false ;
}else{
- if(bs.length >= ProtocolConstantV206V202404.lenHead2Code){
- if(bs[2] != ProtocolConstantV206V202404.P_Head_Byte
- && (byte)(bs[2] & 0xF8) != ProtocolConstantV206V202404.P_Head_Byte){
- throw new Exception("涓婅鏁版嵁甯уご涓嶆纭紒") ;
- }
- }else{
- throw new Exception("涓婅鏁版嵁甯уご涓嶆纭紒") ;
- }
+ return null ;
}
}
@@ -89,8 +112,19 @@
* @return 鏁版嵁闀垮害
* @throws Exception 寮傚父
*/
- public int parseDataLen(byte[] bs)throws Exception{
+ public int parseDataLen4P202404(byte[] bs)throws Exception{
return parseFrameLen(bs) ;
+ }
+
+ /**
+ * 鍒嗘瀽鐢ㄦ埛鏁版嵁鍩熷瓧鑺傛暟(鍗囩骇鍗忚)
+ * @param bs 涓婅瀛楄妭鏁扮粍
+ * @return 鏁版嵁闀垮害
+ * @throws Exception 寮傚父
+ */
+ public int parseDataLen4Ug(byte[] bs)throws Exception{
+ int len = ByteUtilUnsigned.bytes2Short_LE(bs, ProtocolConstantV206V2.UG_dataLenIndex_start) ;
+ return len - ProtocolConstantV206V2.UG_lenCmd - ProtocolConstantV206V2.UG_lenRtuAddr ;
}
@@ -137,6 +171,18 @@
}
/**
+ * 鍒嗘瀽鍔熻兘鐮�
+ * @param bs 涓婅瀛楄妭鏁扮粍
+ * @return 鍔熻兘鐮�
+ */
+ public String parseCode(byte[] bs, boolean p202404TrueUgFalse){
+ if(p202404TrueUgFalse) {
+ return ByteUtil.bytes2Hex(bs, false, ProtocolConstantV206V202404.codeIndex, 1);
+ }else{
+ return ByteUtil.bytes2Hex(bs, false, ProtocolConstantV206V202404.UG_codeIndex, 2);
+ }
+ }
+ /**
* 鏍¢獙鍜屾鏌�
* @param bs 涓婅瀛楄妭鏁扮粍
* @return 閫氳繃null锛屾湭閫氳繃杩斿洖鍘熷洜
@@ -152,6 +198,33 @@
}
}
+ /**
+ * 鏍¢獙鍜屾鏌�
+ * @param bs 涓婅瀛楄妭鏁扮粍
+ * @param p202404TrueUgFalse 202404鍗忚涓簍rue锛屽崌绾у崗璁负false
+ * @return 閫氳繃null锛屾湭閫氳繃杩斿洖鍘熷洜
+ * @throws Exception 寮傚父
+ */
+ public String checkCrc_str(byte[] bs, boolean p202404TrueUgFalse) throws Exception {
+ if(p202404TrueUgFalse){
+ byte crcCompute = (byte)new CRC8_for_2_0().CRC8(bs, ProtocolConstantV206V202404.ctrlIndex, bs.length - 3) ;
+ byte crcInBs = bs[bs.length - 2] ;
+ if(crcCompute == crcInBs){
+ return null ;
+ }else{
+ return "璁$畻CRC鏄�:" + crcCompute + "锛屼笂浼燙RC鏄�" + crcInBs ;
+ }
+ }else{
+ 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 ;
+ }
+ }
+ }
/*
鏋勯�犳帶鍒跺煙
@@ -172,30 +245,121 @@
public byte createCtrl(byte dir, byte funcCode){
byte b = dir;//DIR = 1(0x80)锛岃〃绀烘甯ф姤鏂囨槸鐢辩粓绔彂鍑虹殑涓婅鎶ユ枃锛�
b = (byte)(b | funcCode) ;
- //DIV = 1(0x40)锛岃〃绀烘鎶ユ枃宸茶鎷嗗垎涓鸿嫢骞插抚
- //FCB = 1(0x08)锛岃〃绀哄彧鍙戜竴娆�
- b = (byte)(b |0x08) ;
+ //DIV = 1(0x20)锛岃〃绀烘鎶ユ枃宸茶鎷嗗垎涓鸿嫢骞插抚
+ //FCB = 1(0x10)锛岃〃绀哄彧鍙戜竴娆�
+ b = (byte)(b |0x10) ;
//DIR = 0 涓嬭锛屽垯鍔熻兘鐮侀噰鐢�0
return b ;
}
/**
+ * 0x01锛氬埛鍗″紑闃�
+ * 0x02锛氫腑蹇冪珯寮�闃�
+ * 0x08锛氱敤鎴稟pp杩滅▼寮�闃�
+ * 0x0B锛氬贰妫�鍗″紑闃�
+ * @param type
+ * @return
+ */
+ public static String openValveType(byte type){
+ return switch (type) {
+ case 1 -> "鍒峰崱寮�闃�";
+ case 2 -> "涓績绔欏紑闃�";
+ case 8 -> "鐢ㄦ埛App杩滅▼寮�闃�";
+ case 11 -> "宸℃鍗″紑闃�";
+ default -> "鏈煡";
+ };
+ }
+ /**
+ * 0x01锛氬埛鍗″紑闃� => p206V1 1
+ * 0x02锛氫腑蹇冪珯寮�闃� => p206V1 3
+ * 0x08锛氱敤鎴稟pp杩滅▼寮�闃� => p206V1 3
+ * 0x0B锛氬贰妫�鍗″紑闃� => p206V1 11
+ * @param type
+ * @return
+ */
+ public static byte openType2P206V1(byte type){
+ return switch (type) {
+ case 1 -> (byte)1 ;
+ case 2 -> (byte)3 ;
+ case 8 -> (byte)3 ;
+ case 11 -> (byte)11 ;
+ default -> (byte)-1;
+ };
+ }
+
+ /**
* 寰楀埌鍏冲紑闃�绫诲瀷鍚嶇О
+ * 0x00:鍒峰崱闂�
+ * 0x01:骞冲彴鍏�
+ * 0x02:APP鍏�
+ * 0x03:闈炴硶鍗″叧
+ * 0x04:姘磋〃閫氳寮傚父鍏�
+ * 0x05:鐢佃〃寮傚父鍏�
+ * 0x06:鍓╀綑姘撮噺涓嶈冻鍏�
+ * 0x07:鍓╀綑閲戦涓�0鍏�
+ * 0x08:寮�娉�/闃�鍚庣閬撴病鏈夋祦閲忓叧
+ * 0x09:鎺夌數鍐嶄笂鐢靛叧
+ * 0x0a:姘磋〃鐬椂娴侀噺涓�0鍏�
+ * 0x0b:鍒峰崱寮�娉碉紝杩滅▼鍏�
+ * 0x0c:鐢垫睜浣庣數鍘嬪叧
* @param type 瀛楄妭
* @return 鍚嶇О
*/
- public static String openCloseValveType(byte type){
+ public static String closeValveType(byte type){
return switch (type) {
- case 1 -> "鍒峰崱寮�闃�";
- case 2 -> "鍒峰崱鍏抽榾";
- case 3 -> "涓績绔欏紑闃�";
- case 4 -> "涓績绔欏叧闃�";
- case 5 -> "娆犺垂鍏抽榾";
- case 6 -> "娴侀噺璁℃晠闅滃叧闃�";
- case 7 -> "绱ф�ュ叧闃�";
- case 8 -> "鐢ㄦ埛杩滅▼寮�闃�";
- case 9 -> "鐢ㄦ埛杩滅▼鍏抽榾";
- case 16 -> "绠¢亾鏃犳按鑷姩鍏抽榾";
+ case 0 -> "鍒峰崱鍏抽榾";
+ case 1 -> "骞冲彴鍏抽榾";
+ case 2 -> "APP鍏抽榾";
+ case 3 -> "闈炴硶鍗″叧闃�";
+ case 4 -> "姘磋〃閫氳寮傚父鍏抽榾";
+ case 5 -> "鐢佃〃寮傚父鍏抽榾";
+ case 6 -> "鍓╀綑姘撮噺涓嶈冻鍏抽榾";
+ case 7 -> "鍓╀綑閲戦涓�0鍏抽榾";
+ case 8 -> "绠¢亾娌℃湁娴侀噺鍏抽榾";
+ case 9 -> "鎺夌數鍐嶄笂鐢靛叧闃�";
+ case 10 -> "姘磋〃鐬椂娴侀噺涓�0鍏抽榾";
+ case 11 -> "鍒峰崱寮�杩滅▼鍏抽榾";
+ case 12 -> "鐢垫睜浣庣數鍘嬪叧闃�";
+ default -> "鏈煡";
+ };
+ }
+ /**
+ * 寰楀埌鍏冲紑闃�绫诲瀷鍚嶇О
+ * 0x00:鍒峰崱闂� => p206V1 2
+ * 0x01:骞冲彴鍏� => p206V1 4
+ * 0x02:APP鍏� => p206V1 4
+ * 0x03:闈炴硶鍗″叧 => p206V1 12
+ * 0x04:姘磋〃閫氳寮傚父鍏� => p206V1 6
+ * 0x05:鐢佃〃寮傚父鍏� => p206V1 6
+ * 0x06:鍓╀綑姘撮噺涓嶈冻鍏� => p206V1 5
+ * 0x07:鍓╀綑閲戦涓�0鍏� => p206V1 5
+ * 0x08:寮�娉�/闃�鍚庣閬撴病鏈夋祦閲忓叧 => p206V1 16
+ * 0x09:鎺夌數鍐嶄笂鐢靛叧锛� => p206V1 7
+ * 0x0a:姘磋〃鐬椂娴侀噺涓�0鍏筹紝 => p206V1 5
+ * 0x0b:鍒峰崱寮�娉碉紝杩滅▼鍏炽�� => p206V1 9
+ * 0x0c:鐢垫睜浣庣數鍘嬪叧銆� => p206V1 7
+ * @param type 瀛楄妭
+ * @return 鍚嶇О
+ */
+ public static byte closeType2P206V1(byte type){
+ return switch (type) {
+ case 0 -> (byte)2;
+ case 1,2 -> (byte)4;
+ case 3 -> (byte)12;
+ case 4,5 -> (byte)6;
+ case 6,7,10 -> (byte)5;
+ case 8 -> (byte)16;
+ case 9,12 -> (byte)7;
+ case 11 -> (byte)9;
+ default -> (byte)-1;
+ };
+ }
+
+ public static String ctrlDevType(String hex){
+ return switch (hex) {
+ case "01" -> "娴嬫帶涓�浣撻榾";
+ case "02" -> "琛ㄩ榾涓�浣撴満";
+ case "57" -> "浜曠數鎺у埗鍣�";
default -> "鏈煡";
};
}
--
Gitblit v1.8.0