Browse Source

feat:完善业务指令

master
白凤吉 5 months ago
parent
commit
edea29d119
  1. 96
      src/main/java/com/qyft/ms/app/handler/impl/DehumidifierStart.java
  2. 42
      src/main/java/com/qyft/ms/app/handler/impl/DehumidifierStop.java
  3. 124
      src/main/java/com/qyft/ms/app/handler/impl/NozzlePipelinePreFill.java
  4. 102
      src/main/java/com/qyft/ms/app/handler/impl/NozzlePipelinePreFillStop.java
  5. 184
      src/main/java/com/qyft/ms/app/handler/impl/NozzlePipelineWash.java
  6. 35
      src/main/java/com/qyft/ms/app/handler/impl/SlideTrayIn.java
  7. 37
      src/main/java/com/qyft/ms/app/handler/impl/SlideTrayOut.java
  8. 231
      src/main/java/com/qyft/ms/app/handler/impl/SyringePipelineWash.java
  9. 75
      src/main/java/com/qyft/ms/app/handler/impl/SyringePipelineWashStop.java

96
src/main/java/com/qyft/ms/app/handler/impl/DehumidifierStart.java

@ -37,55 +37,79 @@ public class DehumidifierStart implements CommandHandler {
String frontCmdId = cmdForm.getCmdId();
String frontCmdName = cmdForm.getCmdName();
Map<String, Object> param = cmdForm.getParam();
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RECEIVE, "后台已收到指令"), MediaType.APPLICATION_JSON);//向前端发送接收到指令
//1.判断参数是否合法
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RECEIVE, "后台已收到指令"), MediaType.APPLICATION_JSON);
// 1. 参数校验
Integer frontHumidity = (Integer) param.get("humidity");
if (frontHumidity == null) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "参数 humidity 必填"), MediaType.APPLICATION_JSON);
emitter.complete();
return;
}
//2.获取设备湿度
CMDToDevice humidityCmdToDevice = DeviceCommandGenerator.humidity_get();//生成指令 获取当前湿度
CommandFuture humidityGetFuture = new CommandFuture();
humidityGetFuture.setCmdToDevice(humidityCmdToDevice);
Integer toDeviceCmdId = humidityCmdToDevice.getCmdId();
CurrentSendCmdMapInstance.getInstance().putCommand(toDeviceCmdId, humidityGetFuture);//将指令放入map
// 2. 获取设备当前湿度
CMDToDevice humidityCmdToDevice = DeviceCommandGenerator.humidity_get(); // 生成获取湿度指令
CommandFuture humidityFuture = new CommandFuture();
humidityFuture.setCmdToDevice(humidityCmdToDevice);
Integer humidityCmdId = humidityCmdToDevice.getCmdId();
CurrentSendCmdMapInstance.getInstance().putCommand(humidityCmdId, humidityFuture); // 放入map
deviceClient.sendToJSON(humidityCmdToDevice); // 发送指令给设备
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "已向设备发送了获取湿度指令", humidityCmdToDevice), MediaType.APPLICATION_JSON);
humidityGetFuture.waitForContinue();//等待设备的反馈
//3.处理返回结果或者响应超时
JSONObject deviceResult = humidityGetFuture.getCallbackResult();//拿到设备返回结果
CurrentSendCmdMapInstance.getInstance().removeCommand(toDeviceCmdId);//将指令从map中删除
if (humidityGetFuture.isReceived() || humidityGetFuture.isGetResult()) {
//设备已经收到指令并且执行成功
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RESULT, "设备指令反馈", deviceResult), MediaType.APPLICATION_JSON);
Double deviceHumidity = deviceResult.getJSONObject("result").getDouble("humidity");//拿到设备返回的湿度数值
humidityFuture.waitForContinue();
JSONObject humidityResult = humidityFuture.getCallbackResult();
CurrentSendCmdMapInstance.getInstance().removeCommand(humidityCmdId);
if (!humidityFuture.isReceived()) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "获取湿度指令响应超时", humidityResult), MediaType.APPLICATION_JSON);
emitter.complete();
return;
}
if (humidityResult.getJSONObject("error") != null) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "获取湿度指令返回错误", humidityResult), MediaType.APPLICATION_JSON);
emitter.complete();
return;
}
Boolean humidityStatus = humidityResult.getBool("result");
if (!humidityStatus) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "获取湿度指令执行失败", humidityResult), MediaType.APPLICATION_JSON);
emitter.complete();
return;
}
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RESULT, "获取湿度指令反馈", humidityResult), MediaType.APPLICATION_JSON);
Double deviceHumidity = humidityResult.getJSONObject("result").getDouble("humidity");
// 3. 根据前端设置湿度与设备湿度比较决定是否开启除湿
if (frontHumidity > deviceHumidity) {
//如果小于设置值提醒用户不用除湿
// 如果设定湿度大于当前湿度无需除湿
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "设定湿度大于当前湿度,无需除湿"), MediaType.APPLICATION_JSON);
} else {
//4.如果大于设置值开始除湿;打开除湿阀门
CMDToDevice dehumidifier_valve_control = DeviceCommandGenerator.dehumidifier_valve_control("open");//生成指令 开启除湿阀
CommandFuture dehumidifier_valve_control_Future = new CommandFuture();
humidityGetFuture.setCmdToDevice(dehumidifier_valve_control);
Integer dehumidifier_valve_control_cmdId = dehumidifier_valve_control.getCmdId();
CurrentSendCmdMapInstance.getInstance().putCommand(dehumidifier_valve_control_cmdId, dehumidifier_valve_control_Future);//将指令放入map
deviceClient.sendToJSON(dehumidifier_valve_control); //发送指令给设备
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "已向设备发送了开启除湿阀指令", dehumidifier_valve_control), MediaType.APPLICATION_JSON);
dehumidifier_valve_control_Future.waitForContinue();//等待设备的反馈
//5.处理打开除湿阀门返回结果
JSONObject dehumidifier_valve_control_result = dehumidifier_valve_control_Future.getCallbackResult();//拿到设备返回结果
CurrentSendCmdMapInstance.getInstance().removeCommand(dehumidifier_valve_control_cmdId);//将指令从map中删除
if (dehumidifier_valve_control_Future.isReceived() || dehumidifier_valve_control_Future.isGetResult()) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RESULT, "开启除湿阀指令指令设备反馈", dehumidifier_valve_control_result), MediaType.APPLICATION_JSON);//设备已经收到指令并且执行成功
} else {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "开启除湿阀指令响应超时", deviceResult), MediaType.APPLICATION_JSON); //设备未收到指令或者执行失败
emitter.complete();
return;
}
// 4. 开启除湿阀门
CMDToDevice dehumidifierValveCmd = DeviceCommandGenerator.dehumidifier_valve_control("open"); // 生成开启除湿阀指令
CommandFuture dehumidifierValveFuture = new CommandFuture();
dehumidifierValveFuture.setCmdToDevice(dehumidifierValveCmd);
Integer dehumidifierValveCmdId = dehumidifierValveCmd.getCmdId();
CurrentSendCmdMapInstance.getInstance().putCommand(dehumidifierValveCmdId, dehumidifierValveFuture);
deviceClient.sendToJSON(dehumidifierValveCmd);
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "已向设备发送了开启除湿阀指令", dehumidifierValveCmd), MediaType.APPLICATION_JSON);
dehumidifierValveFuture.waitForContinue();
JSONObject dehumidifierValveResult = dehumidifierValveFuture.getCallbackResult();
CurrentSendCmdMapInstance.getInstance().removeCommand(dehumidifierValveCmdId);
if (!dehumidifierValveFuture.isReceived()) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "开启除湿阀指令响应超时", dehumidifierValveResult), MediaType.APPLICATION_JSON);
emitter.complete();
return;
}
} else {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "设备响应超时", deviceResult), MediaType.APPLICATION_JSON);//设备未收到指令或者执行失败
if (dehumidifierValveResult.getJSONObject("error") != null) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "开启除湿阀指令返回错误", dehumidifierValveResult), MediaType.APPLICATION_JSON);
emitter.complete();
return;
}
Boolean dehumidifierValveStatus = dehumidifierValveResult.getBool("result");
if (!dehumidifierValveStatus) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "开启除湿阀指令执行失败", dehumidifierValveResult), MediaType.APPLICATION_JSON);
emitter.complete();
return;
}
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RESULT, "开启除湿阀指令反馈", dehumidifierValveResult), MediaType.APPLICATION_JSON);
emitter.complete();
}
}

