lsh
2026-04-21 720e0926fa1c94b952c26e111206c5d6e1ed5ba2
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;
                }