Browse Source

增加了调试指令

master
仁冬 5 months ago
parent
commit
c998f526bf
  1. 71
      src/main/java/com/qyft/ms/app/handler/debugimpl/DehumidifierValveClose.java
  2. 69
      src/main/java/com/qyft/ms/app/handler/debugimpl/DehumidifierValveOpen.java
  3. 94
      src/main/java/com/qyft/ms/app/handler/debugimpl/HighVoltageClose.java
  4. 94
      src/main/java/com/qyft/ms/app/handler/debugimpl/HighVoltageOpen.java
  5. 85
      src/main/java/com/qyft/ms/app/handler/debugimpl/LaserControlClose.java
  6. 94
      src/main/java/com/qyft/ms/app/handler/debugimpl/LaserControlOpen.java
  7. 83
      src/main/java/com/qyft/ms/app/handler/debugimpl/LightingPanelClose.java
  8. 79
      src/main/java/com/qyft/ms/app/handler/debugimpl/LightingPanelOpen.java
  9. 167
      src/main/java/com/qyft/ms/app/handler/debugimpl/MotorXMove.java
  10. 85
      src/main/java/com/qyft/ms/app/handler/debugimpl/MotorXOrigin.java
  11. 85
      src/main/java/com/qyft/ms/app/handler/debugimpl/MotorXStop.java
  12. 85
      src/main/java/com/qyft/ms/app/handler/debugimpl/MotorXYZPositionGet.java
  13. 167
      src/main/java/com/qyft/ms/app/handler/debugimpl/MotorYMove.java
  14. 87
      src/main/java/com/qyft/ms/app/handler/debugimpl/MotorYOrigin.java
  15. 85
      src/main/java/com/qyft/ms/app/handler/debugimpl/MotorYStop.java
  16. 167
      src/main/java/com/qyft/ms/app/handler/debugimpl/MotorZMove.java
  17. 85
      src/main/java/com/qyft/ms/app/handler/debugimpl/MotorZOrigin.java
  18. 85
      src/main/java/com/qyft/ms/app/handler/debugimpl/MotorZStop.java
  19. 74
      src/main/java/com/qyft/ms/app/handler/debugimpl/NozzleValveClose.java
  20. 79
      src/main/java/com/qyft/ms/app/handler/debugimpl/NozzleValveOpen.java
  21. 87
      src/main/java/com/qyft/ms/app/handler/debugimpl/WashValveClose.java
  22. 88
      src/main/java/com/qyft/ms/app/handler/debugimpl/WashValveOpen.java

71
src/main/java/com/qyft/ms/app/handler/debugimpl/DehumidifierValveClose.java

@ -0,0 +1,71 @@
package com.qyft.ms.app.handler.debugimpl;
import cn.hutool.json.JSONObject;
import com.qyft.ms.app.common.annotation.CommandMapping;
import com.qyft.ms.app.common.command.CommandFuture;
import com.qyft.ms.app.common.command.CurrentSendCmdMapInstance;
import com.qyft.ms.app.common.command.DeviceCommandGenerator;
import com.qyft.ms.app.common.command.FrontCommandAck;
import com.qyft.ms.app.common.constant.CommandStatus;
import com.qyft.ms.app.handler.CommandHandler;
import com.qyft.ms.app.model.bo.CMDToDevice;
import com.qyft.ms.app.model.form.CMDFormV2;
import com.qyft.ms.device.client.TcpClient;
import lombok.RequiredArgsConstructor;
import 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;
/**
* z轴回原点
*/
@Slf4j
@Component
@RequiredArgsConstructor
@Async("asyncExecutor")
@CommandMapping("dehumidifier_valve_close")//业务指令注解
public class DehumidifierValveClose implements CommandHandler {
private final TcpClient deviceClient;
@Override
public void handle(CMDFormV2 cmdForm, ResponseBodyEmitter emitter) throws Exception {
String frontCmdId = cmdForm.getCmdId();
String frontCmdName = cmdForm.getCmdName();
//向前端发送接收到指令
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RECEIVE, "后台已收到指令"), MediaType.APPLICATION_JSON);
CMDToDevice cmdToDevice = DeviceCommandGenerator.dehumidifier_valve_close();// 关闭除湿阀
CommandFuture cmdToDeviceFuture = new CommandFuture();
cmdToDeviceFuture.setCmdToDevice(cmdToDevice);
Integer cmdId = cmdToDevice.getCmdId();
CurrentSendCmdMapInstance.getInstance().putCommand(cmdId, cmdToDeviceFuture);
deviceClient.sendToJSON(cmdToDevice);
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "已向设备发送了关闭除湿阀指令", cmdToDevice), MediaType.APPLICATION_JSON);
cmdToDeviceFuture.waitForContinue();
JSONObject deviceResult = cmdToDeviceFuture.getCallbackResult();
CurrentSendCmdMapInstance.getInstance().removeCommand(cmdId);
if (!cmdToDeviceFuture.isReceived()) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "关闭除湿阀指令响应超时", deviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
return;
}
if (deviceResult.getJSONObject("error") != null) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "关闭除湿阀指令返回错误", deviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
return;
}
Boolean cmdStatus = deviceResult.getBool("result");
if (!cmdStatus) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "关闭除湿阀指令执行失败", deviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
return;
}
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RESULT, "关闭除湿阀指令反馈", deviceResult), MediaType.APPLICATION_JSON);
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "指令执行完毕"), MediaType.APPLICATION_JSON);
emitter.complete();
}
}

69
src/main/java/com/qyft/ms/app/handler/debugimpl/DehumidifierValveOpen.java

@ -0,0 +1,69 @@
package com.qyft.ms.app.handler.debugimpl;
import cn.hutool.json.JSONObject;
import com.qyft.ms.app.common.annotation.CommandMapping;
import com.qyft.ms.app.common.command.CommandFuture;
import com.qyft.ms.app.common.command.CurrentSendCmdMapInstance;
import com.qyft.ms.app.common.command.DeviceCommandGenerator;
import com.qyft.ms.app.common.command.FrontCommandAck;
import com.qyft.ms.app.common.constant.CommandStatus;
import com.qyft.ms.app.handler.CommandHandler;
import com.qyft.ms.app.model.bo.CMDToDevice;
import com.qyft.ms.app.model.form.CMDFormV2;
import com.qyft.ms.device.client.TcpClient;
import lombok.RequiredArgsConstructor;
import 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;
/**
* z轴回原点
*/
@Slf4j
@Component
@RequiredArgsConstructor
@Async("asyncExecutor")
@CommandMapping("dehumidifier_valve_open")//业务指令注解
public class DehumidifierValveOpen implements CommandHandler {
private final TcpClient deviceClient;
@Override
public void handle(CMDFormV2 cmdForm, ResponseBodyEmitter emitter) throws Exception {
String frontCmdId = cmdForm.getCmdId();
String frontCmdName = cmdForm.getCmdName();
//向前端发送接收到指令
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RECEIVE, "后台已收到指令"), MediaType.APPLICATION_JSON);
CMDToDevice cmdToDevice = DeviceCommandGenerator.dehumidifier_valve_open(); // 生成开启除湿阀指令
CommandFuture cmdToDeviceFuture = new CommandFuture();
cmdToDeviceFuture.setCmdToDevice(cmdToDevice);
Integer dehumidifierValveCmdId = cmdToDevice.getCmdId();
CurrentSendCmdMapInstance.getInstance().putCommand(dehumidifierValveCmdId, cmdToDeviceFuture);
deviceClient.sendToJSON(cmdToDevice);
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "已向设备发送了开启除湿阀指令", cmdToDeviceFuture), MediaType.APPLICATION_JSON);
cmdToDeviceFuture.waitForContinue();
JSONObject dehumidifierValveResult = cmdToDeviceFuture.getCallbackResult();
CurrentSendCmdMapInstance.getInstance().removeCommand(dehumidifierValveCmdId);
if (!cmdToDeviceFuture.isReceived()) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "开启除湿阀指令响应超时", dehumidifierValveResult), MediaType.APPLICATION_JSON);
emitter.complete();
return;
}
if (dehumidifierValveResult.getJSONObject("error") != null) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "开启除湿阀指令返回错误", dehumidifierValveResult), MediaType.APPLICATION_JSON);
emitter.complete();
return;
}
Boolean dehumidifierValveStatus = dehumidifierValveResult.getBool("result");
if (!dehumidifierValveStatus) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "开启除湿阀指令执行失败", dehumidifierValveResult), MediaType.APPLICATION_JSON);
emitter.complete();
return;
}
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RESULT, "开启除湿阀指令反馈", dehumidifierValveResult), MediaType.APPLICATION_JSON);
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "指令执行完毕"), MediaType.APPLICATION_JSON);
emitter.complete();
}
}

94
src/main/java/com/qyft/ms/app/handler/debugimpl/HighVoltageClose.java