42
src/main/java/com/qyft/ms/app/handler/impl/DehumidifierStop.java

@ -34,27 +34,35 @@ public class DehumidifierStop implements CommandHandler {
public void handle(CMDFormV2 cmdForm, ResponseBodyEmitter emitter) throws Exception {
String frontCmdId = cmdForm.getCmdId();
String frontCmdName = cmdForm.getCmdName();
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RECEIVE, "后台已收到指令"), MediaType.APPLICATION_JSON);//向前端发送接收到指令
CMDToDevice cmdToDevice = DeviceCommandGenerator.dehumidifier_valve_close();//生成指令 关闭除湿阀
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RECEIVE, "后台已收到指令"), MediaType.APPLICATION_JSON);
CMDToDevice cmdToDevice = DeviceCommandGenerator.dehumidifier_valve_close();// 关闭除湿阀
CommandFuture cmdToDeviceFuture = new CommandFuture();
cmdToDeviceFuture.setCmdToDevice(cmdToDevice);
Integer toDeviceCmdId = cmdToDevice.getCmdId();
CurrentSendCmdMapInstance.getInstance().putCommand(toDeviceCmdId, cmdToDeviceFuture);//将指令放入map
deviceClient.sendToJSON(cmdToDevice); //发送指令给设备
Integer cmdId = cmdToDevice.getCmdId();
CurrentSendCmdMapInstance.getInstance().putCommand(cmdId, cmdToDeviceFuture);
deviceClient.sendToJSON(cmdToDevice);
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "已向设备发送了关闭除湿阀指令", cmdToDevice), MediaType.APPLICATION_JSON);
cmdToDeviceFuture.waitForContinue();//等待设备的反馈
JSONObject deviceResult = cmdToDeviceFuture.getCallbackResult();//拿到设备返回结果
CurrentSendCmdMapInstance.getInstance().removeCommand(toDeviceCmdId);//将指令从map中删除
if (cmdToDeviceFuture.isReceived()) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RESULT, "关闭除湿阀指令设备反馈", deviceResult), MediaType.APPLICATION_JSON);
} else {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "关闭除湿阀指令有响应", deviceResult), MediaType.APPLICATION_JSON);
cmdToDeviceFuture.waitForContinue();
JSONObject deviceResult = cmdToDeviceFuture.getCallbackResult();
CurrentSendCmdMapInstance.getInstance().removeCommand(cmdId);
if (!cmdToDeviceFuture.isReceived()) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "关闭除湿阀指令响应超时", deviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
return;
}
if (deviceResult.getJSONObject("error") != null) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "关闭除湿阀指令返回错误", deviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
return;
}
Boolean cmdStatus = deviceResult.getBool("result");
if (!cmdStatus) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "关闭除湿阀指令执行失败", deviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
return;
}
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RESULT, "关闭除湿阀指令反馈", deviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
}
}

124
src/main/java/com/qyft/ms/app/handler/impl/NozzlePipelinePreFill.java

