# 测试调整路径规划消息下发处理

This commit is contained in:
2026-08-25 08:36:45 +00:00
parent 544efbd0f9
commit 9ff685e0c1
4 changed files with 64 additions and 64 deletions

View File

@@ -62,7 +62,7 @@ public class NettyDevice extends Connector {
// todo 注册的时候更新 siteId // todo 注册的时候更新 siteId
private Device device; private Device device;
//todo 当前登录的账号的token 以token为控制的权限 // todo 当前登录的账号的token 以token为控制的权限
private String token; private String token;
@JsonIgnore @JsonIgnore
@@ -86,7 +86,6 @@ public class NettyDevice extends Connector {
this.deviceType = deviceType; this.deviceType = deviceType;
} }
public void status(Integer onlineStatus) { public void status(Integer onlineStatus) {
this.onlineStatus = onlineStatus; this.onlineStatus = onlineStatus;
} }
@@ -123,7 +122,7 @@ public class NettyDevice extends Connector {
} }
public synchronized Long finishTask() { public synchronized Long finishTask() {
// sendPathCommand((byte) 0x01, (short) 0, 0.00d, 0.00d, (short) 0); // sendPathCommand((byte) 0x01, (short) 0, 0.00d, 0.00d, (short) 0);
long finishId = task.getId(); long finishId = task.getId();
task.setTaskStaus(DeviceTaskStaus.FINISH); task.setTaskStaus(DeviceTaskStaus.FINISH);
task.setFinishTime(LocalDateTime.now()); task.setFinishTime(LocalDateTime.now());
@@ -140,22 +139,23 @@ public class NettyDevice extends Connector {
} }
// public synchronized boolean cancelTask() { // public synchronized boolean cancelTask() {
// if (task != null) { // if (task != null) {
// sendPathCommand((byte) 0x01, (short) 0, 0.00d, 0.00d, (short) 0); // sendPathCommand((byte) 0x01, (short) 0, 0.00d, 0.00d, (short) 0);
// task.setTaskStaus(DeviceTaskStaus.CANCELED); // task.setTaskStaus(DeviceTaskStaus.CANCELED);
// task.setUpdateTime(LocalDateTime.now()); // task.setUpdateTime(LocalDateTime.now());
// devicePlanTaskMapper.saveOrUpdate(task); // devicePlanTaskMapper.saveOrUpdate(task);
// SiteMemory siteMemory = GlobalMemory.getSiteMemory(task.getOrgId(), task.getSiteId()); // SiteMemory siteMemory = GlobalMemory.getSiteMemory(task.getOrgId(),
// siteMemory.removeDevicePlanPrepare(task); // task.getSiteId());
// siteMemory.removeDevicePlanExecute(task.getDeviceId()); // siteMemory.removeDevicePlanPrepare(task);
// task = null; // siteMemory.removeDevicePlanExecute(task.getDeviceId());
// currentTaskId = null; // task = null;
// currentPoint = null; // currentTaskId = null;
// locationQueue.clear(); // currentPoint = null;
// executingTask = false; // locationQueue.clear();
// } // executingTask = false;
// return true; // }
// } // return true;
// }
public synchronized boolean cancelingTask() throws MqttException { public synchronized boolean cancelingTask() throws MqttException {
if (task != null) { if (task != null) {
@@ -171,7 +171,8 @@ public class NettyDevice extends Connector {
dto.setMessage_id(task.getId() + "_" + System.currentTimeMillis()); dto.setMessage_id(task.getId() + "_" + System.currentTimeMillis());
dto.setProtocol_version("1.4"); dto.setProtocol_version("1.4");
GlobalMemory.customMqttDeviceMonitor.publish(mqttClientId, String.format(MqttTopic.MOWER_TASK_ROUTE_SET, task.getDeviceId()), GlobalMemory.customMqttDeviceMonitor.publish(mqttClientId,
String.format(MqttTopic.MOWER_TASK_ROUTE_SET, task.getDeviceId()),
JsonUtils.toJsonString(dto)); JsonUtils.toJsonString(dto));
task.setTaskStaus(DeviceTaskStaus.CANCELING); task.setTaskStaus(DeviceTaskStaus.CANCELING);
task.setUpdateTime(LocalDateTime.now()); task.setUpdateTime(LocalDateTime.now());
@@ -181,7 +182,6 @@ public class NettyDevice extends Connector {
return true; return true;
} }
public synchronized boolean canceledTask() { public synchronized boolean canceledTask() {
if (task != null) { if (task != null) {
task.setTaskStaus(DeviceTaskStaus.CANCELED); task.setTaskStaus(DeviceTaskStaus.CANCELED);
@@ -214,8 +214,9 @@ public class NettyDevice extends Connector {
} }
} }
//配置左右轮增益系数 // 配置左右轮增益系数
public void sendWheelGainCoefficientsCommand(double leftForwardGain, double leftBackwardGain, double rightForwardGain, double rightBackwardGain) { public void sendWheelGainCoefficientsCommand(double leftForwardGain, double leftBackwardGain,
double rightForwardGain, double rightBackwardGain) {
ByteBuffer buffer = ByteBuffer.allocate(39); ByteBuffer buffer = ByteBuffer.allocate(39);
buffer.order(ByteOrder.LITTLE_ENDIAN); buffer.order(ByteOrder.LITTLE_ENDIAN);
@@ -247,7 +248,6 @@ public class NettyDevice extends Connector {
} }
} }
public void readConfigCommand() { public void readConfigCommand() {
byte[] bytes = DeviceRunParam.toReadBytes(); byte[] bytes = DeviceRunParam.toReadBytes();
log.debug("下发读取配置的报文:{}", toHexString(bytes)); log.debug("下发读取配置的报文:{}", toHexString(bytes));
@@ -296,34 +296,35 @@ public class NettyDevice extends Connector {
} }
} }
// public void startTask() { // public void startTask() {
// try { // try {
// if (executingTask) // if (executingTask)
// return; // return;
// if (task != null) { // if (task != null) {
// Long routeId = task.getRouteId(); // Long routeId = task.getRouteId();
// WorkRecord workRecord = workRecordMapper.selectById(routeId); // WorkRecord workRecord = workRecordMapper.selectById(routeId);
// if (workRecord != null) { // if (workRecord != null) {
// PlanPath planPath = workRecord.getJsonData(); // PlanPath planPath = workRecord.getJsonData();
// if (planPath != null && !CollectionUtils.isEmpty(planPath.getPath())) { // if (planPath != null && !CollectionUtils.isEmpty(planPath.getPath())) {
// planPath.getPath().forEach(x -> { // planPath.getPath().forEach(x -> {
// locationQueue.offer(x); // locationQueue.offer(x);
// }); // });
// } // }
// } // }
// task.setStartTime(LocalDateTime.now()); // task.setStartTime(LocalDateTime.now());
// } // }
// executingTask = true; // executingTask = true;
// sendNextPoint(); // sendNextPoint();
// } catch (Exception e) { // } catch (Exception e) {
// throw new RuntimeException(e); // throw new RuntimeException(e);
// } // }
// } // }
public void startTask() { public void startTask() {
try { try {
if (executingTask) if (executingTask)
return; return;
executingTask = true;
if (task != null) { if (task != null) {
// startTime 在启动前记录 // startTime 在启动前记录
task.setStartTime(LocalDateTime.now()); task.setStartTime(LocalDateTime.now());
@@ -333,7 +334,6 @@ public class NettyDevice extends Connector {
futureHolder[0] = executor.scheduleWithFixedDelay(() -> { futureHolder[0] = executor.scheduleWithFixedDelay(() -> {
int current = count.incrementAndGet(); int current = count.incrementAndGet();
try { try {
executingTask = true;
if (task.isTaskAccepted()) { if (task.isTaskAccepted()) {
// 成功,停止后续执行 // 成功,停止后续执行
futureHolder[0].cancel(false); futureHolder[0].cancel(false);
@@ -364,7 +364,7 @@ public class NettyDevice extends Connector {
task = null; task = null;
} }
}, 0, 3, TimeUnit.SECONDS); }, 0, 5, TimeUnit.SECONDS);
} }
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
@@ -398,13 +398,13 @@ public class NettyDevice extends Connector {
} }
if (workRecord.getMode().equals("coverage")) { if (workRecord.getMode().equals("coverage")) {
List<MutiPointEntity> boundary_points = new ArrayList<>(); List<MutiPointEntity> boundary_points = new ArrayList<>();
// workRecord.getJsonData().getPath().forEach(x -> { // workRecord.getJsonData().getPath().forEach(x -> {
// MutiPointEntity mutiPoint = new MutiPointEntity(); // MutiPointEntity mutiPoint = new MutiPointEntity();
// mutiPoint.setLongitude(x.getLng()); // mutiPoint.setLongitude(x.getLng());
// mutiPoint.setLatitude(x.getLat()); // mutiPoint.setLatitude(x.getLat());
// mutiPoint.setIndex(); // mutiPoint.setIndex();
// boundary_points.add(mutiPoint); // boundary_points.add(mutiPoint);
// }); // });
List<LatAndLngEntity> path = workRecord.getJsonData().getPath(); List<LatAndLngEntity> path = workRecord.getJsonData().getPath();
for (int i = 0; i < path.size(); i++) { for (int i = 0; i < path.size(); i++) {
@@ -420,7 +420,8 @@ public class NettyDevice extends Connector {
} }
} }
dto.setData(point); dto.setData(point);
GlobalMemory.customMqttDeviceMonitor.publish(mqttClientId, String.format(MqttTopic.MOWER_TASK_ROUTE_SET, task.getDeviceId()), GlobalMemory.customMqttDeviceMonitor.publish(mqttClientId,
String.format(MqttTopic.MOWER_TASK_ROUTE_SET, task.getDeviceId()),
JsonUtils.toJsonString(dto)); JsonUtils.toJsonString(dto));
} }
} }

View File

@@ -15,5 +15,4 @@ public class HostNavigationReplyDTO extends HostBase {
private String message; private String message;
} }

View File

@@ -314,7 +314,7 @@ public class HostMessageHandler implements CustomMqttMessageHandler {
log.debug("【路径任务下发响应】deviceId={}, payload={}", deviceId, payload); log.debug("【路径任务下发响应】deviceId={}, payload={}", deviceId, payload);
//todo 更新任务接收状态 //todo 更新任务接收状态
HostNavigationReplyDTO replyDTO = SpringUtils.getBean(HostNavigationReplyDTO.class); HostNavigationReplyDTO replyDTO = JsonUtils.parseObject(payload, HostNavigationReplyDTO.class);
NettyDevice device = deviceSessionManager.getDevice(deviceId); NettyDevice device = deviceSessionManager.getDevice(deviceId);
if (replyDTO.isAccepted()) { if (replyDTO.isAccepted()) {
if (device != null && device.getTask() != null && String.valueOf(device.getTask().getId()).equals(replyDTO.getTask_id())) { if (device != null && device.getTask() != null && String.valueOf(device.getTask().getId()).equals(replyDTO.getTask_id())) {
@@ -366,7 +366,7 @@ public class HostMessageHandler implements CustomMqttMessageHandler {
if (remaining.equals("task/finish/post")) return "task_finish_post"; if (remaining.equals("task/finish/post")) return "task_finish_post";
if (remaining.equals("action/config/reply")) return "config_reply"; if (remaining.equals("action/config/reply")) return "config_reply";
if (remaining.equals("action/control/reply")) return "control_reply"; if (remaining.equals("action/control/reply")) return "control_reply";
if (remaining.equals("/task/target/reply")) return "route_reply"; if (remaining.equals("task/target/reply")) return "route_reply";
return null; return null;
} }

View File

@@ -214,7 +214,7 @@ public class DevicePlanTaskMonitorService {
planMap.keySet().forEach(key -> { planMap.keySet().forEach(key -> {
NettyDevice device = deviceSessionManager.getDevice(key); NettyDevice device = deviceSessionManager.getDevice(key);
//判断是否能进execute //判断是否能进execute
if (device != null && device.getCurrentTaskId() == null && device.getOnlineStatus() != null && device.getOnlineStatus() == 1) { if (device != null && device.getTask() == null && device.getOnlineStatus() != null && device.getOnlineStatus() == 1) {
List<DevicePlanTask> tasks = planMap.get(key); List<DevicePlanTask> tasks = planMap.get(key);
if (!CollectionUtils.isEmpty(tasks)) { if (!CollectionUtils.isEmpty(tasks)) {
tasks.removeIf(Objects::isNull); tasks.removeIf(Objects::isNull);