|
|
@ -9,6 +9,7 @@ import com.qyft.ms.app.common.command.FrontCommandAck; |
|
|
|
import com.qyft.ms.app.common.constant.CommandStatus; |
|
|
|
import com.qyft.ms.app.common.generator.PathGenerator; |
|
|
|
import com.qyft.ms.app.handler.CommandHandler; |
|
|
|
import com.qyft.ms.app.handler.MatrixSprayState; |
|
|
|
import com.qyft.ms.app.model.bo.CMDToDevice; |
|
|
|
import com.qyft.ms.app.model.form.CMDFormV2; |
|
|
|
import com.qyft.ms.device.client.TcpClient; |
|
|
@ -16,7 +17,6 @@ import com.qyft.ms.device.handler.DeviceMessageHandler; |
|
|
|
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; |
|
|
|
|
|
|
@ -34,7 +34,7 @@ import java.util.concurrent.TimeoutException; |
|
|
|
@Slf4j |
|
|
|
@Component |
|
|
|
@RequiredArgsConstructor |
|
|
|
@Async("asyncExecutor") |
|
|
|
//@Async("asyncExecutor") |
|
|
|
@CommandMapping("matrix_spray_start")//业务指令注解 |
|
|
|
public class MatrixSprayStart implements CommandHandler { |
|
|
|
|
|
|
@ -42,6 +42,8 @@ public class MatrixSprayStart implements CommandHandler { |
|
|
|
|
|
|
|
private final DeviceMessageHandler deviceMessageHandler; |
|
|
|
|
|
|
|
private final MatrixSprayState matrixSprayState; |
|
|
|
|
|
|
|
/** |
|
|
|
* { |
|
|
|
* cmdName:'matrix_spray_start' |
|
|
@ -62,10 +64,14 @@ public class MatrixSprayStart implements CommandHandler { |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public void handle(CMDFormV2 cmdForm, ResponseBodyEmitter emitter) throws Exception { |
|
|
|
log.info("申请中断喷涂线程:{}", matrixSprayState.cancelTask()); |
|
|
|
matrixSprayState.startTask(() -> { |
|
|
|
try { |
|
|
|
String frontCmdId = cmdForm.getCmdId(); |
|
|
|
String frontCmdName = cmdForm.getCmdName(); |
|
|
|
Map<String, Object> param = cmdForm.getParam(); |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.RECEIVE, "后台已收到指令"), MediaType.APPLICATION_JSON);//向前端发送接收到指令 |
|
|
|
|
|
|
|
// 1. 参数校验 |
|
|
|
String matrixPathType = Optional.ofNullable(param.get("matrixPathType")) |
|
|
|
.map(Object::toString) |
|
|
@ -226,7 +232,8 @@ 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); |
|
|
@ -255,7 +262,8 @@ public class MatrixSprayStart implements CommandHandler { |
|
|
|
spacing, |
|
|
|
PathGenerator.MoveMode.VERTICAL_ZIGZAG_LEFT_RIGHT |
|
|
|
); |
|
|
|
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); |
|
|
@ -288,13 +296,15 @@ public class MatrixSprayStart implements CommandHandler { |
|
|
|
spacing, |
|
|
|
PathGenerator.MoveMode.VERTICAL_ZIGZAG_LEFT_RIGHT |
|
|
|
); |
|
|
|
if (pathSpray(emitter, frontCmdId, frontCmdName, volume, pathList, movingSpeed)) return;//路径喷涂 |
|
|
|
if (pathSpray(emitter, frontCmdId, frontCmdName, volume, pathList, movingSpeed)) |
|
|
|
return;//路径喷涂 |
|
|
|
pathList = PathGenerator.generatePathPoints( |
|
|
|
leftReal, rightReal, topReal, bottomReal, |
|
|
|
spacing, |
|
|
|
PathGenerator.MoveMode.HORIZONTAL_ZIGZAG_TOP_DOWN |
|
|
|
); |
|
|
|
if (pathSpray(emitter, frontCmdId, frontCmdName, volume, pathList, movingSpeed)) return;//路径喷涂 |
|
|
|
if (pathSpray(emitter, frontCmdId, frontCmdName, volume, pathList, movingSpeed)) |
|
|
|
return;//路径喷涂 |
|
|
|
if (i + 1 != times) { //如果不是最后一次,执行完毕后回到玻片原点 |
|
|
|
log.info("123"); |
|
|
|
latch = new CountDownLatch(2); |
|
|
@ -340,8 +350,15 @@ public class MatrixSprayStart implements CommandHandler { |
|
|
|
//12.结束日志 |
|
|
|
//TODO写日志 |
|
|
|
emitter.send(FrontCommandAck.backstageAck(frontCmdId, frontCmdName, CommandStatus.SEND, "指令执行完毕"), MediaType.APPLICATION_JSON); |
|
|
|
} catch (Exception e) { |
|
|
|
Thread.currentThread().interrupt(); |
|
|
|
log.info("喷涂线程已停止"); |
|
|
|
System.out.println("任务中断"); |
|
|
|
} finally { |
|
|
|
emitter.complete(); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private boolean motorSpeedSet(ResponseBodyEmitter emitter, Double movingSpeed, String frontCmdId, String frontCmdName) throws IOException { |
|
|
|