From 66b091963fb0f3356f27ec094c013369bf91db89 Mon Sep 17 00:00:00 2001 From: jiazx0107@163.com <jiazx0107@163.com> Date: 星期日, 24 十二月 2023 14:02:19 +0800 Subject: [PATCH] 游仙协议解析-3 --- src/main/java/com/fzzy/protocol/youxian0/client/ClientHandler.java | 2 src/main/java/com/fzzy/protocol/youxian0/service/Youxian0GatewayGrainService.java | 27 + src/main/java/com/fzzy/api/utils/BytesUtil.java | 834 ++++++++++++++++++++++++++++--------------------------- src/main/java/com/fzzy/gateway/hx2023/service/DeviceReportServiceImpl.java | 14 src/main/java/com/fzzy/protocol/youxian0/analysis/AnalysisService.java | 11 5 files changed, 467 insertions(+), 421 deletions(-) diff --git a/src/main/java/com/fzzy/api/utils/BytesUtil.java b/src/main/java/com/fzzy/api/utils/BytesUtil.java index af4348e..491ee75 100644 --- a/src/main/java/com/fzzy/api/utils/BytesUtil.java +++ b/src/main/java/com/fzzy/api/utils/BytesUtil.java @@ -4,447 +4,469 @@ public class BytesUtil { - /** - * bytes杈撳嚭鍗佽繘鍒� - * - * @param bytes - * @return - */ - public static Integer bytesToInt(byte[] bytes) { - String str = ""; - int i = 0; - boolean flag = true && bytes.length > 0; - while (flag) { - Byte b = bytes[i]; - i++; - Integer bi = Byte.toUnsignedInt(b); - str += toHexString(bi); - if (i >= bytes.length || str.endsWith("EEEE")) - flag = false; - } - return Integer.parseInt(str, 16); - } + /** + * bytes杈撳嚭鍗佽繘鍒� + * + * @param bytes + * @return + */ + public static Integer bytesToInt(byte[] bytes) { + String str = ""; + int i = 0; + boolean flag = true && bytes.length > 0; + while (flag) { + Byte b = bytes[i]; + i++; + Integer bi = Byte.toUnsignedInt(b); + str += toHexString(bi); + if (i >= bytes.length || str.endsWith("EEEE")) + flag = false; + } + return Integer.parseInt(str, 16); + } - /** - * bytes杈撳嚭鍗佸叚杩涘埗瀛楃涓� - * - * @param bytes - * @return - */ - public static String bytesToString(byte[] bytes) { - String str = ""; - int i = 0; - boolean flag = true && bytes.length > 0; - while (flag) { - Byte b = bytes[i]; - i++; - Integer bi = Byte.toUnsignedInt(b); - str += toHexString(bi); - if (i >= bytes.length) - flag = false; - } - return str; - } + /** + * bytes杈撳嚭鍗佸叚杩涘埗瀛楃涓� + * + * @param bytes + * @return + */ + public static String bytesToString(byte[] bytes) { + String str = ""; + int i = 0; + boolean flag = true && bytes.length > 0; + while (flag) { + Byte b = bytes[i]; + i++; + Integer bi = Byte.toUnsignedInt(b); + str += toHexString(bi); + if (i >= bytes.length) + flag = false; + } + return str; + } - /** - * 鍗佸叚杩涘埗杞瓧鑺� - * - * @param hex - * @return - */ - public static byte hexToByte(Integer hex) { - return hex.byteValue(); - } + /** + * 鍗佸叚杩涘埗杞瓧鑺� + * + * @param hex + * @return + */ + public static byte hexToByte(Integer hex) { + return hex.byteValue(); + } - /** - * short杞�2瀛楄妭 宸茶皟鏁撮珮浣庝綅 - * - * @param number - * @return - */ - public static byte[] shortToByte(short number) { - int temp = number; - byte[] b = new byte[2]; - for (int i = 0; i < b.length; i++) { - b[i] = new Integer(temp & 0xff).byteValue();// 灏嗘渶浣庝綅淇濆瓨鍦ㄦ渶浣庝綅 - temp = temp >> 8; // 鍚戝彸绉�8浣� - } - return b; - } + /** + * short杞�2瀛楄妭 宸茶皟鏁撮珮浣庝綅 + * + * @param number + * @return + */ + public static byte[] shortToByte(short number) { + int temp = number; + byte[] b = new byte[2]; + for (int i = 0; i < b.length; i++) { + b[i] = new Integer(temp & 0xff).byteValue();// 灏嗘渶浣庝綅淇濆瓨鍦ㄦ渶浣庝綅 + temp = temp >> 8; // 鍚戝彸绉�8浣� + } + return b; + } - /** - * 浜岃繘鍒跺瓙涓茶浆16杩涘埗瀛愪覆 - * - * @param bin - * @return - */ - public static String binToHex(String bin) { - String hexStr = ""; - int size = bin.length() / 8; - for (int i = 0; i < size; i++) { - String value = bin.substring(i * 8, (i + 1) * 8); - int temp = Integer.parseInt(value, 2); - String tempHex = Integer.toHexString(temp); - hexStr += tempHex; - } - return hexStr; - } + /** + * 浜岃繘鍒跺瓙涓茶浆16杩涘埗瀛愪覆 + * + * @param bin + * @return + */ + public static String binToHex(String bin) { + String hexStr = ""; + int size = bin.length() / 8; + for (int i = 0; i < size; i++) { + String value = bin.substring(i * 8, (i + 1) * 8); + int temp = Integer.parseInt(value, 2); + String tempHex = Integer.toHexString(temp); + hexStr += tempHex; + } + return hexStr; + } - /** - * 浜岃繘鍒惰浆16杩涘埗锛屼笉瓒�2浣嶈ˉ浣� - * - * @param bin - * @return - */ - public static String bin2Hex(String bin) { - String hexStr = ""; - int size = bin.length() / 8; - for (int i = 0; i < size; i++) { - String value = bin.substring(i * 8, (i + 1) * 8); - int temp = Integer.parseInt(value, 2); - String tempHex = Integer.toHexString(temp); - if (tempHex.length() < 2) { - tempHex = "0" + tempHex; - } - hexStr += tempHex; - } + /** + * 浜岃繘鍒惰浆16杩涘埗锛屼笉瓒�2浣嶈ˉ浣� + * + * @param bin + * @return + */ + public static String bin2Hex(String bin) { + String hexStr = ""; + int size = bin.length() / 8; + for (int i = 0; i < size; i++) { + String value = bin.substring(i * 8, (i + 1) * 8); + int temp = Integer.parseInt(value, 2); + String tempHex = Integer.toHexString(temp); + if (tempHex.length() < 2) { + tempHex = "0" + tempHex; + } + hexStr += tempHex; + } - return hexStr; - } + return hexStr; + } - /** - * 杞负鍗佸叚杩涘埗涓诧紝涓嶈冻2浣嶈ˉ0 - * - * @param value - * @return - */ - public static String toHexString(int value) { - String tempHex = Integer.toHexString(value); - if (tempHex.length() < 2) { - tempHex = "0" + tempHex; - } - return tempHex.toUpperCase(); - } + /** + * 杞负鍗佸叚杩涘埗涓诧紝涓嶈冻2浣嶈ˉ0 + * + * @param value + * @return + */ + public static String toHexString(int value) { + String tempHex = Integer.toHexString(value); + if (tempHex.length() < 2) { + tempHex = "0" + tempHex; + } + return tempHex.toUpperCase(); + } - public static String getTargetId(String value, boolean isTwo) { - String tempHex = Integer.toHexString(Integer.valueOf(value)); - if (tempHex.length() < 2) { - tempHex = "0" + tempHex; - } - if (isTwo) { - if (tempHex.length() < 4) { - tempHex = "0" + tempHex; - } - if (tempHex.length() < 4) { - tempHex = "0" + tempHex; - } - } - return tempHex.toUpperCase(); - } + public static String getTargetId(String value, boolean isTwo) { + String tempHex = Integer.toHexString(Integer.valueOf(value)); + if (tempHex.length() < 2) { + tempHex = "0" + tempHex; + } + if (isTwo) { + if (tempHex.length() < 4) { + tempHex = "0" + tempHex; + } + if (tempHex.length() < 4) { + tempHex = "0" + tempHex; + } + } + return tempHex.toUpperCase(); + } - /** - * 鏍规嵁鏁板�艰幏鍙栧埌闀垮害涓�2瀛楄妭鐨�16杩涘埗瀛楃 - * - * @param value - * @return - */ - public static String getHex2LenStr(int value) { - String tempHex = Integer.toHexString(value); - if (tempHex.length() < 2) { - tempHex = "0" + tempHex; - } - if (tempHex.length() < 4) { - tempHex = "0" + tempHex; - } - if (tempHex.length() < 4) { - tempHex = "0" + tempHex; - } - return tempHex.toUpperCase(); - } + /** + * 鏍规嵁鏁板�艰幏鍙栧埌闀垮害涓�2瀛楄妭鐨�16杩涘埗瀛楃 + * + * @param value + * @return + */ + public static String getHex2LenStr(int value) { + String tempHex = Integer.toHexString(value); + if (tempHex.length() < 2) { + tempHex = "0" + tempHex; + } + if (tempHex.length() < 4) { + tempHex = "0" + tempHex; + } + if (tempHex.length() < 4) { + tempHex = "0" + tempHex; + } + return tempHex.toUpperCase(); + } - public static String getOrderId(int value) { - return getHex2LenStr(value); - } + public static String getOrderId(int value) { + return getHex2LenStr(value); + } - /** - * 灏唙alue杞负same涓浉鍚屾弧8浣嶇殑浜岃繘鍒跺瓧涓� - * - * @param value - * @param same - * @return - */ - public static String toBinary8StringSame(int value, int same) { - String tempBinStr = toBinary8String(value); - String rsBinStr = ""; - for (int i = 0; i < same; i++) { - rsBinStr += tempBinStr; - } - return rsBinStr; - } + /** + * 灏唙alue杞负same涓浉鍚屾弧8浣嶇殑浜岃繘鍒跺瓧涓� + * + * @param value + * @param same + * @return + */ + public static String toBinary8StringSame(int value, int same) { + String tempBinStr = toBinary8String(value); + String rsBinStr = ""; + for (int i = 0; i < same; i++) { + rsBinStr += tempBinStr; + } + return rsBinStr; + } - /** - * 涓嶈冻width涓瓧鑺傚搴︽椂锛屽墠闈㈣ˉ0鑷硍idth*8 - * - * @param value - * @param width - * @return - */ - public static String toBinary8String(int value, int width) { - String tempBinStr = toBinary8String(value); - int size = tempBinStr.length(); - for (int i = 0; i < width; i++) { - int temp = (i + 1) * 8; - if (temp > size) { - tempBinStr = "00000000" + tempBinStr; - size = tempBinStr.length(); - } - } - return tempBinStr; - } + /** + * 涓嶈冻width涓瓧鑺傚搴︽椂锛屽墠闈㈣ˉ0鑷硍idth*8 + * + * @param value + * @param width + * @return + */ + public static String toBinary8String(int value, int width) { + String tempBinStr = toBinary8String(value); + int size = tempBinStr.length(); + for (int i = 0; i < width; i++) { + int temp = (i + 1) * 8; + if (temp > size) { + tempBinStr = "00000000" + tempBinStr; + size = tempBinStr.length(); + } + } + return tempBinStr; + } - /** - * 琛ヨ冻8浣� - * - * @param value - * @return - */ - public static String toBinary8String(int value) { - String temp = Integer.toBinaryString(value); - if (value == 0) { - temp = "00000000"; - } - int length = temp.length(); - while (length < 8) { - temp = "0" + temp; - length = temp.length(); - } - return temp; - } + /** + * 琛ヨ冻8浣� + * + * @param value + * @return + */ + public static String toBinary8String(int value) { + String temp = Integer.toBinaryString(value); + if (value == 0) { + temp = "00000000"; + } + int length = temp.length(); + while (length < 8) { + temp = "0" + temp; + length = temp.length(); + } + return temp; + } - public static String toEmptyBinaryWidthString(int width) { - String str = ""; - for (int i = 0; i < width; i++) { - str += "00000000"; - } - return str; - } + public static String toEmptyBinaryWidthString(int width) { + String str = ""; + for (int i = 0; i < width; i++) { + str += "00000000"; + } + return str; + } - public static byte[] emptyBytes(int bytes) { - byte[] bys = new byte[bytes]; - for (int i = 0; i < bytes; i++) { - bys[i] = emptyByte(); - } - return bys; - } + public static byte[] emptyBytes(int bytes) { + byte[] bys = new byte[bytes]; + for (int i = 0; i < bytes; i++) { + bys[i] = emptyByte(); + } + return bys; + } - public static byte emptyByte() { - Integer b0 = 0x00; - return b0.byteValue(); - } + public static byte emptyByte() { + Integer b0 = 0x00; + return b0.byteValue(); + } - public static byte binToBytes(String bin) { - return Integer.valueOf(bin, 2).byteValue(); - } + public static byte binToBytes(String bin) { + return Integer.valueOf(bin, 2).byteValue(); + } - public static byte[] binaryStrToBytes(String binStr) { - int size = binStr.length() / 8; - byte[] bs = new byte[size]; - for (int i = 0; i < size; i++) { - String temp = binStr.substring(i * 8, (i + 1) * 8); - bs[i] = Integer.valueOf(temp, 2).byteValue(); - } - return bs; - } + public static byte[] binaryStrToBytes(String binStr) { + int size = binStr.length() / 8; + byte[] bs = new byte[size]; + for (int i = 0; i < size; i++) { + String temp = binStr.substring(i * 8, (i + 1) * 8); + bs[i] = Integer.valueOf(temp, 2).byteValue(); + } + return bs; + } - /** - * 鍗佸叚杩涘埗涓茶浆瀛楄妭鏁扮粍 - * - * @param hexStr - * @return - */ - public static byte[] hexStrToBytes(String hexStr) { - int size = hexStr.length() / 2; - byte[] bytes = new byte[size]; - for (int i = 0; i < size; i++) { - String tmp = hexStr.substring(i * 2, (i + 1) * 2); - Integer tmpHex = Integer.parseInt(tmp, 16); - bytes[i] = tmpHex.byteValue(); - } - return bytes; - } + /** + * 鍗佸叚杩涘埗涓茶浆瀛楄妭鏁扮粍 + * + * @param hexStr + * @return + */ + public static byte[] hexStrToBytes(String hexStr) { + int size = hexStr.length() / 2; + byte[] bytes = new byte[size]; + for (int i = 0; i < size; i++) { + String tmp = hexStr.substring(i * 2, (i + 1) * 2); + Integer tmpHex = Integer.parseInt(tmp, 16); + bytes[i] = tmpHex.byteValue(); + } + return bytes; + } - /** - * 涓ゅ瓧鑺傞珮浣庝綅瑁呮崲 - * - * @param b - * @return - */ - public static byte[] hexHeightLow(byte[] b) { - byte[] b2 = new byte[2]; - // 杞崲楂樹綆浣� - b2[0] = b[1]; - b2[1] = b[0]; - return b2; - } + /** + * 涓ゅ瓧鑺傞珮浣庝綅瑁呮崲 + * + * @param b + * @return + */ + public static byte[] hexHeightLow(byte[] b) { + byte[] b2 = new byte[2]; + // 杞崲楂樹綆浣� + b2[0] = b[1]; + b2[1] = b[0]; + return b2; + } - /** - * 16杩涘埗杞崲涓�10杩涘埗 - * - * @param strHex - * @return - */ - public static int hexToInt(String strHex) { - short s = (short) (Integer.valueOf(strHex, 16) & 0xffff); - return s; - } + /** + * 16杩涘埗杞崲涓�10杩涘埗 + * + * @param strHex + * @return + */ + public static int hexToInt(String strHex) { + short s = (short) (Integer.valueOf(strHex, 16) & 0xffff); + return s; + } - /** - * 16杩涘埗杞崲涓�10杩涘埗 - * - * @param strHex - * @return - */ - public static int hexToBigInt(String strHex) { - BigInteger bigint = new BigInteger(strHex, 16); - return bigint.intValue(); - } + /** + * 16杩涘埗杞崲涓�10杩涘埗 + * + * @param strHex + * @return + */ + public static int hexToBigInt(String strHex) { + BigInteger bigint = new BigInteger(strHex, 16); + return bigint.intValue(); + } - /** - * int杞�16杩涘埗瀛楃涓� 2浣� 00 00 - * - * @param num - * @return - */ - public static String intToHexStr(int num) { - // 闇�瑕佷娇鐢�2瀛楄妭琛ㄧずb - return String.format("%04x", num).toUpperCase(); - } + /** + * int杞�16杩涘埗瀛楃涓� 2浣� 00 00 + * + * @param num + * @return + */ + public static String intToHexStr(int num) { + // 闇�瑕佷娇鐢�2瀛楄妭琛ㄧずb + return String.format("%04x", num).toUpperCase(); + } - public static void main(String[] args) { - - double d1 = hexToBigInt("000906EB")/100.0; - double d2 = hexToBigInt("0004F6E6")/100.0; - - System.out.println(d1); - System.out.println(d2); - - System.out.println(d1 + d2); + public static void main(String[] args) { - - } +// double d1 = hexToBigInt("000906EB")/100.0; +// double d2 = hexToBigInt("0004F6E6")/100.0; +// +// System.out.println(d1); +// System.out.println(d2); +// +// System.out.println(d1 + d2); - /** - * 16杩涘埗瀛楃涓� 楂樹綆鎹綅 - * - * @param info - * @return - */ - public static String tran_LH(String info) { - return info.substring(2) + info.substring(0, 2); - } - /** - * 16杩涘埗瀛楃涓� 楂樹綆鎹綅 8涓瓧绗� - * - * @param info - * @return - */ - public static String tran_LH8(String info) { - return tran_LH(info.substring(4)) + tran_LH(info.substring(0, 4)); - } + String kyeNumBin = "10100100"; + String key = "00000" + kyeNumBin.substring(0, 3); - /** - * 灏� 4瀛楄妭鐨�16杩涘埗瀛楃涓诧紝杞崲涓�32浣嶅甫绗﹀彿鐨勫崄杩涘埗娴偣鍨� - * - * 42c60000 -> 99.00 - * - * @param str - * 4瀛楄妭 16杩涘埗瀛楃 - * @return - */ - public static float hexToFloat(String str) { - return Float.intBitsToFloat(new BigInteger(str, 16).intValue()); - } + System.out.println("-----key-----" + key); - /** - * 灏嗗甫绗﹀彿鐨�32浣嶆诞鐐规暟瑁呮崲涓�16杩涘埗 - * - * 99.00 -> 42c60000 - * - * - * @param value - * @return - */ - public static String folatToHexString(Float value) { - return Integer.toHexString(Float.floatToIntBits(value)); - } + String bin2hex = BytesUtil.bin2Hex(key); - /** - * int杞�16杩涘埗瀛楃涓� 1浣嶇疆 00 - * - * @param num - * @return - */ - public static String intToHexStr1(int num) { - // 闇�瑕佷娇鐢�2瀛楄妭琛ㄧずb - return String.format("%02x", num).toUpperCase(); - } + System.out.println("-----bin2hex-----" + bin2hex); - public static String hexString2binaryString(String hexString, int num) { - //16杩涘埗杞�10杩涘埗 - BigInteger sint = new BigInteger(hexString, num); - //10杩涘埗杞�2杩涘埗 - String str = sint.toString(2); - if(str.length() < num){ - for (int i = str.length(); i < num; i++) { - str = "0" + str; - } - } - return str; - } + int keyValue = BytesUtil.hexToInt(bin2hex); - /** - * 灏嗕簩杩涘埗杞崲涓�10杩涘埗 - * @param binStr - * @return - */ - public static Integer biannary2Decimal(String binStr){ + System.out.println("-----keyValue-----" + keyValue); - Integer sum = 0; - int len = binStr.length(); + key = "0000" + kyeNumBin.substring(4); - for (int i=1;i<=len;i++){ - //绗琲浣� 鐨勬暟瀛椾负锛� - int dt = Integer.parseInt(binStr.substring(i-1,i)); - sum+=(int)Math.pow(2,len-i)*dt; - } - return sum; - } + System.out.println("-----key-----" + key); - /** - * 浜岃繘鍒惰ˉ鐮侊細鍙栧弽鍙e姞1 - * @param str - * @return - */ - public static Integer twoToString(String str) { - String two = ""; - String[] split = str.split(""); - for (int i = 0;i< split.length;i++){ - if("1".equals(split[i])){ - two += "0"; - }else if("0".equals(split[i])){ - two += "1"; - } - } - return biannary2Decimal(two) + 1; - } + bin2hex = BytesUtil.bin2Hex(key); + System.out.println("-----bin2hex-----" + bin2hex); + keyValue = BytesUtil.hexToInt(bin2hex); + System.out.println("-----keyValue-----" + keyValue); - public static String byteToHex(byte b) { - String hex = Integer.toHexString(b & 0xFF); - if (hex.length() < 2) { - hex = "0" + hex; - } - return hex; - } + } + + /** + * 16杩涘埗瀛楃涓� 楂樹綆鎹綅 + * + * @param info + * @return + */ + public static String tran_LH(String info) { + return info.substring(2) + info.substring(0, 2); + } + + /** + * 16杩涘埗瀛楃涓� 楂樹綆鎹綅 8涓瓧绗� + * + * @param info + * @return + */ + public static String tran_LH8(String info) { + return tran_LH(info.substring(4)) + tran_LH(info.substring(0, 4)); + } + + /** + * 灏� 4瀛楄妭鐨�16杩涘埗瀛楃涓诧紝杞崲涓�32浣嶅甫绗﹀彿鐨勫崄杩涘埗娴偣鍨� + * <p> + * 42c60000 -> 99.00 + * + * @param str 4瀛楄妭 16杩涘埗瀛楃 + * @return + */ + public static float hexToFloat(String str) { + return Float.intBitsToFloat(new BigInteger(str, 16).intValue()); + } + + /** + * 灏嗗甫绗﹀彿鐨�32浣嶆诞鐐规暟瑁呮崲涓�16杩涘埗 + * <p> + * 99.00 -> 42c60000 + * + * @param value + * @return + */ + public static String folatToHexString(Float value) { + return Integer.toHexString(Float.floatToIntBits(value)); + } + + /** + * int杞�16杩涘埗瀛楃涓� 1浣嶇疆 00 + * + * @param num + * @return + */ + public static String intToHexStr1(int num) { + // 闇�瑕佷娇鐢�2瀛楄妭琛ㄧずb + return String.format("%02x", num).toUpperCase(); + } + + public static String hexString2binaryString(String hexString, int num) { + //16杩涘埗杞�10杩涘埗 + BigInteger sint = new BigInteger(hexString, num); + //10杩涘埗杞�2杩涘埗 + String str = sint.toString(2); + if (str.length() < num) { + for (int i = str.length(); i < num; i++) { + str = "0" + str; + } + } + return str; + } + + /** + * 灏嗕簩杩涘埗杞崲涓�10杩涘埗 + * + * @param binStr + * @return + */ + public static Integer biannary2Decimal(String binStr) { + + Integer sum = 0; + int len = binStr.length(); + + for (int i = 1; i <= len; i++) { + //绗琲浣� 鐨勬暟瀛椾负锛� + int dt = Integer.parseInt(binStr.substring(i - 1, i)); + sum += (int) Math.pow(2, len - i) * dt; + } + return sum; + } + + /** + * 浜岃繘鍒惰ˉ鐮侊細鍙栧弽鍙e姞1 + * + * @param str + * @return + */ + public static Integer twoToString(String str) { + String two = ""; + String[] split = str.split(""); + for (int i = 0; i < split.length; i++) { + if ("1".equals(split[i])) { + two += "0"; + } else if ("0".equals(split[i])) { + two += "1"; + } + } + return biannary2Decimal(two) + 1; + } + + public static String byteToHex(byte b) { + String hex = Integer.toHexString(b & 0xFF); + if (hex.length() < 2) { + hex = "0" + hex; + } + return hex; + } } diff --git a/src/main/java/com/fzzy/gateway/hx2023/service/DeviceReportServiceImpl.java b/src/main/java/com/fzzy/gateway/hx2023/service/DeviceReportServiceImpl.java index 7ba5fdc..2d572be 100644 --- a/src/main/java/com/fzzy/gateway/hx2023/service/DeviceReportServiceImpl.java +++ b/src/main/java/com/fzzy/gateway/hx2023/service/DeviceReportServiceImpl.java @@ -2,6 +2,7 @@ import com.alibaba.fastjson2.JSONObject; import com.fzzy.api.data.PushProtocol; +import com.fzzy.data.ConfigData; import com.fzzy.gateway.api.GatewayDeviceReportService; import com.fzzy.gateway.data.BaseReqData; import com.fzzy.gateway.data.BaseResp; @@ -13,6 +14,7 @@ import com.fzzy.gateway.hx2023.data.WeightInfo; import com.fzzy.gateway.hx2023.kafka.KafkaDeviceReportService; import com.fzzy.mqtt.MqttGatewayService; +import jdk.nashorn.internal.runtime.regexp.joni.Config; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang.StringUtils; import org.springframework.stereotype.Component; @@ -27,6 +29,8 @@ private KafkaDeviceReportService kafkaDeviceReportService; @Resource private MqttGatewayService publishService; + @Resource + private ConfigData configData; @Override public String getProtocol() { @@ -39,6 +43,16 @@ String topic = ScConstant.TOPIC_REPORT; topic = topic.replace("${productId}", reqData.getProductId()).replace("${deviceId}", reqData.getDeviceId()); + //濡傛灉鏄祴璇曟ā寮忎笉鎵ц鎺ㄩ�� + if(configData.getActive().indexOf("dev")>=0){ + + log.info("----------------------------鎺ㄩ�丮QTT绮儏淇℃伅锛屾敞锛氳皟璇曟ā寮忎笉鎺ㄩ��---------------------------"); + log.info("-----TOPIC-----{}", topic); + log.info("-----Message-----{}", reqData.getData()); + + return new BaseResp(); + } + publishService.publishMqttWithTopic(reqData.getData(), topic); log.info("----------------------------鎺ㄩ�丮QTT绮儏淇℃伅---------------------------"); diff --git a/src/main/java/com/fzzy/protocol/youxian0/analysis/AnalysisService.java b/src/main/java/com/fzzy/protocol/youxian0/analysis/AnalysisService.java index 5e1d840..fd3b52b 100644 --- a/src/main/java/com/fzzy/protocol/youxian0/analysis/AnalysisService.java +++ b/src/main/java/com/fzzy/protocol/youxian0/analysis/AnalysisService.java @@ -1,7 +1,6 @@ package com.fzzy.protocol.youxian0.analysis; import com.alibaba.fastjson.JSONObject; -import com.fzzy.api.Constant; import com.fzzy.api.data.GatewayDeviceType; import com.fzzy.api.utils.BytesUtil; import com.fzzy.api.utils.NumberUtil; @@ -39,7 +38,6 @@ @Resource private GatewayRemoteManager gatewayRemoteManager; - private static Map<String, GrainRoot> contextGrainRoot = new HashMap<>(); @@ -80,11 +78,14 @@ //绮儏杩斿洖 if (ServiceUtils.FUNCTION_66.equalsIgnoreCase(funId)) { + + log.info("---------寮�濮嬭В鏋愮伯鎯呬俊鎭�---------"); this.analysisGrainStep1(device, msgId, strMsg); } //娓╂箍搴﹁繑鍥� if (ServiceUtils.FUNCTION_68.equalsIgnoreCase(funId)) { + log.info("---------寮�濮嬭В鏋愪粨娓╂箍搴︿俊鎭�---------"); this.analysisGrainTh(device, strMsg); } @@ -130,9 +131,9 @@ String kyeNumHex = strMsg.substring(2, 4); String kyeNumBin = BytesUtil.toBinary8String(BytesUtil.hexToInt(kyeNumHex)); - String key = kyeNumBin.substring(0, 3); + String key = "00000" + kyeNumBin.substring(0, 3); int keyValue = BytesUtil.hexToInt(BytesUtil.bin2Hex(key)); - key = kyeNumBin.substring(4); + key = "0000" + kyeNumBin.substring(4); int numValue = BytesUtil.hexToInt(BytesUtil.bin2Hex(key)); //02 A4 BB BA BA B4 @@ -149,6 +150,7 @@ point = this.getGrainTemp(keyValue, tempHex); log.debug("--------瑙f瀽鍚庣殑娓╁害鐐�----{}---{}", tempHex, point); grainRoot.getPoints().add(point); + start = 2 * 2; } @@ -307,6 +309,7 @@ log.error("------------绮儏鎺ㄩ�佸け璐ワ紝绯荤粺涓嶅瓨鍦ㄥ綋鍓嶅崗璁墽琛岀被----{}", reqData.getDevice().getDeviceName()); return; } + reportService.reportGrainData(reqData); } diff --git a/src/main/java/com/fzzy/protocol/youxian0/client/ClientHandler.java b/src/main/java/com/fzzy/protocol/youxian0/client/ClientHandler.java index 0e99869..41e4c99 100644 --- a/src/main/java/com/fzzy/protocol/youxian0/client/ClientHandler.java +++ b/src/main/java/com/fzzy/protocol/youxian0/client/ClientHandler.java @@ -31,6 +31,8 @@ InetSocketAddress socketAddress = (InetSocketAddress) ctx.channel().remoteAddress(); log.info("杩炴帴缁堢鎺夌嚎锛孖P={},port={}", socketAddress.getAddress(), socketAddress.getPort()); + + } @Override diff --git a/src/main/java/com/fzzy/protocol/youxian0/service/Youxian0GatewayGrainService.java b/src/main/java/com/fzzy/protocol/youxian0/service/Youxian0GatewayGrainService.java index b15b8ba..ba4473e 100644 --- a/src/main/java/com/fzzy/protocol/youxian0/service/Youxian0GatewayGrainService.java +++ b/src/main/java/com/fzzy/protocol/youxian0/service/Youxian0GatewayGrainService.java @@ -65,22 +65,26 @@ String hexStr = ""; InvokeResult message; for (int i = 1; i <= cableX; i++) { - if (1 == i) start = 255; - start = i * cableY + 1; + if (1 == i) { + start = 255; + } else { + start = (i - 1) * cableY + 1; + } hexStr = this.buildGrainCmd(device, i, start, length); - // 鍙戦�佸懡浠� - Channel channel = ClientEngine.getChannel(device.getIp()); + // 鍙戦�佸懡浠� TODO----->>>鏆傛椂璋冩暣涓烘瘡娆″垱寤轰竴涓柊杩炴帴 + //Channel channel = ClientEngine.getChannel(device.getIp()); + Channel channel = null; if (null == channel) { ClientEngine clientEngine = new ClientEngine(device.getIp(), device.getPort()); clientEngine.start(); - Thread.sleep(500); + Thread.sleep(300); channel = clientEngine.getChannel(); } message = ClientEngine.send2(hexStr, channel); - log.error("骞冲彴------>>>>鎺у埗鏌滐細鍙戦�佺伯鎯呮娴嬪懡浠�-{}", message); + log.error("骞冲彴------>>>>涓绘帶锛氬彂閫佺伯鎯呮娴嬪懡浠�-{}---{}", message,hexStr); // 灏佽杩斿洖淇℃伅 if (!InvokeResult.SUCCESS.getCode().equals(message.getCode())) { @@ -118,22 +122,23 @@ //寮�濮嬪皝瑁呮秷鎭綋-涓绘満ID String deviceSn = device.getDeviceSn(); deviceSn = BytesUtil.intToHexStr1(Integer.valueOf(deviceSn)); - content = content.replaceAll("\\{id}", deviceSn); + content = content.replace("{id}", deviceSn); + content = content.replace("{id}", deviceSn); //鍛戒护ID String msgIdHex = BytesUtil.intToHexStr1(cur); - content = content.replace("\\{msgId}", msgIdHex); + content = content.replace("{msgId}", msgIdHex); //鍛戒护绫诲瀷 - content = content.replace("\\{funId}", ServiceUtils.FUNCTION_66); + content = content.replace("{funId}", ServiceUtils.FUNCTION_66); //寮�濮嬫牴鍙� String startCurHex = BytesUtil.intToHexStr1(startCur); - content = content.replace("\\{start}", startCurHex); + content = content.replace("{start}", startCurHex); //鎴彇闀垮害 String lenHex = BytesUtil.intToHexStr1(length); - content = content.replace("\\{length}", lenHex); + content = content.replace("{length}", lenHex); //鏍¢獙鐮� String crcCode = this.getCRC(content); -- Gitblit v1.9.3