#更新实时消息具体字段

This commit is contained in:
2026-10-20 09:04:57 +08:00
parent 9e3ec6a1dd
commit e57699dbdf
7 changed files with 214 additions and 39 deletions

View File

@@ -7,12 +7,14 @@ public class DeviceMapPushDTO {
private String id;
private double lat;
private double lng;
private double y; //yaw
private String f; //fix_status
private double a; //altitude
private String s;//status 运行状态
private Long t; //taskId 任务id
private double b; //电量
private boolean ha = false;//hasAlarm 有无告警
private double y; // yaw
private String f; // fix_status
private double a; // altitude
private String s;// status 运行状态
private Long t; // taskId 任务id
private double b; // 电量
private boolean ha = false;// hasAlarm 有无告警
private String cm;// 控制模式 manual_remote|auto
}

View File

@@ -5,12 +5,30 @@ import lombok.Data;
@Data
public class VehicleMessage {
private double speed;
private double battery_percentage;// 电量
private double battery_voltage;// 电压
private String motion;// moving|stopped|blocked
private boolean emergency_stop; // 急停状态
private double battery_percentage;// 实时电量百分比
private double battery_voltage;// 实时电压
private double distance; // 里程数
private double left_motor_current;// 实时左电机电流
private double right_motor_current;// 实时右电机电流
private double left_motor_temperature;// 实时左电机温度
private double right_motor_temperature;// 实时右电机温度
private double main_temperature;// 实时主温度
private double yaw;// 实时航向角度
private double pitch;// 实时俯仰角度
private String heading_status;// 实时航向状态
private double total_work_area;// 累计作业面积
private double total_work_duration;// 累计作业时长
private double total_work_distance;// 累计作业里程
private String motion;// moving|stopped|blocked 运动状态
private Boolean emergency_stop; // 急停状态
private double left_target_rpm; // 实时左电机目标转速
private double right_target_rpm;// 实时右电机目标转速
private double left_measured_rpm;// 实时左电机测量转速
private double right_measured_rpm;// 实时右电机测量转速
private double left_motor_rpm;// 实时左电机转速
private double right_motor_rpm;// 实时右电机转速
private double roll;// 实时翻滚角度
private String control_mode;// 遥控器拨杆对应的当前控制模式
}

View File