@ -74,17 +74,17 @@ public class NozzlePipelinePreFill implements CommandHandler {
return;
}
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RESULT, "电机XYZ相对原点坐标指令反馈", motorXYZPositionGetCmdToDeviceResult), MediaType.APPLICATION_JSON);
if (zAxisPosition > 80) { //z轴超出安全距离抬升z轴
if (zAxisPosition > 80) { //z轴超出安全距离抬升z轴 //TODO安全距离应该可配置
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "z轴超出安全距离,抬升z轴至安全距离"), MediaType.APPLICATION_JSON);
CMDToDevice motorZPositionSetCmdToDevice = DeviceCommandGenerator.motor_z_position_set(80.0, 2);//生成指令 移动z轴到指定位置
CMDToDevice motorZPositionSetCmdToDevice = DeviceCommandGenerator.motor_z_position_set(80.0, 2);//生成指令 移动z轴到指定位置 (TODO)安全距离应该可配置
CommandFuture motorZPositionSetCmdToDeviceFuture = new CommandFuture();
motorZPositionSetCmdToDeviceFuture.setCmdToDevice(motorZPositionSetCmdToDevice);
Integer motorZPositionSetCmdToDeviceCmdId = motorXYZPositionGetCmdToDevice.getCmdId();
Integer motorZPositionSetCmdToDeviceCmdId = motorZPositionSetCmdToDevice.getCmdId();
CurrentSendCmdMapInstance.getInstance().putCommand(motorZPositionSetCmdToDeviceCmdId, motorZPositionSetCmdToDeviceFuture);//将指令放入map
deviceClient.sendToJSON(motorZPositionSetCmdToDevice); //发送指令给设备
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "已向设备发送了移动z轴到指定位置指令", motorXYZPositionGetCmdToDevice), MediaType.APPLICATION_JSON);
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "已向设备发送了移动z轴到指定位置指令", motorZPositionSetCmdToDevice), MediaType.APPLICATION_JSON);
motorZPositionSetCmdToDeviceFuture.waitForContinue();//等待设备的反馈
JSONObject motorZPositionSetCmdToDeviceResult = motorXYZPositionGetCmdToDeviceFuture.getCallbackResult();//拿到设备返回结果
JSONObject motorZPositionSetCmdToDeviceResult = motorZPositionSetCmdToDeviceFuture.getCallbackResult();//拿到设备返回结果
CurrentSendCmdMapInstance.getInstance().removeCommand(motorZPositionSetCmdToDeviceCmdId);//将指令从map中删除
if (!motorZPositionSetCmdToDeviceFuture.isReceived()) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "移动z轴到指定位指令置响应超时", motorZPositionSetCmdToDeviceResult), MediaType.APPLICATION_JSON);
@ -105,9 +105,9 @@ public class NozzlePipelinePreFill implements CommandHandler {
}
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RESULT, "移动z轴到指定位指令反馈", motorZPositionSetCmdToDeviceResult), MediaType.APPLICATION_JSON);
}
//3.轴移动到废液位置
//3.xy轴移动到废液位置
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "轴移动到废液位置"), MediaType.APPLICATION_JSON);
CMDToDevice motorXPositionSetCmdToDevice = DeviceCommandGenerator.motor_x_position_set(173.08, 0);//生成指令 移动x轴到指定位置
CMDToDevice motorXPositionSetCmdToDevice = DeviceCommandGenerator.motor_x_position_set(173.08, 2);//生成指令 移动x轴到指定位置 (TODO) 废液桶X轴位置应当可以配置
CommandFuture motorXPositionSetCmdToDeviceFuture = new CommandFuture();
motorXPositionSetCmdToDeviceFuture.setCmdToDevice(motorXPositionSetCmdToDevice);
Integer motorXPositionSetCmdToDeviceCmdId = motorXPositionSetCmdToDevice.getCmdId();
@ -127,16 +127,14 @@ public class NozzlePipelinePreFill implements CommandHandler {
emitter.complete();
return;
}
Boolean motorXYZPositionGetCmdToDeviceResultStatus = motorXPositionSetCmdToDeviceResult.getBool("result");
if (!motorXYZPositionGetCmdToDeviceResultStatus) {
Boolean motorXYZPositionSetCmdToDeviceResultStatus = motorXPositionSetCmdToDeviceResult.getBool("result");
if (!motorXYZPositionSetCmdToDeviceResultStatus) {
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);
CMDToDevice motorYPositionSetCMDToDevice = DeviceCommandGenerator.motor_y_position_set(75.0, 0);//移动y轴到指定位置 (TODO) 废液桶Y轴位置应当可以配置
CommandFuture motorYPositionSetCMDToDeviceFuture = new CommandFuture();
motorYPositionSetCMDToDeviceFuture.setCmdToDevice(motorYPositionSetCMDToDevice);
Integer motorYPositionSetCMDToDeviceCmdId = motorYPositionSetCMDToDevice.getCmdId();
@ -147,25 +145,26 @@ public class NozzlePipelinePreFill implements CommandHandler {
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.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "移动y轴到指定位置指令响应超时", 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.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "移动y轴到指定位置指令返回错误", 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.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "移动y轴到指定位置指令执行失败", motorYPositionSetCMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
return;
}
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RESULT, "移动x轴到指定位置指令反馈", motorYPositionSetCMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RESULT, "移动y轴到指定位置指令反馈", motorYPositionSetCMDToDeviceResult), MediaType.APPLICATION_JSON);
//4.下降z轴高度防止飞溅
Thread.sleep(10 * 1000);//TODO 等待10秒x和y轴移动完毕
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "下降z轴高度,防止飞溅"), MediaType.APPLICATION_JSON);
CMDToDevice motorZPositionSetDownCmdToDevice = DeviceCommandGenerator.motor_z_position_set(85.0, 2);//生成指令 移动z轴到指定位置
CMDToDevice motorZPositionSetDownCmdToDevice = DeviceCommandGenerator.motor_z_position_set(70.0, 2);//生成指令 移动z轴到指定位置 (TODO) 废液桶Y轴位置应当可以配置
CommandFuture motorZPositionSetDownCmdToDeviceFuture = new CommandFuture();
motorZPositionSetDownCmdToDeviceFuture.setCmdToDevice(motorZPositionSetDownCmdToDevice);
Integer motorZPositionSetDownCmdToDeviceCmdId = motorZPositionSetDownCmdToDevice.getCmdId();
@ -193,12 +192,93 @@ public class NozzlePipelinePreFill implements CommandHandler {
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轴到指定位置
//5.打开三通阀注射器管路
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "打开三通阀注射器管路"), MediaType.APPLICATION_JSON);
CMDToDevice threeWayValveOpenSprayPipelineCMDToDevice = DeviceCommandGenerator.three_way_valve_open_spray_pipeline();//生成指令 打开三通阀注射器管路
CommandFuture threeWayValveOpenSprayPipelineCMDToDeviceFuture = new CommandFuture();
threeWayValveOpenSprayPipelineCMDToDeviceFuture.setCmdToDevice(threeWayValveOpenSprayPipelineCMDToDevice);
Integer threeWayValveOpenSprayPipelineCMDToDeviceCmdId = threeWayValveOpenSprayPipelineCMDToDevice.getCmdId();
CurrentSendCmdMapInstance.getInstance().putCommand(threeWayValveOpenSprayPipelineCMDToDeviceCmdId, threeWayValveOpenSprayPipelineCMDToDeviceFuture); // 将指令放入map
deviceClient.sendToJSON(threeWayValveOpenSprayPipelineCMDToDevice); // 发送指令给设备
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "已向设备发送了打开三通阀注射器管路指令", threeWayValveOpenSprayPipelineCMDToDevice), MediaType.APPLICATION_JSON);
threeWayValveOpenSprayPipelineCMDToDeviceFuture.waitForContinue(); // 等待设备的反馈
JSONObject threeWayValveOpenSprayPipelineCMDToDeviceResult = threeWayValveOpenSprayPipelineCMDToDeviceFuture.getCallbackResult(); // 拿到设备返回结果
CurrentSendCmdMapInstance.getInstance().removeCommand(threeWayValveOpenSprayPipelineCMDToDeviceCmdId); // 将指令从map中删除
if (!threeWayValveOpenSprayPipelineCMDToDeviceFuture.isReceived()) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "打开三通阀注射器管路指令响应超时", threeWayValveOpenSprayPipelineCMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
return;
}
if (threeWayValveOpenSprayPipelineCMDToDeviceResult.getJSONObject("error") != null) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "打开三通阀注射器管路指令返回错误", threeWayValveOpenSprayPipelineCMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
return;
}
Boolean threeWayValveOpenSprayPipelineCMDToDeviceResultStatus = threeWayValveOpenSprayPipelineCMDToDeviceResult.getBool("result");
if (!threeWayValveOpenSprayPipelineCMDToDeviceResultStatus) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "打开三通阀注射器管路指令执行失败", threeWayValveOpenSprayPipelineCMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
return;
}
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RESULT, "打开三通阀注射器管路指令反馈", threeWayValveOpenSprayPipelineCMDToDeviceResult), MediaType.APPLICATION_JSON);
//6.打开喷嘴阀
//7.设置注射泵速度
//8.推注射泵"
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "开启喷嘴阀"), MediaType.APPLICATION_JSON);
CMDToDevice nozzleValveOpenCMDToDevice = DeviceCommandGenerator.nozzle_valve_open();//生成指令 开启喷嘴阀
CommandFuture nozzleValveOpenCMDToDeviceFuture = new CommandFuture();
nozzleValveOpenCMDToDeviceFuture.setCmdToDevice(nozzleValveOpenCMDToDevice);
Integer nozzleValveOpenCMDToDeviceCmdId = nozzleValveOpenCMDToDevice.getCmdId();
CurrentSendCmdMapInstance.getInstance().putCommand(nozzleValveOpenCMDToDeviceCmdId, nozzleValveOpenCMDToDeviceFuture); // 将指令放入map
deviceClient.sendToJSON(nozzleValveOpenCMDToDevice); // 发送指令给设备
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "已向设备发送了开启喷嘴阀指令", nozzleValveOpenCMDToDevice), MediaType.APPLICATION_JSON);
nozzleValveOpenCMDToDeviceFuture.waitForContinue(); // 等待设备的反馈
JSONObject nozzleValveOpenCMDToDeviceResult = nozzleValveOpenCMDToDeviceFuture.getCallbackResult(); // 拿到设备返回结果
CurrentSendCmdMapInstance.getInstance().removeCommand(nozzleValveOpenCMDToDeviceCmdId); // 将指令从map中删除
if (!nozzleValveOpenCMDToDeviceFuture.isReceived()) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "开启喷嘴阀指令响应超时", nozzleValveOpenCMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
return;
}
if (nozzleValveOpenCMDToDeviceResult.getJSONObject("error") != null) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "开启喷嘴阀指令返回错误", nozzleValveOpenCMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
return;
}
Boolean nozzleValveOpenCMDToDeviceResultStatus = nozzleValveOpenCMDToDeviceResult.getBool("result");
if (!nozzleValveOpenCMDToDeviceResultStatus) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "开启喷嘴阀指令执行失败", nozzleValveOpenCMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
return;
}
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RESULT, "开启喷嘴阀指令反馈", nozzleValveOpenCMDToDeviceResult), MediaType.APPLICATION_JSON);
//7.设置注射泵速度推注射泵
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "设置注射泵速度,推注射泵"), MediaType.APPLICATION_JSON);
CMDToDevice syringePumpInjectionVolumeSetCMDToDevice = DeviceCommandGenerator.syringe_pump_injection_volume_set(1);//推动移动注射泵
CommandFuture syringePumpInjectionVolumeSetCMDToDeviceFuture = new CommandFuture();
syringePumpInjectionVolumeSetCMDToDeviceFuture.setCmdToDevice(syringePumpInjectionVolumeSetCMDToDevice);
Integer syringePumpInjectionVolumeSetCMDToDeviceCmdId = syringePumpInjectionVolumeSetCMDToDevice.getCmdId();
CurrentSendCmdMapInstance.getInstance().putCommand(syringePumpInjectionVolumeSetCMDToDeviceCmdId, syringePumpInjectionVolumeSetCMDToDeviceFuture); // 将指令放入map
deviceClient.sendToJSON(syringePumpInjectionVolumeSetCMDToDevice); // 发送指令给设备
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "已向设备发送了推动移动注射泵指令", syringePumpInjectionVolumeSetCMDToDevice), MediaType.APPLICATION_JSON);
syringePumpInjectionVolumeSetCMDToDeviceFuture.waitForContinue(); // 等待设备的反馈
JSONObject syringePumpInjectionVolumeSetCMDToDeviceResult = syringePumpInjectionVolumeSetCMDToDeviceFuture.getCallbackResult(); // 拿到设备返回结果
CurrentSendCmdMapInstance.getInstance().removeCommand(syringePumpInjectionVolumeSetCMDToDeviceCmdId); // 将指令从map中删除
if (!syringePumpInjectionVolumeSetCMDToDeviceFuture.isReceived()) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "推动移动注射泵指令响应超时", syringePumpInjectionVolumeSetCMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
return;
}
if (syringePumpInjectionVolumeSetCMDToDeviceResult.getJSONObject("error") != null) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "推动移动注射泵指令返回错误", syringePumpInjectionVolumeSetCMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
return;
}
Boolean syringePumpInjectionVolumeSetCMDToDeviceResultStatus = syringePumpInjectionVolumeSetCMDToDeviceResult.getBool("result");
if (!syringePumpInjectionVolumeSetCMDToDeviceResultStatus) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "推动移动注射泵指令执行失败", syringePumpInjectionVolumeSetCMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
return;
}
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RESULT, "推动移动注射泵指令反馈", syringePumpInjectionVolumeSetCMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
}
}

