Browse Source

feat:完善业务指令

master
白凤吉 5 months ago
parent
commit
46cb2b1a80
  1. 4
      src/main/java/com/qyft/ms/app/common/generator/PathGenerator.java
  2. 10
      src/main/java/com/qyft/ms/app/handler/impl/MatrixSprayChangeParam.java
  3. 328
      src/main/java/com/qyft/ms/app/handler/impl/MatrixSprayContinue.java
  4. 57
      src/main/java/com/qyft/ms/app/handler/impl/MatrixSprayStart.java

4
src/main/java/com/qyft/ms/app/common/generator/PathGenerator.java

@ -205,7 +205,7 @@ public class PathGenerator {
left, right, top, bottom, spacing, MoveMode.HORIZONTAL_ZIGZAG_TOP_DOWN
);
for (Points p : horizontalPath) {
System.out.println(p);
System.out.println(p.x + "," + p.y);
}
// 2) 测试垂直之字形(从左往右)
@ -214,7 +214,7 @@ public class PathGenerator {
left, right, top, bottom, spacing, MoveMode.VERTICAL_ZIGZAG_LEFT_RIGHT
);
for (Points p : verticalPath) {
System.out.println(p);
System.out.println(p.x + "," + p.y);
}
}
}

10
src/main/java/com/qyft/ms/app/handler/impl/MatrixSprayChangeParam.java

@ -59,12 +59,12 @@ public class MatrixSprayChangeParam implements CommandHandler {
Map<String, Object> param = cmdForm.getParam();
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RECEIVE, "后台已收到指令"), MediaType.APPLICATION_JSON);//向前端发送接收到指令
// 1. 参数校验
Double motorZHeight = Optional.ofNullable(param.get("motor_z_height"))
Double motorZHeight = Optional.ofNullable(param.get("motorZHeight"))
.map(Object::toString)
.map(Double::parseDouble)
.orElse(null);
Double gasPressure = Optional.ofNullable(param.get("gas_pressure"))
Double gasPressure = Optional.ofNullable(param.get("gasPressure"))
.map(Object::toString)
.map(Double::parseDouble)
.orElse(null);
@ -74,17 +74,17 @@ public class MatrixSprayChangeParam implements CommandHandler {
.map(Double::parseDouble)
.orElse(null);
Boolean highVoltage = Optional.ofNullable(param.get("high_voltage"))
Boolean highVoltage = Optional.ofNullable(param.get("highVoltage"))
.map(Object::toString)
.map(Boolean::parseBoolean)
.orElse(null);
Double highVoltageValue = Optional.ofNullable(param.get("high_voltage_value"))
Double highVoltageValue = Optional.ofNullable(param.get("highVoltageValue"))
.map(Object::toString)
.map(Double::parseDouble)
.orElse(null);
Double movingSpeed = Optional.ofNullable(param.get("moving_speed"))
Double movingSpeed = Optional.ofNullable(param.get("movingSpeed"))
.map(Object::toString)
.map(Double::parseDouble)
.orElse(null);

328
src/main/java/com/qyft/ms/app/handler/impl/MatrixSprayContinue.java

@ -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;
}
}

57
src/main/java/com/qyft/ms/app/handler/impl/MatrixSprayStart.java

