From d66fdfdeaf6a0fbfdeed97848ee507243977878e Mon Sep 17 00:00:00 2001 From: Administrator <zhubaomin> Date: 星期三, 17 一月 2024 16:35:48 +0800 Subject: [PATCH] 2024-01-17 朱宝民 获取未绑控制器的取水口列表 --- pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V1_0_0/CommonV1_0_1.java | 93 ++++++++++++++++++++++++++++++++-------------- 1 files changed, 64 insertions(+), 29 deletions(-) diff --git a/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V1_0_0/CommonV1_0_1.java b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V1_0_0/CommonV1_0_1.java index e8616b0..e9677bb 100644 --- a/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V1_0_0/CommonV1_0_1.java +++ b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V1_0_0/CommonV1_0_1.java @@ -2,6 +2,7 @@ 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 { @@ -49,18 +50,31 @@ /** - * 鍒嗘瀽鏁版嵁瀛楄妭鏁� + * 鍒嗘瀽甯ч暱搴� + * @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 ; } /** - * 鍒嗘瀽IMEI鍙� + * 鍒嗘瀽Rtu鍦板潃 * @param bs 涓婅瀛楄妭鏁扮粍 * @return 鎺у埗鍣ㄥ湴鍧� * @throws Exception 寮傚父 @@ -68,11 +82,29 @@ 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() < 5){ rtuAddrStr = "0" + rtuAddrStr ; } return rtuAddrBCD + rtuAddrStr ; } + + + /** + * 鍒嗘瀽Rtu鍦板潃 + * @param bs 涓婅瀛楄妭鏁扮粍 + * @param index 鍚浣� + * @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_BE(bs, index + 3) ; + while(rtuAddrStr.length() < 5){ + rtuAddrStr = "0" + rtuAddrStr ; + } + return rtuAddrBCD + rtuAddrStr ; + } + /** * 鍒嗘瀽鍔熻兘鐮� @@ -83,20 +115,6 @@ 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 涓婅瀛楄妭鏁扮粍 @@ -104,16 +122,12 @@ * @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 + "锛屼笂浼燙RC鏄�" + crcInBs ; } } @@ -123,15 +137,36 @@ D7 D6 D5锝濪4 D3锝濪0 浼犺緭鏂瑰悜浣� 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 ; } + + /** + * 寰楀埌鍏冲紑闃�绫诲瀷鍚嶇О + * @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 -> "鐢ㄦ埛杩滅▼鍏抽榾"; + case 16 -> "绠¢亾鏃犳按鑷姩鍏抽榾"; + default -> "鏈煡"; + }; + } /* * 鍒嗘瀽鐗堟湰鍙� -- Gitblit v1.8.0