102
src/main/java/com/qyft/ms/app/handler/impl/NozzlePipelinePreFillStop.java

@ -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,14 +27,104 @@ import java.util.Map;
@Async("asyncExecutor")
@CommandMapping("matrix_prefill")//业务指令注解
public class NozzlePipelinePreFillStop implements CommandHandler {
/**
* 设备通信client
*/
private final TcpClient deviceClient;
@Override
public void handle(CMDFormV2 cmdForm, ResponseBodyEmitter emitter) throws Exception {
String frontCmdId = cmdForm.getCmdId();
String frontCmdName = cmdForm.getCmdName();
Map<String, Object> param = cmdForm.getParam();
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RECEIVE, "后台已收到指令"), MediaType.APPLICATION_JSON);//向前端发送接收到指令
//1.停止推动注射泵
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "停止推动注射泵"), MediaType.APPLICATION_JSON);
CMDToDevice syringePumpStopCMDToDevice = DeviceCommandGenerator.syringe_pump_stop();//停止推动注射泵
CommandFuture syringePumpStopCMDToDeviceCMDToDeviceFuture = new CommandFuture();
syringePumpStopCMDToDeviceCMDToDeviceFuture.setCmdToDevice(syringePumpStopCMDToDevice);
Integer syringePumpStopCMDToDeviceCmdId = syringePumpStopCMDToDevice.getCmdId();
CurrentSendCmdMapInstance.getInstance().putCommand(syringePumpStopCMDToDeviceCmdId, syringePumpStopCMDToDeviceCMDToDeviceFuture); // 将指令放入map
deviceClient.sendToJSON(syringePumpStopCMDToDevice); // 发送指令给设备
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "已向设备发送了停止推动注射泵指令", syringePumpStopCMDToDevice), MediaType.APPLICATION_JSON);
syringePumpStopCMDToDeviceCMDToDeviceFuture.waitForContinue(); // 等待设备的反馈
JSONObject syringePumpStopCMDToDeviceResult = syringePumpStopCMDToDeviceCMDToDeviceFuture.getCallbackResult(); // 拿到设备返回结果
CurrentSendCmdMapInstance.getInstance().removeCommand(syringePumpStopCMDToDeviceCmdId); // 将指令从map中删除
if (!syringePumpStopCMDToDeviceCMDToDeviceFuture.isReceived()) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "停止推动注射泵指令响应超时", syringePumpStopCMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
return;
}
if (syringePumpStopCMDToDeviceResult.getJSONObject("error") != null) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "停止推动注射泵指令返回错误", syringePumpStopCMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
return;
}
Boolean syringePumpStopCMDToDeviceResultStatus = syringePumpStopCMDToDeviceResult.getBool("result");
if (!syringePumpStopCMDToDeviceResultStatus) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "停止推动注射泵指令执行失败", syringePumpStopCMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
return;
}
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RESULT, "停止推动注射泵指令反馈", syringePumpStopCMDToDeviceResult), MediaType.APPLICATION_JSON);
//2.全部关闭三通阀
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "全部关闭三通阀"), MediaType.APPLICATION_JSON);
CMDToDevice threeWayValveCloseAllCMDToDevice = DeviceCommandGenerator.three_way_valve_close_all();//全部关闭三通阀
CommandFuture threeWayValveCloseAllCMDToDeviceFuture = new CommandFuture();
threeWayValveCloseAllCMDToDeviceFuture.setCmdToDevice(threeWayValveCloseAllCMDToDevice);
Integer threeWayValveCloseAllCMDToDeviceCmdId = threeWayValveCloseAllCMDToDevice.getCmdId();
CurrentSendCmdMapInstance.getInstance().putCommand(threeWayValveCloseAllCMDToDeviceCmdId, threeWayValveCloseAllCMDToDeviceFuture); // 将指令放入map
deviceClient.sendToJSON(threeWayValveCloseAllCMDToDevice); // 发送指令给设备
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "已向设备发送了全部关闭三通阀指令", threeWayValveCloseAllCMDToDevice), MediaType.APPLICATION_JSON);
threeWayValveCloseAllCMDToDeviceFuture.waitForContinue(); // 等待设备的反馈
JSONObject threeWayValveCloseAllCMDToDeviceResult = threeWayValveCloseAllCMDToDeviceFuture.getCallbackResult(); // 拿到设备返回结果
CurrentSendCmdMapInstance.getInstance().removeCommand(threeWayValveCloseAllCMDToDeviceCmdId); // 从map中删除该指令
if (!threeWayValveCloseAllCMDToDeviceFuture.isReceived()) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "全部关闭三通阀指令响应超时", threeWayValveCloseAllCMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
return;
}
if (threeWayValveCloseAllCMDToDeviceResult.getJSONObject("error") != null) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "全部关闭三通阀指令返回错误", threeWayValveCloseAllCMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
return;
}
Boolean threeWayValveCloseAllCMDToDeviceResultStatus = threeWayValveCloseAllCMDToDeviceResult.getBool("result");
if (!threeWayValveCloseAllCMDToDeviceResultStatus) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "全部关闭三通阀指令执行失败", threeWayValveCloseAllCMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
return;
}
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RESULT, "全部关闭三通阀指令反馈", threeWayValveCloseAllCMDToDeviceResult), MediaType.APPLICATION_JSON);
//3.关闭喷嘴阀
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "关闭喷嘴阀"), MediaType.APPLICATION_JSON);
CMDToDevice nozzleValveCloseCMDToDevice = DeviceCommandGenerator.nozzle_valve_close();//关闭喷嘴阀
CommandFuture nozzleValveCloseCMDToDeviceFuture = new CommandFuture();
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "关闭喷嘴阀"), MediaType.APPLICATION_JSON);
nozzleValveCloseCMDToDeviceFuture.setCmdToDevice(nozzleValveCloseCMDToDevice);
Integer nozzleValveCloseCMDToDeviceCmdId = nozzleValveCloseCMDToDevice.getCmdId();
CurrentSendCmdMapInstance.getInstance().putCommand(nozzleValveCloseCMDToDeviceCmdId, nozzleValveCloseCMDToDeviceFuture); // 将指令放入map
deviceClient.sendToJSON(nozzleValveCloseCMDToDevice); // 发送指令给设备
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "已向设备发送了关闭喷嘴阀指令", nozzleValveCloseCMDToDevice), MediaType.APPLICATION_JSON);
nozzleValveCloseCMDToDeviceFuture.waitForContinue(); // 等待设备的反馈
JSONObject nozzleValveCloseCMDToDeviceResult = nozzleValveCloseCMDToDeviceFuture.getCallbackResult(); // 拿到设备返回结果
CurrentSendCmdMapInstance.getInstance().removeCommand(nozzleValveCloseCMDToDeviceCmdId); // 从map中删除该指令
if (!nozzleValveCloseCMDToDeviceFuture.isReceived()) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "关闭喷嘴阀指令响应超时", nozzleValveCloseCMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
return;
}
if (nozzleValveCloseCMDToDeviceResult.getJSONObject("error") != null) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "关闭喷嘴阀指令返回错误", nozzleValveCloseCMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
return;
}
Boolean nozzleValveCloseCMDToDeviceResultStatus = nozzleValveCloseCMDToDeviceResult.getBool("result");
if (!nozzleValveCloseCMDToDeviceResultStatus) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "关闭喷嘴阀指令执行失败", nozzleValveCloseCMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
return;
}
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RESULT, "关闭喷嘴阀指令反馈", nozzleValveCloseCMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
}
}