@ -0,0 +1,94 @@
package com.qyft.ms.app.handler.debugimpl;
import cn.hutool.json.JSONObject;
import com.qyft.ms.app.common.annotation.CommandMapping;
import com.qyft.ms.app.common.command.CommandFuture;
import com.qyft.ms.app.common.command.CurrentSendCmdMapInstance;
import com.qyft.ms.app.common.command.DeviceCommandGenerator;
import com.qyft.ms.app.common.command.FrontCommandAck;
import com.qyft.ms.app.common.constant.CommandStatus;
import com.qyft.ms.app.handler.CommandHandler;
import com.qyft.ms.app.model.bo.CMDToDevice;
import com.qyft.ms.app.model.form.CMDFormV2;
import com.qyft.ms.device.client.TcpClient;
import lombok.RequiredArgsConstructor;
import 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.util.Map;
/**
* z轴回原点
*/
@Slf4j
@Component
@RequiredArgsConstructor
@Async("asyncExecutor")
@CommandMapping("high_voltage_close")//业务指令注解
public class HighVoltageClose implements CommandHandler {
private final TcpClient deviceClient;
@Override
public void handle(CMDFormV2 cmdForm, ResponseBodyEmitter emitter) throws Exception {
String frontCmdId = cmdForm.getCmdId();
String frontCmdName = cmdForm.getCmdName();
Map<String, Object> param = cmdForm.getParam();
Integer power = (Integer) param.get("power");
/**
* 1.向前端发送接收到指令
*/
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RECEIVE, "后台已收到指令"), MediaType.APPLICATION_JSON);
/**
* TODO 2.判断指令是否合法
*/
/**
* 3.生成指令并发送指令
*/
CMDToDevice high_voltage_close_CMDToDevice = DeviceCommandGenerator.high_voltage_close();//关闭喷嘴阀
CommandFuture high_voltage_close_CMDToDeviceFuture = new CommandFuture();
high_voltage_close_CMDToDeviceFuture.setCmdToDevice(high_voltage_close_CMDToDevice);
Integer nozzleValveCloseCMDToDeviceCmdId = high_voltage_close_CMDToDevice.getCmdId();
CurrentSendCmdMapInstance.getInstance().putCommand(nozzleValveCloseCMDToDeviceCmdId, high_voltage_close_CMDToDeviceFuture); // 将指令放入map
deviceClient.sendToJSON(high_voltage_close_CMDToDevice); // 发送指令给设备
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "已向设备发送了关闭高压指令", high_voltage_close_CMDToDeviceFuture), MediaType.APPLICATION_JSON);
/**
* 4.等待
*/
high_voltage_close_CMDToDeviceFuture.waitForContinue(); // 等待设备的反馈
/**
* 5.处理结果
*/
JSONObject laser_control_open_CMDToDeviceResult = high_voltage_close_CMDToDeviceFuture.getCallbackResult(); // 拿到设备返回结果
CurrentSendCmdMapInstance.getInstance().removeCommand(nozzleValveCloseCMDToDeviceCmdId); // 从map中删除该指令
if (!high_voltage_close_CMDToDeviceFuture.isReceived()) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "关闭高压指令响应超时", laser_control_open_CMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
}
if (laser_control_open_CMDToDeviceResult.getJSONObject("error") != null) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "关闭高压指令返回错误", laser_control_open_CMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
}
Boolean nozzleValveCloseCMDToDeviceResultStatus = laser_control_open_CMDToDeviceResult.getBool("result");
if (!nozzleValveCloseCMDToDeviceResultStatus) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "关闭高压指令执行失败", laser_control_open_CMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
}
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RESULT, "关闭高压指令指令反馈", laser_control_open_CMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
}
}

94
src/main/java/com/qyft/ms/app/handler/debugimpl/HighVoltageOpen.java

@ -0,0 +1,94 @@
package com.qyft.ms.app.handler.debugimpl;
import cn.hutool.json.JSONObject;
import com.qyft.ms.app.common.annotation.CommandMapping;
import com.qyft.ms.app.common.command.CommandFuture;
import com.qyft.ms.app.common.command.CurrentSendCmdMapInstance;
import com.qyft.ms.app.common.command.DeviceCommandGenerator;
import com.qyft.ms.app.common.command.FrontCommandAck;
import com.qyft.ms.app.common.constant.CommandStatus;
import com.qyft.ms.app.handler.CommandHandler;
import com.qyft.ms.app.model.bo.CMDToDevice;
import com.qyft.ms.app.model.form.CMDFormV2;
import com.qyft.ms.device.client.TcpClient;
import lombok.RequiredArgsConstructor;
import 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.util.Map;
/**
* z轴回原点
*/
@Slf4j
@Component
@RequiredArgsConstructor
@Async("asyncExecutor")
@CommandMapping("high_voltage_open")//业务指令注解
public class HighVoltageOpen implements CommandHandler {
private final TcpClient deviceClient;
@Override
public void handle(CMDFormV2 cmdForm, ResponseBodyEmitter emitter) throws Exception {
String frontCmdId = cmdForm.getCmdId();
String frontCmdName = cmdForm.getCmdName();
Map<String, Object> param = cmdForm.getParam();
Integer voltage = (Integer) param.get("voltage");
/**
* 1.向前端发送接收到指令
*/
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RECEIVE, "后台已收到指令"), MediaType.APPLICATION_JSON);
/**
* TODO 2.判断指令是否合法
*/
/**
* 3.生成指令并发送指令
*/
CMDToDevice laser_control_open_CMDToDevice = DeviceCommandGenerator.high_voltage_open(voltage);//关闭喷嘴阀
CommandFuture nozzleValveCloseCMDToDeviceFuture = new CommandFuture();
nozzleValveCloseCMDToDeviceFuture.setCmdToDevice(laser_control_open_CMDToDevice);
Integer nozzleValveCloseCMDToDeviceCmdId = laser_control_open_CMDToDevice.getCmdId();
CurrentSendCmdMapInstance.getInstance().putCommand(nozzleValveCloseCMDToDeviceCmdId, nozzleValveCloseCMDToDeviceFuture); // 将指令放入map
deviceClient.sendToJSON(laser_control_open_CMDToDevice); // 发送指令给设备
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "已向设备发送了打开高压指令", laser_control_open_CMDToDevice), MediaType.APPLICATION_JSON);
/**
* 4.等待
*/
nozzleValveCloseCMDToDeviceFuture.waitForContinue(); // 等待设备的反馈
/**
* 5.处理结果
*/
JSONObject laser_control_open_CMDToDeviceResult = nozzleValveCloseCMDToDeviceFuture.getCallbackResult(); // 拿到设备返回结果
CurrentSendCmdMapInstance.getInstance().removeCommand(nozzleValveCloseCMDToDeviceCmdId); // 从map中删除该指令
if (!nozzleValveCloseCMDToDeviceFuture.isReceived()) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "打开高压指令响应超时", laser_control_open_CMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
}
if (laser_control_open_CMDToDeviceResult.getJSONObject("error") != null) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "打开高压指令返回错误", laser_control_open_CMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
}
Boolean nozzleValveCloseCMDToDeviceResultStatus = laser_control_open_CMDToDeviceResult.getBool("result");
if (!nozzleValveCloseCMDToDeviceResultStatus) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "打开高压指令执行失败", laser_control_open_CMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
}
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RESULT, "打开高压指令指令反馈", laser_control_open_CMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
}
}

85
src/main/java/com/qyft/ms/app/handler/debugimpl/LaserControlClose.java

@ -0,0 +1,85 @@
package com.qyft.ms.app.handler.debugimpl;
import cn.hutool.json.JSONObject;
import com.qyft.ms.app.common.annotation.CommandMapping;
import com.qyft.ms.app.common.command.CommandFuture;
import com.qyft.ms.app.common.command.CurrentSendCmdMapInstance;
import com.qyft.ms.app.common.command.DeviceCommandGenerator;
import com.qyft.ms.app.common.command.FrontCommandAck;
import com.qyft.ms.app.common.constant.CommandStatus;
import com.qyft.ms.app.handler.CommandHandler;
import com.qyft.ms.app.model.bo.CMDToDevice;
import com.qyft.ms.app.model.form.CMDFormV2;
import com.qyft.ms.device.client.TcpClient;
import lombok.RequiredArgsConstructor;
import 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.util.Map;
/**
* z轴回原点
*/
@Slf4j
@Component
@RequiredArgsConstructor
@Async("asyncExecutor")
@CommandMapping("laser_control_close")//业务指令注解
public class LaserControlClose implements CommandHandler {
private final TcpClient deviceClient;
@Override
public void handle(CMDFormV2 cmdForm, ResponseBodyEmitter emitter) throws Exception {
String frontCmdId = cmdForm.getCmdId();
String frontCmdName = cmdForm.getCmdName();
/**
* 1.向前端发送接收到指令
*/
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RECEIVE, "后台已收到指令"), MediaType.APPLICATION_JSON);
/**
* 2.生成指令并发送指令
*/
CMDToDevice laser_control_close_CMDToDevice = DeviceCommandGenerator.high_voltage_close();
CommandFuture laser_control_close_CMDToDeviceFuture = new CommandFuture();
laser_control_close_CMDToDeviceFuture.setCmdToDevice(laser_control_close_CMDToDevice);
Integer nozzleValveCloseCMDToDeviceCmdId = laser_control_close_CMDToDevice.getCmdId();
CurrentSendCmdMapInstance.getInstance().putCommand(nozzleValveCloseCMDToDeviceCmdId, laser_control_close_CMDToDeviceFuture); // 将指令放入map
deviceClient.sendToJSON(laser_control_close_CMDToDevice); // 发送指令给设备
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "已向设备发送了关闭激光指令", laser_control_close_CMDToDevice), MediaType.APPLICATION_JSON);
/**
* 3.等待
*/
laser_control_close_CMDToDeviceFuture.waitForContinue(); // 等待设备的反馈
/**
* 4.处理结果
*/
JSONObject nozzleValveCloseCMDToDeviceResult = laser_control_close_CMDToDeviceFuture.getCallbackResult(); // 拿到设备返回结果
CurrentSendCmdMapInstance.getInstance().removeCommand(nozzleValveCloseCMDToDeviceCmdId); // 从map中删除该指令
if (!laser_control_close_CMDToDeviceFuture.isReceived()) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "关闭激光指令响应超时", nozzleValveCloseCMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
}
if (nozzleValveCloseCMDToDeviceResult.getJSONObject("error") != null) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "关闭激光指令返回错误", nozzleValveCloseCMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
}
Boolean nozzleValveCloseCMDToDeviceResultStatus = nozzleValveCloseCMDToDeviceResult.getBool("result");
if (!nozzleValveCloseCMDToDeviceResultStatus) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "关闭激光指令执行失败", nozzleValveCloseCMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
}
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RESULT, "关闭激光指令指令反馈", nozzleValveCloseCMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
}
}

94
src/main/java/com/qyft/ms/app/handler/debugimpl/LaserControlOpen.java

