From 8f444535d40bf13ce7ca2fb0585e1f9b8d089f1a Mon Sep 17 00:00:00 2001
From: Junjie <DELL@qq.com>
Date: 星期三, 24 十二月 2025 14:30:25 +0800
Subject: [PATCH] #
---
src/main/java/com/zy/core/network/fake/ZyDualCrnFakeConnect.java | 222 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 222 insertions(+), 0 deletions(-)
diff --git a/src/main/java/com/zy/core/network/fake/ZyDualCrnFakeConnect.java b/src/main/java/com/zy/core/network/fake/ZyDualCrnFakeConnect.java
new file mode 100644
index 0000000..11fa99e
--- /dev/null
+++ b/src/main/java/com/zy/core/network/fake/ZyDualCrnFakeConnect.java
@@ -0,0 +1,222 @@
+package com.zy.core.network.fake;
+
+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.DualCrnCommand;
+import com.zy.core.network.api.ZyDualCrnConnectApi;
+import com.zy.core.network.entity.ZyDualCrnStatusEntity;
+
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+public class ZyDualCrnFakeConnect implements ZyDualCrnConnectApi {
+
+ private ZyDualCrnStatusEntity crnStatus;
+ private DeviceConfig deviceConfig;
+ private final ExecutorService executor = Executors.newSingleThreadExecutor();
+
+ public ZyDualCrnFakeConnect(DeviceConfig deviceConfig) {
+ this.deviceConfig = deviceConfig;
+ this.crnStatus = JSON.parseObject(deviceConfig.getFakeInitStatus(), ZyDualCrnStatusEntity.class);
+ }
+
+ @Override
+ public boolean connect() {
+ return true;
+ }
+
+ @Override
+ public boolean disconnect() {
+ try { executor.shutdownNow(); } catch (Exception ignore) {}
+ return true;
+ }
+
+ @Override
+ public ZyDualCrnStatusEntity getStatus() {
+ return this.crnStatus;
+ }
+
+ @Override
+ public CommandResponse sendCommand(DualCrnCommand 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(DualCrnCommand command) {
+ this.crnStatus.setTaskNo(0);
+ this.crnStatus.setStatus(CrnStatusType.IDLE.id);
+ }
+
+ private void commandMove(DualCrnCommand 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();
+
+ if(command.getStation() == 1) {
+ this.crnStatus.setTaskNo(taskNo);
+ this.crnStatus.setStatus(CrnStatusType.MOVING.id);
+ moveY(this.crnStatus.getBay(), destinationPosY, command.getStation().intValue());
+ moveZ(this.crnStatus.getLevel(), destinationPosZ, command.getStation().intValue());
+ this.crnStatus.setStatus(CrnStatusType.WAITING.id);
+ }else {
+ this.crnStatus.setTaskNoTwo(taskNo);
+ this.crnStatus.setStatusTwo(CrnStatusType.MOVING.id);
+ moveY(this.crnStatus.getBayTwo(), destinationPosY, command.getStation().intValue());
+ moveZ(this.crnStatus.getLevelTwo(), destinationPosZ, command.getStation().intValue());
+ this.crnStatus.setStatusTwo(CrnStatusType.WAITING.id);
+ }
+ }
+
+ private void commandTake(DualCrnCommand 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.setMode(taskMode);
+ if(command.getStation() == 1) {
+ this.crnStatus.setTaskNo(taskNo);
+ this.crnStatus.setStatus(CrnStatusType.FETCH_MOVING.id);
+
+ moveY(this.crnStatus.getBay(), sourcePosY, command.getStation().intValue());
+ moveZ(this.crnStatus.getLevel(), sourcePosZ, command.getStation().intValue());
+ this.crnStatus.setStatus(CrnStatusType.FETCHING.id);
+ sleep(2000);
+ if (Thread.currentThread().isInterrupted()) {
+ return;
+ }
+
+ this.crnStatus.setLoaded(1);
+ this.crnStatus.setStatus(CrnStatusType.PUT_MOVING.id);
+ moveY(this.crnStatus.getBay(), destinationPosY, command.getStation().intValue());
+ moveZ(this.crnStatus.getLevel(), destinationPosZ, command.getStation().intValue());
+ this.crnStatus.setStatus(CrnStatusType.PUTTING.id);
+ sleep(2000);
+ if (Thread.currentThread().isInterrupted()) {
+ return;
+ }
+ this.crnStatus.setLoaded(0);
+ this.crnStatus.setStatus(CrnStatusType.WAITING.id);
+ }else {
+ this.crnStatus.setTaskNoTwo(taskNo);
+ this.crnStatus.setStatusTwo(CrnStatusType.FETCH_MOVING.id);
+
+ moveY(this.crnStatus.getBayTwo(), sourcePosY, command.getStation().intValue());
+ moveZ(this.crnStatus.getLevelTwo(), sourcePosZ, command.getStation().intValue());
+ this.crnStatus.setStatusTwo(CrnStatusType.FETCHING.id);
+ sleep(2000);
+ if (Thread.currentThread().isInterrupted()) {
+ return;
+ }
+
+ this.crnStatus.setLoadedTwo(1);
+ this.crnStatus.setStatusTwo(CrnStatusType.PUT_MOVING.id);
+ moveY(this.crnStatus.getBayTwo(), destinationPosY, command.getStation().intValue());
+ moveZ(this.crnStatus.getLevelTwo(), destinationPosZ, command.getStation().intValue());
+ this.crnStatus.setStatusTwo(CrnStatusType.PUTTING.id);
+ sleep(2000);
+ if (Thread.currentThread().isInterrupted()) {
+ return;
+ }
+ this.crnStatus.setLoadedTwo(0);
+ this.crnStatus.setStatusTwo(CrnStatusType.WAITING.id);
+ }
+ }
+
+ private void moveZ(int sourcePosZ, int destinationPosZ, int station) {
+ if(destinationPosZ - sourcePosZ > 0) {
+ int moveLength = destinationPosZ - sourcePosZ;
+ int initSourcePosZ = sourcePosZ;
+ for(int i = 0; i < moveLength; i++) {
+ initSourcePosZ++;
+ if(station == 1) {
+ this.crnStatus.setLevel(initSourcePosZ);
+ }else {
+ this.crnStatus.setLevelTwo(initSourcePosZ);
+ }
+ sleep(1000);
+ if (Thread.currentThread().isInterrupted()) {
+ return;
+ }
+ }
+ }else {
+ int moveLength = sourcePosZ - destinationPosZ;
+ int initSourcePosZ = sourcePosZ;
+ for(int i = 0; i < moveLength; i++) {
+ initSourcePosZ--;
+ if(station == 1) {
+ this.crnStatus.setLevel(initSourcePosZ);
+ }else {
+ this.crnStatus.setLevelTwo(initSourcePosZ);
+ }
+ this.crnStatus.setLevel(initSourcePosZ);
+ sleep(1000);
+ if (Thread.currentThread().isInterrupted()) {
+ return;
+ }
+ }
+ }
+ }
+
+ private void moveY(int sourcePosY, int destinationPosY, int station) {
+ if(destinationPosY - sourcePosY > 0) {
+ int moveLength = destinationPosY - sourcePosY;
+ int initSourcePosY = sourcePosY;
+ for(int i = 0; i < moveLength; i++) {
+ initSourcePosY++;
+ if(station == 1) {
+ this.crnStatus.setBay(initSourcePosY);
+ }else {
+ this.crnStatus.setBayTwo(initSourcePosY);
+ }
+ sleep(1000);
+ if (Thread.currentThread().isInterrupted()) {
+ return;
+ }
+ }
+ }else {
+ int moveLength = sourcePosY - destinationPosY;
+ int initSourcePosY = sourcePosY;
+ for(int i = 0; i < moveLength; i++) {
+ initSourcePosY--;
+ if(station == 1) {
+ this.crnStatus.setBay(initSourcePosY);
+ }else {
+ this.crnStatus.setBayTwo(initSourcePosY);
+ }
+ sleep(1000);
+ if (Thread.currentThread().isInterrupted()) {
+ return;
+ }
+ }
+ }
+ }
+
+ private void sleep(long ms) {
+ try {
+ Thread.sleep(ms);
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ }
+ }
+}
--
Gitblit v1.9.1