修改枚举
This commit is contained in:
parent
e79d8e15fb
commit
9f5457a2fa
|
|
@ -19,47 +19,11 @@ public class DeviceTelemetry {
|
||||||
// Jackson ObjectMapper 用于 JSON 解析
|
// Jackson ObjectMapper 用于 JSON 解析
|
||||||
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
|
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 无人机 position_state.rtk_number RTK 搜星数量
|
* 机场独有状态
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public static final TelemetryKey<Integer> Position_State_Rtk_Number = TelemetryKey.of(
|
|
||||||
"position_state.rtk_number",
|
|
||||||
Integer.class,
|
|
||||||
value -> {
|
|
||||||
if (value == null) return null;
|
|
||||||
if (value instanceof Number) {
|
|
||||||
return ((Number) value).intValue();
|
|
||||||
}
|
|
||||||
return Integer.parseInt(value.toString());
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
//wind_speed{"unit_name":"米每秒 / m/s"} float
|
|
||||||
public static final TelemetryKey<Double> Wind_Speed = TelemetryKey.of(
|
|
||||||
"wind_speed",
|
|
||||||
Double.class,
|
|
||||||
value -> {
|
|
||||||
if (value == null) return null;
|
|
||||||
if (value instanceof Number) {
|
|
||||||
return ((Number) value).doubleValue();
|
|
||||||
}
|
|
||||||
return Double.parseDouble(value.toString());
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
//rainfall {"0":"无雨","1":"小雨","2":"中雨","3":"大雨"} enum_int
|
|
||||||
public static final TelemetryKey<Integer> Rainfall = TelemetryKey.of(
|
|
||||||
"rainfall",
|
|
||||||
Integer.class,
|
|
||||||
value -> {
|
|
||||||
if (value == null) return null;
|
|
||||||
if (value instanceof Number) {
|
|
||||||
return ((Number) value).intValue();
|
|
||||||
}
|
|
||||||
return Integer.parseInt(value.toString());
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 网络类型 {"1":"4G","2":"以太网"}
|
* 网络类型 {"1":"4G","2":"以太网"}
|
||||||
|
|
@ -92,73 +56,7 @@ public class DeviceTelemetry {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
|
||||||
* 飞行次数 作业架次
|
|
||||||
*/
|
|
||||||
public static final TelemetryKey<Integer> Total_Flight_Sorties = TelemetryKey.of(
|
|
||||||
"total_flight_sorties",
|
|
||||||
Integer.class,
|
|
||||||
value -> {
|
|
||||||
if (value == null) return null;
|
|
||||||
if (value instanceof Number) {
|
|
||||||
return ((Number) value).intValue();
|
|
||||||
}
|
|
||||||
return Integer.parseInt(value.toString());
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 无人机挂载信息
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public static final TelemetryKey<List<PsdkDevice>> PSDK_WIDGET_VALUES = TelemetryKey.of(
|
|
||||||
"psdk_widget_values",
|
|
||||||
(Class<List<PsdkDevice>>) (Class<?>) List.class,
|
|
||||||
value -> {
|
|
||||||
if (value == null) return null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
// 如果已经是 List<PsdkDevice> 类型,直接返回
|
|
||||||
if (value instanceof List) {
|
|
||||||
return (List<PsdkDevice>) value;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 如果是字符串,需要处理 Python 风格的字典格式
|
|
||||||
if (value instanceof String) {
|
|
||||||
String jsonStr = (String) value;
|
|
||||||
|
|
||||||
// 将 Python 风格的字典转换为标准 JSON 格式
|
|
||||||
// 1. 将单引号替换为双引号
|
|
||||||
jsonStr = jsonStr.replace("'", "\"");
|
|
||||||
|
|
||||||
// 2. 处理 True/False/None (如果有的话)
|
|
||||||
jsonStr = jsonStr.replace(": True", ": true")
|
|
||||||
.replace(": False", ": false")
|
|
||||||
.replace(": None", ": null");
|
|
||||||
|
|
||||||
return OBJECT_MAPPER.readValue(
|
|
||||||
jsonStr,
|
|
||||||
new TypeReference<List<PsdkDevice>>() {}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 如果是其他对象(如 JsonNode),转换为 JSON 再解析
|
|
||||||
String json = OBJECT_MAPPER.writeValueAsString(value);
|
|
||||||
return OBJECT_MAPPER.readValue(
|
|
||||||
json,
|
|
||||||
new TypeReference<List<PsdkDevice>>() {}
|
|
||||||
);
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new RuntimeException("Failed to parse psdk_widget_values: " + e.getMessage(), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 机场独有状态
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 舱内温度 temperature
|
* 舱内温度 temperature
|
||||||
|
|
@ -274,6 +172,153 @@ public class DeviceTelemetry {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 无人机 position_state.rtk_number RTK 搜星数量
|
||||||
|
*/
|
||||||
|
|
||||||
|
public static final TelemetryKey<Integer> Position_State_Rtk_Number = TelemetryKey.of(
|
||||||
|
"position_state.rtk_number",
|
||||||
|
Integer.class,
|
||||||
|
value -> {
|
||||||
|
if (value == null) return null;
|
||||||
|
if (value instanceof Number) {
|
||||||
|
return ((Number) value).intValue();
|
||||||
|
}
|
||||||
|
return Integer.parseInt(value.toString());
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 风速
|
||||||
|
*/
|
||||||
|
//wind_speed{"unit_name":"米每秒 / m/s"} float
|
||||||
|
public static final TelemetryKey<Double> Wind_Speed = TelemetryKey.of(
|
||||||
|
"wind_speed",
|
||||||
|
Double.class,
|
||||||
|
value -> {
|
||||||
|
if (value == null) return null;
|
||||||
|
if (value instanceof Number) {
|
||||||
|
return ((Number) value).doubleValue();
|
||||||
|
}
|
||||||
|
return Double.parseDouble(value.toString());
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 降雨量
|
||||||
|
*/
|
||||||
|
//rainfall {"0":"无雨","1":"小雨","2":"中雨","3":"大雨"} enum_int
|
||||||
|
public static final TelemetryKey<Integer> Rainfall = TelemetryKey.of(
|
||||||
|
"rainfall",
|
||||||
|
Integer.class,
|
||||||
|
value -> {
|
||||||
|
if (value == null) return null;
|
||||||
|
if (value instanceof Number) {
|
||||||
|
return ((Number) value).intValue();
|
||||||
|
}
|
||||||
|
return Integer.parseInt(value.toString());
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 无人机特有
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 无人机挂载信息
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public static final TelemetryKey<List<PsdkDevice>> PSDK_WIDGET_VALUES = TelemetryKey.of(
|
||||||
|
"psdk_widget_values",
|
||||||
|
(Class<List<PsdkDevice>>) (Class<?>) List.class,
|
||||||
|
value -> {
|
||||||
|
if (value == null) return null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 如果已经是 List<PsdkDevice> 类型,直接返回
|
||||||
|
if (value instanceof List) {
|
||||||
|
return (List<PsdkDevice>) value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果是字符串,需要处理 Python 风格的字典格式
|
||||||
|
if (value instanceof String) {
|
||||||
|
String jsonStr = (String) value;
|
||||||
|
|
||||||
|
// 将 Python 风格的字典转换为标准 JSON 格式
|
||||||
|
// 1. 将单引号替换为双引号
|
||||||
|
jsonStr = jsonStr.replace("'", "\"");
|
||||||
|
|
||||||
|
// 2. 处理 True/False/None (如果有的话)
|
||||||
|
jsonStr = jsonStr.replace(": True", ": true")
|
||||||
|
.replace(": False", ": false")
|
||||||
|
.replace(": None", ": null");
|
||||||
|
|
||||||
|
return OBJECT_MAPPER.readValue(
|
||||||
|
jsonStr,
|
||||||
|
new TypeReference<List<PsdkDevice>>() {}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果是其他对象(如 JsonNode),转换为 JSON 再解析
|
||||||
|
String json = OBJECT_MAPPER.writeValueAsString(value);
|
||||||
|
return OBJECT_MAPPER.readValue(
|
||||||
|
json,
|
||||||
|
new TypeReference<List<PsdkDevice>>() {}
|
||||||
|
);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException("Failed to parse psdk_widget_values: " + e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 限高
|
||||||
|
*/
|
||||||
|
public static final TelemetryKey<Integer> Height_Limit = TelemetryKey.of(
|
||||||
|
"height_limit",
|
||||||
|
Integer.class,
|
||||||
|
value -> {
|
||||||
|
if (value == null) return null;
|
||||||
|
if (value instanceof Number) {
|
||||||
|
return ((Number) value).intValue();
|
||||||
|
}
|
||||||
|
return Integer.parseInt(value.toString());
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 飞行器限远
|
||||||
|
* {"max":"8000","min":"15","step":"1","unit_name":"米 / m"}
|
||||||
|
*/
|
||||||
|
|
||||||
|
public static final TelemetryKey<Integer> Distance_Limit_Status_Distance_Limit = TelemetryKey.of(
|
||||||
|
"distance_limit_status.distance_limit",
|
||||||
|
Integer.class,
|
||||||
|
value -> {
|
||||||
|
if (value == null) return null;
|
||||||
|
if (value instanceof Number) {
|
||||||
|
return ((Number) value).intValue();
|
||||||
|
}
|
||||||
|
return Integer.parseInt(value.toString());
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 飞行次数 作业架次
|
||||||
|
*/
|
||||||
|
public static final TelemetryKey<Integer> Total_Flight_Sorties = TelemetryKey.of(
|
||||||
|
"total_flight_sorties",
|
||||||
|
Integer.class,
|
||||||
|
value -> {
|
||||||
|
if (value == null) return null;
|
||||||
|
if (value instanceof Number) {
|
||||||
|
return ((Number) value).intValue();
|
||||||
|
}
|
||||||
|
return Integer.parseInt(value.toString());
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 以下尚未划分
|
* 以下尚未划分
|
||||||
|
|
@ -281,8 +326,6 @@ public class DeviceTelemetry {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private DeviceTelemetry() {
|
private DeviceTelemetry() {
|
||||||
// 工具类,禁止实例化
|
// 工具类,禁止实例化
|
||||||
}
|
}
|
||||||
|
|
@ -307,11 +350,15 @@ public class DeviceTelemetry {
|
||||||
Network_State_Type,
|
Network_State_Type,
|
||||||
Wind_Speed,
|
Wind_Speed,
|
||||||
Rainfall,
|
Rainfall,
|
||||||
Position_State_Rtk_Number
|
Position_State_Rtk_Number,
|
||||||
|
Height_Limit,
|
||||||
|
Distance_Limit_Status_Distance_Limit
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 初始化所有遥测键
|
* 初始化所有遥测键
|
||||||
* 确保所有静态字段被加载和注册
|
* 确保所有静态字段被加载和注册
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue