From 720e0926fa1c94b952c26e111206c5d6e1ed5ba2 Mon Sep 17 00:00:00 2001
From: lsh <lsh@163.com>
Date: 星期二, 21 四月 2026 15:59:49 +0800
Subject: [PATCH] Merge branch 'master' of http://47.97.1.152:5880/r/zy-wcs-master

---
 src/main/java/com/zy/core/network/fake/ZyCrnFakeConnect.java |   44 ++++++++++++++++++++++++++++++++++++++------
 1 files changed, 38 insertions(+), 6 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 921132a..acd7b71 100644
--- a/src/main/java/com/zy/core/network/fake/ZyCrnFakeConnect.java
+++ b/src/main/java/com/zy/core/network/fake/ZyCrnFakeConnect.java
@@ -17,9 +17,37 @@
     private DeviceConfig deviceConfig;
     private final ExecutorService executor = Executors.newSingleThreadExecutor();
 
+    private long fetchPutDurationMs() { return FakeConfigSupport.getLong(FakeConfigKeys.FAKE_CRN_FETCH_PUT_DURATION_MS); }
+    private long levelStepDurationMs() { return FakeConfigSupport.getLong(FakeConfigKeys.FAKE_CRN_LEVEL_STEP_DURATION_MS); }
+    private long bayStepDurationMs() { return FakeConfigSupport.getLong(FakeConfigKeys.FAKE_CRN_BAY_STEP_DURATION_MS); }
+    private long resetDurationMs() { return FakeConfigSupport.getLong(FakeConfigKeys.FAKE_CRN_RESET_DURATION_MS); }
+    private long bayMin() { return FakeConfigSupport.getLong(FakeConfigKeys.FAKE_CRN_BAY_MIN); }
+    private long bayMax() { return FakeConfigSupport.getLong(FakeConfigKeys.FAKE_CRN_BAY_MAX); }
+    private long laserMin() { return FakeConfigSupport.getLong(FakeConfigKeys.FAKE_CRN_LASER_MIN); }
+    private long laserMax() { return FakeConfigSupport.getLong(FakeConfigKeys.FAKE_CRN_LASER_MAX); }
+
     public ZyCrnFakeConnect(DeviceConfig deviceConfig) {
         this.deviceConfig = deviceConfig;
         this.crnStatus = JSON.parseObject(deviceConfig.getFakeInitStatus(), ZyCrnStatusEntity.class);
+        if (this.crnStatus != null && this.crnStatus.getBay() != null) {
+            updateLaserByBay(this.crnStatus.getBay());
+        }
+    }
+
+    private void updateLaserByBay(int bay) {
+        long bayMin = bayMin();
+        long bayMax = bayMax();
+        long laserMin = laserMin();
+        long laserMax = laserMax();
+        if (bayMax <= bayMin || laserMax <= laserMin) {
+            this.crnStatus.setLaserValue((int) laserMin);
+            return;
+        }
+        long normalizedBay = Math.max(bayMin, Math.min(bayMax, bay));
+        double ratio = (double) (normalizedBay - bayMin) / (double) (bayMax - bayMin);
+        long computed = Math.round(laserMin + ratio * (laserMax - laserMin));
+        long clamped = Math.max(laserMin, Math.min(laserMax, computed));
+        this.crnStatus.setLaserValue((int) clamped);
     }
 
     @Override
@@ -56,6 +84,8 @@
     }
 
     private void commandTaskComplete(CrnCommand command) {
+        sleep(resetDurationMs());
+        this.crnStatus.setLoaded(0);
         this.crnStatus.setTaskNo(0);
         this.crnStatus.setStatus(CrnStatusType.IDLE.id);
     }
@@ -90,7 +120,7 @@
         moveY(this.crnStatus.getBay(), sourcePosY);
         moveZ(this.crnStatus.getLevel(), sourcePosZ);
         this.crnStatus.setStatus(CrnStatusType.FETCHING.id);
-        sleep(2000);
+        sleep(fetchPutDurationMs());
         if (Thread.currentThread().isInterrupted()) {
             return;
         }
@@ -100,7 +130,7 @@
         moveY(this.crnStatus.getBay(), destinationPosY);
         moveZ(this.crnStatus.getLevel(), destinationPosZ);
         this.crnStatus.setStatus(CrnStatusType.PUTTING.id);
-        sleep(2000);
+        sleep(fetchPutDurationMs());
         if (Thread.currentThread().isInterrupted()) {
             return;
         }
@@ -115,7 +145,7 @@
             for(int i = 0; i < moveLength; i++) {
                 initSourcePosZ++;
                 this.crnStatus.setLevel(initSourcePosZ);
-                sleep(1000);
+                sleep(levelStepDurationMs());
                 if (Thread.currentThread().isInterrupted()) {
                     return;
                 }
@@ -126,7 +156,7 @@
             for(int i = 0; i < moveLength; i++) {
                 initSourcePosZ--;
                 this.crnStatus.setLevel(initSourcePosZ);
-                sleep(1000);
+                sleep(levelStepDurationMs());
                 if (Thread.currentThread().isInterrupted()) {
                     return;
                 }
@@ -141,7 +171,8 @@
             for(int i = 0; i < moveLength; i++) {
                 initSourcePosY++;
                 this.crnStatus.setBay(initSourcePosY);
-                sleep(1000);
+                updateLaserByBay(initSourcePosY);
+                sleep(bayStepDurationMs());
                 if (Thread.currentThread().isInterrupted()) {
                     return;
                 }
@@ -152,7 +183,8 @@
             for(int i = 0; i < moveLength; i++) {
                 initSourcePosY--;
                 this.crnStatus.setBay(initSourcePosY);
-                sleep(1000);
+                updateLaserByBay(initSourcePosY);
+                sleep(bayStepDurationMs());
                 if (Thread.currentThread().isInterrupted()) {
                     return;
                 }

--
Gitblit v1.9.1