|
@ -9,6 +9,9 @@ import com.qyft.ms.app.model.entity.OperationLog; |
|
|
import com.qyft.ms.app.model.entity.SysSettings; |
|
|
import com.qyft.ms.app.model.entity.SysSettings; |
|
|
import com.qyft.ms.app.model.form.CMDForm; |
|
|
import com.qyft.ms.app.model.form.CMDForm; |
|
|
import com.qyft.ms.app.model.vo.ExecutionResult; |
|
|
import com.qyft.ms.app.model.vo.ExecutionResult; |
|
|
|
|
|
import com.qyft.ms.device.controller.DeviceController; |
|
|
|
|
|
import com.qyft.ms.device.model.bo.DeviceStatus; |
|
|
|
|
|
import com.qyft.ms.device.service.DeviceStatusService; |
|
|
import com.qyft.ms.device.service.DeviceTcpCMDService; |
|
|
import com.qyft.ms.device.service.DeviceTcpCMDService; |
|
|
import lombok.RequiredArgsConstructor; |
|
|
import lombok.RequiredArgsConstructor; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
@ -30,6 +33,8 @@ public class CMDService { |
|
|
private final OperationLogService operationLogService; |
|
|
private final OperationLogService operationLogService; |
|
|
private final MatrixCraftService matrixCraftService; |
|
|
private final MatrixCraftService matrixCraftService; |
|
|
private final ISysSettingsService sysSettingsService; |
|
|
private final ISysSettingsService sysSettingsService; |
|
|
|
|
|
private final DeviceStatusService deviceStatusService; |
|
|
|
|
|
private volatile boolean running = true; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void initExecutorThread(List<Supplier<Boolean>> cmdList, CMDForm form) { |
|
|
private void initExecutorThread(List<Supplier<Boolean>> cmdList, CMDForm form) { |
|
@ -185,6 +190,24 @@ public class CMDService { |
|
|
if (position == null) { |
|
|
if (position == null) { |
|
|
return "position参数错误"; |
|
|
return "position参数错误"; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 设置指定轴的电机的运行速度 |
|
|
|
|
|
int movementSpeed = (Integer) params.get("movementSpeed"); |
|
|
|
|
|
cmdList.add(() -> deviceTcpCMDService.setMotorSpeed("x", movementSpeed)); |
|
|
|
|
|
cmdList.add(() -> deviceTcpCMDService.setMotorSpeed("y", movementSpeed)); |
|
|
|
|
|
cmdList.add(() -> deviceTcpCMDService.setMotorSpeed("z", 10)); |
|
|
|
|
|
|
|
|
|
|
|
// 回到原点 |
|
|
|
|
|
cmdList.add(() -> deviceTcpCMDService.moveMotorToPosition("Z", 5)); |
|
|
|
|
|
cmdList.add(() -> deviceTcpCMDService.moveMotorToPosition("X", 5)); |
|
|
|
|
|
cmdList.add(() -> deviceTcpCMDService.moveMotorToPosition("Y", 5)); |
|
|
|
|
|
|
|
|
|
|
|
cmdList.add(() -> deviceTcpCMDService.motorMoveToHome("Z")); |
|
|
|
|
|
cmdList.add(() -> deviceTcpCMDService.motorMoveToHome("X")); |
|
|
|
|
|
cmdList.add(() -> deviceTcpCMDService.motorMoveToHome("Y")); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < position.size(); i++) { |
|
|
for (int i = 0; i < position.size(); i++) { |
|
|
Map<String, Integer> p = position.get(i); |
|
|
Map<String, Integer> p = position.get(i); |
|
|
|
|
|
|
|
@ -216,12 +239,8 @@ public class CMDService { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 将三通阀转至喷涂管路 |
|
|
// 将三通阀转至喷涂管路 |
|
|
cmdList.add(deviceTcpCMDService::switchThreeWayValveToSpray); |
|
|
|
|
|
// 设置指定轴的电机的运行速度 |
|
|
|
|
|
int movementSpeed = (Integer) params.get("movementSpeed"); |
|
|
|
|
|
cmdList.add(() -> deviceTcpCMDService.setMotorSpeed("x", movementSpeed)); |
|
|
|
|
|
cmdList.add(() -> deviceTcpCMDService.setMotorSpeed("y", movementSpeed)); |
|
|
|
|
|
cmdList.add(() -> deviceTcpCMDService.setMotorSpeed("z", 10)); |
|
|
|
|
|
|
|
|
cmdList.add(() -> deviceTcpCMDService.switchThreeWayValve("clear_spray")); |
|
|
|
|
|
|
|
|
// 移动到指定高度(位置) |
|
|
// 移动到指定高度(位置) |
|
|
int height = (Integer) params.get("height"); |
|
|
int height = (Integer) params.get("height"); |
|
|
|
|
|
|
|
@ -291,15 +310,58 @@ public class CMDService { |
|
|
}); |
|
|
}); |
|
|
cmdList.add(() -> { |
|
|
cmdList.add(() -> { |
|
|
sysSettingsService.updateWorkStatus("idle"); |
|
|
sysSettingsService.updateWorkStatus("idle"); |
|
|
|
|
|
Map<String, String> result = new HashMap<>(); |
|
|
|
|
|
result.put("code", "spray_complete"); |
|
|
|
|
|
result.put("msg", "喷涂任务已完成"); |
|
|
|
|
|
webSocketService.pushMsg(WebSocketMessageType.WARN, result); |
|
|
return true; |
|
|
return true; |
|
|
}); |
|
|
}); |
|
|
initExecutorThread(cmdList, form); |
|
|
|
|
|
|
|
|
new Thread(() -> { |
|
|
|
|
|
running = true; |
|
|
|
|
|
ExecutionResult executionResult = new ExecutionResult(); |
|
|
|
|
|
executionResult.setCommandId(form.getCommandId()); |
|
|
|
|
|
executionResult.setCommandName(form.getCommandName()); |
|
|
|
|
|
|
|
|
|
|
|
// 执行所有命令 |
|
|
|
|
|
for (Supplier<Boolean> command : cmdList) { |
|
|
|
|
|
|
|
|
|
|
|
boolean result = command.get(); |
|
|
|
|
|
if(!running) { |
|
|
|
|
|
log.error("指令线程停止: {}", JSONUtil.toJsonStr(form)); |
|
|
|
|
|
executionResult.setStatus(CMDResultCode.FAILURE.getCode()); |
|
|
|
|
|
executionResult.setMessage(CMDResultCode.FAILURE.getMsg()); |
|
|
|
|
|
webSocketService.pushMsg(WebSocketMessageType.CMD, executionResult); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
// try { |
|
|
|
|
|
// Thread.sleep(5000); |
|
|
|
|
|
// } catch (InterruptedException e) { |
|
|
|
|
|
// throw new RuntimeException(e); |
|
|
|
|
|
// } |
|
|
|
|
|
if (!result) { |
|
|
|
|
|
log.error("指令执行异常: {}", JSONUtil.toJsonStr(form)); |
|
|
|
|
|
executionResult.setStatus(CMDResultCode.FAILURE.getCode()); |
|
|
|
|
|
executionResult.setMessage(CMDResultCode.FAILURE.getMsg()); |
|
|
|
|
|
webSocketService.pushMsg(WebSocketMessageType.CMD, executionResult); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
log.info("指令执行成功: {}", JSONUtil.toJsonStr(form)); |
|
|
|
|
|
executionResult.setStatus(CMDResultCode.SUCCESS.getCode()); |
|
|
|
|
|
executionResult.setMessage(CMDResultCode.SUCCESS.getMsg()); |
|
|
|
|
|
webSocketService.pushMsg(WebSocketMessageType.CMD, executionResult); |
|
|
|
|
|
}).start(); |
|
|
return "ok"; |
|
|
return "ok"; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 结束喷涂 |
|
|
// 结束喷涂 |
|
|
public boolean stopWork(CMDForm form) { |
|
|
public boolean stopWork(CMDForm form) { |
|
|
List<Supplier<Boolean>> cmdList = new ArrayList<>(); |
|
|
List<Supplier<Boolean>> cmdList = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
|
|
cmdList.add(() -> { |
|
|
|
|
|
running = false; |
|
|
|
|
|
return true; |
|
|
|
|
|
}); |
|
|
// 停止喷涂 |
|
|
// 停止喷涂 |
|
|
cmdList.add(deviceTcpCMDService::turnOffSyringePump); |
|
|
cmdList.add(deviceTcpCMDService::turnOffSyringePump); |
|
|
// 关闭高压 |
|
|
// 关闭高压 |
|
@ -470,6 +532,19 @@ public class CMDService { |
|
|
cmdList.add(() -> deviceTcpCMDService.startDehumidify(humidity)); |
|
|
cmdList.add(() -> deviceTcpCMDService.startDehumidify(humidity)); |
|
|
cmdList.add(() -> { |
|
|
cmdList.add(() -> { |
|
|
sysSettingsService.updateTargetHumidity(humidity); |
|
|
sysSettingsService.updateTargetHumidity(humidity); |
|
|
|
|
|
while (true) { |
|
|
|
|
|
double targetHumidity = sysSettingsService.getTargetHumidity(); |
|
|
|
|
|
DeviceStatus deviceStatus = deviceStatusService.getDeviceStatus(); |
|
|
|
|
|
if (deviceStatus.getHumidity()<=targetHumidity ) { |
|
|
|
|
|
deviceTcpCMDService.controlValve("Dehumidification", false); |
|
|
|
|
|
sysSettingsService.updateWorkStatus("idle"); |
|
|
|
|
|
Map<String, String> result = new HashMap<>(); |
|
|
|
|
|
result.put("code", "dehumidify_complete"); |
|
|
|
|
|
result.put("msg", "已达到目标湿度"); |
|
|
|
|
|
webSocketService.pushMsg(WebSocketMessageType.WARN, result); |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
return true; |
|
|
return true; |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
@ -528,11 +603,11 @@ public class CMDService { |
|
|
for (Supplier<Boolean> command : cmdList) { |
|
|
for (Supplier<Boolean> command : cmdList) { |
|
|
|
|
|
|
|
|
boolean result = command.get(); |
|
|
boolean result = command.get(); |
|
|
try { |
|
|
|
|
|
Thread.sleep(5000); |
|
|
|
|
|
} catch (InterruptedException e) { |
|
|
|
|
|
throw new RuntimeException(e); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// try { |
|
|
|
|
|
// Thread.sleep(5000); |
|
|
|
|
|
// } catch (InterruptedException e) { |
|
|
|
|
|
// throw new RuntimeException(e); |
|
|
|
|
|
// } |
|
|
if (!result) { |
|
|
if (!result) { |
|
|
log.error("指令执行异常: {}", JSONUtil.toJsonStr(form)); |
|
|
log.error("指令执行异常: {}", JSONUtil.toJsonStr(form)); |
|
|
executionResult.setStatus(CMDResultCode.FAILURE.getCode()); |
|
|
executionResult.setStatus(CMDResultCode.FAILURE.getCode()); |
|
|