|
|
@ -1,10 +1,16 @@ |
|
|
|
package com.qyft.ms.app.handler.impl; |
|
|
|
|
|
|
|
import cn.hutool.json.JSONObject; |
|
|
|
import com.qyft.ms.app.common.annotation.CommandMapping; |
|
|
|
import com.qyft.ms.app.common.command.CommandFuture; |
|
|
|
import com.qyft.ms.app.common.command.CurrentSendCmdMapInstance; |
|
|
|
import com.qyft.ms.app.common.command.DeviceCommandGenerator; |
|
|
|
import com.qyft.ms.app.common.command.FrontCommandAck; |
|
|
|
import com.qyft.ms.app.common.constant.CommandStatus; |
|
|
|
import com.qyft.ms.app.handler.CommandHandler; |
|
|
|
import com.qyft.ms.app.model.bo.CMDToDevice; |
|
|
|
import com.qyft.ms.app.model.form.CMDFormV2; |
|
|
|
import com.qyft.ms.device.client.TcpClient; |
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
import org.springframework.http.MediaType; |
|
|
|
import org.springframework.scheduling.annotation.Async; |
|
|
@ -21,6 +27,10 @@ import java.util.Map; |
|
|
|
@Async("asyncExecutor") |
|
|
|
@CommandMapping("matrix_prefill")//业务指令注解 |
|
|
|
public class NozzlePipelinePreFill implements CommandHandler { |
|
|
|
/** |
|
|
|
* 设备通信client |
|
|
|
*/ |
|
|
|
private final TcpClient deviceClient; |
|
|
|
|
|
|
|
@Override |
|
|
|
public void handle(CMDFormV2 cmdForm, ResponseBodyEmitter emitter) throws Exception { |
|
|
@ -28,5 +38,167 @@ public class NozzlePipelinePreFill implements CommandHandler { |
|
|
|
String frontCmdName = cmdForm.getCmdName(); |
|
|
|
Map<String, Object> param = cmdForm.getParam(); |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RECEIVE, "后台已收到指令"), MediaType.APPLICATION_JSON);//向前端发送接收到指令 |
|
|
|
//1.传参校验 |
|
|
|
Integer speed = (Integer) param.get("speed"); |
|
|
|
if (speed == null) { |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "参数 speed 必填"), MediaType.APPLICATION_JSON); |
|
|
|
emitter.complete(); |
|
|
|
return; |
|
|
|
} |
|
|
|
//2.判断z轴是否在安全距离,如果不在安全距离可以不抬升z轴 |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "判断z轴是否在安全距离,如果不在安全距离可以不抬升z轴"), MediaType.APPLICATION_JSON); |
|
|
|
CMDToDevice motorXYZPositionGetCmdToDevice = DeviceCommandGenerator.motor_xyz_position_get();//生成指令 获取xyz当前位置 |
|
|
|
CommandFuture motorXYZPositionGetCmdToDeviceFuture = new CommandFuture(); |
|
|
|
motorXYZPositionGetCmdToDeviceFuture.setCmdToDevice(motorXYZPositionGetCmdToDevice); |
|
|
|
Integer motorXYZPositionGetCmdToDeviceCmdId = motorXYZPositionGetCmdToDevice.getCmdId(); |
|
|
|
CurrentSendCmdMapInstance.getInstance().putCommand(motorXYZPositionGetCmdToDeviceCmdId, motorXYZPositionGetCmdToDeviceFuture);//将指令放入map |
|
|
|
deviceClient.sendToJSON(motorXYZPositionGetCmdToDevice); //发送指令给设备 |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "已向设备发送了获得电机XYZ相对原点坐标指令", motorXYZPositionGetCmdToDevice), MediaType.APPLICATION_JSON); |
|
|
|
motorXYZPositionGetCmdToDeviceFuture.waitForContinue();//等待设备的反馈 |
|
|
|
JSONObject motorXYZPositionGetCmdToDeviceResult = motorXYZPositionGetCmdToDeviceFuture.getCallbackResult();//拿到设备返回结果 |
|
|
|
CurrentSendCmdMapInstance.getInstance().removeCommand(motorXYZPositionGetCmdToDeviceCmdId);//将指令从map中删除 |
|
|
|
if (!motorXYZPositionGetCmdToDeviceFuture.isReceived()) { |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "获得电机XYZ相对原点坐标指令响应超时", motorXYZPositionGetCmdToDeviceResult), MediaType.APPLICATION_JSON); |
|
|
|
emitter.complete(); |
|
|
|
return; |
|
|
|
} |
|
|
|
if (motorXYZPositionGetCmdToDeviceResult.getJSONObject("error") != null) { |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "获得电机XYZ相对原点坐标指令返回错误", motorXYZPositionGetCmdToDeviceResult), MediaType.APPLICATION_JSON); |
|
|
|
emitter.complete(); |
|
|
|
return; |
|
|
|
} |
|
|
|
Double zAxisPosition = motorXYZPositionGetCmdToDeviceResult.getJSONObject("result").getDouble("zAxisPosition");//当前z轴相对于原点的位置 |
|
|
|
if(zAxisPosition == null || zAxisPosition < 0.0) { |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "获得电机XYZ相对原点坐标指令执行失败", motorXYZPositionGetCmdToDeviceResult), MediaType.APPLICATION_JSON); |
|
|
|
emitter.complete(); |
|
|
|
return; |
|
|
|
} |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RESULT, "电机XYZ相对原点坐标指令反馈", motorXYZPositionGetCmdToDeviceResult), MediaType.APPLICATION_JSON); |
|
|
|
if (zAxisPosition > 80) { //z轴超出安全距离,抬升z轴 |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "z轴超出安全距离,抬升z轴至安全距离"), MediaType.APPLICATION_JSON); |
|
|
|
CMDToDevice motorZPositionSetCmdToDevice = DeviceCommandGenerator.motor_z_position_set(80.0, 2);//生成指令 移动z轴到指定位置 |
|
|
|
CommandFuture motorZPositionSetCmdToDeviceFuture = new CommandFuture(); |
|
|
|
motorZPositionSetCmdToDeviceFuture.setCmdToDevice(motorZPositionSetCmdToDevice); |
|
|
|
Integer motorZPositionSetCmdToDeviceCmdId = motorXYZPositionGetCmdToDevice.getCmdId(); |
|
|
|
CurrentSendCmdMapInstance.getInstance().putCommand(motorZPositionSetCmdToDeviceCmdId, motorZPositionSetCmdToDeviceFuture);//将指令放入map |
|
|
|
deviceClient.sendToJSON(motorZPositionSetCmdToDevice); //发送指令给设备 |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "已向设备发送了移动z轴到指定位置指令", motorXYZPositionGetCmdToDevice), MediaType.APPLICATION_JSON); |
|
|
|
motorZPositionSetCmdToDeviceFuture.waitForContinue();//等待设备的反馈 |
|
|
|
JSONObject motorZPositionSetCmdToDeviceResult = motorXYZPositionGetCmdToDeviceFuture.getCallbackResult();//拿到设备返回结果 |
|
|
|
CurrentSendCmdMapInstance.getInstance().removeCommand(motorZPositionSetCmdToDeviceCmdId);//将指令从map中删除 |
|
|
|
if (!motorZPositionSetCmdToDeviceFuture.isReceived()) { |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "移动z轴到指定位指令置响应超时", motorZPositionSetCmdToDeviceResult), MediaType.APPLICATION_JSON); |
|
|
|
emitter.complete(); |
|
|
|
return; |
|
|
|
} |
|
|
|
if (motorZPositionSetCmdToDeviceResult.getJSONObject("error") != null) { |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "移动z轴到指定位指令返回错误", motorZPositionSetCmdToDeviceResult), MediaType.APPLICATION_JSON); |
|
|
|
emitter.complete(); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
Boolean motorZPositionSetCmdToDeviceResultStatus = motorZPositionSetCmdToDeviceResult.getBool("result"); |
|
|
|
if(!motorZPositionSetCmdToDeviceResultStatus){ |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "移动z轴到指定位指令执行失败", motorZPositionSetCmdToDeviceResult), MediaType.APPLICATION_JSON); |
|
|
|
emitter.complete(); |
|
|
|
return; |
|
|
|
} |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RESULT, "移动z轴到指定位指令反馈", motorZPositionSetCmdToDeviceResult), MediaType.APPLICATION_JSON); |
|
|
|
} |
|
|
|
//3.轴移动到废液位置 |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "轴移动到废液位置"), MediaType.APPLICATION_JSON); |
|
|
|
CMDToDevice motorXPositionSetCmdToDevice = DeviceCommandGenerator.motor_x_position_set(173.08, 0);//生成指令 移动x轴到指定位置 |
|
|
|
CommandFuture motorXPositionSetCmdToDeviceFuture = new CommandFuture(); |
|
|
|
motorXPositionSetCmdToDeviceFuture.setCmdToDevice(motorXPositionSetCmdToDevice); |
|
|
|
Integer motorXPositionSetCmdToDeviceCmdId = motorXPositionSetCmdToDevice.getCmdId(); |
|
|
|
CurrentSendCmdMapInstance.getInstance().putCommand(motorXPositionSetCmdToDeviceCmdId, motorXPositionSetCmdToDeviceFuture);//将指令放入map |
|
|
|
deviceClient.sendToJSON(motorXPositionSetCmdToDevice); //发送指令给设备 |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "已向设备发送了移动x轴到指定位置指令", motorXPositionSetCmdToDevice), MediaType.APPLICATION_JSON); |
|
|
|
motorXPositionSetCmdToDeviceFuture.waitForContinue();//等待设备的反馈 |
|
|
|
JSONObject motorXPositionSetCmdToDeviceResult = motorXPositionSetCmdToDeviceFuture.getCallbackResult();//拿到设备返回结果 |
|
|
|
CurrentSendCmdMapInstance.getInstance().removeCommand(motorXPositionSetCmdToDeviceCmdId);//将指令从map中删除 |
|
|
|
if (!motorXPositionSetCmdToDeviceFuture.isReceived()) { |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "移动x轴到指定位置指令响应超时", motorXPositionSetCmdToDeviceResult), MediaType.APPLICATION_JSON); |
|
|
|
emitter.complete(); |
|
|
|
return; |
|
|
|
} |
|
|
|
if (motorXPositionSetCmdToDeviceResult.getJSONObject("error") != null) { |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "移动x轴到指定位置指令返回错误", motorXPositionSetCmdToDeviceResult), MediaType.APPLICATION_JSON); |
|
|
|
emitter.complete(); |
|
|
|
return; |
|
|
|
} |
|
|
|
Boolean motorXYZPositionGetCmdToDeviceResultStatus = motorXPositionSetCmdToDeviceResult.getBool("result"); |
|
|
|
if (!motorXYZPositionGetCmdToDeviceResultStatus) { |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "移动x轴到指定位置指令执行失败", motorXPositionSetCmdToDeviceResult), MediaType.APPLICATION_JSON); |
|
|
|
emitter.complete(); |
|
|
|
return; |
|
|
|
} |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RESULT, "移动x轴到指定位置指令反馈", motorXPositionSetCmdToDeviceResult), MediaType.APPLICATION_JSON); |
|
|
|
|
|
|
|
|
|
|
|
CMDToDevice motorYPositionSetCMDToDevice = DeviceCommandGenerator.motor_y_position_set(173.08, 0); |
|
|
|
CommandFuture motorYPositionSetCMDToDeviceFuture = new CommandFuture(); |
|
|
|
motorYPositionSetCMDToDeviceFuture.setCmdToDevice(motorYPositionSetCMDToDevice); |
|
|
|
Integer motorYPositionSetCMDToDeviceCmdId = motorYPositionSetCMDToDevice.getCmdId(); |
|
|
|
CurrentSendCmdMapInstance.getInstance().putCommand(motorYPositionSetCMDToDeviceCmdId, motorYPositionSetCMDToDeviceFuture);//将指令放入map |
|
|
|
deviceClient.sendToJSON(motorYPositionSetCMDToDevice); //发送指令给设备 |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "已向设备发送了移动y轴到指定位置指令", motorYPositionSetCMDToDevice), MediaType.APPLICATION_JSON); |
|
|
|
motorYPositionSetCMDToDeviceFuture.waitForContinue();//等待设备的反馈 |
|
|
|
JSONObject motorYPositionSetCMDToDeviceResult = motorYPositionSetCMDToDeviceFuture.getCallbackResult();//拿到设备返回结果 |
|
|
|
CurrentSendCmdMapInstance.getInstance().removeCommand(motorYPositionSetCMDToDeviceCmdId);//将指令从map中删除 |
|
|
|
if (!motorYPositionSetCMDToDeviceFuture.isReceived()) { |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "移动x轴到指定位置指令响应超时", motorYPositionSetCMDToDeviceResult), MediaType.APPLICATION_JSON); |
|
|
|
emitter.complete(); |
|
|
|
return; |
|
|
|
} |
|
|
|
if (motorYPositionSetCMDToDeviceResult.getJSONObject("error") != null) { |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "移动x轴到指定位置指令返回错误", motorYPositionSetCMDToDeviceResult), MediaType.APPLICATION_JSON); |
|
|
|
emitter.complete(); |
|
|
|
return; |
|
|
|
} |
|
|
|
Boolean motorYPositionSetCMDToDeviceResultStatus = motorYPositionSetCMDToDeviceResult.getBool("result"); |
|
|
|
if (!motorYPositionSetCMDToDeviceResultStatus) { |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "移动x轴到指定位置指令执行失败", motorYPositionSetCMDToDeviceResult), MediaType.APPLICATION_JSON); |
|
|
|
emitter.complete(); |
|
|
|
return; |
|
|
|
} |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RESULT, "移动x轴到指定位置指令反馈", motorYPositionSetCMDToDeviceResult), MediaType.APPLICATION_JSON); |
|
|
|
//4.下降z轴高度,防止飞溅 |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "下降z轴高度,防止飞溅"), MediaType.APPLICATION_JSON); |
|
|
|
CMDToDevice motorZPositionSetDownCmdToDevice = DeviceCommandGenerator.motor_z_position_set(85.0, 2);//生成指令 移动z轴到指定位置 |
|
|
|
CommandFuture motorZPositionSetDownCmdToDeviceFuture = new CommandFuture(); |
|
|
|
motorZPositionSetDownCmdToDeviceFuture.setCmdToDevice(motorZPositionSetDownCmdToDevice); |
|
|
|
Integer motorZPositionSetDownCmdToDeviceCmdId = motorZPositionSetDownCmdToDevice.getCmdId(); |
|
|
|
CurrentSendCmdMapInstance.getInstance().putCommand(motorZPositionSetDownCmdToDeviceCmdId, motorZPositionSetDownCmdToDeviceFuture);//将指令放入map |
|
|
|
deviceClient.sendToJSON(motorZPositionSetDownCmdToDevice); //发送指令给设备 |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "已向设备发送了移动z轴到指定位置指令", motorZPositionSetDownCmdToDevice), MediaType.APPLICATION_JSON); |
|
|
|
motorZPositionSetDownCmdToDeviceFuture.waitForContinue();//等待设备的反馈 |
|
|
|
JSONObject motorZPositionSetDownCmdToDeviceResult = motorZPositionSetDownCmdToDeviceFuture.getCallbackResult();//拿到设备返回结果 |
|
|
|
CurrentSendCmdMapInstance.getInstance().removeCommand(motorZPositionSetDownCmdToDeviceCmdId);//将指令从map中删除 |
|
|
|
if (!motorZPositionSetDownCmdToDeviceFuture.isReceived()) { |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "移动z轴到指定位指令置响应超时", motorZPositionSetDownCmdToDeviceResult), MediaType.APPLICATION_JSON); |
|
|
|
emitter.complete(); |
|
|
|
return; |
|
|
|
} |
|
|
|
if (motorZPositionSetDownCmdToDeviceResult.getJSONObject("error") != null) { |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "移动z轴到指定位指令返回错误", motorZPositionSetDownCmdToDeviceResult), MediaType.APPLICATION_JSON); |
|
|
|
emitter.complete(); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
Boolean motorZPositionSetDownCmdToDeviceResultStatus = motorZPositionSetDownCmdToDeviceResult.getBool("result"); |
|
|
|
if(!motorZPositionSetDownCmdToDeviceResultStatus){ |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "移动z轴到指定位指令执行失败", motorZPositionSetDownCmdToDeviceResult), MediaType.APPLICATION_JSON); |
|
|
|
emitter.complete(); |
|
|
|
return; |
|
|
|
} |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RESULT, "移动z轴到指定位指令反馈", motorZPositionSetDownCmdToDeviceResult), MediaType.APPLICATION_JSON); |
|
|
|
//5.三通阀切换到注射器管路 |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "三通阀切换到注射器管路"), MediaType.APPLICATION_JSON); |
|
|
|
CMDToDevice a = DeviceCommandGenerator.motor_z_position_set(85.0, 2);//生成指令 移动z轴到指定位置 |
|
|
|
//6.打开喷嘴阀 |
|
|
|
//7.设置注射泵速度 |
|
|
|
//8.推注射泵" |
|
|
|
emitter.complete(); |
|
|
|
} |
|
|
|
} |