184
src/main/java/com/qyft/ms/app/handler/impl/NozzlePipelineWash.java

@ -1,9 +1,14 @@
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;
@ -12,6 +17,8 @@ import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyEmitter;
import java.util.Map;
/**
* 喷嘴管路_清洗喷嘴管路
*/
@ -26,8 +33,183 @@ public class NozzlePipelineWash implements CommandHandler {
public void handle(CMDFormV2 cmdForm, ResponseBodyEmitter emitter) throws Exception {
String frontCmdId = cmdForm.getCmdId();
String frontCmdName = cmdForm.getCmdName();
//向前端发送接收到指令
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RECEIVE, "后台已收到指令"), MediaType.APPLICATION_JSON);
//1.判断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轴 //TODO安全距离应该可配置
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "z轴超出安全距离,抬升z轴至安全距离"), MediaType.APPLICATION_JSON);
CMDToDevice motorZPositionSetCmdToDevice = DeviceCommandGenerator.motor_z_position_set(80.0, 2);//生成指令 移动z轴到指定位置 (TODO)安全距离应该可配置
CommandFuture motorZPositionSetCmdToDeviceFuture = new CommandFuture();
motorZPositionSetCmdToDeviceFuture.setCmdToDevice(motorZPositionSetCmdToDevice);
Integer motorZPositionSetCmdToDeviceCmdId = motorZPositionSetCmdToDevice.getCmdId();
CurrentSendCmdMapInstance.getInstance().putCommand(motorZPositionSetCmdToDeviceCmdId, motorZPositionSetCmdToDeviceFuture);//将指令放入map
deviceClient.sendToJSON(motorZPositionSetCmdToDevice); //发送指令给设备
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "已向设备发送了移动z轴到指定位置指令", motorZPositionSetCmdToDevice), MediaType.APPLICATION_JSON);
motorZPositionSetCmdToDeviceFuture.waitForContinue();//等待设备的反馈
JSONObject motorZPositionSetCmdToDeviceResult = motorZPositionSetCmdToDeviceFuture.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);
}
//2.轴移动到废液位置
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "轴移动到废液位置"), MediaType.APPLICATION_JSON);
CMDToDevice motorXPositionSetCmdToDevice = DeviceCommandGenerator.motor_x_position_set(173.08, 2);//生成指令 移动x轴到指定位置 (TODO) 废液桶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 motorXYZPositionSetCmdToDeviceResultStatus = motorXPositionSetCmdToDeviceResult.getBool("result");
if (!motorXYZPositionSetCmdToDeviceResultStatus) {
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(75.0, 0);//移动y轴到指定位置 (TODO) 废液桶Y轴位置应当可以配置
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, "移动y轴到指定位置指令响应超时", motorYPositionSetCMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
return;
}
if (motorYPositionSetCMDToDeviceResult.getJSONObject("error") != null) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "移动y轴到指定位置指令返回错误", motorYPositionSetCMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
return;
}
Boolean motorYPositionSetCMDToDeviceResultStatus = motorYPositionSetCMDToDeviceResult.getBool("result");
if (!motorYPositionSetCMDToDeviceResultStatus) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "移动y轴到指定位置指令执行失败", motorYPositionSetCMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
return;
}
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RESULT, "移动y轴到指定位置指令反馈", motorYPositionSetCMDToDeviceResult), MediaType.APPLICATION_JSON);
//3.下降z轴高度防止飞溅
Thread.sleep(10 * 1000);//TODO 等待10秒x和y轴移动完毕
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "下降z轴高度,防止飞溅"), MediaType.APPLICATION_JSON);
CMDToDevice motorZPositionSetDownCmdToDevice = DeviceCommandGenerator.motor_z_position_set(70.0, 2);//生成指令 移动z轴到指定位置 (TODO) 废液桶Y轴位置应当可以配置
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);
//4.开启三通阀到喷嘴管路
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "打开三通阀注射器管路"), MediaType.APPLICATION_JSON);
CMDToDevice threeWayValveOpenSyringePipelineCMDToDevice = DeviceCommandGenerator.three_way_valve_open_syringe_pipeline();//打开三通阀喷嘴管路
CommandFuture threeWayValveOpenSyringePipelineCMDToDeviceFuture = new CommandFuture();
threeWayValveOpenSyringePipelineCMDToDeviceFuture.setCmdToDevice(threeWayValveOpenSyringePipelineCMDToDevice);
Integer threeWayValveOpenSyringePipelineCMDToDeviceCmdId = threeWayValveOpenSyringePipelineCMDToDevice.getCmdId();
CurrentSendCmdMapInstance.getInstance().putCommand(threeWayValveOpenSyringePipelineCMDToDeviceCmdId, threeWayValveOpenSyringePipelineCMDToDeviceFuture); // 将指令放入map
deviceClient.sendToJSON(threeWayValveOpenSyringePipelineCMDToDevice); // 发送指令给设备
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "已向设备发送了打开三通阀喷嘴管路指令", threeWayValveOpenSyringePipelineCMDToDevice), MediaType.APPLICATION_JSON);
threeWayValveOpenSyringePipelineCMDToDeviceFuture.waitForContinue(); // 等待设备反馈
JSONObject threeWayValveOpenSyringePipelineCMDToDeviceResult = threeWayValveOpenSyringePipelineCMDToDeviceFuture.getCallbackResult(); // 获取设备返回结果
CurrentSendCmdMapInstance.getInstance().removeCommand(threeWayValveOpenSyringePipelineCMDToDeviceCmdId); // 从map中删除该指令
if (!threeWayValveOpenSyringePipelineCMDToDeviceFuture.isReceived()) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "打开三通阀喷嘴管路指令响应超时", threeWayValveOpenSyringePipelineCMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
return;
}
if (threeWayValveOpenSyringePipelineCMDToDeviceResult.getJSONObject("error") != null) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "打开三通阀喷嘴管路指令返回错误", threeWayValveOpenSyringePipelineCMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
return;
}
Boolean threeWayValveOpenSyringePipelineCMDToDeviceResultStatus = threeWayValveOpenSyringePipelineCMDToDeviceResult.getBool("result");
if (!threeWayValveOpenSyringePipelineCMDToDeviceResultStatus) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "打开三通阀喷嘴管路指令执行失败", threeWayValveOpenSyringePipelineCMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
return;
}
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RESULT, "打开三通阀喷嘴管路指令反馈", threeWayValveOpenSyringePipelineCMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
}
}