@ -0,0 +1,94 @@
package com.qyft.ms.app.handler.debugimpl;
import cn.hutool.json.JSONObject;
import com.qyft.ms.app.common.annotation.CommandMapping;
import com.qyft.ms.app.common.command.CommandFuture;
import com.qyft.ms.app.common.command.CurrentSendCmdMapInstance;
import com.qyft.ms.app.common.command.DeviceCommandGenerator;
import com.qyft.ms.app.common.command.FrontCommandAck;
import com.qyft.ms.app.common.constant.CommandStatus;
import com.qyft.ms.app.handler.CommandHandler;
import com.qyft.ms.app.model.bo.CMDToDevice;
import com.qyft.ms.app.model.form.CMDFormV2;
import com.qyft.ms.device.client.TcpClient;
import lombok.RequiredArgsConstructor;
import 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.util.Map;
/**
* z轴回原点
*/
@Slf4j
@Component
@RequiredArgsConstructor
@Async("asyncExecutor")
@CommandMapping("laser_control_open")//业务指令注解
public class LaserControlOpen implements CommandHandler {
private final TcpClient deviceClient;
@Override
public void handle(CMDFormV2 cmdForm, ResponseBodyEmitter emitter) throws Exception {
String frontCmdId = cmdForm.getCmdId();
String frontCmdName = cmdForm.getCmdName();
Map<String, Object> param = cmdForm.getParam();
Integer power = (Integer) param.get("power");
/**
* 1.向前端发送接收到指令
*/
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RECEIVE, "后台已收到指令"), MediaType.APPLICATION_JSON);
/**
* TODO 2.判断指令是否合法
*/
/**
* 3.生成指令并发送指令
*/
CMDToDevice laser_control_open_CMDToDevice = DeviceCommandGenerator.laser_control_open(power);//关闭喷嘴阀
CommandFuture nozzleValveCloseCMDToDeviceFuture = new CommandFuture();
nozzleValveCloseCMDToDeviceFuture.setCmdToDevice(laser_control_open_CMDToDevice);
Integer nozzleValveCloseCMDToDeviceCmdId = laser_control_open_CMDToDevice.getCmdId();
CurrentSendCmdMapInstance.getInstance().putCommand(nozzleValveCloseCMDToDeviceCmdId, nozzleValveCloseCMDToDeviceFuture); // 将指令放入map
deviceClient.sendToJSON(laser_control_open_CMDToDevice); // 发送指令给设备
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "已向设备发送了打开激光指令", laser_control_open_CMDToDevice), MediaType.APPLICATION_JSON);
/**
* 4.等待
*/
nozzleValveCloseCMDToDeviceFuture.waitForContinue(); // 等待设备的反馈
/**
* 5.处理结果
*/
JSONObject laser_control_open_CMDToDeviceResult = nozzleValveCloseCMDToDeviceFuture.getCallbackResult(); // 拿到设备返回结果
CurrentSendCmdMapInstance.getInstance().removeCommand(nozzleValveCloseCMDToDeviceCmdId); // 从map中删除该指令
if (!nozzleValveCloseCMDToDeviceFuture.isReceived()) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "打开激光指令响应超时", laser_control_open_CMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
}
if (laser_control_open_CMDToDeviceResult.getJSONObject("error") != null) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "打开激光指令返回错误", laser_control_open_CMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
}
Boolean nozzleValveCloseCMDToDeviceResultStatus = laser_control_open_CMDToDeviceResult.getBool("result");
if (!nozzleValveCloseCMDToDeviceResultStatus) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "打开激光指令执行失败", laser_control_open_CMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
}
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RESULT, "打开激光指令指令反馈", laser_control_open_CMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
}
}

83
src/main/java/com/qyft/ms/app/handler/debugimpl/LightingPanelClose.java

@ -0,0 +1,83 @@
package com.qyft.ms.app.handler.debugimpl;
import cn.hutool.json.JSONObject;
import com.qyft.ms.app.common.annotation.CommandMapping;
import com.qyft.ms.app.common.command.CommandFuture;
import com.qyft.ms.app.common.command.CurrentSendCmdMapInstance;
import com.qyft.ms.app.common.command.DeviceCommandGenerator;
import com.qyft.ms.app.common.command.FrontCommandAck;
import com.qyft.ms.app.common.constant.CommandStatus;
import com.qyft.ms.app.handler.CommandHandler;
import com.qyft.ms.app.model.bo.CMDToDevice;
import com.qyft.ms.app.model.form.CMDFormV2;
import com.qyft.ms.device.client.TcpClient;
import lombok.RequiredArgsConstructor;
import 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;
/**
* z轴回原点
*/
@Slf4j
@Component
@RequiredArgsConstructor
@Async("asyncExecutor")
@CommandMapping("lighting_panel_close")//业务指令注解
public class LightingPanelClose implements CommandHandler {
private final TcpClient deviceClient;
@Override
public void handle(CMDFormV2 cmdForm, ResponseBodyEmitter emitter) throws Exception {
String frontCmdId = cmdForm.getCmdId();
String frontCmdName = cmdForm.getCmdName();
//向前端发送接收到指令
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RECEIVE, "后台已收到指令"), MediaType.APPLICATION_JSON);
/**
* 1.生成指令并发送指令
*/
CMDToDevice lightingPanelCloseCMDToDevice = DeviceCommandGenerator.lighting_panel_close();//生成指令 开启喷嘴阀
CommandFuture lightingPanelCMDToDeviceFuture = new CommandFuture();
lightingPanelCMDToDeviceFuture.setCmdToDevice(lightingPanelCloseCMDToDevice);
Integer nozzleValveOpenCMDToDeviceCmdId = lightingPanelCloseCMDToDevice.getCmdId();
CurrentSendCmdMapInstance.getInstance().putCommand(nozzleValveOpenCMDToDeviceCmdId, lightingPanelCMDToDeviceFuture); // 将指令放入map
deviceClient.sendToJSON(lightingPanelCloseCMDToDevice); // 发送指令给设备
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "已向设备发送了开启照明灯指令", lightingPanelCloseCMDToDevice), MediaType.APPLICATION_JSON);
/**
* 2.等待
*/
lightingPanelCMDToDeviceFuture.waitForContinue(); // 等待设备的反馈
/**
* 3.处理结果
*/
JSONObject lightingPanelOpenCMDToDeviceResult = lightingPanelCMDToDeviceFuture.getCallbackResult(); // 拿到设备返回结果
CurrentSendCmdMapInstance.getInstance().removeCommand(nozzleValveOpenCMDToDeviceCmdId); // 将指令从map中删除
if (!lightingPanelCMDToDeviceFuture.isReceived()) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "关闭照明灯指令响应超时", lightingPanelOpenCMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
}
if (lightingPanelOpenCMDToDeviceResult.getJSONObject("error") != null) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "关闭照明灯指令返回错误", lightingPanelOpenCMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
}
Boolean nozzleValveOpenCMDToDeviceResultStatus = lightingPanelOpenCMDToDeviceResult.getBool("result");
if (!nozzleValveOpenCMDToDeviceResultStatus) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "关闭照明灯指令执行失败", lightingPanelOpenCMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
}
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RESULT, "关闭照明灯指令反馈", lightingPanelOpenCMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
}
}

79
src/main/java/com/qyft/ms/app/handler/debugimpl/LightingPanelOpen.java

@ -0,0 +1,79 @@
package com.qyft.ms.app.handler.debugimpl;
import cn.hutool.json.JSONObject;
import com.qyft.ms.app.common.annotation.CommandMapping;
import com.qyft.ms.app.common.command.CommandFuture;
import com.qyft.ms.app.common.command.CurrentSendCmdMapInstance;
import com.qyft.ms.app.common.command.DeviceCommandGenerator;
import com.qyft.ms.app.common.command.FrontCommandAck;
import com.qyft.ms.app.common.constant.CommandStatus;
import com.qyft.ms.app.handler.CommandHandler;
import com.qyft.ms.app.model.bo.CMDToDevice;
import com.qyft.ms.app.model.form.CMDFormV2;
import com.qyft.ms.device.client.TcpClient;
import lombok.RequiredArgsConstructor;
import 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;
/**
* z轴回原点
*/
@Slf4j
@Component
@RequiredArgsConstructor
@Async("asyncExecutor")
@CommandMapping("lighting_panel_open")//业务指令注解
public class LightingPanelOpen implements CommandHandler {
private final TcpClient deviceClient;
@Override
public void handle(CMDFormV2 cmdForm, ResponseBodyEmitter emitter) throws Exception {
String frontCmdId = cmdForm.getCmdId();
String frontCmdName = cmdForm.getCmdName();
//向前端发送接收到指令
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RECEIVE, "后台已收到指令"), MediaType.APPLICATION_JSON);
CMDToDevice lightingPanelOpenCMDToDevice = DeviceCommandGenerator.lighting_panel_open();//生成指令 开启喷嘴阀
CommandFuture lightingPanelCMDToDeviceFuture = new CommandFuture();
lightingPanelCMDToDeviceFuture.setCmdToDevice(lightingPanelOpenCMDToDevice);
Integer nozzleValveOpenCMDToDeviceCmdId = lightingPanelOpenCMDToDevice.getCmdId();
CurrentSendCmdMapInstance.getInstance().putCommand(nozzleValveOpenCMDToDeviceCmdId, lightingPanelCMDToDeviceFuture); // 将指令放入map
deviceClient.sendToJSON(lightingPanelOpenCMDToDevice); // 发送指令给设备
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "已向设备发送了开启照明灯指令", lightingPanelOpenCMDToDevice), MediaType.APPLICATION_JSON);
lightingPanelCMDToDeviceFuture.waitForContinue(); // 等待设备的反馈
JSONObject lightingPanelOpenCMDToDeviceResult = lightingPanelCMDToDeviceFuture.getCallbackResult(); // 拿到设备返回结果
CurrentSendCmdMapInstance.getInstance().removeCommand(nozzleValveOpenCMDToDeviceCmdId); // 将指令从map中删除
if (!lightingPanelCMDToDeviceFuture.isReceived()) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "开启照明灯指令响应超时", lightingPanelOpenCMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
}
if (lightingPanelOpenCMDToDeviceResult.getJSONObject("error") != null) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "开启照明灯指令返回错误", lightingPanelOpenCMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
}
Boolean nozzleValveOpenCMDToDeviceResultStatus = lightingPanelOpenCMDToDeviceResult.getBool("result");
if (!nozzleValveOpenCMDToDeviceResultStatus) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "开启照明灯指令执行失败", lightingPanelOpenCMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
}
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RESULT, "开启照明灯指令反馈", lightingPanelOpenCMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
}
}

167
src/main/java/com/qyft/ms/app/handler/debugimpl/MotorXMove.java

