2021与蓝度共同重构项目,服务端
zhanzhiqin
2022-08-04 ff3ee157b0d2cce72e3419c65b6eb1a5d53d32e2
大气设备
已修改7个文件
408 ■■■■■ 文件已修改
ximon-admin/src/main/java/com/sandu/ximon/admin/controller/AirEquipmentController.java 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ximon-admin/src/main/java/com/sandu/ximon/admin/manager/iot/frame/inner/report/A5AtmosphereHeartbeatReportInnerFrame.java 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ximon-admin/src/main/java/com/sandu/ximon/admin/manager/iot/frame/inner/report/A5AtmosphereQueryVersionReportInnerFrame.java 13 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ximon-admin/src/main/java/com/sandu/ximon/admin/manager/iot/frame/inner/request/AtmosphereModifiedDataReqInnerFrame.java 258 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ximon-admin/src/main/java/com/sandu/ximon/admin/manager/iot/rrpc/enums/AtmoFunctionCode.java 32 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ximon-admin/src/main/java/com/sandu/ximon/admin/service/AirEquipmentService.java 23 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ximon-admin/src/test/java/com/sandu/ximon/admin/AdminApplicationTests.java 73 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ximon-admin/src/main/java/com/sandu/ximon/admin/controller/AirEquipmentController.java
@@ -91,8 +91,7 @@
     */
    @GetMapping("/QueryVersion")
    public ResponseVO<Object> QueryVersion(@RequestParam(value = "mac", required = false) String mac) {
        airEquipmentService.QueryVersion(mac);
        return ResponseUtil.success(null);
        return ResponseUtil.success(airEquipmentService.QueryVersion(mac));
    }
    /**
@@ -116,10 +115,11 @@
     * @param valueOfStandard 标准仪器数值
     * @return
     */
    @GetMapping("/ModifiedData")
    public ResponseVO<Object> ModifiedData(@RequestParam(value = "mac", required = false) String mac,
                                           @RequestParam(value = "type", required = false) String type,
                                           @RequestParam(value = "valueOfReal", required = false) Double valueOfReal,
                                           @RequestParam(value = "valueOfStandard", required = false) Double valueOfStandard) {
                                           @RequestParam(value = "valueOfReal", required = false) String valueOfReal,
                                           @RequestParam(value = "valueOfStandard", required = false) String valueOfStandard) {
        airEquipmentService.ModifiedData(mac, type, valueOfReal, valueOfStandard);
        return ResponseUtil.success(null);
    }
