vince
2025-01-08 caf2599a9869244ded811018811c37a2aabac3fc
src/main/java/com/fzzy/protocol/youxian0/analysis/AnalysisService.java
@@ -160,7 +160,12 @@
        String tempStr = "";
        for (int j = 0;j<cableY;j++){
            tempStr = strMsg.substring(12 * j,12 * j +12);
            String index = BytesUtil.intToHexStr1((msgId -1)*cableY + j +1);
            tempStr = strMsg.substring(strMsg.indexOf(index),strMsg.indexOf(index) + (6+2*cableZ) );
            strMsg = strMsg.substring(strMsg.indexOf(index) + (6+2*cableZ));
            //tempStr = strMsg.substring((6+2*cableZ) * j,(6+2*cableZ)  * j + (6+2*cableZ) );
            log.info("----线缆报文----:"+tempStr);
            log.info("----剩余报文----:"+strMsg);
            //密钥和点数 02 A4 BB BA BA B4
            String kyeNumHex = tempStr.substring(2, 4);
            String kyeNumBin = BytesUtil.toBinary8String(BytesUtil.hexToInt(kyeNumHex));
@@ -173,10 +178,11 @@
            //02 A4 BB BA BA B4
            start = 2 * 2;
            String tempHex;
            double point = 0;
            for (int i = 0; i < numValue; i++) {
                start = start + i * 2;
            log.info("----报文----:"+tempStr);
            log.info("----密钥="+keyValue +"----点数="+numValue+"----"+"层数="+cableZ+"----");
            for (int i = 0; i < cableZ; i++) {
                start = start + (i * 2);
                tempHex = tempStr.substring(start, start + 2);
                //实际温度=密钥*密钥*37(溢出为无符号字节)再异或加密后的温度/2。
                point = this.getGrainTemp(keyValue, tempHex);
@@ -207,14 +213,24 @@
        List<Double> points = new ArrayList<>();
        GrainRoot root;
        List<Double> t = null;
        for (int i = 1; i <= cableX; i++) {
            root = this.getGrainRoot(buildGrainRootKey(reqData.getDevice().getDeviceSn(), i));
            if (null == root || null == root.getPoints()) {
                log.error("-----------解析获取所有粮情检测点失败,取消执行---------{}---{}", reqData.getDevice().getDeviceName(),i);
                return;
                ;
                t = new ArrayList<>();
                for (int x = 0;x<cableY*cableZ;x++
                     ) {
                    t.add(-100.00);
                }
                //return;
                points.addAll(t);
            }else{
                points.addAll(root.getPoints());
            }
            points.addAll(root.getPoints());
        }
        //执行封装解析
@@ -241,11 +257,11 @@
        GrainOutPut outPut = new GrainOutPut();
        double max = ReMessageBuilder.MAX_TEMP, min = ReMessageBuilder.MIN_TEMP, sumT = 0.0, sumNum = cableX * cableY * cableZ;
        double max = ReMessageBuilder.MAX_TEMP, min = ReMessageBuilder.MIN_TEMP, sumT = 0.0;
        List<GrainTemp> temperature = new ArrayList<>();
        //根号
        int cableNum = 1, position = 0;
        int cableNum = 1, position = 0,sumNum = 0;
        double curTemp;
        int x = 0, y = 0, z = 0;
@@ -261,12 +277,15 @@
            temperature.add(new GrainTemp(cableNum + "", z + "", curTemp + "", position + ""));
            sumT += curTemp;
            if (curTemp > max) {
            if (curTemp > max  && curTemp < 40) {
                max = curTemp;
            }
            if (curTemp < min) {
            if (curTemp < min && curTemp > 3) {
                min = curTemp;
            }
            if(curTemp > 3 &&  curTemp < 40){
                sumT += curTemp;
                sumNum++;
            }
        }
@@ -285,7 +304,7 @@
        outPut.setTemperature(temperature);
        outPut.setAvgTemperature(NumberUtil.keepPrecision((sumT / sumNum), 1) + "");
        outPut.setMinTemperature(min + "");
        outPut.setMaxTemperature(min + "");
        outPut.setMaxTemperature(max + "");
        List<GrainTH> ths = new ArrayList<>();
@@ -312,7 +331,7 @@
            weatherStation.setId(device.getDeviceId());
        }
        weatherStation.setAirPressure(weather.getPressure());
        weatherStation.setHumidity(weather.getHumidity());
        weatherStation.setHumidity(weather.getHumidity().replaceAll("%",""));
        weatherStation.setPm(weather.getAir_pm25());
        weatherStation.setRadiation("0");
        weatherStation.setRainfallAmount(weather.getWea());
@@ -328,21 +347,22 @@
        reqData.setData(JSONObject.toJSONString(grain));
        doPushGrain(reqData);
        doPushGrain(reqData,grain);
    }
    private void doPushGrain(BaseReqData reqData) {
    private void doPushGrain(BaseReqData reqData,GrainData grainData) {
        GatewayDeviceReportService reportService = gatewayRemoteManager.getDeviceReportService(reqData.getDevice().getPushProtocol());
        if (null == reportService) {
            log.error("------------粮情推送失败,系统不存在当前协议执行类----{}", reqData.getDevice().getDeviceName());
            return;
        }
        reportService.reportGrainData(reqData);
        reqData.setData(reportService.grainData2GatewayApiInfoKafka(grainData,reqData.getDevice()).getData());
        reportService.reportGrainDataByKafka(reqData);
    }
    private void add2GrainMap(GrainRoot grainRoot) {
    private synchronized  void add2GrainMap(GrainRoot grainRoot) {
        contextGrainRoot.put(grainRoot.getKey(), grainRoot);
    }
@@ -371,8 +391,12 @@
        int num1 = BytesUtil.hexToInt(valueHex);
        int num2 = BytesUtil.hexToInt(tempHex);
        if((num1 ^ num2) / 2.0 > 35){
            return  -100.00;
        }else {
            return  (num1 ^ num2) / 2.0;
        }
        return (num1 ^ num2) / 2.0;
    }
    private void add2ThMap(String depotIdSys, THDto th) {