# 测试调整路径规划消息下发处理
This commit is contained in:
@@ -62,7 +62,7 @@ public class NettyDevice extends Connector {
|
||||
// todo 注册的时候更新 siteId
|
||||
private Device device;
|
||||
|
||||
//todo 当前登录的账号的token 以token为控制的权限
|
||||
// todo 当前登录的账号的token 以token为控制的权限
|
||||
private String token;
|
||||
|
||||
@JsonIgnore
|
||||
@@ -86,7 +86,6 @@ public class NettyDevice extends Connector {
|
||||
this.deviceType = deviceType;
|
||||
}
|
||||
|
||||
|
||||
public void status(Integer onlineStatus) {
|
||||
this.onlineStatus = onlineStatus;
|
||||
}
|
||||
@@ -123,7 +122,7 @@ public class NettyDevice extends Connector {
|
||||
}
|
||||
|
||||
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();
|
||||
task.setTaskStaus(DeviceTaskStaus.FINISH);
|
||||
task.setFinishTime(LocalDateTime.now());
|
||||
@@ -139,23 +138,24 @@ public class NettyDevice extends Connector {
|
||||
return finishId;
|
||||
}
|
||||
|
||||
// public synchronized boolean cancelTask() {
|
||||
// if (task != null) {
|
||||
// sendPathCommand((byte) 0x01, (short) 0, 0.00d, 0.00d, (short) 0);
|
||||
// task.setTaskStaus(DeviceTaskStaus.CANCELED);
|
||||
// task.setUpdateTime(LocalDateTime.now());
|
||||
// devicePlanTaskMapper.saveOrUpdate(task);
|
||||
// SiteMemory siteMemory = GlobalMemory.getSiteMemory(task.getOrgId(), task.getSiteId());
|
||||
// siteMemory.removeDevicePlanPrepare(task);
|
||||
// siteMemory.removeDevicePlanExecute(task.getDeviceId());
|
||||
// task = null;
|
||||
// currentTaskId = null;
|
||||
// currentPoint = null;
|
||||
// locationQueue.clear();
|
||||
// executingTask = false;
|
||||
// }
|
||||
// return true;
|
||||
// }
|
||||
// public synchronized boolean cancelTask() {
|
||||
// if (task != null) {
|
||||
// sendPathCommand((byte) 0x01, (short) 0, 0.00d, 0.00d, (short) 0);
|
||||
// task.setTaskStaus(DeviceTaskStaus.CANCELED);
|
||||
// task.setUpdateTime(LocalDateTime.now());
|
||||
// devicePlanTaskMapper.saveOrUpdate(task);
|
||||
// SiteMemory siteMemory = GlobalMemory.getSiteMemory(task.getOrgId(),
|
||||
// task.getSiteId());
|
||||
// siteMemory.removeDevicePlanPrepare(task);
|
||||
// siteMemory.removeDevicePlanExecute(task.getDeviceId());
|
||||
// task = null;
|
||||
// currentTaskId = null;
|
||||
// currentPoint = null;
|
||||
// locationQueue.clear();
|
||||
// executingTask = false;
|
||||
// }
|
||||
// return true;
|
||||
// }
|
||||
|
||||
public synchronized boolean cancelingTask() throws MqttException {
|
||||
if (task != null) {
|
||||
@@ -171,7 +171,8 @@ public class NettyDevice extends Connector {
|
||||
dto.setMessage_id(task.getId() + "_" + System.currentTimeMillis());
|
||||
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));
|
||||
task.setTaskStaus(DeviceTaskStaus.CANCELING);
|
||||
task.setUpdateTime(LocalDateTime.now());
|
||||
@@ -181,7 +182,6 @@ public class NettyDevice extends Connector {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public synchronized boolean canceledTask() {
|
||||
if (task != null) {
|
||||
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);
|
||||
buffer.order(ByteOrder.LITTLE_ENDIAN);
|
||||
|
||||
@@ -247,7 +248,6 @@ public class NettyDevice extends Connector {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void readConfigCommand() {
|
||||
byte[] bytes = DeviceRunParam.toReadBytes();
|
||||
log.debug("下发读取配置的报文:{}", toHexString(bytes));
|
||||
@@ -296,34 +296,35 @@ public class NettyDevice extends Connector {
|
||||
}
|
||||
}
|
||||
|
||||
// public void startTask() {
|
||||
// try {
|
||||
// if (executingTask)
|
||||
// return;
|
||||
// if (task != null) {
|
||||
// Long routeId = task.getRouteId();
|
||||
// WorkRecord workRecord = workRecordMapper.selectById(routeId);
|
||||
// if (workRecord != null) {
|
||||
// PlanPath planPath = workRecord.getJsonData();
|
||||
// if (planPath != null && !CollectionUtils.isEmpty(planPath.getPath())) {
|
||||
// planPath.getPath().forEach(x -> {
|
||||
// locationQueue.offer(x);
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
// task.setStartTime(LocalDateTime.now());
|
||||
// }
|
||||
// executingTask = true;
|
||||
// sendNextPoint();
|
||||
// } catch (Exception e) {
|
||||
// throw new RuntimeException(e);
|
||||
// }
|
||||
// }
|
||||
// public void startTask() {
|
||||
// try {
|
||||
// if (executingTask)
|
||||
// return;
|
||||
// if (task != null) {
|
||||
// Long routeId = task.getRouteId();
|
||||
// WorkRecord workRecord = workRecordMapper.selectById(routeId);
|
||||
// if (workRecord != null) {
|
||||
// PlanPath planPath = workRecord.getJsonData();
|
||||
// if (planPath != null && !CollectionUtils.isEmpty(planPath.getPath())) {
|
||||
// planPath.getPath().forEach(x -> {
|
||||
// locationQueue.offer(x);
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
// task.setStartTime(LocalDateTime.now());
|
||||
// }
|
||||
// executingTask = true;
|
||||
// sendNextPoint();
|
||||
// } catch (Exception e) {
|
||||
// throw new RuntimeException(e);
|
||||
// }
|
||||
// }
|
||||
|
||||
public void startTask() {
|
||||
try {
|
||||
if (executingTask)
|
||||
return;
|
||||
executingTask = true;
|
||||
if (task != null) {
|
||||
// startTime 在启动前记录
|
||||
task.setStartTime(LocalDateTime.now());
|
||||
@@ -333,7 +334,6 @@ public class NettyDevice extends Connector {
|
||||
futureHolder[0] = executor.scheduleWithFixedDelay(() -> {
|
||||
int current = count.incrementAndGet();
|
||||
try {
|
||||
executingTask = true;
|
||||
if (task.isTaskAccepted()) {
|
||||
// 成功,停止后续执行
|
||||
futureHolder[0].cancel(false);
|
||||
@@ -364,7 +364,7 @@ public class NettyDevice extends Connector {
|
||||
task = null;
|
||||
}
|
||||
|
||||
}, 0, 3, TimeUnit.SECONDS);
|
||||
}, 0, 5, TimeUnit.SECONDS);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
@@ -398,13 +398,13 @@ public class NettyDevice extends Connector {
|
||||
}
|
||||
if (workRecord.getMode().equals("coverage")) {
|
||||
List<MutiPointEntity> boundary_points = new ArrayList<>();
|
||||
// workRecord.getJsonData().getPath().forEach(x -> {
|
||||
// MutiPointEntity mutiPoint = new MutiPointEntity();
|
||||
// mutiPoint.setLongitude(x.getLng());
|
||||
// mutiPoint.setLatitude(x.getLat());
|
||||
// mutiPoint.setIndex();
|
||||
// boundary_points.add(mutiPoint);
|
||||
// });
|
||||
// workRecord.getJsonData().getPath().forEach(x -> {
|
||||
// MutiPointEntity mutiPoint = new MutiPointEntity();
|
||||
// mutiPoint.setLongitude(x.getLng());
|
||||
// mutiPoint.setLatitude(x.getLat());
|
||||
// mutiPoint.setIndex();
|
||||
// boundary_points.add(mutiPoint);
|
||||
// });
|
||||
List<LatAndLngEntity> path = workRecord.getJsonData().getPath();
|
||||
|
||||
for (int i = 0; i < path.size(); i++) {
|
||||
@@ -420,7 +420,8 @@ public class NettyDevice extends Connector {
|
||||
}
|
||||
}
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,5 @@ public class HostNavigationReplyDTO extends HostBase {
|
||||
private String code;//任务动作 OK|INVALID|BUSY|ERROR
|
||||
|
||||
private String message;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -314,7 +314,7 @@ public class HostMessageHandler implements CustomMqttMessageHandler {
|
||||
log.debug("【路径任务下发响应】deviceId={}, payload={}", deviceId, payload);
|
||||
|
||||
//todo 更新任务接收状态
|
||||
HostNavigationReplyDTO replyDTO = SpringUtils.getBean(HostNavigationReplyDTO.class);
|
||||
HostNavigationReplyDTO replyDTO = JsonUtils.parseObject(payload, HostNavigationReplyDTO.class);
|
||||
NettyDevice device = deviceSessionManager.getDevice(deviceId);
|
||||
if (replyDTO.isAccepted()) {
|
||||
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("action/config/reply")) return "config_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;
|
||||
}
|
||||
|
||||
@@ -214,11 +214,11 @@ public class DevicePlanTaskMonitorService {
|
||||
planMap.keySet().forEach(key -> {
|
||||
NettyDevice device = deviceSessionManager.getDevice(key);
|
||||
//判断是否能进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);
|
||||
if (!CollectionUtils.isEmpty(tasks)) {
|
||||
tasks.removeIf(Objects::isNull);
|
||||
tasks.sort(
|
||||
tasks.sort(
|
||||
Comparator.comparing(
|
||||
DevicePlanTask::getStartTime,
|
||||
Comparator.nullsLast(Comparator.naturalOrder())
|
||||
|
||||
Reference in New Issue
Block a user