35
src/main/java/com/qyft/ms/app/handler/impl/SlideTrayIn.java

@ -35,26 +35,35 @@ public class SlideTrayIn implements CommandHandler {
public void handle(CMDFormV2 cmdForm, ResponseBodyEmitter emitter) throws Exception {
String frontCmdId = cmdForm.getCmdId();
String frontCmdName = cmdForm.getCmdName();
//向前端发送接收到指令
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RECEIVE, "后台已收到指令"), MediaType.APPLICATION_JSON);
CMDToDevice slideTrayInCmdToDevice = DeviceCommandGenerator.slide_tray_in(0.0, 2);//生成指令 推入玻片托盘
CMDToDevice slideTrayInCmdToDevice = DeviceCommandGenerator.slide_tray_in(0.0, 2);// 推入玻片托盘
CommandFuture slideTrayInCmdToDeviceFuture = new CommandFuture();
slideTrayInCmdToDeviceFuture.setCmdToDevice(slideTrayInCmdToDevice);
Integer toDeviceCmdId = slideTrayInCmdToDevice.getCmdId();
CurrentSendCmdMapInstance.getInstance().putCommand(toDeviceCmdId, slideTrayInCmdToDeviceFuture); // 将指令放入map
deviceClient.sendToJSON(slideTrayInCmdToDevice); //发送指令给设备
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "已向设备发送了推入玻片托盘指令:", slideTrayInCmdToDevice), MediaType.APPLICATION_JSON);
slideTrayInCmdToDeviceFuture.waitForContinue();//等待设备的反馈
JSONObject deviceResult = slideTrayInCmdToDeviceFuture.getCallbackResult();//拿到设备返回结果
CurrentSendCmdMapInstance.getInstance().removeCommand(toDeviceCmdId);//将指令从map中删除
if (slideTrayInCmdToDeviceFuture.isReceived()) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RESULT, "推入玻片托盘指令设备反馈:", deviceResult), MediaType.APPLICATION_JSON);
} else {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "推入玻片托盘指令响应超时:", deviceResult), MediaType.APPLICATION_JSON);
deviceClient.sendToJSON(slideTrayInCmdToDevice);
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "已向设备发送了推入玻片托盘指令", slideTrayInCmdToDevice), MediaType.APPLICATION_JSON);
slideTrayInCmdToDeviceFuture.waitForContinue();
JSONObject slideTrayInCmdToDeviceResult = slideTrayInCmdToDeviceFuture.getCallbackResult();
CurrentSendCmdMapInstance.getInstance().removeCommand(toDeviceCmdId);
if (!slideTrayInCmdToDeviceFuture.isReceived()) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "推入玻片托盘指令响应超时", slideTrayInCmdToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
return;
}
if (slideTrayInCmdToDeviceResult.getJSONObject("error") != null) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "推入玻片托盘指令返回错误", slideTrayInCmdToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
return;
}
Boolean slideTrayInCmdToDeviceResultStatus = slideTrayInCmdToDeviceResult.getBool("result");
if (!slideTrayInCmdToDeviceResultStatus) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "推入玻片托盘指令执行失败", slideTrayInCmdToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
return;
}
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RESULT, "推入玻片托盘指令反馈", slideTrayInCmdToDeviceResult), MediaType.APPLICATION_JSON);
}
}

37
src/main/java/com/qyft/ms/app/handler/impl/SlideTrayOut.java

@ -34,27 +34,36 @@ public class SlideTrayOut implements CommandHandler {
public void handle(CMDFormV2 cmdForm, ResponseBodyEmitter emitter) throws Exception {
String frontCmdId = cmdForm.getCmdId();
String frontCmdName = cmdForm.getCmdName();
//向前端发送接收到指令
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RECEIVE, "后台已收到指令"), MediaType.APPLICATION_JSON);
//TODO 数值应该从数据库中获取
CMDToDevice slideTrayOutCmdToDevice = DeviceCommandGenerator.slide_tray_out(20.0, 2);//生成指令 推出玻片托盘
CMDToDevice slideTrayOutCmdToDevice = DeviceCommandGenerator.slide_tray_out(20.0, 2);// 推出玻片托盘TODO数值应从数据库中获取
CommandFuture slideTrayOutCmdToDeviceFuture = new CommandFuture();
slideTrayOutCmdToDeviceFuture.setCmdToDevice(slideTrayOutCmdToDevice);
Integer toDeviceCmdId = slideTrayOutCmdToDevice.getCmdId();
CurrentSendCmdMapInstance.getInstance().putCommand(toDeviceCmdId, slideTrayOutCmdToDeviceFuture); // 将指令放入map
deviceClient.sendToJSON(slideTrayOutCmdToDevice); //发送指令给设备
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "已向设备发送了推出玻片托盘指令:", slideTrayOutCmdToDevice), MediaType.APPLICATION_JSON);
slideTrayOutCmdToDeviceFuture.waitForContinue();//等待设备的反馈
deviceClient.sendToJSON(slideTrayOutCmdToDevice);
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "已向设备发送了推出玻片托盘指令", slideTrayOutCmdToDevice), MediaType.APPLICATION_JSON);
slideTrayOutCmdToDeviceFuture.waitForContinue();
JSONObject slideTrayOutCmdToDeviceResult = slideTrayOutCmdToDeviceFuture.getCallbackResult();
CurrentSendCmdMapInstance.getInstance().removeCommand(toDeviceCmdId);
if (!slideTrayOutCmdToDeviceFuture.isReceived()) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "推出玻片托盘指令响应超时", slideTrayOutCmdToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
return;
}
JSONObject deviceResult = slideTrayOutCmdToDeviceFuture.getCallbackResult();//拿到设备返回结果
CurrentSendCmdMapInstance.getInstance().removeCommand(toDeviceCmdId);//将指令从map中删除
if (slideTrayOutCmdToDeviceResult.getJSONObject("error") != null) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "推出玻片托盘指令返回错误", slideTrayOutCmdToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
return;
}
if (slideTrayOutCmdToDeviceFuture.isReceived()) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RESULT, "推出玻片托盘指令设备反馈:", deviceResult), MediaType.APPLICATION_JSON);
} else {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "推出玻片托盘指令响应超时:", deviceResult), MediaType.APPLICATION_JSON);
Boolean slideTrayOutCmdToDeviceResultStatus = slideTrayOutCmdToDeviceResult.getBool("result");
if (!slideTrayOutCmdToDeviceResultStatus) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "推出玻片托盘指令执行失败", slideTrayOutCmdToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
return;
}
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RESULT, "推出玻片托盘指令反馈", slideTrayOutCmdToDeviceResult), MediaType.APPLICATION_JSON);
}
}