@ -0,0 +1,167 @@
package com.qyft.ms.app.handler.debugimpl;
import cn.hutool.json.JSONObject;
import com.qyft.ms.app.common.annotation.CommandMapping;
import com.qyft.ms.app.common.command.CommandFuture;
import com.qyft.ms.app.common.command.CurrentSendCmdMapInstance;
import com.qyft.ms.app.common.command.DeviceCommandGenerator;
import com.qyft.ms.app.common.command.FrontCommandAck;
import com.qyft.ms.app.common.constant.CommandStatus;
import com.qyft.ms.app.handler.CommandHandler;
import com.qyft.ms.app.model.bo.CMDToDevice;
import com.qyft.ms.app.model.form.CMDFormV2;
import com.qyft.ms.device.client.TcpClient;
import lombok.RequiredArgsConstructor;
import 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.util.Map;
/**
* z轴回原点
*/
@Slf4j
@Component
@RequiredArgsConstructor
@Async("asyncExecutor")
@CommandMapping("motor_x_move")//业务指令注解
public class MotorXMove implements CommandHandler {
private final TcpClient deviceClient;
/**
* {
* cmdName:'motor_x_move',
* cmdId:'',
* device:'x',
* action:'move',
* param:{
* current:'',//这四个参数可以不同时存在
* direction:'forward|backward',
* position:'',
* speed:''
* }
* }
* @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();
Double position = (Double) param.get("position");
String direction = (String) param.get("direction");
/**
* 1.向前端发送接收到指令
*/
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RECEIVE, "后台已收到指令"), MediaType.APPLICATION_JSON);
/**
* 2.获取电机X的位置
*/
CMDToDevice cmdToDevice = DeviceCommandGenerator.motor_xyz_position_get();//关闭喷嘴阀
CommandFuture cmdToDeviceFuture = new CommandFuture();
cmdToDeviceFuture.setCmdToDevice(cmdToDevice);
Integer cmdToDeviceCmdId = cmdToDevice.getCmdId();
CurrentSendCmdMapInstance.getInstance().putCommand(cmdToDeviceCmdId, cmdToDeviceFuture); // 将指令放入map
deviceClient.sendToJSON(cmdToDevice); // 发送指令给设备
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "已向设备发送了XYZ获取位置指令", cmdToDevice), MediaType.APPLICATION_JSON);
/**
* 3.等待
*/
cmdToDeviceFuture.waitForContinue(); // 等待设备的反馈
/**
* "{
* ""tag"": ""ack"",
* ""payload"": {
* ""cmdId"": """",
* ""result"": {
* // 双精度浮点型X 轴电机当前位置
* ""xAxisPosition"": 0.0,
* // 双精度浮点型Y 轴电机当前位置
* ""yAxisPosition"": 0.0,
* // 双精度浮点型Z 轴电机当前位置
* ""zAxisPosition"": 0.0,
* }
* }
* }"
*/
/**
* 4.处理电机位置结果
*/
JSONObject resultObject = cmdToDeviceFuture.getCallbackResult(); // 拿到设备返回结果
CurrentSendCmdMapInstance.getInstance().removeCommand(cmdToDeviceCmdId); // 从map中删除该指令
JSONObject cmdToDeviceResult = resultObject.getJSONObject("result");
Double xAxisPosition = cmdToDeviceResult.getDouble("xAxisPosition");
Double finalPosition = 0.0;
if("forward".equals(direction)){
finalPosition+=xAxisPosition+position;
}
if("backward".equals(direction)){
finalPosition-=xAxisPosition-position;
if(finalPosition<0){
finalPosition = 0.0;
}
}
/**
* 5.生成电机移动指令并发送指令
*/
cmdToDevice = DeviceCommandGenerator.motor_x_position_set(finalPosition);//关闭喷嘴阀
cmdToDeviceFuture = new CommandFuture();
cmdToDeviceFuture.setCmdToDevice(cmdToDevice);
Integer nozzleValveCloseCMDToDeviceCmdId = cmdToDevice.getCmdId();
CurrentSendCmdMapInstance.getInstance().putCommand(nozzleValveCloseCMDToDeviceCmdId, cmdToDeviceFuture); // 将指令放入map
deviceClient.sendToJSON(cmdToDevice); // 发送指令给设备
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "已向设备发送了X移动指令", cmdToDevice), MediaType.APPLICATION_JSON);
/**
* 6.等待
*/
cmdToDeviceFuture.waitForContinue(); // 等待设备的反馈
/**
* 7.处理结果
*/
cmdToDeviceResult = cmdToDeviceFuture.getCallbackResult(); // 拿到设备返回结果
CurrentSendCmdMapInstance.getInstance().removeCommand(nozzleValveCloseCMDToDeviceCmdId); // 从map中删除该指令
if (!cmdToDeviceFuture.isReceived()) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "X移动指令响应超时", cmdToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
}
if (cmdToDeviceResult.getJSONObject("error") != null) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "X移动指令返回错误", cmdToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
}
Boolean nozzleValveCloseCMDToDeviceResultStatus = cmdToDeviceResult.getBool("result");
if (!nozzleValveCloseCMDToDeviceResultStatus) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "X移动指令执行失败", cmdToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
}
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RESULT, "X移动指令反馈", cmdToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
}
}

85
src/main/java/com/qyft/ms/app/handler/debugimpl/MotorXOrigin.java

@ -0,0 +1,85 @@
package com.qyft.ms.app.handler.debugimpl;
import cn.hutool.json.JSONObject;
import com.qyft.ms.app.common.annotation.CommandMapping;
import com.qyft.ms.app.common.command.CommandFuture;
import com.qyft.ms.app.common.command.CurrentSendCmdMapInstance;
import com.qyft.ms.app.common.command.DeviceCommandGenerator;
import com.qyft.ms.app.common.command.FrontCommandAck;
import com.qyft.ms.app.common.constant.CommandStatus;
import com.qyft.ms.app.handler.CommandHandler;
import com.qyft.ms.app.model.bo.CMDToDevice;
import com.qyft.ms.app.model.form.CMDFormV2;
import com.qyft.ms.device.client.TcpClient;
import lombok.RequiredArgsConstructor;
import 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;
/**
* z轴回原点
*/
@Slf4j
@Component
@RequiredArgsConstructor
@Async("asyncExecutor")
@CommandMapping("motor_x_origin")//业务指令注解
public class MotorXOrigin implements CommandHandler {
private final TcpClient deviceClient;
@Override
public void handle(CMDFormV2 cmdForm, ResponseBodyEmitter emitter) throws Exception {
String frontCmdId = cmdForm.getCmdId();
String frontCmdName = cmdForm.getCmdName();
/**
* 1.向前端发送接收到指令
*/
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RECEIVE, "后台已收到指令"), MediaType.APPLICATION_JSON);
/**
* 2.生成指令并发送指令
*/
CMDToDevice cmdToDevice = DeviceCommandGenerator.motor_x_origin();//关闭喷嘴阀
CommandFuture cmdToDeviceFuture = new CommandFuture();
cmdToDeviceFuture.setCmdToDevice(cmdToDevice);
Integer nozzleValveCloseCMDToDeviceCmdId = cmdToDevice.getCmdId();
CurrentSendCmdMapInstance.getInstance().putCommand(nozzleValveCloseCMDToDeviceCmdId, cmdToDeviceFuture); // 将指令放入map
deviceClient.sendToJSON(cmdToDevice); // 发送指令给设备
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "已向设备发送了X回原点指令", cmdToDevice), MediaType.APPLICATION_JSON);
/**
* 3.等待
*/
cmdToDeviceFuture.waitForContinue(); // 等待设备的反馈
/**
* 4.处理结果
*/
JSONObject cmdToDeviceResult = cmdToDeviceFuture.getCallbackResult(); // 拿到设备返回结果
CurrentSendCmdMapInstance.getInstance().removeCommand(nozzleValveCloseCMDToDeviceCmdId); // 从map中删除该指令
if (!cmdToDeviceFuture.isReceived()) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "X回原点指令响应超时", cmdToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
}
if (cmdToDeviceResult.getJSONObject("error") != null) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "X回原点指令返回错误", cmdToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
}
Boolean nozzleValveCloseCMDToDeviceResultStatus = cmdToDeviceResult.getBool("result");
if (!nozzleValveCloseCMDToDeviceResultStatus) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "X回原点指令执行失败", cmdToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
}
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RESULT, "X回原点指令指令反馈", cmdToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
}
}

85
src/main/java/com/qyft/ms/app/handler/debugimpl/MotorXStop.java

@ -0,0 +1,85 @@
package com.qyft.ms.app.handler.debugimpl;
import cn.hutool.json.JSONObject;
import com.qyft.ms.app.common.annotation.CommandMapping;
import com.qyft.ms.app.common.command.CommandFuture;
import com.qyft.ms.app.common.command.CurrentSendCmdMapInstance;
import com.qyft.ms.app.common.command.DeviceCommandGenerator;
import com.qyft.ms.app.common.command.FrontCommandAck;
import com.qyft.ms.app.common.constant.CommandStatus;
import com.qyft.ms.app.handler.CommandHandler;
import com.qyft.ms.app.model.bo.CMDToDevice;
import com.qyft.ms.app.model.form.CMDFormV2;
import com.qyft.ms.device.client.TcpClient;
import lombok.RequiredArgsConstructor;
import 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;
/**
* z轴回原点
*/
@Slf4j
@Component
@RequiredArgsConstructor
@Async("asyncExecutor")
@CommandMapping("motor_x_stop")//业务指令注解
public class MotorXStop implements CommandHandler {
private final TcpClient deviceClient;
@Override
public void handle(CMDFormV2 cmdForm, ResponseBodyEmitter emitter) throws Exception {
String frontCmdId = cmdForm.getCmdId();
String frontCmdName = cmdForm.getCmdName();
/**
* 1.向前端发送接收到指令
*/
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RECEIVE, "后台已收到指令"), MediaType.APPLICATION_JSON);
/**
* 2.生成指令并发送指令
*/
CMDToDevice cmdToDevice = DeviceCommandGenerator.motor_x_stop();//关闭喷嘴阀
CommandFuture cmdToDeviceFuture = new CommandFuture();
cmdToDeviceFuture.setCmdToDevice(cmdToDevice);
Integer nozzleValveCloseCMDToDeviceCmdId = cmdToDevice.getCmdId();
CurrentSendCmdMapInstance.getInstance().putCommand(nozzleValveCloseCMDToDeviceCmdId, cmdToDeviceFuture); // 将指令放入map
deviceClient.sendToJSON(cmdToDevice); // 发送指令给设备
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "已向设备发送了X停止指令", cmdToDevice), MediaType.APPLICATION_JSON);
/**
* 3.等待
*/
cmdToDeviceFuture.waitForContinue(); // 等待设备的反馈
/**
* 4.处理结果
*/
JSONObject laser_control_open_CMDToDeviceResult = cmdToDeviceFuture.getCallbackResult(); // 拿到设备返回结果
CurrentSendCmdMapInstance.getInstance().removeCommand(nozzleValveCloseCMDToDeviceCmdId); // 从map中删除该指令
if (!cmdToDeviceFuture.isReceived()) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "X停止指令响应超时", laser_control_open_CMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
}
if (laser_control_open_CMDToDeviceResult.getJSONObject("error") != null) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "X停止指令返回错误", laser_control_open_CMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
}
Boolean nozzleValveCloseCMDToDeviceResultStatus = laser_control_open_CMDToDeviceResult.getBool("result");
if (!nozzleValveCloseCMDToDeviceResultStatus) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "X停止指令执行失败", laser_control_open_CMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
}
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RESULT, "X停止指令指令反馈", laser_control_open_CMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
}
}

85
src/main/java/com/qyft/ms/app/handler/debugimpl/MotorXYZPositionGet.java

@ -0,0 +1,85 @@
package com.qyft.ms.app.handler.debugimpl;
import cn.hutool.json.JSONObject;
import com.qyft.ms.app.common.annotation.CommandMapping;
import com.qyft.ms.app.common.command.CommandFuture;
import com.qyft.ms.app.common.command.CurrentSendCmdMapInstance;
import com.qyft.ms.app.common.command.DeviceCommandGenerator;
import com.qyft.ms.app.common.command.FrontCommandAck;
import com.qyft.ms.app.common.constant.CommandStatus;
import com.qyft.ms.app.handler.CommandHandler;
import com.qyft.ms.app.model.bo.CMDToDevice;
import com.qyft.ms.app.model.form.CMDFormV2;
import com.qyft.ms.device.client.TcpClient;
import lombok.RequiredArgsConstructor;
import 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;
/**
* z轴回原点
*/
@Slf4j
@Component
@RequiredArgsConstructor
@Async("asyncExecutor")
@CommandMapping("motor_xyz_position_get")//业务指令注解
public class MotorXYZPositionGet implements CommandHandler {
private final TcpClient deviceClient;
@Override
public void handle(CMDFormV2 cmdForm, ResponseBodyEmitter emitter) throws Exception {
String frontCmdId = cmdForm.getCmdId();
String frontCmdName = cmdForm.getCmdName();
/**
* 1.向前端发送接收到指令
*/
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RECEIVE, "后台已收到指令"), MediaType.APPLICATION_JSON);
/**
* 2.生成指令并发送指令
*/
CMDToDevice cmdToDevice = DeviceCommandGenerator.motor_xyz_position_get();//关闭喷嘴阀
CommandFuture cmdToDeviceFuture = new CommandFuture();
cmdToDeviceFuture.setCmdToDevice(cmdToDevice);
Integer nozzleValveCloseCMDToDeviceCmdId = cmdToDevice.getCmdId();
CurrentSendCmdMapInstance.getInstance().putCommand(nozzleValveCloseCMDToDeviceCmdId, cmdToDeviceFuture); // 将指令放入map
deviceClient.sendToJSON(cmdToDevice); // 发送指令给设备
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "已向设备发送了XYZ获取位置指令", cmdToDevice), MediaType.APPLICATION_JSON);
/**
* 3.等待
*/
cmdToDeviceFuture.waitForContinue(); // 等待设备的反馈
/**
* 4.处理结果
*/
JSONObject laser_control_open_CMDToDeviceResult = cmdToDeviceFuture.getCallbackResult(); // 拿到设备返回结果
CurrentSendCmdMapInstance.getInstance().removeCommand(nozzleValveCloseCMDToDeviceCmdId); // 从map中删除该指令
if (!cmdToDeviceFuture.isReceived()) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "XYZ获取位置指令响应超时", laser_control_open_CMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
}
if (laser_control_open_CMDToDeviceResult.getJSONObject("error") != null) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "XYZ获取位置指令返回错误", laser_control_open_CMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
}
Boolean cmdToDeviceResultStatus = laser_control_open_CMDToDeviceResult.getBool("result");
if (!cmdToDeviceResultStatus) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "XYZ获取位置指令执行失败", laser_control_open_CMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
}
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RESULT, "XYZ获取位置指令指令反馈", laser_control_open_CMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
}
}

167
src/main/java/com/qyft/ms/app/handler/debugimpl/MotorYMove.java

@ -0,0 +1,167 @@
package com.qyft.ms.app.handler.debugimpl;
import cn.hutool.json.JSONObject;
import com.qyft.ms.app.common.annotation.CommandMapping;
import com.qyft.ms.app.common.command.CommandFuture;
import com.qyft.ms.app.common.command.CurrentSendCmdMapInstance;
import com.qyft.ms.app.common.command.DeviceCommandGenerator;
import com.qyft.ms.app.common.command.FrontCommandAck;
import com.qyft.ms.app.common.constant.CommandStatus;
import com.qyft.ms.app.handler.CommandHandler;
import com.qyft.ms.app.model.bo.CMDToDevice;
import com.qyft.ms.app.model.form.CMDFormV2;
import com.qyft.ms.device.client.TcpClient;
import lombok.RequiredArgsConstructor;
import 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.util.Map;
/**
* z轴回原点
*/
@Slf4j
@Component
@RequiredArgsConstructor
@Async("asyncExecutor")
@CommandMapping("motor_x_move")//业务指令注解
public class MotorYMove implements CommandHandler {
private final TcpClient deviceClient;
/**
* {
* cmdName:'motor_y_move',
* cmdId:'',
* device:'x',
* action:'move',
* param:{
* current:'',//这四个参数可以不同时存在
* direction:'forward|backward',
* position:'',
* speed:''
* }
* }
* @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();
Double position = (Double) param.get("position");
String direction = (String) param.get("direction");
/**
* 1.向前端发送接收到指令
*/
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RECEIVE, "后台已收到指令"), MediaType.APPLICATION_JSON);
/**
* 2.获取电机X的位置
*/
CMDToDevice cmdToDevice = DeviceCommandGenerator.motor_xyz_position_get();//关闭喷嘴阀
CommandFuture cmdToDeviceFuture = new CommandFuture();
cmdToDeviceFuture.setCmdToDevice(cmdToDevice);
Integer cmdToDeviceCmdId = cmdToDevice.getCmdId();
CurrentSendCmdMapInstance.getInstance().putCommand(cmdToDeviceCmdId, cmdToDeviceFuture); // 将指令放入map
deviceClient.sendToJSON(cmdToDevice); // 发送指令给设备
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "已向设备发送了XYZ获取位置指令", cmdToDevice), MediaType.APPLICATION_JSON);
/**
* 3.等待
*/
cmdToDeviceFuture.waitForContinue(); // 等待设备的反馈
/**
* "{
* ""tag"": ""ack"",
* ""payload"": {
* ""cmdId"": """",
* ""result"": {
* // 双精度浮点型X 轴电机当前位置
* ""xAxisPosition"": 0.0,
* // 双精度浮点型Y 轴电机当前位置
* ""yAxisPosition"": 0.0,
* // 双精度浮点型Z 轴电机当前位置
* ""zAxisPosition"": 0.0,
* }
* }
* }"
*/
/**
* 4.处理电机位置结果
*/
JSONObject resultObject = cmdToDeviceFuture.getCallbackResult(); // 拿到设备返回结果
CurrentSendCmdMapInstance.getInstance().removeCommand(cmdToDeviceCmdId); // 从map中删除该指令
JSONObject cmdToDeviceResult = resultObject.getJSONObject("result");
Double yAxisPosition = cmdToDeviceResult.getDouble("yAxisPosition");
Double finalPosition = 0.0;
if("forward".equals(direction)){
finalPosition+=yAxisPosition+position;
}
if("backward".equals(direction)){
finalPosition-=yAxisPosition-position;
if(finalPosition<0){
finalPosition = 0.0;
}
}
/**
* 5.生成电机移动指令并发送指令
*/
cmdToDevice = DeviceCommandGenerator.motor_y_position_set(finalPosition);//关闭喷嘴阀
cmdToDeviceFuture = new CommandFuture();
cmdToDeviceFuture.setCmdToDevice(cmdToDevice);
Integer nozzleValveCloseCMDToDeviceCmdId = cmdToDevice.getCmdId();
CurrentSendCmdMapInstance.getInstance().putCommand(nozzleValveCloseCMDToDeviceCmdId, cmdToDeviceFuture); // 将指令放入map
deviceClient.sendToJSON(cmdToDevice); // 发送指令给设备
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "已向设备发送了Y移动指令", cmdToDevice), MediaType.APPLICATION_JSON);
/**
* 6.等待
*/
cmdToDeviceFuture.waitForContinue(); // 等待设备的反馈
/**
* 7.处理结果
*/
cmdToDeviceResult = cmdToDeviceFuture.getCallbackResult(); // 拿到设备返回结果
CurrentSendCmdMapInstance.getInstance().removeCommand(nozzleValveCloseCMDToDeviceCmdId); // 从map中删除该指令
if (!cmdToDeviceFuture.isReceived()) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "Y移动指令响应超时", cmdToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
}
if (cmdToDeviceResult.getJSONObject("error") != null) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "Y移动指令返回错误", cmdToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
}
Boolean nozzleValveCloseCMDToDeviceResultStatus = cmdToDeviceResult.getBool("result");
if (!nozzleValveCloseCMDToDeviceResultStatus) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "Y移动指令执行失败", cmdToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
}
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RESULT, "Y移动指令反馈", cmdToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
}
}

87
src/main/java/com/qyft/ms/app/handler/debugimpl/MotorYOrigin.java

@ -0,0 +1,87 @@
package com.qyft.ms.app.handler.debugimpl;
import cn.hutool.json.JSONObject;
import com.qyft.ms.app.common.annotation.CommandMapping;
import com.qyft.ms.app.common.command.CommandFuture;
import com.qyft.ms.app.common.command.CurrentSendCmdMapInstance;
import com.qyft.ms.app.common.command.DeviceCommandGenerator;
import com.qyft.ms.app.common.command.FrontCommandAck;
import com.qyft.ms.app.common.constant.CommandStatus;
import com.qyft.ms.app.handler.CommandHandler;
import com.qyft.ms.app.model.bo.CMDToDevice;
import com.qyft.ms.app.model.form.CMDFormV2;
import com.qyft.ms.device.client.TcpClient;
import lombok.RequiredArgsConstructor;
import 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.util.Map;
/**
* z轴回原点
*/
@Slf4j
@Component
@RequiredArgsConstructor
@Async("asyncExecutor")
@CommandMapping("motor_y_origin")//业务指令注解
public class MotorYOrigin implements CommandHandler {
private final TcpClient deviceClient;
@Override
public void handle(CMDFormV2 cmdForm, ResponseBodyEmitter emitter) throws Exception {
String frontCmdId = cmdForm.getCmdId();
String frontCmdName = cmdForm.getCmdName();
/**
* 1.向前端发送接收到指令
*/
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RECEIVE, "后台已收到指令"), MediaType.APPLICATION_JSON);
/**
* 2.生成指令并发送指令
*/
CMDToDevice cmdToDevice = DeviceCommandGenerator.motor_y_origin();//关闭喷嘴阀
CommandFuture cmdToDeviceFuture = new CommandFuture();
cmdToDeviceFuture.setCmdToDevice(cmdToDevice);
Integer nozzleValveCloseCMDToDeviceCmdId = cmdToDevice.getCmdId();
CurrentSendCmdMapInstance.getInstance().putCommand(nozzleValveCloseCMDToDeviceCmdId, cmdToDeviceFuture); // 将指令放入map
deviceClient.sendToJSON(cmdToDevice); // 发送指令给设备
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "已向设备发送了Y回原点指令", cmdToDevice), MediaType.APPLICATION_JSON);
/**
* 3.等待
*/
cmdToDeviceFuture.waitForContinue(); // 等待设备的反馈
/**
* 4.处理结果
*/
JSONObject laser_control_open_CMDToDeviceResult = cmdToDeviceFuture.getCallbackResult(); // 拿到设备返回结果
CurrentSendCmdMapInstance.getInstance().removeCommand(nozzleValveCloseCMDToDeviceCmdId); // 从map中删除该指令
if (!cmdToDeviceFuture.isReceived()) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "Y回原点指令响应超时", laser_control_open_CMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
}
if (laser_control_open_CMDToDeviceResult.getJSONObject("error") != null) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "Y回原点指令返回错误", laser_control_open_CMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
}
Boolean nozzleValveCloseCMDToDeviceResultStatus = laser_control_open_CMDToDeviceResult.getBool("result");
if (!nozzleValveCloseCMDToDeviceResultStatus) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "Y回原点指令执行失败", laser_control_open_CMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
}
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RESULT, "Y回原点指令指令反馈", laser_control_open_CMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
}
}

85
src/main/java/com/qyft/ms/app/handler/debugimpl/MotorYStop.java

@ -0,0 +1,85 @@
package com.qyft.ms.app.handler.debugimpl;
import cn.hutool.json.JSONObject;
import com.qyft.ms.app.common.annotation.CommandMapping;
import com.qyft.ms.app.common.command.CommandFuture;
import com.qyft.ms.app.common.command.CurrentSendCmdMapInstance;
import com.qyft.ms.app.common.command.DeviceCommandGenerator;
import com.qyft.ms.app.common.command.FrontCommandAck;
import com.qyft.ms.app.common.constant.CommandStatus;
import com.qyft.ms.app.handler.CommandHandler;
import com.qyft.ms.app.model.bo.CMDToDevice;
import com.qyft.ms.app.model.form.CMDFormV2;
import com.qyft.ms.device.client.TcpClient;
import lombok.RequiredArgsConstructor;
import 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;
/**
* z轴回原点
*/
@Slf4j
@Component
@RequiredArgsConstructor
@Async("asyncExecutor")
@CommandMapping("motor_y_stop")//业务指令注解
public class MotorYStop implements CommandHandler {
private final TcpClient deviceClient;
@Override
public void handle(CMDFormV2 cmdForm, ResponseBodyEmitter emitter) throws Exception {
String frontCmdId = cmdForm.getCmdId();
String frontCmdName = cmdForm.getCmdName();
/**
* 1.向前端发送接收到指令
*/
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RECEIVE, "后台已收到指令"), MediaType.APPLICATION_JSON);
/**
* 2.生成指令并发送指令
*/
CMDToDevice cmdToDevice = DeviceCommandGenerator.motor_y_stop();//关闭喷嘴阀
CommandFuture cmdToDeviceFuture = new CommandFuture();
cmdToDeviceFuture.setCmdToDevice(cmdToDevice);
Integer nozzleValveCloseCMDToDeviceCmdId = cmdToDevice.getCmdId();
CurrentSendCmdMapInstance.getInstance().putCommand(nozzleValveCloseCMDToDeviceCmdId, cmdToDeviceFuture); // 将指令放入map
deviceClient.sendToJSON(cmdToDevice); // 发送指令给设备
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "已向设备发送了Y停止指令", cmdToDevice), MediaType.APPLICATION_JSON);
/**
* 3.等待
*/
cmdToDeviceFuture.waitForContinue(); // 等待设备的反馈
/**
* 4.处理结果
*/
JSONObject laser_control_open_CMDToDeviceResult = cmdToDeviceFuture.getCallbackResult(); // 拿到设备返回结果
CurrentSendCmdMapInstance.getInstance().removeCommand(nozzleValveCloseCMDToDeviceCmdId); // 从map中删除该指令
if (!cmdToDeviceFuture.isReceived()) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "Y停止指令响应超时", laser_control_open_CMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
}
if (laser_control_open_CMDToDeviceResult.getJSONObject("error") != null) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "X停止指令返回错误", laser_control_open_CMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
}
Boolean nozzleValveCloseCMDToDeviceResultStatus = laser_control_open_CMDToDeviceResult.getBool("result");
if (!nozzleValveCloseCMDToDeviceResultStatus) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "Y停止指令执行失败", laser_control_open_CMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
}
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RESULT, "Y停止指令指令反馈", laser_control_open_CMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
}
}

167
src/main/java/com/qyft/ms/app/handler/debugimpl/MotorZMove.java

@ -0,0 +1,167 @@
package com.qyft.ms.app.handler.debugimpl;
import cn.hutool.json.JSONObject;
import com.qyft.ms.app.common.annotation.CommandMapping;
import com.qyft.ms.app.common.command.CommandFuture;
import com.qyft.ms.app.common.command.CurrentSendCmdMapInstance;
import com.qyft.ms.app.common.command.DeviceCommandGenerator;
import com.qyft.ms.app.common.command.FrontCommandAck;
import com.qyft.ms.app.common.constant.CommandStatus;
import com.qyft.ms.app.handler.CommandHandler;
import com.qyft.ms.app.model.bo.CMDToDevice;
import com.qyft.ms.app.model.form.CMDFormV2;
import com.qyft.ms.device.client.TcpClient;
import lombok.RequiredArgsConstructor;
import 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.util.Map;
/**
* z轴回原点
*/
@Slf4j
@Component
@RequiredArgsConstructor
@Async("asyncExecutor")
@CommandMapping("motor_x_move")//业务指令注解
public class MotorZMove implements CommandHandler {
private final TcpClient deviceClient;
/**
* {
* cmdName:'motor_z_move',
* cmdId:'',
* device:'x',
* action:'move',
* param:{
* current:'',//这四个参数可以不同时存在
* direction:'forward|backward',
* position:'',
* speed:''
* }
* }
* @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();
Double position = (Double) param.get("position");
String direction = (String) param.get("direction");
/**
* 1.向前端发送接收到指令
*/
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RECEIVE, "后台已收到指令"), MediaType.APPLICATION_JSON);
/**
* 2.获取电机Z的位置
*/
CMDToDevice cmdToDevice = DeviceCommandGenerator.motor_xyz_position_get();//关闭喷嘴阀
CommandFuture cmdToDeviceFuture = new CommandFuture();
cmdToDeviceFuture.setCmdToDevice(cmdToDevice);
Integer cmdToDeviceCmdId = cmdToDevice.getCmdId();
CurrentSendCmdMapInstance.getInstance().putCommand(cmdToDeviceCmdId, cmdToDeviceFuture); // 将指令放入map
deviceClient.sendToJSON(cmdToDevice); // 发送指令给设备
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "已向设备发送了XYZ获取位置指令", cmdToDevice), MediaType.APPLICATION_JSON);
/**
* 3.等待
*/
cmdToDeviceFuture.waitForContinue(); // 等待设备的反馈
/**
* "{
* ""tag"": ""ack"",
* ""payload"": {
* ""cmdId"": """",
* ""result"": {
* // 双精度浮点型X 轴电机当前位置
* ""xAxisPosition"": 0.0,
* // 双精度浮点型Y 轴电机当前位置
* ""yAxisPosition"": 0.0,
* // 双精度浮点型Z 轴电机当前位置
* ""zAxisPosition"": 0.0,
* }
* }
* }"
*/
/**
* 4.处理电机位置结果
*/
JSONObject resultObject = cmdToDeviceFuture.getCallbackResult(); // 拿到设备返回结果
CurrentSendCmdMapInstance.getInstance().removeCommand(cmdToDeviceCmdId); // 从map中删除该指令
JSONObject cmdToDeviceResult = resultObject.getJSONObject("result");
Double zAxisPosition = cmdToDeviceResult.getDouble("zAxisPosition");
Double finalPosition = 0.0;
if("forward".equals(direction)){
finalPosition+=zAxisPosition+position;
}
if("backward".equals(direction)){
finalPosition-=zAxisPosition-position;
if(finalPosition<0){
finalPosition = 0.0;
}
}
/**
* 5.生成电机移动指令并发送指令
*/
cmdToDevice = DeviceCommandGenerator.motor_x_position_set(finalPosition);//关闭喷嘴阀
cmdToDeviceFuture = new CommandFuture();
cmdToDeviceFuture.setCmdToDevice(cmdToDevice);
Integer nozzleValveCloseCMDToDeviceCmdId = cmdToDevice.getCmdId();
CurrentSendCmdMapInstance.getInstance().putCommand(nozzleValveCloseCMDToDeviceCmdId, cmdToDeviceFuture); // 将指令放入map
deviceClient.sendToJSON(cmdToDevice); // 发送指令给设备
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "已向设备发送了X移动指令", cmdToDevice), MediaType.APPLICATION_JSON);
/**
* 6.等待
*/
cmdToDeviceFuture.waitForContinue(); // 等待设备的反馈
/**
* 7.处理结果
*/
cmdToDeviceResult = cmdToDeviceFuture.getCallbackResult(); // 拿到设备返回结果
CurrentSendCmdMapInstance.getInstance().removeCommand(nozzleValveCloseCMDToDeviceCmdId); // 从map中删除该指令
if (!cmdToDeviceFuture.isReceived()) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "X移动指令响应超时", cmdToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
}
if (cmdToDeviceResult.getJSONObject("error") != null) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "X移动指令返回错误", cmdToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
}
Boolean nozzleValveCloseCMDToDeviceResultStatus = cmdToDeviceResult.getBool("result");
if (!nozzleValveCloseCMDToDeviceResultStatus) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "X移动指令执行失败", cmdToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
}
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RESULT, "X移动指令反馈", cmdToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
}
}

85
src/main/java/com/qyft/ms/app/handler/debugimpl/MotorZOrigin.java

@ -0,0 +1,85 @@
package com.qyft.ms.app.handler.debugimpl;
import cn.hutool.json.JSONObject;
import com.qyft.ms.app.common.annotation.CommandMapping;
import com.qyft.ms.app.common.command.CommandFuture;
import com.qyft.ms.app.common.command.CurrentSendCmdMapInstance;
import com.qyft.ms.app.common.command.DeviceCommandGenerator;
import com.qyft.ms.app.common.command.FrontCommandAck;
import com.qyft.ms.app.common.constant.CommandStatus;
import com.qyft.ms.app.handler.CommandHandler;
import com.qyft.ms.app.model.bo.CMDToDevice;
import com.qyft.ms.app.model.form.CMDFormV2;
import com.qyft.ms.device.client.TcpClient;
import lombok.RequiredArgsConstructor;
import 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;
/**
* z轴回原点
*/
@Slf4j
@Component
@RequiredArgsConstructor
@Async("asyncExecutor")
@CommandMapping("motor_z_origin")//业务指令注解
public class MotorZOrigin implements CommandHandler {
private final TcpClient deviceClient;
@Override
public void handle(CMDFormV2 cmdForm, ResponseBodyEmitter emitter) throws Exception {
String frontCmdId = cmdForm.getCmdId();
String frontCmdName = cmdForm.getCmdName();
/**
* 1.向前端发送接收到指令
*/
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RECEIVE, "后台已收到指令"), MediaType.APPLICATION_JSON);
/**
* 2.生成指令并发送指令
*/
CMDToDevice cmdToDevice = DeviceCommandGenerator.motor_z_origin();//关闭喷嘴阀
CommandFuture cmdToDeviceFuture = new CommandFuture();
cmdToDeviceFuture.setCmdToDevice(cmdToDevice);
Integer nozzleValveCloseCMDToDeviceCmdId = cmdToDevice.getCmdId();
CurrentSendCmdMapInstance.getInstance().putCommand(nozzleValveCloseCMDToDeviceCmdId, cmdToDeviceFuture); // 将指令放入map
deviceClient.sendToJSON(cmdToDevice); // 发送指令给设备
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "已向设备发送了Z回原点指令", cmdToDevice), MediaType.APPLICATION_JSON);
/**
* 3.等待
*/
cmdToDeviceFuture.waitForContinue(); // 等待设备的反馈
/**
* 4.处理结果
*/
JSONObject laser_control_open_CMDToDeviceResult = cmdToDeviceFuture.getCallbackResult(); // 拿到设备返回结果
CurrentSendCmdMapInstance.getInstance().removeCommand(nozzleValveCloseCMDToDeviceCmdId); // 从map中删除该指令
if (!cmdToDeviceFuture.isReceived()) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "Z回原点指令响应超时", laser_control_open_CMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
}
if (laser_control_open_CMDToDeviceResult.getJSONObject("error") != null) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "Z回原点指令返回错误", laser_control_open_CMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
}
Boolean nozzleValveCloseCMDToDeviceResultStatus = laser_control_open_CMDToDeviceResult.getBool("result");
if (!nozzleValveCloseCMDToDeviceResultStatus) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "Z回原点指令执行失败", laser_control_open_CMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
}
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RESULT, "Z回原点指令指令反馈", laser_control_open_CMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
}
}

85
src/main/java/com/qyft/ms/app/handler/debugimpl/MotorZStop.java

@ -0,0 +1,85 @@
package com.qyft.ms.app.handler.debugimpl;
import cn.hutool.json.JSONObject;
import com.qyft.ms.app.common.annotation.CommandMapping;
import com.qyft.ms.app.common.command.CommandFuture;
import com.qyft.ms.app.common.command.CurrentSendCmdMapInstance;
import com.qyft.ms.app.common.command.DeviceCommandGenerator;
import com.qyft.ms.app.common.command.FrontCommandAck;
import com.qyft.ms.app.common.constant.CommandStatus;
import com.qyft.ms.app.handler.CommandHandler;
import com.qyft.ms.app.model.bo.CMDToDevice;
import com.qyft.ms.app.model.form.CMDFormV2;
import com.qyft.ms.device.client.TcpClient;
import lombok.RequiredArgsConstructor;
import 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;
/**
* z轴回原点
*/
@Slf4j
@Component
@RequiredArgsConstructor
@Async("asyncExecutor")
@CommandMapping("motor_z_stop")//业务指令注解
public class MotorZStop implements CommandHandler {
private final TcpClient deviceClient;
@Override
public void handle(CMDFormV2 cmdForm, ResponseBodyEmitter emitter) throws Exception {
String frontCmdId = cmdForm.getCmdId();
String frontCmdName = cmdForm.getCmdName();
/**
* 1.向前端发送接收到指令
*/
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RECEIVE, "后台已收到指令"), MediaType.APPLICATION_JSON);
/**
* 2.生成指令并发送指令
*/
CMDToDevice cmdToDevice = DeviceCommandGenerator.motor_z_stop();//关闭喷嘴阀
CommandFuture cmdToDeviceFuture = new CommandFuture();
cmdToDeviceFuture.setCmdToDevice(cmdToDevice);
Integer nozzleValveCloseCMDToDeviceCmdId = cmdToDevice.getCmdId();
CurrentSendCmdMapInstance.getInstance().putCommand(nozzleValveCloseCMDToDeviceCmdId, cmdToDeviceFuture); // 将指令放入map
deviceClient.sendToJSON(cmdToDevice); // 发送指令给设备
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "已向设备发送了Z停止指令", cmdToDevice), MediaType.APPLICATION_JSON);
/**
* 3.等待
*/
cmdToDeviceFuture.waitForContinue(); // 等待设备的反馈
/**
* 4.处理结果
*/
JSONObject laser_control_open_CMDToDeviceResult = cmdToDeviceFuture.getCallbackResult(); // 拿到设备返回结果
CurrentSendCmdMapInstance.getInstance().removeCommand(nozzleValveCloseCMDToDeviceCmdId); // 从map中删除该指令
if (!cmdToDeviceFuture.isReceived()) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "Z停止指令响应超时", laser_control_open_CMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
}
if (laser_control_open_CMDToDeviceResult.getJSONObject("error") != null) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "Z停止指令返回错误", laser_control_open_CMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
}
Boolean nozzleValveCloseCMDToDeviceResultStatus = laser_control_open_CMDToDeviceResult.getBool("result");
if (!nozzleValveCloseCMDToDeviceResultStatus) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "Z停止指令执行失败", laser_control_open_CMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
}
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RESULT, "Z停止指令指令反馈", laser_control_open_CMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
}
}

74
src/main/java/com/qyft/ms/app/handler/debugimpl/NozzleValveClose.java

@ -0,0 +1,74 @@
package com.qyft.ms.app.handler.debugimpl;
import cn.hutool.json.JSONObject;
import com.qyft.ms.app.common.annotation.CommandMapping;
import com.qyft.ms.app.common.command.CommandFuture;
import com.qyft.ms.app.common.command.CurrentSendCmdMapInstance;
import com.qyft.ms.app.common.command.DeviceCommandGenerator;
import com.qyft.ms.app.common.command.FrontCommandAck;
import com.qyft.ms.app.common.constant.CommandStatus;
import com.qyft.ms.app.handler.CommandHandler;
import com.qyft.ms.app.model.bo.CMDToDevice;
import com.qyft.ms.app.model.form.CMDFormV2;
import com.qyft.ms.device.client.TcpClient;
import lombok.RequiredArgsConstructor;
import 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;
/**
* z轴回原点
*/
@Slf4j
@Component
@RequiredArgsConstructor
@Async("asyncExecutor")
@CommandMapping("nozzle_valve_close")//业务指令注解
public class NozzleValveClose implements CommandHandler {
private final TcpClient deviceClient;
@Override
public void handle(CMDFormV2 cmdForm, ResponseBodyEmitter emitter) throws Exception {
String frontCmdId = cmdForm.getCmdId();
String frontCmdName = cmdForm.getCmdName();
//向前端发送接收到指令
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RECEIVE, "后台已收到指令"), MediaType.APPLICATION_JSON);
CMDToDevice cmdToDevice = DeviceCommandGenerator.nozzle_valve_close();//关闭喷嘴阀
CommandFuture cmdToDeviceFuture = new CommandFuture();
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "关闭喷嘴阀"), MediaType.APPLICATION_JSON);
cmdToDeviceFuture.setCmdToDevice(cmdToDevice);
Integer nozzleValveCloseCMDToDeviceCmdId = cmdToDevice.getCmdId();
CurrentSendCmdMapInstance.getInstance().putCommand(nozzleValveCloseCMDToDeviceCmdId, cmdToDeviceFuture); // 将指令放入map
deviceClient.sendToJSON(cmdToDevice); // 发送指令给设备
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "已向设备发送了关闭喷嘴阀指令", cmdToDevice), MediaType.APPLICATION_JSON);
cmdToDeviceFuture.waitForContinue(); // 等待设备的反馈
JSONObject nozzleValveCloseCMDToDeviceResult = cmdToDeviceFuture.getCallbackResult(); // 拿到设备返回结果
CurrentSendCmdMapInstance.getInstance().removeCommand(nozzleValveCloseCMDToDeviceCmdId); // 从map中删除该指令
if (!cmdToDeviceFuture.isReceived()) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "关闭喷嘴阀指令响应超时", nozzleValveCloseCMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
}
if (nozzleValveCloseCMDToDeviceResult.getJSONObject("error") != null) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "关闭喷嘴阀指令返回错误", nozzleValveCloseCMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
}
Boolean nozzleValveCloseCMDToDeviceResultStatus = nozzleValveCloseCMDToDeviceResult.getBool("result");
if (!nozzleValveCloseCMDToDeviceResultStatus) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "关闭喷嘴阀指令执行失败", nozzleValveCloseCMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
}
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RESULT, "关闭喷嘴阀指令反馈", nozzleValveCloseCMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
}
}

