jiazx0107@163.com
2023-12-24 66b091963fb0f3356f27ec094c013369bf91db89
游仙协议解析-3
已修改5个文件
888 ■■■■ 文件已修改
src/main/java/com/fzzy/api/utils/BytesUtil.java 834 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/gateway/hx2023/service/DeviceReportServiceImpl.java 14 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/protocol/youxian0/analysis/AnalysisService.java 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/protocol/youxian0/client/ClientHandler.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/protocol/youxian0/service/Youxian0GatewayGrainService.java 27 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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);
    }
    /**
     * 将value转为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;
    }
    /**
     * 将value转为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至width*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至width*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++){
            //第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);
    /**
     * 二进制补码:取反口加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++) {
            //第i位 的数字为:
            int dt = Integer.parseInt(binStr.substring(i - 1, i));
            sum += (int) Math.pow(2, len - i) * dt;
        }
        return sum;
    }
    /**
     * 二进制补码:取反口加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;
    }
}
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("----------------------------推送MQTT粮情信息,注:调试模式不推送---------------------------");
            log.info("-----TOPIC-----{}", topic);
            log.info("-----Message-----{}", reqData.getData());
            return new BaseResp();
        }
        publishService.publishMqttWithTopic(reqData.getData(), topic);
        log.info("----------------------------推送MQTT粮情信息---------------------------");
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("--------解析后的温度点----{}---{}", tempHex, point);
            grainRoot.getPoints().add(point);
            start = 2 * 2;
        }
@@ -307,6 +309,7 @@
            log.error("------------粮情推送失败,系统不存在当前协议执行类----{}", reqData.getDevice().getDeviceName());
            return;
        }
        reportService.reportGrainData(reqData);
    }
src/main/java/com/fzzy/protocol/youxian0/client/ClientHandler.java
@@ -31,6 +31,8 @@
        InetSocketAddress socketAddress = (InetSocketAddress) ctx.channel().remoteAddress();
        log.info("连接终端掉线,IP={},port={}", socketAddress.getAddress(), socketAddress.getPort());
    }
    @Override
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);