231
src/main/java/com/qyft/ms/app/handler/impl/SyringePipelineWash.java

@ -1,13 +1,24 @@
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;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyEmitter;
import java.util.Map;
/**
* 注射器管路_清洗注射器管路
*/
@ -16,9 +27,229 @@ import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyEmitter
@Async("asyncExecutor")
@CommandMapping("syringe_pipeline_wash")//业务指令注解
public class SyringePipelineWash implements CommandHandler {
/**
* 设备通信client
*/
private final TcpClient deviceClient;
@Override
public void handle(CMDFormV2 cmdForm, ResponseBodyEmitter emitter) throws Exception {
String frontCmdId = cmdForm.getCmdId();
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轴 //TODO安全距离应该可配置
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "z轴超出安全距离,抬升z轴至安全距离"), MediaType.APPLICATION_JSON);
CMDToDevice motorZPositionSetCmdToDevice = DeviceCommandGenerator.motor_z_position_set(80.0, 2);//生成指令 移动z轴到指定位置 (TODO)安全距离应该可配置
CommandFuture motorZPositionSetCmdToDeviceFuture = new CommandFuture();
motorZPositionSetCmdToDeviceFuture.setCmdToDevice(motorZPositionSetCmdToDevice);
Integer motorZPositionSetCmdToDeviceCmdId = motorZPositionSetCmdToDevice.getCmdId();
CurrentSendCmdMapInstance.getInstance().putCommand(motorZPositionSetCmdToDeviceCmdId, motorZPositionSetCmdToDeviceFuture);//将指令放入map
deviceClient.sendToJSON(motorZPositionSetCmdToDevice); //发送指令给设备
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "已向设备发送了移动z轴到指定位置指令", motorZPositionSetCmdToDevice), MediaType.APPLICATION_JSON);
motorZPositionSetCmdToDeviceFuture.waitForContinue();//等待设备的反馈
JSONObject motorZPositionSetCmdToDeviceResult = motorZPositionSetCmdToDeviceFuture.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.xy轴移动到废液位置
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "轴移动到废液位置"), MediaType.APPLICATION_JSON);
CMDToDevice motorXPositionSetCmdToDevice = DeviceCommandGenerator.motor_x_position_set(173.08, 2);//生成指令 移动x轴到指定位置 (TODO) 废液桶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 motorXYZPositionSetCmdToDeviceResultStatus = motorXPositionSetCmdToDeviceResult.getBool("result");
if (!motorXYZPositionSetCmdToDeviceResultStatus) {
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(75.0, 0);//移动y轴到指定位置 (TODO) 废液桶Y轴位置应当可以配置
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, "移动y轴到指定位置指令响应超时", motorYPositionSetCMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
return;
}
if (motorYPositionSetCMDToDeviceResult.getJSONObject("error") != null) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "移动y轴到指定位置指令返回错误", motorYPositionSetCMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
return;
}
Boolean motorYPositionSetCMDToDeviceResultStatus = motorYPositionSetCMDToDeviceResult.getBool("result");
if (!motorYPositionSetCMDToDeviceResultStatus) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "移动y轴到指定位置指令执行失败", motorYPositionSetCMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
return;
}
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RESULT, "移动y轴到指定位置指令反馈", motorYPositionSetCMDToDeviceResult), MediaType.APPLICATION_JSON);
//4.下降z轴高度防止飞溅
Thread.sleep(10 * 1000);//TODO 等待10秒x和y轴移动完毕
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "下降z轴高度,防止飞溅"), MediaType.APPLICATION_JSON);
CMDToDevice motorZPositionSetDownCmdToDevice = DeviceCommandGenerator.motor_z_position_set(70.0, 2);//生成指令 移动z轴到指定位置 (TODO) 废液桶Y轴位置应当可以配置
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 threeWayValveOpenSprayPipelineCMDToDevice = DeviceCommandGenerator.three_way_valve_open_spray_pipeline();//生成指令 打开三通阀注射器管路
CommandFuture threeWayValveOpenSprayPipelineCMDToDeviceFuture = new CommandFuture();
threeWayValveOpenSprayPipelineCMDToDeviceFuture.setCmdToDevice(threeWayValveOpenSprayPipelineCMDToDevice);
Integer threeWayValveOpenSprayPipelineCMDToDeviceCmdId = threeWayValveOpenSprayPipelineCMDToDevice.getCmdId();
CurrentSendCmdMapInstance.getInstance().putCommand(threeWayValveOpenSprayPipelineCMDToDeviceCmdId, threeWayValveOpenSprayPipelineCMDToDeviceFuture); // 将指令放入map
deviceClient.sendToJSON(threeWayValveOpenSprayPipelineCMDToDevice); // 发送指令给设备
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "已向设备发送了打开三通阀注射器管路指令", threeWayValveOpenSprayPipelineCMDToDevice), MediaType.APPLICATION_JSON);
threeWayValveOpenSprayPipelineCMDToDeviceFuture.waitForContinue(); // 等待设备的反馈
JSONObject threeWayValveOpenSprayPipelineCMDToDeviceResult = threeWayValveOpenSprayPipelineCMDToDeviceFuture.getCallbackResult(); // 拿到设备返回结果
CurrentSendCmdMapInstance.getInstance().removeCommand(threeWayValveOpenSprayPipelineCMDToDeviceCmdId); // 将指令从map中删除
if (!threeWayValveOpenSprayPipelineCMDToDeviceFuture.isReceived()) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "打开三通阀注射器管路指令响应超时", threeWayValveOpenSprayPipelineCMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
return;
}
if (threeWayValveOpenSprayPipelineCMDToDeviceResult.getJSONObject("error") != null) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "打开三通阀注射器管路指令返回错误", threeWayValveOpenSprayPipelineCMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
return;
}
Boolean threeWayValveOpenSprayPipelineCMDToDeviceResultStatus = threeWayValveOpenSprayPipelineCMDToDeviceResult.getBool("result");
if (!threeWayValveOpenSprayPipelineCMDToDeviceResultStatus) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "打开三通阀注射器管路指令执行失败", threeWayValveOpenSprayPipelineCMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
return;
}
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RESULT, "打开三通阀注射器管路指令反馈", threeWayValveOpenSprayPipelineCMDToDeviceResult), MediaType.APPLICATION_JSON);
//6.设置注射泵速度推注射泵
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "设置注射泵速度,推注射泵"), MediaType.APPLICATION_JSON);
CMDToDevice syringePumpInjectionVolumeSetCMDToDevice = DeviceCommandGenerator.syringe_pump_injection_volume_set(1);//推动移动注射泵
CommandFuture syringePumpInjectionVolumeSetCMDToDeviceFuture = new CommandFuture();
syringePumpInjectionVolumeSetCMDToDeviceFuture.setCmdToDevice(syringePumpInjectionVolumeSetCMDToDevice);
Integer syringePumpInjectionVolumeSetCMDToDeviceCmdId = syringePumpInjectionVolumeSetCMDToDevice.getCmdId();
CurrentSendCmdMapInstance.getInstance().putCommand(syringePumpInjectionVolumeSetCMDToDeviceCmdId, syringePumpInjectionVolumeSetCMDToDeviceFuture); // 将指令放入map
deviceClient.sendToJSON(syringePumpInjectionVolumeSetCMDToDevice); // 发送指令给设备
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "已向设备发送了推动移动注射泵指令", syringePumpInjectionVolumeSetCMDToDevice), MediaType.APPLICATION_JSON);
syringePumpInjectionVolumeSetCMDToDeviceFuture.waitForContinue(); // 等待设备的反馈
JSONObject syringePumpInjectionVolumeSetCMDToDeviceResult = syringePumpInjectionVolumeSetCMDToDeviceFuture.getCallbackResult(); // 拿到设备返回结果
CurrentSendCmdMapInstance.getInstance().removeCommand(syringePumpInjectionVolumeSetCMDToDeviceCmdId); // 将指令从map中删除
if (!syringePumpInjectionVolumeSetCMDToDeviceFuture.isReceived()) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "推动移动注射泵指令响应超时", syringePumpInjectionVolumeSetCMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
return;
}
if (syringePumpInjectionVolumeSetCMDToDeviceResult.getJSONObject("error") != null) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "推动移动注射泵指令返回错误", syringePumpInjectionVolumeSetCMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
return;
}
Boolean syringePumpInjectionVolumeSetCMDToDeviceResultStatus = syringePumpInjectionVolumeSetCMDToDeviceResult.getBool("result");
if (!syringePumpInjectionVolumeSetCMDToDeviceResultStatus) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "推动移动注射泵指令执行失败", syringePumpInjectionVolumeSetCMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
return;
}
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RESULT, "推动移动注射泵指令反馈", syringePumpInjectionVolumeSetCMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
}
}

