From bfe469c7fa604a6431d58ea5e5143c959d76bd86 Mon Sep 17 00:00:00 2001
From: Junjie <540245094@qq.com>
Date: 星期二, 11 十一月 2025 16:09:38 +0800
Subject: [PATCH] #
---
src/main/java/com/zy/core/network/fake/ZyCrnFakeConnect.java | 126 ++++++++++++++++++++++++++++++++++++++++++
1 files changed, 126 insertions(+), 0 deletions(-)
diff --git a/src/main/java/com/zy/core/network/fake/ZyCrnFakeConnect.java b/src/main/java/com/zy/core/network/fake/ZyCrnFakeConnect.java
index f68bdb1..6aa6da4 100644
--- a/src/main/java/com/zy/core/network/fake/ZyCrnFakeConnect.java
+++ b/src/main/java/com/zy/core/network/fake/ZyCrnFakeConnect.java
@@ -2,15 +2,20 @@
import com.alibaba.fastjson.JSON;
import com.zy.asrs.entity.DeviceConfig;
+import com.zy.core.enums.CrnStatusType;
+import com.zy.core.enums.CrnTaskModeType;
import com.zy.core.model.CommandResponse;
import com.zy.core.model.command.CrnCommand;
import com.zy.core.network.api.ZyCrnConnectApi;
import com.zy.core.network.entity.ZyCrnStatusEntity;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
public class ZyCrnFakeConnect implements ZyCrnConnectApi {
private ZyCrnStatusEntity crnStatus;
private DeviceConfig deviceConfig;
+ private final ExecutorService executor = Executors.newSingleThreadExecutor();
public ZyCrnFakeConnect(DeviceConfig deviceConfig) {
this.deviceConfig = deviceConfig;
@@ -35,6 +40,127 @@
@Override
public CommandResponse sendCommand(CrnCommand command) {
CommandResponse response = new CommandResponse(false);
+ if (command.getTaskMode().intValue() == CrnTaskModeType.LOC_MOVE.id) {
+ //鍙栨斁璐�
+ executor.submit(() -> commandTake(command));
+ } else if (command.getTaskMode().intValue() == CrnTaskModeType.CRN_MOVE.id) {
+ //绉诲姩
+ executor.submit(() -> commandMove(command));
+ } else if (command.getTaskMode().intValue() == CrnTaskModeType.NONE.id) {
+ //澶嶄綅
+ executor.submit(() -> commandTaskComplete(command));
+ }
+ response.setResult(true);
return response;
}
+
+ private void commandTaskComplete(CrnCommand command) {
+ this.crnStatus.setTaskNo(0);
+ this.crnStatus.setStatus(CrnStatusType.IDLE.id);
+ }
+
+ private void commandMove(CrnCommand command) {
+ int destinationPosX = command.getDestinationPosX().intValue();
+ int destinationPosY = command.getDestinationPosY().intValue();
+ int destinationPosZ = command.getDestinationPosZ().intValue();
+ int taskMode = command.getTaskMode().intValue();
+ int taskNo = command.getTaskNo().intValue();
+
+ this.crnStatus.setTaskNo(taskNo);
+ this.crnStatus.setStatus(CrnStatusType.MOVING.id);
+ moveY(this.crnStatus.getBay(), destinationPosY);
+ moveZ(this.crnStatus.getLevel(), destinationPosZ);
+ this.crnStatus.setStatus(CrnStatusType.WAITING.id);
+ }
+
+ private void commandTake(CrnCommand command) {
+ int sourcePosX = command.getSourcePosX().intValue();
+ int sourcePosY = command.getSourcePosY().intValue();
+ int sourcePosZ = command.getSourcePosZ().intValue();
+ int destinationPosX = command.getDestinationPosX().intValue();
+ int destinationPosY = command.getDestinationPosY().intValue();
+ int destinationPosZ = command.getDestinationPosZ().intValue();
+ int taskMode = command.getTaskMode().intValue();
+ int taskNo = command.getTaskNo().intValue();
+
+ this.crnStatus.setTaskNo(taskNo);
+ this.crnStatus.setStatus(CrnStatusType.FETCH_MOVING.id);
+ moveY(this.crnStatus.getBay(), sourcePosY);
+ moveZ(this.crnStatus.getLevel(), sourcePosZ);
+ this.crnStatus.setStatus(CrnStatusType.FETCHING.id);
+ try {
+ Thread.sleep(2000);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+
+ this.crnStatus.setLoaded(1);
+ this.crnStatus.setStatus(CrnStatusType.PUT_MOVING.id);
+ moveY(this.crnStatus.getBay(), destinationPosY);
+ moveZ(this.crnStatus.getLevel(), destinationPosZ);
+ this.crnStatus.setStatus(CrnStatusType.PUTTING.id);
+ try {
+ Thread.sleep(2000);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ this.crnStatus.setLoaded(0);
+ this.crnStatus.setStatus(CrnStatusType.WAITING.id);
+ }
+
+ private void moveZ(int sourcePosZ, int destinationPosZ) {
+ if(destinationPosZ - sourcePosZ > 0) {
+ int moveLength = destinationPosZ - sourcePosZ;
+ int initSourcePosZ = sourcePosZ;
+ for(int i = 0; i < moveLength; i++) {
+ initSourcePosZ++;
+ this.crnStatus.setLevel(initSourcePosZ);
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ }else {
+ int moveLength = sourcePosZ - destinationPosZ;
+ int initSourcePosZ = sourcePosZ;
+ for(int i = 0; i < moveLength; i++) {
+ initSourcePosZ--;
+ this.crnStatus.setLevel(initSourcePosZ);
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+
+ private void moveY(int sourcePosY, int destinationPosY) {
+ if(destinationPosY - sourcePosY > 0) {
+ int moveLength = destinationPosY - sourcePosY;
+ int initSourcePosY = sourcePosY;
+ for(int i = 0; i < moveLength; i++) {
+ initSourcePosY++;
+ this.crnStatus.setBay(initSourcePosY);
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ }else {
+ int moveLength = sourcePosY - destinationPosY;
+ int initSourcePosY = sourcePosY;
+ for(int i = 0; i < moveLength; i++) {
+ initSourcePosY--;
+ this.crnStatus.setBay(initSourcePosY);
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
}
--
Gitblit v1.9.1