|
|
@ -1,19 +1,34 @@ |
|
|
|
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.core.registry.CommandHandlerRegistry; |
|
|
|
import com.qyft.ms.app.common.generator.PathGenerator; |
|
|
|
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.device.*; |
|
|
|
import com.qyft.ms.device.service.DeviceTcpCMDServiceV2; |
|
|
|
import com.qyft.ms.device.client.TcpClient; |
|
|
|
import com.qyft.ms.device.device.DeviceInstance; |
|
|
|
import com.qyft.ms.device.device.MatrixSprayStatusEnum; |
|
|
|
import com.qyft.ms.device.handler.DeviceMessageHandler; |
|
|
|
import lombok.Getter; |
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
import lombok.Setter; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
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.io.IOException; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.concurrent.CountDownLatch; |
|
|
|
|
|
|
|
/** |
|
|
|
* 喷涂_基质喷涂开始 |
|
|
|
*/ |
|
|
@ -24,82 +39,807 @@ import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyEmitter |
|
|
|
@CommandMapping("matrix_spray_start")//业务指令注解 |
|
|
|
public class MatrixSprayStart implements CommandHandler { |
|
|
|
|
|
|
|
private final CommandHandlerRegistry registry; |
|
|
|
private final TcpClient deviceClient; |
|
|
|
|
|
|
|
// private final CommandHandlerRegistry registry; |
|
|
|
|
|
|
|
private final DeviceMessageHandler deviceMessageHandler; |
|
|
|
|
|
|
|
/** |
|
|
|
* 目标坐标 |
|
|
|
*/ |
|
|
|
@Getter |
|
|
|
@Setter |
|
|
|
public Double targetX = null; |
|
|
|
@Getter |
|
|
|
@Setter |
|
|
|
public Double targetY = null; |
|
|
|
|
|
|
|
/** |
|
|
|
* { |
|
|
|
* cmdName:'matrix_spray_start' |
|
|
|
* cmdId:'', |
|
|
|
* param:{ |
|
|
|
* matrix_path_type:;//喷涂路径类型 |
|
|
|
* motor_z_height:;//高度 |
|
|
|
* gas_pressure://Mpa兆帕 |
|
|
|
* volume:20;//单位uL微升 |
|
|
|
* high_voltage:true/false;//是否打开高压 |
|
|
|
* high_voltage_value:4000;//高压值 |
|
|
|
* spacing:''//毫米 |
|
|
|
* moving_speed:8mm/s;//移动速度 |
|
|
|
* times:;//喷涂遍数 |
|
|
|
* position:[{x1,y1,x2,y2,index}] |
|
|
|
* } |
|
|
|
* cmdName:'matrix_spray_start' |
|
|
|
* cmdId:'', |
|
|
|
* param:{ |
|
|
|
* matrix_path_type:horizontal | vertical | grid;//喷涂路径类型 |
|
|
|
* motor_z_height:;//高度 Z轴距离玻片的高度 |
|
|
|
* gas_pressure://Mpa兆帕 不处理 |
|
|
|
* volume:20;//单位uL微升 基质流速(控制注射泵速度) |
|
|
|
* high_voltage:true/false;//是否打开高压 |
|
|
|
* high_voltage_value:4000;//高压值 |
|
|
|
* spacing:''//毫米 间距 |
|
|
|
* moving_speed:8mm/s;//移动速度 轴速度 |
|
|
|
* times:;//喷涂遍数 |
|
|
|
* position:[{x1,y1,x2,y2,index}] |
|
|
|
* } |
|
|
|
* } |
|
|
|
* @param cmdForm |
|
|
|
* @param emitter |
|
|
|
* @throws Exception |
|
|
|
*/ |
|
|
|
|
|
|
|
@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. 参数校验 |
|
|
|
String matrixPathType = (String) param.get("matrix_path_type");//喷涂路径类型 horizontal | vertical | grid |
|
|
|
Integer motorZHeight = (Integer) param.get("motor_z_height");//Z轴距离玻片的高度(距玻片的距离) |
|
|
|
Integer gasPressure = (Integer) param.get("gas_pressure");//Mpa兆帕 不处理 |
|
|
|
Integer volume = (Integer) param.get("volume");//单位uL微升 基质流速(控制注射泵速度) |
|
|
|
Boolean highVoltage = (Boolean) param.get("high_voltage");//是否打开高压 |
|
|
|
Integer highVoltageValue = (Integer) param.get("high_voltage_value");//高压值 |
|
|
|
Integer spacing = (Integer) param.get("spacing");//毫米 间距 |
|
|
|
Integer movingSpeed = (Integer) param.get("moving_speed");//轴移动速度 |
|
|
|
Integer times = (Integer) param.get("times");//喷涂遍数 |
|
|
|
//noinspection unchecked |
|
|
|
List<Map<String, Object>> positionList = (List<Map<String, Object>>) param.get("position"); |
|
|
|
|
|
|
|
if (validate(emitter, matrixPathType, frontCmdId, frontCmdName, motorZHeight, gasPressure, volume, highVoltage, highVoltageValue, spacing, movingSpeed, times, positionList)) |
|
|
|
return; |
|
|
|
|
|
|
|
DeviceInstance deviceInstance = DeviceInstance.getInstance(); |
|
|
|
MatrixSprayStatusEnum matrixSprayStatus = DeviceInstance.getInstance().getMatrixSprayStatusEnum(); |
|
|
|
|
|
|
|
/** |
|
|
|
* 1.判断设备是否正在喷涂中 |
|
|
|
*/ |
|
|
|
if("yes".equals(matrixSprayStatus.getCode())){ |
|
|
|
//2.判断设备是否正在喷涂中 |
|
|
|
if ("yes".equals(matrixSprayStatus.getCode())) { |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "设备正在喷涂中,请勿重复操作"), MediaType.APPLICATION_JSON); |
|
|
|
return; |
|
|
|
} |
|
|
|
/** |
|
|
|
* 2.判断喷涂状态 |
|
|
|
*/ |
|
|
|
deviceInstance.setMatrixSprayStatusEnum(MatrixSprayStatusEnum.YES); |
|
|
|
deviceInstance.setMatrixSprayStatusEnum(MatrixSprayStatusEnum.YES);//如果没有在喷涂,设定当前状态为正在喷涂 |
|
|
|
//三轴回到原点 先 z |
|
|
|
CountDownLatch latch = new CountDownLatch(1); |
|
|
|
deviceMessageHandler.setLatch(latch); |
|
|
|
// z轴回原点 |
|
|
|
if (originZ(emitter, frontCmdId, frontCmdName)) return; |
|
|
|
latch.await();//等待z轴回到原点 |
|
|
|
latch = new CountDownLatch(2); |
|
|
|
deviceMessageHandler.setLatch(latch); |
|
|
|
// x轴回原点 |
|
|
|
if (originX(emitter, frontCmdId, frontCmdName)) return; |
|
|
|
|
|
|
|
// y轴回原点 |
|
|
|
if (originY(emitter, frontCmdId, frontCmdName)) return; |
|
|
|
latch.await();//等待x与y轴回到原点 |
|
|
|
|
|
|
|
//设定轴移动速度 |
|
|
|
if (motorSpeedSet(emitter, movingSpeed, frontCmdId, frontCmdName)) return; |
|
|
|
|
|
|
|
//2. 插入日志 |
|
|
|
//TODO写日志 |
|
|
|
//3.将三通阀转至喷涂管路 |
|
|
|
//4.开启三通阀到喷嘴管路 |
|
|
|
if (threeWayValveOpenSyringePipeLine(emitter, frontCmdId, frontCmdName)) return; |
|
|
|
//4.设置指定轴的电机的运行速度 |
|
|
|
//5.注射泵速度 |
|
|
|
//6.判断高度安全值 |
|
|
|
//7.移动到指定高度(位置) (z - height) |
|
|
|
Double height = 101.2 - motorZHeight;//TODO 101.2是玻片高度,这个应该从数据库中获取 |
|
|
|
if (moveZ(emitter, height, frontCmdId, frontCmdName)) return; |
|
|
|
//8.是否加电 电压 |
|
|
|
if (highVoltage) {//加电 |
|
|
|
if (highVoltageOpen(emitter, highVoltageValue, frontCmdId, frontCmdName)) return; |
|
|
|
} |
|
|
|
//9 循环position进 position:[{x1,y1,x2,y2,index}] |
|
|
|
Double[][] slideArr = { |
|
|
|
{18.08, 101.2}, |
|
|
|
{45.08, 101.2}, |
|
|
|
{72.08, 101.2}, |
|
|
|
{99.08, 101.2} |
|
|
|
}; |
|
|
|
for (Map<String, Object> postion : positionList) { |
|
|
|
//范围左上角 x1,y1 |
|
|
|
Double[] upperLeft = {(Double) postion.get("x1"), (Double) postion.get("y1")}; |
|
|
|
//范围右下角 x2,y2 |
|
|
|
Double[] lowerRight = {(Double) postion.get("x2"), (Double) postion.get("y2")}; |
|
|
|
//index 第几个玻片 |
|
|
|
int index = (int) postion.get("index"); |
|
|
|
//1.获取玻片的位置 |
|
|
|
Double[] slide = slideArr[index]; |
|
|
|
//2.玻片范围的实际位置 |
|
|
|
Double slideCompleteUCSX = slide[0] + upperLeft[0]; |
|
|
|
Double slideCompleteUCSY = slide[1] + upperLeft[1]; |
|
|
|
//3.算出路径坐标list |
|
|
|
//定义边界 |
|
|
|
// 托盘点位 x y z |
|
|
|
double left = slideCompleteUCSX + upperLeft[0]; |
|
|
|
double right = slideCompleteUCSX + lowerRight[0]; |
|
|
|
double top = slideCompleteUCSY + upperLeft[1]; |
|
|
|
double bottom = slideCompleteUCSY + lowerRight[1]; |
|
|
|
//移动xy到slide(玻片)的位置 |
|
|
|
if (moveX(emitter, slide[0], frontCmdId, frontCmdName)) return; |
|
|
|
if (moveY(emitter, slide[1], frontCmdId, frontCmdName)) return; |
|
|
|
|
|
|
|
if ("horizontal".equals(matrixPathType)) { //生成路径(从“左上角”往下的水平之字形) String matrixPathType = (String) param.get("matrix_path_type");//喷涂路径类型 horizontal | vertical | grid |
|
|
|
for (int i = 0; i < times; i++) { |
|
|
|
double topReal = top; |
|
|
|
double bottomReal = bottom; |
|
|
|
if (i % 2 == 0) {//双数喷涂 |
|
|
|
double halfSpacing = (double) spacing / 2; |
|
|
|
topReal = top - halfSpacing; |
|
|
|
bottomReal = bottom + halfSpacing; |
|
|
|
} |
|
|
|
List<PathGenerator.Points> pathList = PathGenerator.generatePathPoints( |
|
|
|
left, right, topReal, bottomReal, |
|
|
|
spacing, |
|
|
|
PathGenerator.MoveMode.HORIZONTAL_ZIGZAG_TOP_DOWN |
|
|
|
); |
|
|
|
if (pathSpray(emitter, frontCmdId, frontCmdName, volume, pathList, movingSpeed)) return;//路径喷涂 |
|
|
|
} |
|
|
|
} else if ("vertical".equals(matrixPathType)) { |
|
|
|
for (int i = 0; i < times; i++) { |
|
|
|
double leftReal = left; |
|
|
|
double rightReal = right; |
|
|
|
if (i % 2 == 0) {//双数喷涂 |
|
|
|
double halfSpacing = (double) spacing / 2; |
|
|
|
leftReal = top - halfSpacing; |
|
|
|
rightReal = bottom + halfSpacing; |
|
|
|
} |
|
|
|
List<PathGenerator.Points> pathList = PathGenerator.generatePathPoints( |
|
|
|
leftReal, rightReal, top, bottom, |
|
|
|
spacing, |
|
|
|
PathGenerator.MoveMode.VERTICAL_ZIGZAG_LEFT_RIGHT |
|
|
|
); |
|
|
|
if (pathSpray(emitter, frontCmdId, frontCmdName, volume, pathList, movingSpeed)) return;//路径喷涂 |
|
|
|
} |
|
|
|
} else if ("grid".equals(matrixPathType)) {//横竖喷2次 |
|
|
|
for (int i = 0; i < times; i++) { |
|
|
|
double leftReal = left; |
|
|
|
double rightReal = right; |
|
|
|
double topReal = top; |
|
|
|
double bottomReal = bottom; |
|
|
|
if (i % 2 == 0) {//双数喷涂 |
|
|
|
double halfSpacing = (double) spacing / 2; |
|
|
|
leftReal = top - halfSpacing; |
|
|
|
rightReal = bottom + halfSpacing; |
|
|
|
topReal = top - halfSpacing; |
|
|
|
bottomReal = bottom + halfSpacing; |
|
|
|
} |
|
|
|
List<PathGenerator.Points> pathList = PathGenerator.generatePathPoints( |
|
|
|
leftReal, rightReal, topReal, bottomReal, |
|
|
|
spacing, |
|
|
|
PathGenerator.MoveMode.VERTICAL_ZIGZAG_LEFT_RIGHT |
|
|
|
); |
|
|
|
if (pathSpray(emitter, frontCmdId, frontCmdName, volume, pathList, movingSpeed)) return;//路径喷涂 |
|
|
|
pathList = PathGenerator.generatePathPoints( |
|
|
|
leftReal, rightReal, topReal, bottomReal, |
|
|
|
spacing, |
|
|
|
PathGenerator.MoveMode.HORIZONTAL_ZIGZAG_TOP_DOWN |
|
|
|
); |
|
|
|
if (pathSpray(emitter, frontCmdId, frontCmdName, volume, pathList, movingSpeed)) return;//路径喷涂 |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
//10.关高压电 |
|
|
|
if (highVoltageClose(emitter, frontCmdId, frontCmdName)) return; |
|
|
|
//11.回到原点 motorMoveToHome 先 z |
|
|
|
latch = new CountDownLatch(1); |
|
|
|
deviceMessageHandler.setLatch(latch); |
|
|
|
// z轴回原点 |
|
|
|
if (originZ(emitter, frontCmdId, frontCmdName)) return; |
|
|
|
latch.await();//等待z轴回到原点 |
|
|
|
latch = new CountDownLatch(2); |
|
|
|
deviceMessageHandler.setLatch(latch); |
|
|
|
// x轴回原点 |
|
|
|
if (originX(emitter, frontCmdId, frontCmdName)) return; |
|
|
|
|
|
|
|
// y轴回原点 |
|
|
|
if (originY(emitter, frontCmdId, frontCmdName)) return; |
|
|
|
latch.await();//等待x与y轴回到原点 |
|
|
|
//12.结束日志 |
|
|
|
//TODO写日志 |
|
|
|
emitter.complete(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private boolean motorSpeedSet(ResponseBodyEmitter emitter, Integer 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 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 true; |
|
|
|
} |
|
|
|
|
|
|
|
if (highVoltageCloseResult.getJSONObject("error") != null) { |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "关闭高压电指令返回错误", highVoltageCloseResult), MediaType.APPLICATION_JSON); |
|
|
|
emitter.complete(); |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
Boolean highVoltageCloseStatus = highVoltageCloseResult.getBool("result"); |
|
|
|
if (!highVoltageCloseStatus) { |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "关闭高压电指令执行失败", highVoltageCloseResult), MediaType.APPLICATION_JSON); |
|
|
|
emitter.complete(); |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RESULT, "关闭高压电指令反馈", highVoltageCloseResult), MediaType.APPLICATION_JSON); |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
private boolean pathSpray(ResponseBodyEmitter emitter, String frontCmdId, String frontCmdName, Integer volume, List<PathGenerator.Points> pathList, Integer movingSpeed) throws IOException, InterruptedException { |
|
|
|
CountDownLatch latch; |
|
|
|
//1.开启喷嘴阀 |
|
|
|
if (nozzleValveOpen(emitter, frontCmdId, frontCmdName)) return true; |
|
|
|
//2.推注射泵 |
|
|
|
if (syringePumpInjectionVolumeSet(emitter, frontCmdId, frontCmdName, volume)) return true; |
|
|
|
//3 喷针移动目标位置 |
|
|
|
for (PathGenerator.Points p : pathList) { |
|
|
|
latch = new CountDownLatch(2); |
|
|
|
deviceMessageHandler.setLatch(latch); |
|
|
|
//移动x与y到点位 |
|
|
|
if (moveX(emitter, p.getX(), frontCmdId, frontCmdName)) return true; |
|
|
|
if (moveY(emitter, p.getY(), frontCmdId, frontCmdName)) return true; |
|
|
|
latch.await();//等待移动完毕 |
|
|
|
} |
|
|
|
//5. 停止注射泵 |
|
|
|
if (syringePumpStop(emitter, frontCmdId, frontCmdName)) return true; |
|
|
|
//6.关闭喷嘴阀 |
|
|
|
if (nozzleValveClose(emitter, frontCmdId, frontCmdName)) return true; |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
private boolean nozzleValveClose(ResponseBodyEmitter emitter, String frontCmdId, String frontCmdName) throws IOException { |
|
|
|
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 true; |
|
|
|
} |
|
|
|
if (nozzleValveCloseCMDToDeviceResult.getJSONObject("error") != null) { |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "关闭喷嘴阀指令返回错误", nozzleValveCloseCMDToDeviceResult), MediaType.APPLICATION_JSON); |
|
|
|
emitter.complete(); |
|
|
|
return true; |
|
|
|
} |
|
|
|
Boolean nozzleValveCloseCMDToDeviceResultStatus = nozzleValveCloseCMDToDeviceResult.getBool("result"); |
|
|
|
if (!nozzleValveCloseCMDToDeviceResultStatus) { |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "关闭喷嘴阀指令执行失败", nozzleValveCloseCMDToDeviceResult), MediaType.APPLICATION_JSON); |
|
|
|
emitter.complete(); |
|
|
|
return true; |
|
|
|
} |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RESULT, "关闭喷嘴阀指令反馈", nozzleValveCloseCMDToDeviceResult), MediaType.APPLICATION_JSON); |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
private boolean syringePumpStop(ResponseBodyEmitter emitter, String frontCmdId, String frontCmdName) throws IOException { |
|
|
|
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 true; |
|
|
|
} |
|
|
|
if (syringePumpStopCMDToDeviceResult.getJSONObject("error") != null) { |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "停止推动注射泵指令返回错误", syringePumpStopCMDToDeviceResult), MediaType.APPLICATION_JSON); |
|
|
|
emitter.complete(); |
|
|
|
return true; |
|
|
|
} |
|
|
|
Boolean syringePumpStopCMDToDeviceResultStatus = syringePumpStopCMDToDeviceResult.getBool("result"); |
|
|
|
if (!syringePumpStopCMDToDeviceResultStatus) { |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "停止推动注射泵指令执行失败", syringePumpStopCMDToDeviceResult), MediaType.APPLICATION_JSON); |
|
|
|
emitter.complete(); |
|
|
|
return true; |
|
|
|
} |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RESULT, "停止推动注射泵指令反馈", syringePumpStopCMDToDeviceResult), MediaType.APPLICATION_JSON); |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
private static boolean validate(ResponseBodyEmitter emitter, String matrixPathType, String frontCmdId, String frontCmdName, Integer motorZHeight, Integer gasPressure, Integer volume, Boolean highVoltage, Integer highVoltageValue, Integer spacing, Integer movingSpeed, Integer times, List<Map<String, Object>> positionList) throws IOException { |
|
|
|
if (matrixPathType == null) { |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "参数 matrix_path_type 必填"), MediaType.APPLICATION_JSON); |
|
|
|
emitter.complete(); |
|
|
|
return true; |
|
|
|
} |
|
|
|
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 (spacing == null) { |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "参数 spacing 必填"), 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 (times == null) { |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "参数 times 必填"), 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 syringePumpInjectionVolumeSet(ResponseBodyEmitter emitter, String frontCmdId, String frontCmdName, Integer volume) throws IOException { |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "设置注射泵速度,推注射泵"), MediaType.APPLICATION_JSON); |
|
|
|
CMDToDevice syringePumpInjectionVolumeSetCMDToDevice = DeviceCommandGenerator.syringe_pump_injection_volume_set(volume);//推动移动注射泵 |
|
|
|
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 true; |
|
|
|
} |
|
|
|
if (syringePumpInjectionVolumeSetCMDToDeviceResult.getJSONObject("error") != null) { |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "推动移动注射泵指令返回错误", syringePumpInjectionVolumeSetCMDToDeviceResult), MediaType.APPLICATION_JSON); |
|
|
|
emitter.complete(); |
|
|
|
return true; |
|
|
|
} |
|
|
|
Boolean syringePumpInjectionVolumeSetCMDToDeviceResultStatus = syringePumpInjectionVolumeSetCMDToDeviceResult.getBool("result"); |
|
|
|
if (!syringePumpInjectionVolumeSetCMDToDeviceResultStatus) { |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "推动移动注射泵指令执行失败", syringePumpInjectionVolumeSetCMDToDeviceResult), MediaType.APPLICATION_JSON); |
|
|
|
emitter.complete(); |
|
|
|
return true; |
|
|
|
} |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RESULT, "推动移动注射泵指令反馈", syringePumpInjectionVolumeSetCMDToDeviceResult), MediaType.APPLICATION_JSON); |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
private boolean nozzleValveOpen(ResponseBodyEmitter emitter, String frontCmdId, String frontCmdName) throws IOException { |
|
|
|
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 true; |
|
|
|
} |
|
|
|
if (nozzleValveOpenCMDToDeviceResult.getJSONObject("error") != null) { |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "开启喷嘴阀指令返回错误", nozzleValveOpenCMDToDeviceResult), MediaType.APPLICATION_JSON); |
|
|
|
emitter.complete(); |
|
|
|
return true; |
|
|
|
} |
|
|
|
Boolean nozzleValveOpenCMDToDeviceResultStatus = nozzleValveOpenCMDToDeviceResult.getBool("result"); |
|
|
|
if (!nozzleValveOpenCMDToDeviceResultStatus) { |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "开启喷嘴阀指令执行失败", nozzleValveOpenCMDToDeviceResult), MediaType.APPLICATION_JSON); |
|
|
|
emitter.complete(); |
|
|
|
return true; |
|
|
|
} |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RESULT, "开启喷嘴阀指令反馈", nozzleValveOpenCMDToDeviceResult), MediaType.APPLICATION_JSON); |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
private boolean originZ(ResponseBodyEmitter emitter, String frontCmdId, String frontCmdName) throws IOException { |
|
|
|
CMDToDevice motorZOriginCMDToDevice = DeviceCommandGenerator.motor_z_origin(); // 生成 z轴回原点指令 |
|
|
|
CommandFuture motorZOriginCMDToDeviceFuture = new CommandFuture(); |
|
|
|
motorZOriginCMDToDeviceFuture.setCmdToDevice(motorZOriginCMDToDevice); |
|
|
|
Integer motorZOriginCmdId = motorZOriginCMDToDevice.getCmdId(); |
|
|
|
CurrentSendCmdMapInstance.getInstance().putCommand(motorZOriginCmdId, motorZOriginCMDToDeviceFuture); // 将指令放入map |
|
|
|
|
|
|
|
deviceClient.sendToJSON(motorZOriginCMDToDevice); // 发送指令给设备 |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "已向设备发送了z轴回原点指令", motorZOriginCMDToDevice), MediaType.APPLICATION_JSON); |
|
|
|
|
|
|
|
motorZOriginCMDToDeviceFuture.waitForContinue(); // 等待设备反馈 |
|
|
|
JSONObject motorZOriginResult = motorZOriginCMDToDeviceFuture.getCallbackResult(); // 获取设备返回结果 |
|
|
|
CurrentSendCmdMapInstance.getInstance().removeCommand(motorZOriginCmdId); // 从map中删除该指令 |
|
|
|
|
|
|
|
if (!motorZOriginCMDToDeviceFuture.isReceived()) { |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "z轴回原点指令响应超时", motorZOriginResult), MediaType.APPLICATION_JSON); |
|
|
|
emitter.complete(); |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
if (motorZOriginResult.getJSONObject("error") != null) { |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "z轴回原点指令返回错误", motorZOriginResult), MediaType.APPLICATION_JSON); |
|
|
|
emitter.complete(); |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 3.获取XYZ轴的当前位置 |
|
|
|
*/ |
|
|
|
MotorX motorX = deviceInstance.getMotorX(); |
|
|
|
MotorY motorY = deviceInstance.getMotorY(); |
|
|
|
MotorZ motorZ = deviceInstance.getMotorZ(); |
|
|
|
Boolean motorZOriginStatus = motorZOriginResult.getBool("result"); |
|
|
|
if (!motorZOriginStatus) { |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "z轴回原点指令执行失败", motorZOriginResult), MediaType.APPLICATION_JSON); |
|
|
|
emitter.complete(); |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RESULT, "z轴回原点指令反馈", motorZOriginResult), MediaType.APPLICATION_JSON); |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "z轴已回到原点", motorZOriginCMDToDevice), MediaType.APPLICATION_JSON); |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
private boolean originX(ResponseBodyEmitter emitter, String frontCmdId, String frontCmdName) throws IOException { |
|
|
|
CMDToDevice motorXOriginCMDToDevice = DeviceCommandGenerator.motor_x_origin(); //x轴回原点指令 |
|
|
|
CommandFuture motorXOriginCMDToDeviceFuture = new CommandFuture(); |
|
|
|
motorXOriginCMDToDeviceFuture.setCmdToDevice(motorXOriginCMDToDevice); |
|
|
|
Integer motorXOriginCmdId = motorXOriginCMDToDevice.getCmdId(); |
|
|
|
CurrentSendCmdMapInstance.getInstance().putCommand(motorXOriginCmdId, motorXOriginCMDToDeviceFuture); // 将指令放入map |
|
|
|
deviceClient.sendToJSON(motorXOriginCMDToDevice); // 发送指令给设备 |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "已向设备发送了x轴回原点指令", motorXOriginCMDToDevice), MediaType.APPLICATION_JSON); |
|
|
|
|
|
|
|
motorXOriginCMDToDeviceFuture.waitForContinue(); // 等待设备反馈 |
|
|
|
JSONObject motorXOriginResult = motorXOriginCMDToDeviceFuture.getCallbackResult(); // 获取设备返回结果 |
|
|
|
CurrentSendCmdMapInstance.getInstance().removeCommand(motorXOriginCmdId); // 从map中删除该指令 |
|
|
|
|
|
|
|
if (!motorXOriginCMDToDeviceFuture.isReceived()) { |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "x轴回原点指令响应超时", motorXOriginResult), MediaType.APPLICATION_JSON); |
|
|
|
emitter.complete(); |
|
|
|
return true; |
|
|
|
} |
|
|
|
if (motorXOriginResult.getJSONObject("error") != null) { |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "x轴回原点指令返回错误", motorXOriginResult), MediaType.APPLICATION_JSON); |
|
|
|
emitter.complete(); |
|
|
|
return true; |
|
|
|
} |
|
|
|
Boolean motorXOriginResultStatus = motorXOriginResult.getBool("result"); |
|
|
|
if (!motorXOriginResultStatus) { |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "x轴回原点指令执行失败", motorXOriginResult), MediaType.APPLICATION_JSON); |
|
|
|
emitter.complete(); |
|
|
|
return true; |
|
|
|
} |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RESULT, "x轴回原点指令反馈", motorXOriginResult), MediaType.APPLICATION_JSON); |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
param.get("position"); |
|
|
|
private boolean originY(ResponseBodyEmitter emitter, String frontCmdId, String frontCmdName) throws IOException { |
|
|
|
CMDToDevice motorYOriginCMDToDevice = DeviceCommandGenerator.motor_y_origin(); //y轴回原点指令 |
|
|
|
CommandFuture motorYOriginCMDToDeviceFuture = new CommandFuture(); |
|
|
|
motorYOriginCMDToDeviceFuture.setCmdToDevice(motorYOriginCMDToDevice); |
|
|
|
Integer motorYOriginCmdId = motorYOriginCMDToDevice.getCmdId(); |
|
|
|
CurrentSendCmdMapInstance.getInstance().putCommand(motorYOriginCmdId, motorYOriginCMDToDeviceFuture); // 将指令放入map |
|
|
|
deviceClient.sendToJSON(motorYOriginCMDToDevice); // 发送指令给设备 |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "已向设备发送了y轴回原点指令", motorYOriginCMDToDevice), MediaType.APPLICATION_JSON); |
|
|
|
|
|
|
|
/** |
|
|
|
* 4.XYZ回原点 |
|
|
|
*/ |
|
|
|
motorYOriginCMDToDeviceFuture.waitForContinue(); // 等待设备反馈 |
|
|
|
JSONObject motorYOriginResult = motorYOriginCMDToDeviceFuture.getCallbackResult(); // 获取设备返回结果 |
|
|
|
CurrentSendCmdMapInstance.getInstance().removeCommand(motorYOriginCmdId); // 从map中删除该指令 |
|
|
|
|
|
|
|
if (!motorYOriginCMDToDeviceFuture.isReceived()) { |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "y轴回原点指令响应超时", motorYOriginResult), MediaType.APPLICATION_JSON); |
|
|
|
emitter.complete(); |
|
|
|
return true; |
|
|
|
} |
|
|
|
if (motorYOriginResult.getJSONObject("error") != null) { |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "y轴回原点指令返回错误", motorYOriginResult), MediaType.APPLICATION_JSON); |
|
|
|
emitter.complete(); |
|
|
|
return true; |
|
|
|
} |
|
|
|
Boolean motorYOriginResultStatus = motorYOriginResult.getBool("result"); |
|
|
|
if (!motorYOriginResultStatus) { |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "y轴回原点指令执行失败", motorYOriginResult), MediaType.APPLICATION_JSON); |
|
|
|
emitter.complete(); |
|
|
|
return true; |
|
|
|
} |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RESULT, "y轴回原点指令反馈", motorYOriginResult), MediaType.APPLICATION_JSON); |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RESULT, "x轴与y轴已回到原点"), MediaType.APPLICATION_JSON); |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 5. |
|
|
|
*/ |
|
|
|
private boolean threeWayValveOpenSyringePipeLine(ResponseBodyEmitter emitter, String frontCmdId, String frontCmdName) throws IOException { |
|
|
|
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 true; |
|
|
|
} |
|
|
|
if (threeWayValveOpenSyringePipelineCMDToDeviceResult.getJSONObject("error") != null) { |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "打开三通阀喷嘴管路指令返回错误", threeWayValveOpenSyringePipelineCMDToDeviceResult), MediaType.APPLICATION_JSON); |
|
|
|
emitter.complete(); |
|
|
|
return true; |
|
|
|
} |
|
|
|
Boolean threeWayValveOpenSyringePipelineCMDToDeviceResultStatus = threeWayValveOpenSyringePipelineCMDToDeviceResult.getBool("result"); |
|
|
|
if (!threeWayValveOpenSyringePipelineCMDToDeviceResultStatus) { |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "打开三通阀喷嘴管路指令执行失败", threeWayValveOpenSyringePipelineCMDToDeviceResult), MediaType.APPLICATION_JSON); |
|
|
|
emitter.complete(); |
|
|
|
return true; |
|
|
|
} |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RESULT, "打开三通阀喷嘴管路指令反馈", threeWayValveOpenSyringePipelineCMDToDeviceResult), MediaType.APPLICATION_JSON); |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
for(int i=0;i<5;i++){ |
|
|
|
private boolean highVoltageOpen(ResponseBodyEmitter emitter, Integer 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; |
|
|
|
} |
|
|
|
|
|
|
|
private boolean moveZ(ResponseBodyEmitter emitter, Double height, String frontCmdId, String frontCmdName) throws IOException { |
|
|
|
CMDToDevice motorZPositionSetDownCmdToDevice = DeviceCommandGenerator.motor_z_position_set(height);//移动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; |
|
|
|
} |
|
|
|
|
|
|
|
//TODO 业务逻辑 |
|
|
|
//1.生成指令 |
|
|
|
//2.发送指令 |
|
|
|
//3.等待设备反馈 |
|
|
|
//4.返回结果 |
|
|
|
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 moveY(ResponseBodyEmitter emitter, Double position, String frontCmdId, String frontCmdName) throws IOException { |
|
|
|
CMDToDevice motorYPositionSetCMDToDevice = DeviceCommandGenerator.motor_y_position_set(position);//移动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 true; |
|
|
|
} |
|
|
|
if (motorYPositionSetCMDToDeviceResult.getJSONObject("error") != null) { |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "移动y轴到指定位置指令返回错误", motorYPositionSetCMDToDeviceResult), MediaType.APPLICATION_JSON); |
|
|
|
emitter.complete(); |
|
|
|
return true; |
|
|
|
} |
|
|
|
Boolean motorYPositionSetCMDToDeviceResultStatus = motorYPositionSetCMDToDeviceResult.getBool("result"); |
|
|
|
if (!motorYPositionSetCMDToDeviceResultStatus) { |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "移动y轴到指定位置指令执行失败", motorYPositionSetCMDToDeviceResult), MediaType.APPLICATION_JSON); |
|
|
|
emitter.complete(); |
|
|
|
return true; |
|
|
|
} |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RESULT, "移动y轴到指定位置指令反馈", motorYPositionSetCMDToDeviceResult), MediaType.APPLICATION_JSON); |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
private boolean moveX(ResponseBodyEmitter emitter, Double position, String frontCmdId, String frontCmdName) throws IOException { |
|
|
|
CMDToDevice motorXPositionSetCmdToDevice = DeviceCommandGenerator.motor_x_position_set(position);//移动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 true; |
|
|
|
} |
|
|
|
if (motorXPositionSetCmdToDeviceResult.getJSONObject("error") != null) { |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "移动x轴到指定位置指令返回错误", motorXPositionSetCmdToDeviceResult), MediaType.APPLICATION_JSON); |
|
|
|
emitter.complete(); |
|
|
|
return true; |
|
|
|
} |
|
|
|
Boolean motorXYZPositionSetCmdToDeviceResultStatus = motorXPositionSetCmdToDeviceResult.getBool("result"); |
|
|
|
if (!motorXYZPositionSetCmdToDeviceResultStatus) { |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "移动x轴到指定位置指令执行失败", motorXPositionSetCmdToDeviceResult), MediaType.APPLICATION_JSON); |
|
|
|
emitter.complete(); |
|
|
|
return true; |
|
|
|
} |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RESULT, "移动x轴到指定位置指令反馈", motorXPositionSetCmdToDeviceResult), MediaType.APPLICATION_JSON); |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
} |