2021与蓝度共同重构项目,服务端
chenjiantian
2021-12-13 11fedf1d94650cbda4751ea89371ed43432c325a
ximon-admin/src/main/java/com/sandu/ximon/admin/manager/iot/frame/inner/report/A5LightHeartbeatReportInnerFrame.java
@@ -1,5 +1,7 @@
package com.sandu.ximon.admin.manager.iot.frame.inner.report;
import cn.hutool.core.util.HexUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.StrUtil;
import com.sandu.ximon.admin.manager.iot.frame.inner.BaseResponseInnerFrame;
import com.sandu.ximon.admin.manager.iot.frame.inner.IResponseInnerFrame;
@@ -54,41 +56,41 @@
    @Data
    public static class HeartBeatDataPackage implements IResponseInnerFrame<HeartBeatDataPackage> {
        //  年RTC 1
        private String year;
        private Integer year;
        //  月RTC 1
        private String month;
        private Integer month;
        //  日RTC 1
        private String day;
        private Integer day;
        //  时RTC 1
        private String hour;
        private Integer hour;
        //  分RTC 1
        private String min;
        private Integer min;
        //  秒RTC 1
        private String sec;
        private Integer sec;
        //  设备温度 2  1字节整数1字节小数
        private String deviceTemperature;
        private Double deviceTemperature;
        //  亮度百分比 1
        private String lightPercent;
        private Integer lightPercent;
        //  电网电压 2 1字节整数1字节小数
        private String gridVol;
        private Double voltage;
        //  电网电流 2 1字节整数1字节小数
        private String gridCur;
        private Double electricCurrent;
        //  赫兹 2 1字节整数1字节小数
        private String hertz;
        private Double hertz;
        //  功率因素 2 1字节整数1字节小数
        private String powerFactor;
        private Double powerFactor;
        //  有功功率 2 1字节整数1字节小数
        private String activePower;
        private Double activePower;
        //  无功功率 2 1字节整数1字节小数
        private String reactivePower;
        private Double reactivePower;
        //  最近一次亮灯时间 4 秒
        private String recentlyLightSec;
        private Long recentlyLightSec;
        //  累计亮灯时间 4
        private String totalLightTime;
        private Long totalLightSec;
        //  最近一次用电电量 4
        private String recentlyUsingPower;
        private Double recentlyUsingPower;
        //  累计用电电量 4
        private String totalUsingPower;
        private Double totalUsingPower;
        //  保留 11
        private String retain;
        //  原帧
@@ -97,27 +99,32 @@
        @Override
        public HeartBeatDataPackage transformFrame(String hex) {
            this.originFrame = hex;
            this.year = hex.substring(0, 2);
            this.month = hex.substring(2, 4);
            this.day = hex.substring(4, 6);
            this.hour = hex.substring(6, 8);
            this.min = hex.substring(8, 10);
            this.sec = hex.substring(10, 12);
            this.year = HexUtil.hexToInt(hex.substring(0, 2));
            this.month = HexUtil.hexToInt(hex.substring(2, 4));
            this.day = HexUtil.hexToInt(hex.substring(4, 6));
            this.hour = HexUtil.hexToInt(hex.substring(6, 8));
            this.min = HexUtil.hexToInt(hex.substring(8, 10));
            this.sec = HexUtil.hexToInt(hex.substring(10, 12));
            this.deviceTemperature = hex.substring(12, 16);
            this.lightPercent = hex.substring(16, 18);
            this.gridVol = hex.substring(18, 22);
            this.gridCur = hex.substring(22, 26);
            this.hertz = hex.substring(26, 30);
            this.powerFactor = hex.substring(30, 34);
            this.activePower = hex.substring(34, 38);
            this.reactivePower = hex.substring(38, 42);
            this.recentlyLightSec = hex.substring(42, 50);
            this.totalLightTime = hex.substring(50, 58);
            this.recentlyUsingPower = hex.substring(58, 66);
            this.totalUsingPower = hex.substring(66, 74);
            this.deviceTemperature = NumberUtil.round(HexUtil.hexToInt(hex.substring(12, 16)) * 0.01, 2).doubleValue();
            this.lightPercent = HexUtil.hexToInt(hex.substring(16, 18));
            this.voltage = NumberUtil.round(HexUtil.hexToInt(hex.substring(18, 22)) * 0.1, 1).doubleValue();
            this.electricCurrent = NumberUtil.round(HexUtil.hexToInt(hex.substring(22, 26)) * 0.001, 3).doubleValue();
            this.hertz = NumberUtil.round(HexUtil.hexToInt(hex.substring(26, 30)) * 0.01, 2).doubleValue();
            this.powerFactor = NumberUtil.round(HexUtil.hexToInt(hex.substring(30, 34)) * 0.001, 3).doubleValue();
            this.activePower = NumberUtil.round(HexUtil.hexToInt(hex.substring(34, 38)) * 0.01, 2).doubleValue();
            this.reactivePower = NumberUtil.round(HexUtil.hexToInt(hex.substring(38, 42)) * 0.01, 2).doubleValue();
            this.recentlyLightSec = HexUtil.hexToLong(hex.substring(42, 50));
            this.totalLightSec = HexUtil.hexToLong(hex.substring(50, 58));
            this.recentlyUsingPower = NumberUtil.round(HexUtil.hexToInt(hex.substring(58, 66)) * (double) 0.001, 3).doubleValue();
            this.totalUsingPower = NumberUtil.round(HexUtil.hexToInt(hex.substring(66, 74)) * (double) 0.001, 3).doubleValue();
            this.retain = hex.substring(74, 96);
            return this;
        }
    }
    public static void main(String[] args) {
        System.out.println(HexUtil.hexToLong("F64D020F"));
        System.out.println(5 * (float) 0.001);
    }
}