ximon-admin/src/main/java/com/sandu/ximon/admin/manager/iot/frame/inner/report/A5AtmosphereHeartbeatReportInnerFrame.java
@@ -27,6 +27,7 @@
    @Override
    public A5AtmosphereHeartbeatReportInnerFrame transformFrame(String hex) {
        //  长度不一致时,返回null
        //TODO
        if (StrUtil.isBlank(hex)) {
            return null;
        }
ximon-admin/src/main/java/com/sandu/ximon/admin/manager/iot/frame/inner/report/A5AtmosphereQueryVersionReportInnerFrame.java
@@ -16,10 +16,13 @@
public class A5AtmosphereQueryVersionReportInnerFrame extends BaseResponseInnerFrame<A5AtmosphereQueryVersionReportInnerFrame> {
    //设备地址
    private String deviceAddress;
    //硬件版本
    private String version;
    @Override
    public A5AtmosphereQueryVersionReportInnerFrame transformFrame(String hex) {
        if (StrUtil.isBlank(hex) || hex.length() != 100) {
        //FE040004FFFF0105954FAA7F
        if (StrUtil.isBlank(hex) || hex.length() != 24) {
            return null;
        }
        // MQTT通信方式(1)
@@ -30,7 +33,13 @@
        setPayloadLength(hex.substring(4, 8));
        //设备地址
        setDeviceAddress(hex.substring(8, 12));
        //
        //硬件版本
        String version1 = String.valueOf(Integer.parseInt(hex.substring(12, 14), 16));
        String version2 = String.valueOf(Integer.parseInt(hex.substring(14, 16), 16));
        if (version2.length() == 1) {
            version2 = "0" + version2;
        }
        setVersion("硬件版本为:" + version1 + "." + version2);
        //校验
        setCrc32(hex.substring(hex.length() - 8));
ximon-admin/src/main/java/com/sandu/ximon/admin/manager/iot/frame/inner/request/AtmosphereModifiedDataReqInnerFrame.java
@@ -5,6 +5,8 @@
import com.sandu.ximon.admin.manager.iot.rrpc.enums.MQTTConnectTypeEnum;
import com.sandu.ximon.admin.manager.iot.rrpc.util.CRC32Utils;
import java.math.BigDecimal;
/**
 * 大气设备修正数据
 *
@@ -12,81 +14,327 @@
 * @date 2022/7/29 10:32
 */
public class AtmosphereModifiedDataReqInnerFrame implements IRequestInnerFrame {
    //TODO
    private String functionCode;
    private String value;
    public AtmosphereModifiedDataReqInnerFrame(String functionType, Double valueOfReal, Double valueOfStandard) {
    public AtmosphereModifiedDataReqInnerFrame(String functionType, String valueOfReal, String valueOfStandard) {
        //传感器数值
        BigDecimal value1;
        //标准值
        BigDecimal value2;
        //修正值
        Double subtract;
        //整数
        int i;
        //小数
        int y;
        int z;
        switch (functionType) {
            //设置数据修正值-温度
            case "温度":
                functionCode = AtmoFunctionCode.Setting_Data_Correction_temperature.getCode();
                value1 = new BigDecimal(valueOfReal);
                value2 = new BigDecimal(valueOfStandard);
                subtract = value1.subtract(value2).doubleValue();
                i = Integer.valueOf((int) (subtract * 100)) / 100;
                y = Integer.valueOf((int) (subtract * 100)) % 100;
                if (subtract > 0) {
                    value = hex10To16(i) + hex10To16(y);
                } else {
                    value = hex10To16(-i + 128) + hex10To16(-y);
                }
                break;
            //设置数据修正值-湿度
            case "湿度":
                functionCode = AtmoFunctionCode.Setting_Data_Correction_humidity.getCode();
                value1 = new BigDecimal(valueOfReal);
                value2 = new BigDecimal(valueOfStandard);
                subtract = value1.subtract(value2).doubleValue();
                i = Integer.valueOf((int) (subtract * 100)) / 100;
                y = Integer.valueOf((int) (subtract * 100)) % 100;
                if (subtract > 0) {
                    value = hex10To16(i) + hex10To16(y);
                } else {
                    value = hex10To16(-i + 128) + hex10To16(-y);
                }
                break;
            //设置数据修正值-风速
            case "风速":
                functionCode = AtmoFunctionCode.Setting_Data_Correction_windSpeed.getCode();
                value1 = new BigDecimal(valueOfReal);
                value2 = new BigDecimal(valueOfStandard);
                subtract = value1.subtract(value2).doubleValue();
                z = Integer.valueOf((int) (subtract * 10));
                if (subtract > 0) {
                    value = hex10To16(z);
                } else {
                    value = hex10To16(-z + 32768);
                }
                break;
            //设置数据修正值-风向
            case "风向":
                functionCode = AtmoFunctionCode.Setting_Data_Correction_windDirection.getCode();
                //TODO
                break;
            //设置数据修正值-风力
            case "风力":
                functionCode = AtmoFunctionCode.Setting_Data_Correction_windPower.getCode();
                //TODO
                break;
            //设置数据修正值-气压
            case "气压":
                functionCode = AtmoFunctionCode.Setting_Data_Correction_airPressure.getCode();
                value1 = new BigDecimal(valueOfReal);
                value2 = new BigDecimal(valueOfStandard);
                subtract = value1.subtract(value2).doubleValue();
                z = Integer.valueOf((int) (subtract * 100));
                if (subtract > 0) {
                    value = hex10To16(z);
                } else {
                    value = hex10To16(-z + 32768);
                }
                break;
            //设置数据修正值-光强
            case "光强":
                functionCode = AtmoFunctionCode.Setting_Data_Correction_lightIntensity.getCode();
                value1 = new BigDecimal(valueOfReal);
                value2 = new BigDecimal(valueOfStandard);
                subtract = value1.subtract(value2).doubleValue();
                z = Integer.valueOf((int) (subtract * 100) / 100);
                if (subtract > 0) {
                    value = hex10To16(z);
                } else {
                    value = hex10To16(-z + 32768);
                }
                break;
            //设置数据修正值-噪音
            case "噪音":
                functionCode = AtmoFunctionCode.Setting_Data_Correction_noise.getCode();
                value1 = new BigDecimal(valueOfReal);
                value2 = new BigDecimal(valueOfStandard);
                subtract = value1.subtract(value2).doubleValue();
                z = Integer.valueOf((int) (subtract * 10));
                if (subtract > 0) {
                    value = hex10To16(z);
                } else {
                    value = hex10To16(-z + 32768);
                }
                break;
            //设置数据修正值-PM2.5
            case "PM2.5":
                functionCode = AtmoFunctionCode.Setting_Data_Correction_PM2_5.getCode();
                value1 = new BigDecimal(valueOfReal);
                value2 = new BigDecimal(valueOfStandard);
                subtract = value1.subtract(value2).doubleValue();
                z = Integer.valueOf((int) (subtract * 100) / 100);
                if (subtract > 0) {
                    value = hex10To16(z);
                } else {
                    value = hex10To16(-z + 32768);
                }
                break;
            //设置数据修正值-PM10
            case "PM10":
                functionCode = AtmoFunctionCode.Setting_Data_Correction_PM10.getCode();
                value1 = new BigDecimal(valueOfReal);
                value2 = new BigDecimal(valueOfStandard);
                subtract = value1.subtract(value2).doubleValue();
                z = Integer.valueOf((int) (subtract * 100) / 100);
                if (subtract > 0) {
                    value = hex10To16(z);
                } else {
                    value = hex10To16(-z + 32768);
                }
                break;
            //设置数据修正值-TSP
            case "TSP":
                functionCode = AtmoFunctionCode.Setting_Data_Correction_tsp.getCode();
                value1 = new BigDecimal(valueOfReal);
                value2 = new BigDecimal(valueOfStandard);
                subtract = value1.subtract(value2).doubleValue();
                z = Integer.valueOf((int) (subtract * 100) / 100);
                if (subtract > 0) {
                    value = hex10To16(z);
                } else {
                    value = hex10To16(-z + 32768);
                }
                break;
            //设置数据修正值-雨量
            case "雨量":
                functionCode = AtmoFunctionCode.Setting_Data_Correction_rainfall.getCode();
                functionCode = AtmoFunctionCode.Setting_Data_Correction_rain.getCode();
                value1 = new BigDecimal(valueOfReal);
                value2 = new BigDecimal(valueOfStandard);
                subtract = value1.subtract(value2).doubleValue();
                z = Integer.valueOf((int) (subtract * 10));
                if (subtract > 0) {
                    value = hex10To16(z);
                } else {
                    value = hex10To16(-z + 32768);
                }
                break;
            //设置数据修正值-雨量
            case "甲醛":
                functionCode = AtmoFunctionCode.Setting_Data_Correction_ech2o.getCode();
                value1 = new BigDecimal(valueOfReal);
                value2 = new BigDecimal(valueOfStandard);
                subtract = value1.subtract(value2).doubleValue();
                z = Integer.valueOf((int) (subtract * 100) / 100);
                if (subtract > 0) {
                    value = hex10To16(z);
                } else {
                    value = hex10To16(-z + 32768);
                }
                break;
            //设置数据修正值-TVOC
            case "TVOC":
                functionCode = AtmoFunctionCode.Setting_Data_Correction_tvoc.getCode();
                value1 = new BigDecimal(valueOfReal);
                value2 = new BigDecimal(valueOfStandard);
                subtract = value1.subtract(value2).doubleValue();
                z = Integer.valueOf((int) (subtract * 100) / 100);
                if (subtract > 0) {
                    value = hex10To16(z);
                } else {
                    value = hex10To16(-z + 32768);
                }
                break;
            //设置数据修正值-eCO2
            case "二氧化碳":
                functionCode = AtmoFunctionCode.Setting_Data_Correction_eCO2.getCode();
                value1 = new BigDecimal(valueOfReal);
                value2 = new BigDecimal(valueOfStandard);
                subtract = value1.subtract(value2).doubleValue();
                z = Integer.valueOf((int) (subtract * 100) / 100);
                if (subtract > 0) {
                    value = hex10To16(z);
                } else {
                    value = hex10To16(-z + 32768);
                }
                break;
            //设置数据修正值-SO2二氧化硫
            case "二氧化硫":
                functionCode = AtmoFunctionCode.Setting_Data_Correction_SO2.getCode();
                value1 = new BigDecimal(valueOfReal);
                value2 = new BigDecimal(valueOfStandard);
                subtract = value1.subtract(value2).doubleValue();
                z = Integer.valueOf((int) (subtract * 100) / 100);
                if (subtract > 0) {
                    value = hex10To16(z);
                } else {
                    value = hex10To16(-z + 32768);
                }
                break;
            //设置数据修正值-NO2二氧化氮
            case "二氧化氮":
                functionCode = AtmoFunctionCode.Setting_Data_Correction_NO2.getCode();
                value1 = new BigDecimal(valueOfReal);
                value2 = new BigDecimal(valueOfStandard);
                subtract = value1.subtract(value2).doubleValue();
                z = Integer.valueOf((int) (subtract * 100) / 100);
                if (subtract > 0) {
                    value = hex10To16(z);
                } else {
                    value = hex10To16(-z + 32768);
                }
                break;
            //设置数据修正值-CO一氧化碳
            case "一氧化碳":
                functionCode = AtmoFunctionCode.Setting_Data_Correction_CO.getCode();
                value1 = new BigDecimal(valueOfReal);
                value2 = new BigDecimal(valueOfStandard);
                subtract = value1.subtract(value2).doubleValue();
                z = Integer.valueOf((int) (subtract * 100) / 100);
                if (subtract > 0) {
                    value = hex10To16(z);
                } else {
                    value = hex10To16(-z + 32768);
                }
                break;
            //设置数据修正值-O3臭氧
            case "臭氧":
                functionCode = AtmoFunctionCode.Setting_Data_Correction_O3.getCode();
                value1 = new BigDecimal(valueOfReal);
                value2 = new BigDecimal(valueOfStandard);
                subtract = value1.subtract(value2).doubleValue();
                z = Integer.valueOf((int) (subtract * 100) / 100);
                if (subtract > 0) {
                    value = hex10To16(z);
                } else {
                    value = hex10To16(-z + 32768);
                }
                break;
            //设置数据修正值-F氟化物
            case "氟化物":
                functionCode = AtmoFunctionCode.Setting_Data_Correction_F.getCode();
                value1 = new BigDecimal(valueOfReal);
                value2 = new BigDecimal(valueOfStandard);
                subtract = value1.subtract(value2).doubleValue();
                z = Integer.valueOf((int) (subtract * 100) / 100);
                if (subtract > 0) {
                    value = hex10To16(z);
                } else {
                    value = hex10To16(-z + 32768);
                }
                break;
            default:
        }
        System.out.println(value);
    }
    @Override
    public String getEncodeFrame() {
        String payloadLength = "0004";
        String payload = "FFFF";
        String payload = "FFFF" + value;
        String frame = functionCode + payloadLength + payload;
        return MQTTConnectTypeEnum.SYNCHRONIZATION.getCode() + frame.toUpperCase() + CRC32Utils.getCRC32(frame.toUpperCase());
    }
    /**
     * 十进制转十六进制
     *
     * @param value
     * @return
     */
    private static String hex10To16(int value) {
        return String.format("%02X", value);
    }
}
ximon-admin/src/main/java/com/sandu/ximon/admin/manager/iot/rrpc/enums/AtmoFunctionCode.java
@@ -31,28 +31,38 @@
    Setting_Data_Correction_windSpeed("16"),
    //设置数据修正值-风向
    Setting_Data_Correction_windDirection("17"),
    //设置数据修正值-风力
    Setting_Data_Correction_windPower("18"),
    //设置数据修正值-气压
    Setting_Data_Correction_airPressure("18"),
    Setting_Data_Correction_airPressure("19"),
    //设置数据修正值-光强
    Setting_Data_Correction_lightIntensity("19"),
    Setting_Data_Correction_lightIntensity("1A"),
    //设置数据修正值-噪音
    Setting_Data_Correction_noise("1A"),
    Setting_Data_Correction_noise("1B"),
    //设置数据修正值-PM2.5
    Setting_Data_Correction_PM2_5("1B"),
    Setting_Data_Correction_PM2_5("1C"),
    //设置数据修正值-PM10
    Setting_Data_Correction_PM10("1C"),
    Setting_Data_Correction_PM10("1D"),
    //设置数据修正值-TSP
    Setting_Data_Correction_tsp("1E"),
    //设置数据修正值-雨量
    Setting_Data_Correction_rainfall("1D"),
    Setting_Data_Correction_rain("1F"),
    //设置数据修正值-甲醛
    Setting_Data_Correction_ech2o("20"),
    //设置数据修正值-TVOC
    Setting_Data_Correction_tvoc("21"),
    //设置数据修正值-eCO2
    Setting_Data_Correction_eCO2("22"),
    //设置数据修正值-SO2二氧化硫
    Setting_Data_Correction_SO2("1E"),
    Setting_Data_Correction_SO2("23"),
    //设置数据修正值-NO2二氧化氮
    Setting_Data_Correction_NO2("1F"),
    Setting_Data_Correction_NO2("24"),
    //设置数据修正值-CO一氧化碳
    Setting_Data_Correction_CO("20"),
    Setting_Data_Correction_CO("25"),
    //设置数据修正值-O3臭氧
    Setting_Data_Correction_O3("21"),
    Setting_Data_Correction_O3("26"),
    //设置数据修正值-F氟化物
    Setting_Data_Correction_F("22"),
    Setting_Data_Correction_F("27"),
    //  大气设备心跳包存储
ximon-admin/src/main/java/com/sandu/ximon/admin/service/AirEquipmentService.java
@@ -10,6 +10,7 @@
import com.sandu.ximon.admin.manager.iot.frame.inner.report.A5AtmosphereHeartBeatTimeReportInnerFrame;
import com.sandu.ximon.admin.manager.iot.frame.inner.report.A5AtmosphereOperationReportInnerFrame;
import com.sandu.ximon.admin.manager.iot.frame.inner.report.A5AtmosphereQuerySensorInfoReportInnerFrame;
import com.sandu.ximon.admin.manager.iot.frame.inner.report.A5AtmosphereQueryVersionReportInnerFrame;
import com.sandu.ximon.admin.manager.iot.frame.inner.request.*;
import com.sandu.ximon.admin.manager.iot.rrpc.dto.CommonFrame;
import com.sandu.ximon.admin.manager.iot.rrpc.enums.A5OrderEnum;
@@ -254,11 +255,10 @@
     * @param mac
     * @return
     */
    public void QueryVersion(String mac) {
    public String QueryVersion(String mac) {
        if (StringUtil.strIsNullOrEmpty(mac)) {
            throw new BusinessException("灯杆mac参数错误!");
        }
        //TODO
        AirEquipment airEquipment = SpringContextHolder.getBean(AirEquipmentService.class).
                getOne(Wrappers.lambdaQuery(AirEquipment.class).eq(AirEquipment::getMac, mac).last("limit 1"));
@@ -273,7 +273,14 @@
        System.out.println(commonFrame + "         -----------commonFrame");
//        FEA504000AFE040002FFFF8E00974C          --------a5Frame
//        FEA584000BFE040003FFFFFF38586A49EE3EAF62         -----------commonFrame
//        FEA584000CFE040004FFFF0105954FAA7F1123C0CB         -----------commonFrame
        A5AtmosphereQueryVersionReportInnerFrame a5AtmosphereQueryVersionReportInnerFrame =
                new A5AtmosphereQueryVersionReportInnerFrame().transformFrame(commonFrame.getPayload());
        if (a5AtmosphereQueryVersionReportInnerFrame.isValidate()) {
            return a5AtmosphereQueryVersionReportInnerFrame.getVersion();
        } else {
            throw new BusinessException("数据校验异常!");
        }
    }
    /**
@@ -317,8 +324,7 @@
     * @param valueOfReal     传感器数值
     * @param valueOfStandard 标准仪器数值
     */
    public void ModifiedData(String mac, String type, Double valueOfReal, Double valueOfStandard) {
        //TODO
    public String ModifiedData(String mac, String type, String valueOfReal, String valueOfStandard) {
        if (StringUtil.strIsNullOrEmpty(mac)) {
            throw new BusinessException("灯杆mac参数错误!");
        }
@@ -340,5 +346,12 @@
        System.out.println(commonFrame + "         -----------commonFrame");
        A5AtmosphereOperationReportInnerFrame a5AtmosphereOperationReportInnerFrame
                = new A5AtmosphereOperationReportInnerFrame().transformFrame(commonFrame.getPayload());
        if (a5AtmosphereOperationReportInnerFrame.isValidate()) {
            return a5AtmosphereOperationReportInnerFrame.getState();
        } else {
            throw new BusinessException("数据校验异常!");
        }
    }
}
ximon-admin/src/test/java/com/sandu/ximon/admin/AdminApplicationTests.java
@@ -10,6 +10,7 @@
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.security.crypto.password.PasswordEncoder;
import java.math.BigDecimal;
import java.util.List;
@SpringBootTest
@@ -36,8 +37,80 @@
    }
    public static void main(String[] args) {
        BigDecimal value1 = new BigDecimal("1");
        BigDecimal value2 = new BigDecimal("10");
        String value;
        Double subtract = value1.subtract(value2).doubleValue();
        System.out.println(subtract);
        if (subtract > 0) {
            System.out.println("大于0  " + subtract);
        } else {
            System.out.println("小于0  " + subtract);
        }
        int i = Integer.valueOf((int) (subtract * 100)) / 100;
        int y = Integer.valueOf((int) (subtract * 100)) % 100;
        System.out.println(i);
        System.out.println(y);
        if (subtract > 0) {
            value = hex10To16(i) + hex10To16(y);
            System.out.println("-------------");
            System.out.println(hex10To16(i));
            System.out.println(hex10To16(y));
            System.out.println(value);
        } else {
            value = hex10To16(-i + 128) + hex10To16(-y);
            System.out.println("+++++++++++");
            System.out.println(hex10To16(-i + 128));
            System.out.println(hex10To16(-y));
            System.out.println(value);
        }
        System.out.println("....................................");
        int z = Integer.valueOf((int) (subtract * 10));
        System.out.println(z);
        if (subtract > 0) {
            value = hex10To16(z);
            System.out.println(value);
        } else {
            value = hex10To16(-z + 32768);
            System.out.println(value);
        }
        System.out.println("....................................");
        int x = Integer.valueOf((int) (subtract * 100));
        System.out.println(z);
        if (subtract > 0) {
            value = hex10To16(x);
            System.out.println(value);
        } else {
            value = hex10To16(-x + 32768);
            System.out.println(value);
        }
        System.out.println("....................................");
        int a = Integer.valueOf((int) (subtract * 100)/100);
        System.out.println(z);
        if (subtract > 0) {
            value = hex10To16(a);
            System.out.println(value);
        } else {
            value = hex10To16(-a + 32768);
            System.out.println(value);
        }
    }
    private static String hex10To16(int value) {
        return String.format("%02X", value);
    }
}