75
src/main/java/com/qyft/ms/app/handler/impl/SyringePipelineWashStop.java

@ -1,9 +1,18 @@
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;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyEmitter;
@ -16,9 +25,73 @@ import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyEmitter
@Async("asyncExecutor")
@CommandMapping("syringe_pipeline_wash_stop")//业务指令注解
public class SyringePipelineWashStop implements CommandHandler {
/**
* 设备通信client
*/
private final TcpClient deviceClient;
@Override
public void handle(CMDFormV2 cmdForm, ResponseBodyEmitter emitter) throws Exception {
String frontCmdId = cmdForm.getCmdId();
String frontCmdName = cmdForm.getCmdName();
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RECEIVE, "后台已收到指令"), MediaType.APPLICATION_JSON);//向前端发送接收到指令
//1.停止推动注射泵
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "停止推动注射泵"), MediaType.APPLICATION_JSON);
CMDToDevice syringePumpStopCMDToDevice = DeviceCommandGenerator.syringe_pump_stop();//停止推动注射泵
CommandFuture syringePumpStopCMDToDeviceCMDToDeviceFuture = new CommandFuture();
syringePumpStopCMDToDeviceCMDToDeviceFuture.setCmdToDevice(syringePumpStopCMDToDevice);
Integer syringePumpStopCMDToDeviceCmdId = syringePumpStopCMDToDevice.getCmdId();
CurrentSendCmdMapInstance.getInstance().putCommand(syringePumpStopCMDToDeviceCmdId, syringePumpStopCMDToDeviceCMDToDeviceFuture); // 将指令放入map
deviceClient.sendToJSON(syringePumpStopCMDToDevice); // 发送指令给设备
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "已向设备发送了停止推动注射泵指令", syringePumpStopCMDToDevice), MediaType.APPLICATION_JSON);
syringePumpStopCMDToDeviceCMDToDeviceFuture.waitForContinue(); // 等待设备的反馈
JSONObject syringePumpStopCMDToDeviceResult = syringePumpStopCMDToDeviceCMDToDeviceFuture.getCallbackResult(); // 拿到设备返回结果
CurrentSendCmdMapInstance.getInstance().removeCommand(syringePumpStopCMDToDeviceCmdId); // 将指令从map中删除
if (!syringePumpStopCMDToDeviceCMDToDeviceFuture.isReceived()) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "停止推动注射泵指令响应超时", syringePumpStopCMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
return;
}
if (syringePumpStopCMDToDeviceResult.getJSONObject("error") != null) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "停止推动注射泵指令返回错误", syringePumpStopCMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
return;
}
Boolean syringePumpStopCMDToDeviceResultStatus = syringePumpStopCMDToDeviceResult.getBool("result");
if (!syringePumpStopCMDToDeviceResultStatus) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "停止推动注射泵指令执行失败", syringePumpStopCMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
return;
}
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RESULT, "停止推动注射泵指令反馈", syringePumpStopCMDToDeviceResult), MediaType.APPLICATION_JSON);
//2.全部关闭三通阀
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "全部关闭三通阀"), MediaType.APPLICATION_JSON);
CMDToDevice threeWayValveCloseAllCMDToDevice = DeviceCommandGenerator.three_way_valve_close_all();//全部关闭三通阀
CommandFuture threeWayValveCloseAllCMDToDeviceFuture = new CommandFuture();
threeWayValveCloseAllCMDToDeviceFuture.setCmdToDevice(threeWayValveCloseAllCMDToDevice);
Integer threeWayValveCloseAllCMDToDeviceCmdId = threeWayValveCloseAllCMDToDevice.getCmdId();
CurrentSendCmdMapInstance.getInstance().putCommand(threeWayValveCloseAllCMDToDeviceCmdId, threeWayValveCloseAllCMDToDeviceFuture); // 将指令放入map
deviceClient.sendToJSON(threeWayValveCloseAllCMDToDevice); // 发送指令给设备
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "已向设备发送了全部关闭三通阀指令", threeWayValveCloseAllCMDToDevice), MediaType.APPLICATION_JSON);
threeWayValveCloseAllCMDToDeviceFuture.waitForContinue(); // 等待设备的反馈
JSONObject threeWayValveCloseAllCMDToDeviceResult = threeWayValveCloseAllCMDToDeviceFuture.getCallbackResult(); // 拿到设备返回结果
CurrentSendCmdMapInstance.getInstance().removeCommand(threeWayValveCloseAllCMDToDeviceCmdId); // 从map中删除该指令
if (!threeWayValveCloseAllCMDToDeviceFuture.isReceived()) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "全部关闭三通阀指令响应超时", threeWayValveCloseAllCMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
return;
}
if (threeWayValveCloseAllCMDToDeviceResult.getJSONObject("error") != null) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "全部关闭三通阀指令返回错误", threeWayValveCloseAllCMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
return;
}
Boolean threeWayValveCloseAllCMDToDeviceResultStatus = threeWayValveCloseAllCMDToDeviceResult.getBool("result");
if (!threeWayValveCloseAllCMDToDeviceResultStatus) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "全部关闭三通阀指令执行失败", threeWayValveCloseAllCMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
return;
}
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RESULT, "全部关闭三通阀指令反馈", threeWayValveCloseAllCMDToDeviceResult), MediaType.APPLICATION_JSON);
}
}
Loading…
Cancel
Save