diff --git a/src/main/java/com/iflytop/a800/task/TubeTestTask.java b/src/main/java/com/iflytop/a800/task/TubeTestTask.java index 4e64f99..2793557 100644 --- a/src/main/java/com/iflytop/a800/task/TubeTestTask.java +++ b/src/main/java/com/iflytop/a800/task/TubeTestTask.java @@ -9,11 +9,17 @@ import com.iflytop.a800.model.MdbProject; import com.iflytop.a800.model.MdbTest; import com.iflytop.a800.resource.*; import com.iflytop.a800.utils.ScanResultAnalysisAlgo; +import com.iflytop.uf.UfActuatorCmdExecutor; import com.iflytop.uf.UfCmdSnippetExecutor; -import com.iflytop.uf.util.UfCommon; +import com.iflytop.uf.model.UfMdbDictItem; +import com.iflytop.uf.model.UfMdbOption; import com.iflytop.uf.util.UfJsonHelper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.*; public class TubeTestTask extends TaskBase { + // logger + public static final Logger LOG = LoggerFactory.getLogger(TubeTestTask.class); // 测试试管 public TestTube tube; // 测试项目 @@ -32,6 +38,8 @@ public class TubeTestTask extends TaskBase { private TestCard testCard; // id chip private MdbIdChip idChip; + // 孵育槽位 + private IncubatorSlot incubatorSlot; // 任务准备 public void prepare() { @@ -54,6 +62,14 @@ public class TubeTestTask extends TaskBase { this.test.materialLotCode = this.testCard.lotCode; this.test.save(); + // 移动试管架 + if ( !UfMdbDictItem.match("TUBE_TYPE", "EMERGENCY", this.tube.type) ) { + Integer testStartPos = UfMdbOption.getInteger("TubeRackTubeTestStartPos"); + Integer testDistance = UfMdbOption.getInteger("TubeRackTubeTestDistance"); + int testPos = testStartPos + testDistance * this.tube.index; + UfActuatorCmdExecutor.execute("MotorTubeRackMove", "motor_easy_move_to", Integer.toString(testPos)); + } + this.idChip = new MdbIdChip(); this.idChip.peakCount = 3; this.idChip.itemCount = 1; @@ -69,6 +85,11 @@ public class TubeTestTask extends TaskBase { ))); } + // 记录日志 + private void log(String message, Object ... args ) { + LOG.info(message, args); + } + @Override public void run() { this.prepare(); @@ -89,7 +110,9 @@ public class TubeTestTask extends TaskBase { var stepAction = stepNode.get("action").asText(); switch ( stepAction ) { -// case "shaking" : this.shake(stepNode); break; + case "shaking" : this.shake(stepNode); break; + case "uncap" : this.uncap(); break; + case "cap" : this.cap(); break; case "puncture" : this.executeStepPuncture(stepNode); break; case "aspirate" : this.executeStepAspirate(stepNode); break; case "mixing" : this.executeStepMixing(stepNode); break; @@ -98,16 +121,36 @@ public class TubeTestTask extends TaskBase { case "analysis" : this.executeStepAnalysis(stepNode); break; } } + + this.taskFinish(); } // 摇匀 private void shake( JsonNode stepNode ) { - UfCmdSnippetExecutor.execute("SampleTestShake"); + UfCmdSnippetExecutor.execute("SampleTestShakePrepare"); + for ( int i=0; i<3; i++ ) { + UfActuatorCmdExecutor.execute("MotorTubeShake","step_motor_easy_move_to", "60"); + UfActuatorCmdExecutor.execute("MotorTubeShake","step_motor_easy_move_to", "120"); + } + UfActuatorCmdExecutor.execute("MotorTubeShake","step_motor_easy_move_to", "90"); } // 取盖 private void uncap() { - UfCmdSnippetExecutor.execute("SampleTestUnCap"); + if ( UfMdbDictItem.match("TUBE_TYPE", "WB_5ML", this.tube.type) ) { + UfCmdSnippetExecutor.execute("SampleTestUnCap"); + } else if ( UfMdbDictItem.match("TUBE_TYPE", "WB_3ML", this.tube.type) ) { + UfCmdSnippetExecutor.execute("SampleTestUnCap"); + } + } + + // 盖帽 + private void cap() { + if ( UfMdbDictItem.match("TUBE_TYPE", "WB_5ML", this.tube.type) ) { + UfCmdSnippetExecutor.execute("SampleTestCap"); + } else if ( UfMdbDictItem.match("TUBE_TYPE", "WB_3ML", this.tube.type) ) { + UfCmdSnippetExecutor.execute("SampleTestCap"); + } } // 穿孔 @@ -133,8 +176,8 @@ public class TubeTestTask extends TaskBase { pipette.aspirateFromSampleEpp0_5(this.tube.index, volume); } else if ( "Sample".equals(source) && "SampleEpp1_5Tube".equals(this.tube.type) ) { pipette.aspirateFromSampleEpp1_5(this.tube.index, volume); - } else if ( "Sample".equals(source) && "SampleWholeBlood5mlTube".equals(this.tube.type) ) { - pipette.aspirateFromWholeBlood5ml(this.tube.index, volume); + } else if ( "Sample".equals(source) && UfMdbDictItem.match("TUBE_TYPE", "WB_5ML", this.tube.type)) { + pipette.aspirateFromWholeBlood5ml(volume); } else if ( "Sample".equals(source) && "SampleWholeBlood3mlTube".equals(this.tube.type) ) { pipette.aspirateFromWholeBlood3ml(this.tube.index, volume); } else { @@ -162,7 +205,7 @@ public class TubeTestTask extends TaskBase { // 孵育 private void executeStepIncubate( JsonNode stepNode ) { Device device = Device.getInstance(); - device.incubator.pushNewCard(this.testCard.boxIndex); + this.incubatorSlot = device.incubator.pushNewCard(this.testCard); var pipette = device.pipette; pipette.tipPickUp(); @@ -172,15 +215,25 @@ public class TubeTestTask extends TaskBase { pipette.tipDrop(); - Integer duration = stepNode.get("duration").asInt(); - UfCommon.delay(duration); + int duration = stepNode.get("duration").asInt(); + TimerTask wakeupTask = new TimerTask() { + @Override + public void run() { + TubeTestTask.this.log("孵育完成,等待扫描结果"); + TubeTestTask.this.setStatus("READY"); + } + }; + Timer timer = new Timer(); + timer.schedule(wakeupTask, duration); + this.taskWait("IncubateDone"); } // 扫描 private void executeStepAnalysis( JsonNode stepNode ) { - // 扫描 + this.log("扫描结果"); + Device device = Device.getInstance(); -// device.incubator.exitToScanner(); + device.incubator.exitToScanner(this.incubatorSlot); var scanner = device.scanner; scanner.scanTypeF(); var scanResult = scanner.readResult();