| | |
| | | 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 |
| | |
| | | } |
| | | |
| | | private void commandTaskComplete(CrnCommand command) { |
| | | sleep(resetDurationMs()); |
| | | this.crnStatus.setLoaded(0); |
| | | this.crnStatus.setTaskNo(0); |
| | | this.crnStatus.setStatus(CrnStatusType.IDLE.id); |
| | | } |
| | |
| | | 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; |
| | | } |
| | |
| | | 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; |
| | | } |
| | |
| | | for(int i = 0; i < moveLength; i++) { |
| | | initSourcePosZ++; |
| | | this.crnStatus.setLevel(initSourcePosZ); |
| | | sleep(1000); |
| | | sleep(levelStepDurationMs()); |
| | | if (Thread.currentThread().isInterrupted()) { |
| | | return; |
| | | } |
| | |
| | | for(int i = 0; i < moveLength; i++) { |
| | | initSourcePosZ--; |
| | | this.crnStatus.setLevel(initSourcePosZ); |
| | | sleep(1000); |
| | | sleep(levelStepDurationMs()); |
| | | if (Thread.currentThread().isInterrupted()) { |
| | | return; |
| | | } |
| | |
| | | for(int i = 0; i < moveLength; i++) { |
| | | initSourcePosY++; |
| | | this.crnStatus.setBay(initSourcePosY); |
| | | sleep(1000); |
| | | updateLaserByBay(initSourcePosY); |
| | | sleep(bayStepDurationMs()); |
| | | if (Thread.currentThread().isInterrupted()) { |
| | | return; |
| | | } |
| | |
| | | for(int i = 0; i < moveLength; i++) { |
| | | initSourcePosY--; |
| | | this.crnStatus.setBay(initSourcePosY); |
| | | sleep(1000); |
| | | updateLaserByBay(initSourcePosY); |
| | | sleep(bayStepDurationMs()); |
| | | if (Thread.currentThread().isInterrupted()) { |
| | | return; |
| | | } |