79
src/main/java/com/qyft/ms/app/handler/debugimpl/NozzleValveOpen.java

@ -0,0 +1,79 @@
package com.qyft.ms.app.handler.debugimpl;
import cn.hutool.json.JSONObject;
import com.qyft.ms.app.common.annotation.CommandMapping;
import com.qyft.ms.app.common.command.CommandFuture;
import com.qyft.ms.app.common.command.CurrentSendCmdMapInstance;
import com.qyft.ms.app.common.command.DeviceCommandGenerator;
import com.qyft.ms.app.common.command.FrontCommandAck;
import com.qyft.ms.app.common.constant.CommandStatus;
import com.qyft.ms.app.handler.CommandHandler;
import com.qyft.ms.app.model.bo.CMDToDevice;
import com.qyft.ms.app.model.form.CMDFormV2;
import com.qyft.ms.device.client.TcpClient;
import lombok.RequiredArgsConstructor;
import 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;
/**
* z轴回原点
*/
@Slf4j
@Component
@RequiredArgsConstructor
@Async("asyncExecutor")
@CommandMapping("nozzle_valve_open")//业务指令注解
public class NozzleValveOpen implements CommandHandler {
private final TcpClient deviceClient;
@Override
public void handle(CMDFormV2 cmdForm, ResponseBodyEmitter emitter) throws Exception {
String frontCmdId = cmdForm.getCmdId();
String frontCmdName = cmdForm.getCmdName();
//向前端发送接收到指令
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RECEIVE, "后台已收到指令"), MediaType.APPLICATION_JSON);
CMDToDevice cmdToDevice = DeviceCommandGenerator.nozzle_valve_open();//生成指令 开启喷嘴阀
CommandFuture cmdToDeviceFuture = new CommandFuture();
cmdToDeviceFuture.setCmdToDevice(cmdToDevice);
Integer nozzleValveOpenCMDToDeviceCmdId = cmdToDevice.getCmdId();
CurrentSendCmdMapInstance.getInstance().putCommand(nozzleValveOpenCMDToDeviceCmdId, cmdToDeviceFuture); // 将指令放入map
deviceClient.sendToJSON(cmdToDevice); // 发送指令给设备
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "已向设备发送了开启喷嘴阀指令", cmdToDevice), MediaType.APPLICATION_JSON);
cmdToDeviceFuture.waitForContinue(); // 等待设备的反馈
JSONObject nozzleValveOpenCMDToDeviceResult = cmdToDeviceFuture.getCallbackResult(); // 拿到设备返回结果
CurrentSendCmdMapInstance.getInstance().removeCommand(nozzleValveOpenCMDToDeviceCmdId); // 将指令从map中删除
if (!cmdToDeviceFuture.isReceived()) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "开启喷嘴阀指令响应超时", nozzleValveOpenCMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
}
if (nozzleValveOpenCMDToDeviceResult.getJSONObject("error") != null) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "开启喷嘴阀指令返回错误", nozzleValveOpenCMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
}
Boolean nozzleValveOpenCMDToDeviceResultStatus = nozzleValveOpenCMDToDeviceResult.getBool("result");
if (!nozzleValveOpenCMDToDeviceResultStatus) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "开启喷嘴阀指令执行失败", nozzleValveOpenCMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
}
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RESULT, "开启喷嘴阀指令反馈", nozzleValveOpenCMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
}
}

87
src/main/java/com/qyft/ms/app/handler/debugimpl/WashValveClose.java

@ -0,0 +1,87 @@
package com.qyft.ms.app.handler.debugimpl;
import cn.hutool.json.JSONObject;
import com.qyft.ms.app.common.annotation.CommandMapping;
import com.qyft.ms.app.common.command.CommandFuture;
import com.qyft.ms.app.common.command.CurrentSendCmdMapInstance;
import com.qyft.ms.app.common.command.DeviceCommandGenerator;
import com.qyft.ms.app.common.command.FrontCommandAck;
import com.qyft.ms.app.common.constant.CommandStatus;
import com.qyft.ms.app.handler.CommandHandler;
import com.qyft.ms.app.model.bo.CMDToDevice;
import com.qyft.ms.app.model.form.CMDFormV2;
import com.qyft.ms.device.client.TcpClient;
import lombok.RequiredArgsConstructor;
import 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.util.Map;
/**
* z轴回原点
*/
@Slf4j
@Component
@RequiredArgsConstructor
@Async("asyncExecutor")
@CommandMapping("wash_valve_close")//业务指令注解
public class WashValveClose implements CommandHandler {
private final TcpClient deviceClient;
@Override
public void handle(CMDFormV2 cmdForm, ResponseBodyEmitter emitter) throws Exception {
String frontCmdId = cmdForm.getCmdId();
String frontCmdName = cmdForm.getCmdName();
/**
* 1.向前端发送接收到指令
*/
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RECEIVE, "后台已收到指令"), MediaType.APPLICATION_JSON);
/**
* 2.生成指令并发送指令
*/
CMDToDevice cmdToDevice = DeviceCommandGenerator.wash_valve_close();//
CommandFuture cmdToDeviceFuture = new CommandFuture();
cmdToDeviceFuture.setCmdToDevice(cmdToDevice);
Integer nozzleValveCloseCMDToDeviceCmdId = cmdToDevice.getCmdId();
CurrentSendCmdMapInstance.getInstance().putCommand(nozzleValveCloseCMDToDeviceCmdId, cmdToDeviceFuture); // 将指令放入map
deviceClient.sendToJSON(cmdToDevice); // 发送指令给设备
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "已向设备发送了关闭清洗阀指令", cmdToDevice), MediaType.APPLICATION_JSON);
/**
* 3.等待
*/
cmdToDeviceFuture.waitForContinue(); // 等待设备的反馈
/**
* 4.处理结果
*/
JSONObject laser_control_open_CMDToDeviceResult = cmdToDeviceFuture.getCallbackResult(); // 拿到设备返回结果
CurrentSendCmdMapInstance.getInstance().removeCommand(nozzleValveCloseCMDToDeviceCmdId); // 从map中删除该指令
if (!cmdToDeviceFuture.isReceived()) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "关闭清洗阀指令响应超时", laser_control_open_CMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
}
if (laser_control_open_CMDToDeviceResult.getJSONObject("error") != null) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "关闭清洗阀指令返回错误", laser_control_open_CMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
}
Boolean nozzleValveCloseCMDToDeviceResultStatus = laser_control_open_CMDToDeviceResult.getBool("result");
if (!nozzleValveCloseCMDToDeviceResultStatus) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "关闭清洗阀指令执行失败", laser_control_open_CMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
}
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RESULT, "关闭清洗阀指令指令反馈", laser_control_open_CMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
}
}

88
src/main/java/com/qyft/ms/app/handler/debugimpl/WashValveOpen.java

@ -0,0 +1,88 @@
package com.qyft.ms.app.handler.debugimpl;
import cn.hutool.json.JSONObject;
import com.qyft.ms.app.common.annotation.CommandMapping;
import com.qyft.ms.app.common.command.CommandFuture;
import com.qyft.ms.app.common.command.CurrentSendCmdMapInstance;
import com.qyft.ms.app.common.command.DeviceCommandGenerator;
import com.qyft.ms.app.common.command.FrontCommandAck;
import com.qyft.ms.app.common.constant.CommandStatus;
import com.qyft.ms.app.handler.CommandHandler;
import com.qyft.ms.app.model.bo.CMDToDevice;
import com.qyft.ms.app.model.form.CMDFormV2;
import com.qyft.ms.device.client.TcpClient;
import lombok.RequiredArgsConstructor;
import 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.util.Map;
/**
* z轴回原点
*/
@Slf4j
@Component
@RequiredArgsConstructor
@Async("asyncExecutor")
@CommandMapping("wash_valve_open")//业务指令注解
public class WashValveOpen implements CommandHandler {
private final TcpClient deviceClient;
@Override
public void handle(CMDFormV2 cmdForm, ResponseBodyEmitter emitter) throws Exception {
String frontCmdId = cmdForm.getCmdId();
String frontCmdName = cmdForm.getCmdName();
/**
* 1.向前端发送接收到指令
*/
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RECEIVE, "后台已收到指令"), MediaType.APPLICATION_JSON);
/**
* 2.生成指令并发送指令
*/
CMDToDevice wash_valve_open_CMDToDevice = DeviceCommandGenerator.wash_valve_open();//关闭喷嘴阀
CommandFuture wash_valve_open_CMDToDeviceFuture = new CommandFuture();
wash_valve_open_CMDToDeviceFuture.setCmdToDevice(wash_valve_open_CMDToDevice);
Integer nozzleValveCloseCMDToDeviceCmdId = wash_valve_open_CMDToDevice.getCmdId();
CurrentSendCmdMapInstance.getInstance().putCommand(nozzleValveCloseCMDToDeviceCmdId, wash_valve_open_CMDToDeviceFuture); // 将指令放入map
deviceClient.sendToJSON(wash_valve_open_CMDToDevice); // 发送指令给设备
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "已向设备发送了打开清洗阀", wash_valve_open_CMDToDevice), MediaType.APPLICATION_JSON);
/**
* 3.等待
*/
wash_valve_open_CMDToDeviceFuture.waitForContinue(); // 等待设备的反馈
/**
* 4.处理结果
*/
JSONObject laser_control_open_CMDToDeviceResult = wash_valve_open_CMDToDeviceFuture.getCallbackResult(); // 拿到设备返回结果
CurrentSendCmdMapInstance.getInstance().removeCommand(nozzleValveCloseCMDToDeviceCmdId); // 从map中删除该指令
if (!wash_valve_open_CMDToDeviceFuture.isReceived()) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "打开清洗阀指令响应超时", laser_control_open_CMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
}
if (laser_control_open_CMDToDeviceResult.getJSONObject("error") != null) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "打开清洗阀指令返回错误", laser_control_open_CMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
}
Boolean nozzleValveCloseCMDToDeviceResultStatus = laser_control_open_CMDToDeviceResult.getBool("result");
if (!nozzleValveCloseCMDToDeviceResultStatus) {
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.ERROR, "打开清洗阀指令执行失败", laser_control_open_CMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
}
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RESULT, "打开清洗阀指令指令反馈", laser_control_open_CMDToDeviceResult), MediaType.APPLICATION_JSON);
emitter.complete();
}
}
Loading…
Cancel
Save