@ -219,8 +219,8 @@ public class MatrixSprayStart implements CommandHandler {
for (int i = 0; i < times; i++) {
double topReal = top;
double bottomReal = bottom;
if (i % 2 == 0) {//双数喷涂
double halfSpacing = (double) spacing / 2;
if (i != 0 && i % 2 == 0) {//双数喷涂
double halfSpacing = spacing / 2;
topReal = top - halfSpacing;
bottomReal = bottom + halfSpacing;
}
@ -230,13 +230,26 @@ public class MatrixSprayStart implements CommandHandler {
PathGenerator.MoveMode.HORIZONTAL_ZIGZAG_TOP_DOWN
);
if (pathSpray(emitter, frontCmdId, frontCmdName, volume, pathList, movingSpeed)) return;//路径喷涂
if (i + 1 != times) { //如果不是最后一次执行完毕后回到玻片原点
log.info("123");
latch = new CountDownLatch(2);
deviceMessageHandler.setLatch(latch);
if (moveX(emitter, slide[0], frontCmdId, frontCmdName)) return;
if (moveY(emitter, slide[1], frontCmdId, frontCmdName)) return;
finished = latch.await(10, TimeUnit.SECONDS);
if (!finished) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "等待指令执行完成超时"), MediaType.APPLICATION_JSON);
emitter.complete();
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;
if (i != 0 && i % 2 == 0) {//双数喷涂
double halfSpacing = spacing / 2;
leftReal = top - halfSpacing;
rightReal = bottom + halfSpacing;
}
@ -246,6 +259,19 @@ public class MatrixSprayStart implements CommandHandler {
PathGenerator.MoveMode.VERTICAL_ZIGZAG_LEFT_RIGHT
);
if (pathSpray(emitter, frontCmdId, frontCmdName, volume, pathList, movingSpeed)) return;//路径喷涂
if (i + 1 != times) { //如果不是最后一次执行完毕后回到玻片原点
log.info("123");
latch = new CountDownLatch(2);
deviceMessageHandler.setLatch(latch);
if (moveX(emitter, slide[0], frontCmdId, frontCmdName)) return;
if (moveY(emitter, slide[1], frontCmdId, frontCmdName)) return;
finished = latch.await(10, TimeUnit.SECONDS);
if (!finished) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "等待指令执行完成超时"), MediaType.APPLICATION_JSON);
emitter.complete();
return;
}
}
}
} else if ("grid".equals(matrixPathType)) {//横竖喷2次
for (int i = 0; i < times; i++) {
@ -253,8 +279,8 @@ public class MatrixSprayStart implements CommandHandler {
double rightReal = right;
double topReal = top;
double bottomReal = bottom;
if (i % 2 == 0) {//双数喷涂
double halfSpacing = (double) spacing / 2;
if (i != 0 && i % 2 == 0) {//双数喷涂
double halfSpacing = spacing / 2;
leftReal = top - halfSpacing;
rightReal = bottom + halfSpacing;
topReal = top - halfSpacing;
@ -271,11 +297,24 @@ public class MatrixSprayStart implements CommandHandler {
spacing,
PathGenerator.MoveMode.HORIZONTAL_ZIGZAG_TOP_DOWN
);
if (pathSpray(emitter, frontCmdId, frontCmdName, volume, pathList, movingSpeed)) return;//路径喷涂
// if (pathSpray(emitter, frontCmdId, frontCmdName, volume, pathList, movingSpeed)) return;//路径喷涂
if (i + 1 != times) { //如果不是最后一次执行完毕后回到玻片原点
log.info("123");
// latch = new CountDownLatch(2);
// deviceMessageHandler.setLatch(latch);
// if (moveX(emitter, slide[0], frontCmdId, frontCmdName)) return;
// if (moveY(emitter, slide[1], frontCmdId, frontCmdName)) return;
// finished = latch.await(10, TimeUnit.SECONDS);
// if (!finished) {
// emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "等待指令执行完成超时"), MediaType.APPLICATION_JSON);
// emitter.complete();
// return;
// }
}
}
}
}
//10.关高压电
/* //10.关高压电
if (highVoltageClose(emitter, frontCmdId, frontCmdName)) return;
//11.回到原点 motorMoveToHome z
latch = new CountDownLatch(1);
@ -302,7 +341,7 @@ public class MatrixSprayStart implements CommandHandler {
return;
}
//12.结束日志
//TODO写日志
//TODO写日志*/
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "指令执行完毕"), MediaType.APPLICATION_JSON);
emitter.complete();
}

Loading…
Cancel
Save