package com.sandu.ximon.admin.entity;
|
|
import lombok.Data;
|
|
@Data
|
public class AtmoHeartBeatDataPackage implements MainBoardResponse<AtmoHeartBeatDataPackage> {
|
|
public enum DeviceType {
|
|
SENSOR_V1("0101");
|
|
private String type;
|
|
DeviceType(String type) {
|
this.type = type;
|
}
|
|
public String getType() {
|
return type;
|
}
|
}
|
// 设备型号 2
|
private String deviceType;
|
// 模块预热状态标志 1
|
private String moduleWarmUpStatusFlag;
|
// 温度值
|
private Double temperature;
|
// 湿度值
|
private Double humidity;
|
// 风速
|
private Double windSpeed;
|
// 风向
|
private Double windDirection;
|
// 大气压
|
private Integer pressure;
|
// 光强
|
private Integer lightIntensity;
|
// 噪音
|
private Integer noise;
|
// PM2.5
|
private Integer PM25;
|
// PM10
|
private Integer PM10;
|
// 总悬浮颗粒物(TSP)
|
private Integer TSP;
|
// SO2二氧化硫/甲醛相对值
|
private Integer SO2;
|
private Integer eCH2O;
|
// NO2二氧化氮/TVOC
|
private Integer NO2;
|
private Integer TVOC;
|
// CO一氧化碳 /二氧化碳
|
private Integer CO;
|
private Integer CO2;
|
// O3臭氧
|
private Integer O3;
|
// F氟化物
|
private Integer fluoride;
|
|
@Override
|
public AtmoHeartBeatDataPackage convertInstance(String hex) {
|
|
if (hex.length() != 64) {
|
LogUtils.error("转换大气心跳包长度错误:"+hex);
|
return null;
|
}
|
Integer type = 0;
|
this.deviceType = hex.substring(0, 4);
|
if(this.deviceType.equals(DeviceType.SENSOR_V1.getType())) {
|
type = 1;
|
}
|
this.moduleWarmUpStatusFlag = hex.substring(4, 6);
|
this.temperature = Double.parseDouble(
|
parseVal(hex,6,8)
|
+ "."
|
+ parseVal(hex,8,10)
|
);
|
this.humidity = Double.parseDouble(
|
parseVal(hex,10,12)
|
+ "."
|
+ parseVal(hex,12,14)
|
);
|
this.windSpeed = parseVal(hex,14,18) * .1;
|
this.windDirection = parseVal(hex,18,22) * .1;
|
this.pressure = parseVal(hex,22,26);
|
this.lightIntensity = parseVal(hex,26,32);
|
this.noise = parseVal(hex,32, 36);
|
this.PM25 = parseVal(hex,36, 40);
|
this.PM10 = parseVal(hex,40,44);
|
this.TSP = parseVal(hex,44,48);
|
|
/**
|
* 以下区分版本
|
*/
|
if(type.equals(1)) {
|
this.eCH2O = parseVal(hex,48, 52);
|
this.TVOC = parseVal(hex,52, 56);
|
this.CO2 = parseVal(hex,56, 60);
|
} else {
|
this.SO2 = parseVal(hex,48, 52);
|
this.eCH2O = parseVal(hex,48, 52);
|
this.TVOC = parseVal(hex,52, 56);
|
this.NO2 = parseVal(hex,52, 56);
|
this.CO = parseVal(hex,56, 60);
|
this.CO2 = parseVal(hex,56, 60);
|
}
|
|
this.O3 = parseVal(hex,60, 62);
|
this.fluoride = parseVal(hex,62, 64);
|
|
return this;
|
}
|
|
|
private Integer parseVal (String frame, int start, int end) {
|
return Integer.parseInt(frame.substring(start,end),16);
|
}
|
|
}
|