@@ -16,6 +16,7 @@ import org.springframework.util.CollectionUtils;
import com.maibu.core.domain.entity.SysSite;
import com.maibu.core.enums.ErrorSource;
import com.maibu.core.host.VehicleMessage;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
@@ -59,6 +60,20 @@ public class SiteMemory {
public static ConcurrentHashMap<String, DeviceMapPushDTO> deviceMapPushMap = new ConcurrentHashMap<>();
public static ConcurrentHashMap<String, VehicleMessage> vehicleMessageMap = new ConcurrentHashMap<>();
public VehicleMessage getVehicleMessage(String deviceId) {
return vehicleMessageMap.get(deviceId);
}
public void saveVehicleMessage(String deviceId, VehicleMessage vehicleMessage) {
vehicleMessageMap.put(deviceId, vehicleMessage);
}
public void removeVehicleMessage(String deviceId) {
vehicleMessageMap.remove(deviceId);
}
public Map<String, DeviceMapPushDTO> getAllDeviceMapPush() {
return deviceMapPushMap;
}

View File

@@ -148,6 +148,15 @@ public class HostMessageHandler implements CustomMqttMessageHandler {
locationMessage.setDeviceId(deviceId);
redisCache.setCacheObject(key, locationMessage);
// todo 推送实时位置和状态消息到外部
try {
GlobalMemory.customMqttDeviceMonitor.publish(mqttClientId,
String.format(MqttTopic.DEVICE_LOCATION_MESSAGE_TOPIC, deviceId),
JsonUtils.toJsonString(locationRelTimeDTO));
} catch (MqttException e) {
log.error("位置实时数据推送失败: deviceId={}, error={}", deviceId, e.getMessage(), e);
}
}
} catch (Exception e) {
log.error("位置消息解析失败: deviceId={}, payload={}, error={}", deviceId, payload, e);
@@ -227,7 +236,6 @@ public class HostMessageHandler implements CustomMqttMessageHandler {
DeviceMapPushDTO dto = new DeviceMapPushDTO();
dto.setA(Double.parseDouble(altitude.getValue()));
dto.setId(deviceId);
// dto.setB();
// dto.setHa();
dto.setF(fix_status.getValue());
dto.setS(status.getValue());
@@ -235,6 +243,12 @@ public class HostMessageHandler implements CustomMqttMessageHandler {
dto.setLng(Double.parseDouble(lng.getValue()));
dto.setT(nettyDevice.getCurrentTaskId());
dto.setY(Double.parseDouble(yaw.getValue()));
siteMemory.getVehicleMessage(deviceId);
VehicleMessage vehicleMessage = siteMemory.getVehicleMessage(deviceId);
if (vehicleMessage != null) {
dto.setCm(vehicleMessage.getControl_mode());
dto.setB(vehicleMessage.getBattery_percentage());
}
siteMemory.saveMapPushDTO(deviceId, dto);
}
}
@@ -248,17 +262,82 @@ public class HostMessageHandler implements CustomMqttMessageHandler {
WebStatusMessageDTO webStatusMessageDTO = new WebStatusMessageDTO();
List<DeviceStatusDetail> transferData = new ArrayList<>();
DeviceStatusDetail voltage = new DeviceStatusDetail();
voltage.setName("voltage");
voltage.setValue(String.valueOf(vehicleRelTimeDTO.getData().getBattery_voltage()));
voltage.setName("battery_percentage");
voltage.setValue(String.valueOf(vehicleRelTimeDTO.getData().getBattery_percentage()));
voltage.setUnit("");
transferData.add(voltage);
DeviceStatusDetail speed = new DeviceStatusDetail();
speed.setName("speed");
speed.setValue(String.valueOf(vehicleRelTimeDTO.getData().getSpeed()));
speed.setUnit("");
transferData.add(speed);
DeviceStatusDetail battery_voltage = new DeviceStatusDetail();
battery_voltage.setName("battery_voltage");
battery_voltage.setValue(String.valueOf(vehicleRelTimeDTO.getData().getBattery_voltage()));
battery_voltage.setUnit("");
transferData.add(battery_voltage);
DeviceStatusDetail left_motor_current = new DeviceStatusDetail();
left_motor_current.setName("left_motor_current");
left_motor_current.setValue(String.valueOf(vehicleRelTimeDTO.getData().getLeft_motor_current()));
left_motor_current.setUnit("");
transferData.add(left_motor_current);
DeviceStatusDetail right_motor_current = new DeviceStatusDetail();
right_motor_current.setName("right_motor_current");
right_motor_current.setValue(String.valueOf(vehicleRelTimeDTO.getData().getRight_motor_current()));
right_motor_current.setUnit("");
transferData.add(right_motor_current);
DeviceStatusDetail left_motor_temperature = new DeviceStatusDetail();
left_motor_temperature.setName("left_motor_temperature");
left_motor_temperature.setValue(String.valueOf(vehicleRelTimeDTO.getData().getLeft_motor_temperature()));
left_motor_temperature.setUnit("");
transferData.add(left_motor_temperature);
DeviceStatusDetail right_motor_temperature = new DeviceStatusDetail();
right_motor_temperature.setName("right_motor_temperature");
right_motor_temperature.setValue(String.valueOf(vehicleRelTimeDTO.getData().getRight_motor_temperature()));
right_motor_temperature.setUnit("");
transferData.add(right_motor_temperature);
DeviceStatusDetail main_temperature = new DeviceStatusDetail();
main_temperature.setName("main_temperature");
main_temperature.setValue(String.valueOf(vehicleRelTimeDTO.getData().getMain_temperature()));
main_temperature.setUnit("");
transferData.add(main_temperature);
DeviceStatusDetail yaw = new DeviceStatusDetail();
yaw.setName("yaw");
yaw.setValue(String.valueOf(vehicleRelTimeDTO.getData().getYaw()));
yaw.setUnit("");
transferData.add(yaw);
DeviceStatusDetail pitch = new DeviceStatusDetail();
pitch.setName("pitch");
pitch.setValue(String.valueOf(vehicleRelTimeDTO.getData().getPitch()));
pitch.setUnit("");
transferData.add(pitch);
DeviceStatusDetail heading_status = new DeviceStatusDetail();
heading_status.setName("heading_status");
heading_status.setValue(String.valueOf(vehicleRelTimeDTO.getData().getHeading_status()));
heading_status.setUnit("");
transferData.add(heading_status);
DeviceStatusDetail total_work_area = new DeviceStatusDetail();
total_work_area.setName("total_work_area");
total_work_area.setValue(String.valueOf(vehicleRelTimeDTO.getData().getTotal_work_area()));
total_work_area.setUnit("");
transferData.add(total_work_area);
DeviceStatusDetail total_work_duration = new DeviceStatusDetail();
total_work_duration.setName("total_work_duration");
total_work_duration.setValue(String.valueOf(vehicleRelTimeDTO.getData().getTotal_work_duration()));
total_work_duration.setUnit("");
transferData.add(total_work_duration);
DeviceStatusDetail total_work_distance = new DeviceStatusDetail();
total_work_distance.setName("total_work_distance");
total_work_distance.setValue(String.valueOf(vehicleRelTimeDTO.getData().getTotal_work_distance()));
total_work_distance.setUnit("");
transferData.add(total_work_distance);
DeviceStatusDetail motion = new DeviceStatusDetail();
motion.setName("motion");
@@ -266,11 +345,59 @@ public class HostMessageHandler implements CustomMqttMessageHandler {
motion.setUnit("");
transferData.add(motion);
DeviceStatusDetail percentage = new DeviceStatusDetail();
percentage.setName("percentage");
percentage.setValue(String.valueOf(vehicleRelTimeDTO.getData().getBattery_percentage()));
percentage.setUnit("");
transferData.add(percentage);
DeviceStatusDetail emergency_stop = new DeviceStatusDetail();
emergency_stop.setName("emergency_stop");
emergency_stop.setValue(String.valueOf(vehicleRelTimeDTO.getData().getEmergency_stop()));
emergency_stop.setUnit("");
transferData.add(emergency_stop);
DeviceStatusDetail left_target_rpm = new DeviceStatusDetail();
left_target_rpm.setName("left_target_rpm");
left_target_rpm.setValue(String.valueOf(vehicleRelTimeDTO.getData().getLeft_target_rpm()));
left_target_rpm.setUnit("");
transferData.add(left_target_rpm);
DeviceStatusDetail right_target_rpm = new DeviceStatusDetail();
right_target_rpm.setName("right_target_rpm");
right_target_rpm.setValue(String.valueOf(vehicleRelTimeDTO.getData().getRight_target_rpm()));
right_target_rpm.setUnit("");
transferData.add(right_target_rpm);
DeviceStatusDetail left_measured_rpm = new DeviceStatusDetail();
left_measured_rpm.setName("left_measured_rpm");
left_measured_rpm.setValue(String.valueOf(vehicleRelTimeDTO.getData().getLeft_measured_rpm()));
left_measured_rpm.setUnit("");
transferData.add(left_measured_rpm);
DeviceStatusDetail right_measured_rpm = new DeviceStatusDetail();
right_measured_rpm.setName("right_measured_rpm");
right_measured_rpm.setValue(String.valueOf(vehicleRelTimeDTO.getData().getRight_measured_rpm()));
right_measured_rpm.setUnit("");
transferData.add(right_measured_rpm);
DeviceStatusDetail left_motor_rpm = new DeviceStatusDetail();
left_motor_rpm.setName("left_motor_rpm");
left_motor_rpm.setValue(String.valueOf(vehicleRelTimeDTO.getData().getLeft_motor_rpm()));
left_motor_rpm.setUnit("");
transferData.add(left_motor_rpm);
DeviceStatusDetail right_motor_rpm = new DeviceStatusDetail();
right_motor_rpm.setName("right_motor_rpm");
right_motor_rpm.setValue(String.valueOf(vehicleRelTimeDTO.getData().getRight_motor_rpm()));
right_motor_rpm.setUnit("");
transferData.add(right_motor_rpm);
DeviceStatusDetail roll = new DeviceStatusDetail();
roll.setName("roll");
roll.setValue(String.valueOf(vehicleRelTimeDTO.getData().getRoll()));
roll.setUnit("");
transferData.add(roll);
DeviceStatusDetail control_mode = new DeviceStatusDetail();
control_mode.setName("control_mode");
control_mode.setValue(String.valueOf(vehicleRelTimeDTO.getData().getControl_mode()));
control_mode.setUnit("");
transferData.add(control_mode);
webStatusMessageDTO.setData(transferData);
webStatusMessageDTO.setType(MesType.deviceInfo);
@@ -287,7 +414,7 @@ public class HostMessageHandler implements CustomMqttMessageHandler {
if (vehicleRelTimeDTO != null) {
// todo 更新里程数 里程数 * 割幅0.8
vehicleRelTimeDTO.getData().getDistance();
vehicleRelTimeDTO.getData().getTotal_work_distance();
NettyDevice nettyDevice = deviceSessionManager.getDevice(deviceId);
if (nettyDevice != null) {
Long orgId = nettyDevice.getDevice().getOrgId();
@@ -299,9 +426,11 @@ public class HostMessageHandler implements CustomMqttMessageHandler {
deviceRunStatistics = new DeviceRunStatistics();
}
deviceRunStatistics.setDeviceId(deviceId);
deviceRunStatistics.setDistance(vehicleRelTimeDTO.getData().getDistance());
deviceRunStatistics.setWorkArea(vehicleRelTimeDTO.getData().getDistance() * 0.8);
deviceRunStatistics.setDistance(vehicleRelTimeDTO.getData().getTotal_work_distance());
deviceRunStatistics.setWorkArea(vehicleRelTimeDTO.getData().getTotal_work_distance() * 0.8);
siteMemory.saveRunStatistics(deviceRunStatistics);
siteMemory.saveVehicleMessage(deviceId, vehicleRelTimeDTO.getData());
}
}
@@ -318,6 +447,14 @@ public class HostMessageHandler implements CustomMqttMessageHandler {
}
}
}
// todo 推送实时位置和状态消息到外部
try {
GlobalMemory.customMqttDeviceMonitor.publish(mqttClientId,
String.format(MqttTopic.DEVICE_VEHICLE_MESSAGE_TOPIC, deviceId),
JsonUtils.toJsonString(vehicleRelTimeDTO));
} catch (MqttException e) {
log.error("位置实时数据推送失败: deviceId={}, error={}", deviceId, e.getMessage(), e);
}
}
} catch (Exception e) {
log.error("实时消息解析失败: deviceId={}, payload={}, error={}", deviceId, payload, e.getMessage());
@@ -371,7 +508,7 @@ public class HostMessageHandler implements CustomMqttMessageHandler {
try {
websocketMesDispather.dispather(x.getConnectorId(), JsonUtils.toJsonString(sendDto));
} catch (Exception e) {
log.error("实时数据websocket推送失败: connectorId={}, error={}", x.getConnectorId(),
log.error("实时数据websocket任务状态推送失败: connectorId={}, error={}", x.getConnectorId(),
e.getMessage());
}
}
@@ -382,8 +519,7 @@ public class HostMessageHandler implements CustomMqttMessageHandler {
String.format(MqttTopic.DEVICE_TASK_STATUS_TOPIC, taskId),
JsonUtils.toJsonString(sendDto));
} catch (MqttException e) {
// TODO Auto-generated catch block
e.printStackTrace();
log.error("实时数据websocket任务状态推送失败: deviceId={}, error={}", deviceId, e.getMessage(), e);
}
}
@@ -451,7 +587,7 @@ public class HostMessageHandler implements CustomMqttMessageHandler {
websocketMesDispather.dispather(x.getConnectorId(), JsonUtils.toJsonString(sendDto));
} catch (Exception e) {
log.error("实时数据websocket推送失败: connectorId={}, error={}", x.getConnectorId(),
e.getMessage());
e.getMessage(), e);
}
}
}
@@ -461,8 +597,7 @@ public class HostMessageHandler implements CustomMqttMessageHandler {
String.format(MqttTopic.DEVICE_TASK_STATUS_TOPIC, device.getTask().getId()),
JsonUtils.toJsonString(sendDto));
} catch (MqttException e) {
// TODO Auto-generated catch block
e.printStackTrace();
log.error("实时数据websocket推送失败: deviceId={}, error={}", deviceId, e.getMessage(), e);
}
}

View File

@@ -5,7 +5,9 @@ public class MqttTopic {
/** 通用设备主题,建议使用 MOWER_* 系列主题 */
public static final String DEVICE_STATUS_TOPIC = "device/%s/realTimeMessage";
public static final String DEVICE_LOCATION_TOPIC = "device/%s/locationMessage";
public static final String DEVICE_VEHICLE_MESSAGE_TOPIC = "device/%s/host/realTime/message";
public static final String DEVICE_LOCATION_MESSAGE_TOPIC = "device/%s/host/location/message";
/** 通用设备主题,建议使用 MOWER_* 系列主题 */
public static final String DEVICE_TASK_STATUS_TOPIC = "task/%s/status";
/** 通用设备主题,建议使用 MOWER_* 系列主题 */