CZT
2023-10-07 876270f40c443d99729c5d98d629b74fa5a7a1c0
贝博粮情解析5
已修改2个文件
88 ■■■■ 文件已修改
igds-core/src/main/java/com/ld/igds/util/BytesUtil.java 45 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
igds-protocol-beibo/src/main/java/com/ld/igds/protocol/beibo/grainv1/analysis/AnalysisService.java 43 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
igds-core/src/main/java/com/ld/igds/util/BytesUtil.java
@@ -190,6 +190,42 @@
        return rsBinStr;
    }
    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;
    }
    public static void main(String[] args) {
        String s = hexString2binaryString("21E9", 16);
        System.out.println(s);
    }
    /**
     * 不足width个字节宽度时,前面补0至width*8
     * 
@@ -362,15 +398,6 @@
            nSum = nSum * nValue;
        }
        return nSum;
    }
    public static void main(String[] args) {
        String hex = "<END>";
        byte[] attr = hex.getBytes();
        hex = bytesToString(attr);
    }
    /**
igds-protocol-beibo/src/main/java/com/ld/igds/protocol/beibo/grainv1/analysis/AnalysisService.java
@@ -26,6 +26,7 @@
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.*;
/**
@@ -54,13 +55,12 @@
    public static String result = "";
    public static Map<String, String> contextMap = new HashMap<>();
    public static double ERROR_CHECK_TAG = -100.0;
    public static double FAULT_CHECK_TAG = 85.0;
    public static double ERROR_CHECK_TAG2 = 50;
    public static String ERROR_HEX = "FFFF";
    public static double MAX_TEMP = -50.0;
    public static double MIN_TEMP = 50.0;
@@ -69,6 +69,7 @@
        String str = "00000000FFEB90FEAA41E821EC21EA21EC21ED21EC21E921E221E921E921E921EC21E921ED21F021E521E521E221E421E321E321E121DE21D721E021DD21DC21DF21FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF";
        System.out.println(str.substring(9*2, 10*2));
    }
    /**
     * 00000000FFEB90FEAA41E821EC21EA21EC21ED21EC21E921E221E921E921E921EC21E921ED21F021E521E521E221E421E321E321E121DE21D721E021DD21DC21DF21FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
     *
@@ -81,6 +82,9 @@
            log.info("分机------->>平台,报文长度不够,等待下一包数据");
            return;
        }
        try {
        //封装数据
        ReMessage reMessage = ReMessageBuilder.getInstance().buildMessage(result);
@@ -130,6 +134,10 @@
        reMessage.setCompanyId(ser.getCompanyId());
        analysisGrain(depotConf, reMessage, ser, exeRequest, sysConf);
        } catch (Exception e) {
            result = "";
            log.error("分机------->>平台,解析粮情异常:原因={}", e.toString());
        }
    }
@@ -255,15 +263,22 @@
                temp = "0000";
            }
            //高低位转换后转为16位二进制字符串
            temp = BytesUtil.toBinary8StringSame(BytesUtil.hexToInt(BytesUtil.tran_LH(temp)), 16);
            temp = BytesUtil.tran_LH(temp);
            if(ERROR_HEX.equals(temp)){
                tempValue = Constant.ERROR_TEMP;
            }else {
                //10进制转16位的2进制
                temp = BytesUtil.hexString2binaryString(temp, 16);
            //符号位
            symbol = Integer.valueOf(temp.substring(0, 1));
            //获取温度值
            tempValue = BytesUtil.hexToInt(BytesUtil.binToHex(temp.substring(6))) * 0.0625;
                tempValue = BytesUtil.biannary2Decimal(temp.substring(6)) * 0.0625;
                //若为负,则补码:取反加1
            if(symbol == 1){
                tempValue = (1- BytesUtil.hexToInt(BytesUtil.binToHex(temp.substring(6))))*0.0625;
                    tempValue = ((~BytesUtil.biannary2Decimal(temp.substring(6))) + 1) * 0.0625;
            }
            tempValue = NumberUtil.keepPrecision(tempValue, 1);
            }
            //非正常值
            if (tempValue > ERROR_CHECK_TAG2) {
@@ -370,16 +385,22 @@
                temp = "0000";
            }
            //高低位转换后转为16位二进制字符串
            temp = BytesUtil.toBinary8StringSame(BytesUtil.hexToInt(BytesUtil.tran_LH(temp)), 16);
            if(ERROR_HEX.equals(temp)){
                tempValue = Constant.ERROR_TEMP;
            }else {
                //10进制转16位的2进制
                temp = BytesUtil.hexString2binaryString(temp, 16);
            //符号位
            symbol = Integer.valueOf(temp.substring(0, 1));
            //获取温度值
            tempValue = BytesUtil.hexToInt(BytesUtil.binToHex(temp.substring(6))) * 0.0625;
                tempValue = BytesUtil.biannary2Decimal(temp.substring(6)) * 0.0625;
                //若为负,则补码:取反加1
            if(symbol == 1){
                tempValue = (1- BytesUtil.hexToInt(BytesUtil.binToHex(temp.substring(6))))*0.0625;
                    tempValue = ((~BytesUtil.biannary2Decimal(temp.substring(6))) + 1) * 0.0625;
            }
            tempValue = NumberUtil.keepPrecision(tempValue, 1);
            }
            // 说明解析的数据有问题
            if (tempValue == ERROR_CHECK_TAG || tempValue == ERROR_CHECK_TAG2) {
                tempValue = Constant.ERROR_TEMP;
@@ -442,7 +463,7 @@
        grain.setTempIn(Constant.ERROR_TEMP);
        grain.setHumidityIn(Constant.ERROR_TEMP);
        grain.setReceiveDate(msg.getReceiveDate());
        grain.setReceiveDate(new Date());
        grain.setRemark("粮温正常");
        // 获取缓存中的命令信息
@@ -524,7 +545,7 @@
        grain.setTempIn(Constant.ERROR_TEMP);
        grain.setHumidityIn(Constant.ERROR_TEMP);
        grain.setReceiveDate(msg.getReceiveDate());
        grain.setReceiveDate(new Date());
        grain.setRemark("粮温正常");
        grain.setCheckUser(exeRequest.getExeUser());