|
|
@ -19,6 +19,11 @@ import org.springframework.scheduling.annotation.Async; |
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyEmitter; |
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Optional; |
|
|
|
|
|
|
|
/** |
|
|
|
* 喷涂_基质喷涂继续 |
|
|
|
*/ |
|
|
@ -40,6 +45,60 @@ public class MatrixSprayContinue implements CommandHandler { |
|
|
|
String frontCmdId = cmdForm.getCmdId(); |
|
|
|
String frontCmdName = cmdForm.getCmdName(); |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RECEIVE, "后台已收到指令"), MediaType.APPLICATION_JSON);//向前端发送接收到指令 |
|
|
|
Map<String, Object> param = cmdForm.getParam(); |
|
|
|
|
|
|
|
// 1. 参数校验 |
|
|
|
Double motorZHeight = Optional.ofNullable(param.get("motorZHeight")) |
|
|
|
.map(Object::toString) |
|
|
|
.map(Double::parseDouble) |
|
|
|
.orElse(null); |
|
|
|
|
|
|
|
Double gasPressure = Optional.ofNullable(param.get("gasPressure")) |
|
|
|
.map(Object::toString) |
|
|
|
.map(Double::parseDouble) |
|
|
|
.orElse(null); |
|
|
|
|
|
|
|
Double volume = Optional.ofNullable(param.get("volume")) |
|
|
|
.map(Object::toString) |
|
|
|
.map(Double::parseDouble) |
|
|
|
.orElse(null); |
|
|
|
|
|
|
|
Boolean highVoltage = Optional.ofNullable(param.get("highVoltage")) |
|
|
|
.map(Object::toString) |
|
|
|
.map(Boolean::parseBoolean) |
|
|
|
.orElse(null); |
|
|
|
|
|
|
|
Double highVoltageValue = Optional.ofNullable(param.get("highVoltageValue")) |
|
|
|
.map(Object::toString) |
|
|
|
.map(Double::parseDouble) |
|
|
|
.orElse(null); |
|
|
|
|
|
|
|
Double movingSpeed = Optional.ofNullable(param.get("movingSpeed")) |
|
|
|
.map(Object::toString) |
|
|
|
.map(Double::parseDouble) |
|
|
|
.orElse(null); |
|
|
|
|
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
List<Map<String, Object>> positionList = (List<Map<String, Object>>) param.get("position"); |
|
|
|
|
|
|
|
if (validate(emitter, frontCmdId, frontCmdName, motorZHeight, gasPressure, volume, highVoltage, highVoltageValue, movingSpeed, positionList)) |
|
|
|
return; |
|
|
|
|
|
|
|
//1.速度 |
|
|
|
if (motorSpeedSet(emitter, movingSpeed, frontCmdId, frontCmdName)) return; |
|
|
|
//2.流速 |
|
|
|
if (syringePumpVolumeSet(emitter, volume, frontCmdId, frontCmdName)) return; |
|
|
|
//3.z轴高度 |
|
|
|
Double height = 101.2 - motorZHeight;//TODO 101.2是玻片高度,这个应该从数据库中获取 |
|
|
|
if (moveZ(emitter, height, movingSpeed, frontCmdId, frontCmdName)) return; |
|
|
|
//4.是否打开高压 |
|
|
|
if (highVoltage) {//加电 |
|
|
|
highVoltageOpen(emitter, highVoltageValue, frontCmdId, frontCmdName); |
|
|
|
} else {//关闭高压 |
|
|
|
highVoltageClose(emitter, frontCmdId, frontCmdName); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//开启喷嘴阀 |
|
|
|
CMDToDevice nozzleValveOpenCMDToDevice = DeviceCommandGenerator.nozzle_valve_open();//生成指令 开启喷嘴阀 |
|
|
|
CommandFuture nozzleValveOpenCMDToDeviceFuture = new CommandFuture(); |
|
|
@ -131,4 +190,273 @@ public class MatrixSprayContinue implements CommandHandler { |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "指令执行完毕"), MediaType.APPLICATION_JSON); |
|
|
|
emitter.complete(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private boolean motorSpeedSet(ResponseBodyEmitter emitter, Double movingSpeed, String frontCmdId, String frontCmdName) throws IOException { |
|
|
|
CMDToDevice motorXSpeedSetCmdToDevice = DeviceCommandGenerator.motor_x_speed_set(movingSpeed); // x轴电机速度设置 |
|
|
|
CommandFuture motorXSpeedSetCmdToDeviceFuture = new CommandFuture(); |
|
|
|
motorXSpeedSetCmdToDeviceFuture.setCmdToDevice(motorXSpeedSetCmdToDevice); |
|
|
|
Integer motorXSpeedSetCmdId = motorXSpeedSetCmdToDevice.getCmdId(); |
|
|
|
CurrentSendCmdMapInstance.getInstance().putCommand(motorXSpeedSetCmdId, motorXSpeedSetCmdToDeviceFuture); |
|
|
|
deviceClient.sendToJSON(motorXSpeedSetCmdToDevice); |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "已向设备发送了x轴电机速度设置指令", motorXSpeedSetCmdToDevice), MediaType.APPLICATION_JSON); |
|
|
|
|
|
|
|
motorXSpeedSetCmdToDeviceFuture.waitForContinue(); |
|
|
|
JSONObject motorXSpeedSetResult = motorXSpeedSetCmdToDeviceFuture.getCallbackResult(); |
|
|
|
CurrentSendCmdMapInstance.getInstance().removeCommand(motorXSpeedSetCmdId); |
|
|
|
|
|
|
|
if (!motorXSpeedSetCmdToDeviceFuture.isReceived()) { |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "x轴电机速度设置指令响应超时", motorXSpeedSetResult), MediaType.APPLICATION_JSON); |
|
|
|
emitter.complete(); |
|
|
|
return true; |
|
|
|
} |
|
|
|
if (motorXSpeedSetResult.getJSONObject("error") != null) { |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "x轴电机速度设置指令返回错误", motorXSpeedSetResult), MediaType.APPLICATION_JSON); |
|
|
|
emitter.complete(); |
|
|
|
return true; |
|
|
|
} |
|
|
|
Boolean motorXSpeedSetStatus = motorXSpeedSetResult.getBool("result"); |
|
|
|
if (!motorXSpeedSetStatus) { |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "x轴电机速度设置指令执行失败", motorXSpeedSetResult), MediaType.APPLICATION_JSON); |
|
|
|
emitter.complete(); |
|
|
|
return true; |
|
|
|
} |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RESULT, "x轴电机速度设置指令反馈", motorXSpeedSetResult), MediaType.APPLICATION_JSON); |
|
|
|
|
|
|
|
|
|
|
|
CMDToDevice motorYSpeedSetCmdToDevice = DeviceCommandGenerator.motor_x_speed_set(movingSpeed); // y轴电机速度设置 |
|
|
|
CommandFuture motorYSpeedSetCmdToDeviceFuture = new CommandFuture(); |
|
|
|
motorYSpeedSetCmdToDeviceFuture.setCmdToDevice(motorYSpeedSetCmdToDevice); |
|
|
|
Integer motorYSpeedSetCmdId = motorYSpeedSetCmdToDevice.getCmdId(); |
|
|
|
CurrentSendCmdMapInstance.getInstance().putCommand(motorYSpeedSetCmdId, motorYSpeedSetCmdToDeviceFuture); |
|
|
|
deviceClient.sendToJSON(motorYSpeedSetCmdToDevice); |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "已向设备发送了y轴电机速度设置指令", motorYSpeedSetCmdToDevice), MediaType.APPLICATION_JSON); |
|
|
|
|
|
|
|
motorYSpeedSetCmdToDeviceFuture.waitForContinue(); |
|
|
|
JSONObject motorYSpeedSetResult = motorYSpeedSetCmdToDeviceFuture.getCallbackResult(); |
|
|
|
CurrentSendCmdMapInstance.getInstance().removeCommand(motorYSpeedSetCmdId); |
|
|
|
|
|
|
|
if (!motorYSpeedSetCmdToDeviceFuture.isReceived()) { |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "y轴电机速度设置指令响应超时", motorYSpeedSetResult), MediaType.APPLICATION_JSON); |
|
|
|
emitter.complete(); |
|
|
|
return true; |
|
|
|
} |
|
|
|
if (motorYSpeedSetResult.getJSONObject("error") != null) { |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "y轴电机速度设置指令返回错误", motorYSpeedSetResult), MediaType.APPLICATION_JSON); |
|
|
|
emitter.complete(); |
|
|
|
return true; |
|
|
|
} |
|
|
|
Boolean motorYSpeedSetStatus = motorYSpeedSetResult.getBool("result"); |
|
|
|
if (!motorYSpeedSetStatus) { |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "y轴电机速度设置指令执行失败", motorYSpeedSetResult), MediaType.APPLICATION_JSON); |
|
|
|
emitter.complete(); |
|
|
|
return true; |
|
|
|
} |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RESULT, "y轴电机速度设置指令反馈", motorYSpeedSetResult), MediaType.APPLICATION_JSON); |
|
|
|
|
|
|
|
|
|
|
|
CMDToDevice motorZSpeedSetCmdToDevice = DeviceCommandGenerator.motor_x_speed_set(movingSpeed);// z轴电机速度设置 |
|
|
|
CommandFuture motorZSpeedSetCmdToDeviceFuture = new CommandFuture(); |
|
|
|
motorZSpeedSetCmdToDeviceFuture.setCmdToDevice(motorZSpeedSetCmdToDevice); |
|
|
|
Integer motorZSpeedSetCmdId = motorZSpeedSetCmdToDevice.getCmdId(); |
|
|
|
CurrentSendCmdMapInstance.getInstance().putCommand(motorZSpeedSetCmdId, motorZSpeedSetCmdToDeviceFuture); |
|
|
|
deviceClient.sendToJSON(motorZSpeedSetCmdToDevice); |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "已向设备发送了z轴电机速度设置指令", motorZSpeedSetCmdToDevice), MediaType.APPLICATION_JSON); |
|
|
|
|
|
|
|
motorZSpeedSetCmdToDeviceFuture.waitForContinue(); |
|
|
|
JSONObject motorZSpeedSetResult = motorZSpeedSetCmdToDeviceFuture.getCallbackResult(); |
|
|
|
CurrentSendCmdMapInstance.getInstance().removeCommand(motorZSpeedSetCmdId); |
|
|
|
|
|
|
|
if (!motorZSpeedSetCmdToDeviceFuture.isReceived()) { |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "z轴电机速度设置指令响应超时", motorZSpeedSetResult), MediaType.APPLICATION_JSON); |
|
|
|
emitter.complete(); |
|
|
|
return true; |
|
|
|
} |
|
|
|
if (motorZSpeedSetResult.getJSONObject("error") != null) { |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "z轴电机速度设置指令返回错误", motorZSpeedSetResult), MediaType.APPLICATION_JSON); |
|
|
|
emitter.complete(); |
|
|
|
return true; |
|
|
|
} |
|
|
|
Boolean motorZSpeedSetStatus = motorZSpeedSetResult.getBool("result"); |
|
|
|
if (!motorZSpeedSetStatus) { |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "z轴电机速度设置指令执行失败", motorZSpeedSetResult), MediaType.APPLICATION_JSON); |
|
|
|
emitter.complete(); |
|
|
|
return true; |
|
|
|
} |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RESULT, "z轴电机速度设置指令反馈", motorZSpeedSetResult), MediaType.APPLICATION_JSON); |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
private boolean syringePumpVolumeSet(ResponseBodyEmitter emitter, Double volume, String frontCmdId, String frontCmdName) throws IOException { |
|
|
|
CMDToDevice syringePumpVolumeSetCmdToDevice = DeviceCommandGenerator.syringe_pump_volume_set(volume);//注射泵流速设置 |
|
|
|
CommandFuture syringePumpVolumeSetCmdToDeviceFuture = new CommandFuture(); |
|
|
|
syringePumpVolumeSetCmdToDeviceFuture.setCmdToDevice(syringePumpVolumeSetCmdToDevice); |
|
|
|
Integer syringePumpVolumeSetCmdId = syringePumpVolumeSetCmdToDevice.getCmdId(); |
|
|
|
CurrentSendCmdMapInstance.getInstance().putCommand(syringePumpVolumeSetCmdId, syringePumpVolumeSetCmdToDeviceFuture); // 将指令放入map |
|
|
|
deviceClient.sendToJSON(syringePumpVolumeSetCmdToDevice); // 发送指令给设备 |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "已向设备发送了注射泵流速设置指令", syringePumpVolumeSetCmdToDevice), MediaType.APPLICATION_JSON); |
|
|
|
|
|
|
|
syringePumpVolumeSetCmdToDeviceFuture.waitForContinue(); // 等待设备反馈 |
|
|
|
JSONObject syringePumpVolumeSetResult = syringePumpVolumeSetCmdToDeviceFuture.getCallbackResult(); // 获取设备返回结果 |
|
|
|
CurrentSendCmdMapInstance.getInstance().removeCommand(syringePumpVolumeSetCmdId); // 从map中删除该指令 |
|
|
|
|
|
|
|
if (!syringePumpVolumeSetCmdToDeviceFuture.isReceived()) { |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "注射泵流速设置指令响应超时", syringePumpVolumeSetResult), MediaType.APPLICATION_JSON); |
|
|
|
emitter.complete(); |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
if (syringePumpVolumeSetResult.getJSONObject("error") != null) { |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "注射泵流速设置指令返回错误", syringePumpVolumeSetResult), MediaType.APPLICATION_JSON); |
|
|
|
emitter.complete(); |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
Boolean syringePumpVolumeSetStatus = syringePumpVolumeSetResult.getBool("result"); |
|
|
|
if (!syringePumpVolumeSetStatus) { |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "注射泵流速设置指令执行失败", syringePumpVolumeSetResult), MediaType.APPLICATION_JSON); |
|
|
|
emitter.complete(); |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RESULT, "注射泵流速设置指令反馈", syringePumpVolumeSetResult), MediaType.APPLICATION_JSON); |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
private void highVoltageClose(ResponseBodyEmitter emitter, String frontCmdId, String frontCmdName) throws IOException { |
|
|
|
CMDToDevice highVoltageCloseCmdToDevice = DeviceCommandGenerator.high_voltage_close();//关闭高压 |
|
|
|
CommandFuture highVoltageCloseCmdToDeviceFuture = new CommandFuture(); |
|
|
|
highVoltageCloseCmdToDeviceFuture.setCmdToDevice(highVoltageCloseCmdToDevice); |
|
|
|
Integer highVoltageCloseCmdId = highVoltageCloseCmdToDevice.getCmdId(); |
|
|
|
CurrentSendCmdMapInstance.getInstance().putCommand(highVoltageCloseCmdId, highVoltageCloseCmdToDeviceFuture); // 将指令放入map |
|
|
|
deviceClient.sendToJSON(highVoltageCloseCmdToDevice); // 发送指令给设备 |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "已向设备发送了关闭高压指令", highVoltageCloseCmdToDevice), MediaType.APPLICATION_JSON); |
|
|
|
|
|
|
|
highVoltageCloseCmdToDeviceFuture.waitForContinue(); // 等待设备反馈 |
|
|
|
JSONObject highVoltageCloseResult = highVoltageCloseCmdToDeviceFuture.getCallbackResult(); // 获取设备返回结果 |
|
|
|
CurrentSendCmdMapInstance.getInstance().removeCommand(highVoltageCloseCmdId); // 从map中删除该指令 |
|
|
|
|
|
|
|
if (!highVoltageCloseCmdToDeviceFuture.isReceived()) { |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "关闭高压指令响应超时", highVoltageCloseResult), MediaType.APPLICATION_JSON); |
|
|
|
emitter.complete(); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
if (highVoltageCloseResult.getJSONObject("error") != null) { |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "关闭高压指令返回错误", highVoltageCloseResult), MediaType.APPLICATION_JSON); |
|
|
|
emitter.complete(); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
Boolean highVoltageCloseStatus = highVoltageCloseResult.getBool("result"); |
|
|
|
if (!highVoltageCloseStatus) { |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "关闭高压指令执行失败", highVoltageCloseResult), MediaType.APPLICATION_JSON); |
|
|
|
emitter.complete(); |
|
|
|
return; |
|
|
|
} |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RESULT, "关闭高压指令反馈", highVoltageCloseResult), MediaType.APPLICATION_JSON); |
|
|
|
} |
|
|
|
|
|
|
|
private static boolean validate(ResponseBodyEmitter emitter, String frontCmdId, String frontCmdName, Double motorZHeight, Double gasPressure, Double volume, Boolean highVoltage, Double highVoltageValue, Double movingSpeed, List<Map<String, Object>> positionList) throws IOException { |
|
|
|
if (motorZHeight == null) { |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "参数 motor_z_height 必填"), MediaType.APPLICATION_JSON); |
|
|
|
emitter.complete(); |
|
|
|
return true; |
|
|
|
} |
|
|
|
if (gasPressure == null) { |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "参数 gas_pressure 必填"), MediaType.APPLICATION_JSON); |
|
|
|
emitter.complete(); |
|
|
|
return true; |
|
|
|
} |
|
|
|
if (volume == null) { |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "参数 volume 必填"), MediaType.APPLICATION_JSON); |
|
|
|
emitter.complete(); |
|
|
|
return true; |
|
|
|
} |
|
|
|
if (highVoltage == null) { |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "参数 high_voltage 必填"), MediaType.APPLICATION_JSON); |
|
|
|
emitter.complete(); |
|
|
|
return true; |
|
|
|
} |
|
|
|
if (highVoltageValue == null) { |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "参数 high_voltage_value 必填"), MediaType.APPLICATION_JSON); |
|
|
|
emitter.complete(); |
|
|
|
return true; |
|
|
|
} |
|
|
|
if (movingSpeed == null) { |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "参数 moving_speed 必填"), MediaType.APPLICATION_JSON); |
|
|
|
emitter.complete(); |
|
|
|
return true; |
|
|
|
} |
|
|
|
if (positionList == null) { |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "参数 position 必填"), MediaType.APPLICATION_JSON); |
|
|
|
emitter.complete(); |
|
|
|
return true; |
|
|
|
} |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private boolean moveZ(ResponseBodyEmitter emitter, Double height, Double movingSpeed, String frontCmdId, String frontCmdName) throws IOException { |
|
|
|
CMDToDevice motorZPositionSetDownCmdToDevice = DeviceCommandGenerator.motor_z_position_set(height, movingSpeed);//移动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 true; |
|
|
|
} |
|
|
|
if (motorZPositionSetDownCmdToDeviceResult.getJSONObject("error") != null) { |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "移动z轴到指定位指令返回错误", motorZPositionSetDownCmdToDeviceResult), MediaType.APPLICATION_JSON); |
|
|
|
emitter.complete(); |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
Boolean motorZPositionSetDownCmdToDeviceResultStatus = motorZPositionSetDownCmdToDeviceResult.getBool("result"); |
|
|
|
if (!motorZPositionSetDownCmdToDeviceResultStatus) { |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "移动z轴到指定位指令执行失败", motorZPositionSetDownCmdToDeviceResult), MediaType.APPLICATION_JSON); |
|
|
|
emitter.complete(); |
|
|
|
return true; |
|
|
|
} |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RESULT, "移动z轴到指定位指令反馈", motorZPositionSetDownCmdToDeviceResult), MediaType.APPLICATION_JSON); |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
private boolean highVoltageOpen(ResponseBodyEmitter emitter, Double highVoltageValue, String frontCmdId, String frontCmdName) throws IOException { |
|
|
|
CMDToDevice highVoltageOpenCmdToDevice = DeviceCommandGenerator.high_voltage_open(highVoltageValue);//开启高压 |
|
|
|
CommandFuture highVoltageOpenCmdToDeviceFuture = new CommandFuture(); |
|
|
|
highVoltageOpenCmdToDeviceFuture.setCmdToDevice(highVoltageOpenCmdToDevice); |
|
|
|
Integer highVoltageOpenCmdId = highVoltageOpenCmdToDevice.getCmdId(); |
|
|
|
CurrentSendCmdMapInstance.getInstance().putCommand(highVoltageOpenCmdId, highVoltageOpenCmdToDeviceFuture); // 将指令放入map |
|
|
|
deviceClient.sendToJSON(highVoltageOpenCmdToDevice); // 发送指令给设备 |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "已向设备发送了开启高压指令", highVoltageOpenCmdToDevice), MediaType.APPLICATION_JSON); |
|
|
|
highVoltageOpenCmdToDeviceFuture.waitForContinue(); // 等待设备反馈 |
|
|
|
JSONObject highVoltageOpenResult = highVoltageOpenCmdToDeviceFuture.getCallbackResult(); // 获取设备返回结果 |
|
|
|
CurrentSendCmdMapInstance.getInstance().removeCommand(highVoltageOpenCmdId); // 从map中删除该指令 |
|
|
|
if (!highVoltageOpenCmdToDeviceFuture.isReceived()) { |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "开启高压指令响应超时", highVoltageOpenResult), MediaType.APPLICATION_JSON); |
|
|
|
emitter.complete(); |
|
|
|
return true; |
|
|
|
} |
|
|
|
if (highVoltageOpenResult.getJSONObject("error") != null) { |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "开启高压指令返回错误", highVoltageOpenResult), MediaType.APPLICATION_JSON); |
|
|
|
emitter.complete(); |
|
|
|
return true; |
|
|
|
} |
|
|
|
Boolean highVoltageOpenStatus = highVoltageOpenResult.getBool("result"); |
|
|
|
if (!highVoltageOpenStatus) { |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "开启高压指令执行失败", highVoltageOpenResult), MediaType.APPLICATION_JSON); |
|
|
|
emitter.complete(); |
|
|
|
return true; |
|
|
|
} |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RESULT, "开启高压指令反馈", highVoltageOpenResult), MediaType.APPLICATION_JSON); |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |