Browse Source

fix:动态调整参数

tags/1.0
白凤吉 4 months ago
parent
commit
6f69d11bb1
  1. 16
      src/main/java/com/qyft/ms/app/device/spray/SprayTaskExecutor.java
  2. 7
      src/main/java/com/qyft/ms/system/service/device/DeviceCommandService.java

16
src/main/java/com/qyft/ms/app/device/spray/SprayTaskExecutor.java

@ -104,17 +104,21 @@ public class SprayTaskExecutor {
continue; continue;
} }
List<DeviceCommand> sprayStepCommands = sprayTaskStep.getSpraySteps().get(i); List<DeviceCommand> sprayStepCommands = sprayTaskStep.getSpraySteps().get(i);
DeviceCommand xSprayStepCommands = sprayStepCommands.get(0);
xSprayStepCommands.getParam().put("speed", sprayTask.getSprayParams().getMovingSpeed());//防止修改了移动速度这里重新设置移动速度
DeviceCommand ySprayStepCommands = sprayStepCommands.get(1);
ySprayStepCommands.getParam().put("speed", sprayTask.getSprayParams().getMovingSpeed());
List<CommandFuture> commandFutureList = new ArrayList<>(); List<CommandFuture> commandFutureList = new ArrayList<>();
double aXPoint = (double) sprayStepCommands.get(0).getParam().get("position");
double aYPoint = (double) sprayStepCommands.get(1).getParam().get("position");
double aXPoint = (double) xSprayStepCommands.getParam().get("position");
double aYPoint = (double) ySprayStepCommands.getParam().get("position");
if (cacheXPoint != aXPoint) { if (cacheXPoint != aXPoint) {
CommandFuture commandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), sprayStepCommands.get(0));
CommandFuture commandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), xSprayStepCommands);
commandFutureList.add(commandFuture); commandFutureList.add(commandFuture);
cacheXPoint = aXPoint; cacheXPoint = aXPoint;
} }
if (cacheYPoint != aYPoint) { if (cacheYPoint != aYPoint) {
CommandFuture commandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), sprayStepCommands.get(1));
CommandFuture commandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), ySprayStepCommands);
commandFutureList.add(commandFuture); commandFutureList.add(commandFuture);
cacheYPoint = aYPoint; cacheYPoint = aYPoint;
} }
@ -126,8 +130,8 @@ public class SprayTaskExecutor {
double currentXPoint = (Double) currentSprayStepCommands.get(0).getParam().get("position") - slideArr[sprayTaskStep.getIndex()][0]; double currentXPoint = (Double) currentSprayStepCommands.get(0).getParam().get("position") - slideArr[sprayTaskStep.getIndex()][0];
double currentYPoint = 75.5 - (Double) currentSprayStepCommands.get(1).getParam().get("position"); double currentYPoint = 75.5 - (Double) currentSprayStepCommands.get(1).getParam().get("position");
currentPoint = new Point2D(currentXPoint, currentYPoint); currentPoint = new Point2D(currentXPoint, currentYPoint);
double nextXPoint = (Double) sprayStepCommands.get(0).getParam().get("position") - slideArr[sprayTaskStep.getIndex()][0];
double nextYPoint = 75.5 - (Double) sprayStepCommands.get(1).getParam().get("position");
double nextXPoint = (Double) xSprayStepCommands.getParam().get("position") - slideArr[sprayTaskStep.getIndex()][0];
double nextYPoint = 75.5 - (Double) ySprayStepCommands.getParam().get("position");
nextPoint = new Point2D(nextXPoint, nextYPoint); nextPoint = new Point2D(nextXPoint, nextYPoint);
SprayTaskPointCollectorPushBO sprayTaskPointCollectorPushBO = new SprayTaskPointCollectorPushBO(sprayTask.getCmdId(), sprayTask.getCmdCode(), sprayTaskStep.getIndex(), sprayNum, currentPoint, nextPoint); SprayTaskPointCollectorPushBO sprayTaskPointCollectorPushBO = new SprayTaskPointCollectorPushBO(sprayTask.getCmdId(), sprayTask.getCmdCode(), sprayTaskStep.getIndex(), sprayNum, currentPoint, nextPoint);
webSocketService.pushMsg(WebSocketMessageType.SPRAY_POINT, sprayTaskPointCollectorPushBO); webSocketService.pushMsg(WebSocketMessageType.SPRAY_POINT, sprayTaskPointCollectorPushBO);

7
src/main/java/com/qyft/ms/system/service/device/DeviceCommandService.java

@ -1,6 +1,7 @@
package com.qyft.ms.system.service.device; package com.qyft.ms.system.service.device;
import cn.hutool.json.JSONObject; import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.qyft.ms.app.device.status.DeviceStatus; import com.qyft.ms.app.device.status.DeviceStatus;
import com.qyft.ms.system.common.constant.CommandStatus; import com.qyft.ms.system.common.constant.CommandStatus;
import com.qyft.ms.system.common.device.command.CommandFuture; import com.qyft.ms.system.common.device.command.CommandFuture;
@ -78,7 +79,7 @@ public class DeviceCommandService {
// Boolean success = result.getBool("success"); // Boolean success = result.getBool("success");
// if (success == null || !success) { //ack失败 // if (success == null || !success) { //ack失败
// String message = deviceCommand.getCmdName() + "指令,设备ack错误"; // String message = deviceCommand.getCmdName() + "指令,设备ack错误";
// webSocketService.pushDebugMsg(FrontResponseGenerator.generateJson(cmdId, cmdCode, CommandStatus.SEND, message, result));
// webSocketService.pushDebugMsg(FrontResponseGenerator.generateJson(cmdId, cmdCode, CommandStatus.DEVICE_ERROR, message, result));
// throw new RuntimeException(message); // throw new RuntimeException(message);
// } // }
// webSocketService.pushDebugMsg(FrontResponseGenerator.generateJson(cmdId, cmdCode, CommandStatus.RESULT, deviceCommand.getCmdName() + "指令,设备ack正常", result)); // webSocketService.pushDebugMsg(FrontResponseGenerator.generateJson(cmdId, cmdCode, CommandStatus.RESULT, deviceCommand.getCmdName() + "指令,设备ack正常", result));
@ -89,7 +90,7 @@ public class DeviceCommandService {
Boolean success = result.getBool("success"); Boolean success = result.getBool("success");
if (success == null || !success) { //response失败 if (success == null || !success) { //response失败
String message = deviceCommand.getCmdName() + "指令,设备response错误"; String message = deviceCommand.getCmdName() + "指令,设备response错误";
webSocketService.pushDebugMsg(FrontResponseGenerator.generateJson(cmdId, cmdCode, CommandStatus.SEND, message, result));
webSocketService.pushDebugMsg(FrontResponseGenerator.generateJson(cmdId, cmdCode, CommandStatus.DEVICE_ERROR, message, result));
throw new RuntimeException(message); throw new RuntimeException(message);
} }
webSocketService.pushDebugMsg(FrontResponseGenerator.generateJson(cmdId, cmdCode, CommandStatus.DEVICE_RESULT, deviceCommand.getCmdName() + "指令,设备response正常,耗时:" + (commandFuture.getEndSendTime() - commandFuture.getStartSendTime()), result)); webSocketService.pushDebugMsg(FrontResponseGenerator.generateJson(cmdId, cmdCode, CommandStatus.DEVICE_RESULT, deviceCommand.getCmdName() + "指令,设备response正常,耗时:" + (commandFuture.getEndSendTime() - commandFuture.getStartSendTime()), result));
@ -103,8 +104,10 @@ public class DeviceCommandService {
public void handleDeviceResult(JSONObject deviceResult) { public void handleDeviceResult(JSONObject deviceResult) {
String tag = deviceResult.getStr("tag"); String tag = deviceResult.getStr("tag");
if ("ACK".equals(tag)) { if ("ACK".equals(tag)) {
log.info("ACK {}", JSONUtil.toJsonStr(deviceResult));
completeCommandAck(deviceResult); completeCommandAck(deviceResult);
} else if ("RESPONSE".equals(tag)) { } else if ("RESPONSE".equals(tag)) {
log.info("RESPONSE {}", JSONUtil.toJsonStr(deviceResult));
completeCommandResponse(deviceResult); completeCommandResponse(deviceResult);
} else if ("EVENT".equals(tag)) { } else if ("EVENT".equals(tag)) {
String eventType = deviceResult.getStr("event_type"); String eventType = deviceResult.getStr("event_type");

Loading…
Cancel
Save