package com.iflytop.a800.device; import com.iflytop.a800.resource.IncubatorSlot; import com.iflytop.a800.resource.TestCard; import com.iflytop.uf.UfActuatorCmdExecutor; import com.iflytop.uf.UfCmdSnippetExecutor; import com.iflytop.uf.model.UfMdbOption; import java.util.ArrayList; import java.util.List; import java.util.Map; public class Incubator extends DeviceComponent { // 槽位 private final List slots; // 槽位起始索引 private Integer slotStartIndex = 0; // 构造函数 public Incubator() { this.slotStartIndex = 0; this.slots = new ArrayList<>(); for ( int i = 0; i < 20; i++ ) { var slot = new IncubatorSlot(); slot.index = i; this.slots.add(slot); } } // 移动至提交位置 public void moveToCommitPos( IncubatorSlot slot ) { Integer commitStartPos = UfMdbOption.getInteger("IncubatorSlotCommitStartPos"); Integer commitDistance = UfMdbOption.getInteger("IncubatorSlotCommitDistance"); int commitPos = commitStartPos + commitDistance * slot.index; UfActuatorCmdExecutor.execute("MotorIncubatorRotate", "motor_easy_move_to", Integer.toString(commitPos)); } // 推送新卡片 public IncubatorSlot pushNewCard(TestCard card) { var lock = this.lock("PushNewCard"); IncubatorSlot slot = null; for ( int i=0; i<20; i++ ) { var tmpSlot = this.slots.get(this.slotStartIndex); this.slotStartIndex = (this.slotStartIndex + 1) % 20; if ( tmpSlot.card != null ) { continue ; } slot = tmpSlot; break; } if ( slot == null ) { throw new RuntimeException("无可用孵育盘槽位"); } Integer boxPos = UfMdbOption.getInteger(String.format("TestCardWarehouseBox.%d", card.boxIndex)); Integer slotStartPos = UfMdbOption.getInteger("IncubatorSlotStartPos"); Integer slotDistance = UfMdbOption.getInteger("IncubatorSlotDistance"); Integer slotPos = slotStartPos + slotDistance * slot.index; Integer commitStartPos = UfMdbOption.getInteger("IncubatorSlotCommitStartPos"); Integer commitDistance = UfMdbOption.getInteger("IncubatorSlotCommitDistance"); Integer commitPos = commitStartPos + commitDistance * slot.index; Map params = Map.of( "box", boxPos, "slot", slotPos, "commit", commitPos ); UfCmdSnippetExecutor.execute("IncubatorTestCardPushIn", params); slot.card = card; this.unlock(lock); return slot; } // 退出到扫描 public void exitCardToScanner( IncubatorSlot slot ) { Integer startPos = UfMdbOption.getInteger("IncubatorSlotExitStartPos"); Integer distance = UfMdbOption.getInteger("IncubatorSlotExitDistance"); Integer slotPos = startPos + distance * slot.index; Map params = Map.of("slot", slotPos); UfCmdSnippetExecutor.execute("IncubatorTestCardExitToScanner", params); slot.card = null; } }